/** * Initializes all receive related tasks and synchronization primitives. * This function must be called before anything is attempted to be received! * * @param uart_nr - number of the UART * * @return pdPASS if initialization is successful, pdFAIL otherwise */ int16_t recvInit(uint8_t uart_nr) { /* Obtain the UART's IRQ from BSP */ const uint8_t uartIrqs[BSP_NR_UARTS] = BSP_UART_IRQS; const uint8_t irq = ( uart_nr<BSP_NR_UARTS ? uartIrqs[uart_nr] : (uint8_t) -1 ); uint16_t i; for ( i=0; i<RECV_BUFFER_SIZE; ++i ) { memset((void*) buf[i], '\0', RECV_TOTAL_BUFFER_LEN); strcpy(buf[i], MSG_TEXT); } bufCntr = 0; bufPos = 0; /* Check if UART number is valid */ if ( uart_nr >= BSP_NR_UARTS ) { return pdFAIL; } recvUartNr = uart_nr; /* Create and assert a queue for received characters */ recvQueue = xQueueCreate(RECV_QUEUE_SIZE, sizeof(portCHAR)); if ( 0 == recvQueue ) { return pdFAIL; } /* Attempt to register UART's IRQ on VIC */ if ( pic_registerIrq(irq, &recvIsrHandler, 50) < 0 ) { return pdFAIL; } /* Enable the UART's IRQ on VIC */ pic_enableInterrupt(irq); /* Configure the UART to receive data and trigger interrupts on receive */ uart_enableRx(recvUartNr); uart_enableRxInterrupt(recvUartNr); return pdPASS; }
/* * Setup the timer 0 and the VIC */ static void prvSetupTimerInterrupt( void ) { /* * If timer settings are inappropriate (portTICK_TIMER>=BSP_NR_TIMERS), this * file will not compile. Thus an invalid timer's IRQ (something read from * a "random" location) will be prevented. */ #if portTICK_TIMER >= BSP_NR_TIMERS #error Invalid timer selected! #endif uint32_t ulCompareMatch; const uint8_t irqs[BSP_NR_TIMERS] = BSP_TIMER_IRQS; const uint8_t irq = irqs[portTICK_TIMER]; extern void vTickISR(void); /* Calculate the match value required for our desired tick rate. */ ulCompareMatch = ( 0 != configTICK_RATE_HZ ? configCPU_CLOCK_HZ / configTICK_RATE_HZ : (uint32_t) (-1) ); /* Counter's load should always be greater than 0 */ if ( 0 == ulCompareMatch ) { ulCompareMatch = 1; } /* Configure the timer 0, counter 0 */ timer_init(portTICK_TIMER, portTICK_TIMER_COUNTER); timer_setLoad(portTICK_TIMER, portTICK_TIMER_COUNTER, ulCompareMatch); timer_enableInterrupt(portTICK_TIMER, portTICK_TIMER_COUNTER); /* Configure the VIC to service IRQ4 (triggered by the timer) properly */ pic_registerIrq(irq, &vTickISR, PIC_MAX_PRIORITY); /* Enable servicing of IRQ4 */ pic_enableInterrupt(irq); /* * Start the timer. * Note that IRQ mode will only be enabled when the first FreeRTOS task starts. */ timer_start(portTICK_TIMER, portTICK_TIMER_COUNTER); }