You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
842 B
44 lines
842 B
|
1 month ago
|
#include "app_scheduler.h"
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
#define APP_JOB_QUEUE_SIZE 8
|
||
|
|
|
||
|
|
static app_job_t g_queue[APP_JOB_QUEUE_SIZE];
|
||
|
|
static uint8_t g_head;
|
||
|
|
static uint8_t g_tail;
|
||
|
|
static uint8_t g_count;
|
||
|
|
|
||
|
|
void app_scheduler_init(void)
|
||
|
|
{
|
||
|
|
g_head = 0;
|
||
|
|
g_tail = 0;
|
||
|
|
g_count = 0;
|
||
|
|
memset(g_queue, 0, sizeof(g_queue));
|
||
|
|
}
|
||
|
|
|
||
|
|
int app_scheduler_push(const app_job_t *job)
|
||
|
|
{
|
||
|
|
if (!job) return 0;
|
||
|
|
if (g_count >= APP_JOB_QUEUE_SIZE) return 0;
|
||
|
|
|
||
|
|
g_queue[g_tail] = *job;
|
||
|
|
g_tail = (uint8_t)((g_tail + 1U) % APP_JOB_QUEUE_SIZE);
|
||
|
|
g_count++;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
int app_scheduler_pop(app_job_t *job)
|
||
|
|
{
|
||
|
|
if (!job) return 0;
|
||
|
|
if (g_count == 0) return 0;
|
||
|
|
|
||
|
|
*job = g_queue[g_head];
|
||
|
|
g_head = (uint8_t)((g_head + 1U) % APP_JOB_QUEUE_SIZE);
|
||
|
|
g_count--;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
int app_scheduler_is_empty(void)
|
||
|
|
{
|
||
|
|
return (g_count == 0U);
|
||
|
|
}
|