unsigned long USART0IntHandler(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgParam, void *pvMsgData) { char receive_byte; if (Contiki_Sem != NULL){ if ((ulEvent & UART_EVENT_RX) == UART_EVENT_RX) { receive_byte = xHWREGB(UART0_BASE + UART_012_D); if (slip_input_byte(receive_byte) == 1) OSSemPost(Contiki_Sem); buffer_rcvd[buffer_rcvd_i++]=receive_byte; #if 0 if (OSQueuePost(Serial0, receive_byte) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSQueueClean(Serial0); } #endif } if ((ulEvent & UART_EVENT_TC) == UART_EVENT_TC) { if ((xHWREGB(UART0_BASE + UART_012_C2) & UART_EVENT_TC) == UART_EVENT_TC) { UARTIntDisable(UART0_BASE, UART_INT_TC); (void)OSSemPost(SerialTX0); } } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT_EXT(); // ************************ }else{ if ((ulEvent & UART_EVENT_RX) == UART_EVENT_RX) { receive_byte = xHWREGB(UART0_BASE + UART_012_D); } if ((ulEvent & UART_EVENT_TC) == UART_EVENT_TC) { if ((xHWREGB(UART0_BASE + UART_012_C2) & UART_EVENT_TC) == UART_EVENT_TC) { UARTIntDisable(UART0_BASE, UART_INT_TC); } } } }
void Keyboard_Handler(void) { // task setup INT8U key = NO_KEY; INT32U read = 0; ButtonsInit(); if (OSSemCreate(0,&sKeyboard) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! while(1){}; }; if (OSQueueCreate(64, &qKeyboard) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! while(1){}; }; // task main loop for (;;) { // Wait for a keyboard interrupt OSSemPend (sKeyboard,0); DelayTask(50); read = GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); // Find out which key was pressed key = (INT8U)read; // Copy the key to the keyboard buffer if(key != NO_KEY) { if (OSQueuePost(qKeyboard, key) == BUFFER_UNDERRUN) { // Buffer overflow OSQueueClean(qKeyboard); } } key = NO_KEY; DelayTask(200); // Enable interrupt to the next key detection GPIOIntEnable(BUTTONS_GPIO_BASE, ALL_BUTTONS); } }
void uart2_rx(void) { // ************************ // Interrupt Entry // ************************ #if __GNUC__ OS_SAVE_ISR(); #endif OS_INT_ENTER(); // Tratamento da interrupção (void) SCI2S1; /* Leitura do registrador SCIxS1 para analisar o estado da transmissão */ (void) SCI2C3; /* Leitura do registrador SCIxC3 para limpar o bit de paridade */ receive_byte2 = SCI2D; /* Leitura dos dados recebidos */ #if (NESTING_INT == 1) OS_ENABLE_NESTING(); #endif if (OSQueuePost(Serial2, receive_byte2) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSQueueClean(Serial2); } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT(); // ************************ #if __GNUC__ OS_RESTORE_ISR(); #endif }