void log_dll_rx_res(dll_rx_res_t* res) { uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_DLL_RX_RES); uart_transmit_data(LOG_TYPE_DLL_RX_RES_SIZE); uart_transmit_data(res->frame_type); uart_transmit_data(res->spectrum_id); }
__LINK_C void log_print_data(uint8_t* message, uint32_t length) { #ifdef FRAMEWORK_LOG_BINARY uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_DATA); uart_transmit_data(length); uart_transmit_message(message, length); #else printf("\n\r[%03d]", NG(counter)++); for( uint32_t i=0 ; i<length ; i++ ) { printf(" %02X", message[i]); } #endif //FRAMEWORK_LOG_BINARY }
/** **************************************************************************************** * @brief Start a data transmission. * @param[in] UART QN_UART0 or QN_UART1 * @param[in] bufptr Pointer to the TX data buffer * @param[in] size Size of the transmission * @param[in] tx_callback Callback for end of transmission * @description * This function is used to write data into TX buffer to transmit data by UART. * As soon as the end of the data transfer is detected, the callback function is executed. * ***************************************************************************************** */ void uart_write(QN_UART_TypeDef *UART, uint8_t *bufptr, uint32_t size, void (*tx_callback)(void)) { #if CONFIG_ENABLE_DRIVER_UART0==TRUE if (UART == QN_UART0) { #if UART_TX_DMA_EN==TRUE dma_tx(DMA_TRANS_BYTE, (uint32_t)bufptr, DMA_UART0_TX, size, tx_callback); #else //Store environment parameters uart0_env.tx.size = size; uart0_env.tx.bufptr = bufptr; #if UART_CALLBACK_EN==TRUE uart0_env.tx.callback = tx_callback; #endif #if CONFIG_UART0_TX_ENABLE_INTERRUPT==TRUE // Enable UART tx int uart_tx_int_enable(UART, MASK_ENABLE); #else // Start data transmission uart_transmit_data(UART, &uart0_env); #endif #endif } #endif #if CONFIG_ENABLE_DRIVER_UART1==TRUE if (UART == QN_UART1) { #if UART_TX_DMA_EN==TRUE dma_tx(DMA_TRANS_BYTE, (uint32_t)bufptr, DMA_UART1_TX, size, tx_callback); #else //Store environment parameters uart1_env.tx.size = size; uart1_env.tx.bufptr = bufptr; #if UART_CALLBACK_EN==TRUE uart1_env.tx.callback = tx_callback; #endif #if CONFIG_UART1_TX_ENABLE_INTERRUPT==TRUE // Enable UART tx int uart_tx_int_enable(UART, MASK_ENABLE); #else // Start data transmission uart_transmit_data(UART, &uart1_env); #endif #endif } #endif }
__LINK_C void log_print_string(char* format, ...) { va_list args; va_start(args, format); #ifdef FRAMEWORK_LOG_BINARY uint8_t len = vsnprintf(NG(buffer), BUFFER_SIZE, format, args); uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_STRING); uart_transmit_data(len); uart_transmit_message(NG(buffer),len); #else printf("\n\r[%03d] ", NG(counter)++); vprintf(format, args); #endif //FRAMEWORK_LOG_BINARY va_end(args); }
void uart_transmit_message(void const *data, size_t length) { unsigned char i=0; for (; i<length; i++) { uart_transmit_data(((char const*)data)[i]); } }
void uart_transmit_message(unsigned char *data, unsigned char length) { unsigned char i=0; for (; i<length; i++) { uart_transmit_data(data[i]); } }
void log_printf(char* format, ...) { va_list args; va_start(args, format); uint8_t len = vsnprintf(buffer, BUFFER_SIZE, format, args); va_end(args); #ifndef USE_SIMPLE_TERMINAL uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_STRING); uart_transmit_data(len); uart_transmit_message((unsigned char*) buffer, len); #else char buf[BUFFER_SIZE]; sprintf(buf, "\n\r[%03d] %s", counter, buffer); uart_transmit_message((unsigned char*) buf, len+8); counter++; #endif }
void log_print_data(uint8_t* message, uint8_t length) { #ifndef USE_SIMPLE_TERMINAL uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_DATA); uart_transmit_data(length); uart_transmit_message((unsigned char*) message, length); #else char buf[BUFFER_SIZE], i; sprintf(buf, "\n\r[%03d]", counter); uart_transmit_message((unsigned char*) buf, 7); for( i=0 ; i<length ; i++ ) { sprintf(buf, " %02X", message[i]); uart_transmit_message((unsigned char*) buf, 3); } counter++; #endif }
void log_print_stack_string(char type, char* format, ...) { va_list args; va_start(args, format); uint8_t len = vsnprintf(buffer, BUFFER_SIZE, format, args); va_end(args); #ifndef USE_SIMPLE_OUTPUT uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_STACK); uart_transmit_data(type); uart_transmit_data(len); uart_transmit_message((unsigned char*) buffer, len); #else char buf[BUFFER_SIZE]; sprintf(buf, "[%03d] %s\n\r", counter, buffer); uart_transmit_message((unsigned char*) buf, len+8); counter++; #endif }
void log_phy_rx_res(phy_rx_data_t* res) { // TODO: add channel id and frame_type // transmit the log header uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_PHY_RX_RES); uart_transmit_data(LOG_TYPE_PHY_RX_RES_SIZE + res->length); // transmit struct member per member, so we are not dependent on packing uart_transmit_data(res->rssi); uart_transmit_data(res->lqi); uart_transmit_data(res->spectrum_id[1]); uart_transmit_data(res->spectrum_id[0]); uart_transmit_data(res->sync_word_class); uart_transmit_data(res->length); // transmit the packet uart_transmit_message(res->data, res->length); }
void log_phy_rx_res(phy_rx_data_t* res) { // transmit the log header uart_transmit_data(0xDD); uart_transmit_data(LOG_TYPE_PHY_RX_RES); uart_transmit_data(LOG_TYPE_PHY_RX_RES_SIZE + res->length); // transmit struct member per member, so we are not dependent on packing uart_transmit_data(res->rssi); uart_transmit_data(res->lqi); uart_transmit_data(res->length); // transmit the packet uart_transmit_message(res->data, res->length); }
__LINK_C void log_print_raw_phy_packet(hw_radio_packet_t* packet, bool is_tx) { #ifdef FRAMEWORK_LOG_BINARY uart_transmit_data(0xDD); if(is_tx) { uart_transmit_data(LOG_TYPE_PHY_PACKET_TX); uart_transmit_message(&(packet->tx_meta.timestamp), sizeof(timer_tick_t)); uart_transmit_data(packet->tx_meta.tx_cfg.channel_id.channel_header_raw); uart_transmit_data(packet->tx_meta.tx_cfg.channel_id.center_freq_index); uart_transmit_data(packet->tx_meta.tx_cfg.syncword_class); uart_transmit_data(packet->tx_meta.tx_cfg.eirp); uart_transmit_message(packet->data, packet->length+1); } else { uart_transmit_data(LOG_TYPE_PHY_PACKET_RX); uart_transmit_message(&(packet->rx_meta.timestamp), sizeof(timer_tick_t)); uart_transmit_data(packet->rx_meta.rx_cfg.channel_id.channel_header_raw); uart_transmit_data(packet->rx_meta.rx_cfg.channel_id.center_freq_index); uart_transmit_data(packet->rx_meta.rx_cfg.syncword_class); uart_transmit_data(packet->rx_meta.lqi); uart_transmit_message(&(packet->rx_meta.rssi), sizeof(int16_t)); // TODO CRC? uart_transmit_message(packet->data, packet->length+1); } #endif // FRAMEWORK_LOG_BINARY }