void uart_write_ext_wkup_func(uint8_t *bufptr, uint32_t size, void (*callback) (uint8_t)) { // Sanity check ASSERT_ERR(bufptr != NULL); ASSERT_ERR(size != 0); ASSERT_ERR(uart_env.tx.bufptr == NULL); GPIO_SetActive (EXT_WAKEUP_PORT, EXT_WAKEUP_PIN); // Prepare TX parameters uart_env.tx.size = size; uart_env.tx.bufptr = bufptr; uart_env.tx.callback = callback; /* start data transaction * first isr execution is done without interrupt generation to reduce * interrupt load */ uart_thr_empty_isr(); if (uart_env.tx.bufptr != NULL) { uart_thr_empty_setf(1); } GPIO_SetInactive (EXT_WAKEUP_PORT, EXT_WAKEUP_PIN); }
void uart_sps_write(uint8_t *bufptr, uint32_t size, uint8_t *state, void (*callback) (uint8_t)) { // Sanity check ASSERT_ERR(bufptr != NULL); if(*state == UART_NONE && !UART_SW_FLOW_ENABLED) //size could be 0 if only flow control must be send { ASSERT_ERR(size != 0); } ASSERT_ERR(uart_sps_env.tx.bufptr == NULL); // Prepare TX parameters uart_sps_env.tx.size = size; uart_sps_env.tx.bufptr = bufptr; uart_sps_env.tx.state = state; uart_sps_env.tx.callback = callback; uart_thr_empty_setf(1); }
/** **************************************************************************************** * @brief Serves the transmit data fill interrupt requests. It clears the requests and * executes the callback function. * * The callback function is called as soon as the last byte of the provided data is * put into the FIFO. The interrupt is disabled at the same time. **************************************************************************************** */ static void uart_thr_empty_isr(void) { void (*callback) (uint8_t) = NULL; // Fill TX FIFO until there is no more room inside it while (uart_txfifo_full_getf()) { // Put a byte in the FIFO uart_txdata_setf(*uart_env.tx.bufptr); // Update TX parameters uart_env.tx.size--; uart_env.tx.bufptr++; if (uart_env.tx.size == 0) { // Reset TX parameters uart_env.tx.bufptr = NULL; // Disable TX interrupt uart_thr_empty_setf(0); // Retrieve callback pointer callback = uart_env.tx.callback; if(callback != NULL) { // Clear callback pointer uart_env.tx.callback = NULL; // Call handler callback(UART_STATUS_OK); } else { ASSERT_ERR(0); } // Exit loop break; } } }
/** **************************************************************************************** * @brief Serves the transmit data fill interrupt requests. It clears the requests and * executes the callback function. The callback function is called as soon as the * last byte of the provided data is put into the FIFO. The interrupt is disabled * at the same time. * * @return void **************************************************************************************** */ static void uart_sps_thr_empty_isr(void) { void (*callback) (uint8_t) = NULL; // Fill TX FIFO until there is no more room inside it while (uart_txfifo_full_getf()) { #if (UART_SW_FLOW_ENABLED) if(*uart_sps_env.tx.state == UART_NONE) #endif { // Put a byte in the FIFO uart_txdata_setf(*uart_sps_env.tx.bufptr); // Update TX parameters uart_sps_env.tx.size--; uart_sps_env.tx.bufptr++; } #if (UART_SW_FLOW_ENABLED) else if(*uart_sps_env.tx.state == UART_XOFF) { uart_txdata_setf(UART_XOFF_BYTE); //push UART XOFF byte } else if (*uart_sps_env.tx.state == UART_XON) { uart_txdata_setf(UART_XON_BYTE); //push UART XON byte } else //undefined state { while(1); //this should never happen } *uart_sps_env.tx.state = UART_NONE; //just send data from now on #endif if (uart_sps_env.tx.size == 0 && *uart_sps_env.tx.state == UART_NONE) { // Reset TX parameters uart_sps_env.tx.bufptr = NULL; // Disable TX interrupt uart_thr_empty_setf(0); // Retrieve callback pointer callback = uart_sps_env.tx.callback; if(callback != NULL) { // Clear callback pointer uart_sps_env.tx.callback = NULL; // Call handler callback(UART_STATUS_OK); } else { ASSERT_ERR(0); } // Exit loop break; } } }