-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |