-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try minimalistic cooperative scheduler
- Loading branch information
1 parent
9e97767
commit 2e5430c
Showing
12 changed files
with
182 additions
and
76 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
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
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
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,12 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Copyright Christopher Kormanyos 2024. | ||
// Distributed under The Unlicense | ||
// | ||
|
||
void app_acc_init(void) | ||
{ | ||
} | ||
|
||
void app_acc_task(void) | ||
{ | ||
} |
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
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
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
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,26 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Copyright Christopher Kormanyos 2024. | ||
// Distributed under The Unlicense | ||
// | ||
|
||
#include <mcal/mcal_gpt.h> | ||
#include <os/os.h> | ||
#include <startup/asm_util.h> | ||
|
||
void main(void) | ||
{ | ||
mcal_gpt_init(); | ||
|
||
os_init(); | ||
|
||
os_schedule(); | ||
|
||
mcal_gpt_de_init(); | ||
|
||
// Exit the Application and return to the home screen | ||
// using the JForceCmdNoChar function. See also page 16 | ||
// in "TI-83 Plus System Routines", Third Release, | ||
// (Jan. 25, 2002). | ||
|
||
__asm__("rst 0x28\n" ".dw #0x4027\n"); | ||
} |
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
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,67 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Copyright Christopher Kormanyos 2024. | ||
// Distributed under The Unlicense | ||
// | ||
|
||
#include <stdbool.h> | ||
#include <stddef.h> | ||
|
||
#include <mcal/mcal_gpt.h> | ||
#include <os/os.h> | ||
#include <startup/asm_util.h> | ||
|
||
#define OS_COUNTOF(a) (size_t) (sizeof(a) / sizeof(a[(size_t) 0U])) | ||
|
||
#define OS_TIMER_TIMEOUT(T) (bool) (((uint8_t) ((uint8_t) (mcal_gpt_get_time_elapsed() - (T)) & (uint8_t) UINT8_C(0x80)) == (uint8_t) UINT8_C(0)) ? true : false) | ||
|
||
extern void app_led_init(void); | ||
extern void app_led_task(void); | ||
extern void app_acc_init(void); | ||
extern void app_acc_task(void); | ||
|
||
static bool os_wants_exit(void) ATTRIBUTE_NAKED; | ||
|
||
static os_task_control_block os_task_list[2U] = | ||
{ | ||
{ app_led_init, app_led_task, (uint8_t) UINT8_C(1), (uint8_t) UINT8_C(0) }, | ||
{ app_acc_init, app_acc_task, (uint8_t) UINT8_C(7), (uint8_t) UINT8_C(0) } | ||
}; | ||
|
||
void os_init(void) | ||
{ | ||
for(uint8_t task_index = (uint8_t) UINT8_C(0); task_index < (uint8_t) OS_COUNTOF(os_task_list); ++task_index) | ||
{ | ||
os_task_list[task_index].p_init(); | ||
} | ||
} | ||
|
||
void os_schedule(void) | ||
{ | ||
while(!os_wants_exit()) | ||
{ | ||
for(uint8_t task_index = (uint8_t) UINT8_C(0); task_index < (uint8_t) OS_COUNTOF(os_task_list); ++task_index) | ||
{ | ||
if(OS_TIMER_TIMEOUT(os_task_list[task_index].timer)) | ||
{ | ||
os_task_list[task_index].p_func(); | ||
|
||
os_task_list[task_index].timer += os_task_list[task_index].cycle; | ||
} | ||
} | ||
} | ||
} | ||
|
||
static bool os_wants_exit(void) ATTRIBUTE_NAKED | ||
{ | ||
__asm__("rst 0x28\n" ".dw #0x4018\n"); | ||
__asm__("ld h, #0x0\n"); | ||
__asm__("cp #0x9\n"); | ||
__asm__("jp nz, no_exit\n"); | ||
__asm__("ld h, #0x1\n"); | ||
__asm__("no_exit:\n"); | ||
__asm__("ret\n"); | ||
|
||
#if defined(_MSC_VER) | ||
return false; | ||
#endif | ||
} |
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,25 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Copyright Christopher Kormanyos 2024. | ||
// Distributed under The Unlicense | ||
// | ||
|
||
#ifndef OS_2024_01_09_H | ||
#define OS_2024_01_09_H | ||
|
||
#include <stdint.h> | ||
|
||
typedef void(*os_function_type)(void); | ||
|
||
typedef struct os_task_control_block | ||
{ | ||
os_function_type p_init; | ||
os_function_type p_func; | ||
uint8_t cycle; | ||
uint8_t timer; | ||
} | ||
os_task_control_block; | ||
|
||
void os_init (void); | ||
void os_schedule(void); | ||
|
||
#endif // OS_2024_01_09_H |
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