From 9654c6324d167033f1bd4fda802e5b30aeb57e59 Mon Sep 17 00:00:00 2001 From: Vishal Prakash Date: Sat, 7 Sep 2024 15:12:24 +0000 Subject: [PATCH 1/4] Complete task 1 --- projects/task1/src/main.c | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 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..27ecc31b --- /dev/null +++ b/projects/task1/src/main.c @@ -0,0 +1,50 @@ +#include +#include + +#include "FreeRTOS.h" +#include "delay.h" +#include "gpio.h" +#include "log.h" +#include "misc.h" +#include "tasks.h" + +// Non blocking delay. Simply consumes cpu cycles until a given time has passed +static void prv_delay(const TickType_t delay_ms) { + TickType_t curr_tick = xTaskGetTickCount(); + while (xTaskGetTickCount() - curr_tick < pdMS_TO_TICKS(delay_ms)) { + } +} + +TASK(task1, TASK_STACK_512) { + int counter1 = 0; + while (true) { + // Your code here + LOG_DEBUG("Task 1: %d\n", counter1); + counter1++; + prv_delay(1000); + } +} + +TASK(task2, TASK_STACK_512) { + int counter2 = 0; + while (true) { + // Your code here + LOG_DEBUG("Task 2: %d\n", counter2); + counter2++; + prv_delay(1000); + } +} + +int main(void) { + log_init(); + tasks_init(); + // Create tasks here + tasks_init_task(task1, TASK_PRIORITY(1), NULL); + tasks_init_task(task2, TASK_PRIORITY(1), NULL); + + LOG_DEBUG("Program start...\n"); + // Start the scheduler + tasks_start(); + + return 0; +} From 2fe87807c0240257dd9ae01a2f608e8a2dafe86b Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 10 Sep 2024 16:33:36 +0000 Subject: [PATCH 2/4] test commmit --- projects/task1/README.md | 15 +++++++++++++++ projects/task1/config.json | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 projects/task1/README.md create mode 100644 projects/task1/config.json diff --git a/projects/task1/README.md b/projects/task1/README.md new file mode 100644 index 00000000..da215757 --- /dev/null +++ b/projects/task1/README.md @@ -0,0 +1,15 @@ + +# task1 \ No newline at end of file diff --git a/projects/task1/config.json b/projects/task1/config.json new file mode 100644 index 00000000..4019f474 --- /dev/null +++ b/projects/task1/config.json @@ -0,0 +1,6 @@ +{ + "libs": [ + "FreeRTOS", + "ms-common" + ] +} \ No newline at end of file From 87706aec0dc18ab3d18a824b893db04deebf90fe Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 10 Sep 2024 21:54:21 +0000 Subject: [PATCH 3/4] Vishal Prakash tasks --- projects/task1/src/{main.c => tasks/tasks.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename projects/task1/src/{main.c => tasks/tasks.c} (100%) diff --git a/projects/task1/src/main.c b/projects/task1/src/tasks/tasks.c similarity index 100% rename from projects/task1/src/main.c rename to projects/task1/src/tasks/tasks.c From 2a6c4ae804bb3ddd2a6f4f7af0584484fb88f5e7 Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 10 Sep 2024 23:01:58 +0000 Subject: [PATCH 4/4] Task 2 Complete --- projects/task2/src/queues.c | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 projects/task2/src/queues.c diff --git a/projects/task2/src/queues.c b/projects/task2/src/queues.c new file mode 100644 index 00000000..36a91b00 --- /dev/null +++ b/projects/task2/src/queues.c @@ -0,0 +1,69 @@ +#include "queues.h" + +#include +#include + +#include "FreeRTOS.h" +#include "delay.h" +#include "log.h" +#include "misc.h" +#include "status.h" +#include "tasks.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 = { + // Add parameters + .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; + const char *current_string; + while (true) { + // Your code goes here + for (int i = 0; i < QUEUE_LEN; i++) { + current_string = s_list[i]; + queue_send(&s_queue1, current_string, 1000); + delay_ms(50); + } + } +} + +TASK(task2, TASK_STACK_512) { + LOG_DEBUG("Task 2 initialized!\n"); + const char outstr[ITEM_SZ]; + StatusCode ret; + while (true) { + // Your code goes here + for (int i = 0; i < QUEUE_LEN; i++) { + queue_receive(&s_queue1, outstr, 1000); + delay_ms(100); + LOG_DEBUG("%s", outstr); + } + } +} + +int main(void) { + log_init(); + tasks_init(); + // Initialize queues here + queue_init(&s_queue1); + + 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; +}