/*! * @brief Power manager user callback */ power_manager_error_code_t callback0(power_manager_notify_struct_t * notify, power_manager_callback_data_t * dataPtr) { user_callback_data_t * userData = (user_callback_data_t*) dataPtr; power_manager_error_code_t ret = kPowerManagerError; volatile bool isLastByteTranmistComplete = false; switch (notify->notifyType) { case kPowerManagerNotifyBefore: userData->before.counter++; do { isLastByteTranmistComplete = LPUART_HAL_GetStatusFlag(BOARD_DEBUG_UART_BASEADDR,kLpuartTxComplete); } while (!isLastByteTranmistComplete); disable_unused_pins(); ret = kPowerManagerSuccess; break; case kPowerManagerNotifyAfter: userData->after.counter++; enable_unused_pins(); ret = kPowerManagerSuccess; break; default: userData->err++; break; } userData->lastType = notify->notifyType; return ret; }
/*! * @brief wait uart finished. * */ void wait_finish_uart(void) { uint32_t bytesRemaining = 0; volatile bool isLastByteTranmistComplete = false; do { LPUART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, &bytesRemaining); isLastByteTranmistComplete = LPUART_HAL_GetStatusFlag(BOARD_DEBUG_UART_BASEADDR,kLpuartTxComplete); } while ((bytesRemaining != 0) || (!isLastByteTranmistComplete)); }
/*FUNCTION********************************************************************** * * Function Name : LPUART_DRV_IRQHandler * Description : Interrupt handler for LPUART. * This handler uses the buffers stored in the lpuart_state_t structs to transfer * data. This is not a public API as it is called by IRQ whenever an interrupt * occurs. * *END**************************************************************************/ void LPUART_DRV_IRQHandler(uint32_t instance) { lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance]; LPUART_Type * base = g_lpuartBase[instance]; /* Exit the ISR if no transfer is happening for this instance. */ if ((!lpuartState->isTxBusy) && (!lpuartState->isRxBusy)) { return; } /* Handle receive data full interrupt */ if((LPUART_BRD_CTRL_RIE(base)) && (LPUART_BRD_STAT_RDRF(base))) { /* Get data and put in receive buffer */ LPUART_HAL_Getchar(base, lpuartState->rxBuff); /* Invoke callback if there is one */ if (lpuartState->rxCallback != NULL) { lpuartState->rxCallback(instance, lpuartState); } else { ++lpuartState->rxBuff; --lpuartState->rxSize; /* Check and see if this was the last byte received */ if (lpuartState->rxSize == 0) { LPUART_DRV_CompleteReceiveData(instance); } } } /* Handle transmitter data register empty interrupt */ if((LPUART_BRD_CTRL_TIE(base)) && (LPUART_BRD_STAT_TDRE(base))) { /* check to see if there are any more bytes to send */ if (lpuartState->txSize) { /* Transmit the data */ LPUART_HAL_Putchar(base, *(lpuartState->txBuff)); /* Invoke callback if there is one */ if (lpuartState->txCallback != NULL) { /* The callback MUST set the txSize to 0 if the * transmit is ended.*/ lpuartState->txCallback(instance, lpuartState); } else { ++lpuartState->txBuff; --lpuartState->txSize; } } else //modified for ISO7816 { /* If this was the last byte, complete transfer, will disable tx interrupt */ LPUART_DRV_CompleteSendData(instance); LPUART_HAL_ClearStatusFlag(base, kLpuartTxDataRegEmpty); LPUART_HAL_SetTxdirInSinglewireMode(LPUART0, kLpuartSinglewireTxdirIn); //set it to receive mode } } /* Handle receive overrun interrupt */ if (LPUART_HAL_GetStatusFlag(base, kLpuartRxOverrun)) { /* Clear the flag, OR the rxDataRegFull will not be set any more */ LPUART_HAL_ClearStatusFlag(base, kLpuartRxOverrun); } }