void BPL_FreeMessageBufferFromIsr(unsigned char* pBuffer) { // make sure the returned pointer is in range if ( pBuffer < LOW_BUFFER_ADDRESS || pBuffer > HIGH_BUFFER_ADDRESS ) { PrintString("Free Buffer Corruption\r\n"); SetBufferPoolFailureBit(); } signed portBASE_TYPE HigherPriorityTaskWoken; // params are: queue handle, ptr to item to queue, tick to wait if full // the queue can't be full unless there is a bug, so don't wait on full if( pdTRUE != xQueueSendFromISR(QueueHandles[FREE_QINDEX], &pBuffer, &HigherPriorityTaskWoken) ) { PrintString("Unable to add buffer to Free Queue\r\n"); SetBufferPoolFailureBit(); } #if 0 /* this should never be true when freeing a message buffer */ if ( HigherPriorityTaskWoken == pdTRUE ) { portYIELD(); } #endif }
void USART1_IRQHandler(void) { static uint8_t buffer[64]; static int index = 0; uint8_t dat; if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { dat = USART_ReceiveData(USART1); USART_ClearITPendingBit(USART2, USART_IT_RXNE); if (dat == '\r' || dat == '\n') { uint8_t *msg; portBASE_TYPE xHigherPriorityTaskWoken; buffer[index++] = 0; msg = __uartDebugCreateMessage(buffer, index); if (pdTRUE == xQueueSendFromISR(__uartDebugQueue, &msg, &xHigherPriorityTaskWoken)) { if (xHigherPriorityTaskWoken) { portYIELD(); } } index = 0; } else { buffer[index++] = dat; } } }
/* send a message to a specific queue from an isr * routing requires 25 us * putting a message into a queue (in interrupt context) requires 28 us * this requires 1/2 the time of using route */ void SendMessageToQueueFromIsr(unsigned char Qindex, tMessage* pMsg) { signed portBASE_TYPE HigherPriorityTaskWoken; if ( Qindex == FREE_QINDEX ) { SendToFreeQueueIsr(pMsg); } else if ( errQUEUE_FULL == xQueueSendFromISR(QueueHandles[Qindex], pMsg, &HigherPriorityTaskWoken)) { PrintQueueNameIsFull(Qindex); SendToFreeQueueIsr(pMsg); } #if 0 /* This is not used * * we don't want to task switch when in sleep mode * The ISR will exit sleep mode and then the RTOS will run * */ if ( HigherPriorityTaskWoken == pdTRUE ) { portYIELD(); } #endif }
void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void ) { /* Clear the timer interrupt. */ IFS0bits.T1IF = 0; if( xTaskIncrementTick() != pdFALSE ) { portYIELD(); } }
/** * This function will be called when new message arrives from UART1 (when UART line idle interrupt happens) */ void UART1_MsgAvailable_Callback(void) { static signed portBASE_TYPE xHigherPriorityTaskWoken; xSemaphoreGiveFromISR( xUART1ReadSemaphore, &xHigherPriorityTaskWoken ); if( xHigherPriorityTaskWoken == pdTRUE) { portYIELD(); } }
void __attribute__((used)) EXTI13_Callback(void) { portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(sensorsDataReady, &xHigherPriorityTaskWoken); if (xHigherPriorityTaskWoken) { portYIELD(); } }
static void interruptCallback() { portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; //To unlock RadioTask xSemaphoreGiveFromISR(dataRdy, &xHigherPriorityTaskWoken); if(xHigherPriorityTaskWoken) portYIELD(); }
void __attribute__((__interrupt__, auto_psv)) _T1Interrupt( void ) { /* Clear the timer interrupt. */ IFS0bits.T1IF = 0; vTaskIncrementTick(); #if configUSE_PREEMPTION == 1 portYIELD(); #endif }
/* * Button INT0 interrupt handler */ void EINT3_IRQHandler(void){ static signed portBASE_TYPE xHigherPriorityTaskWoken; LPC_GPIOINT->IO2IntClr |= (1<<10); //kasuje flagę prerwania xSemaphoreGiveFromISR(xButton_pushed_Semaphore, &xHigherPriorityTaskWoken); if (xHigherPriorityTaskWoken == pdTRUE){ portYIELD(); } }
void sensorsBmi088Bmp388DataAvailableCallback(void) { portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; imuIntTimestamp = usecTimestamp(); xSemaphoreGiveFromISR(sensorsDataReady, &xHigherPriorityTaskWoken); if (xHigherPriorityTaskWoken) { portYIELD(); } }
static uint16_t sync_irq(void) { sync_word_time = TBR; if (state == RX) { portBASE_TYPE yield; if (xSemaphoreGiveFromISR(rx_sem, &yield) == pdTRUE) { #if configUSE_PREEMPTION if (yield) { portYIELD(); } #endif } return 1; } return 0; }
__interrupt void vCOM0_ISR( void ) { volatile unsigned char ucByte, ucStatus; portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; /* What caused the interrupt? */ ucStatus = SCI0SR1; if( ucStatus & serOVERRUN_INTERRUPT ) { /* The interrupt was caused by an overrun. Clear the error by reading the data register. */ ucByte = SCI0DRL; } if( ucStatus & serRX_INTERRUPT ) { /* The interrupt was caused by a character being received. Read the received byte. */ ucByte = SCI0DRL; /* Post the character onto the queue of received characters - noting whether or not this wakes a task. */ xQueueSendFromISR( xRxedChars, ( void * ) &ucByte, &xHigherPriorityTaskWoken ); } if( ( ucStatus & serTX_INTERRUPT ) && ( SCI0CR2_SCTIE ) ) { /* The interrupt was caused by a character being transmitted. */ if( xQueueReceiveFromISR( xCharsForTx, ( void * ) &ucByte, &xHigherPriorityTaskWoken ) == pdTRUE ) { /* Clear the SCRF bit. */ SCI0DRL = ucByte; } else { /* Disable transmit interrupt */ SCI0CR2_SCTIE = 0; } } if( xHigherPriorityTaskWoken ) { portYIELD(); } }
/// Callback when EP2_IN is active bool EP2_IN_callback() override { configASSERT(txPending); int woken = 0; if (TxHelper()) { txBuf->signal_condition_from_isr(); } if (woken) { #ifdef TARGET_LPC1768 portYIELD(); #elif defined(TARGET_LPC2368) /** @todo(balazs.racz): need to find a way to yield on ARM7. The builtin * portYIELD_FROM_ISR assumes that we have entered the ISR with context * saving, which we didn't. */ #else #error define how to yield on your CPU. #endif } return true; }
IRAM void uart0_rx_handler(void) { // TODO: Handle UART1, see reg 0x3ff20020, bit2, bit0 represents uart1 and uart0 respectively if (!UART(UART0).INT_STATUS & UART_INT_STATUS_RXFIFO_FULL) { return; } // printf(" [%08x (%d)]\n", READ_PERI_REG(UART_INT_ST(UART0)), READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)); if (UART(UART0).INT_STATUS & UART_INT_STATUS_RXFIFO_FULL) { UART(UART0).INT_CLEAR = UART_INT_CLEAR_RXFIFO_FULL; if (UART(UART0).STATUS & (UART_STATUS_RXFIFO_COUNT_M << UART_STATUS_RXFIFO_COUNT_S)) { long int xHigherPriorityTaskWoken; _xt_isr_mask(1 << INUM_UART); _xt_clear_ints(1<<INUM_UART); xSemaphoreGiveFromISR(uart0_sem, &xHigherPriorityTaskWoken); if(xHigherPriorityTaskWoken) { portYIELD(); } } } else { printf("Error: unexpected uart irq, INT_STATUS 0x%02x\n", UART(UART0).INT_STATUS); } }
/* This is too slow to use */ unsigned char* BPL_AllocMessageBufferFromISR(void) { unsigned char * pBuffer = NULL; signed portBASE_TYPE HigherPriorityTaskWoken; // params are: queue handle, ptr to the msg buffer, ticks to wait if( pdTRUE != xQueueReceiveFromISR(QueueHandles[FREE_QINDEX], &pBuffer, &HigherPriorityTaskWoken )) { PrintString2("@ Alloc Buf frm Isr", CR); SetBufferPoolFailureBit(); } if ( HigherPriorityTaskWoken == pdTRUE ) { portYIELD(); } return pBuffer; }
/** * XBH server thread */ static void xbh_srv_task(void *arg){/*{{{*/ struct sockaddr_in listen_addr; struct sockaddr_in clnt_addr; int srv_sock = -1, clnt_sock = -1; socklen_t clnt_addr_sz; int retval; xbhsrv_state state = XBHSRV_ACCEPT; //Setup socket and listen/*{{{*/ memset(&listen_addr, 0, sizeof(listen_addr)); listen_addr.sin_family = AF_INET; listen_addr.sin_port = htons(TCP_XBH_PORT); listen_addr.sin_addr.s_addr = htonl(INADDR_ANY); srv_sock = socket(PF_INET,SOCK_STREAM,0); LOOP_ERRMSG(srv_sock < 0, "Could not create socket\n"); retval = bind(srv_sock, (struct sockaddr *)&listen_addr, (socklen_t)sizeof(listen_addr)); LOOP_ERRMSG(retval != 0, "Could not bind socket to address\n"); retval = listen(srv_sock, 0); LOOP_ERRMSG(retval != 0, "Could not listen on socket\n"); /*}}}*/ while(true){ //If socket closed, go back to accepting another connection if(send(clnt_sock, NULL, 0, 0) < 0){ state = XBHSRV_ACCEPT; } switch(state){ case XBHSRV_ACCEPT: clnt_addr_sz = sizeof(clnt_addr); clnt_sock = accept(srv_sock, (struct sockaddr *)&clnt_addr, &clnt_addr_sz); LOOP_ERRMSG(clnt_sock < 0, "Failed to accept connection\n"); uart_printf("New connection from %hd.%hd.%hd.%hd, port = %d\n", ((uint8_t *)&clnt_addr.sin_addr.s_addr)[0], ((uint8_t *)&clnt_addr.sin_addr.s_addr)[1], ((uint8_t *)&clnt_addr.sin_addr.s_addr)[2], ((uint8_t *)&clnt_addr.sin_addr.s_addr)[3], clnt_addr.sin_port); state = XBHSRV_CMD; break; case XBHSRV_CMD: { ssize_t len = recv_cmd(clnt_sock, xbh_cmd, XBH_PACKET_SIZE_MAX); if (len < 0){ goto cmd_err; } #if 0 // Reset if reset cmd received if(!memcmp(xbh_cmd, XBH_CMD[XBH_CMD_rsr], len)){ xbh_reset(); } #endif struct xbh_srv_to_hndlr_msg tx_msg; tx_msg.cmd_buf = xbh_cmd; tx_msg.len = len; xQueueSend(xbh_srv_to_hndlr_q_handle, &tx_msg, portMAX_DELAY); portYIELD(); state = XBHSRV_WAIT; break; cmd_err: close(clnt_sock); state = XBHSRV_ACCEPT; break; } case XBHSRV_WAIT: { static TickType_t last_sent = 0; // Check for xbh handle completion and issue reply to PC struct xbh_hndlr_to_srv_msg rx_msg; if(xQueueReceive(xbh_hndlr_to_srv_q_handle, &rx_msg, 1) == pdTRUE){ if(rx_msg.type == XBH_HNDLR_DONE){ size_t len = rx_msg.len; // Prepend length to buffer len2hex(len, reply_buf); len += CMDLEN_SZ; sendall(clnt_sock, reply_buf, len, 0); state = XBHSRV_CMD; } last_sent = xTaskGetTickCount(); //If last keepalive greater than 1k ticks ago, send //keepalive }else if (xTaskGetTickCount() - last_sent > 1000){ memcpy(wait_buf+CMDLEN_SZ, XBH_CMD[XBH_CMD_kao], XBH_COMMAND_LEN); len2hex(XBH_COMMAND_LEN, wait_buf); int retval = sendall(clnt_sock, wait_buf, XBH_COMMAND_LEN+CMDLEN_SZ, 0); if (retval < 0) xbh_reset(); last_sent = xTaskGetTickCount(); } // Unneeded, just reset if connection terminated. Ugly, but should work // If enabling, add GEN(rsr) to XBH_CMD #if 0 //Check for RST from pc struct timeval tv; fd_set read_fds; int nready = 0; memset(&tv, 0, sizeof(tv)); FD_SET(clnt_sock, &read_fds); nready = select(clnt_sock+1, &read_fds, NULL, NULL, &tv); if(nready < 0){ goto wait_err; } if(nready == 1){ ssize_t len = recv_cmd(clnt_sock, wait_buf, XBH_WAITBUF_MAX); if(len < 0){ goto wait_err; }else if(!memcmp(wait_buf, XBH_CMD[XBH_CMD_rsr], len)){ xbh_reset(); } } break; wait_err: close(clnt_sock); state = XBHSRV_ACCEPT; break; #endif } } #if DEBUG_STACK DEBUG_OUT("Stack Usage: %s: %d\n", __PRETTY_FUNCTION__, uxTaskGetStackHighWaterMark(NULL)); #endif } }/*}}}*/