// Function used to print a string in the terminal by other tasks void echo (char *string, char Terminalbackup) { INT8U backup_cnt = 0; INT8U i = 0; char backup[(CONSOLE_BUFFER_SIZE/2)]; char *command_start = "echo "; char *command_end = "\n\r"; if (Terminalbackup == TRUE) { backup_cnt = TerminalBackup(&backup[0]); } SetSilentMode(TRUE); while (*command_start) { if (OSQueuePost(USB, *command_start++) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSCleanQueue(USB); } } while (*string) { if (OSQueuePost(USB, *string++) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSCleanQueue(USB); } } while (*command_end) { if (OSQueuePost(USB, *command_end++) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSCleanQueue(USB); } } if (Terminalbackup == TRUE) { for(i=0;i<backup_cnt;i++) { if (OSQueuePost(USB, backup[i]) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSCleanQueue(USB); } } } }
interrupt void serial_rx(void) #endif { // ************************ // Entrada de interrupção // ************************ OS_INT_ENTER(); // Tratamento da interrupção (void)UART_STAT1; /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */ (void)UART_CTRL3; /* Leitura do registrador SCI1C3 para limpar o bit de paridade */ receive_byte = UART_DATA; /* Leitura dos dados recebidos */ #if (NESTING_INT == 1) OS_ENABLE_NESTING(); #endif if (OSQueuePost(Serial, receive_byte) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSCleanQueue(Serial); } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT(); // ************************ }
interrupt void uart2_rx(void) #endif { // ************************ // Entrada de interrupção // ************************ 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 OSCleanQueue(Serial2); } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT(); // ************************ }
unsigned long USART1IntHandler(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgParam, void *pvMsgData) { char receive_byte; if ((ulEvent & UART_EVENT_RX) == UART_EVENT_RX) { receive_byte = xHWREGB(UART1_BASE + UART_012_D); if (OSQueuePost(Serial1, receive_byte) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer //OSCleanQueue(Serial0); } } if ((ulEvent & UART_EVENT_TC) == UART_EVENT_TC) { if ((xHWREGB(UART1_BASE + UART_012_C2) & UART_EVENT_TC) == UART_EVENT_TC) { UARTIntDisable(UART1_BASE, UART_INT_TC); (void)OSSemPost(SerialTX1); } } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT_EXT(); // ************************ return 0; }
void Keyboard_Handler(void) { // task setup INT16U ADSample = 0; INT8U Key = NO_KEY; // Initialize ACM keyboard for channel 1 ACM_Keyb_Setup(Enable, Enable, Rising, ACM_CHANNEL1); if (OSSemCreate(0, &sKeyboard) != ALLOC_EVENT_OK) { while (1){}; }; if (OSQueueCreate(&KeyboardBuffer, 64, &qKeyboard) != ALLOC_EVENT_OK) { while (1){}; }; // task main loop for (;;) { // Wait for a keyboard interrupt OSSemPend(sKeyboard, 0); DelayTask(50); // Converts the value of AD to discover the pressed key UserEnterCritical(); ADSample = ADConvert(KEYB_CHANNEL); UserExitCritical(); UserEnterCritical(); ADSample += ADConvert(KEYB_CHANNEL); UserExitCritical(); ADSample = ADSample >> 1; // Find out which key was pressed Key = FindKey(ADSample); // Copy the key to the keyboard buffer if (Key != NO_KEY) { if (OSQueuePost(qKeyboard, Key) == BUFFER_UNDERRUN) { // Buffer overflow OSCleanQueue(qKeyboard); } } // Enable interrupt to the next key detection DelayTask(200); ACMEnable(); } }
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); } }
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { uint32_t ui32Status; char data; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART0_BASE, true); UARTIntClear(UART0_BASE, ui32Status); if ((ui32Status&UART_INT_RX) == UART_INT_RX) { // // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART and write it back to the UART. // data = (char)ROM_UARTCharGetNonBlocking(UART0_BASE); OSQueuePost(qUART, data); } } if ((ui32Status&UART_INT_TX) == UART_INT_TX) { ROM_UARTIntDisable(UART0_BASE, UART_INT_TX); // Call the keyboard analysis task OSSemPost(sUART); } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT_EXT(); // ************************ }
void uart1_rx(void) { // ************************ // Interrupt Entry // ************************ #if __GNUC__ OS_SAVE_ISR(); #endif OS_INT_ENTER(); // Tratamento da interrupção (void) SCI1S1; /* Leitura do registrador SCIxS1 para analisar o estado da transmissão */ (void) SCI1C3; /* Leitura do registrador SCIxC3 para limpar o bit de paridade */ receive_byte1 = SCI1D; /* Leitura dos dados recebidos */ #if (NESTING_INT == 1) OS_ENABLE_NESTING(); #endif if (OSQueuePost(Serial1, receive_byte1) == BUFFER_UNDERRUN) { // Problema: Estouro de buffer OSQueueClean(Serial1); } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT(); // ************************ #if __GNUC__ OS_RESTORE_ISR(); #endif }