Commit cbaee57f authored by Rémy Huet's avatar Rémy Huet 💻
Browse files

Exemple with patfinder code

parent f61df4b1
......@@ -136,6 +136,7 @@ void task_end() {
// Current task is the first task of heap
k_heap_pop();
yield();
_irq_enable();
}
uint16_t create_task(TASK_ADDR addr, uint32_t period) {
......@@ -239,6 +240,7 @@ void delay_process(void) {
if(--contexts[i].delay == 0) {
// If the task is already in EXEC we don't respect rate monotonic constraints
if(contexts[i].status == EXEC) {
printf("%d is already EXEC\n", i);
kernel_exit("Scheduling error : attemptend to wake an allready awaken task");
} else if (contexts[i].status == SUSP) { // If task is susp : awake it
// Set status to exec
......
......@@ -9,6 +9,9 @@
#include "kernel.h"
#include "macros.h"
#include "serial.h"
#include "sem.h"
static uint8_t sem;
/**
* @brief Busy wait in a task
......@@ -23,33 +26,109 @@ void busy_wait(uint32_t delay) {
continue;
}
void task_b() {
printf("B : Hello from task B\n");
for (int i = 0; i < 1000000; i++) {
printf("B %d, tick %d\n", i, get_tick_count());
busy_wait(25);
sleep();
}
kernel_exit("graceful exit from task B");
void get_ressource() {
s_wait(sem);
}
void release_ressource() {
s_signal(sem);
}
void ordo_task() {
puts("Starting task ordo");
while (1) {
sleep();
puts("Doing ordo");
busy_wait(25);
puts("Ending ordo");
}
}
void distrib_task() {
puts("Starting distrib task");
while (1) {
sleep();
get_ressource();
puts("Doing distrib");
busy_wait(25);
puts("Ending distrib");
release_ressource();
}
}
void task_a() {
printf("A : Hello from task A\n");
activate_task(create_task(task_b, 250));
void pilotage_task() {
puts("Starting pilotage task");
while (1) {
sleep();
get_ressource();
puts("Doing pilotage");
busy_wait(25);
puts("Ending pilotage");
release_ressource();
}
}
printf("A : Launched task B\n");
void radio_task() {
puts("Starting radio task");
while (1) {
sleep();
puts("Doing radio");
busy_wait(25);
puts("Ending radio");
}
}
void camera_task() {
puts("Starting camera task");
while (1) {
sleep();
puts("Doing camera");
busy_wait(25);
puts("Ending camera");
}
}
void mesures_task() {
puts("Starting mesures task");
while (1) {
sleep();
get_ressource();
puts("Doing mesures");
busy_wait(50);
puts("Ending mesures");
release_ressource();
}
}
void meteo_task() {
puts("Starting meteo task");
while (1) {
sleep();
get_ressource();
puts("Doing meteo");
busy_wait(30);
puts("Ending meteo");
release_ressource();
}
}
for (int i = 0; i < 1000000; i++) {
printf("A %d\n", i);
busy_wait(25);
sleep();
}
void lauch_task() {
activate_task(create_task(ordo_task, 125));
activate_task(create_task(distrib_task, 125));
activate_task(create_task(pilotage_task, 250));
activate_task(create_task(radio_task, 250));
activate_task(create_task(camera_task, 250));
activate_task(create_task(mesures_task, 5000));
activate_task(create_task(meteo_task, 5000));
kernel_exit("graceful exit from task A");
puts("terminate lauch task");
task_end();
}
void main() {
serial_init(1, 115200u);
kernel_start(task_a, 250);
s_init();
sem = s_create(1);
kernel_start(lauch_task, 1000);
kernel_exit("unexpected exit");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment