katapult/src/sched.c
Kevin O'Connor 8316d2f0af armcm_boot: Introduce application_check_valid()
Move application_check_valid() in bootentry.c to armcm_boot.c and make
the check specific to the ARM cortex-m.  On these ARM machines it is
easier to validate the application stack address.

Also rename jump_to_application() to application_jump().

Also rename flash_read_block() to application_read_flash() and move to
armcm_boot.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 19:21:51 -04:00

62 lines
1.3 KiB
C

// Basic scheduling functions and startup code
//
// Copyright (C) 2016-2022 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "board/io.h" // readb
#include "board/misc.h" // jump_to_application
#include "bootentry.h" // bootentry_check
#include "sched.h" // sched_check_periodic
// Implement simple delay mechanism
void
udelay(uint32_t usecs)
{
uint32_t end = timer_read_time() + timer_from_us(usecs);
while (timer_is_before(timer_read_time(), end))
;
}
// Wrapper for Klipper compatibility
void
sched_wake_tasks(void)
{
}
// Note that a task is ready to run
void
sched_wake_task(struct task_wake *w)
{
writeb(&w->wake, 1);
}
// Check if a task is ready to run (as indicated by sched_wake_task)
uint8_t
sched_check_wake(struct task_wake *w)
{
if (!readb(&w->wake))
return 0;
writeb(&w->wake, 0);
return 1;
}
// Init followed by main task dispatch loop
void
sched_main(void)
{
timer_setup();
if (!bootentry_check())
application_jump();
// Run all init functions marked with DECL_INIT()
extern void ctr_run_initfuncs(void);
ctr_run_initfuncs();
for (;;) {
// Run all task functions marked with DECL_TASK()
extern void ctr_run_taskfuncs(void);
ctr_run_taskfuncs();
}
}