Changeset 10674 for firmware/FSC
- Timestamp:
- 05/12/11 10:15:41 (14 years ago)
- Location:
- firmware/FSC/src
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/application.h
r10667 r10674 8 8 9 9 //----------------------------------------------------------------------------- 10 11 // in order to check the user interface on a hardware near level. 12 // user can issue 'heartbeat command'. 13 // then this üpin is toggled with the 'main-while-loop-frequency' 14 // --> nice check for this frequency as well 15 #define HEARTBEATPIN PB3 10 16 11 17 // SPI DEFINITIONS … … 27 33 #ifndef ___MAIN_WORKFLOW_GLOBAL_VARS 28 34 #define ___MAIN_WORKFLOW_GLOBAL_VARS 29 #define TEMP_CHANNELS 64 30 #define CHANNEL_BITMAP 8 35 #define RESISTANCE_CHANNELS 64 31 36 #define AD7719_READINGS_UNTIL_SETTLED 3 // bei3:480ms 32 37 33 #define V_CHANNELS 40 34 #define I_CHANNELS 40 35 #define H_CHANNELS 4 36 #define V_BITMAP 5 37 #define I_BITMAP 5 38 #define H_BITMAP 1 38 #define VOLTAGE_CHANNELS 84 39 39 #define ADC_READINGS_UNTIL_SETTLED 1 40 40 #endif 41 42 #define W5100_INPUT_CHECK_TIME 25 // defines how often the W5100 should be asked if something arrived... in ms 41 43 42 44 // MAIN WORKFLOW GLOBAL VARIABLES … … 50 52 51 53 // AD7719 global variables 52 extern U32 ad7719_values[ TEMP_CHANNELS];53 extern U08 ad7719_enables[ CHANNEL_BITMAP];54 extern U08 ad7719_channels_ready[ CHANNEL_BITMAP];54 extern U32 ad7719_values[]; 55 extern U08 ad7719_enables[]; 56 extern U08 ad7719_channels_ready[]; 55 57 extern U08 ad7719_readings_since_last_muxing; 56 58 extern U08 ad7719_current_channel; 57 59 extern U32 ad7719_current_reading; 58 60 extern bool ad7719_measured_all; 61 extern bool ad7719_values_printed; 62 extern bool ad7719_print_endless; 63 59 64 // ATMEGA ADC global variables 60 extern U08 adc_values[ V_CHANNELS + I_CHANNELS + H_CHANNELS]; // stores measured voltage in steps of 16mV61 extern U08 adc_enables[ V_BITMAP + I_BITMAP + H_BITMAP];62 extern U08 adc_channels_ready[ V_BITMAP + I_BITMAP + H_BITMAP];65 extern U08 adc_values[]; // stores measured voltage in steps of 16mV 66 extern U08 adc_enables[]; 67 extern U08 adc_channels_ready[]; 63 68 extern U08 adc_readings_since_last_muxing; 64 69 extern U08 adc_current_channel; 65 70 extern U08 adc_current_reading; 66 71 extern bool adc_measured_all; 72 extern bool adc_values_printed; 73 extern bool adc_print_endless; 67 74 68 75 extern bool once_told_you; -
firmware/FSC/src/output.c
r10667 r10674 2 2 #include "usart.h" 3 3 #include "application.h" 4 #include "timer.h" 4 5 5 6 void print_status() { … … 29 30 30 31 usart_write_str((pU08)"time:"); 31 usart_write_ float((float)local_ms/1000 , 1,7);32 usart_write_U32(sec,10); 32 33 usart_write_str((pU08)" sec.\n"); 33 34 -
firmware/FSC/src/parser.c
r10667 r10674 105 105 106 106 } 107 108 109 // this is the recent MSR parser 110 ///////////////////////////////////////////////////////////////////////////////////////////////////// 111 /////////////// P A R S E R ///////////////////////////////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////////////////////////////// 113 // this method parses the data, 114 // which came in via USART 115 // later it might as well parse the data from ethernet. 116 void MSR_parser() { 117 118 U08 input_number = 0; 119 bool enable = false; 120 // look at first byte 121 // I hope, I can manage to use one byte commands 122 usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0; 123 usart_write_char(' '); 124 usart_write_str(usart_rx_buffer); 125 usart_write_char('\n'); 126 //usart_write_str((pU08)"\n received number of bytes:"); 127 //usart_write_U08(usart_rx_buffer_index,3); 128 129 if (usart_rx_buffer_index >0) { 130 switch (usart_rx_buffer[0]) { 131 case 'E': // user wants to enable/disable something 132 case 'e': 133 enable = true; 134 case 'D': 135 case 'd': 136 137 if (usart_rx_buffer_index>=1) { // let's see what. 138 if ( usart_rx_buffer[1] != 'r' && 139 usart_rx_buffer[1] != 'v' && 140 usart_rx_buffer[1] != 'h' && 141 usart_rx_buffer[1] != 'p' ) 142 { 143 print_invalid_enable_statement(); 144 break; 145 } 146 } 147 148 input_number = 0; 149 if (usart_rx_buffer_index >2) { // lets check the first digit 150 if ( usart_rx_buffer[2] >= '0' && usart_rx_buffer[2] <= '9' ) { 151 input_number = usart_rx_buffer[2] - '0'; 152 } else { 153 print_invalid_enable_statement(); 154 break; 155 } 156 } 157 if (usart_rx_buffer_index >3) { // lets check the 2nd digit 158 if ( usart_rx_buffer[3] >= '0' && usart_rx_buffer[3] <= '9' ) { 159 input_number = 10*input_number + usart_rx_buffer[3] - '0'; 160 } else { 161 // okay as well ... if the second digit is missing .. 162 // we might have trailing spaces 163 // that's okay .. we just accept the first number. 164 } 165 } 166 if (usart_rx_buffer_index>2) { 167 usart_write_str((pU08)"\n I will switch "); 168 if (enable) 169 usart_write_str((pU08)"on "); 170 else 171 usart_write_str((pU08)"off "); 172 173 // now we know, what the user wanted ... and we need to do it. 174 switch (usart_rx_buffer[1]) { 175 case 'r': 176 if (enable) 177 ad7719_enables[input_number/8] |= (1<<(input_number%8)); 178 else { 179 ad7719_enables[input_number/8] &= ~(1<<(input_number%8)); 180 ad7719_channels_ready[input_number/8] &= ~(1<<(input_number%8)); 181 } 182 usart_write_str((pU08)" resistance channel "); 183 usart_write_U08(input_number,2); 184 usart_write_char('\n'); 185 break; 186 case 'v': 187 if (enable) 188 adc_enables[input_number/8] |= (1<<(input_number%8)); 189 else { 190 adc_enables[input_number/8] &= ~(1<<(input_number%8)); 191 adc_channels_ready[input_number/8] &= ~(1<<(input_number%8)); 192 } 193 usart_write_str((pU08)" voltage channel "); 194 usart_write_U08(input_number,2); 195 usart_write_char('\n'); 196 break; 197 198 case 'h': 199 if (enable) 200 adc_enables[1] |= (1<<(input_number%4)); 201 else { 202 adc_enables[1] &= ~(1<<(input_number%4)); 203 adc_channels_ready[1] &= ~(1<<(input_number%4)); 204 } 205 usart_write_str((pU08)" humidity channel "); 206 usart_write_U08(input_number,2); 207 usart_write_char('\n'); 208 break; 209 case 'p': 210 if (enable) 211 adc_enables[1] |= (1<<((input_number%4) + 4)); 212 else { 213 adc_enables[1] &= ~(1<<((input_number%4) + 4)); 214 adc_channels_ready[1] &= ~(1<<((input_number%4) + 4)); 215 } 216 usart_write_str((pU08)" pressure channel "); 217 usart_write_U08(input_number,2); 218 usart_write_char('\n'); 219 break; 220 default: 221 usart_write_str((pU08)"\n DAMN! this should never happen" 222 "- enable/disable switch-case!\n"); 223 break; 224 } 225 226 227 228 }// end of if usart_rx_buffer_index>2 --> this should not be necessary at all 229 break; 230 231 case 'b': 232 usart_write_str((pU08)"\nheartbeat "); 233 heartbeat_enable = true; 234 if (usart_rx_buffer[1] == '0'){ 235 heartbeat_enable = false; 236 usart_write_str((pU08)"off\n"); 237 } else { 238 usart_write_str((pU08)"on\n"); 239 } 240 break; 241 case 'G': // GET the Temperature channels, which are enabled 242 ad7719_values_printed = false; 243 for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) { 244 ad7719_channels_ready[i]=0; 245 } 246 break; 247 case 'g': // GET the voltage/current/humidity channels, which are enabled 248 adc_values_printed = false; 249 for ( U08 i=0; i<V_BITMAP; ++i ) { 250 adc_channels_ready[i]=0; 251 } 252 break; 253 254 case 'p': 255 adc_print_endless = true; 256 if (usart_rx_buffer[1] == '0') 257 adc_print_endless = false; 258 break; 259 260 case 'P': 261 ad7719_print_endless = true; 262 if (usart_rx_buffer[1] == '0') 263 ad7719_print_endless = false; 264 break; 265 266 267 case 's': 268 print_adc_enable_status(true); 269 usart_write_char('\n'); 270 271 print_ad7719_enable_status(true); 272 usart_write_char('\n'); 273 274 usart_write_str((pU08)"time:"); 275 usart_write_float((float)local_ms/1000 , 1,7); 276 usart_write_str((pU08)" sec.\n"); 277 break; 278 279 case '!': 280 usart_write_str((pU08)"\ndebug mode "); 281 debug_mode = true; 282 if (usart_rx_buffer[1] == '0'){ 283 debug_mode = false; 284 usart_write_str((pU08)"off\n"); 285 } else { 286 usart_write_str((pU08)"on\n"); 287 } 288 break; 289 290 case 'h': 291 case 'H': 292 print_help(); 293 break; 294 } 295 } else 296 { 297 // zero bytes received 298 } 299 300 301 for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i) 302 usart_rx_buffer[i] = 0; 303 usart_rx_buffer_index = 0; 304 usart_rx_ready = false; 305 } // END of MSR_parser(); 306 -
firmware/FSC/src/parser.h
r10667 r10674 3 3 4 4 void parse_ascii(); 5 5 void MSR_parser() ; 6 6 7 7 // all allowed non readable commands are listed here -
firmware/FSC/src/usart.c
r10667 r10674 8 8 9 9 #endif 10 11 U08 usart_tx_buffer[USART_TX_BUFFER_SIZE]; 12 U08 usart_tx_buffer_index = 0; 13 bool usart_tx_buffer_overflow = false; // true if usart_tx_buffer was full. 14 15 10 16 11 17 #ifdef USART_USE_RX_IRQ -
firmware/FSC/src/w5100_spi_interface.c
r10667 r10674 9 9 10 10 //----------------------------------------------------------------------------- 11 // INTERFACE CONTROL VARS 12 13 bool w5100_needs_reset = true; 14 bool w5100_needs_init = true; 15 bool w5100_ready = false; 16 17 U08 w5100_caretaker() { 18 U08 socket_status; 19 if (w5100_needs_reset) 20 w5100_reset(); 21 22 socket_status = w5100_sock_status(); 23 24 if (socket_status == SR_SOCK_ESTABLISHED) { 25 w5100_ready = true; 26 // everything is fine... 27 return 0; 28 } 29 else if(socket_status < SR_SOCK_ESTABLISHED) { 30 // it might be LISTENING ... or not even OPEN 31 if (socket_status == SR_SOCK_CLOSED) { 32 w5100_init(); 33 } 34 if (socket_status == SR_SOCK_INIT) { 35 w5100_init(); 36 } 37 if (socket_status == SR_SOCK_LISTEN) { 38 39 } 40 } 41 else { // all other socket states need a reset 42 w5100_needs_reset = true; 43 } 44 w5100_ready = false; 45 return 1; 46 } 47 48 void w5100_reset() { 49 PORTB &= ~(1<<PB2); //#reset = LOW --> W5100 is in reset ... 50 _delay_ms(50); //reset 51 52 PORTB |= 1<<PB2; //#reset = HIGH --> W5100 is active 53 _delay_ms(5); // give it 5ms to accomodate. 54 w5100_needs_reset = false; 55 } 56 11 57 12 58 void w5100_write( U16 addr, U08 data) -
firmware/FSC/src/w5100_spi_interface.h
r10667 r10674 10 10 11 11 12 #define ETH_READ_BUFFER_SIZE 1612 #define ETH_READ_BUFFER_SIZE 32 13 13 #define ETH_WRITE_BUFFER_SIZE 16 14 14 extern volatile U08 eth_read_buffer[ETH_READ_BUFFER_SIZE]; … … 216 216 void w5100_TX(U08 NumBytes, U08 *str); 217 217 U08 w5100_set_TX(U08 NumBytes); 218 219 extern bool w5100_needs_reset; 220 extern bool w5100_needs_init; 221 extern bool w5100_ready; 222 223 224 225 U08 w5100_caretaker(); 226 void w5100_reset() ; 227 228
Note:
See TracChangeset
for help on using the changeset viewer.