//----------------------------------------------------------------------------- #include "typedefs.h" #include "muxer_fsc.h" #include "parser.h" #include "application.h" #include "output.h" #include "spi_master.h" #include "ad7719_adc.h" #include "atmega_adc.h" #include "usart.h" #include "macros.h" #include "interpol.h" #include "w5100_spi_interface.h" #include #include #include //----------------------------------------------------------------------------- // MAIN WORKFLOW GLOBAL VARIABLES bool heartbeat_enable = true; bool human_readable_interface_active = true; // USART global variables U08 usart_rx_buffer[USART_RX_BUFFER_SIZE]; U08 usart_tx_buffer[USART_TX_BUFFER_SIZE]; U08 usart_received_chars; U08 usart_rx_buffer_index = 0; U08 usart_tx_buffer_index = 0; U08 usart_last_char; // last received char // USART FLAGS bool usart_tx_buffer_overflow = false; // true if usart_tx_buffer was full. bool usart_rx_ready = false; // EOL was received, parser needs to be called // TIMER global variable volatile U32 local_ms = 0; // AD7719 global variables U32 ad7719_values[TEMP_CHANNELS]; U08 ad7719_enables[CHANNEL_BITMAP]; U08 ad7719_channels_ready[CHANNEL_BITMAP]; U08 ad7719_readings_since_last_muxing = 0; U08 ad7719_current_channel = 0; U32 ad7719_current_reading = 0; bool ad7719_measured_all = false; // ATMEGA ADC global variables U08 adc_values[V_CHANNELS + I_CHANNELS + H_CHANNELS]; // stores measured voltage in steps of 16mV U08 adc_enables[V_BITMAP + I_BITMAP + H_BITMAP]; U08 adc_channels_ready[V_BITMAP + I_BITMAP + H_BITMAP]; U08 adc_readings_since_last_muxing = 0; U08 adc_current_channel = 0; U08 adc_current_reading = 0; bool adc_measured_all = false; bool once_told_you = true; bool debug_mode = false; //----------------------------------------------------------------------------- // M A I N --- M A I N --- M A I N --- M A I N --- M A I N //----------------------------------------------------------------------------- int main(void) { app_init(); // Setup: Watchdog and I/Os usart_init(); // Initialize serial interface spi_init(); // Initialize SPI interface as master ad7719_init(); // Initialize AD7719 ADC as SPI slave atmega_adc_init(); // TIMER2 is used as local clock: // configure timer 2 TCCR2 = (1< counts up every 8us OCR2 = 125-1; // --> output compare interrupt occurs every 125 x 8us = 1ms // Compare Interrupt erlauben TIMSK |= (1< this is #RST of WIZ812MJ --> WIZ812MJ is inactive. static U08 welcome[]="\n\nwelcome to FACT FSC commandline interface v0.5\nready?"; usart_write_str(welcome); for ( U08 i=0; i heartbeat //---------------------------------------------------------------------------- //IF we need to send away one byte, and ready to send // THIS IS NOT USED AT THE MOMENT if ( (usart_tx_buffer_index > 0) && (UCSRA & (1<=5) && (usart_rx_buffer[2] >= 'A' && usart_rx_buffer[2] <= 'H')) { usart_write_char(usart_rx_buffer[2]); usart_write_str((pU08)" to "); usart_write_U08_hex(usart_rx_buffer[4]); usart_write_char('\n'); ad7719_enables[usart_rx_buffer[2]-'A']=usart_rx_buffer[4]; ad7719_channels_ready[usart_rx_buffer[2]-'A']=0x00; } else if ((usart_rx_buffer_index=3) && (usart_rx_buffer[1] >= 'A' && usart_rx_buffer[1] <= 'H')) { usart_write_char(usart_rx_buffer[1]); if (usart_rx_buffer[2]!='0') { usart_write_str((pU08)" to 0xFF\n"); ad7719_enables[usart_rx_buffer[1]-'A']=0xFF; } else { usart_write_str((pU08)" to 0x00\n"); ad7719_enables[usart_rx_buffer[1]-'A']=0x00; } ad7719_channels_ready[usart_rx_buffer[1]-'A']=0x00; } else { usart_write_str((pU08)"\n something wrong\n"); usart_write_str((pU08)"usart_rx_buffer_index: "); usart_write_U08(usart_rx_buffer_index, 3); usart_write_str((pU08)"\n usart_rx_buffer[2]: "); usart_write_char(usart_rx_buffer[2]); usart_write_str((pU08)"\n usart_rx_buffer[4]: "); usart_write_U08_hex(usart_rx_buffer[4]); usart_write_char('\n'); } } void set_adc_enable_register() { // TODO usart_write_str((pU08)"setting of ATmega internal ADC enable registers is not supported. yet.\n"); }