add ring queue/message queue/mail queue, binary heap/priority queue/priority message queue/priority mail queue
1. remove the old msg queue and queue: i. msg queue is not a common and reusable/flexible component(need user to config the msg pool size and this componet can only be used by tos_queue) ii. tos_queue can only deliver the pointer message(cannot do a memory buffer deliver) 2. add ring queue(tos_ring_q) componet rinq queue can be reused by tos_chr_fifi/tos_msg_q/tos_mail_q as the foundational data container 3. add message queue(tos_msg_q) a little like the old queue mechanism, supply the capability to deliver a pointer message 4. add mail queue(tos_mail_q) supply the capability to deliver a memory buffer 5. add binary heap(tos_bin_heap) the basement componet to implement priority queue 6. add priority queue(tos_prio_q) can be reused by the priority message/mail queue as the foundational data container. 7. add priority message queue(tos_prio_msg_q) a message(pointer) deliver mechanism, supply the capability of delivering the message with priority(message with higher priority comes faster to the pender than with lower) 8. add priority mail queue(tos_prio_mail_q) a mail(memory buffer) deliver mechanism, supply the capability of delivering the mail with priority(mail with higher priority comes faster to the pender than with lower)
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
#include "tos.h"
|
||||
#include "mcu_init.h"
|
||||
|
||||
#define STK_SIZE_TASK_DEMO 512
|
||||
#define STK_SIZE_TASK_DEMO 512
|
||||
|
||||
#define PRIO_TASK_DEMO 4
|
||||
|
||||
k_stack_t stack_task_demo[STK_SIZE_TASK_DEMO];
|
||||
|
||||
k_stack_t stack_task_demo[STK_SIZE_TASK_DEMO];
|
||||
|
||||
k_task_t task_demo;
|
||||
|
||||
#define FIFO_BUFFER_SIZE 5
|
||||
uint8_t fifo_buffer[FIFO_BUFFER_SIZE];
|
||||
|
||||
k_fifo_t fifo;
|
||||
k_chr_fifo_t fifo;
|
||||
|
||||
extern void entry_task_demo(void *arg);
|
||||
|
||||
@@ -24,30 +24,30 @@ void char_push(void)
|
||||
|
||||
for (i = 0; i < FIFO_BUFFER_SIZE; ++i) {
|
||||
printf("char pushed: %c\n", 'a' + i);
|
||||
err = tos_fifo_push(&fifo, 'a' + i);
|
||||
err = tos_chr_fifo_push(&fifo, 'a' + i);
|
||||
if (err != K_ERR_NONE) {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
}
|
||||
|
||||
err = tos_fifo_push(&fifo, 'z');
|
||||
err = tos_chr_fifo_push(&fifo, 'z');
|
||||
if (err == K_ERR_FIFO_FULL) {
|
||||
printf("fifo is full: %s\n", tos_fifo_is_full(&fifo) ? "TRUE" : "FALSE");
|
||||
printf("fifo is full: %s\n", tos_chr_fifo_is_full(&fifo) ? "TRUE" : "FALSE");
|
||||
} else {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
|
||||
for (i = 0; i < FIFO_BUFFER_SIZE; ++i) {
|
||||
err = tos_fifo_pop(&fifo, &data);
|
||||
err = tos_chr_fifo_pop(&fifo, &data);
|
||||
if (err == K_ERR_NONE) {
|
||||
printf("%d pop: %c\n", i, data);
|
||||
} else {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
}
|
||||
err = tos_fifo_pop(&fifo, &data);
|
||||
err = tos_chr_fifo_pop(&fifo, &data);
|
||||
if (err == K_ERR_FIFO_EMPTY) {
|
||||
printf("fifo is empty: %s\n", tos_fifo_is_empty(&fifo) ? "TRUE" : "FALSE");
|
||||
printf("fifo is empty: %s\n", tos_chr_fifo_is_empty(&fifo) ? "TRUE" : "FALSE");
|
||||
} else {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
@@ -60,19 +60,19 @@ void stream_push(void)
|
||||
uint8_t stream_dummy[1] = { 'z' };
|
||||
uint8_t stream_pop[FIFO_BUFFER_SIZE];
|
||||
|
||||
count = tos_fifo_push_stream(&fifo, &stream[0], FIFO_BUFFER_SIZE);
|
||||
count = tos_chr_fifo_push_stream(&fifo, &stream[0], FIFO_BUFFER_SIZE);
|
||||
if (count != FIFO_BUFFER_SIZE) {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
|
||||
count = tos_fifo_push_stream(&fifo, &stream_dummy[0], 1);
|
||||
count = tos_chr_fifo_push_stream(&fifo, &stream_dummy[0], 1);
|
||||
if (count == 0) {
|
||||
printf("fifo is full: %s\n", tos_fifo_is_full(&fifo) ? "TRUE" : "FALSE");
|
||||
printf("fifo is full: %s\n", tos_chr_fifo_is_full(&fifo) ? "TRUE" : "FALSE");
|
||||
} else {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
|
||||
count = tos_fifo_pop_stream(&fifo, &stream_pop[0], FIFO_BUFFER_SIZE);
|
||||
count = tos_chr_fifo_pop_stream(&fifo, &stream_pop[0], FIFO_BUFFER_SIZE);
|
||||
if (count == FIFO_BUFFER_SIZE) {
|
||||
printf("stream popped:\n");
|
||||
for (i = 0; i < FIFO_BUFFER_SIZE; ++i) {
|
||||
@@ -83,9 +83,9 @@ void stream_push(void)
|
||||
printf("should never happen\n");
|
||||
}
|
||||
|
||||
count = tos_fifo_pop_stream(&fifo, &stream_pop[0], 1);
|
||||
count = tos_chr_fifo_pop_stream(&fifo, &stream_pop[0], 1);
|
||||
if (count == 0) {
|
||||
printf("fifo is empty: %s\n", tos_fifo_is_empty(&fifo) ? "TRUE" : "FALSE");
|
||||
printf("fifo is empty: %s\n", tos_chr_fifo_is_empty(&fifo) ? "TRUE" : "FALSE");
|
||||
} else {
|
||||
printf("should never happen\n");
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void stream_push(void)
|
||||
|
||||
void entry_task_demo(void *arg)
|
||||
{
|
||||
tos_fifo_create(&fifo, &fifo_buffer[0], FIFO_BUFFER_SIZE);
|
||||
tos_chr_fifo_create(&fifo, &fifo_buffer[0], FIFO_BUFFER_SIZE);
|
||||
|
||||
printf("fifo, dealing with char\n");
|
||||
char_push();
|
||||
@@ -105,10 +105,10 @@ void entry_task_demo(void *arg)
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
tos_knl_init();
|
||||
tos_knl_init();
|
||||
(void)tos_task_create(&task_demo, "demo1", entry_task_demo, NULL,
|
||||
PRIO_TASK_DEMO, stack_task_demo, STK_SIZE_TASK_DEMO,
|
||||
0);
|
||||
0);
|
||||
tos_knl_start();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user