/* the UART task - it enables the UART interrupt and then suspend the task until a message has arrived with UART */
void uart_task()
{
int Status;
//UART 1 init
Status = Init_uart_1(&InterruptController, &UartPs, UART_DEVICE_ID_WEAP,
UART_INT_IRQ_ID_WEAP);
if (Status != XST_SUCCESS)
{
return XST_FAILURE;
}
while(1)
{
vTaskSuspend(NULL); // suspend itself
printf("received uart message\r\n");
}
}
/* the UART interrupt handler - it counts the bytes received by the UART and raises a flag when a message with 10 bytes long has received */
void Handler_uart_1(void *CallBackRef, u32 Event, unsigned int EventData)
{
XUartPs_Recv(&UartPs, &RecvByte_uart_1, 1); // receive data from uart into RecvByte_uart_1
// push the received byte into cyclic buffer
CB_Push_byte(CycleBuffer, CYCLE_BUFFER_SIZE, &CB_count, &CB_tail, RecvByte_uart_1);
// Later on, I will use the cyclic buffer in the uart_task to inspect the received message.
if (RecvByte_uart_1 == 0x5dU) // check if it is the beginning of a message
{
hadler_msg_counter = 0;
}
hadler_msg_counter++;
if (hadler_msg_counter == 10) // if finished reading a message
{
BaseType_t checkIfYieldRequired;
checkIfYieldRequired = xTaskResumeFromISR(myIntTaskHandle);
portYIELD_FROM_ISR(checkIfYieldRequired);
}
}
/* the main task*/
void my_main_task(void * p)
{
int count = 0;
while(1)
{
printf("hello world! : %d\r\n", count++);
vTaskDelay(1000 * configTICK_RATE_HZ / 1000);
}
}
int main( void )
{
xTaskCreate(my_main_task, "main_task", 200, (void*) 0, tskIDLE_PRIORITY, &myTaskHandle);
xTaskCreate(uart_task, "UartListener", 200, (void*) 0, tskIDLE_PRIORITY, &myIntTaskHandle);
vTaskStartScheduler();
while(1);
return 0;
}