Skip to content

Commit

Permalink
task 2: queues is complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial-Suhail committed Dec 29, 2024
1 parent d15c4d8 commit ea7aa90
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions projects/task1/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <stdbool.h>
#include <stdint.h>

#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 = {
// 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;
uint32_t i = 0;
while (true) {
i %= QUEUE_LEN;
ret = queue_send(&s_queue1, &s_list[i], 0);
if (ret != STATUS_CODE_OK) {
LOG_DEBUG("write to queue failed\n");
}
++i;
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("%s\n", outstr);
} else {
LOG_DEBUG("read from queue failed\n");
}
}
}

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;
}

0 comments on commit ea7aa90

Please sign in to comment.