static const char * sim900_wait_string(const char * const sz,const uint8_t isPGM) { #ifndef SIM900_USART_POLLED usart_buffer_flush(&sim900_usart_data); #endif const char * p=sz; char c2 = 0; while(c2=((isPGM)?(nvm_flash_read_byte(p++)):(*p++) )) { if(!sim900_wait_data_on_usart(20)) { debug_string_P(NORMAL,PSTR("(sim900_wait_string) timeout waiting for sim900 response\r\n(sim900_wait_string) OUT\r\n")); return NULL; } #ifdef SIM900_USART_POLLED const char c1=usart_get(USART_GPRS); #else const char c1=USART_RX_CBuffer_GetByte(&sim900_usart_data); #endif //if the sequence is not the same we start over again if(c1!=c2) { p = sz; continue; } } return sz; }
/** * \brief Test checking different registers of the USART module * * This function calls the different check functions and make sure they set the * correct values. * * \param test Current test case. */ static void run_check_registers_test(const struct test_case *test) { bool success; uint8_t data = 'b'; const usart_rs232_options_t options = { .baudrate = CONF_UNIT_BAUDRATE, .charlength = CONF_UNIT_CHARLENGTH, .paritytype = CONF_UNIT_PARITY, .stopbits = CONF_UNIT_STOPBITS }; usart_init_rs232(&CONF_UNIT_USART, &options); /* Test empty data register */ success = usart_data_register_is_empty(&CONF_UNIT_USART); test_assert_true(test, success, "Checking if the data register is empty failed"); /* Test finished data transfers */ usart_put(&CONF_UNIT_USART, data); for(volatile uint16_t delay=0;delay<20000;delay++); success = usart_rx_is_complete(&CONF_UNIT_USART); usart_get(&CONF_UNIT_USART); test_assert_true(test, success, "Checking if the receive is finished failed"); success = usart_tx_is_complete(&CONF_UNIT_USART); test_assert_true(test, success, "Checking if the transmit is finished failed"); }
/** * \internal * \brief Helper function to read a byte from an arbitrary interface * * This function is used to hide what interface is used by the component * driver, e.g. the component driver does not need to know if USART in SPI * mode is used or the native SPI module. * * \retval uint8_t Byte of data read from the display controller */ __always_inline static uint8_t ili9341_read_byte(void) { uint8_t data; #if defined(CONF_ILI9341_USART_SPI) # if XMEGA /* Workaround for clearing the RXCIF for XMEGA */ usart_rx_enable(CONF_ILI9341_USART_SPI); usart_put(CONF_ILI9341_USART_SPI, 0xFF); while (!usart_rx_is_complete(CONF_ILI9341_USART_SPI)) { /* Do nothing */ } data = usart_get(CONF_ILI9341_USART_SPI); /* Workaround for clearing the RXCIF for XMEGA */ usart_rx_disable(CONF_ILI9341_USART_SPI); # else usart_spi_read_single(CONF_ILI9341_USART_SPI, &data); # endif #elif defined(CONF_ILI9341_SPI) spi_write_single(CONF_ILI9341_SPI, 0xFF); ili9341_wait_for_send_done(); /* Wait for RX to complete */ while (!spi_is_rx_full(CONF_ILI9341_SPI)) { /* Do nothing */ } spi_read_single(CONF_ILI9341_SPI, &data); #endif return data; }
void lambda_getData() { if(!is_Init) return; uint16_t s_temp; uint16_t i_temp; uint16_t i; int c = -1; char buffer[MAX_BUFFER_SIZE] = {0}; char * pbuf ; int result; if(lambda_fd == -1) return; result = usart_get(lambda_fd, buffer, MAX_BUFFER_SIZE); if(result > 0) { pbuf = strtok(buffer, "\r\n"); // split using space as divider while (pbuf != NULL) { lambda_auswerten(pbuf); pbuf = strtok(NULL, "\r\n"); // split using space as divider } } };
uint16_t USART_get_buffer(uint8_t* buffer){ uint8_t tmp; uint16_t index=0; while (usart_get(&tmp)) { *(buffer+index) = tmp; index++; } return index; }
static uint8_t sim900_wait_data_on_usart(uint8_t seconds) { for(uint8_t d1=seconds;d1>0;--d1) { for(uint16_t d2=10000;d2>0;--d2) { #ifdef SIM900_USART_POLLED if(usart_rx_is_complete(USART_GPRS)) { #else if(USART_RX_CBuffer_Data_Available(&sim900_usart_data)) { #endif return 0xFF; } delay_us(100); } } debug_string(VERY_VERBOSE,PSTR("(sim900_wait_data_on_usart) timed-out\r\n"),PGM_STRING); return 0; } static uint8_t sim900_read_string(char * const szBuf,uint8_t * const lenBuf) { const uint8_t ec = *lenBuf; uint8_t l = 0; uint8_t r = 0; char c; #ifndef SIM900_USART_POLLED usart_buffer_flush(&sim900_usart_data); #endif while(1) { if(!sim900_wait_data_on_usart(10)) { debug_string(NORMAL,PSTR("(sim900_read_string) got timeout waiting for a character\r\n"),true); r=1; break; } #ifdef SIM900_USART_POLLED c = usart_get(USART_GPRS); #else c = USART_RX_CBuffer_GetByte(&sim900_usart_data); #endif if(c=='\r') { if(g_log_verbosity > NORMAL) usart_putchar(USART_DEBUG,'@'); } else if(c=='\n') { if(g_log_verbosity > NORMAL) usart_putchar(USART_DEBUG,'#'); } else break; } if(r==0) while(l<ec) { szBuf[l++] = c; if(!sim900_wait_data_on_usart(10)) { debug_string(NORMAL,PSTR("(sim900_read_string) got timeout waiting for a character\r\n"),true); r=1; break; } #ifdef SIM900_USART_POLLED c = usart_get(USART_GPRS); #else c = USART_RX_CBuffer_GetByte(&sim900_usart_data); #endif if(c=='\r') { //if(g_log_verbosity > NORMAL) usart_putchar(USART_DEBUG,'@'); break; } else if(c=='\n') { //if(g_log_verbosity > NORMAL) usart_putchar(USART_DEBUG,'#'); break; } //if(g_log_verbosity > NORMAL) usart_putchar(USART_DEBUG,'.'); } if(ec==l) { r = 2; debug_string(NORMAL,PSTR("(sim900_read_string) Provided buffer is not big enough. Discarding chars\r\n"),true); l -= 1; } szBuf[l] = 0; //debug_string(VERBOSE,szBuf,RAM_STRING); //debug_string(VERBOSE,szCRLF,PGM_STRING); //debug_string(VERBOSE,PSTR("(sim900_read_string) out\r\n"),true); *lenBuf = l; return r; } static const char * sim900_wait4dictionary(const char * const dictionary[],uint8_t len) { uint8_t num = len; const char * p[len]; #ifndef SIM900_USART_POLLED usart_buffer_flush(&sim900_usart_data); #endif //debug_string(VERBOSE,PSTR("(sim900_wait4dictionary) IN\r\n"),true); while(num--) { p[num] = nvm_flash_read_word(dictionary+num); } while(1) { if(!sim900_wait_data_on_usart(20)) { debug_string(NORMAL,PSTR("(sim900_wait4dictionary) timeout waiting for sim900 response\r\n(sim900_wait4dictionary) OUT\r\n"),true); return NULL; } #ifdef SIM900_USART_POLLED const char c1 = usart_get(USART_GPRS); #else const char c1=USART_RX_CBuffer_GetByte(&sim900_usart_data); #endif for(uint8_t i=0;i<len;++i) { const char c2 = nvm_flash_read_byte(p[i]); if(c1!=c2) { p[i]=(char *) nvm_flash_read_word(dictionary+i); continue; } p[i]++; if(nvm_flash_read_byte(p[i])==0) { const char * const r = nvm_flash_read_word(dictionary+i); //debug_string(VERY_VERBOSE,PSTR("(sim900_wait4dictionary) got: "),true); //debug_string(VERY_VERBOSE,r,true); //debug_string(VERY_VERBOSE,szCRLF,true); //debug_string(NORMAL,PSTR("(sim900_wait4dictionary) OUT\r\n"),true); return r; } } } }