Skip to content

Commit

Permalink
Task 2 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
d3kanesa committed Dec 20, 2024
1 parent 2e95943 commit 05de575
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions projects/task1/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

#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 = {
.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;
}

0 comments on commit 05de575

Please sign in to comment.