Changeset 10677
- Timestamp:
- 05/12/11 17:47:17 (14 years ago)
- Location:
- firmware/FSC/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/FSC_eth_with_user_interface.c
r10674 r10677 33 33 34 34 // ATMEGA ADC global variables 35 U08 adc_values[VOLTAGE_CHANNELS]; // stores measured voltage in steps of 16mV 35 U08 adc_readings_until_mean=250; 36 U32 adc_values[VOLTAGE_CHANNELS]; // stores measured voltage in steps of 16mV 36 37 U08 adc_enables[VOLTAGE_CHANNELS/8]; 37 38 U08 adc_channels_ready[VOLTAGE_CHANNELS/8]; 38 39 U08 adc_readings_since_last_muxing = 0; 39 40 U08 adc_current_channel = 0; 40 U 08adc_current_reading = 0;41 U16 adc_current_reading = 0; 41 42 bool adc_measured_all = false; 42 43 bool adc_values_printed = true; … … 45 46 bool once_told_you = true; 46 47 bool debug_mode = false; 48 49 // ETHERNET VARS 50 U08 downloaded_bytes; 47 51 48 52 //----------------------------------------------------------------------------- 49 53 // M A I N --- M A I N --- M A I N --- M A I N --- M A I N 50 54 //----------------------------------------------------------------------------- 55 /* 51 56 int main(void) 52 57 { … … 58 63 received_bytes = get_S0_RX_RSR(); 59 64 60 usart_write_U16_hex(get_S0_TX_FSR()); usart_write_char('\t'); usart_write_char('|'); 61 usart_write_U16_hex(get_S0_TX_RD()); usart_write_char('\t'); usart_write_char('|'); 62 usart_write_U16_hex(get_S0_TX_WR()); usart_write_char('\t'); usart_write_char('|'); 63 usart_write_U16_hex(get_S0_RX_RSR()); usart_write_char('\t'); usart_write_char('|'); 64 usart_write_U16_hex(get_S0_RX_RD()); usart_write_char('\t'); usart_write_char('|'); 65 65 66 66 67 … … 115 116 116 117 } // end of main() 117 118 */ 118 119 int main(void) 119 120 { … … 141 142 static U08 welcome[]="welcome to:\n FSC command interface 0.1 \n build: ??.05.2010\n"; 142 143 usart_write_str(welcome); 144 /* 143 145 print_help(); 144 146 print_adc_enable_status(true); … … 149 151 usart_write_U32(sec , 7); 150 152 usart_write_str((pU08)" sec.\n"); 151 153 */ 152 154 //MAIN LOOP 153 155 while (1) 154 156 { 155 if (w5100_caretaker()) 157 // checks if socket is okay and resets in case of problem the W5100 158 if (w5100_caretaker()) 156 159 { 157 160 // something is not okay with the ethernet ... … … 159 162 } 160 163 164 // this if should check every 25ms if we have any data on the W5100 161 165 if ( (milisec % W5100_INPUT_CHECK_TIME == 0) && (w5100_ready) ) 162 166 { 163 167 if (get_S0_RX_RSR() != 0) { // we have something to read 164 really_downloaded_bytes = w5100_get_RX(ETH_READ_BUFFER_SIZE, true); 168 downloaded_bytes = w5100_get_RX(ETH_READ_BUFFER_SIZE, true); 169 usart_write_str((pU08)"got ethernet stream - no. of. bytes:"); 170 usart_write_U08(downloaded_bytes,3); 171 usart_write_char('\n'); 172 for (U08 i=0; i<downloaded_bytes; i++){ 173 usart_write_U08_hex(eth_read_buffer[i]); 174 usart_write_char(' '); 175 } 176 usart_write_char('\n'); 165 177 } 166 178 } … … 170 182 if(adc_print_endless){ 171 183 usart_write_str((pU08)"V|"); 172 usart_write_ float((float)local_ms/1000 , 1,4);184 usart_write_U32(sec ,8); 173 185 print_adc_nicely(false,true); 174 for ( U08 i=0; i< V_BITMAP; ++i ) {186 for ( U08 i=0; i<(VOLTAGE_CHANNELS/8); ++i ) { 175 187 adc_channels_ready[i]=0; 176 188 } … … 185 197 if(ad7719_print_endless){ 186 198 usart_write_str((pU08)"R|"); 187 usart_write_ float((float)local_ms/1000 , 1,4);199 usart_write_U32(sec ,8); 188 200 print_ad7719_nicely(false,true); 189 for ( U08 i=0; i< CHANNEL_BITMAP; ++i ) {201 for ( U08 i=0; i<(RESISTANCE_CHANNELS/8); ++i ) { 190 202 ad7719_channels_ready[i]=0; 191 203 } … … 224 236 if ( UCSRA & (1<<DOR) ){ 225 237 usart_write_str((pU08)"PC sending to fast!\n"); 226 usart_last_char = UDR; 238 //usart_last_char = UDR; 239 UDR; 227 240 // flush TX_buffer and write warning message in 228 241 // maybe even switch off every measurement. ? -
firmware/FSC/src/FSC_test.c
r10667 r10677 11 11 #include "parser.h" 12 12 #include "interpol.h" 13 #include "timer.h" 13 14 #include "w5100_spi_interface.h" 14 15 #include <avr/interrupt.h> … … 29 30 bool verbose; 30 31 bool heartbeat_enable; 31 32 /* 32 33 // USART global variables 33 34 U08 usart_rx_buffer[USART_RX_BUFFER_SIZE]; … … 39 40 // USART FLAGS 40 41 bool usart_tx_buffer_overflow = false; // true if usart_tx_buffer was full. 41 42 */ 42 43 // TIMER global variable 43 44 volatile U32 local_ms = 0; 44 45 45 46 // AD7719 global variables 46 U32 ad7719_values[ TEMP_CHANNELS];47 U08 ad7719_enables[ CHANNEL_BITMAP];48 U08 ad7719_channels_ready[ CHANNEL_BITMAP];47 U32 ad7719_values[RESISTANCE_CHANNELS]; 48 U08 ad7719_enables[RESISTANCE_CHANNELS/8]; 49 U08 ad7719_channels_ready[RESISTANCE_CHANNELS/8]; 49 50 U08 ad7719_readings_since_last_muxing = 0; 50 51 U08 ad7719_current_channel = 0; … … 53 54 54 55 // ATMEGA ADC global variables 55 U08 adc_values[V _CHANNELS + I_CHANNELS + H_CHANNELS]; // stores measured voltage in steps of 16mV56 U08 adc_enables[V _BITMAP + I_BITMAP + H_BITMAP];57 U08 adc_channels_ready[V _BITMAP + I_BITMAP + H_BITMAP];56 U08 adc_values[VOLTAGE_CHANNELS]; // stores measured voltage in steps of 16mV 57 U08 adc_enables[VOLTAGE_CHANNELS/8]; 58 U08 adc_channels_ready[VOLTAGE_CHANNELS/8]; 58 59 U08 adc_readings_since_last_muxing = 0; 59 60 U08 adc_current_channel = 0; … … 356 357 */ 357 358 358 359 /* 359 360 360 361 ISR (TIMER2_COMP_vect) … … 366 367 367 368 369 */ -
firmware/FSC/src/application.c
r10667 r10677 139 139 U08 increase_adc (U08 channel){ 140 140 U08 effective_channel; 141 for ( U08 increase = 1 ; increase <= V _CHANNELS + I_CHANNELS + H_CHANNELS; increase++)142 { 143 effective_channel = (channel + increase) % (V _CHANNELS + I_CHANNELS + H_CHANNELS);141 for ( U08 increase = 1 ; increase <= VOLTAGE_CHANNELS; increase++) 142 { 143 effective_channel = (channel + increase) % (VOLTAGE_CHANNELS); 144 144 if (adc_enables[effective_channel/8] & (1<<effective_channel%8)) 145 145 return effective_channel; … … 150 150 U08 increase_ad7719 (U08 channel){ 151 151 U08 effective_channel; 152 for ( U08 increase = 1 ; increase <= TEMP_CHANNELS; increase++)153 { 154 effective_channel = (channel + increase) % ( TEMP_CHANNELS);152 for ( U08 increase = 1 ; increase <= RESISTANCE_CHANNELS; increase++) 153 { 154 effective_channel = (channel + increase) % (RESISTANCE_CHANNELS); 155 155 if (ad7719_enables[effective_channel/8] & (1<<effective_channel%8)) 156 156 return effective_channel; … … 161 161 void check_if_measured_all() { 162 162 adc_measured_all = true; 163 for ( U08 i=0; i< V_BITMAP + I_BITMAP + H_BITMAP; ++i ) {163 for ( U08 i=0; i<(VOLTAGE_CHANNELS/8); ++i ) { 164 164 if ((adc_enables[i] ^ adc_channels_ready[i]) != 0x00) { 165 165 adc_measured_all = false; … … 168 168 } 169 169 ad7719_measured_all = true; 170 for ( U08 i=0; i< CHANNEL_BITMAP; ++i ) {170 for ( U08 i=0; i<(RESISTANCE_CHANNELS/8); ++i ) { 171 171 if ((ad7719_enables[i] ^ ad7719_channels_ready[i]) != 0x00) { 172 172 ad7719_measured_all = false; … … 177 177 178 178 } 179 180 181 bool check_if_adc_measurement_done(){ 182 adc_measured_all = true; 183 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) { 184 if ((adc_enables[i] ^ adc_channels_ready[i]) != 0x00) { 185 adc_measured_all = false; 186 break; 187 } 188 } 189 return adc_measured_all; 190 } 191 192 bool check_if_ad7719_measurement_done(){ 193 ad7719_measured_all = true; 194 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) { 195 if ((ad7719_enables[i] ^ ad7719_channels_ready[i]) != 0x00) { 196 ad7719_measured_all = false; 197 break; 198 } 199 } 200 return ad7719_measured_all; 201 } -
firmware/FSC/src/application.h
r10674 r10677 63 63 64 64 // ATMEGA ADC global variables 65 extern U 08adc_values[]; // stores measured voltage in steps of 16mV65 extern U32 adc_values[]; // stores measured voltage in steps of 16mV 66 66 extern U08 adc_enables[]; 67 67 extern U08 adc_channels_ready[]; 68 68 extern U08 adc_readings_since_last_muxing; 69 69 extern U08 adc_current_channel; 70 extern U 08adc_current_reading;70 extern U16 adc_current_reading; 71 71 extern bool adc_measured_all; 72 72 extern bool adc_values_printed; … … 95 95 void check_what_measurement_was_finished() ; 96 96 void check_if_measured_all() ; 97 98 bool check_if_adc_measurement_done(); 99 bool check_if_ad7719_measurement_done(); 97 100 // end of function definition: 98 101 //----------------------------------------------------------------------------- -
firmware/FSC/src/output.c
r10674 r10677 6 6 void print_status() { 7 7 usart_write_str((pU08)"adc status:\n"); 8 for (U08 i=0; i< V _BITMAP + I_BITMAP + H_BITMAP;++i) {8 for (U08 i=0; i< VOLTAGE_CHANNELS/8;++i) { 9 9 usart_write_U08_bin(adc_enables[i]); 10 10 usart_write_char(' '); 11 11 } 12 12 usart_write_char('\n'); 13 for (U08 i=0; i< V _BITMAP + I_BITMAP + H_BITMAP;++i){13 for (U08 i=0; i< VOLTAGE_CHANNELS/8;++i){ 14 14 usart_write_U08_bin(adc_channels_ready[i]); 15 15 usart_write_char(' '); … … 18 18 19 19 usart_write_str((pU08)"ad7719 status:\n"); 20 for (U08 i=0; i< CHANNEL_BITMAP;++i) {20 for (U08 i=0; i< RESISTANCE_CHANNELS/8;++i) { 21 21 usart_write_U08_bin(ad7719_enables[i]); 22 22 usart_write_char(' '); 23 23 } 24 24 usart_write_char('\n'); 25 for (U08 i=0; i< CHANNEL_BITMAP;++i){25 for (U08 i=0; i< RESISTANCE_CHANNELS/8;++i){ 26 26 usart_write_U08_bin(ad7719_channels_ready[i]); 27 27 usart_write_char(' '); … … 57 57 usart_write_str((pU08)"\n printing voltages in mV:\n"); 58 58 // output: U08 adc_values[V_CHANNELS + I_CHANNELS + H_CHANNELS]; 59 for (U08 i=0; i< V _CHANNELS + I_CHANNELS + H_CHANNELS;++i) {59 for (U08 i=0; i< VOLTAGE_CHANNELS;++i) { 60 60 if (i%8 == 0) usart_write_char('\n'); 61 61 adc_output(i, adc_values[i]); … … 72 72 usart_write_str((pU08)"\n printing measured resistance in kohms:\n"); 73 73 74 for (U08 i=0; i< TEMP_CHANNELS;++i) {74 for (U08 i=0; i< RESISTANCE_CHANNELS;++i) { 75 75 if (i%8 == 0) usart_write_char('\n'); 76 76 -
firmware/FSC/src/parser.c
r10674 r10677 33 33 case 'G': // GET the Temperature channels, which are enabled 34 34 once_told_you = false; 35 for ( U08 i=0; i< CHANNEL_BITMAP; ++i ) {35 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) { 36 36 ad7719_channels_ready[i]=0; 37 37 } … … 40 40 case 'g': // GET the voltage/current/humidity channels, which are enabled 41 41 once_told_you = false; 42 for ( U08 i=0; i<V _BITMAP + I_BITMAP + H_BITMAP; ++i ) {42 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) { 43 43 adc_channels_ready[i]=0; 44 44 } … … 84 84 // to be discarded, because something went wrong, and the bytemade no sense... 85 85 // the end of a commmand, and so the 'real parser' may do his work. 86 86 /* 87 87 void incoming_byte_parser() { 88 88 static bool receiving_command = false; … … 105 105 106 106 } 107 107 */ 108 /* 108 109 109 110 // this is the recent MSR parser … … 124 125 usart_write_str(usart_rx_buffer); 125 126 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) { 127 128 129 if (usart_received_chars >0) { 130 130 switch (usart_rx_buffer[0]) { 131 131 case 'E': // user wants to enable/disable something … … 135 135 case 'd': 136 136 137 if (usart_r x_buffer_index>=1) { // let's see what.137 if (usart_received_chars>=1) { // let's see what. 138 138 if ( usart_rx_buffer[1] != 'r' && 139 139 usart_rx_buffer[1] != 'v' && … … 141 141 usart_rx_buffer[1] != 'p' ) 142 142 { 143 print_invalid_enable_statement();143 //print_invalid_enable_statement(); 144 144 break; 145 145 } … … 147 147 148 148 input_number = 0; 149 if (usart_r x_buffer_index>2) { // lets check the first digit149 if (usart_received_chars >2) { // lets check the first digit 150 150 if ( usart_rx_buffer[2] >= '0' && usart_rx_buffer[2] <= '9' ) { 151 151 input_number = usart_rx_buffer[2] - '0'; 152 152 } else { 153 print_invalid_enable_statement();153 //print_invalid_enable_statement(); 154 154 break; 155 155 } 156 156 } 157 if (usart_r x_buffer_index>3) { // lets check the 2nd digit157 if (usart_received_chars >3) { // lets check the 2nd digit 158 158 if ( usart_rx_buffer[3] >= '0' && usart_rx_buffer[3] <= '9' ) { 159 159 input_number = 10*input_number + usart_rx_buffer[3] - '0'; … … 164 164 } 165 165 } 166 if (usart_r x_buffer_index>2) {166 if (usart_received_chars>2) { 167 167 usart_write_str((pU08)"\n I will switch "); 168 168 if (enable) … … 226 226 227 227 228 }// end of if usart_r x_buffer_index>2 --> this should not be necessary at all228 }// end of if usart_received_chars>2 --> this should not be necessary at all 229 229 break; 230 230 … … 241 241 case 'G': // GET the Temperature channels, which are enabled 242 242 ad7719_values_printed = false; 243 for ( U08 i=0; i< CHANNEL_BITMAP; ++i ) {243 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) { 244 244 ad7719_channels_ready[i]=0; 245 245 } … … 247 247 case 'g': // GET the voltage/current/humidity channels, which are enabled 248 248 adc_values_printed = false; 249 for ( U08 i=0; i<V _BITMAP; ++i ) {249 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) { 250 250 adc_channels_ready[i]=0; 251 251 } … … 301 301 for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i) 302 302 usart_rx_buffer[i] = 0; 303 usart_r x_buffer_index= 0;303 usart_received_chars = 0; 304 304 usart_rx_ready = false; 305 305 } // END of MSR_parser(); 306 306 307 */ -
firmware/FSC/src/spi_master.c
r10667 r10677 53 53 54 54 // Lets try with the fastest! 55 spi_clock_index = 0; // Set Clockindex for lowest clock speed (F_CPU / 128)55 spi_clock_index = 4; // this is reasonable for W5100 because of slow level shifters on the FSC. 56 56 57 57 spi_dord = 0; // Data Order MSB first dord = 0 --> good for all devices … … 188 188 for (n = 0; n < bytes; n++) 189 189 { 190 PORTB |= 1<< PB3; 190 191 // Check for active slave select level 191 192 if (SPI_DEVICE_ACTIVE_HIGH[device]) … … 206 207 } 207 208 208 209 PORTB &= ~(1<< PB3); 209 210 spi_read_buffer[n] = spi_transfer_byte(spi_write_buffer[n]); 210 211 PORTB |= 1<< PB3; 211 212 212 213 // Check for inactive slave select level … … 227 228 } 228 229 } 229 230 PORTB &= ~(1<< PB3); 230 231 } 231 232 } … … 240 241 241 242 // Wait for transfer completed 243 PORTB |= 1<<PB3; 242 244 while (!(SPSR & (1 << SPIF))) 243 245 { 244 } 246 PORTB ^= 1<<PB3; 247 } 248 PORTB &= ~(1<<PB3); 245 249 246 250 // Return result of transfer … … 282 286 } 283 287 //----------------------------------------------------------------------------- 288 289 290 //----------------------------------------------------------------------------- 291 292 void spi_transfer_w5100(U08 bytes) 293 { 294 295 U08 n; 296 // Transfer requested bytes 297 SPCR |= 1<<MSTR; // make sure we are still SPI MASTER ... sometimes this bit is cleared by something ... dkw? 298 for (n = 0; n < bytes; n++) 299 { 300 PORTB &= ~(1<< PB4); // SS low 301 302 SPDR = spi_write_buffer[n]; 303 while (!(SPSR & (1 << SPIF))) 304 spi_read_buffer[n] = SPDR ; 305 306 PORTB |= (1<< PB4); // SS HIGH 307 } 308 309 310 } 311 //----------------------------------------------------------------------------- -
firmware/FSC/src/spi_master.h
r10109 r10677 26 26 void spi_init(void); 27 27 void spi_transfer(U08 bytes, U08 device); 28 void spi_transfer_w5100(U08 bytes); 28 29 U08 spi_transfer_byte(U08 data); 29 30 void spi_set_clock_index(U08 clock_index); -
firmware/FSC/src/w5100_spi_interface.c
r10674 r10677 24 24 if (socket_status == SR_SOCK_ESTABLISHED) { 25 25 w5100_ready = true; 26 26 27 // everything is fine... 27 28 return 0; … … 63 64 spi_write_buffer[3]=data; 64 65 65 spi_transfer (4, 0);66 spi_transfer_w5100(4); 66 67 // spi_read_buffer should contain 0x00 0x01 0x02 and 0x03 ... nice check! 67 68 } … … 74 75 spi_write_buffer[3]=0x00; 75 76 76 spi_transfer (4, 0);77 spi_transfer_w5100(4); 77 78 return spi_read_buffer[3]; 78 79 // spi_read_buffer should contain 0x00 0x01 0x02 and data ... nice check! … … 117 118 w5100_write ( S0_PORT0, 0x13 ); // Port 5000 -> 0x1388 118 119 w5100_write ( S0_PORT1, 0x88 ); 119 usart_write_str((pU08)"Issuing Socket open command. NOW\n");120 120 w5100_write ( S0_CR, CR_OPEN ); // issue Socket open command 121 121 while (sock0_status != SR_SOCK_INIT) { 122 122 sock0_status = w5100_read(S0_SR); // request socket 0 status 123 usart_write_str((pU08)"Socket 0 status is:"); 124 usart_write_U08_hex(sock0_status); 125 usart_write_char('\n'); 126 } 127 128 usart_write_str((pU08)"Issuing Socket LISTEN command. NOW\n"); 123 } 124 129 125 w5100_write ( S0_CR, CR_LISTEN ); // issue Socket listen command 130 131 126 while (sock0_status != SR_SOCK_LISTEN) { 132 127 sock0_status = w5100_read(S0_SR); // request socket 0 status 133 usart_write_str((pU08)"Socket 0 status is:");134 usart_write_U08_hex(sock0_status);135 usart_write_char('\n');136 128 } 137 129 return sock0_status; -
firmware/FSC/src/w5100_spi_interface.h
r10674 r10677 11 11 12 12 #define ETH_READ_BUFFER_SIZE 32 13 #define ETH_WRITE_BUFFER_SIZE 1613 #define ETH_WRITE_BUFFER_SIZE 32 14 14 extern volatile U08 eth_read_buffer[ETH_READ_BUFFER_SIZE]; 15 15 extern volatile U08 eth_write_buffer[ETH_WRITE_BUFFER_SIZE];
Note:
See TracChangeset
for help on using the changeset viewer.