void EXTI4_15_IRQHandler(void) { if (EXTI_GetITStatus(EXTI_Line5) != RESET) { //Check Which Pin Caused Interrupt //USB_FLG_1 Error!! isr_evt_set(UI_EVT_USB_OC, ui_t); //Clear the EXTI line 5 pending bit EXTI_ClearITPendingBit(EXTI_Line5); } if (EXTI_GetITStatus(EXTI_Line6) != RESET) { //Check Which Pin Caused Interrupt //USB_FLG_2 Error!! isr_evt_set(UI_EVT_USB_OC, ui_t); //Clear the EXTI line 5 pending bit EXTI_ClearITPendingBit(EXTI_Line6); } if (EXTI_GetITStatus(EXTI_Line7) != RESET) { //Check Which Pin Caused Interrupt //Keypad line 3 event, buttons 3, 6, 8, ./ //Send event to ui task isr_evt_set (UI_EVT_KEYPAD_3 , ui_t); //Clear the EXTI line 7 pending bit EXTI_ClearITPendingBit(EXTI_Line7); } if (EXTI_GetITStatus(EXTI_Line8) != RESET) { //Check Which Pin Caused Interrupt //Keypad line 2 event, buttons 2, 5, 8, 0 //Send event to ui task isr_evt_set (UI_EVT_KEYPAD_2 , ui_t); //Clear the EXTI line 8 pending bit EXTI_ClearITPendingBit(EXTI_Line8); } if (EXTI_GetITStatus(EXTI_Line9) != RESET) { //Check Which Pin Caused Interrupt //Keypad line 1 event, buttons 1, 4, 7, X //Send event to ui task isr_evt_set (UI_EVT_KEYPAD_1 , ui_t); //Clear the EXTI line 9 pending bit EXTI_ClearITPendingBit(EXTI_Line9); } }
/**************************************************************************************************** * @fn I2C_Driver_ERR_ISR_Handler * This function is the I2C error interrupt handler. * * @param none * * @return none * ***************************************************************************************************/ void I2C_Driver_ERR_ISR_Handler(void) { __IO uint32_t SR1Register = 0; /* Read the I2C1 status register */ SR1Register = I2C_SENSOR_BUS->SR1; /* If AF = 1 */ if ((SR1Register & I2C_MASK_AF) == I2C_STATUS_BIT_AF) { I2C_SENSOR_BUS->SR1 &= (~I2C_STATUS_BIT_AF); SR1Register = 0; } /* If ARLO = 1 */ if ((SR1Register & I2C_MASK_ARLO) == I2C_STATUS_BIT_ARLO) { I2C_SENSOR_BUS->SR1 &= (~I2C_STATUS_BIT_ARLO); SR1Register = 0; } /* If BERR = 1 */ if ((SR1Register & I2C_MASK_BERR) == I2C_STATUS_BIT_BERR) { I2C_SENSOR_BUS->SR1 &= (~I2C_STATUS_BIT_BERR); SR1Register = 0; } /* If OVR = 1 */ if ((SR1Register & I2C_MASK_OVR) == I2C_STATUS_BIT_OVR) { I2C_SENSOR_BUS->SR1 &= (~I2C_STATUS_BIT_OVR); SR1Register = 0; } asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_FAILED; isr_evt_set(I2C_TXRX_STATUS_FAILED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); }
void FLEX_INT0_IRQHandler() { isr_evt_set(isr_flags, isr_notify); NVIC_DisableIRQ(FLEX_INT0_IRQn); // ack interrupt LPC_GPIO_PIN_INT->IST = 0x01; }
/******************************************************************************* * Function Name : uart_irq_handler * Description : Interrupt handle function * Input : - Uart: Select the USART or the UART peripheral. * Output : None * Return : None *******************************************************************************/ void uart_irq_handler(const _Uart_Descriptor *Uart) { // __hw_enter_interrupt(); // if (*Uart->Ctrl && (*Uart->Ctrl)->DmaBufSize) { if (USART_GetITStatus(Uart->UARTx, USART_IT_IDLE) != RESET) // Idle line { NVIC_SetPendingIRQ(Uart->DMAx_IRQn); USART_ReceiveData(Uart->UARTx); } } else if (USART_GetITStatus(Uart->UARTx, USART_IT_RXNE) != RESET) // Received Data Ready to be Read { if (*Uart->Ctrl && ((*Uart->Ctrl)->RxCnt < (*Uart->Ctrl)->RxBufSize)) { (*Uart->Ctrl)->RxBufPtr[(*Uart->Ctrl)->RxiPut++] = (char)USART_ReceiveData(Uart->UARTx); //lepton if(!(*Uart->Ctrl)->RxCnt){ if(Uart->board_uart_info && Uart->board_uart_info->desc_r!=-1) __fire_io_int(ofile_lst[Uart->board_uart_info->desc_r].owner_pthread_ptr_read); } //lepton (*Uart->Ctrl)->RxCnt++; if ((*Uart->Ctrl)->RxiPut >= (*Uart->Ctrl)->RxBufSize) (*Uart->Ctrl)->RxiPut = 0; if (((*Uart->Ctrl)->HwCtrl & UART_HW_FLOW_CTRL_RX) && ((*Uart->Ctrl)->RxCnt > ((*Uart->Ctrl)->RxBufSize - (*Uart->Ctrl)->DmaBufSize))) uart_set_rx_hw_fc(Uart); } else USART_ClearITPendingBit(Uart->UARTx, USART_IT_RXNE); #ifdef _UART_OS_SUPPORT isr_evt_set((*Uart->Ctrl)->Event, (*Uart->Ctrl)->Task); #endif } if (USART_GetITStatus(Uart->UARTx, USART_IT_TXE) != RESET) // Transmit Data Register Empty { if (*Uart->Ctrl && (*Uart->Ctrl)->TxCnt) { USART_SendData(Uart->UARTx, (*Uart->Ctrl)->TxBufPtr[(*Uart->Ctrl)->TxiGet++]); (*Uart->Ctrl)->TxCnt--; if ((*Uart->Ctrl)->TxiGet >= (*Uart->Ctrl)->TxBufSize) (*Uart->Ctrl)->TxiGet = 0; } else{ USART_ITConfig(Uart->UARTx, USART_IT_TXE, DISABLE); //lepton if(Uart->board_uart_info && Uart->board_uart_info->desc_w!=-1) __fire_io_int(ofile_lst[Uart->board_uart_info->desc_w].owner_pthread_ptr_write); //lepton } } if (USART_GetITStatus(Uart->UARTx, USART_IT_TC) != RESET) // Transmission complete { if (*Uart->Ctrl && ((*Uart->Ctrl)->HwCtrl & UART_HALF_DUPLEX)) uart_tx_disable(Uart); USART_ClearITPendingBit(Uart->UARTx, USART_IT_TC); } // __hw_leave_interrupt(); }
/******************************************************************************* * Function Name : uart_dma_irq_handler * Description : DMA interrupt handle function * Input : - Uart: Select the USART or the UART peripheral. * Output : None * Return : None *******************************************************************************/ void uart_dma_irq_handler(const _Uart_Descriptor *Uart) { // __hw_enter_interrupt(); // if (*Uart->Ctrl) { while ((DMA_GetCurrDataCounter(Uart->DMAy_Streamx) != (*Uart->Ctrl)->iDma) && ((*Uart->Ctrl)->RxCnt < (*Uart->Ctrl)->RxBufSize)) { (*Uart->Ctrl)->RxBufPtr[(*Uart->Ctrl)->RxiPut++] = (*Uart->Ctrl)->DmaBufPtr[(*Uart->Ctrl)->DmaBufSize - (*Uart->Ctrl)->iDma--]; if (!(*Uart->Ctrl)->iDma) (*Uart->Ctrl)->iDma = (*Uart->Ctrl)->DmaBufSize; //lepton if(!(*Uart->Ctrl)->RxCnt){ if(Uart->board_uart_info && Uart->board_uart_info->desc_r!=-1) __fire_io_int(ofile_lst[Uart->board_uart_info->desc_r].owner_pthread_ptr_read); } //lepton (*Uart->Ctrl)->RxCnt++; if ((*Uart->Ctrl)->RxiPut >= (*Uart->Ctrl)->RxBufSize) (*Uart->Ctrl)->RxiPut = 0; if (((*Uart->Ctrl)->HwCtrl & UART_HW_FLOW_CTRL_RX) && ((*Uart->Ctrl)->RxCnt > ((*Uart->Ctrl)->RxBufSize - (*Uart->Ctrl)->DmaBufSize))) uart_set_rx_hw_fc(Uart); } } #ifdef _UART_OS_SUPPORT isr_evt_set((*Uart->Ctrl)->Event, (*Uart->Ctrl)->Task); #endif // DMA_ClearITPendingBit(Uart->DMAy_Streamx, DMA_IT_ALL_1); // __hw_leave_interrupt(); // }
void DMA1_Channel1_IRQHandler(void) { if(DMA_GetITStatus(DMA1_IT_TC1)) { DMA_ClearITPendingBit(DMA1_IT_GL1); isr_evt_set(EVT_ADC_DONE, tid_conflict_monitor); } }
int32_t LLMJVM_IMPL_wakeupVM(void){ if(isInInterrupt()) isr_evt_set(LLMJVM_RTX_EVT_WAKEUP, LLMJVM_RTX_taskID); else os_evt_set(LLMJVM_RTX_EVT_WAKEUP, LLMJVM_RTX_taskID); LLMJVM_RTX_nextWakeupTime = INT64_MAX; return LLMJVM_OK; }
uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags) { if (cortex_in_isr()){ isr_evt_set(flags, (OS_TID)thread_id); }else { os_evt_set(flags, (OS_TID)thread_id); } return flags; }
void EXTI0_1_IRQHandler(void) { if (EXTI_GetITStatus(EXTI_Line0) != RESET) { //Check Which Pin Caused Interrupt //Only PA0 configures //Temp: Use switch as Reset Switch //NVIC_SystemReset(); //Send event to ui task isr_evt_set (UI_PWR_SW , ui_t); //Clear the EXTI line 0 pending bit EXTI_ClearITPendingBit(EXTI_Line0); } }
void DMA0_IRQHandler(void) { // Light green LED in DMA IRQ handler Control_RGB_LEDs(0,1,0); NVIC_ClearPendingIRQ(DMA0_IRQn); // Clear done flag DMA0->DMA[0].DSR_BCR |= DMA_DSR_BCR_DONE_MASK; #if 1 // under development for continuous playback // Signal event requesting source buffer refill isr_evt_set(EV_REFILL_SOUND, t_Refill_Sound_Buffer); // Start playback again Start_DMA_Playback(); #else // Disable DMA DMAMUX0->CHCFG[0] &= ~DMAMUX_CHCFG_ENBL_MASK; #endif Control_RGB_LEDs(0,0,0); }
void USBD_Handler(void) { uint32_t irq_flags; unsigned int ep; uint32_t ep_int, mask; // Read and clear interrupts irq_flags = MXC_USB->dev_intfl; MXC_USB->dev_intfl = irq_flags; /* reset interrupt */ if (irq_flags & MXC_F_USB_DEV_INTFL_BRST) { if (suspended) { suspended = 0; #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_RESUME, USBD_RTX_DevTask); } #else if (USBD_P_Resume_Event) { USBD_P_Resume_Event(); } #endif } reset_state(); usbd_reset_core(); #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_RESET, USBD_RTX_DevTask); } #else if (USBD_P_Reset_Event) { USBD_P_Reset_Event(); } #endif } /* reset done interrupt */ if (irq_flags & MXC_F_USB_DEV_INTFL_BRST_DN) { reset_state(); } /* suspend interrupt */ if (irq_flags & MXC_F_USB_DEV_INTFL_SUSP) { suspended = 1; #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_SUSPEND, USBD_RTX_DevTask); } #else if (USBD_P_Suspend_Event) { USBD_P_Suspend_Event(); } #endif } if (irq_flags & MXC_F_USB_DEV_INTFL_VBUS) { #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_POWER_ON, USBD_RTX_DevTask); } #else if (USBD_P_Power_Event) { USBD_P_Power_Event(1); } #endif } if (irq_flags & MXC_F_USB_DEV_INTFL_NO_VBUS) { #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_POWER_OFF, USBD_RTX_DevTask); } #else if (USBD_P_Power_Event) { USBD_P_Power_Event(0); } #endif } if (irq_flags & MXC_F_USB_DEV_INTFL_SETUP) { setup_waiting = 1; #ifdef __RTX if (USBD_RTX_EPTask[0]) { isr_evt_set(USBD_EVT_SETUP, USBD_RTX_EPTask[0]); } #else if (USBD_P_EP[0]) { USBD_P_EP[0](USBD_EVT_SETUP); } #endif } if (irq_flags & MXC_F_USB_DEV_INTFL_EP_IN) { // Read and clear endpoint interrupts ep_int = MXC_USB->in_int; MXC_USB->in_int = ep_int; mask = 1; for (ep = 0; ep < MXC_USB_NUM_EP; ep++) { if (ep_int & mask) { #ifdef __RTX if (USBD_RTX_EPTask[ep]) { isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[ep]); } #else if (USBD_P_EP[ep]) { USBD_P_EP[ep](USBD_EVT_IN); } #endif } mask <<= 1; } } if (irq_flags & MXC_F_USB_DEV_INTFL_EP_OUT) { // Read and clear endpoint interrupts ep_int = MXC_USB->out_int; MXC_USB->out_int = ep_int; mask = 1; for (ep = 0; ep < MXC_USB_NUM_EP; ep++) { if (ep_int & mask) { #ifdef __RTX if (USBD_RTX_EPTask[ep]) { isr_evt_set(USBD_EVT_OUT, USBD_RTX_EPTask[ep]); } #else if (USBD_P_EP[ep]) { USBD_P_EP[ep](USBD_EVT_OUT); } #endif } mask <<= 1; } } if (irq_flags & MXC_F_USB_DEV_INTFL_DMA_ERR) { // Read and clear endpoint interrupts ep_int = MXC_USB->dma_err_int; MXC_USB->dma_err_int = ep_int; while(1); // not recoverable } NVIC_EnableIRQ(USB_IRQn); }
void USART3_IRQHandler(void) { receivedData=USART3->DR; isr_evt_set(0x01,t_UsartTask); }
void USBD_SignalHandler() { isr_evt_set(FLAGS_MAIN_PROC_USB, main_task_id); }
/**************************************************************************************************** * @fn I2C_IRQHandler * Handler for I2C Tx/Rx related interrupt * ***************************************************************************************************/ void I2C_IRQHandler(LPC_I2C_T *pI2C) { uint32_t status = Chip_I2CM_GetStatus(pI2C); uint32_t i2cmststate = Chip_I2CM_GetMasterState(pI2C); /* Only check Master and Slave State */ uint32_t mstCtrl = I2C_MSTCTL_MSTCONTINUE; if ( status & I2C_STAT_MSTRARBLOSS ) { /* Master Lost Arbitration */ /* Clear Status Flags */ Chip_I2CM_ClearStatus(pI2C, I2C_STAT_MSTRARBLOSS); /* Master continue */ if ( status & I2C_STAT_MSTPENDING ) { pI2C->MSTCTL = I2C_MSTCTL_MSTCONTINUE; } asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_FAILED; isr_evt_set(I2C_TXRX_STATUS_FAILED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); D0_printf("I2C-ISR: Arb Loss Err!\r\n"); } else if ( status & I2C_STAT_MSTSTSTPERR ) { /* Master Start Stop Error */ /* Clear Status Flags */ Chip_I2CM_ClearStatus(pI2C, I2C_STAT_MSTSTSTPERR); /* Master continue */ if ( status & I2C_STAT_MSTPENDING ) { pI2C->MSTCTL = I2C_MSTCTL_MSTCONTINUE; } asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_FAILED; isr_evt_set(I2C_TXRX_STATUS_FAILED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); D0_printf("I2C-ISR: Start Stop Err!\r\n"); } else if ( status & I2C_STAT_MSTPENDING ) { pI2C->INTENCLR = I2C_STAT_MSTPENDING; /* Below five states are for Master mode: IDLE, TX, RX, NACK_ADDR, NAC_TX. IDLE is not under consideration for now. */ switch ( i2cmststate ) { case I2C_STAT_MSTCODE_IDLE: /* Do not send the message to the waiting task until we are done with the transaction */ if ((asyncXfer.i2c_txrx_status == I2C_TXRX_STATUS_ACTIVE) && (asyncXfer.num == 0)) { asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_PASSED; isr_evt_set(I2C_TXRX_STATUS_PASSED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); } break; /* Received data. Address plus Read was previously sent and Acknowledged by slave */ case I2C_STAT_MSTCODE_RXREADY: asyncXfer.pData[asyncXfer.byte_index++] = pI2C->MSTDAT; asyncXfer.num--; if (asyncXfer.num == 0) { //we are done with the read mstCtrl |= I2C_MSTCTL_MSTSTOP; } pI2C->MSTCTL = mstCtrl; pI2C->INTENSET = I2C_STAT_MSTPENDING; break; /* Ready to Transmit data. Address plus Write was previously sent and Acknowledged by slave */ case I2C_STAT_MSTCODE_TXREADY: if (i2c_mode == I2C_MASTER_WRITE) { if (asyncXfer.i2c_txrx_phase == 0) { pI2C->MSTDAT = asyncXfer.i2c_slave_reg; //Send register addr asyncXfer.i2c_txrx_phase = 1; } else { if (asyncXfer.num == 0) { //Done with write transaction mstCtrl |= I2C_MSTCTL_MSTSTOP; } else { pI2C->MSTDAT = asyncXfer.pData[asyncXfer.byte_index++]; asyncXfer.num--; } } pI2C->MSTCTL = mstCtrl; pI2C->INTENSET = I2C_STAT_MSTPENDING; } else { // MASTER_READ if (asyncXfer.i2c_txrx_phase == 0) { pI2C->MSTDAT = asyncXfer.i2c_slave_reg; //Send register addr asyncXfer.i2c_txrx_phase = 1; } else { //Send Re-Start with SLA+R pI2C->MSTDAT = asyncXfer.i2c_slave_addr | 1; mstCtrl |= I2C_MSTCTL_MSTSTART; } } pI2C->MSTCTL = mstCtrl; pI2C->INTENSET = I2C_STAT_MSTPENDING; break; case I2C_STAT_MSTCODE_NACKADR: //Slave NACKed address /* For now just stop the transaction */ pI2C->MSTCTL = I2C_MSTCTL_MSTSTOP | I2C_MSTCTL_MSTCONTINUE; pI2C->INTENSET = I2C_STAT_MSTPENDING; asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_FAILED; isr_evt_set(I2C_TXRX_STATUS_FAILED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); D0_printf("I2C-ISR: Slave NACKed Addr!\r\n"); break; default: case I2C_STAT_MSTCODE_NACKDAT: //Slave NACKed transmitted data /* For now just stop the transaction */ pI2C->MSTCTL = I2C_MSTCTL_MSTSTOP | I2C_MSTCTL_MSTCONTINUE; pI2C->INTENSET = I2C_STAT_MSTPENDING; asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_FAILED; isr_evt_set(I2C_TXRX_STATUS_FAILED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); D0_printf("I2C-ISR: Slave NACKed Data!\r\n"); break; } } }
/**************************************************************************************************** * @fn I2C_Driver_ISR_Handler * This function is the Interrupt Service Routine (ISR), and called when the I2C interrupt * is triggered; that is whenever a I2C event has occurred. * * @param none * * @return none * ***************************************************************************************************/ void I2C_Driver_ISR_Handler(void) { __IO uint32_t SR1Register = 0; __IO uint32_t SR2Register = 0; /* Read the I2C SR1 and SR2 status registers */ SR1Register = I2C_SENSOR_BUS->SR1; SR2Register = I2C_SENSOR_BUS->SR2; /* If SB = 1, I2C master sent a START on the bus (EV5) or ReSTART in case of receive */ if ((SR1Register & I2C_MASK_SB) == I2C_STATUS_BIT_SB) { /* Send the slave address for transmssion or for reception (according to the configured value in the write master write routine */ if (gSendMode == I2C_MASTER_RESTART) { I2C_SENSOR_BUS->DR = asyncXfer.i2c_slave_addr | 0x01; //Set read bit //After this we just wait for RXNE interrupts to read data } else { I2C_SENSOR_BUS->DR = asyncXfer.i2c_slave_addr; //I2C_msgSize--; } SR1Register = 0; SR2Register = 0; } //if ((SR2Register & I2C_MASK_MSL) == I2C_STATUS_BIT_MASTER) { /* If ADDR = 1, EV6 */ if ((SR1Register & I2C_MASK_ADDR) == I2C_STATUS_BIT_ADDR) { if (gSendMode != I2C_MASTER_RESTART) { /* Write the device register address */ I2C_SENSOR_BUS->DR = asyncXfer.i2c_slave_reg; //I2C_msgSize--; /* If this is receive mode then program start bit here so that repeat start will be generated as soon as ACK is received */ if (gSendMode == I2C_MASTER_READ) { gSendMode = I2C_MASTER_RESTART; I2C_SENSOR_BUS->CR1 |= CR1_START_Set; } /* If no further data to be sent, disable the I2C BUF IT in order to not have a TxE interrupt */ if (asyncXfer.num == 0) { I2C_SENSOR_BUS->CR2 &= (uint16_t)~I2C_IT_BUF; //This will ensure interrupt only when BTF is set (EV8_2) } } else if (asyncXfer.num == 1) { /* Clear ACK */ I2C_SENSOR_BUS->CR1 &= CR1_ACK_Reset; /* Program the STOP */ I2C_SENSOR_BUS->CR1 |= CR1_STOP_Set; } SR1Register = 0; SR2Register = 0; } /* Master transmits the remaing data: from data2 until the last one. */ /* If TXE is set (EV_8) */ if ((SR1Register & I2C_MASK_TXE_BTF) == I2C_STATUS_BIT_TXE) { if (gSendMode == I2C_MASTER_WRITE) { /* If there is still data to write */ if (asyncXfer.num != 0) { /* Write the data in DR register */ I2C_SENSOR_BUS->DR = asyncXfer.pData[asyncXfer.byte_index++]; /* Decrment the number of data to be written */ asyncXfer.num--; /* If no data remains to write, disable the BUF IT in order to not have again a TxE interrupt. */ if (asyncXfer.num == 0) { /* Disable the BUF IT */ I2C_SENSOR_BUS->CR2 &= (uint16_t)~I2C_IT_BUF; //This ensures BTF interrupt (EV8_2) } } } SR1Register = 0; SR2Register = 0; } /* If BTF and TXE are set (EV8_2), program the STOP */ if ((SR1Register & I2C_MASK_TXE_BTF) == (I2C_STATUS_BIT_TXE | I2C_STATUS_BIT_BTF)) { if (gSendMode == I2C_MASTER_WRITE) { /* Program the STOP */ I2C_SENSOR_BUS->CR1 |= CR1_STOP_Set; /* Disable EVT IT In order to not have again a BTF IT */ I2C_SENSOR_BUS->CR2 &= (uint16_t)~I2C_IT_EVT; asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_PASSED; isr_evt_set(I2C_TXRX_STATUS_PASSED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); } SR1Register = 0; SR2Register = 0; } /* If RXNE is set */ if ((SR1Register & I2C_MASK_RXNE) == I2C_STATUS_BIT_RXNE) { if (asyncXfer.num == 0) //received all expected data { /* Disable the BUF IT */ I2C_SENSOR_BUS->CR2 &= (uint16_t)~I2C_IT_BUF; /* Indicate that we are done receiving */ asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_PASSED; isr_evt_set(I2C_TXRX_STATUS_PASSED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); } else { /* Read the data register */ asyncXfer.pData[asyncXfer.byte_index++] = I2C_SENSOR_BUS->DR; /* Decrement the number of bytes to be read */ asyncXfer.num--; /* If it remains only one byte to read, disable ACK and program the STOP (EV7_1) */ if (asyncXfer.num == 1) { /* Clear ACK */ I2C_SENSOR_BUS->CR1 &= CR1_ACK_Reset; /* Program the STOP */ I2C_SENSOR_BUS->CR1 |= CR1_STOP_Set; } if (asyncXfer.num == 0) //received all expected data { /* Disable the BUF IT */ I2C_SENSOR_BUS->CR2 &= (uint16_t)~I2C_IT_BUF; /* Indicate that we are done receiving */ asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_PASSED; isr_evt_set(I2C_TXRX_STATUS_PASSED, asfTaskHandleTable[SENSOR_ACQ_TASK_ID].handle ); } } SR1Register = 0; SR2Register = 0; } } }
void USB_LP_CAN1_RX0_IRQHandler(void) { U32 istr, num, val; istr = ISTR; /* USB Reset Request */ if (istr & ISTR_RESET) { USBD_Reset(); usbd_reset_core(); #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_RESET, USBD_RTX_DevTask); } #else if (USBD_P_Reset_Event) { USBD_P_Reset_Event(); } #endif ISTR = ~ISTR_RESET; } /* USB Suspend Request */ if (istr & ISTR_SUSP) { USBD_Suspend(); #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_SUSPEND, USBD_RTX_DevTask); } #else if (USBD_P_Suspend_Event) { USBD_P_Suspend_Event(); } #endif ISTR = ~ISTR_SUSP; } /* USB Wakeup */ if (istr & ISTR_WKUP) { USBD_WakeUp(); #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_RESUME, USBD_RTX_DevTask); } #else if (USBD_P_Resume_Event) { USBD_P_Resume_Event(); } #endif ISTR = ~ISTR_WKUP; } /* Start of Frame */ if (istr & ISTR_SOF) { #ifdef __RTX if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_SOF, USBD_RTX_DevTask); } #else if (USBD_P_SOF_Event) { USBD_P_SOF_Event(); } #endif ISTR = ~ISTR_SOF; } /* PMA Over/underrun */ if (istr & ISTR_PMAOVR) { #ifdef __RTX LastError = 2; if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_ERROR, USBD_RTX_DevTask); } #else if (USBD_P_Error_Event) { USBD_P_Error_Event(2); } #endif ISTR = ~ISTR_PMAOVR; } /* Error: No Answer, CRC Error, Bit Stuff Error, Frame Format Error */ if (istr & ISTR_ERR) { #ifdef __RTX LastError = 1; if (USBD_RTX_DevTask) { isr_evt_set(USBD_EVT_ERROR, USBD_RTX_DevTask); } #else if (USBD_P_Error_Event) { USBD_P_Error_Event(1); } #endif ISTR = ~ISTR_ERR; } /* Endpoint Interrupts */ while ((istr = ISTR) & ISTR_CTR) { ISTR = ~ISTR_CTR; num = istr & ISTR_EP_ID; val = EPxREG(num); if (val & EP_CTR_RX) { EPxREG(num) = val & ~EP_CTR_RX & EP_MASK; #ifdef __RTX if (USBD_RTX_EPTask[num]) { isr_evt_set((val & EP_SETUP) ? USBD_EVT_SETUP : USBD_EVT_OUT, USBD_RTX_EPTask[num]); } #else if (USBD_P_EP[num]) { USBD_P_EP[num]((val & EP_SETUP) ? USBD_EVT_SETUP : USBD_EVT_OUT); } #endif } if (val & EP_CTR_TX) { EPxREG(num) = val & ~EP_CTR_TX & EP_MASK; #ifdef __RTX if (USBD_RTX_EPTask[num]) { isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[num]); } #else if (USBD_P_EP[num]) { USBD_P_EP[num](USBD_EVT_IN); } #endif } } }
/**************************************************************************************************** * @fn I2C_Slave_Handler * Handles the I2C Slave communication events * ***************************************************************************************************/ void I2C_Slave_Handler(I2C_TypeDef *pI2C, uint8_t irqCh) { uint32_t i2cslvstate = I2C_GetLastEvent(pI2C); uint8_t slvRxData; /* If error event - clear it */ if ((irqCh == I2C_SLAVE_BUS_ERROR_IRQ_CH) && ((i2cslvstate & 0xFF00) != 0)) { pI2C->SR1 &= 0x00FF; if ((i2cslvstate & 0xFF00) == I2C_EVENT_SLAVE_ACK_FAILURE) { /* Master NAKed - this was end of transaction when slave is transmitting */ isr_evt_set(I2C_SLAVE_XFER_DONE, asfTaskHandleTable[I2CSLAVE_COMM_TASK_ID].handle ); slave_xfer.rxCnt = 0; return; } } /* Below three states are for Slave mode: Address Received, TX, and RX. */ switch ( i2cslvstate ) { case I2C_EVENT_SLAVE_BYTE_RECEIVED: /* 00020040 */ case (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_SR1_BTF): SensorHubIntLow(); //Deassert Interrupt slvRxData = (uint8_t)I2C_ReceiveData(pI2C); slave_xfer.rxCnt++; if (slave_xfer.rxCnt == 1) //First byte received must be the register address { switch (slvRxData) { case SH_REG_IRQ_CAUSE: slave_xfer.txBuff = &SlaveRegMap.irq_cause; slave_xfer.txSz = TX_LENGTH; slave_xfer.txCnt = 0; break; case SH_REG_RD_LEN: slave_xfer.txBuff = &SlaveRegMap.read_len; slave_xfer.txSz = TX_LENGTH; slave_xfer.txCnt = 0; break; case SH_REG_ACK: //TODO -- Need to define state machine logic that would handle ACK break; case SH_REG_REQUEST: //TODO break; case SH_REG_WHO_AM_I: slave_xfer.txBuff = &SlaveRegMap.whoami; slave_xfer.txSz = TX_LENGTH; slave_xfer.txCnt = 0; break; case SH_REG_VERSION0: slave_xfer.txBuff = &SlaveRegMap.version0; slave_xfer.txSz = TX_LENGTH; slave_xfer.txCnt = 0; break; case SH_REG_VERSION1: slave_xfer.txBuff = &SlaveRegMap.version1; slave_xfer.txSz = TX_LENGTH; slave_xfer.txCnt = 0; break; case SH_REG_RD_MEM: slave_xfer.txBuff = &SlaveRegMap.rd_mem[0]; slave_xfer.txSz = SlaveRegMap.read_len; slave_xfer.txCnt = 0; break; case SH_REG_WR_MEM: default: //Not supported at this time so just NACK it for now I2C_AcknowledgeConfig(pI2C, DISABLE); break; case 0xEE: //Ack write //Ack is ignored for now break; } } else { //TODO Implement host command functions } break; case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED: /* 00060082 */ slave_xfer.rxCnt = 0; /* I2C Read Mode - no more receive */ /* Fall thru */ case I2C_EVENT_SLAVE_BYTE_TRANSMITTING: /* 00060080 */ case I2C_EVENT_SLAVE_BYTE_TRANSMITTED: case 0x00060004: //Sometimes we get this event and the driver is stuck in ISR! /* In transmit we will do not want to send data beyond the register set */ if (&slave_xfer.txBuff[slave_xfer.txCnt] < &SlaveRegMap.endMarker) { I2C_SendData(pI2C, slave_xfer.txBuff[slave_xfer.txCnt++]); } else { I2C_SendData(pI2C, I2C_OVERREACH_VAL); //This value signifies read beyond allowed range } break; case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: /* 00020002 */ /* Nothing to do except continue */ break; case I2C_EVENT_SLAVE_STOP_DETECTED: /* This is end of transaction when slave is receiving */ /* if (STOPF==1) Read SR1;Write CR1 */ I2C_GetFlagStatus(pI2C, I2C_FLAG_STOPF); I2C_Cmd(pI2C, ENABLE); isr_evt_set(I2C_SLAVE_XFER_DONE, asfTaskHandleTable[I2CSLAVE_COMM_TASK_ID].handle ); slave_xfer.rxCnt = 0; /* Re-enable ACK (in case it was disabled) */ I2C_AcknowledgeConfig(pI2C, ENABLE); break; default: break; } }