/*! * @brief LPTMR interrupt call back function. * The function is used to toggle LED1. */ static void lptmr_call_back(void) { /* AGC adjust */ if (CMP_DRV_GetOutputLogic(0) != g_cmpConf.invertEnable) { if (g_cmpDacConf.dacValue < 63) { g_cmpDacConf.dacValue++; CMP_DRV_ConfigDacChn(0, &g_cmpDacConf); } } else { if (g_cmpDacConf.dacValue > 0) { g_cmpDacConf.dacValue--; CMP_DRV_ConfigDacChn(0, &g_cmpDacConf); } } /* FIRE THE LASER */ if (laser_on) { LPUART_DRV_SendData(1, txBuff, laser_pulse_length); } /* countdown to turn off LED */ if (blank_led) { if (blank_led == 1) { led(0, 0, 0); } blank_led--; } /* kick EPD driver every once in a while */ EPD_Tick(); }
/*! * @brief Check send/receive non blocking functionality * */ int main(void) { uint8_t rxChar = 0, txChar = 0; uint32_t byteCountBuff = 0; lpuart_state_t lpuartStatePtr; // Fill in lpuart config data lpuart_user_config_t lpuartConfig = { .clockSource = BOARD_LPUART_CLOCK_SOURCE, .bitCountPerChar = kLpuart8BitsPerChar, .parityMode = kLpuartParityDisabled, .stopBitCount = kLpuartOneStopBit, .baudRate = BOARD_DEBUG_UART_BAUD }; // Enable clock for PORTs, setup board clock source hardware_init(); // Initialize the lpuart module with instance number and config structure LPUART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &lpuartStatePtr, &lpuartConfig); // Inform to start non blocking example byteCountBuff = sizeof(buffStart); LPUART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, buffStart, byteCountBuff); while (kStatus_LPUART_TxBusy == LPUART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){} // Inform user of what to do byteCountBuff = sizeof(bufferData1); LPUART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, bufferData1, byteCountBuff); while (kStatus_LPUART_TxBusy == LPUART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){} // Send/receive non blocking function while(true) { // Wait to receive input data LPUART_DRV_ReceiveData(BOARD_DEBUG_UART_INSTANCE, &rxChar, 1); while (kStatus_LPUART_RxBusy == LPUART_DRV_GetReceiveStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){} txChar = rxChar; // Wait for the transfer finish, OR do something else LPUART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, &txChar, 1); } }
// Send function void gsm_uart_send_task(void *arg) { // Create protected queue to send data to gsm modem xSemaphore_uart_gsm_send_handle = xSemaphoreCreateMutex(); xQueue_uart_gsm_send_handle = xQueueCreate(UART_GSM_SEND_QUEUE_SIZE, sizeof( char )); // Create byte send buffer char queue_data_buffer; char uart_send_buffer[255]; uint32_t bytes_remaining; // Enter while loop and send when new data is added to queue while(true) { vTaskDelay(10/portTICK_RATE_MS); uint8_t buffer_counter = 0; if( xQueueReceive( xQueue_uart_gsm_send_handle, &queue_data_buffer, LONG_TIME) ) { *uart_send_buffer = queue_data_buffer; while(xQueueReceive( xQueue_uart_gsm_send_handle, &queue_data_buffer, 0)) { buffer_counter++; *(uart_send_buffer + buffer_counter) = queue_data_buffer; } *(uart_send_buffer + buffer_counter+1) = NULL; // Send package to gsm module LPUART_DRV_SendData(FSL_LPUARTCOM1, &uart_send_buffer, (buffer_counter+1)); // Add to virtual com queue // add_string_to_queue(uart_send_buffer, xQueue_virtual_com_send_handle, 0, xSemaphore_virtual_com_send_handle, 10); while((LPUART_DRV_GetTransmitStatus(FSL_LPUARTCOM1, &bytes_remaining) == kStatus_UART_TxBusy)) { vTaskDelay(2/portTICK_RATE_MS); } } } }