From 05de575c8586cc92bf37c624d64896c10a208ed8 Mon Sep 17 00:00:00 2001 From: Darun Date: Fri, 20 Dec 2024 00:55:14 +0000 Subject: [PATCH] Task 2 complete --- projects/task1/src/main.c | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 projects/task1/src/main.c diff --git a/projects/task1/src/main.c b/projects/task1/src/main.c new file mode 100644 index 00000000..1bccbe13 --- /dev/null +++ b/projects/task1/src/main.c @@ -0,0 +1,82 @@ + +#include +#include +#include "FreeRTOS.h" +#include "tasks.h" +#include "queues.h" +#include "status.h" +#include "delay.h" +#include "log.h" +#include "misc.h" +#define ITEM_SZ 6 +#define QUEUE_LEN 5 +#define BUF_SIZE (QUEUE_LEN * ITEM_SZ) +static const char s_list[QUEUE_LEN][ITEM_SZ] = { + "Item1", + "Item2", + "Item3", + "Item4", + "Item5" +}; +// Task static entities +static uint8_t s_queue1_buf[BUF_SIZE]; +static Queue s_queue1 = { + .num_items = QUEUE_LEN, + .item_size = ITEM_SZ, + .storage_buf = s_queue1_buf +}; + + +TASK(task1, TASK_STACK_512) { + + LOG_DEBUG("Task 1 initialized!\n"); + StatusCode ret; + int i = 0; + + while (true) { + + StatusCode ret = queue_send(&s_queue1, &s_list[i%5], 0); + + if (ret != STATUS_CODE_OK) { + LOG_DEBUG("Write to Queue Failed \n"); + } else{ + i+=1; + } + + delay_ms(100); + + } +} +TASK(task2, TASK_STACK_512) { + + LOG_DEBUG("Task 2 initialized!\n"); + const char outstr[ITEM_SZ]; + StatusCode ret; + + while (true) { + + ret = queue_receive(&s_queue1, outstr, 100); + + if (ret == STATUS_CODE_OK) { + LOG_DEBUG("Received: %s\n", outstr); + } else { + LOG_DEBUG("Read from Queue Failed\n"); + } + } + +} + +int main(void) { + + log_init(); + // Initialize queues here + queue_init(&s_queue1); + + tasks_init(); + tasks_init_task(task1, TASK_PRIORITY(2), NULL); + tasks_init_task(task2, TASK_PRIORITY(2), NULL); + + LOG_DEBUG("Program start...\n"); + tasks_start(); + return 0; +} \ No newline at end of file