From c71fcfd916c379b53b7f921126d6cfbeaafe268c Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Fri, 30 Dec 2022 15:33:38 +0530 Subject: [PATCH 01/22] Bug Fixed --- src/visor/terravisor/services/kernel/cc_os_sched.c | 2 +- src/visor/terravisor/services/kernel/cc_os_sem.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index 9513288c..6f51d84d 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -198,7 +198,7 @@ static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) { ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ - if ((wait_res != CC_OS_NULL_PTR) && (*wait_res == CC_OS_FALSE)) + if ((wait_res != CC_OS_NULL_PTR) && *wait_res) { /* The resource is available can can go to ready state */ ptr->wait_res.task_delay_ticks = CC_OS_FALSE; diff --git a/src/visor/terravisor/services/kernel/cc_os_sem.c b/src/visor/terravisor/services/kernel/cc_os_sem.c index 759fb1b1..ceba6718 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sem.c +++ b/src/visor/terravisor/services/kernel/cc_os_sem.c @@ -1,8 +1,8 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2CC_OS_FALSE22, Cyancore Team + * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_sem.h + * File Name : cc_os_sem.c * Description : CC OS Semaphore function definations * Primary Author : Pranjal Chanda [pranjalchandaCC_OS_FALSE8@gmail.com] * Organisation : Cyancore Core-Team From f019b8b6588b3096176115cf435585fa284b8db3 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Sun, 1 Jan 2023 17:22:02 +0530 Subject: [PATCH 02/22] Demo initial commit + Memory footprint enhancement --- .gitignore | 4 ++ .vscode/settings.json | 61 ------------------- .../visor/terravisor/cc_os/cc_os_config.h | 6 +- .../visor/terravisor/cc_os/cc_os_sem.h | 1 + .../visor/terravisor/cc_os/cc_os_tasks.h | 30 +++++++-- .../visor/terravisor/cc_os/utils/cc_os_heap.h | 2 +- .../terravisor/cc_os/utils/cc_os_sched.h | 5 +- .../terravisor/services/kernel/cc_os_heap.c | 8 +-- .../terravisor/services/kernel/cc_os_sched.c | 4 +- .../services/kernel/cc_os_task_idle.c | 1 + .../terravisor/services/kernel/cc_os_tasks.c | 13 ++-- 11 files changed, 52 insertions(+), 83 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 82f9ae17..c3281316 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,7 @@ projects/ *.mod* *.cmd *.todo + +.vscode/compile_commands.json + +.vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b46e6ca1..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "editor.tabSize": 8, - "[c]": { - "editor.tabSize": 8 - }, - "[cpp]": { - "editor.tabSize": 8 - }, - "[json]": { - "editor.tabSize": 8 - }, - "[makefile]": { - "editor.tabSize": 8 - }, - "[python]": { - "editor.tabSize": 8 - }, - "editor.selectionHighlight": true, - "editor.semanticHighlighting.enabled": true, - "editor.trimAutoWhitespace": true, - "editor.autoClosingQuotes": "always", - "editor.autoClosingBrackets": "always", - "editor.wordBasedSuggestions": true, - "editor.insertSpaces": false, - "editor.autoIndent": "advanced", - "editor.detectIndentation": true, - "editor.codeLens": true, - "editor.columnSelection": false, - "editor.colorDecorators": true, - "editor.cursorBlinking": "blink", - "editor.lightbulb.enabled": true, - "editor.lineNumbers": "on", - "editor.suggest.showFunctions": true, - "diffEditor.codeLens": true, - "diffEditor.wordWrap": "on", - "editor.suggest.showStatusBar": true, - "editor.formatOnSave": false, - "files.associations": { - "*.sx": "c", - "*.{c,c.dev.c.temp,c.tmp,c.old,h,h.dev,h.old,h.temp,h.tmp)": "C", - "*.{cpp,cpp.dev,cpp.temp,cpp.tmp,cpp.old}": "C++", - "*.{S,S.old,S.dev.S.temp,S.tmp,s.old,s.temp,s.tmp,s.dev,asm,asm.old,asm.dev.asm.temp,asm.tmp,inc,inc.old,inc.temp,inc.tmp,ld,ld.old,ld.temp,ld.tmp,ld.sx,ld.sx.old,ld.sx.temp,ld.sx.tmp,lst}": "coffeescript" - }, - "files.autoSave": "afterDelay", - "files.autoSaveDelay": 100, - "files.defaultLanguage": "C", - "files.insertFinalNewline": true, - "files.trimTrailingWhitespace": true, - "files.trimFinalNewlines": true, - "files.simpleDialog.enable": true, - "workbench.activityBar.iconClickBehavior": "focus", - "workbench.editor.closeOnFileDelete": true, - "workbench.editor.decorations.badges": true, - "workbench.editor.enablePreviewFromCodeNavigation": true, - "workbench.editor.enablePreviewFromQuickOpen": true, - "workbench.editor.highlightModifiedTabs": true, - "workbench.settings.openDefaultKeybindings": true, - "C_Cpp.autocompleteAddParentheses": true, - "git.alwaysSignOff": true, - "files.autoGuessEncoding": true -} diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.h b/src/include/visor/terravisor/cc_os/cc_os_config.h index 3ffb4fd6..3af96b2f 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.h +++ b/src/include/visor/terravisor/cc_os/cc_os_config.h @@ -15,7 +15,7 @@ * @note Possible values : 1/0 */ #ifndef ccosconfig_CC_OS_USE_DYNAMIC -#define ccosconfig_CC_OS_USE_DYNAMIC 0 +#define ccosconfig_CC_OS_USE_DYNAMIC 1 #endif /** @@ -33,7 +33,7 @@ * to be used as possible for the application being created. */ #ifndef ccosconfig_CC_OS_MAX_THREAD -#define ccosconfig_CC_OS_MAX_THREAD 10 +#define ccosconfig_CC_OS_MAX_THREAD 2 #endif /** @@ -62,7 +62,7 @@ /** * @brief If the Kernel shall enter poer save mode during IDLE - * + * */ #ifndef ccosconfig_CC_OS_POWER_SAVE_EN #define ccosconfig_CC_OS_POWER_SAVE_EN 0 diff --git a/src/include/visor/terravisor/cc_os/cc_os_sem.h b/src/include/visor/terravisor/cc_os/cc_os_sem.h index e7a3d1e6..e6dc2a92 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_sem.h +++ b/src/include/visor/terravisor/cc_os/cc_os_sem.h @@ -34,6 +34,7 @@ static sem_t _Name##_sem = { \ }; \ static sem_t * _Name##_sem_inst = &_Name##_sem #else +#define CC_SEM_DEF(_Name) \ static sem_t * _Name##_sem_inst = CC_OS_NULL_PTR #endif /***************************************************** diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index 74938dca..b401f673 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -24,7 +24,6 @@ *****************************************************/ typedef void *os_args; typedef void (*task_fn)(os_args args); -typedef const char c_char; /** * @brief TASK infrastructure structure @@ -35,8 +34,8 @@ typedef struct cc_os_task task_fn task_fn; ///>> Task funcion os_args args; ///>> Task Args ptr c_char *name; ///>> String name of the task - size_t priority; ///>> For waited tasks - size_t *stack_ptr; ///>> Stack pointer of the task + uint8_t *stack_ptr; ///>> Stack pointer of the task + uint8_t priority; ///>> For waited tasks size_t stack_len; ///>> Stack lengths of the task cc_sched_tcb_t *task_tcb_ptr; ///>> For internal use only } cc_os_task_t; @@ -51,8 +50,10 @@ typedef struct cc_os_task * @note DO NOT use space in place of TASK_Name as it would result build errors. * */ +#if CC_OS_DYNAMIC == CC_OS_FALSE #define CC_TASK_DEF(_NAME, _fn, _args, _PRI, STACK_LEN) \ - static size_t _NAME##_stack[STACK_LEN]; \ + extern void _fn (os_args args); \ + static uint8_t _NAME##_stack[STACK_LEN]; \ static cc_os_task_t _NAME##_task = { \ .args = _args, \ .task_fn = _fn, \ @@ -60,7 +61,17 @@ typedef struct cc_os_task .priority = _PRI, \ .stack_ptr = _NAME##_stack, \ .stack_len = STACK_LEN} - +#else +#define CC_TASK_DEF(_NAME, _fn, _args, _PRI, STACK_LEN) \ + extern void _fn (os_args args); \ + static cc_os_task_t _NAME##_task = { \ + .args = _args, \ + .task_fn = _fn, \ + .name = #_NAME, \ + .priority = _PRI, \ + .stack_ptr = CC_OS_NULL_PTR, \ + .stack_len = STACK_LEN} +#endif /** * @brief Function to get the instance using its name of already declared task. * @brief Usage: cc_os_task_t * task = &(CC_GET_TASK_INST(TASK_Name)); @@ -131,8 +142,15 @@ status_t cc_os_resume_all_task(void); * @param sched_algo[in] The algorithm that needs to be selected to * @return status_t */ -status_t set_cc_os_sched_algo(cc_sched_algo_t sched_algo); +status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo); +/** + * @brief Get name of current running task + * + * @param None + * @return Pointer to the current task name + */ +const char * cc_os_get_curr_task_name(void); /** * @brief A Function to put the current task to a waiting state and yield * @note To just Yeild set ticks to 0 diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_heap.h b/src/include/visor/terravisor/cc_os/utils/cc_os_heap.h index 7e0cbb97..44ad205a 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_heap.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_heap.h @@ -14,4 +14,4 @@ #include void * cc_os_malloc(size_t size); -void * cc_os_free(const void *addr); +void cc_os_free(void *addr); diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 29330d09..00034c8e 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -34,6 +34,7 @@ *****************************************************/ typedef struct cc_sched_tcb cc_sched_tcb_t; typedef struct cc_sched cc_sched_t; +typedef const char c_char; typedef enum { @@ -58,8 +59,8 @@ typedef struct wres struct cc_sched_tcb { - char name [ccosconfig_CC_OS_TASK_NAME_LEN + 1]; ///> Name of the Current Task - size_t priority; ///> Priority of the task + c_char * name; ///> Name of the Current Task + uint8_t priority; ///> Priority of the task void * stack_ptr; ///> Stack Pointer wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers diff --git a/src/visor/terravisor/services/kernel/cc_os_heap.c b/src/visor/terravisor/services/kernel/cc_os_heap.c index a4683201..e307f9bb 100644 --- a/src/visor/terravisor/services/kernel/cc_os_heap.c +++ b/src/visor/terravisor/services/kernel/cc_os_heap.c @@ -28,11 +28,11 @@ /***************************************************** * USER FUNCTION DEFINATIONS *****************************************************/ -void * cc_os_malloc(size_t size _UNUSED) +void * cc_os_malloc(size_t size) { - return CC_OS_NULL_PTR; + return malloc(size); } -void * cc_os_free(const void *addr _UNUSED ) +void cc_os_free(void *addr ) { - return CC_OS_NULL_PTR; + free(addr); } diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index 6f51d84d..e8ef60bf 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -193,7 +193,7 @@ static void __cc_sched_context_switch(cc_sched_tcb_t * next_task) static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) { cc_sched_tcb_t * ptr = sched_ctrl->wait_list_head; - size_t * wait_res = ptr->wait_res.wait_on_resource; + size_t * wait_res = (size_t *)ptr->wait_res.wait_on_resource; while(ptr != CC_OS_NULL_PTR) { ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ @@ -202,7 +202,7 @@ static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) { /* The resource is available can can go to ready state */ ptr->wait_res.task_delay_ticks = CC_OS_FALSE; - ptr->wait_res.wait_on_resource = CC_OS_NULL_PTR; + ptr->wait_res.wait_on_resource = CC_OS_FALSE; } if(ptr->wait_res.task_delay_ticks == CC_OS_FALSE) { diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index fe416d28..fbdeb83b 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -34,6 +34,7 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) ptr->ready_link.next = CC_OS_NULL_PTR; ptr->ready_link.prev = CC_OS_NULL_PTR; #else + cc_os_free(ptr->stack_ptr); cc_os_free(ptr); #endif } diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index aa31b04c..fb5a7e3f 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -106,13 +106,13 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) { #else /* Dynamic Task Declaration */ - if (ptr != CC_OS_NULL_PTR) ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); + if (ptr != CC_OS_NULL_PTR) { #endif /* Fill tcb details */ - strlcpy(ptr->name, cc_os_task->name, ccosconfig_CC_OS_TASK_NAME_LEN); - ptr->stack_ptr = cc_os_task->stack_ptr; + ptr->name = cc_os_task->name; + ptr->stack_ptr = (uint8_t *) malloc(cc_os_task->stack_len); ptr->priority = cc_os_task->priority; } else @@ -252,7 +252,7 @@ status_t cc_os_resume_task (cc_os_task_t * cc_os_task) return success; } -status_t set_cc_os_sched_algo(cc_sched_algo_t sched_algo) +status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo) { CC_OS_ASSERT_IF_FALSE(sched_algo != cc_sched_algo_max); @@ -261,6 +261,11 @@ status_t set_cc_os_sched_algo(cc_sched_algo_t sched_algo) return success; } +const char * cc_os_get_curr_task_name(void) +{ + return g_sched_ctrl.curr_task->name; +} + void cc_os_task_wait (const size_t ticks) { cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; From 98dacfefcb67544a2912aae032650dce987e5303 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Wed, 4 Jan 2023 19:42:00 +0530 Subject: [PATCH 03/22] Add Test Project files --- .gitignore | 1 - projects/demo_cc_os/build.mk | 25 +++++++++ projects/demo_cc_os/config/cc_os_config.mk | 15 ++++++ projects/demo_cc_os/config/config.mk | 22 ++++++++ projects/demo_cc_os/project.c | 51 +++++++++++++++++++ .../visor/terravisor/cc_os/cc_os_tasks.h | 2 +- 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 projects/demo_cc_os/build.mk create mode 100644 projects/demo_cc_os/config/cc_os_config.mk create mode 100644 projects/demo_cc_os/config/config.mk create mode 100644 projects/demo_cc_os/project.c diff --git a/.gitignore b/.gitignore index c3281316..ab7fa0de 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ out/ tools/ backup/ bkp/ -projects/ *.elf *.bin *.d diff --git a/projects/demo_cc_os/build.mk b/projects/demo_cc_os/build.mk new file mode 100644 index 00000000..43e1b9a8 --- /dev/null +++ b/projects/demo_cc_os/build.mk @@ -0,0 +1,25 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : build.mk +# Description : This file build project sources and specifies +# project properties +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +PROJECT_DIR := $(GET_PATH) + +OPTIMIZATION := s + +EXE_MODE := terravisor + +include $(PROJECT_DIR)/config/config.mk + +# You can add another folder with necessary files to build the project +# The below path should be valid +# include $(PROJECT_DIR)//build.mk + +DIR := $(PROJECT_DIR) +include mk/obj.mk diff --git a/projects/demo_cc_os/config/cc_os_config.mk b/projects/demo_cc_os/config/cc_os_config.mk new file mode 100644 index 00000000..53abecbb --- /dev/null +++ b/projects/demo_cc_os/config/cc_os_config.mk @@ -0,0 +1,15 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : kern_config.mk +# Description : This file consists of CC_OS kernal configuration +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +ccosconfig_CC_OS_USE_DYNAMIC := 0 +ccosconfig_CC_OS_HEAP_SIZE := 1024 +ccosconfig_CC_OS_MAX_THREAD := 2 +ccosconfig_CC_OS_TASK_STACK_LEN := 255 +ccosconfig_CC_OS_POWER_SAVE_EN := 0 diff --git a/projects/demo_cc_os/config/config.mk b/projects/demo_cc_os/config/config.mk new file mode 100644 index 00000000..2b9b587c --- /dev/null +++ b/projects/demo_cc_os/config/config.mk @@ -0,0 +1,22 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : config.mk +# Description : This file consists of project config +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +COMPILER := gcc +TC_VER := 5.4.0 +FAMILY := mega_avr +PLATFORM := atmega328p +STDLOG_MEMBUF := 0 +BOOTMSGS := 0 +EARLYCON_SERIAL := 0 +CONSOLE_SERIAL := 0 +OBRDLED_ENABLE := 1 +TERRAKERN := 1 + +include $(PROJECT_DIR)/config/cc_os_config.mk diff --git a/projects/demo_cc_os/project.c b/projects/demo_cc_os/project.c new file mode 100644 index 00000000..a1973e0f --- /dev/null +++ b/projects/demo_cc_os/project.c @@ -0,0 +1,51 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2019, Cyancore Team + * + * File Name : project.c + * Description : This file consists of project srouces + * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] + * Organisation : Cyancore Core-Team + */ +#include +#include +#include +#include +#include + +#define TASK_WAIT_TICKS 10 + +/* Define the Tasks */ +CC_TASK_DEF( TASK_A, task_handler, NULL, 10, 100); +CC_TASK_DEF( TASK_B, task_handler, NULL, 10, 100); +CC_TASK_DEF( TASK_C, task_handler, NULL, 10, 100); + +/* Define Plug */ +void plug() +{ + bootstrap(); + driver_setup_all(); + + printf("Demo CC OS Program!\n"); + cc_os_add_task(&CC_GET_TASK_INST(TASK_A)); + cc_os_add_task(&CC_GET_TASK_INST(TASK_B)); + cc_os_add_task(&CC_GET_TASK_INST(TASK_C)); + cc_os_run(); +} + +/* Define Play */ +void play() +{ + /* < ! > Play looping code here*/ + return; +} + +/* Define the Task Handler */ +void task_handler(os_args args _UNUSED) +{ + while(CC_OS_TRUE) + { + printf("In Task: %s\n", cc_os_get_curr_task_name()); + cc_os_task_wait(TASK_WAIT_TICKS); + } +} diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index b401f673..a0b62866 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -22,7 +22,7 @@ /***************************************************** * TYPEDEFS *****************************************************/ -typedef void *os_args; +typedef const void * os_args; typedef void (*task_fn)(os_args args); /** From 78d11db7982d08ac7914b42e72d412bc7efaae41 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Wed, 4 Jan 2023 20:59:14 +0530 Subject: [PATCH 04/22] Test Application created + avr + riscv --- mk/path.mk | 1 + projects/demo_cc_os.src/build.mk | 19 +++++++++++ .../{demo_cc_os => demo_cc_os.src}/project.c | 0 .../{demo_cc_os => demo_cc_os_avr}/build.mk | 11 ++----- .../config => demo_cc_os_avr}/cc_os_config.mk | 10 +++--- .../config => demo_cc_os_avr}/config.mk | 8 +++-- projects/demo_cc_os_riscv/build.mk | 18 ++++++++++ projects/demo_cc_os_riscv/cc_os_config.mk | 17 ++++++++++ projects/demo_cc_os_riscv/config.mk | 24 ++++++++++++++ .../visor/terravisor/cc_os/cc_os_config.h | 2 +- .../visor/terravisor/cc_os/cc_os_config.mk | 21 ++++++++++++ .../services/kernel/cc_os_task_idle.c | 2 +- .../terravisor/services/kernel/cc_os_tasks.c | 33 +++++++++---------- 13 files changed, 131 insertions(+), 35 deletions(-) create mode 100644 projects/demo_cc_os.src/build.mk rename projects/{demo_cc_os => demo_cc_os.src}/project.c (100%) rename projects/{demo_cc_os => demo_cc_os_avr}/build.mk (59%) rename projects/{demo_cc_os/config => demo_cc_os_avr}/cc_os_config.mk (56%) rename projects/{demo_cc_os/config => demo_cc_os_avr}/config.mk (64%) create mode 100644 projects/demo_cc_os_riscv/build.mk create mode 100644 projects/demo_cc_os_riscv/cc_os_config.mk create mode 100644 projects/demo_cc_os_riscv/config.mk create mode 100644 src/include/visor/terravisor/cc_os/cc_os_config.mk diff --git a/mk/path.mk b/mk/path.mk index 24318b40..540666a0 100644 --- a/mk/path.mk +++ b/mk/path.mk @@ -18,6 +18,7 @@ TOOLS_ROOT ?= $(abspath $(CC_ROOT))/tools MISC_TOOLS := $(TOOLS_ROOT)/misc_bins SRC := $(CC_ROOT)/src +CC_OS_ROOT := $(SRC)/include/visor/terravisor/cc_os OUT_PATH ?= $(CC_ROOT)/out OUT ?= $(OUT_PATH)/$(PROJECT) diff --git a/projects/demo_cc_os.src/build.mk b/projects/demo_cc_os.src/build.mk new file mode 100644 index 00000000..1fe601cd --- /dev/null +++ b/projects/demo_cc_os.src/build.mk @@ -0,0 +1,19 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : build.mk +# Description : This file build project sources and specifies +# project properties +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DEMO_DIR := $(GET_PATH) + +OPTIMIZATION := s + +EXE_MODE := terravisor + +DIR := $(DEMO_DIR) +include mk/obj.mk diff --git a/projects/demo_cc_os/project.c b/projects/demo_cc_os.src/project.c similarity index 100% rename from projects/demo_cc_os/project.c rename to projects/demo_cc_os.src/project.c diff --git a/projects/demo_cc_os/build.mk b/projects/demo_cc_os_avr/build.mk similarity index 59% rename from projects/demo_cc_os/build.mk rename to projects/demo_cc_os_avr/build.mk index 43e1b9a8..2e8826e4 100644 --- a/projects/demo_cc_os/build.mk +++ b/projects/demo_cc_os_avr/build.mk @@ -11,15 +11,8 @@ PROJECT_DIR := $(GET_PATH) -OPTIMIZATION := s - -EXE_MODE := terravisor - -include $(PROJECT_DIR)/config/config.mk - -# You can add another folder with necessary files to build the project -# The below path should be valid -# include $(PROJECT_DIR)//build.mk +include $(PROJECT_DIR)/../demo_cc_os.src/build.mk +include $(PROJECT_DIR)/config.mk DIR := $(PROJECT_DIR) include mk/obj.mk diff --git a/projects/demo_cc_os/config/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk similarity index 56% rename from projects/demo_cc_os/config/cc_os_config.mk rename to projects/demo_cc_os_avr/cc_os_config.mk index 53abecbb..1ec963e5 100644 --- a/projects/demo_cc_os/config/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -1,15 +1,17 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2019-2023, Cyancore Team # # File Name : kern_config.mk # Description : This file consists of CC_OS kernal configuration -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # -ccosconfig_CC_OS_USE_DYNAMIC := 0 +ccosconfig_CC_OS_USE_DYNAMIC := 1 ccosconfig_CC_OS_HEAP_SIZE := 1024 -ccosconfig_CC_OS_MAX_THREAD := 2 +ccosconfig_CC_OS_MAX_THREAD := 3 ccosconfig_CC_OS_TASK_STACK_LEN := 255 ccosconfig_CC_OS_POWER_SAVE_EN := 0 + +include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/projects/demo_cc_os/config/config.mk b/projects/demo_cc_os_avr/config.mk similarity index 64% rename from projects/demo_cc_os/config/config.mk rename to projects/demo_cc_os_avr/config.mk index 2b9b587c..70242aac 100644 --- a/projects/demo_cc_os/config/config.mk +++ b/projects/demo_cc_os_avr/config.mk @@ -1,10 +1,10 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2019-2023, Cyancore Team # # File Name : config.mk # Description : This file consists of project config -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # @@ -12,6 +12,8 @@ COMPILER := gcc TC_VER := 5.4.0 FAMILY := mega_avr PLATFORM := atmega328p +HEAP_SIZE := 256 +STACK_SIZE := 256 STDLOG_MEMBUF := 0 BOOTMSGS := 0 EARLYCON_SERIAL := 0 @@ -19,4 +21,4 @@ CONSOLE_SERIAL := 0 OBRDLED_ENABLE := 1 TERRAKERN := 1 -include $(PROJECT_DIR)/config/cc_os_config.mk +include $(PROJECT_DIR)/cc_os_config.mk diff --git a/projects/demo_cc_os_riscv/build.mk b/projects/demo_cc_os_riscv/build.mk new file mode 100644 index 00000000..2e8826e4 --- /dev/null +++ b/projects/demo_cc_os_riscv/build.mk @@ -0,0 +1,18 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : build.mk +# Description : This file build project sources and specifies +# project properties +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +PROJECT_DIR := $(GET_PATH) + +include $(PROJECT_DIR)/../demo_cc_os.src/build.mk +include $(PROJECT_DIR)/config.mk + +DIR := $(PROJECT_DIR) +include mk/obj.mk diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk new file mode 100644 index 00000000..1ec963e5 --- /dev/null +++ b/projects/demo_cc_os_riscv/cc_os_config.mk @@ -0,0 +1,17 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019-2023, Cyancore Team +# +# File Name : kern_config.mk +# Description : This file consists of CC_OS kernal configuration +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] +# Organisation : Cyancore Core-Team +# + +ccosconfig_CC_OS_USE_DYNAMIC := 1 +ccosconfig_CC_OS_HEAP_SIZE := 1024 +ccosconfig_CC_OS_MAX_THREAD := 3 +ccosconfig_CC_OS_TASK_STACK_LEN := 255 +ccosconfig_CC_OS_POWER_SAVE_EN := 0 + +include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/projects/demo_cc_os_riscv/config.mk b/projects/demo_cc_os_riscv/config.mk new file mode 100644 index 00000000..2d0b8d10 --- /dev/null +++ b/projects/demo_cc_os_riscv/config.mk @@ -0,0 +1,24 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019-2023, Cyancore Team +# +# File Name : config.mk +# Description : This file consists of project config +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] +# Organisation : Cyancore Core-Team +# + +COMPILER := gcc +TC_VER := 10.2.0 +FAMILY := sifive +PLATFORM := fe310g002 +HEAP_SIZE := 256 +STACK_SIZE := 256 +STDLOG_MEMBUF := 0 +BOOTMSGS := 0 +EARLYCON_SERIAL := 0 +CONSOLE_SERIAL := 0 +OBRDLED_ENABLE := 1 +TERRAKERN := 1 + +include $(PROJECT_DIR)/cc_os_config.mk diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.h b/src/include/visor/terravisor/cc_os/cc_os_config.h index 3af96b2f..f9f2f9ef 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.h +++ b/src/include/visor/terravisor/cc_os/cc_os_config.h @@ -33,7 +33,7 @@ * to be used as possible for the application being created. */ #ifndef ccosconfig_CC_OS_MAX_THREAD -#define ccosconfig_CC_OS_MAX_THREAD 2 +#define ccosconfig_CC_OS_MAX_THREAD 10 #endif /** diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.mk b/src/include/visor/terravisor/cc_os/cc_os_config.mk new file mode 100644 index 00000000..9285fe01 --- /dev/null +++ b/src/include/visor/terravisor/cc_os/cc_os_config.mk @@ -0,0 +1,21 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : kern_config.mk +# Description : This file consists of CC_OS kernal configuration +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +ccosconfig_CC_OS_USE_DYNAMIC ?= 0 +ccosconfig_CC_OS_HEAP_SIZE ?= 1024 +ccosconfig_CC_OS_MAX_THREAD ?= 2 +ccosconfig_CC_OS_TASK_STACK_LEN ?= 255 +ccosconfig_CC_OS_POWER_SAVE_EN ?= 0 + +$(eval $(call add_define,ccosconfig_CC_OS_USE_DYNAMIC)) +$(eval $(call add_define,ccosconfig_CC_OS_HEAP_SIZE)) +$(eval $(call add_define,ccosconfig_CC_OS_MAX_THREAD)) +$(eval $(call add_define,ccosconfig_CC_OS_TASK_STACK_LEN)) +$(eval $(call add_define,ccosconfig_CC_OS_POWER_SAVE_EN)) diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index fbdeb83b..7fdbf50d 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -47,7 +47,7 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) *****************************************************/ void _cc_os_idle_task_fn(os_args args) { - cc_sched_ctrl_t * sched_ctrl = (cc_sched_ctrl_t *) args; + const cc_sched_ctrl_t * sched_ctrl = (const cc_sched_ctrl_t *) args; static cc_sched_tcb_t * ptr = CC_OS_NULL_PTR; ptr = sched_ctrl->ready_list_head; while (CC_OS_TRUE) diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index fb5a7e3f..14ba70f9 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -23,19 +23,9 @@ *****************************************************/ #define CC_OS_PRIORITY_MAX 255 -/***************************************************** - * GLOBAL DECLARATIONS - *****************************************************/ -#if CC_OS_DYNAMIC == CC_OS_FALSE -extern cc_sched_tcb_t g_cc_os_tcb_list[]; -#else -extern cc_sched_tcb_t *g_cc_os_tcb_list; -#endif - /***************************************************** * INTERNAL EXTERNS FUNCTIONS *****************************************************/ -extern void _cc_os_idle_task_fn (void * args); extern status_t _insert_after (cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type); extern status_t _insert_before (cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type); extern void _cc_sched_send_to_wait (cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, const size_t ticks); @@ -48,6 +38,22 @@ extern cc_sched_t *g_cc_sched; extern cc_sched_t g_cc_sched_list []; extern cc_sched_ctrl_t g_sched_ctrl; +/***************************************************** + * GLOBAL DECLARATIONS + *****************************************************/ +#if CC_OS_DYNAMIC == CC_OS_FALSE +extern cc_sched_tcb_t g_cc_os_tcb_list[]; +#else +extern cc_sched_tcb_t *g_cc_os_tcb_list; +#endif + +CC_TASK_DEF( + cc_os_idle, /* Name of the instance */ + _cc_os_idle_task_fn, /* Function pointer */ + &g_sched_ctrl, /* Task Args*/ + ccosconfig_CC_OS_IDLE_TASK_PRIORITY, /* Task Priority */ + ccosconfig_CC_OS_TASK_STACK_LEN /* Stack Length of IDLE Task */ +); /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ @@ -288,13 +294,6 @@ void cc_os_run (void) /* OS Init code */ /* Initialise IDLE Task */ - CC_TASK_DEF( - cc_os_idle, /* Name of the instance */ - _cc_os_idle_task_fn, /* Function pointer */ - &g_sched_ctrl, /* Task Args*/ - ccosconfig_CC_OS_IDLE_TASK_PRIORITY, /* Task Priority */ - ccosconfig_CC_OS_TASK_STACK_LEN /* Stack Length of IDLE Task */ - ); cc_os_add_task(&CC_GET_TASK_INST(cc_os_idle)); /* Initialise scheduler */ From aded497788252f7216c504e7681d083b94ccee9b Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Wed, 4 Jan 2023 21:42:45 +0530 Subject: [PATCH 05/22] Self Review comments update --- .github/workflows/github_ci.yml | 12 ++++-------- .github/workflows/sonarcloud.yml | 2 ++ projects/demo_cc_os.src/build.mk | 4 ++-- projects/demo_cc_os_avr/build.mk | 4 ++-- projects/demo_cc_os_avr/cc_os_config.mk | 2 +- projects/demo_cc_os_riscv/build.mk | 4 ++-- src/visor/terravisor/services/kernel/cc_os_sched.c | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/github_ci.yml b/.github/workflows/github_ci.yml index 7b5c758a..09784824 100644 --- a/.github/workflows/github_ci.yml +++ b/.github/workflows/github_ci.yml @@ -2,10 +2,10 @@ name: GitHub CI on: push: - branches: [ stable, development] + branches: [ stable, development, cc_os_stage] pull_request: - branches: [ stable, development] + branches: [ stable, development, cc_os_stage] jobs: build: @@ -44,17 +44,13 @@ jobs: languages: ${{ matrix.language }} debug: true - - name: Linting - run: | - make demo_avr check - make demo_avr_cpp check - make demo_riscv check - - name: Build run: | make demo_avr make demo_avr_cpp make demo_riscv + make demo_cc_os_avr + make demo_cc_os_riscv - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index bc2a1ed7..d32bf159 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -5,10 +5,12 @@ on: branches: - stable - development + - cc_os_stage pull_request: branches: - stable - development + - cc_os_stage jobs: build: diff --git a/projects/demo_cc_os.src/build.mk b/projects/demo_cc_os.src/build.mk index 1fe601cd..7a5e071a 100644 --- a/projects/demo_cc_os.src/build.mk +++ b/projects/demo_cc_os.src/build.mk @@ -1,11 +1,11 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2019-2023, Cyancore Team # # File Name : build.mk # Description : This file build project sources and specifies # project properties -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Primary Author : Pranjal Chdanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # diff --git a/projects/demo_cc_os_avr/build.mk b/projects/demo_cc_os_avr/build.mk index 2e8826e4..b51f75ab 100644 --- a/projects/demo_cc_os_avr/build.mk +++ b/projects/demo_cc_os_avr/build.mk @@ -1,11 +1,11 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2019-2023, Cyancore Team # # File Name : build.mk # Description : This file build project sources and specifies # project properties -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Primary Author : Pranjal Chdanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk index 1ec963e5..828c47c8 100644 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -2,7 +2,7 @@ # CYANCORE LICENSE # Copyrights (C) 2019-2023, Cyancore Team # -# File Name : kern_config.mk +# File Name : cc_os_config.mk # Description : This file consists of CC_OS kernal configuration # Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team diff --git a/projects/demo_cc_os_riscv/build.mk b/projects/demo_cc_os_riscv/build.mk index 2e8826e4..b51f75ab 100644 --- a/projects/demo_cc_os_riscv/build.mk +++ b/projects/demo_cc_os_riscv/build.mk @@ -1,11 +1,11 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2019-2023, Cyancore Team # # File Name : build.mk # Description : This file build project sources and specifies # project properties -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Primary Author : Pranjal Chdanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index e8ef60bf..c055a35a 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -193,7 +193,7 @@ static void __cc_sched_context_switch(cc_sched_tcb_t * next_task) static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) { cc_sched_tcb_t * ptr = sched_ctrl->wait_list_head; - size_t * wait_res = (size_t *)ptr->wait_res.wait_on_resource; + const size_t * wait_res = (size_t *)ptr->wait_res.wait_on_resource; while(ptr != CC_OS_NULL_PTR) { ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ From 11a715461efa0b3c46451e4543a69a7500c26e37 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Thu, 5 Jan 2023 10:52:22 +0530 Subject: [PATCH 06/22] Review Comments --- .vscode/settings.json | 64 +++++++++++++++++++ projects/demo_cc_os_avr/cc_os_config.mk | 10 +-- projects/demo_cc_os_riscv/cc_os_config.mk | 10 +-- .../visor/terravisor/cc_os/cc_os_config.h | 33 ++++------ .../visor/terravisor/cc_os/cc_os_config.mk | 20 +++--- .../visor/terravisor/cc_os/cc_os_tasks.h | 6 +- .../terravisor/cc_os/utils/cc_os_sched.h | 4 +- .../terravisor/services/kernel/cc_os_sched.c | 6 +- .../services/kernel/cc_os_task_idle.c | 4 +- .../terravisor/services/kernel/cc_os_tasks.c | 12 ++-- 10 files changed, 113 insertions(+), 56 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..afd7a788 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,64 @@ +{ + "editor.tabSize": 8, + "[c]": { + "editor.tabSize": 8 + }, + "[cpp]": { + "editor.tabSize": 8 + }, + "[json]": { + "editor.tabSize": 8 + }, + "[makefile]": { + "editor.tabSize": 8 + }, + "[python]": { + "editor.tabSize": 8 + }, + "editor.selectionHighlight": true, + "editor.semanticHighlighting.enabled": true, + "editor.trimAutoWhitespace": true, + "editor.autoClosingQuotes": "always", + "editor.autoClosingBrackets": "always", + "editor.wordBasedSuggestions": true, + "editor.insertSpaces": false, + "editor.autoIndent": "advanced", + "editor.detectIndentation": true, + "editor.codeLens": true, + "editor.columnSelection": false, + "editor.colorDecorators": true, + "editor.cursorBlinking": "blink", + "editor.lightbulb.enabled": true, + "editor.lineNumbers": "on", + "editor.suggest.showFunctions": true, + "diffEditor.codeLens": true, + "diffEditor.wordWrap": "on", + "editor.suggest.showStatusBar": true, + "editor.formatOnSave": false, + "files.associations": { + "*.sx": "c", + "*.{c,c.dev.c.temp,c.tmp,c.old,h,h.dev,h.old,h.temp,h.tmp)": "C", + "*.{cpp,cpp.dev,cpp.temp,cpp.tmp,cpp.old}": "C++", + "*.{S,S.old,S.dev.S.temp,S.tmp,s.old,s.temp,s.tmp,s.dev,asm,asm.old,asm.dev.asm.temp,asm.tmp,inc,inc.old,inc.temp,inc.tmp,ld,ld.old,ld.temp,ld.tmp,ld.sx,ld.sx.old,ld.sx.temp,ld.sx.tmp,lst}": "coffeescript", + "cc_os_sched.h": "c", + "cc_os.h": "c" + }, + "files.autoSave": "afterDelay", + "files.autoSaveDelay": 100, + "files.defaultLanguage": "C", + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + "files.trimFinalNewlines": true, + "files.simpleDialog.enable": true, + "workbench.activityBar.iconClickBehavior": "focus", + "workbench.editor.closeOnFileDelete": true, + "workbench.editor.decorations.badges": true, + "workbench.editor.enablePreviewFromCodeNavigation": true, + "workbench.editor.enablePreviewFromQuickOpen": true, + "workbench.editor.highlightModifiedTabs": true, + "workbench.settings.openDefaultKeybindings": true, + "C_Cpp.autocompleteAddParentheses": true, + "git.alwaysSignOff": true, + "files.autoGuessEncoding": true, + "sonarlint.pathToCompileCommands": "${workspaceFolder}/.vscode/compile_commands.json" +} diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk index 828c47c8..215c4300 100644 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -8,10 +8,10 @@ # Organisation : Cyancore Core-Team # -ccosconfig_CC_OS_USE_DYNAMIC := 1 -ccosconfig_CC_OS_HEAP_SIZE := 1024 -ccosconfig_CC_OS_MAX_THREAD := 3 -ccosconfig_CC_OS_TASK_STACK_LEN := 255 -ccosconfig_CC_OS_POWER_SAVE_EN := 0 +CC_OS_USE_DYNAMIC := 1 +CC_OS_HEAP_SIZE := 1024 +CC_OS_MAX_THREAD := 3 +CC_OS_TASK_STACK_LEN := 255 +CC_OS_POWER_SAVE_EN := 0 include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk index 1ec963e5..c8e63fc8 100644 --- a/projects/demo_cc_os_riscv/cc_os_config.mk +++ b/projects/demo_cc_os_riscv/cc_os_config.mk @@ -8,10 +8,10 @@ # Organisation : Cyancore Core-Team # -ccosconfig_CC_OS_USE_DYNAMIC := 1 -ccosconfig_CC_OS_HEAP_SIZE := 1024 -ccosconfig_CC_OS_MAX_THREAD := 3 -ccosconfig_CC_OS_TASK_STACK_LEN := 255 -ccosconfig_CC_OS_POWER_SAVE_EN := 0 +CC_OS_USE_DYNAMIC := 1 +CC_OS_HEAP_SIZE := 1024 +CC_OS_MAX_THREAD := 3 +CC_OS_TASK_STACK_LEN := 255 +CC_OS_POWER_SAVE_EN := 0 include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.h b/src/include/visor/terravisor/cc_os/cc_os_config.h index f9f2f9ef..5ca697b1 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.h +++ b/src/include/visor/terravisor/cc_os/cc_os_config.h @@ -14,16 +14,16 @@ * @brief Shall CC_OS use dynamic resource allocation * @note Possible values : 1/0 */ -#ifndef ccosconfig_CC_OS_USE_DYNAMIC -#define ccosconfig_CC_OS_USE_DYNAMIC 1 +#ifndef CC_OS_USE_DYNAMIC +#define CC_OS_USE_DYNAMIC 1 #endif /** * @brief Heap size to be allocated to CC_OS * @note Possible values : Depends on available RAM */ -#ifndef ccosconfig_CC_OS_HEAP_SIZE -#define ccosconfig_CC_OS_HEAP_SIZE 1024 +#ifndef CC_OS_HEAP_SIZE +#define CC_OS_HEAP_SIZE 1024 #endif /** @@ -32,38 +32,31 @@ * User may have to keep it optimised so as to use as low BSS section * to be used as possible for the application being created. */ -#ifndef ccosconfig_CC_OS_MAX_THREAD -#define ccosconfig_CC_OS_MAX_THREAD 10 -#endif - -/** - * @brief Max number of characters allowed to be used for task name - */ -#ifndef ccosconfig_CC_OS_TASK_NAME_LEN -#define ccosconfig_CC_OS_TASK_NAME_LEN 16 +#ifndef CC_OS_MAX_THREAD +#define CC_OS_MAX_THREAD 10 #endif /** * @brief Task priority of IDLE task * @note Possible values : 1 -> 255 */ -#ifndef ccosconfig_CC_OS_IDLE_TASK_PRIORITY -#define ccosconfig_CC_OS_IDLE_TASK_PRIORITY 0x01 +#ifndef CC_OS_IDLE_TASK_PRIORITY +#define CC_OS_IDLE_TASK_PRIORITY 0x01 #endif /** * @brief Stack size used by IDLE task * @note The stack size is either allocated statically or dynamically as - * per the setting of ccosconfig_CC_OS_USE_DYNAMIC + * per the setting of CC_OS_USE_DYNAMIC */ -#ifndef ccosconfig_CC_OS_TASK_STACK_LEN -#define ccosconfig_CC_OS_TASK_STACK_LEN 255 +#ifndef CC_OS_TASK_STACK_LEN +#define CC_OS_TASK_STACK_LEN 255 #endif /** * @brief If the Kernel shall enter poer save mode during IDLE * */ -#ifndef ccosconfig_CC_OS_POWER_SAVE_EN -#define ccosconfig_CC_OS_POWER_SAVE_EN 0 +#ifndef CC_OS_POWER_SAVE_EN +#define CC_OS_POWER_SAVE_EN 0 #endif diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.mk b/src/include/visor/terravisor/cc_os/cc_os_config.mk index 9285fe01..ce9244a0 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.mk +++ b/src/include/visor/terravisor/cc_os/cc_os_config.mk @@ -8,14 +8,14 @@ # Organisation : Cyancore Core-Team # -ccosconfig_CC_OS_USE_DYNAMIC ?= 0 -ccosconfig_CC_OS_HEAP_SIZE ?= 1024 -ccosconfig_CC_OS_MAX_THREAD ?= 2 -ccosconfig_CC_OS_TASK_STACK_LEN ?= 255 -ccosconfig_CC_OS_POWER_SAVE_EN ?= 0 +CC_OS_USE_DYNAMIC ?= 0 +CC_OS_HEAP_SIZE ?= 1024 +CC_OS_MAX_THREAD ?= 2 +CC_OS_TASK_STACK_LEN ?= 255 +CC_OS_POWER_SAVE_EN ?= 0 -$(eval $(call add_define,ccosconfig_CC_OS_USE_DYNAMIC)) -$(eval $(call add_define,ccosconfig_CC_OS_HEAP_SIZE)) -$(eval $(call add_define,ccosconfig_CC_OS_MAX_THREAD)) -$(eval $(call add_define,ccosconfig_CC_OS_TASK_STACK_LEN)) -$(eval $(call add_define,ccosconfig_CC_OS_POWER_SAVE_EN)) +$(eval $(call add_define,CC_OS_USE_DYNAMIC)) +$(eval $(call add_define,CC_OS_HEAP_SIZE)) +$(eval $(call add_define,CC_OS_MAX_THREAD)) +$(eval $(call add_define,CC_OS_TASK_STACK_LEN)) +$(eval $(call add_define,CC_OS_POWER_SAVE_EN)) diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index a0b62866..3de13ca7 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -34,7 +34,7 @@ typedef struct cc_os_task task_fn task_fn; ///>> Task funcion os_args args; ///>> Task Args ptr c_char *name; ///>> String name of the task - uint8_t *stack_ptr; ///>> Stack pointer of the task + uintptr_t stack_ptr; ///>> Stack pointer of the task uint8_t priority; ///>> For waited tasks size_t stack_len; ///>> Stack lengths of the task cc_sched_tcb_t *task_tcb_ptr; ///>> For internal use only @@ -59,7 +59,7 @@ typedef struct cc_os_task .task_fn = _fn, \ .name = #_NAME, \ .priority = _PRI, \ - .stack_ptr = _NAME##_stack, \ + .stack_ptr = (uintptr_t) _NAME##_stack, \ .stack_len = STACK_LEN} #else #define CC_TASK_DEF(_NAME, _fn, _args, _PRI, STACK_LEN) \ @@ -69,7 +69,7 @@ typedef struct cc_os_task .task_fn = _fn, \ .name = #_NAME, \ .priority = _PRI, \ - .stack_ptr = CC_OS_NULL_PTR, \ + .stack_ptr = (uintptr_t) CC_OS_NULL_PTR, \ .stack_len = STACK_LEN} #endif /** diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 00034c8e..770bed1e 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -25,7 +25,7 @@ #define CC_OS_NULL_PTR NULL #define CC_OS_DELAY_MAX ((size_t) -1) -#define CC_OS_DYNAMIC ccosconfig_CC_OS_USE_DYNAMIC +#define CC_OS_DYNAMIC CC_OS_USE_DYNAMIC #define CC_OS_ASSERT_IF_FALSE(con) RET_ON_FAIL(con, error_func_inval_arg) @@ -61,7 +61,7 @@ struct cc_sched_tcb { c_char * name; ///> Name of the Current Task uint8_t priority; ///> Priority of the task - void * stack_ptr; ///> Stack Pointer + uintptr_t stack_ptr; ///> Stack Pointer wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers link_t wait_link; ///> Wait Linked List Pointers diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index c055a35a..3f1f060d 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -30,8 +30,8 @@ static void __cc_sched_algo_priority_driven_fn(cc_sched_ctrl_t * sched_ctrl); /***************************************************** * GLOBAL DECLARATIONS *****************************************************/ -#if !ccosconfig_CC_OS_USE_DYNAMIC -cc_sched_tcb_t g_cc_os_tcb_list [ccosconfig_CC_OS_MAX_THREAD]; +#if !CC_OS_USE_DYNAMIC +cc_sched_tcb_t g_cc_os_tcb_list [CC_OS_MAX_THREAD]; #else cc_sched_tcb_t * g_cc_os_tcb_list = CC_OS_NULL_PTR; #endif @@ -44,7 +44,7 @@ cc_sched_t g_cc_sched_list [] = cc_sched_ctrl_t g_sched_ctrl = { -#if !ccosconfig_CC_OS_USE_DYNAMIC +#if !CC_OS_USE_DYNAMIC .ready_list_head = &(g_cc_os_tcb_list[CC_OS_FALSE]), .curr_task = &(g_cc_os_tcb_list[CC_OS_FALSE]), #else diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index 7fdbf50d..43bd7d62 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -34,7 +34,7 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) ptr->ready_link.next = CC_OS_NULL_PTR; ptr->ready_link.prev = CC_OS_NULL_PTR; #else - cc_os_free(ptr->stack_ptr); + cc_os_free((void *)ptr->stack_ptr); cc_os_free(ptr); #endif } @@ -55,7 +55,7 @@ void _cc_os_idle_task_fn(os_args args) /* Clean up task if terminated */ ptr = __free_terminated_task(ptr); -#if ccosconfig_CC_OS_POWER_SAVE_EN +#if CC_OS_POWER_SAVE_EN /* Power Save code */ #endif diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 14ba70f9..c62cf9e1 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -51,8 +51,8 @@ CC_TASK_DEF( cc_os_idle, /* Name of the instance */ _cc_os_idle_task_fn, /* Function pointer */ &g_sched_ctrl, /* Task Args*/ - ccosconfig_CC_OS_IDLE_TASK_PRIORITY, /* Task Priority */ - ccosconfig_CC_OS_TASK_STACK_LEN /* Stack Length of IDLE Task */ + CC_OS_IDLE_TASK_PRIORITY, /* Task Priority */ + CC_OS_TASK_STACK_LEN /* Stack Length of IDLE Task */ ); /***************************************************** * STATIC FUNCTION DEFINATIONS @@ -68,10 +68,10 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) { CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(cc_os_task->name != CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(cc_os_task->stack_ptr != CC_OS_NULL_PTR); + CC_OS_ASSERT_IF_FALSE(cc_os_task->stack_ptr != (uintptr_t) CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(cc_os_task->task_fn != CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(cc_os_task->stack_len != CC_OS_FALSE); - CC_OS_ASSERT_IF_FALSE(cc_os_task->priority >= ccosconfig_CC_OS_IDLE_TASK_PRIORITY); + CC_OS_ASSERT_IF_FALSE(cc_os_task->priority >= CC_OS_IDLE_TASK_PRIORITY); CC_OS_ASSERT_IF_FALSE(cc_os_task->priority < CC_OS_PRIORITY_MAX); cc_os_pause_all_task(); @@ -99,7 +99,7 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) { #if CC_OS_DYNAMIC == CC_OS_FALSE /* Static Task Allocation */ - for (size_t i = CC_OS_FALSE; i < ccosconfig_CC_OS_MAX_THREAD; i++) + for (size_t i = CC_OS_FALSE; i < CC_OS_MAX_THREAD; i++) { /* Get an available node from global tcb list */ if (g_cc_os_tcb_list[i].task_status == cc_sched_task_status_exit) @@ -118,7 +118,7 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) #endif /* Fill tcb details */ ptr->name = cc_os_task->name; - ptr->stack_ptr = (uint8_t *) malloc(cc_os_task->stack_len); + ptr->stack_ptr = (uintptr_t) malloc(cc_os_task->stack_len); ptr->priority = cc_os_task->priority; } else From 98c8a1b89d6d0314023d0aa039c02fd39c916f2d Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Thu, 5 Jan 2023 13:41:59 +0530 Subject: [PATCH 07/22] Task defination re-structuring Signed-off-by: panjalchanda08 --- .gitignore | 4 - projects/demo_cc_os.src/project.c | 17 ++-- .../visor/terravisor/cc_os/cc_os_config.h | 8 ++ .../visor/terravisor/cc_os/cc_os_tasks.h | 81 +++++------------- .../terravisor/cc_os/utils/cc_os_sched.h | 4 + .../services/kernel/cc_os_task_idle.c | 2 +- .../terravisor/services/kernel/cc_os_tasks.c | 83 ++++++++++++------- 7 files changed, 96 insertions(+), 103 deletions(-) diff --git a/.gitignore b/.gitignore index ab7fa0de..ca29638c 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,3 @@ bkp/ *.mod* *.cmd *.todo - -.vscode/compile_commands.json - -.vscode/settings.json diff --git a/projects/demo_cc_os.src/project.c b/projects/demo_cc_os.src/project.c index a1973e0f..153f8ab0 100644 --- a/projects/demo_cc_os.src/project.c +++ b/projects/demo_cc_os.src/project.c @@ -15,10 +15,11 @@ #define TASK_WAIT_TICKS 10 -/* Define the Tasks */ -CC_TASK_DEF( TASK_A, task_handler, NULL, 10, 100); -CC_TASK_DEF( TASK_B, task_handler, NULL, 10, 100); -CC_TASK_DEF( TASK_C, task_handler, NULL, 10, 100); +extern void task_handler(cc_os_args args); + +cc_os_task_t * Task_A; +cc_os_task_t * Task_B; +cc_os_task_t * Task_C; /* Define Plug */ void plug() @@ -27,9 +28,9 @@ void plug() driver_setup_all(); printf("Demo CC OS Program!\n"); - cc_os_add_task(&CC_GET_TASK_INST(TASK_A)); - cc_os_add_task(&CC_GET_TASK_INST(TASK_B)); - cc_os_add_task(&CC_GET_TASK_INST(TASK_C)); + cc_os_add_task(Task_A, "Task A", &task_handler, NULL, 10, 255, (uintptr_t) NULL); + cc_os_add_task(Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); + cc_os_add_task(Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); cc_os_run(); } @@ -41,7 +42,7 @@ void play() } /* Define the Task Handler */ -void task_handler(os_args args _UNUSED) +void task_handler(cc_os_args args _UNUSED) { while(CC_OS_TRUE) { diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.h b/src/include/visor/terravisor/cc_os/cc_os_config.h index 5ca697b1..bdb0f3e1 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.h +++ b/src/include/visor/terravisor/cc_os/cc_os_config.h @@ -36,6 +36,14 @@ #define CC_OS_MAX_THREAD 10 #endif +#ifndef CC_OS_IDLE_TASK_NAME +#define CC_OS_IDLE_TASK_NAME "CC_OS_IDLE" +#endif + +#ifndef CC_OS_IDLE_STACK_LEN +#define CC_OS_IDLE_STACK_LEN 255 +#endif + /** * @brief Task priority of IDLE task * @note Possible values : 1 -> 255 diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index 3de13ca7..12bf3086 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -22,64 +22,15 @@ /***************************************************** * TYPEDEFS *****************************************************/ -typedef const void * os_args; -typedef void (*task_fn)(os_args args); - /** - * @brief TASK infrastructure structure + * @brief TASK infrastructure * */ -typedef struct cc_os_task -{ - task_fn task_fn; ///>> Task funcion - os_args args; ///>> Task Args ptr - c_char *name; ///>> String name of the task - uintptr_t stack_ptr; ///>> Stack pointer of the task - uint8_t priority; ///>> For waited tasks - size_t stack_len; ///>> Stack lengths of the task - cc_sched_tcb_t *task_tcb_ptr; ///>> For internal use only -} cc_os_task_t; +typedef cc_sched_tcb_t * cc_os_task_t; /***************************************************** * MACROS *****************************************************/ -/** - * @brief Function to declare a static task with a dedicated stack for the task - * @brief Usage: CC_TASK_DEF(TASK_Name, task_func_pointer, priority(int), stack_len(int)); - * - * @note DO NOT use space in place of TASK_Name as it would result build errors. - * - */ -#if CC_OS_DYNAMIC == CC_OS_FALSE -#define CC_TASK_DEF(_NAME, _fn, _args, _PRI, STACK_LEN) \ - extern void _fn (os_args args); \ - static uint8_t _NAME##_stack[STACK_LEN]; \ - static cc_os_task_t _NAME##_task = { \ - .args = _args, \ - .task_fn = _fn, \ - .name = #_NAME, \ - .priority = _PRI, \ - .stack_ptr = (uintptr_t) _NAME##_stack, \ - .stack_len = STACK_LEN} -#else -#define CC_TASK_DEF(_NAME, _fn, _args, _PRI, STACK_LEN) \ - extern void _fn (os_args args); \ - static cc_os_task_t _NAME##_task = { \ - .args = _args, \ - .task_fn = _fn, \ - .name = #_NAME, \ - .priority = _PRI, \ - .stack_ptr = (uintptr_t) CC_OS_NULL_PTR, \ - .stack_len = STACK_LEN} -#endif -/** - * @brief Function to get the instance using its name of already declared task. - * @brief Usage: cc_os_task_t * task = &(CC_GET_TASK_INST(TASK_Name)); - * - * @note DO NOT use space in place of TASK_Name as it would result build errors. - * - */ -#define CC_GET_TASK_INST(_NAME) _NAME##_task /***************************************************** * USER FUNCTION DECLARATIONS @@ -87,39 +38,51 @@ typedef struct cc_os_task /** * @brief A Function to add a task to the scheduler * - * @param cc_os_task[in_out] pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task + * + * @param cc_os_task[out] Pointer to the TASK_instance + * @param name[in] Conatant Name string provided by the user + * @param task_func[in] Pointer to the task function + * @param args[in] Pointer to the argument variable provided to the task + * @param priority[in] Task Priority: 1->255 + * @param stack_len[in] Task stack length + * @param stack_ptr[in] Pointer to static stack for static allocation only. + * * @return status_t */ -status_t cc_os_add_task(cc_os_task_t *cc_os_task); +status_t cc_os_add_task ( + cc_os_task_t * cc_os_task, const char* name, + task_fn task_func, cc_os_args args, + uint8_t priority,size_t stack_len, + uintptr_t stack_ptr); /** * @brief A function to delete a task from the scheduler by instance * - * @param cc_os_task[in] pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task; + * @param cc_os_task[in] pointer to the TASK_instance; * Pass NULL to point to current task * @return status_t */ -status_t cc_os_del_task(cc_os_task_t *cc_os_task); +status_t cc_os_del_task(cc_os_task_t cc_os_task); /** * @brief A Function to pause the task until call resume explicitly using its instance * - * @param cc_os_task[in] pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task; + * @param cc_os_task[in] pointer to the TASK_instance; * Pass NULL to point to current task * @return status_t */ -status_t cc_os_pause_task(cc_os_task_t *cc_os_task); +status_t cc_os_pause_task(cc_os_task_t cc_os_task); /** * * @brief A Function to resume paused task using its instance * @note Calling this function for already non-waiting task has no effect. * - * @param cc_os_task[in] pointer to the TASK_instance; use CC_GET_TASK_INST(Name) to get the Defined Task; + * @param cc_os_task[in] pointer to the TASK_instance; * Pass NULL to point to current task * @return status_t */ -status_t cc_os_resume_task(cc_os_task_t *cc_os_task); +status_t cc_os_resume_task(cc_os_task_t cc_os_task); /** * @brief A Function to pause all the tasks except the current and the IDLE Task diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 770bed1e..0bd73cbe 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -35,6 +35,8 @@ typedef struct cc_sched_tcb cc_sched_tcb_t; typedef struct cc_sched cc_sched_t; typedef const char c_char; +typedef const void * cc_os_args; +typedef void (*task_fn)(cc_os_args args); typedef enum { @@ -62,6 +64,8 @@ struct cc_sched_tcb c_char * name; ///> Name of the Current Task uint8_t priority; ///> Priority of the task uintptr_t stack_ptr; ///> Stack Pointer + task_fn task_func; ///> Task Call Function + uintptr_t args_ptr; ///> Task Call argument ptr wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers link_t wait_link; ///> Wait Linked List Pointers diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index 43bd7d62..66d55d02 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -45,7 +45,7 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) /***************************************************** * USER FUNCTION DEFINATION *****************************************************/ -void _cc_os_idle_task_fn(os_args args) +void _cc_os_idle_task_fn(cc_os_args args) { const cc_sched_ctrl_t * sched_ctrl = (const cc_sched_ctrl_t *) args; static cc_sched_tcb_t * ptr = CC_OS_NULL_PTR; diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index c62cf9e1..04b3bcd2 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -34,7 +34,7 @@ extern void _cc_sched_send_to_resume (cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb /***************************************************** * GLOBAL EXTERNS VARIABLES *****************************************************/ -extern cc_sched_t *g_cc_sched; +extern void _cc_os_idle_task_fn(cc_os_args args); extern cc_sched_t g_cc_sched_list []; extern cc_sched_ctrl_t g_sched_ctrl; @@ -47,13 +47,12 @@ extern cc_sched_tcb_t g_cc_os_tcb_list[]; extern cc_sched_tcb_t *g_cc_os_tcb_list; #endif -CC_TASK_DEF( - cc_os_idle, /* Name of the instance */ - _cc_os_idle_task_fn, /* Function pointer */ - &g_sched_ctrl, /* Task Args*/ - CC_OS_IDLE_TASK_PRIORITY, /* Task Priority */ - CC_OS_TASK_STACK_LEN /* Stack Length of IDLE Task */ -); +#if CC_OS_DYNAMIC == CC_OS_FALSE +uint8_t _cc_os_stack[CC_OS_IDLE_STACK_LEN]; +#else +uint8_t * _cc_os_stack = CC_OS_NULL_PTR; +#endif +cc_os_task_t * cc_os_idle_task; /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ @@ -64,15 +63,25 @@ void __cc_init_scheduler() /***************************************************** * USER FUNCTION DEFINATIONS *****************************************************/ -status_t cc_os_add_task (cc_os_task_t * cc_os_task) +status_t cc_os_add_task ( + cc_os_task_t * cc_os_task, + const char* name, + task_fn task_func, + cc_os_args args, + uint8_t priority, + size_t stack_len, + uintptr_t stack_ptr + ) { - CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(cc_os_task->name != CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(cc_os_task->stack_ptr != (uintptr_t) CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(cc_os_task->task_fn != CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(cc_os_task->stack_len != CC_OS_FALSE); - CC_OS_ASSERT_IF_FALSE(cc_os_task->priority >= CC_OS_IDLE_TASK_PRIORITY); - CC_OS_ASSERT_IF_FALSE(cc_os_task->priority < CC_OS_PRIORITY_MAX); + CC_OS_ASSERT_IF_FALSE(cc_os_task == CC_OS_NULL_PTR); + CC_OS_ASSERT_IF_FALSE(name != CC_OS_NULL_PTR); +#if CC_OS_DYNAMIC == CC_OS_FALSE + CC_OS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t) CC_OS_NULL_PTR); +#endif + CC_OS_ASSERT_IF_FALSE(task_func != CC_OS_NULL_PTR); + CC_OS_ASSERT_IF_FALSE(stack_len != CC_OS_FALSE); + CC_OS_ASSERT_IF_FALSE(priority >= CC_OS_IDLE_TASK_PRIORITY); + CC_OS_ASSERT_IF_FALSE(priority < CC_OS_PRIORITY_MAX); cc_os_pause_all_task(); @@ -86,7 +95,7 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) if (ptr == CC_OS_NULL_PTR) { cc_os_resume_all_task(); - return error_os_task_overfow; + return error_memory_low; } } #endif @@ -117,14 +126,21 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) { #endif /* Fill tcb details */ - ptr->name = cc_os_task->name; - ptr->stack_ptr = (uintptr_t) malloc(cc_os_task->stack_len); - ptr->priority = cc_os_task->priority; + ptr->name = name; + ptr->stack_ptr = (uintptr_t) malloc(stack_len); + if(ptr->stack_ptr == CC_OS_NULL_PTR) + { + cc_os_resume_all_task(); + return error_memory_low; + } + ptr->priority = priority; + ptr->task_func = task_func; + ptr->args_ptr = (uintptr_t) args; } else { cc_os_resume_all_task(); - return error_os_task_overfow; + return error_memory_low; } } /* Insert Tasks in assending order of its priority */ @@ -160,22 +176,22 @@ status_t cc_os_add_task (cc_os_task_t * cc_os_task) } } - cc_os_task->task_tcb_ptr = ptr; + *cc_os_task = ptr; ptr->task_status = cc_sched_task_status_ready; cc_os_resume_all_task(); return success; } -status_t cc_os_del_task (cc_os_task_t * cc_os_task) +status_t cc_os_del_task (cc_os_task_t cc_os_task) { - CC_OS_ASSERT_IF_FALSE(cc_os_task->task_fn != _cc_os_idle_task_fn); + CC_OS_ASSERT_IF_FALSE(cc_os_task->task_func != &_cc_os_idle_task_fn); cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; if (cc_os_task != CC_OS_NULL_PTR) { - ptr = cc_os_task->task_tcb_ptr; + ptr = cc_os_task; } /* Code to handle first node */ if (ptr == g_sched_ctrl.ready_list_head) @@ -193,12 +209,12 @@ status_t cc_os_del_task (cc_os_task_t * cc_os_task) return success; } -status_t cc_os_pause_task (cc_os_task_t * cc_os_task) +status_t cc_os_pause_task (cc_os_task_t cc_os_task) { cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; if (cc_os_task != CC_OS_NULL_PTR) { - ptr = cc_os_task->task_tcb_ptr; + ptr = cc_os_task; } _cc_sched_send_to_wait(&g_sched_ctrl, ptr, CC_OS_DELAY_MAX); @@ -247,11 +263,11 @@ status_t cc_os_resume_all_task (void) return success; } -status_t cc_os_resume_task (cc_os_task_t * cc_os_task) +status_t cc_os_resume_task (cc_os_task_t cc_os_task) { CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); - cc_sched_tcb_t * ptr = cc_os_task->task_tcb_ptr; + cc_sched_tcb_t * ptr = cc_os_task; _cc_sched_send_to_resume(&g_sched_ctrl, ptr); @@ -292,9 +308,14 @@ void cc_os_task_yield() void cc_os_run (void) { /* OS Init code */ - /* Initialise IDLE Task */ - cc_os_add_task(&CC_GET_TASK_INST(cc_os_idle)); + cc_os_add_task(cc_os_idle_task, + CC_OS_IDLE_TASK_NAME, + &_cc_os_idle_task_fn, + &g_sched_ctrl, + CC_OS_IDLE_TASK_PRIORITY, + CC_OS_IDLE_STACK_LEN, + (uintptr_t) _cc_os_stack); /* Initialise scheduler */ __cc_init_scheduler(); From 8f9e401155cff6b35f1c8f821d4c50fb121b50f9 Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Thu, 5 Jan 2023 14:18:30 +0530 Subject: [PATCH 08/22] Compilation fixed --- projects/demo_cc_os_avr/cc_os_config.mk | 4 ++-- projects/demo_cc_os_riscv/cc_os_config.mk | 4 ++-- src/include/visor/terravisor/cc_os/cc_os_config.h | 4 ++-- src/include/visor/terravisor/cc_os/cc_os_config.mk | 4 ++-- src/visor/terravisor/services/kernel/cc_os_tasks.c | 12 ++++++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk index 215c4300..ff7002c5 100644 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -10,8 +10,8 @@ CC_OS_USE_DYNAMIC := 1 CC_OS_HEAP_SIZE := 1024 -CC_OS_MAX_THREAD := 3 -CC_OS_TASK_STACK_LEN := 255 +CC_OS_MAX_THREAD := 4 +CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk index c8e63fc8..b4c26302 100644 --- a/projects/demo_cc_os_riscv/cc_os_config.mk +++ b/projects/demo_cc_os_riscv/cc_os_config.mk @@ -10,8 +10,8 @@ CC_OS_USE_DYNAMIC := 1 CC_OS_HEAP_SIZE := 1024 -CC_OS_MAX_THREAD := 3 -CC_OS_TASK_STACK_LEN := 255 +CC_OS_MAX_THREAD := 4 +CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.h b/src/include/visor/terravisor/cc_os/cc_os_config.h index bdb0f3e1..9896252c 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.h +++ b/src/include/visor/terravisor/cc_os/cc_os_config.h @@ -57,8 +57,8 @@ * @note The stack size is either allocated statically or dynamically as * per the setting of CC_OS_USE_DYNAMIC */ -#ifndef CC_OS_TASK_STACK_LEN -#define CC_OS_TASK_STACK_LEN 255 +#ifndef CC_OS_IDLE_TASK_STACK_LEN +#define CC_OS_IDLE_TASK_STACK_LEN 255 #endif /** diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.mk b/src/include/visor/terravisor/cc_os/cc_os_config.mk index ce9244a0..36e4e629 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.mk +++ b/src/include/visor/terravisor/cc_os/cc_os_config.mk @@ -11,11 +11,11 @@ CC_OS_USE_DYNAMIC ?= 0 CC_OS_HEAP_SIZE ?= 1024 CC_OS_MAX_THREAD ?= 2 -CC_OS_TASK_STACK_LEN ?= 255 +CC_OS_IDLE_TASK_STACK_LEN ?= 255 CC_OS_POWER_SAVE_EN ?= 0 $(eval $(call add_define,CC_OS_USE_DYNAMIC)) $(eval $(call add_define,CC_OS_HEAP_SIZE)) $(eval $(call add_define,CC_OS_MAX_THREAD)) -$(eval $(call add_define,CC_OS_TASK_STACK_LEN)) +$(eval $(call add_define,CC_OS_IDLE_TASK_STACK_LEN)) $(eval $(call add_define,CC_OS_POWER_SAVE_EN)) diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 04b3bcd2..003dbb42 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -71,6 +71,9 @@ status_t cc_os_add_task ( uint8_t priority, size_t stack_len, uintptr_t stack_ptr +#if CC_OS_DYNAMIC == CC_OS_TRUE + _UNUSED +#endif ) { CC_OS_ASSERT_IF_FALSE(cc_os_task == CC_OS_NULL_PTR); @@ -119,20 +122,21 @@ status_t cc_os_add_task ( } if (ptr != g_sched_ctrl.ready_list_head) { + ptr->stack_ptr = stack_ptr; #else /* Dynamic Task Declaration */ ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); if (ptr != CC_OS_NULL_PTR) { -#endif - /* Fill tcb details */ - ptr->name = name; ptr->stack_ptr = (uintptr_t) malloc(stack_len); - if(ptr->stack_ptr == CC_OS_NULL_PTR) + if(ptr->stack_ptr == (uintptr_t) CC_OS_NULL_PTR) { cc_os_resume_all_task(); return error_memory_low; } +#endif + /* Fill tcb details */ + ptr->name = name; ptr->priority = priority; ptr->task_func = task_func; ptr->args_ptr = (uintptr_t) args; From 6192e165fa39fff1434a4b4f394fedd7f5f55f1c Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Fri, 6 Jan 2023 18:43:12 +0530 Subject: [PATCH 09/22] Semaphore bug fix Signed-off-by: panjalchanda08 --- .gitignore | 1 + src/include/visor/terravisor/cc_os/cc_os_sem.h | 4 ++-- src/visor/terravisor/services/kernel/cc_os_sem.c | 12 +++--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index ca29638c..350231a1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ out/ tools/ backup/ bkp/ +.vscode/ *.elf *.bin *.d diff --git a/src/include/visor/terravisor/cc_os/cc_os_sem.h b/src/include/visor/terravisor/cc_os/cc_os_sem.h index e6dc2a92..2534c715 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_sem.h +++ b/src/include/visor/terravisor/cc_os/cc_os_sem.h @@ -32,10 +32,10 @@ static sem_t _Name##_sem = { \ .sem_init = 0, \ .sem_val = 0 \ }; \ -static sem_t * _Name##_sem_inst = &_Name##_sem +sem_t * _Name##_sem_inst = &_Name##_sem #else #define CC_SEM_DEF(_Name) \ -static sem_t * _Name##_sem_inst = CC_OS_NULL_PTR +sem_t * _Name##_sem_inst = CC_OS_NULL_PTR #endif /***************************************************** * USER FUNCTION DECLARATIONS diff --git a/src/visor/terravisor/services/kernel/cc_os_sem.c b/src/visor/terravisor/services/kernel/cc_os_sem.c index ceba6718..1655e76f 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sem.c +++ b/src/visor/terravisor/services/kernel/cc_os_sem.c @@ -33,9 +33,6 @@ status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val) { #if CC_OS_DYNAMIC == CC_OS_FALSE CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init == CC_OS_FALSE)); - - (*sem_ptr)->sem_init = CC_OS_TRUE; - (*sem_ptr)->sem_val = init_val; #else CC_OS_ASSERT_IF_FALSE(*sem_ptr == CC_OS_NULL_PTR); *sem_ptr = cc_os_malloc(sizeof(sem_t)); @@ -43,13 +40,10 @@ status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val) { return error_memory_low; } - else - { - (*sem_ptr)->sem_val = init_val; - (*sem_ptr)->sem_init = CC_OS_TRUE; - } - #endif + (*sem_ptr)->sem_val = init_val; + (*sem_ptr)->sem_init = CC_OS_TRUE; + return success; } status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks) From bdb8cd739a7c8fa071a857532be34802de8907ff Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Tue, 10 Jan 2023 11:52:53 +0530 Subject: [PATCH 10/22] Review Commit --- mk/path.mk | 1 - projects/demo_cc_os.src/project.c | 12 +- projects/demo_cc_os_avr/build.mk | 1 + projects/demo_cc_os_avr/cc_os_config.mk | 2 - projects/demo_cc_os_avr/config.mk | 4 +- projects/demo_cc_os_riscv/build.mk | 1 + projects/demo_cc_os_riscv/cc_os_config.mk | 2 - projects/demo_cc_os_riscv/config.mk | 2 - .../visor/terravisor/cc_os/cc_os_sem.h | 2 +- .../terravisor/cc_os/utils/cc_os_sched.h | 2 - src/visor/terravisor/services/kernel/build.mk | 1 + .../services/kernel}/cc_os_config.mk | 6 +- .../terravisor/services/kernel/cc_os_sched.c | 152 +++++++++--------- .../terravisor/services/kernel/cc_os_sem.c | 22 +-- .../services/kernel/cc_os_task_idle.c | 4 +- .../terravisor/services/kernel/cc_os_tasks.c | 22 +-- 16 files changed, 111 insertions(+), 125 deletions(-) rename src/{include/visor/terravisor/cc_os => visor/terravisor/services/kernel}/cc_os_config.mk (81%) diff --git a/mk/path.mk b/mk/path.mk index 540666a0..24318b40 100644 --- a/mk/path.mk +++ b/mk/path.mk @@ -18,7 +18,6 @@ TOOLS_ROOT ?= $(abspath $(CC_ROOT))/tools MISC_TOOLS := $(TOOLS_ROOT)/misc_bins SRC := $(CC_ROOT)/src -CC_OS_ROOT := $(SRC)/include/visor/terravisor/cc_os OUT_PATH ?= $(CC_ROOT)/out OUT ?= $(OUT_PATH)/$(PROJECT) diff --git a/projects/demo_cc_os.src/project.c b/projects/demo_cc_os.src/project.c index 153f8ab0..17d2b0ac 100644 --- a/projects/demo_cc_os.src/project.c +++ b/projects/demo_cc_os.src/project.c @@ -15,11 +15,11 @@ #define TASK_WAIT_TICKS 10 -extern void task_handler(cc_os_args args); +void task_handler(cc_os_args args); -cc_os_task_t * Task_A; -cc_os_task_t * Task_B; -cc_os_task_t * Task_C; +static cc_os_task_t * Task_A; +static cc_os_task_t * Task_B; +static cc_os_task_t * Task_C; /* Define Plug */ void plug() @@ -30,7 +30,7 @@ void plug() printf("Demo CC OS Program!\n"); cc_os_add_task(Task_A, "Task A", &task_handler, NULL, 10, 255, (uintptr_t) NULL); cc_os_add_task(Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); - cc_os_add_task(Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); + cc_os_add_task(Task_C, "Task C", &task_handler, NULL, 10, 255, (uintptr_t) NULL); cc_os_run(); } @@ -44,7 +44,7 @@ void play() /* Define the Task Handler */ void task_handler(cc_os_args args _UNUSED) { - while(CC_OS_TRUE) + while(true) { printf("In Task: %s\n", cc_os_get_curr_task_name()); cc_os_task_wait(TASK_WAIT_TICKS); diff --git a/projects/demo_cc_os_avr/build.mk b/projects/demo_cc_os_avr/build.mk index b51f75ab..b5ea41ab 100644 --- a/projects/demo_cc_os_avr/build.mk +++ b/projects/demo_cc_os_avr/build.mk @@ -13,6 +13,7 @@ PROJECT_DIR := $(GET_PATH) include $(PROJECT_DIR)/../demo_cc_os.src/build.mk include $(PROJECT_DIR)/config.mk +include $(PROJECT_DIR)/cc_os_config.mk DIR := $(PROJECT_DIR) include mk/obj.mk diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk index ff7002c5..0c754189 100644 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -13,5 +13,3 @@ CC_OS_HEAP_SIZE := 1024 CC_OS_MAX_THREAD := 4 CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 - -include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/projects/demo_cc_os_avr/config.mk b/projects/demo_cc_os_avr/config.mk index 70242aac..605e289f 100644 --- a/projects/demo_cc_os_avr/config.mk +++ b/projects/demo_cc_os_avr/config.mk @@ -12,7 +12,7 @@ COMPILER := gcc TC_VER := 5.4.0 FAMILY := mega_avr PLATFORM := atmega328p -HEAP_SIZE := 256 +HEAP_SIZE := 500 STACK_SIZE := 256 STDLOG_MEMBUF := 0 BOOTMSGS := 0 @@ -20,5 +20,3 @@ EARLYCON_SERIAL := 0 CONSOLE_SERIAL := 0 OBRDLED_ENABLE := 1 TERRAKERN := 1 - -include $(PROJECT_DIR)/cc_os_config.mk diff --git a/projects/demo_cc_os_riscv/build.mk b/projects/demo_cc_os_riscv/build.mk index b51f75ab..b5ea41ab 100644 --- a/projects/demo_cc_os_riscv/build.mk +++ b/projects/demo_cc_os_riscv/build.mk @@ -13,6 +13,7 @@ PROJECT_DIR := $(GET_PATH) include $(PROJECT_DIR)/../demo_cc_os.src/build.mk include $(PROJECT_DIR)/config.mk +include $(PROJECT_DIR)/cc_os_config.mk DIR := $(PROJECT_DIR) include mk/obj.mk diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk index b4c26302..fdc7b1c9 100644 --- a/projects/demo_cc_os_riscv/cc_os_config.mk +++ b/projects/demo_cc_os_riscv/cc_os_config.mk @@ -13,5 +13,3 @@ CC_OS_HEAP_SIZE := 1024 CC_OS_MAX_THREAD := 4 CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 - -include $(CC_OS_ROOT)/cc_os_config.mk diff --git a/projects/demo_cc_os_riscv/config.mk b/projects/demo_cc_os_riscv/config.mk index 2d0b8d10..475c4f2c 100644 --- a/projects/demo_cc_os_riscv/config.mk +++ b/projects/demo_cc_os_riscv/config.mk @@ -20,5 +20,3 @@ EARLYCON_SERIAL := 0 CONSOLE_SERIAL := 0 OBRDLED_ENABLE := 1 TERRAKERN := 1 - -include $(PROJECT_DIR)/cc_os_config.mk diff --git a/src/include/visor/terravisor/cc_os/cc_os_sem.h b/src/include/visor/terravisor/cc_os/cc_os_sem.h index 2534c715..0f6acf29 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_sem.h +++ b/src/include/visor/terravisor/cc_os/cc_os_sem.h @@ -26,7 +26,7 @@ typedef struct sem *****************************************************/ #define CC_SEM_INST(_Name) _Name##_sem_inst -#if CC_OS_DYNAMIC == CC_OS_FALSE +#if CC_OS_DYNAMIC == false #define CC_SEM_DEF(_Name) \ static sem_t _Name##_sem = { \ .sem_init = 0, \ diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 0bd73cbe..e74cdc76 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -20,8 +20,6 @@ /***************************************************** * DEFINES *****************************************************/ -#define CC_OS_FALSE 0 -#define CC_OS_TRUE 1 #define CC_OS_NULL_PTR NULL #define CC_OS_DELAY_MAX ((size_t) -1) diff --git a/src/visor/terravisor/services/kernel/build.mk b/src/visor/terravisor/services/kernel/build.mk index bf5a3d5c..8564489b 100644 --- a/src/visor/terravisor/services/kernel/build.mk +++ b/src/visor/terravisor/services/kernel/build.mk @@ -10,4 +10,5 @@ DIR := $(GET_PATH) +include $(DIR)/cc_os_config.mk include mk/obj.mk diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.mk b/src/visor/terravisor/services/kernel/cc_os_config.mk similarity index 81% rename from src/include/visor/terravisor/cc_os/cc_os_config.mk rename to src/visor/terravisor/services/kernel/cc_os_config.mk index 36e4e629..a524cec8 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_config.mk +++ b/src/visor/terravisor/services/kernel/cc_os_config.mk @@ -2,13 +2,13 @@ # CYANCORE LICENSE # Copyrights (C) 2019, Cyancore Team # -# File Name : kern_config.mk +# File Name : cc_os_config.mk # Description : This file consists of CC_OS kernal configuration -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Primary Author : Pranjal Chanda[pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # -CC_OS_USE_DYNAMIC ?= 0 +CC_OS_USE_DYNAMIC ?= 1 CC_OS_HEAP_SIZE ?= 1024 CC_OS_MAX_THREAD ?= 2 CC_OS_IDLE_TASK_STACK_LEN ?= 255 diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index 3f1f060d..676c5b80 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -45,8 +45,8 @@ cc_sched_t g_cc_sched_list [] = cc_sched_ctrl_t g_sched_ctrl = { #if !CC_OS_USE_DYNAMIC - .ready_list_head = &(g_cc_os_tcb_list[CC_OS_FALSE]), - .curr_task = &(g_cc_os_tcb_list[CC_OS_FALSE]), + .ready_list_head = &(g_cc_os_tcb_list[false]), + .curr_task = &(g_cc_os_tcb_list[false]), #else .ready_list_head = CC_OS_NULL_PTR, .curr_task = CC_OS_NULL_PTR, @@ -62,84 +62,78 @@ cc_sched_ctrl_t g_sched_ctrl = status_t _insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) { CC_OS_ASSERT_IF_FALSE(new_node != CC_OS_NULL_PTR); - switch (link_type) + if (link_type == true) { - case CC_OS_FALSE: - /* Ready Link */ - if (*ptr == CC_OS_NULL_PTR) - { - *ptr = new_node; - new_node->ready_link.next = new_node; - new_node->ready_link.prev = new_node; - } - else - { - new_node->ready_link.next = (*ptr)->ready_link.next; - new_node->ready_link.prev = *ptr; - new_node->ready_link.next->ready_link.prev = new_node; - (*ptr)->ready_link.next = new_node; - } - break; - case CC_OS_TRUE: - /* Wait Link */ - if (*ptr == CC_OS_NULL_PTR) - { - *ptr = new_node; - new_node->wait_link.next = new_node; - new_node->wait_link.prev = new_node; - } - else - { - new_node->wait_link.next = (*ptr)->wait_link.next; - new_node->wait_link.prev = *ptr; - new_node->wait_link.next->wait_link.prev = new_node; - (*ptr)->wait_link.next = new_node; - } - break; - default: - return error_os_invalid_op; + /* Wait Link */ + if (*ptr == CC_OS_NULL_PTR) + { + *ptr = new_node; + new_node->wait_link.next = new_node; + new_node->wait_link.prev = new_node; + } + else + { + new_node->wait_link.next = (*ptr)->wait_link.next; + new_node->wait_link.prev = *ptr; + new_node->wait_link.next->wait_link.prev = new_node; + (*ptr)->wait_link.next = new_node; + } + } + else + { + /* Ready Link */ + if (*ptr == CC_OS_NULL_PTR) + { + *ptr = new_node; + new_node->ready_link.next = new_node; + new_node->ready_link.prev = new_node; + } + else + { + new_node->ready_link.next = (*ptr)->ready_link.next; + new_node->ready_link.prev = *ptr; + new_node->ready_link.next->ready_link.prev = new_node; + (*ptr)->ready_link.next = new_node; + } } return success; } status_t _insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) { CC_OS_ASSERT_IF_FALSE(new_node != CC_OS_NULL_PTR); - switch (link_type) + if (link_type == true) { - case CC_OS_FALSE: - /* Ready Link */ - if (*ptr == CC_OS_NULL_PTR) - { - *ptr = new_node; - new_node->ready_link.next = new_node; - new_node->ready_link.prev = new_node; - } - else - { - new_node->ready_link.next = *ptr; - new_node->ready_link.prev = (*ptr)->ready_link.prev; - (*ptr)->ready_link.prev = new_node; - new_node->ready_link.prev->ready_link.next = new_node; - } - break; - case CC_OS_TRUE: - /* Wait Link */ - if (*ptr == CC_OS_NULL_PTR) - { - *ptr = new_node; - new_node->wait_link.next = new_node; - new_node->wait_link.prev = new_node; - } - else - { - new_node->wait_link.next = *ptr; - new_node->wait_link.prev = (*ptr)->wait_link.prev; - (*ptr)->wait_link.prev = new_node; - new_node->wait_link.prev->wait_link.next = new_node; - } - break; - default: - return error_os_invalid_op; + /* Wait Link */ + if (*ptr == CC_OS_NULL_PTR) + { + *ptr = new_node; + new_node->wait_link.next = new_node; + new_node->wait_link.prev = new_node; + } + else + { + new_node->wait_link.next = *ptr; + new_node->wait_link.prev = (*ptr)->wait_link.prev; + (*ptr)->wait_link.prev = new_node; + new_node->wait_link.prev->wait_link.next = new_node; + } + } + else + { + /* Ready Link */ + if (*ptr == CC_OS_NULL_PTR) + { + *ptr = new_node; + new_node->ready_link.next = new_node; + new_node->ready_link.prev = new_node; + } + else + { + new_node->ready_link.next = *ptr; + new_node->ready_link.prev = (*ptr)->ready_link.prev; + (*ptr)->ready_link.prev = new_node; + new_node->ready_link.prev->ready_link.next = new_node; + } } return success; } @@ -150,7 +144,7 @@ void _cc_sched_send_to_wait(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, { return; } - if(_insert_before(&(sched_ctrl->wait_list_head), ptr, CC_OS_TRUE) == success) + if(_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) { ptr->wait_res.task_delay_ticks = ticks; ptr->task_status = cc_sched_task_status_wait; @@ -178,7 +172,7 @@ void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr ptr->wait_link.next->wait_link.prev = ptr->wait_link.prev; ptr->wait_link.prev = CC_OS_NULL_PTR; ptr->wait_link.next = CC_OS_NULL_PTR; - ptr->wait_res.task_delay_ticks = CC_OS_FALSE; + ptr->wait_res.task_delay_ticks = false; ptr->task_status = cc_sched_task_status_ready; } @@ -193,18 +187,18 @@ static void __cc_sched_context_switch(cc_sched_tcb_t * next_task) static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) { cc_sched_tcb_t * ptr = sched_ctrl->wait_list_head; - const size_t * wait_res = (size_t *)ptr->wait_res.wait_on_resource; + const int * wait_res = (int *)ptr->wait_res.wait_on_resource; while(ptr != CC_OS_NULL_PTR) { ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ - if ((wait_res != CC_OS_NULL_PTR) && *wait_res) + if ((wait_res != CC_OS_NULL_PTR) && *wait_res > false) { /* The resource is available can can go to ready state */ - ptr->wait_res.task_delay_ticks = CC_OS_FALSE; - ptr->wait_res.wait_on_resource = CC_OS_FALSE; + ptr->wait_res.task_delay_ticks = false; + ptr->wait_res.wait_on_resource = false; } - if(ptr->wait_res.task_delay_ticks == CC_OS_FALSE) + if(ptr->wait_res.task_delay_ticks == false) { _cc_sched_send_to_resume(sched_ctrl, ptr); } diff --git a/src/visor/terravisor/services/kernel/cc_os_sem.c b/src/visor/terravisor/services/kernel/cc_os_sem.c index 1655e76f..3703b5db 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sem.c +++ b/src/visor/terravisor/services/kernel/cc_os_sem.c @@ -31,8 +31,8 @@ extern cc_sched_ctrl_t g_sched_ctrl; status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val) { -#if CC_OS_DYNAMIC == CC_OS_FALSE - CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init == CC_OS_FALSE)); +#if CC_OS_DYNAMIC == false + CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init == false)); #else CC_OS_ASSERT_IF_FALSE(*sem_ptr == CC_OS_NULL_PTR); *sem_ptr = cc_os_malloc(sizeof(sem_t)); @@ -42,17 +42,17 @@ status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val) } #endif (*sem_ptr)->sem_val = init_val; - (*sem_ptr)->sem_init = CC_OS_TRUE; + (*sem_ptr)->sem_init = true; return success; } status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks) { - CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != CC_OS_FALSE)); + CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != false)); - if (sem_ptr->sem_val == CC_OS_FALSE) + if (sem_ptr->sem_val == false) { - if (wait_ticks == CC_OS_FALSE) /* ||_IS_ISR */ + if (wait_ticks == false) /* ||_IS_ISR */ { return error_os_sem_get; } @@ -69,7 +69,7 @@ status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks) } status_t cc_os_sem_give (sem_t * sem_ptr) { - CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != CC_OS_FALSE)); + CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != false)); sem_ptr->sem_val++; @@ -77,11 +77,11 @@ status_t cc_os_sem_give (sem_t * sem_ptr) } status_t cc_os_sem_delete (sem_t ** sem_ptr) { - CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init != CC_OS_FALSE)); + CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init != false)); - (*sem_ptr)->sem_init = CC_OS_FALSE; + (*sem_ptr)->sem_init = false; -#if CC_OS_DYNAMIC == CC_OS_TRUE +#if CC_OS_DYNAMIC == true cc_os_free(*sem_ptr); #endif @@ -89,7 +89,7 @@ status_t cc_os_sem_delete (sem_t ** sem_ptr) } status_t cc_os_sem_get_val (const sem_t * sem_ptr, size_t * val) { - CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != CC_OS_FALSE)); + CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != false)); CC_OS_ASSERT_IF_FALSE(val != CC_OS_NULL_PTR); *val = sem_ptr->sem_val; diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index 66d55d02..4d8de0c5 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -30,7 +30,7 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) ptr->ready_link.prev->ready_link.next = ptr->ready_link.next; ptr->ready_link.next->ready_link.prev = ptr->ready_link.prev; -#if CC_OS_DYNAMIC == CC_OS_FALSE +#if CC_OS_DYNAMIC == false ptr->ready_link.next = CC_OS_NULL_PTR; ptr->ready_link.prev = CC_OS_NULL_PTR; #else @@ -50,7 +50,7 @@ void _cc_os_idle_task_fn(cc_os_args args) const cc_sched_ctrl_t * sched_ctrl = (const cc_sched_ctrl_t *) args; static cc_sched_tcb_t * ptr = CC_OS_NULL_PTR; ptr = sched_ctrl->ready_list_head; - while (CC_OS_TRUE) + while (true) { /* Clean up task if terminated */ ptr = __free_terminated_task(ptr); diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 003dbb42..6fab4555 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -41,13 +41,13 @@ extern cc_sched_ctrl_t g_sched_ctrl; /***************************************************** * GLOBAL DECLARATIONS *****************************************************/ -#if CC_OS_DYNAMIC == CC_OS_FALSE +#if CC_OS_DYNAMIC == false extern cc_sched_tcb_t g_cc_os_tcb_list[]; #else extern cc_sched_tcb_t *g_cc_os_tcb_list; #endif -#if CC_OS_DYNAMIC == CC_OS_FALSE +#if CC_OS_DYNAMIC == false uint8_t _cc_os_stack[CC_OS_IDLE_STACK_LEN]; #else uint8_t * _cc_os_stack = CC_OS_NULL_PTR; @@ -71,18 +71,18 @@ status_t cc_os_add_task ( uint8_t priority, size_t stack_len, uintptr_t stack_ptr -#if CC_OS_DYNAMIC == CC_OS_TRUE +#if CC_OS_DYNAMIC == true _UNUSED #endif ) { CC_OS_ASSERT_IF_FALSE(cc_os_task == CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(name != CC_OS_NULL_PTR); -#if CC_OS_DYNAMIC == CC_OS_FALSE +#if CC_OS_DYNAMIC == false CC_OS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t) CC_OS_NULL_PTR); #endif CC_OS_ASSERT_IF_FALSE(task_func != CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(stack_len != CC_OS_FALSE); + CC_OS_ASSERT_IF_FALSE(stack_len != false); CC_OS_ASSERT_IF_FALSE(priority >= CC_OS_IDLE_TASK_PRIORITY); CC_OS_ASSERT_IF_FALSE(priority < CC_OS_PRIORITY_MAX); @@ -90,7 +90,7 @@ status_t cc_os_add_task ( cc_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head; -#if CC_OS_DYNAMIC == CC_OS_TRUE +#if CC_OS_DYNAMIC == true if (ptr == CC_OS_NULL_PTR) { /* First Dynamic task */ @@ -109,9 +109,9 @@ status_t cc_os_add_task ( else { -#if CC_OS_DYNAMIC == CC_OS_FALSE +#if CC_OS_DYNAMIC == false /* Static Task Allocation */ - for (size_t i = CC_OS_FALSE; i < CC_OS_MAX_THREAD; i++) + for (size_t i = false; i < CC_OS_MAX_THREAD; i++) { /* Get an available node from global tcb list */ if (g_cc_os_tcb_list[i].task_status == cc_sched_task_status_exit) @@ -154,7 +154,7 @@ status_t cc_os_add_task ( } else if(g_sched_ctrl.task_max_prio->priority <= ptr->priority) { - if(_insert_after(&(g_sched_ctrl.task_max_prio), ptr, CC_OS_FALSE) == success) + if(_insert_after(&(g_sched_ctrl.task_max_prio), ptr, false) == success) { g_sched_ctrl.task_max_prio = ptr; } @@ -169,7 +169,7 @@ status_t cc_os_add_task ( cc_sched_tcb_t * comp_ptr = g_sched_ctrl.task_max_prio->ready_link.next; while (1) { - if (comp_ptr->priority <= ptr->priority && (_insert_after(&comp_ptr, ptr, CC_OS_FALSE) == success)) + if (comp_ptr->priority <= ptr->priority && (_insert_after(&comp_ptr, ptr, false) == success)) { break; } @@ -296,7 +296,7 @@ void cc_os_task_wait (const size_t ticks) { cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; - if (ticks > CC_OS_FALSE) + if (ticks > false) { _cc_sched_send_to_wait(&g_sched_ctrl, ptr, ticks); } From 8fe9e074087593729eddac2148e1bcb5d0049efe Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Thu, 12 Jan 2023 12:58:27 +0530 Subject: [PATCH 11/22] Comment changes --- .gitignore | 87 +++++++++++++++-------------- .vscode/c_cpp_properties.json | 3 +- projects/demo_cc_os.src/build.mk | 2 +- projects/demo_cc_os.src/project.c | 2 +- projects/demo_cc_os_riscv/config.mk | 4 +- 5 files changed, 50 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 350231a1..07daea91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,43 +1,44 @@ -.scannerwork -sonar-cfamily-reproducer.zip -temp -out/ -tools/ -backup/ -bkp/ -.vscode/ -*.elf -*.bin -*.d -*.o -*.ko -*.obj -*.dll -*.so -*.so.* -*.dylib -*.lib -*.la -*.lo -*.a -*.ilk -*.map -*.dis -*.new -*.bkp -*.backup -*.b -*.dev -*.old -*.temp -*.tmp -*.sw* -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex -*.mod* -*.cmd -*.todo +.scannerwork +.vscode/ +sonar-cfamily-reproducer.zip +temp +out/ +tools/ +backup/ +bkp/ +projects/ +*.elf +*.bin +*.d +*.o +*.ko +*.obj +*.dll +*.so +*.so.* +*.dylib +*.lib +*.la +*.lo +*.a +*.ilk +*.map +*.dis +*.new +*.bkp +*.backup +*.b +*.dev +*.old +*.temp +*.tmp +*.sw* +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +*.mod* +*.cmd +*.todo diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index e1140042..f4353993 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -8,7 +8,8 @@ "intelliSenseMode": "${default}", "compilerPath": "/usr/bin/gcc", "cStandard": "gnu17", - "cppStandard": "gnu++14" + "cppStandard": "gnu++14", + "compileCommands": "${workspaceFolder}/.vscode/compile_commands.json" } ], "version": 4 diff --git a/projects/demo_cc_os.src/build.mk b/projects/demo_cc_os.src/build.mk index 7a5e071a..d44adcf3 100644 --- a/projects/demo_cc_os.src/build.mk +++ b/projects/demo_cc_os.src/build.mk @@ -5,7 +5,7 @@ # File Name : build.mk # Description : This file build project sources and specifies # project properties -# Primary Author : Pranjal Chdanda [pranjalchanda08@gmail.com] +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # diff --git a/projects/demo_cc_os.src/project.c b/projects/demo_cc_os.src/project.c index 17d2b0ac..345a4928 100644 --- a/projects/demo_cc_os.src/project.c +++ b/projects/demo_cc_os.src/project.c @@ -1,6 +1,6 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2019 - 2023, Cyancore Team * * File Name : project.c * Description : This file consists of project srouces diff --git a/projects/demo_cc_os_riscv/config.mk b/projects/demo_cc_os_riscv/config.mk index 475c4f2c..f36fd2de 100644 --- a/projects/demo_cc_os_riscv/config.mk +++ b/projects/demo_cc_os_riscv/config.mk @@ -16,7 +16,7 @@ HEAP_SIZE := 256 STACK_SIZE := 256 STDLOG_MEMBUF := 0 BOOTMSGS := 0 -EARLYCON_SERIAL := 0 -CONSOLE_SERIAL := 0 +EARLYCON_SERIAL := 1 +CONSOLE_SERIAL := 1 OBRDLED_ENABLE := 1 TERRAKERN := 1 From e67cec7891eb9271ec27fee9abc578b398cc6764 Mon Sep 17 00:00:00 2001 From: panjalchanda08 Date: Sat, 14 Jan 2023 15:16:41 +0530 Subject: [PATCH 12/22] Callback sys, Power save user callback Signed-off-by: panjalchanda08 --- .../visor/terravisor/cc_os/cc_os_tasks.h | 10 +++++- .../terravisor/cc_os/utils/cc_os_sched.h | 25 ++++++++++++--- .../services/kernel/cc_os_task_idle.c | 30 ++++++++++++++++-- .../terravisor/services/kernel/cc_os_tasks.c | 31 ++++++++++++++++++- 4 files changed, 87 insertions(+), 9 deletions(-) diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index 12bf3086..6066b228 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -51,7 +51,7 @@ typedef cc_sched_tcb_t * cc_os_task_t; */ status_t cc_os_add_task ( cc_os_task_t * cc_os_task, const char* name, - task_fn task_func, cc_os_args args, + task_fn_t task_func, cc_os_args args, uint8_t priority,size_t stack_len, uintptr_t stack_ptr); @@ -107,6 +107,14 @@ status_t cc_os_resume_all_task(void); */ status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo); +/** + * @brief A function to set the functional callback hooks + * + * @param cb_type[in] Callback type which user would like to register + * @param cb_func[in] Callback hook function associated to the cb_type + * @return status_t + */ +status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func); /** * @brief Get name of current running task * diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index e74cdc76..7b5be62e 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -33,9 +33,9 @@ typedef struct cc_sched_tcb cc_sched_tcb_t; typedef struct cc_sched cc_sched_t; typedef const char c_char; -typedef const void * cc_os_args; -typedef void (*task_fn)(cc_os_args args); - +typedef void * cc_os_args; +typedef void (*task_fn_t)(cc_os_args args); +typedef void (*cc_cb_hook_t)(void); typedef enum { cc_sched_task_status_exit = 0x00, ///> Initial State @@ -45,6 +45,13 @@ typedef enum cc_sched_task_status_max = 0xff, ///> Do Nt Use } cc_sched_task_status_t; +typedef enum +{ + cc_sched_cb_power_pre_sleep = 0x00, + cc_sched_cb_power_post_sleep = 0x01, + cc_sched_cb_power_sleep = 0x02, +}cc_sched_cb_t; + typedef struct link { cc_sched_tcb_t * prev; @@ -62,7 +69,7 @@ struct cc_sched_tcb c_char * name; ///> Name of the Current Task uint8_t priority; ///> Priority of the task uintptr_t stack_ptr; ///> Stack Pointer - task_fn task_func; ///> Task Call Function + task_fn_t task_func; ///> Task Call Function uintptr_t args_ptr; ///> Task Call argument ptr wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers @@ -70,6 +77,15 @@ struct cc_sched_tcb cc_sched_task_status_t task_status; ///> Current state of the task }; +typedef struct cc_sched_func_cb +{ +#if CC_OS_POWER_SAVE_EN + cc_cb_hook_t pre_sleep_cb; + cc_cb_hook_t post_sleep_cb; + cc_cb_hook_t sleep_cb; +#endif +}cc_sched_func_cb_t; + typedef struct cc_sched_ctrl { cc_sched_tcb_t * ready_list_head; @@ -77,6 +93,7 @@ typedef struct cc_sched_ctrl cc_sched_tcb_t * wait_list_head; cc_sched_tcb_t * task_max_prio; cc_sched_t * selected_sched; + cc_sched_func_cb_t cb_hooks_reg; }cc_sched_ctrl_t; /** diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index 4d8de0c5..af1925fb 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -12,6 +12,7 @@ * INCLUDES *****************************************************/ #include +#include /***************************************************** * STATIC FUNCTION DECLARATION @@ -42,14 +43,26 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) return next_ptr; } +#if CC_OS_POWER_SAVE_EN +static void __cc_power_save_callback(void) +{ + arch_wfi(); +} +#endif /***************************************************** * USER FUNCTION DEFINATION *****************************************************/ void _cc_os_idle_task_fn(cc_os_args args) { - const cc_sched_ctrl_t * sched_ctrl = (const cc_sched_ctrl_t *) args; - static cc_sched_tcb_t * ptr = CC_OS_NULL_PTR; + static cc_sched_tcb_t * ptr = CC_OS_NULL_PTR; + cc_sched_ctrl_t * sched_ctrl = (cc_sched_ctrl_t *) args; ptr = sched_ctrl->ready_list_head; +#if CC_OS_POWER_SAVE_EN + if (sched_ctrl->cb_hooks_reg.sleep_cb == CC_OS_NULL_PTR) + { + sched_ctrl->cb_hooks_reg.sleep_cb = __cc_power_save_callback; + } +#endif while (true) { /* Clean up task if terminated */ @@ -57,7 +70,18 @@ void _cc_os_idle_task_fn(cc_os_args args) #if CC_OS_POWER_SAVE_EN /* Power Save code */ - + if (sched_ctrl->cb_hooks_reg.pre_sleep_cb != CC_OS_NULL_PTR) + { + sched_ctrl->cb_hooks_reg.pre_sleep_cb(); + } + if (sched_ctrl->cb_hooks_reg.sleep_cb != CC_OS_NULL_PTR) + { + sched_ctrl->cb_hooks_reg.sleep_cb(); + } + if (sched_ctrl->cb_hooks_reg.post_sleep_cb != CC_OS_NULL_PTR) + { + sched_ctrl->cb_hooks_reg.post_sleep_cb(); + } #endif /* Yield for next available task */ cc_os_task_yield(); diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 6fab4555..b2af3f1c 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -66,7 +66,7 @@ void __cc_init_scheduler() status_t cc_os_add_task ( cc_os_task_t * cc_os_task, const char* name, - task_fn task_func, + task_fn_t task_func, cc_os_args args, uint8_t priority, size_t stack_len, @@ -287,6 +287,35 @@ status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo) return success; } +status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func _UNUSED) +{ + if (cb_type == cc_sched_cb_power_post_sleep) + { +#if CC_OS_POWER_SAVE_EN + g_sched_ctrl.cb_hooks_reg.post_sleep_cb = cb_func; +#else + return error_func_inval_arg; +#endif + } + if (cb_type == cc_sched_cb_power_pre_sleep) + { +#if CC_OS_POWER_SAVE_EN + g_sched_ctrl.cb_hooks_reg.pre_sleep_cb = cb_func; +#else + return error_func_inval_arg; +#endif + } + if (cb_type == cc_sched_cb_power_sleep) + { +#if CC_OS_POWER_SAVE_EN + g_sched_ctrl.cb_hooks_reg.sleep_cb = cb_func; +#else + return error_func_inval_arg; +#endif + } + return success; +} + const char * cc_os_get_curr_task_name(void) { return g_sched_ctrl.curr_task->name; From 4249fcee383cc63d109948e117ff2ad6c222af6d Mon Sep 17 00:00:00 2001 From: Pranjal Chanda <40349163+pranjalchanda08@users.noreply.github.com> Date: Sun, 15 Jan 2023 15:18:01 +0530 Subject: [PATCH 13/22] - cc_os_config.h done by cc_os_config.mk (#208) Signed-off-by: panjalchanda08 --- .../visor/terravisor/cc_os/cc_os_config.h | 70 ------------------- .../visor/terravisor/cc_os/cc_os_tasks.h | 1 - .../services/kernel/cc_os_config.mk | 4 ++ .../terravisor/services/kernel/cc_os_sched.c | 1 - .../terravisor/services/kernel/cc_os_tasks.c | 3 +- 5 files changed, 5 insertions(+), 74 deletions(-) delete mode 100644 src/include/visor/terravisor/cc_os/cc_os_config.h diff --git a/src/include/visor/terravisor/cc_os/cc_os_config.h b/src/include/visor/terravisor/cc_os/cc_os_config.h deleted file mode 100644 index 9896252c..00000000 --- a/src/include/visor/terravisor/cc_os/cc_os_config.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2022, Cyancore Team - * - * File Name : cc_os_config.h - * Description : CC OS Kernel configurations - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once - -/** - * @brief Shall CC_OS use dynamic resource allocation - * @note Possible values : 1/0 - */ -#ifndef CC_OS_USE_DYNAMIC -#define CC_OS_USE_DYNAMIC 1 -#endif - -/** - * @brief Heap size to be allocated to CC_OS - * @note Possible values : Depends on available RAM - */ -#ifndef CC_OS_HEAP_SIZE -#define CC_OS_HEAP_SIZE 1024 -#endif - -/** - * @brief Maximum number of threads allowed in static resource allocation - * @note The number of allowed threads are dependent of available RAM space. - * User may have to keep it optimised so as to use as low BSS section - * to be used as possible for the application being created. - */ -#ifndef CC_OS_MAX_THREAD -#define CC_OS_MAX_THREAD 10 -#endif - -#ifndef CC_OS_IDLE_TASK_NAME -#define CC_OS_IDLE_TASK_NAME "CC_OS_IDLE" -#endif - -#ifndef CC_OS_IDLE_STACK_LEN -#define CC_OS_IDLE_STACK_LEN 255 -#endif - -/** - * @brief Task priority of IDLE task - * @note Possible values : 1 -> 255 - */ -#ifndef CC_OS_IDLE_TASK_PRIORITY -#define CC_OS_IDLE_TASK_PRIORITY 0x01 -#endif - -/** - * @brief Stack size used by IDLE task - * @note The stack size is either allocated statically or dynamically as - * per the setting of CC_OS_USE_DYNAMIC - */ -#ifndef CC_OS_IDLE_TASK_STACK_LEN -#define CC_OS_IDLE_TASK_STACK_LEN 255 -#endif - -/** - * @brief If the Kernel shall enter poer save mode during IDLE - * - */ -#ifndef CC_OS_POWER_SAVE_EN -#define CC_OS_POWER_SAVE_EN 0 -#endif diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index 6066b228..cfa3879f 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -16,7 +16,6 @@ #include "status.h" #include "stdlib.h" #include "stdint.h" -#include #include /***************************************************** diff --git a/src/visor/terravisor/services/kernel/cc_os_config.mk b/src/visor/terravisor/services/kernel/cc_os_config.mk index a524cec8..aca0eef5 100644 --- a/src/visor/terravisor/services/kernel/cc_os_config.mk +++ b/src/visor/terravisor/services/kernel/cc_os_config.mk @@ -11,11 +11,15 @@ CC_OS_USE_DYNAMIC ?= 1 CC_OS_HEAP_SIZE ?= 1024 CC_OS_MAX_THREAD ?= 2 +CC_OS_IDLE_TASK_PRIORITY := 1 +CC_OS_IDLE_TASK_NAME ?= \"CC_OS_IDLE\" CC_OS_IDLE_TASK_STACK_LEN ?= 255 CC_OS_POWER_SAVE_EN ?= 0 $(eval $(call add_define,CC_OS_USE_DYNAMIC)) $(eval $(call add_define,CC_OS_HEAP_SIZE)) $(eval $(call add_define,CC_OS_MAX_THREAD)) +$(eval $(call add_define,CC_OS_IDLE_TASK_NAME)) +$(eval $(call add_define,CC_OS_IDLE_TASK_PRIORITY)) $(eval $(call add_define,CC_OS_IDLE_TASK_STACK_LEN)) $(eval $(call add_define,CC_OS_POWER_SAVE_EN)) diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index 676c5b80..9459899c 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -11,7 +11,6 @@ /***************************************************** * INCLUDES *****************************************************/ -#include #include /***************************************************** diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index b2af3f1c..bbc65337 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -15,7 +15,6 @@ #include #include #include -#include #include /***************************************************** @@ -347,7 +346,7 @@ void cc_os_run (void) &_cc_os_idle_task_fn, &g_sched_ctrl, CC_OS_IDLE_TASK_PRIORITY, - CC_OS_IDLE_STACK_LEN, + CC_OS_IDLE_TASK_STACK_LEN, (uintptr_t) _cc_os_stack); /* Initialise scheduler */ From d480238caa58a7dab4b30b13fb57014b5b15b3a6 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Thu, 26 Jan 2023 23:08:38 +0530 Subject: [PATCH 14/22] Anti-deadlock task functions add. --- projects/demo_cc_os_avr/cc_os_config.mk | 1 + projects/demo_cc_os_riscv/cc_os_config.mk | 1 + .../visor/terravisor/cc_os/cc_os_tasks.h | 23 ++ .../terravisor/cc_os/utils/cc_os_sched.h | 18 ++ .../services/kernel/cc_os_config.mk | 4 +- .../terravisor/services/kernel/cc_os_tasks.c | 214 ++++++++++++------ 6 files changed, 189 insertions(+), 72 deletions(-) diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk index 0c754189..822dab10 100644 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -13,3 +13,4 @@ CC_OS_HEAP_SIZE := 1024 CC_OS_MAX_THREAD := 4 CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 +CC_OS_FEATURE_ANTI_DEADLOCK := 0 diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk index fdc7b1c9..bdfd227f 100644 --- a/projects/demo_cc_os_riscv/cc_os_config.mk +++ b/projects/demo_cc_os_riscv/cc_os_config.mk @@ -13,3 +13,4 @@ CC_OS_HEAP_SIZE := 1024 CC_OS_MAX_THREAD := 4 CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 +CC_OS_FEATURE_ANTI_DEADLOCK := 0 diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index cfa3879f..14cc436a 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -143,3 +143,26 @@ void cc_os_task_yield(void); * @return status_t */ void cc_os_run(void); + +/** + * @brief A function to enable anti-deadlock for the task and feed timer value to scheduler. The same shall be used to reset the task watchdog to keep the task alive. + * @note 1. For this feature user needs to enable CC_OS_FEATURE_ANTI_DEADLOCK flag. + * @note 2. CC_OS does NOT keep the reference of previously set watchdog tick value. + * It is the responsibility of the user to feed the required number of ticks for the tasks to be considered alive. + * @note 3. User needs to set an user callback of type cc_sched_cb_deadlock_notify using cc_os_set_callback(). + * @note 4. This fucntion shall be called from the Task atleast once for the timer to get stared. + * @note 5. This function is only allowed to be called from within the task. + * + * @param task_wd_ticks[in] Watchdog counter reset val. + * + * @return status_t + */ +status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks); + +/** + * @brief A function to disable anti deadlock for the task. + * @note This function shall be called form within the task itself. + * + * @return status_t + */ +status_t cc_os_task_anti_deadlock_disable(void); diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 7b5be62e..e99dad3e 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -45,13 +45,23 @@ typedef enum cc_sched_task_status_max = 0xff, ///> Do Nt Use } cc_sched_task_status_t; +/* + * @note All negative callbacks are internally used by the scheduler + */ typedef enum { + cc_sched_cb_pre_sched = -0x01, cc_sched_cb_power_pre_sleep = 0x00, cc_sched_cb_power_post_sleep = 0x01, cc_sched_cb_power_sleep = 0x02, + cc_sched_cb_deadlock_notify = 0x03, + cc_sched_cb_max = 0x04 }cc_sched_cb_t; +typedef enum +{ + cc_task_flag_set_anti_deadlock = (1 << 0) ///> Enable Antideadlock for the task +}cc_task_flag_t; typedef struct link { cc_sched_tcb_t * prev; @@ -68,22 +78,30 @@ struct cc_sched_tcb { c_char * name; ///> Name of the Current Task uint8_t priority; ///> Priority of the task + uint8_t task_flags; ///> Task Flags uintptr_t stack_ptr; ///> Stack Pointer task_fn_t task_func; ///> Task Call Function uintptr_t args_ptr; ///> Task Call argument ptr wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers link_t wait_link; ///> Wait Linked List Pointers +#if CC_OS_FEATURE_ANTI_DEADLOCK + size_t task_wd_ticks; ///> Tick down counter for Anti Deadlock system +#endif cc_sched_task_status_t task_status; ///> Current state of the task }; typedef struct cc_sched_func_cb { + cc_cb_hook_t pre_sched; #if CC_OS_POWER_SAVE_EN cc_cb_hook_t pre_sleep_cb; cc_cb_hook_t post_sleep_cb; cc_cb_hook_t sleep_cb; #endif +#if CC_OS_FEATURE_ANTI_DEADLOCK + cc_cb_hook_t deadlock_notify; +#endif }cc_sched_func_cb_t; typedef struct cc_sched_ctrl diff --git a/src/visor/terravisor/services/kernel/cc_os_config.mk b/src/visor/terravisor/services/kernel/cc_os_config.mk index aca0eef5..c9728c07 100644 --- a/src/visor/terravisor/services/kernel/cc_os_config.mk +++ b/src/visor/terravisor/services/kernel/cc_os_config.mk @@ -8,13 +8,14 @@ # Organisation : Cyancore Core-Team # +CC_OS_IDLE_TASK_PRIORITY := 1 CC_OS_USE_DYNAMIC ?= 1 CC_OS_HEAP_SIZE ?= 1024 CC_OS_MAX_THREAD ?= 2 -CC_OS_IDLE_TASK_PRIORITY := 1 CC_OS_IDLE_TASK_NAME ?= \"CC_OS_IDLE\" CC_OS_IDLE_TASK_STACK_LEN ?= 255 CC_OS_POWER_SAVE_EN ?= 0 +CC_OS_FEATURE_ANTI_DEADLOCK ?= 1 $(eval $(call add_define,CC_OS_USE_DYNAMIC)) $(eval $(call add_define,CC_OS_HEAP_SIZE)) @@ -23,3 +24,4 @@ $(eval $(call add_define,CC_OS_IDLE_TASK_NAME)) $(eval $(call add_define,CC_OS_IDLE_TASK_PRIORITY)) $(eval $(call add_define,CC_OS_IDLE_TASK_STACK_LEN)) $(eval $(call add_define,CC_OS_POWER_SAVE_EN)) +$(eval $(call add_define,CC_OS_FEATURE_ANTI_DEADLOCK)) diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index bbc65337..98214932 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -20,21 +20,21 @@ /***************************************************** * DEFINES *****************************************************/ -#define CC_OS_PRIORITY_MAX 255 +#define CC_OS_PRIORITY_MAX 255 /***************************************************** * INTERNAL EXTERNS FUNCTIONS *****************************************************/ -extern status_t _insert_after (cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type); -extern status_t _insert_before (cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type); -extern void _cc_sched_send_to_wait (cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, const size_t ticks); -extern void _cc_sched_send_to_resume (cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr); +extern status_t _insert_after(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); +extern status_t _insert_before(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); +extern void _cc_sched_send_to_wait(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr, const size_t ticks); +extern void _cc_sched_send_to_resume(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr); /***************************************************** * GLOBAL EXTERNS VARIABLES *****************************************************/ extern void _cc_os_idle_task_fn(cc_os_args args); -extern cc_sched_t g_cc_sched_list []; +extern cc_sched_t g_cc_sched_list[]; extern cc_sched_ctrl_t g_sched_ctrl; /***************************************************** @@ -49,36 +49,59 @@ extern cc_sched_tcb_t *g_cc_os_tcb_list; #if CC_OS_DYNAMIC == false uint8_t _cc_os_stack[CC_OS_IDLE_STACK_LEN]; #else -uint8_t * _cc_os_stack = CC_OS_NULL_PTR; +uint8_t *_cc_os_stack = CC_OS_NULL_PTR; #endif -cc_os_task_t * cc_os_idle_task; +cc_os_task_t *cc_os_idle_task; /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ -void __cc_init_scheduler() +static void __cc_init_scheduler() { return; } +static status_t __cc_os_set_task_flag(cc_os_task_t cc_os_task, cc_task_flag_t task_flag, bool en) +{ + CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); + + if (en) + { + cc_os_task->task_flags |= (uint8_t)task_flag; + } + else + { + cc_os_task->task_flags &= (uint8_t)~task_flag; + } + return success; +} +static bool __cc_os_is_task_flag(const cc_sched_tcb_t *cc_os_task, cc_task_flag_t task_flag) +{ + if (cc_os_task != CC_OS_NULL_PTR) + { + return (cc_os_task->task_flags & task_flag) == false; + } + + return false; +} /***************************************************** * USER FUNCTION DEFINATIONS *****************************************************/ -status_t cc_os_add_task ( - cc_os_task_t * cc_os_task, - const char* name, - task_fn_t task_func, - cc_os_args args, - uint8_t priority, - size_t stack_len, - uintptr_t stack_ptr +status_t cc_os_add_task( + cc_os_task_t *cc_os_task, + const char *name, + task_fn_t task_func, + cc_os_args args, + uint8_t priority, + size_t stack_len, + uintptr_t stack_ptr #if CC_OS_DYNAMIC == true _UNUSED -#endif - ) +#endif /* CC_OS_DYNAMIC */ +) { CC_OS_ASSERT_IF_FALSE(cc_os_task == CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(name != CC_OS_NULL_PTR); #if CC_OS_DYNAMIC == false - CC_OS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t) CC_OS_NULL_PTR); + CC_OS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t)CC_OS_NULL_PTR); #endif CC_OS_ASSERT_IF_FALSE(task_func != CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(stack_len != false); @@ -87,7 +110,7 @@ status_t cc_os_add_task ( cc_os_pause_all_task(); - cc_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head; + cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; #if CC_OS_DYNAMIC == true if (ptr == CC_OS_NULL_PTR) @@ -100,8 +123,8 @@ status_t cc_os_add_task ( return error_memory_low; } } -#endif - if ((ptr->ready_link.next == CC_OS_NULL_PTR )&& (ptr->ready_link.prev == CC_OS_NULL_PTR)) +#endif /* CC_OS_DYNAMIC */ + if ((ptr->ready_link.next == CC_OS_NULL_PTR) && (ptr->ready_link.prev == CC_OS_NULL_PTR)) { ptr->ready_link.next = ptr->ready_link.prev = g_sched_ctrl.ready_list_head; } @@ -127,18 +150,21 @@ status_t cc_os_add_task ( ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); if (ptr != CC_OS_NULL_PTR) { - ptr->stack_ptr = (uintptr_t) malloc(stack_len); - if(ptr->stack_ptr == (uintptr_t) CC_OS_NULL_PTR) + ptr->stack_ptr = (uintptr_t)malloc(stack_len); + if (ptr->stack_ptr == (uintptr_t)CC_OS_NULL_PTR) { cc_os_resume_all_task(); return error_memory_low; } -#endif +#endif /* CC_OS_DYNAMIC */ /* Fill tcb details */ - ptr->name = name; - ptr->priority = priority; - ptr->task_func = task_func; - ptr->args_ptr = (uintptr_t) args; + ptr->name = name; + ptr->priority = priority; + ptr->task_func = task_func; + ptr->args_ptr = (uintptr_t)args; +#if CC_OS_FEATURE_ANTI_DEADLOCK + ptr->task_wd_ticks = SIZE_MAX; +#endif /* CC_OS_FEATURE_ANTI_DEADLOCK */ } else { @@ -151,9 +177,9 @@ status_t cc_os_add_task ( { g_sched_ctrl.task_max_prio = ptr; } - else if(g_sched_ctrl.task_max_prio->priority <= ptr->priority) + else if (g_sched_ctrl.task_max_prio->priority <= ptr->priority) { - if(_insert_after(&(g_sched_ctrl.task_max_prio), ptr, false) == success) + if (_insert_after(&(g_sched_ctrl.task_max_prio), ptr, false) == success) { g_sched_ctrl.task_max_prio = ptr; } @@ -165,7 +191,7 @@ status_t cc_os_add_task ( } else { - cc_sched_tcb_t * comp_ptr = g_sched_ctrl.task_max_prio->ready_link.next; + cc_sched_tcb_t *comp_ptr = g_sched_ctrl.task_max_prio->ready_link.next; while (1) { if (comp_ptr->priority <= ptr->priority && (_insert_after(&comp_ptr, ptr, false) == success)) @@ -181,16 +207,15 @@ status_t cc_os_add_task ( *cc_os_task = ptr; ptr->task_status = cc_sched_task_status_ready; - cc_os_resume_all_task(); return success; } -status_t cc_os_del_task (cc_os_task_t cc_os_task) +status_t cc_os_del_task(cc_os_task_t cc_os_task) { CC_OS_ASSERT_IF_FALSE(cc_os_task->task_func != &_cc_os_idle_task_fn); - cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; + cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; if (cc_os_task != CC_OS_NULL_PTR) { @@ -202,19 +227,19 @@ status_t cc_os_del_task (cc_os_task_t cc_os_task) /* IDLE Task can not be deleted */ return error_os_invalid_op; } - ptr->task_status = cc_sched_task_status_exit; + ptr->task_status = cc_sched_task_status_exit; if (ptr == g_sched_ctrl.curr_task) { - cc_os_task_yield(); /* Yeild */ + cc_os_task_yield(); /* Yeild */ } return success; } -status_t cc_os_pause_task (cc_os_task_t cc_os_task) +status_t cc_os_pause_task(cc_os_task_t cc_os_task) { - cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; + cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; if (cc_os_task != CC_OS_NULL_PTR) { ptr = cc_os_task; @@ -225,9 +250,9 @@ status_t cc_os_pause_task (cc_os_task_t cc_os_task) return success; } -status_t cc_os_pause_all_task (void) +status_t cc_os_pause_all_task(void) { - cc_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head->ready_link.next; + cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head->ready_link.next; while (ptr != g_sched_ctrl.ready_list_head) { @@ -243,9 +268,9 @@ status_t cc_os_pause_all_task (void) return success; } -status_t cc_os_resume_all_task (void) +status_t cc_os_resume_all_task(void) { - cc_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head->ready_link.next; + cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head->ready_link.next; if (ptr != CC_OS_NULL_PTR) { while (ptr != g_sched_ctrl.ready_list_head) @@ -266,11 +291,11 @@ status_t cc_os_resume_all_task (void) return success; } -status_t cc_os_resume_task (cc_os_task_t cc_os_task) +status_t cc_os_resume_task(cc_os_task_t cc_os_task) { CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); - cc_sched_tcb_t * ptr = cc_os_task; + cc_sched_tcb_t *ptr = cc_os_task; _cc_sched_send_to_resume(&g_sched_ctrl, ptr); @@ -286,43 +311,90 @@ status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo) return success; } +status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks _UNUSED) +{ +#if CC_OS_FEATURE_ANTI_DEADLOCK + CC_OS_ASSERT_IF_FALSE((task_wd_ticks > false) && (task_wd_ticks < SIZE_MAX)); + + cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + if (__cc_os_is_task_flag(ptr, cc_task_flag_set_anti_deadlock)) + { + __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, true); + } + + ptr->task_wd_ticks = task_wd_ticks; + return success; +#else + cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + if (__cc_os_is_task_flag(ptr, cc_task_flag_set_anti_deadlock)) + { + __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, false); + } + return error_func_inval; +#endif /* CC_OS_FEATURE_ANTI_DEADLOCK */ +} + +status_t cc_os_task_anti_deadlock_disable(void) +{ + cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + + if (__cc_os_is_task_flag(ptr, cc_task_flag_set_anti_deadlock)) + { + __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, false); + } + +#if CC_OS_FEATURE_ANTI_DEADLOCK + ptr->task_wd_ticks = SIZE_MAX; + return success; +#else + return error_func_inval; +#endif /* CC_OS_FEATURE_ANTI_DEADLOCK */ +} status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func _UNUSED) { - if (cb_type == cc_sched_cb_power_post_sleep) + CC_OS_ASSERT_IF_FALSE(cb_type >= cc_sched_cb_power_pre_sleep); + + status_t ret = success; + switch (cb_type) { + case cc_sched_cb_pre_sched: + g_sched_ctrl.cb_hooks_reg.pre_sched = cb_func; + break; + case cc_sched_cb_power_post_sleep: #if CC_OS_POWER_SAVE_EN g_sched_ctrl.cb_hooks_reg.post_sleep_cb = cb_func; -#else - return error_func_inval_arg; + break; #endif - } - if (cb_type == cc_sched_cb_power_pre_sleep) - { + case cc_sched_cb_power_pre_sleep: #if CC_OS_POWER_SAVE_EN g_sched_ctrl.cb_hooks_reg.pre_sleep_cb = cb_func; -#else - return error_func_inval_arg; + break; #endif - } - if (cb_type == cc_sched_cb_power_sleep) - { + case cc_sched_cb_power_sleep: #if CC_OS_POWER_SAVE_EN - g_sched_ctrl.cb_hooks_reg.sleep_cb = cb_func; -#else - return error_func_inval_arg; + g_sched_ctrl.cb_hooks_reg.power_sleep = cb_func; + break; +#endif + case cc_sched_cb_deadlock_notify: +#if CC_OS_FEATURE_ANTI_DEADLOCK + g_sched_ctrl.cb_hooks_reg.deadlock_notify = cb_func; + break; #endif + case cc_sched_cb_max: + ret = error_func_inval; + break; } - return success; + return ret; } -const char * cc_os_get_curr_task_name(void) +const char *cc_os_get_curr_task_name(void) { return g_sched_ctrl.curr_task->name; } -void cc_os_task_wait (const size_t ticks) +void cc_os_task_wait(const size_t ticks) { - cc_sched_tcb_t * ptr = g_sched_ctrl.curr_task; + cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; if (ticks > false) { @@ -337,17 +409,17 @@ void cc_os_task_yield() return; } -void cc_os_run (void) +void cc_os_run(void) { /* OS Init code */ /* Initialise IDLE Task */ cc_os_add_task(cc_os_idle_task, - CC_OS_IDLE_TASK_NAME, - &_cc_os_idle_task_fn, - &g_sched_ctrl, - CC_OS_IDLE_TASK_PRIORITY, - CC_OS_IDLE_TASK_STACK_LEN, - (uintptr_t) _cc_os_stack); + CC_OS_IDLE_TASK_NAME, + &_cc_os_idle_task_fn, + &g_sched_ctrl, + CC_OS_IDLE_TASK_PRIORITY, + CC_OS_IDLE_TASK_STACK_LEN, + (uintptr_t)_cc_os_stack); /* Initialise scheduler */ __cc_init_scheduler(); From e888812c6a810069835ab82a2f73b43348222620 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Fri, 27 Jan 2023 13:17:24 +0530 Subject: [PATCH 15/22] Anti-deadlock scheduler function and Pre-sched callback added. Added Pause state --- projects/demo_cc_os_avr/cc_os_config.mk | 2 +- projects/demo_cc_os_riscv/cc_os_config.mk | 2 +- .../visor/terravisor/cc_os/cc_os_tasks.h | 4 +- .../terravisor/cc_os/utils/cc_os_sched.h | 24 ++-- .../services/kernel/cc_os_config.mk | 4 +- .../terravisor/services/kernel/cc_os_sched.c | 117 +++++++++++++++--- .../terravisor/services/kernel/cc_os_tasks.c | 46 +++---- 7 files changed, 147 insertions(+), 52 deletions(-) diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk index 822dab10..178c1a57 100644 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ b/projects/demo_cc_os_avr/cc_os_config.mk @@ -13,4 +13,4 @@ CC_OS_HEAP_SIZE := 1024 CC_OS_MAX_THREAD := 4 CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 -CC_OS_FEATURE_ANTI_DEADLOCK := 0 +CC_OS_ANTI_DEADLOCK := 0 diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk index bdfd227f..05fa1d78 100644 --- a/projects/demo_cc_os_riscv/cc_os_config.mk +++ b/projects/demo_cc_os_riscv/cc_os_config.mk @@ -13,4 +13,4 @@ CC_OS_HEAP_SIZE := 1024 CC_OS_MAX_THREAD := 4 CC_OS_IDLE_TASK_STACK_LEN := 255 CC_OS_POWER_SAVE_EN := 0 -CC_OS_FEATURE_ANTI_DEADLOCK := 0 +CC_OS_ANTI_DEADLOCK := 0 diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index 14cc436a..da87b400 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -146,11 +146,11 @@ void cc_os_run(void); /** * @brief A function to enable anti-deadlock for the task and feed timer value to scheduler. The same shall be used to reset the task watchdog to keep the task alive. - * @note 1. For this feature user needs to enable CC_OS_FEATURE_ANTI_DEADLOCK flag. + * @note 1. For this feature user needs to enable CC_OS_ANTI_DEADLOCK flag. * @note 2. CC_OS does NOT keep the reference of previously set watchdog tick value. * It is the responsibility of the user to feed the required number of ticks for the tasks to be considered alive. * @note 3. User needs to set an user callback of type cc_sched_cb_deadlock_notify using cc_os_set_callback(). - * @note 4. This fucntion shall be called from the Task atleast once for the timer to get stared. + * @note 4. This fucntion shall be called from the Task atleast once for the timer to get started. * @note 5. This function is only allowed to be called from within the task. * * @param task_wd_ticks[in] Watchdog counter reset val. diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index e99dad3e..3566b58f 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -21,7 +21,7 @@ * DEFINES *****************************************************/ #define CC_OS_NULL_PTR NULL -#define CC_OS_DELAY_MAX ((size_t) -1) +#define CC_OS_DELAY_MAX SIZE_MAX #define CC_OS_DYNAMIC CC_OS_USE_DYNAMIC @@ -35,13 +35,14 @@ typedef struct cc_sched cc_sched_t; typedef const char c_char; typedef void * cc_os_args; typedef void (*task_fn_t)(cc_os_args args); -typedef void (*cc_cb_hook_t)(void); +typedef void (*cc_cb_hook_t)(cc_os_args args); typedef enum { cc_sched_task_status_exit = 0x00, ///> Initial State cc_sched_task_status_running = 0x01, ///> Task currently running cc_sched_task_status_ready = 0x02, ///> Task Ready to despatch cc_sched_task_status_wait = 0x03, ///> Task in wait state + cc_sched_task_status_pause = 0x04, ///> Task in pause state cc_sched_task_status_max = 0xff, ///> Do Nt Use } cc_sched_task_status_t; @@ -50,12 +51,11 @@ typedef enum */ typedef enum { - cc_sched_cb_pre_sched = -0x01, cc_sched_cb_power_pre_sleep = 0x00, cc_sched_cb_power_post_sleep = 0x01, cc_sched_cb_power_sleep = 0x02, cc_sched_cb_deadlock_notify = 0x03, - cc_sched_cb_max = 0x04 + cc_sched_cb_max = 0xff }cc_sched_cb_t; typedef enum @@ -85,9 +85,9 @@ struct cc_sched_tcb wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers link_t wait_link; ///> Wait Linked List Pointers -#if CC_OS_FEATURE_ANTI_DEADLOCK +#if CC_OS_ANTI_DEADLOCK size_t task_wd_ticks; ///> Tick down counter for Anti Deadlock system -#endif +#endif /* CC_OS_ANTI_DEADLOCK */ cc_sched_task_status_t task_status; ///> Current state of the task }; @@ -98,10 +98,10 @@ typedef struct cc_sched_func_cb cc_cb_hook_t pre_sleep_cb; cc_cb_hook_t post_sleep_cb; cc_cb_hook_t sleep_cb; -#endif -#if CC_OS_FEATURE_ANTI_DEADLOCK +#endif /* CC_OS_POWER_SAVE_EN */ +#if CC_OS_ANTI_DEADLOCK cc_cb_hook_t deadlock_notify; -#endif +#endif /* CC_OS_ANTI_DEADLOCK */ }cc_sched_func_cb_t; typedef struct cc_sched_ctrl @@ -131,3 +131,9 @@ typedef struct cc_sched cc_sched_algo_t cc_selected_algo; ///> Selected Algorithm ID algo_fn algo_function; ///> Pointer to algorithm function }cc_sched_t; + +typedef struct cc_sched_anti_deadlock +{ + c_char * name; + task_fn_t task_func; +}cc_sched_anti_deadlock_t; diff --git a/src/visor/terravisor/services/kernel/cc_os_config.mk b/src/visor/terravisor/services/kernel/cc_os_config.mk index c9728c07..b753b386 100644 --- a/src/visor/terravisor/services/kernel/cc_os_config.mk +++ b/src/visor/terravisor/services/kernel/cc_os_config.mk @@ -15,7 +15,7 @@ CC_OS_MAX_THREAD ?= 2 CC_OS_IDLE_TASK_NAME ?= \"CC_OS_IDLE\" CC_OS_IDLE_TASK_STACK_LEN ?= 255 CC_OS_POWER_SAVE_EN ?= 0 -CC_OS_FEATURE_ANTI_DEADLOCK ?= 1 +CC_OS_ANTI_DEADLOCK ?= 1 $(eval $(call add_define,CC_OS_USE_DYNAMIC)) $(eval $(call add_define,CC_OS_HEAP_SIZE)) @@ -24,4 +24,4 @@ $(eval $(call add_define,CC_OS_IDLE_TASK_NAME)) $(eval $(call add_define,CC_OS_IDLE_TASK_PRIORITY)) $(eval $(call add_define,CC_OS_IDLE_TASK_STACK_LEN)) $(eval $(call add_define,CC_OS_POWER_SAVE_EN)) -$(eval $(call add_define,CC_OS_FEATURE_ANTI_DEADLOCK)) +$(eval $(call add_define,CC_OS_ANTI_DEADLOCK)) diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index 9459899c..f2ed2842 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -12,6 +12,7 @@ * INCLUDES *****************************************************/ #include +#include /***************************************************** * DEFINES @@ -23,6 +24,8 @@ /***************************************************** * STATIC FUNCTION DECLARATION *****************************************************/ +static void __cc_sched_deadlock_adjustment_and_detection(const cc_sched_ctrl_t * sched_ctrl); +static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl); static void __cc_sched_algo_round_robin_fn(cc_sched_ctrl_t * sched_ctrl); static void __cc_sched_algo_priority_driven_fn(cc_sched_ctrl_t * sched_ctrl); @@ -150,9 +153,22 @@ void _cc_sched_send_to_wait(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, } } +void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) +{ + if (ptr->task_status == cc_sched_task_status_pause) + { + return; + } + if(_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) + { + ptr->wait_res.task_delay_ticks = CC_OS_DELAY_MAX; + ptr->task_status = cc_sched_task_status_pause; + } +} + void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) { - if (ptr->task_status == cc_sched_task_status_ready) + if (ptr->task_status < cc_sched_task_status_wait) { return; } @@ -175,6 +191,39 @@ void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr ptr->task_status = cc_sched_task_status_ready; } +void _cc_os_pre_sched(cc_os_args args) +{ + cc_sched_ctrl_t * sched_ctrl = (cc_sched_ctrl_t *) args; + + __cc_sched_wait_list_adjustment(sched_ctrl); + __cc_sched_deadlock_adjustment_and_detection(sched_ctrl); +} + +void _cc_os_scheduler_despatch(void) +{ + if (g_sched_ctrl.cb_hooks_reg.pre_sched != NULL) + { + /* Call Pre_sched Function */ + g_sched_ctrl.cb_hooks_reg.pre_sched((cc_os_args) &g_sched_ctrl); + } + else + { + /* A System Error case */ + arch_panic_handler(); + } + + if (g_sched_ctrl.selected_sched != NULL) + { + /* Call the scheduler */ + g_sched_ctrl.selected_sched->algo_function(&g_sched_ctrl); + } + else + { + /* A System Error case */ + arch_panic_handler(); + } + +} /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ @@ -183,31 +232,67 @@ static void __cc_sched_context_switch(cc_sched_tcb_t * next_task) next_task->task_status = cc_sched_task_status_running; } -static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) +static void __cc_sched_deadlock_adjustment_and_detection(const cc_sched_ctrl_t * sched_ctrl _UNUSED) { - cc_sched_tcb_t * ptr = sched_ctrl->wait_list_head; - const int * wait_res = (int *)ptr->wait_res.wait_on_resource; - while(ptr != CC_OS_NULL_PTR) +#if CC_OS_ANTI_DEADLOCK + cc_sched_tcb_t * ptr = sched_ctrl->ready_list_head; + static cc_sched_anti_deadlock_t anti_deadlock_notify; + while (ptr != CC_OS_NULL_PTR) { - ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ - - if ((wait_res != CC_OS_NULL_PTR) && *wait_res > false) + if (ptr->task_status != cc_sched_task_status_pause) { - /* The resource is available can can go to ready state */ - ptr->wait_res.task_delay_ticks = false; - ptr->wait_res.wait_on_resource = false; + ptr->task_wd_ticks--; } - if(ptr->wait_res.task_delay_ticks == false) + if ((ptr->task_wd_ticks == false) && (sched_ctrl->cb_hooks_reg.deadlock_notify != CC_OS_NULL_PTR)) { - _cc_sched_send_to_resume(sched_ctrl, ptr); + /* Create notification params */ + anti_deadlock_notify.name = ptr->name; + anti_deadlock_notify.task_func = ptr->task_func; + + if (ptr->task_status != cc_sched_task_status_exit) + { + ptr->task_status = cc_sched_task_status_exit; + } + /* Notify the user that the task pointed by ptr is dead and has been terminated */ + sched_ctrl->cb_hooks_reg.deadlock_notify((cc_os_args) &anti_deadlock_notify); } - if (ptr->wait_link.next == sched_ctrl->wait_list_head) + if (ptr->ready_link.next == sched_ctrl->ready_list_head) { break; } - else + } +#else + return; +#endif /* CC_OS_ANTI_DEADLOCK */ +} +static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) +{ + cc_sched_tcb_t * ptr = sched_ctrl->wait_list_head; + const int * wait_res = (int *)ptr->wait_res.wait_on_resource; + while(ptr != CC_OS_NULL_PTR) + { + if (ptr->task_status == cc_sched_task_status_wait) { - ptr = ptr->wait_link.next; + ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ + + if ((wait_res != CC_OS_NULL_PTR) && *wait_res > false) + { + /* The resource is available can can go to ready state */ + ptr->wait_res.task_delay_ticks = false; + ptr->wait_res.wait_on_resource = false; + } + if(ptr->wait_res.task_delay_ticks == false) + { + _cc_sched_send_to_resume(sched_ctrl, ptr); + } + if (ptr->wait_link.next == sched_ctrl->wait_list_head) + { + break; + } + else + { + ptr = ptr->wait_link.next; + } } } } diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 98214932..bdb1b1a9 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -28,8 +28,9 @@ extern status_t _insert_after(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); extern status_t _insert_before(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); extern void _cc_sched_send_to_wait(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr, const size_t ticks); +extern void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr); extern void _cc_sched_send_to_resume(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr); - +extern void _cc_os_pre_sched(cc_os_args args); /***************************************************** * GLOBAL EXTERNS VARIABLES *****************************************************/ @@ -55,8 +56,9 @@ cc_os_task_t *cc_os_idle_task; /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ -static void __cc_init_scheduler() +static void __cc_init_scheduler(void) { + g_sched_ctrl.cb_hooks_reg.pre_sched = &_cc_os_pre_sched; return; } static status_t __cc_os_set_task_flag(cc_os_task_t cc_os_task, cc_task_flag_t task_flag, bool en) @@ -162,9 +164,9 @@ status_t cc_os_add_task( ptr->priority = priority; ptr->task_func = task_func; ptr->args_ptr = (uintptr_t)args; -#if CC_OS_FEATURE_ANTI_DEADLOCK +#if CC_OS_ANTI_DEADLOCK ptr->task_wd_ticks = SIZE_MAX; -#endif /* CC_OS_FEATURE_ANTI_DEADLOCK */ +#endif /* CC_OS_ANTI_DEADLOCK */ } else { @@ -192,7 +194,7 @@ status_t cc_os_add_task( else { cc_sched_tcb_t *comp_ptr = g_sched_ctrl.task_max_prio->ready_link.next; - while (1) + while (true) { if (comp_ptr->priority <= ptr->priority && (_insert_after(&comp_ptr, ptr, false) == success)) { @@ -245,7 +247,7 @@ status_t cc_os_pause_task(cc_os_task_t cc_os_task) ptr = cc_os_task; } - _cc_sched_send_to_wait(&g_sched_ctrl, ptr, CC_OS_DELAY_MAX); + _cc_sched_send_to_pause(&g_sched_ctrl, ptr); return success; } @@ -258,10 +260,11 @@ status_t cc_os_pause_all_task(void) { if (ptr == g_sched_ctrl.curr_task) { + /* Do not pause the current task */ continue; } - _cc_sched_send_to_wait(&g_sched_ctrl, ptr, CC_OS_DELAY_MAX); + _cc_sched_send_to_pause(&g_sched_ctrl, ptr); ptr = ptr->ready_link.next; } @@ -275,7 +278,7 @@ status_t cc_os_resume_all_task(void) { while (ptr != g_sched_ctrl.ready_list_head) { - if (ptr == g_sched_ctrl.curr_task) + if ((ptr == g_sched_ctrl.curr_task) || (ptr->task_status != cc_sched_task_status_pause)) { continue; } @@ -297,8 +300,14 @@ status_t cc_os_resume_task(cc_os_task_t cc_os_task) cc_sched_tcb_t *ptr = cc_os_task; - _cc_sched_send_to_resume(&g_sched_ctrl, ptr); - + if (ptr->task_status != cc_sched_task_status_pause) + { + _cc_sched_send_to_resume(&g_sched_ctrl, ptr); + } + else + { + return error_os_invalid_op; + } return success; } @@ -313,7 +322,7 @@ status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo) status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks _UNUSED) { -#if CC_OS_FEATURE_ANTI_DEADLOCK +#if CC_OS_ANTI_DEADLOCK CC_OS_ASSERT_IF_FALSE((task_wd_ticks > false) && (task_wd_ticks < SIZE_MAX)); cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; @@ -331,7 +340,7 @@ status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks _UNUSED) __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, false); } return error_func_inval; -#endif /* CC_OS_FEATURE_ANTI_DEADLOCK */ +#endif /* CC_OS_ANTI_DEADLOCK */ } status_t cc_os_task_anti_deadlock_disable(void) @@ -343,23 +352,18 @@ status_t cc_os_task_anti_deadlock_disable(void) __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, false); } -#if CC_OS_FEATURE_ANTI_DEADLOCK +#if CC_OS_ANTI_DEADLOCK ptr->task_wd_ticks = SIZE_MAX; return success; #else return error_func_inval; -#endif /* CC_OS_FEATURE_ANTI_DEADLOCK */ +#endif /* CC_OS_ANTI_DEADLOCK */ } status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func _UNUSED) { - CC_OS_ASSERT_IF_FALSE(cb_type >= cc_sched_cb_power_pre_sleep); - status_t ret = success; switch (cb_type) { - case cc_sched_cb_pre_sched: - g_sched_ctrl.cb_hooks_reg.pre_sched = cb_func; - break; case cc_sched_cb_power_post_sleep: #if CC_OS_POWER_SAVE_EN g_sched_ctrl.cb_hooks_reg.post_sleep_cb = cb_func; @@ -376,7 +380,7 @@ status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_f break; #endif case cc_sched_cb_deadlock_notify: -#if CC_OS_FEATURE_ANTI_DEADLOCK +#if CC_OS_ANTI_DEADLOCK g_sched_ctrl.cb_hooks_reg.deadlock_notify = cb_func; break; #endif @@ -424,7 +428,7 @@ void cc_os_run(void) /* Initialise scheduler */ __cc_init_scheduler(); cc_os_task_yield(); /* Yeild */ - while (1) + while (true) { /* Code shall not reach here */ arch_wfi(); From 8d5d6a5e09839aa79cf2b58880ef8c2b9118899b Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Sun, 29 Jan 2023 11:32:39 +0530 Subject: [PATCH 16/22] Add task ID --- .../visor/terravisor/cc_os/cc_os_tasks.h | 12 +++- .../terravisor/cc_os/utils/cc_os_sched.h | 2 + .../terravisor/services/kernel/cc_os_tasks.c | 68 +++++++++++++++---- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/cc_os/cc_os_tasks.h index da87b400..9e007a8b 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/cc_os/cc_os_tasks.h @@ -25,7 +25,7 @@ * @brief TASK infrastructure * */ -typedef cc_sched_tcb_t * cc_os_task_t; +typedef uintptr_t cc_os_task_t; /***************************************************** * MACROS @@ -114,6 +114,7 @@ status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo); * @return status_t */ status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func); + /** * @brief Get name of current running task * @@ -121,6 +122,15 @@ status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_f * @return Pointer to the current task name */ const char * cc_os_get_curr_task_name(void); + +/** + * @brief Get name of any task using task handler + * + * @param cc_os_task[in] Task handler + * @return Pointer to the task name + */ +const char *cc_os_get_task_name(cc_os_task_t cc_os_task); + /** * @brief A Function to put the current task to a waiting state and yield * @note To just Yeild set ticks to 0 diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 3566b58f..30fe6289 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -76,9 +76,11 @@ typedef struct wres struct cc_sched_tcb { + c_char * name; ///> Name of the Current Task uint8_t priority; ///> Priority of the task uint8_t task_flags; ///> Task Flags + uint16_t task_id; ///> Task ID assigned uintptr_t stack_ptr; ///> Stack Pointer task_fn_t task_func; ///> Task Call Function uintptr_t args_ptr; ///> Task Call argument ptr diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index bdb1b1a9..2dc74306 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -53,6 +53,10 @@ uint8_t _cc_os_stack[CC_OS_IDLE_STACK_LEN]; uint8_t *_cc_os_stack = CC_OS_NULL_PTR; #endif cc_os_task_t *cc_os_idle_task; +/***************************************************** + * STATIC VARIABLES + *****************************************************/ +static uintptr_t __cc_os_task_id_gen = false; /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ @@ -61,9 +65,36 @@ static void __cc_init_scheduler(void) g_sched_ctrl.cb_hooks_reg.pre_sched = &_cc_os_pre_sched; return; } -static status_t __cc_os_set_task_flag(cc_os_task_t cc_os_task, cc_task_flag_t task_flag, bool en) + +static uintptr_t __cc_os_task_id_generate() +{ + __cc_os_task_id_gen++; + return __cc_os_task_id_gen; +} + +static cc_sched_tcb_t * __cc_os_get_tcb_using_task_id(const uintptr_t task_id) +{ + cc_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head; + bool _is_id_found = false; + while (ptr->ready_link.next != g_sched_ctrl.ready_list_head) + { + if (ptr->task_id == task_id) + { + _is_id_found = true; + break; + } + ptr = ptr->ready_link.next; + } + if (_is_id_found == false) + { + ptr = CC_OS_NULL_PTR; + } + return ptr; +} + +static status_t __cc_os_set_task_flag(cc_sched_tcb_t* cc_os_task, cc_task_flag_t task_flag, bool en) { - CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); + CC_OS_ASSERT_IF_FALSE( cc_os_task != CC_OS_NULL_PTR); if (en) { @@ -75,6 +106,7 @@ static status_t __cc_os_set_task_flag(cc_os_task_t cc_os_task, cc_task_flag_t ta } return success; } + static bool __cc_os_is_task_flag(const cc_sched_tcb_t *cc_os_task, cc_task_flag_t task_flag) { if (cc_os_task != CC_OS_NULL_PTR) @@ -207,21 +239,20 @@ status_t cc_os_add_task( } } - *cc_os_task = ptr; ptr->task_status = cc_sched_task_status_ready; + *cc_os_task = __cc_os_task_id_generate(); cc_os_resume_all_task(); return success; } status_t cc_os_del_task(cc_os_task_t cc_os_task) { - CC_OS_ASSERT_IF_FALSE(cc_os_task->task_func != &_cc_os_idle_task_fn); - - cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + cc_sched_tcb_t * ptr = __cc_os_get_tcb_using_task_id(cc_os_task); + CC_OS_ASSERT_IF_FALSE(ptr->task_func != &_cc_os_idle_task_fn); - if (cc_os_task != CC_OS_NULL_PTR) + if (ptr == CC_OS_NULL_PTR) { - ptr = cc_os_task; + ptr = g_sched_ctrl.curr_task; } /* Code to handle first node */ if (ptr == g_sched_ctrl.ready_list_head) @@ -241,10 +272,10 @@ status_t cc_os_del_task(cc_os_task_t cc_os_task) status_t cc_os_pause_task(cc_os_task_t cc_os_task) { - cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; - if (cc_os_task != CC_OS_NULL_PTR) + cc_sched_tcb_t *ptr = __cc_os_get_tcb_using_task_id(cc_os_task); + if (ptr == CC_OS_NULL_PTR) { - ptr = cc_os_task; + ptr = g_sched_ctrl.curr_task; } _cc_sched_send_to_pause(&g_sched_ctrl, ptr); @@ -296,9 +327,8 @@ status_t cc_os_resume_all_task(void) status_t cc_os_resume_task(cc_os_task_t cc_os_task) { - CC_OS_ASSERT_IF_FALSE(cc_os_task != CC_OS_NULL_PTR); - - cc_sched_tcb_t *ptr = cc_os_task; + cc_sched_tcb_t *ptr = __cc_os_get_tcb_using_task_id(cc_os_task); + CC_OS_ASSERT_IF_FALSE(ptr != CC_OS_NULL_PTR); if (ptr->task_status != cc_sched_task_status_pause) { @@ -396,6 +426,16 @@ const char *cc_os_get_curr_task_name(void) return g_sched_ctrl.curr_task->name; } +const char *cc_os_get_task_name(cc_os_task_t cc_os_task) +{ + const cc_sched_tcb_t *ptr = __cc_os_get_tcb_using_task_id(cc_os_task); + if(ptr != CC_OS_NULL_PTR) + { + return ptr->name; + } + return CC_OS_NULL_PTR; +} + void cc_os_task_wait(const size_t ticks) { cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; From 128caba6eb88bfc6df6a2c25c11854e93e8c399d Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Sun, 29 Jan 2023 20:00:00 +0530 Subject: [PATCH 17/22] Comment Addressed --- src/visor/terravisor/services/kernel/cc_os_tasks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 2dc74306..06e512a4 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -56,7 +56,7 @@ cc_os_task_t *cc_os_idle_task; /***************************************************** * STATIC VARIABLES *****************************************************/ -static uintptr_t __cc_os_task_id_gen = false; +static size_t __cc_os_task_id_gen = false; /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ @@ -66,7 +66,7 @@ static void __cc_init_scheduler(void) return; } -static uintptr_t __cc_os_task_id_generate() +static size_t __cc_os_task_id_generate() { __cc_os_task_id_gen++; return __cc_os_task_id_gen; From ccf4c86f40563ed96241eae54d0eee36c6a7b76e Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Mon, 30 Jan 2023 19:14:35 +0530 Subject: [PATCH 18/22] Comment addressed --- src/visor/terravisor/services/kernel/cc_os_tasks.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 06e512a4..5304ad4f 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -126,9 +126,10 @@ status_t cc_os_add_task( cc_os_args args, uint8_t priority, size_t stack_len, +#if CC_OS_DYNAMIC + uintptr_t stack_ptr _UNUSED +#else uintptr_t stack_ptr -#if CC_OS_DYNAMIC == true - _UNUSED #endif /* CC_OS_DYNAMIC */ ) { @@ -240,7 +241,8 @@ status_t cc_os_add_task( } ptr->task_status = cc_sched_task_status_ready; - *cc_os_task = __cc_os_task_id_generate(); + ptr->task_id = __cc_os_task_id_generate(); + *cc_os_task = ptr->task_id; cc_os_resume_all_task(); return success; } From e87e068ab899b10c3c93a993987a0714aef7e631 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 23 Jan 2023 23:12:25 +0530 Subject: [PATCH 19/22] Fixed memory alignment for RODATA Issue: #212 --- src/platform/sifive/common_fe310/sections.ld.sx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/platform/sifive/common_fe310/sections.ld.sx b/src/platform/sifive/common_fe310/sections.ld.sx index b3ba505e..f5650e3a 100644 --- a/src/platform/sifive/common_fe310/sections.ld.sx +++ b/src/platform/sifive/common_fe310/sections.ld.sx @@ -36,12 +36,11 @@ SECTIONS KEEP(*(.text.entry)) *(.text) *(.text.*) - . = ALIGN(4); + . = ALIGN(8); } > vma_imem AT > lma_mem .rodata : ALIGN(4) { - . = ALIGN(4); *(.version) KEEP(*(.version)) KEEP(*(.rdata)) @@ -50,18 +49,18 @@ SECTIONS *(.srodata) *(.srodata.*) KEEP(*(.srodata)) + . = ALIGN(8); } > vma_imem AT > lma_mem .itim : ALIGN(4) { - . = ALIGN(4); KEEP(*(.itim)) *(.itim.*) + . = ALIGN(8); } > vma_itmem AT > lma_mem .bss : ALIGN(4) { - . = ALIGN(4); *(.bss) *(.bss.*) KEEP(*(.bss)) @@ -70,7 +69,6 @@ SECTIONS .static_bss_global : ALIGN(4) { - . = ALIGN(4); *(.sbss) *(.sbss.*) KEEP(*(.sbss)) @@ -82,7 +80,6 @@ SECTIONS .static_data_global : ALIGN(4) { - . = ALIGN(4); *(.sdata) *(.sdata.*) KEEP(*(.sdata)) @@ -90,7 +87,6 @@ SECTIONS .data : ALIGN(4) { - . = ALIGN(4); *(.data) *(.data.*) KEEP(*(.data)) @@ -100,7 +96,6 @@ SECTIONS .tdata : ALIGN(4) { - . = ALIGN(4); *(.tdata) *(.tdata.*) KEEP(*(.tdata)) From 21248e5179b54f0637b44dcf37d56194dd799bf9 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Wed, 25 Jan 2023 21:15:23 +0530 Subject: [PATCH 20/22] Updated ctx mgnt frame to reduce stk use Related to Issue: #180 --- src/arch/avr/8/common_5x_6/terravisor/arch.c | 16 +++----- src/arch/avr/8/common_5x_6/terravisor/asm.S | 41 +------------------ .../8/common_5x_6/terravisor/include/avr.h | 7 ++-- 3 files changed, 11 insertions(+), 53 deletions(-) diff --git a/src/arch/avr/8/common_5x_6/terravisor/arch.c b/src/arch/avr/8/common_5x_6/terravisor/arch.c index e2ea841c..0ed970f4 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/arch.c +++ b/src/arch/avr/8/common_5x_6/terravisor/arch.c @@ -81,16 +81,12 @@ void _NORETURN arch_panic_handler_callback() if(!frame) goto panic; syslog_stdout_enable(); - sysdbg("r0=%p\tr1=%p\tr2=%p\tr3=%p\tr4=%p\tr5=%p\n", - frame->r0, frame->r1, frame->r2, frame->r3, frame->r4, frame->r5); - sysdbg("r6=%p\tr7=%p\tr8=%p\tr9=%p\tr10=%p\tr11=%p\n", - frame->r6, frame->r7, frame->r8, frame->r9, frame->r10, frame->r11); - sysdbg("r12=%p\tr13=%p\tr14=%p\tr15=%p\tr16=%p\tr17=%p\n", - frame->r12, frame->r13, frame->r14, frame->r15, frame->r16, frame->r17); - sysdbg("r18=%p\tr19=%p\tr20=%p\tr21=%p\tr22=%p\tr23=%p\n", - frame->r18, frame->r19, frame->r20, frame->r21, frame->r22, frame->r23); - sysdbg("r24=%p\tr25=%p\tr26=%p\tr27=%p\tr28=%p\tr29=%p\n", - frame->r24, frame->r25, frame->r26, frame->r27, frame->r28, frame->r29); + sysdbg("r0=%p\tr1=%p\tr18=%p\tr19=%p\n", + frame->r0, frame->r1, frame->r18, frame->r19); + sysdbg("r20=%p\tr21=%p\tr22=%p\tr23=%p\n", + frame->r20, frame->r21, frame->r22, frame->r23); + sysdbg("r24=%p\tr25=%p\tr26=%p\tr27=%p\n", + frame->r24, frame->r25, frame->r26, frame->r27); sysdbg("r30=%p\tr31=%p\tSP=%p\tSREG=%p\n", frame->r30, frame->r31, frame, frame->sreg); #if DEBUG==0 diff --git a/src/arch/avr/8/common_5x_6/terravisor/asm.S b/src/arch/avr/8/common_5x_6/terravisor/asm.S index e1e3ce39..64788ddc 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/asm.S +++ b/src/arch/avr/8/common_5x_6/terravisor/asm.S @@ -47,22 +47,6 @@ function arch_panic_handler push r0 in r0, SREG push r0 - push r2 - push r3 - push r4 - push r5 - push r6 - push r7 - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - push r16 - push r17 push r18 push r19 push r20 @@ -72,8 +56,6 @@ function arch_panic_handler push r25 push r26 push r27 - push r28 - push r29 push r30 push r31 .endm @@ -84,8 +66,6 @@ function arch_panic_handler .macro CONTEXT_RESTORE pop r31 pop r30 - pop r29 - pop r28 pop r27 pop r26 pop r25 @@ -95,22 +75,6 @@ function arch_panic_handler pop r20 pop r19 pop r18 - pop r17 - pop r16 - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop r7 - pop r6 - pop r5 - pop r4 - pop r3 - pop r2 pop r0 out SREG, r0 pop r0 @@ -142,11 +106,10 @@ function int_\id */ function isr CONTEXT_SAVE + push r24 in r22, IO_SPL in r23, IO_SPH - ldi r16, 1 - add r22, r16 - adc r23, r1 + pop r24 call interrupt_handler CONTEXT_RESTORE pop r24 diff --git a/src/arch/avr/8/common_5x_6/terravisor/include/avr.h b/src/arch/avr/8/common_5x_6/terravisor/include/avr.h index 364f4622..a9be6ebf 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/include/avr.h +++ b/src/arch/avr/8/common_5x_6/terravisor/include/avr.h @@ -18,10 +18,9 @@ typedef struct context_frame { - uint8_t r31, r30, r29, r28, r27, r26, r25, r23, - r22, r21, r20, r19, r18, r17, r16, r15, - r14, r13, r12, r11, r10, r9, r8, r7, - r6, r5, r4, r3, r2, sreg, r0, r1, r24; + uint8_t r31, r30, r27, r26, r25, r23, + r22, r21, r20, r19, r18, + sreg, r0, r1, r24; } context_frame_t; typedef uint16_t call_arg_t; From 8bf74daa54fd48299a878fe7de11782919783a91 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Tue, 31 Jan 2023 11:52:30 +0530 Subject: [PATCH 21/22] Task Create tested --- .vscode/launch.json | 48 +++++- projects/demo_cc_os.src/project.c | 12 +- projects/demo_cc_os_riscv/config.mk | 12 +- .../terravisor/cc_os/utils/cc_os_sched.h | 3 +- .../terravisor/services/kernel/cc_os_sched.c | 162 +++++++++++++++++- .../services/kernel/cc_os_task_idle.c | 13 +- .../terravisor/services/kernel/cc_os_tasks.c | 160 +++++++---------- 7 files changed, 283 insertions(+), 127 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9adbd8ac..3483dc03 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -35,8 +35,51 @@ "text": "b plug" }, ], - - + }, + { + "name": "FE310 Debug (JLink)", + "type": "cppdbg", + "request": "launch", + "miDebuggerServerAddress": ":2331", + "program": "${workspaceFolder}/out/${input:project}/${input:project}.elf", + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "MIMode": "gdb", + "svdPath": "", + "externalConsole": false, + "showDisplayString": true, + // "preLaunchTask": "Build", + "variables": { + "elfPath": "${workspaceFolder}/out/${input:project}/${input:project}.elf" + }, + "miDebuggerPath": "${workspaceFolder}/tools/risc-v-toolchain/bin/riscv64-unknown-elf-gdb", + "miDebuggerArgs": "${elfPath}", + "setupCommands": + [ + { + "text": "b init" + }, + { + "text": "b plug" + }, + ], + "postRemoteConnectCommands": [ + { + "text": "file ${elfPath}" + }, + { + "text": "monitor halt" + }, + { + "text": "load" + }, + { + "text": "monitor reset" + }, + { + "text": "monitor go" + } + ] } ], "inputs": [ @@ -48,6 +91,7 @@ "demo_avr", "demo_avr_cpp", "demo_riscv", + "demo_cc_os_riscv" ], "default": "demo_avr" }, diff --git a/projects/demo_cc_os.src/project.c b/projects/demo_cc_os.src/project.c index 345a4928..5d5d0581 100644 --- a/projects/demo_cc_os.src/project.c +++ b/projects/demo_cc_os.src/project.c @@ -17,9 +17,9 @@ void task_handler(cc_os_args args); -static cc_os_task_t * Task_A; -static cc_os_task_t * Task_B; -static cc_os_task_t * Task_C; +static cc_os_task_t Task_A; +static cc_os_task_t Task_B; +static cc_os_task_t Task_C; /* Define Plug */ void plug() @@ -28,9 +28,9 @@ void plug() driver_setup_all(); printf("Demo CC OS Program!\n"); - cc_os_add_task(Task_A, "Task A", &task_handler, NULL, 10, 255, (uintptr_t) NULL); - cc_os_add_task(Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); - cc_os_add_task(Task_C, "Task C", &task_handler, NULL, 10, 255, (uintptr_t) NULL); + cc_os_add_task(&Task_A, "Task A", &task_handler, NULL, 5, 255, (uintptr_t) NULL); + cc_os_add_task(&Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); + cc_os_add_task(&Task_C, "Task C", &task_handler, NULL, 4, 255, (uintptr_t) NULL); cc_os_run(); } diff --git a/projects/demo_cc_os_riscv/config.mk b/projects/demo_cc_os_riscv/config.mk index f36fd2de..1a0b11de 100644 --- a/projects/demo_cc_os_riscv/config.mk +++ b/projects/demo_cc_os_riscv/config.mk @@ -12,11 +12,11 @@ COMPILER := gcc TC_VER := 10.2.0 FAMILY := sifive PLATFORM := fe310g002 -HEAP_SIZE := 256 -STACK_SIZE := 256 -STDLOG_MEMBUF := 0 -BOOTMSGS := 0 -EARLYCON_SERIAL := 1 -CONSOLE_SERIAL := 1 +HEAP_SIZE := 3K +STACK_SIZE := 1K +STDLOG_MEMBUF := 1 +BOOTMSGS := 1 +EARLYCON_SERIAL := 0 +CONSOLE_SERIAL := 0 OBRDLED_ENABLE := 1 TERRAKERN := 1 diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h index 30fe6289..933d8202 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h @@ -80,13 +80,13 @@ struct cc_sched_tcb c_char * name; ///> Name of the Current Task uint8_t priority; ///> Priority of the task uint8_t task_flags; ///> Task Flags - uint16_t task_id; ///> Task ID assigned uintptr_t stack_ptr; ///> Stack Pointer task_fn_t task_func; ///> Task Call Function uintptr_t args_ptr; ///> Task Call argument ptr wres_t wait_res; ///> Wait Task resource link_t ready_link; ///> Ready Linked List Pointers link_t wait_link; ///> Wait Linked List Pointers + uintptr_t task_id; ///> Task ID assigned #if CC_OS_ANTI_DEADLOCK size_t task_wd_ticks; ///> Tick down counter for Anti Deadlock system #endif /* CC_OS_ANTI_DEADLOCK */ @@ -111,7 +111,6 @@ typedef struct cc_sched_ctrl cc_sched_tcb_t * ready_list_head; cc_sched_tcb_t * curr_task; cc_sched_tcb_t * wait_list_head; - cc_sched_tcb_t * task_max_prio; cc_sched_t * selected_sched; cc_sched_func_cb_t cb_hooks_reg; }cc_sched_ctrl_t; diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/cc_os_sched.c index f2ed2842..6da4a7b0 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/cc_os_sched.c @@ -54,14 +54,23 @@ cc_sched_ctrl_t g_sched_ctrl = .curr_task = CC_OS_NULL_PTR, #endif .wait_list_head = CC_OS_NULL_PTR, - .task_max_prio = CC_OS_NULL_PTR, .selected_sched = &(g_cc_sched_list[cc_sched_algo_round_robin]) }; /***************************************************** * INTERNAL USED FUNCTIONS (NON-STATIC) *****************************************************/ -status_t _insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) + +/** + * @brief Insert a node after a reference pointer + * + * @param ptr[in_out] Reference pointer address + * @param new_node[in] Node to be inserted + * @param link_type[in] true -> Wait Link, false -> Ready link + * + * @return None +*/ +status_t _cc_os_sched_insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) { CC_OS_ASSERT_IF_FALSE(new_node != CC_OS_NULL_PTR); if (link_type == true) @@ -100,7 +109,17 @@ status_t _insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t } return success; } -status_t _insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) + +/** + * @brief Insert a node before a reference pointer + * + * @param ptr[in_out] Reference pointer address + * @param new_node[in] Node to be inserted + * @param link_type[in] true -> Wait Link, false -> Ready link + * + * @return None +*/ +status_t _cc_os_sched_insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) { CC_OS_ASSERT_IF_FALSE(new_node != CC_OS_NULL_PTR); if (link_type == true) @@ -139,33 +158,57 @@ status_t _insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_ } return success; } - +/** + * @brief Send a task to wait state + * + * @param sched_ctrl[in_out] Current scheduler control + * @param ptr[in_out] Pointer to task TCB + * @param ticks[in] Ticks to wait + * + * @return None + */ void _cc_sched_send_to_wait(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, const size_t ticks) { if (ptr->task_status == cc_sched_task_status_wait) { return; } - if(_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) + if(_cc_os_sched_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) { ptr->wait_res.task_delay_ticks = ticks; ptr->task_status = cc_sched_task_status_wait; } } +/** + * @brief Send a task to pause state + * + * @param sched_ctrl[in_out] Current scheduler control + * @param ptr[in_out] Pointer to task TCB + * + * @return None + */ void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) { if (ptr->task_status == cc_sched_task_status_pause) { return; } - if(_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) + if(_cc_os_sched_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) { ptr->wait_res.task_delay_ticks = CC_OS_DELAY_MAX; ptr->task_status = cc_sched_task_status_pause; } } +/** + * @brief Send a task to ready state + * + * @param sched_ctrl[in_out] Current scheduler control + * @param ptr[in_out] Pointer to task TCB + * + * @return None + */ void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) { if (ptr->task_status < cc_sched_task_status_wait) @@ -191,6 +234,108 @@ void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr ptr->task_status = cc_sched_task_status_ready; } +/** + * @brief A function to detach an existing node from a link + * + * @param node_ptr[in_out] Address of the node to be detached + * @param link_type[in] true -> Wait Link, false -> Ready link + * + * @return None +*/ +status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_type) +{ + CC_OS_ASSERT_IF_FALSE(node_ptr == CC_OS_NULL_PTR); + + if (link_type == true) + { + /* Wait Link */ + node_ptr->wait_link.prev->wait_link.next = node_ptr->wait_link.next; + node_ptr->wait_link.next->wait_link.prev = node_ptr->wait_link.prev; + node_ptr->wait_link.prev = node_ptr->wait_link.next = CC_OS_NULL_PTR; + if (node_ptr == g_sched_ctrl.wait_list_head) + { + g_sched_ctrl.wait_list_head = node_ptr->ready_link.next; + } + } + else + { + /* Ready Link */ + node_ptr->ready_link.prev->ready_link.next = node_ptr->ready_link.next; + node_ptr->ready_link.next->ready_link.prev = node_ptr->ready_link.prev; + node_ptr->ready_link.prev = node_ptr->ready_link.next = CC_OS_NULL_PTR; + + if (node_ptr == g_sched_ctrl.ready_list_head) + { + g_sched_ctrl.ready_list_head = node_ptr->ready_link.next; + } + } + return success; +} + +/** + * @brief Send a task to the back of its own priority list + * + * @param node_ptr[in_out] Pointer to task TCB + * + * @return None + */ +void _cc_sched_send_back_of_task_prio(cc_sched_tcb_t *node_ptr) +{ + cc_sched_tcb_t * ref_ptr = g_sched_ctrl.ready_list_head; + bool least_prio = true; + if(ref_ptr != CC_OS_NULL_PTR) + { + if (node_ptr == ref_ptr) + { + /* Very first node */ + return; + } + + /* Find an optimal space */ + while(node_ptr->priority >= ref_ptr->priority) + { + least_prio = false; + ref_ptr = ref_ptr->ready_link.next; + if (ref_ptr == g_sched_ctrl.ready_list_head) + { + /* traversal complete */ + break; + } + } + if (least_prio) + { + /* Set ready list head if least prio detected */ + g_sched_ctrl.ready_list_head = node_ptr; + } + if(node_ptr->ready_link.next == node_ptr->ready_link.prev) + { + /** + * New Node + * Insert it behind the same priority + */ + _cc_os_sched_insert_before(&ref_ptr, node_ptr, false); + } + else + { + /** + * Detach the current node from link and insert it at the end + * of priority + * This would help to round robin over the same priority when + * scheduling + */ + _cc_sched_node_detach(node_ptr, false); + _cc_os_sched_insert_before(&node_ptr, ref_ptr, false); + } + } +} + +/** + * @brief CC_OS pre scheduler callback being called before any task scheduling is done + * + * @param args[in] cc_os_args (provides scheduler ctrl) + * + * @return None + */ void _cc_os_pre_sched(cc_os_args args) { cc_sched_ctrl_t * sched_ctrl = (cc_sched_ctrl_t *) args; @@ -199,6 +344,11 @@ void _cc_os_pre_sched(cc_os_args args) __cc_sched_deadlock_adjustment_and_detection(sched_ctrl); } +/** + * @brief Despatch a scheduling as per selected algorithm + * + * @return None + */ void _cc_os_scheduler_despatch(void) { if (g_sched_ctrl.cb_hooks_reg.pre_sched != NULL) diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/cc_os_task_idle.c index af1925fb..e2a1b41d 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/cc_os_task_idle.c @@ -14,6 +14,11 @@ #include #include +/***************************************************** + * EXTERN FUNCTION DECLARATION + *****************************************************/ +extern status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_type); + /***************************************************** * STATIC FUNCTION DECLARATION *****************************************************/ @@ -28,13 +33,9 @@ static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) cc_sched_tcb_t * next_ptr = ptr->ready_link.next; if (ptr->ready_link.next->task_status == cc_sched_task_status_exit) { - ptr->ready_link.prev->ready_link.next = ptr->ready_link.next; - ptr->ready_link.next->ready_link.prev = ptr->ready_link.prev; + _cc_sched_node_detach(ptr, false); -#if CC_OS_DYNAMIC == false - ptr->ready_link.next = CC_OS_NULL_PTR; - ptr->ready_link.prev = CC_OS_NULL_PTR; -#else +#if CC_OS_DYNAMIC == true cc_os_free((void *)ptr->stack_ptr); cc_os_free(ptr); #endif diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c index 5304ad4f..cb8f40a3 100644 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ b/src/visor/terravisor/services/kernel/cc_os_tasks.c @@ -25,11 +25,12 @@ /***************************************************** * INTERNAL EXTERNS FUNCTIONS *****************************************************/ -extern status_t _insert_after(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); -extern status_t _insert_before(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); +extern status_t _cc_os_sched_insert_after(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); +extern status_t _cc_os_sched_insert_before(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); extern void _cc_sched_send_to_wait(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr, const size_t ticks); extern void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr); extern void _cc_sched_send_to_resume(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr); +extern void _cc_sched_send_back_of_task_prio(cc_sched_tcb_t *node_ptr); extern void _cc_os_pre_sched(cc_os_args args); /***************************************************** * GLOBAL EXTERNS VARIABLES @@ -52,7 +53,7 @@ uint8_t _cc_os_stack[CC_OS_IDLE_STACK_LEN]; #else uint8_t *_cc_os_stack = CC_OS_NULL_PTR; #endif -cc_os_task_t *cc_os_idle_task; +cc_os_task_t cc_os_idle_task; /***************************************************** * STATIC VARIABLES *****************************************************/ @@ -116,6 +117,7 @@ static bool __cc_os_is_task_flag(const cc_sched_tcb_t *cc_os_task, cc_task_flag_ return false; } + /***************************************************** * USER FUNCTION DEFINATIONS *****************************************************/ @@ -133,7 +135,7 @@ status_t cc_os_add_task( #endif /* CC_OS_DYNAMIC */ ) { - CC_OS_ASSERT_IF_FALSE(cc_os_task == CC_OS_NULL_PTR); + CC_OS_ASSERT_IF_FALSE(*cc_os_task == (uintptr_t)CC_OS_NULL_PTR); CC_OS_ASSERT_IF_FALSE(name != CC_OS_NULL_PTR); #if CC_OS_DYNAMIC == false CC_OS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t)CC_OS_NULL_PTR); @@ -145,101 +147,54 @@ status_t cc_os_add_task( cc_os_pause_all_task(); - cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; + cc_sched_tcb_t *ptr = CC_OS_NULL_PTR; -#if CC_OS_DYNAMIC == true - if (ptr == CC_OS_NULL_PTR) +#if CC_OS_DYNAMIC == false + /* Static Task Allocation */ + for (size_t i = false; i < CC_OS_MAX_THREAD; i++) { - /* First Dynamic task */ - ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); - if (ptr == CC_OS_NULL_PTR) + /* Get an available node from global tcb list */ + if (g_cc_os_tcb_list[i].task_status == cc_sched_task_status_exit) { - cc_os_resume_all_task(); - return error_memory_low; + ptr = &(g_cc_os_tcb_list[i]); + break; } } -#endif /* CC_OS_DYNAMIC */ - if ((ptr->ready_link.next == CC_OS_NULL_PTR) && (ptr->ready_link.prev == CC_OS_NULL_PTR)) + if (ptr != g_sched_ctrl.ready_list_head) { - ptr->ready_link.next = ptr->ready_link.prev = g_sched_ctrl.ready_list_head; - } - - else - { -#if CC_OS_DYNAMIC == false - /* Static Task Allocation */ - for (size_t i = false; i < CC_OS_MAX_THREAD; i++) - { - /* Get an available node from global tcb list */ - if (g_cc_os_tcb_list[i].task_status == cc_sched_task_status_exit) - { - ptr = &(g_cc_os_tcb_list[i]); - break; - } - } - if (ptr != g_sched_ctrl.ready_list_head) - { - ptr->stack_ptr = stack_ptr; + ptr->stack_ptr = stack_ptr; #else - /* Dynamic Task Declaration */ - ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); - if (ptr != CC_OS_NULL_PTR) - { - ptr->stack_ptr = (uintptr_t)malloc(stack_len); - if (ptr->stack_ptr == (uintptr_t)CC_OS_NULL_PTR) - { - cc_os_resume_all_task(); - return error_memory_low; - } -#endif /* CC_OS_DYNAMIC */ - /* Fill tcb details */ - ptr->name = name; - ptr->priority = priority; - ptr->task_func = task_func; - ptr->args_ptr = (uintptr_t)args; -#if CC_OS_ANTI_DEADLOCK - ptr->task_wd_ticks = SIZE_MAX; -#endif /* CC_OS_ANTI_DEADLOCK */ - } - else + /* Dynamic Task Declaration */ + ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); + if (ptr != CC_OS_NULL_PTR) + { + ptr->stack_ptr = (uintptr_t)malloc(stack_len); + if (ptr->stack_ptr == (uintptr_t)CC_OS_NULL_PTR) { cc_os_resume_all_task(); return error_memory_low; } +#endif /* CC_OS_DYNAMIC */ } - /* Insert Tasks in assending order of its priority */ - if (g_sched_ctrl.task_max_prio == CC_OS_NULL_PTR) - { - g_sched_ctrl.task_max_prio = ptr; - } - else if (g_sched_ctrl.task_max_prio->priority <= ptr->priority) + else { - if (_insert_after(&(g_sched_ctrl.task_max_prio), ptr, false) == success) - { - g_sched_ctrl.task_max_prio = ptr; - } - else - { - cc_os_resume_all_task(); - return error_os_task_overfow; - } + cc_os_resume_all_task(); + return error_memory_low; } - else + /* Fill tcb details */ + ptr->name = name; + ptr->priority = priority; + ptr->task_func = task_func; + ptr->args_ptr = (uintptr_t)args; +#if CC_OS_ANTI_DEADLOCK + ptr->task_wd_ticks = SIZE_MAX; +#endif /* CC_OS_ANTI_DEADLOCK */ + if (g_sched_ctrl.ready_list_head == CC_OS_NULL_PTR) { - cc_sched_tcb_t *comp_ptr = g_sched_ctrl.task_max_prio->ready_link.next; - while (true) - { - if (comp_ptr->priority <= ptr->priority && (_insert_after(&comp_ptr, ptr, false) == success)) - { - break; - } - else - { - comp_ptr = comp_ptr->ready_link.next; - } - } + ptr->ready_link.next = ptr->ready_link.prev = g_sched_ctrl.ready_list_head = ptr; } - + /* Insert Tasks in assending order of its priority */ + _cc_sched_send_back_of_task_prio(ptr); ptr->task_status = cc_sched_task_status_ready; ptr->task_id = __cc_os_task_id_generate(); *cc_os_task = ptr->task_id; @@ -287,18 +242,25 @@ status_t cc_os_pause_task(cc_os_task_t cc_os_task) status_t cc_os_pause_all_task(void) { - cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head->ready_link.next; - - while (ptr != g_sched_ctrl.ready_list_head) + cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; + if(ptr != CC_OS_NULL_PTR) { - if (ptr == g_sched_ctrl.curr_task) + while (true) { - /* Do not pause the current task */ - continue; - } + if (ptr == g_sched_ctrl.curr_task) + { + /* Do not pause the current task */ + continue; + } - _cc_sched_send_to_pause(&g_sched_ctrl, ptr); - ptr = ptr->ready_link.next; + _cc_sched_send_to_pause(&g_sched_ctrl, ptr); + ptr = ptr->ready_link.next; + + if(ptr == g_sched_ctrl.ready_list_head) + { + break; + } + } } return success; @@ -306,17 +268,17 @@ status_t cc_os_pause_all_task(void) status_t cc_os_resume_all_task(void) { - cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head->ready_link.next; + cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; if (ptr != CC_OS_NULL_PTR) { - while (ptr != g_sched_ctrl.ready_list_head) + while (true) { - if ((ptr == g_sched_ctrl.curr_task) || (ptr->task_status != cc_sched_task_status_pause)) + ptr = ptr->ready_link.next; + _cc_sched_send_to_resume(&g_sched_ctrl, ptr); + if (ptr == g_sched_ctrl.ready_list_head) { - continue; + break; } - _cc_sched_send_to_resume(&g_sched_ctrl, ptr); - ptr = ptr->ready_link.next; } } else @@ -459,7 +421,7 @@ void cc_os_run(void) { /* OS Init code */ /* Initialise IDLE Task */ - cc_os_add_task(cc_os_idle_task, + cc_os_add_task(&cc_os_idle_task, CC_OS_IDLE_TASK_NAME, &_cc_os_idle_task_fn, &g_sched_ctrl, From 8b2774575025968b972efed962f9bee292a17504 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Tue, 31 Jan 2023 23:33:17 +0530 Subject: [PATCH 22/22] CC_OS -> HELIOS --- .github/workflows/github_ci.yml | 8 +- .github/workflows/sonarcloud.yml | 4 +- .vscode/launch.json | 3 +- projects/demo_cc_os_avr/cc_os_config.mk | 16 - projects/demo_cc_os_riscv/cc_os_config.mk | 16 - .../build.mk | 0 .../project.c | 24 +- .../build.mk | 4 +- .../config.mk | 0 projects/demo_helios_avr/helios_config.mk | 16 + .../build.mk | 4 +- .../config.mk | 0 projects/demo_helios_riscv/helios_config.mk | 16 + .../terravisor/cc_os/utils/cc_os_sched.h | 140 ------ .../{cc_os/cc_os.h => helios/helios.h} | 14 +- .../cc_os_sem.h => helios/helios_sem.h} | 18 +- .../cc_os_tasks.h => helios/helios_tasks.h} | 60 +-- .../utils/helios_heap.h} | 8 +- .../terravisor/helios/utils/helios_sched.h | 140 ++++++ .../services/kernel/cc_os_config.mk | 34 +- .../terravisor/services/kernel/cc_os_tasks.c | 442 ------------------ .../kernel/{cc_os_heap.c => helios_heap.c} | 8 +- .../kernel/{cc_os_sched.c => helios_sched.c} | 188 ++++---- .../kernel/{cc_os_sem.c => helios_sem.c} | 44 +- .../{cc_os_task_idle.c => helios_task_idle.c} | 48 +- .../terravisor/services/kernel/helios_tasks.c | 442 ++++++++++++++++++ 26 files changed, 848 insertions(+), 849 deletions(-) delete mode 100644 projects/demo_cc_os_avr/cc_os_config.mk delete mode 100644 projects/demo_cc_os_riscv/cc_os_config.mk rename projects/{demo_cc_os.src => demo_helios.src}/build.mk (100%) rename projects/{demo_cc_os.src => demo_helios.src}/project.c (54%) rename projects/{demo_cc_os_avr => demo_helios_avr}/build.mk (80%) rename projects/{demo_cc_os_avr => demo_helios_avr}/config.mk (100%) create mode 100644 projects/demo_helios_avr/helios_config.mk rename projects/{demo_cc_os_riscv => demo_helios_riscv}/build.mk (80%) rename projects/{demo_cc_os_riscv => demo_helios_riscv}/config.mk (100%) create mode 100644 projects/demo_helios_riscv/helios_config.mk delete mode 100644 src/include/visor/terravisor/cc_os/utils/cc_os_sched.h rename src/include/visor/terravisor/{cc_os/cc_os.h => helios/helios.h} (59%) rename src/include/visor/terravisor/{cc_os/cc_os_sem.h => helios/helios_sem.h} (80%) rename src/include/visor/terravisor/{cc_os/cc_os_tasks.h => helios/helios_tasks.h} (69%) rename src/include/visor/terravisor/{cc_os/utils/cc_os_heap.h => helios/utils/helios_heap.h} (68%) create mode 100644 src/include/visor/terravisor/helios/utils/helios_sched.h delete mode 100644 src/visor/terravisor/services/kernel/cc_os_tasks.c rename src/visor/terravisor/services/kernel/{cc_os_heap.c => helios_heap.c} (86%) rename src/visor/terravisor/services/kernel/{cc_os_sched.c => helios_sched.c} (58%) rename src/visor/terravisor/services/kernel/{cc_os_sem.c => helios_sem.c} (54%) rename src/visor/terravisor/services/kernel/{cc_os_task_idle.c => helios_task_idle.c} (53%) create mode 100644 src/visor/terravisor/services/kernel/helios_tasks.c diff --git a/.github/workflows/github_ci.yml b/.github/workflows/github_ci.yml index 09784824..832cbfc2 100644 --- a/.github/workflows/github_ci.yml +++ b/.github/workflows/github_ci.yml @@ -2,10 +2,10 @@ name: GitHub CI on: push: - branches: [ stable, development, cc_os_stage] + branches: [ stable, development, helios_stage] pull_request: - branches: [ stable, development, cc_os_stage] + branches: [ stable, development, helios_stage] jobs: build: @@ -49,8 +49,8 @@ jobs: make demo_avr make demo_avr_cpp make demo_riscv - make demo_cc_os_avr - make demo_cc_os_riscv + make demo_helios_avr + make demo_helios_riscv - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index d32bf159..a5066287 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -5,12 +5,12 @@ on: branches: - stable - development - - cc_os_stage + - helios_stage pull_request: branches: - stable - development - - cc_os_stage + - helios_stage jobs: build: diff --git a/.vscode/launch.json b/.vscode/launch.json index 3483dc03..4fef0018 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -48,7 +48,6 @@ "svdPath": "", "externalConsole": false, "showDisplayString": true, - // "preLaunchTask": "Build", "variables": { "elfPath": "${workspaceFolder}/out/${input:project}/${input:project}.elf" }, @@ -91,7 +90,7 @@ "demo_avr", "demo_avr_cpp", "demo_riscv", - "demo_cc_os_riscv" + "demo_helios_riscv" ], "default": "demo_avr" }, diff --git a/projects/demo_cc_os_avr/cc_os_config.mk b/projects/demo_cc_os_avr/cc_os_config.mk deleted file mode 100644 index 178c1a57..00000000 --- a/projects/demo_cc_os_avr/cc_os_config.mk +++ /dev/null @@ -1,16 +0,0 @@ -# -# CYANCORE LICENSE -# Copyrights (C) 2019-2023, Cyancore Team -# -# File Name : cc_os_config.mk -# Description : This file consists of CC_OS kernal configuration -# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] -# Organisation : Cyancore Core-Team -# - -CC_OS_USE_DYNAMIC := 1 -CC_OS_HEAP_SIZE := 1024 -CC_OS_MAX_THREAD := 4 -CC_OS_IDLE_TASK_STACK_LEN := 255 -CC_OS_POWER_SAVE_EN := 0 -CC_OS_ANTI_DEADLOCK := 0 diff --git a/projects/demo_cc_os_riscv/cc_os_config.mk b/projects/demo_cc_os_riscv/cc_os_config.mk deleted file mode 100644 index 05fa1d78..00000000 --- a/projects/demo_cc_os_riscv/cc_os_config.mk +++ /dev/null @@ -1,16 +0,0 @@ -# -# CYANCORE LICENSE -# Copyrights (C) 2019-2023, Cyancore Team -# -# File Name : kern_config.mk -# Description : This file consists of CC_OS kernal configuration -# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] -# Organisation : Cyancore Core-Team -# - -CC_OS_USE_DYNAMIC := 1 -CC_OS_HEAP_SIZE := 1024 -CC_OS_MAX_THREAD := 4 -CC_OS_IDLE_TASK_STACK_LEN := 255 -CC_OS_POWER_SAVE_EN := 0 -CC_OS_ANTI_DEADLOCK := 0 diff --git a/projects/demo_cc_os.src/build.mk b/projects/demo_helios.src/build.mk similarity index 100% rename from projects/demo_cc_os.src/build.mk rename to projects/demo_helios.src/build.mk diff --git a/projects/demo_cc_os.src/project.c b/projects/demo_helios.src/project.c similarity index 54% rename from projects/demo_cc_os.src/project.c rename to projects/demo_helios.src/project.c index 5d5d0581..26677c04 100644 --- a/projects/demo_cc_os.src/project.c +++ b/projects/demo_helios.src/project.c @@ -11,15 +11,15 @@ #include #include #include -#include +#include #define TASK_WAIT_TICKS 10 -void task_handler(cc_os_args args); +void task_handler(helios_args args); -static cc_os_task_t Task_A; -static cc_os_task_t Task_B; -static cc_os_task_t Task_C; +static helios_task_t Task_A; +static helios_task_t Task_B; +static helios_task_t Task_C; /* Define Plug */ void plug() @@ -28,10 +28,10 @@ void plug() driver_setup_all(); printf("Demo CC OS Program!\n"); - cc_os_add_task(&Task_A, "Task A", &task_handler, NULL, 5, 255, (uintptr_t) NULL); - cc_os_add_task(&Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); - cc_os_add_task(&Task_C, "Task C", &task_handler, NULL, 4, 255, (uintptr_t) NULL); - cc_os_run(); + helios_add_task(&Task_A, "Task A", &task_handler, NULL, 5, 255, (uintptr_t) NULL); + helios_add_task(&Task_B, "Task B", &task_handler, NULL, 10, 255, (uintptr_t) NULL); + helios_add_task(&Task_C, "Task C", &task_handler, NULL, 4, 255, (uintptr_t) NULL); + helios_run(); } /* Define Play */ @@ -42,11 +42,11 @@ void play() } /* Define the Task Handler */ -void task_handler(cc_os_args args _UNUSED) +void task_handler(helios_args args _UNUSED) { while(true) { - printf("In Task: %s\n", cc_os_get_curr_task_name()); - cc_os_task_wait(TASK_WAIT_TICKS); + printf("In Task: %s\n", helios_get_curr_task_name()); + helios_task_wait(TASK_WAIT_TICKS); } } diff --git a/projects/demo_cc_os_avr/build.mk b/projects/demo_helios_avr/build.mk similarity index 80% rename from projects/demo_cc_os_avr/build.mk rename to projects/demo_helios_avr/build.mk index b5ea41ab..dd292c5d 100644 --- a/projects/demo_cc_os_avr/build.mk +++ b/projects/demo_helios_avr/build.mk @@ -11,9 +11,9 @@ PROJECT_DIR := $(GET_PATH) -include $(PROJECT_DIR)/../demo_cc_os.src/build.mk +include $(PROJECT_DIR)/../demo_helios.src/build.mk include $(PROJECT_DIR)/config.mk -include $(PROJECT_DIR)/cc_os_config.mk +include $(PROJECT_DIR)/helios_config.mk DIR := $(PROJECT_DIR) include mk/obj.mk diff --git a/projects/demo_cc_os_avr/config.mk b/projects/demo_helios_avr/config.mk similarity index 100% rename from projects/demo_cc_os_avr/config.mk rename to projects/demo_helios_avr/config.mk diff --git a/projects/demo_helios_avr/helios_config.mk b/projects/demo_helios_avr/helios_config.mk new file mode 100644 index 00000000..ba80daae --- /dev/null +++ b/projects/demo_helios_avr/helios_config.mk @@ -0,0 +1,16 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019-2023, Cyancore Team +# +# File Name : helios_config.mk +# Description : This file consists of HELIOS kernal configuration +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] +# Organisation : Cyancore Core-Team +# + +HELIOS_USE_DYNAMIC := 1 +HELIOS_HEAP_SIZE := 1024 +HELIOS_MAX_THREAD := 4 +HELIOS_IDLE_TASK_STACK_LEN := 255 +HELIOS_POWER_SAVE_EN := 0 +HELIOS_ANTI_DEADLOCK := 0 diff --git a/projects/demo_cc_os_riscv/build.mk b/projects/demo_helios_riscv/build.mk similarity index 80% rename from projects/demo_cc_os_riscv/build.mk rename to projects/demo_helios_riscv/build.mk index b5ea41ab..dd292c5d 100644 --- a/projects/demo_cc_os_riscv/build.mk +++ b/projects/demo_helios_riscv/build.mk @@ -11,9 +11,9 @@ PROJECT_DIR := $(GET_PATH) -include $(PROJECT_DIR)/../demo_cc_os.src/build.mk +include $(PROJECT_DIR)/../demo_helios.src/build.mk include $(PROJECT_DIR)/config.mk -include $(PROJECT_DIR)/cc_os_config.mk +include $(PROJECT_DIR)/helios_config.mk DIR := $(PROJECT_DIR) include mk/obj.mk diff --git a/projects/demo_cc_os_riscv/config.mk b/projects/demo_helios_riscv/config.mk similarity index 100% rename from projects/demo_cc_os_riscv/config.mk rename to projects/demo_helios_riscv/config.mk diff --git a/projects/demo_helios_riscv/helios_config.mk b/projects/demo_helios_riscv/helios_config.mk new file mode 100644 index 00000000..ba80daae --- /dev/null +++ b/projects/demo_helios_riscv/helios_config.mk @@ -0,0 +1,16 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019-2023, Cyancore Team +# +# File Name : helios_config.mk +# Description : This file consists of HELIOS kernal configuration +# Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] +# Organisation : Cyancore Core-Team +# + +HELIOS_USE_DYNAMIC := 1 +HELIOS_HEAP_SIZE := 1024 +HELIOS_MAX_THREAD := 4 +HELIOS_IDLE_TASK_STACK_LEN := 255 +HELIOS_POWER_SAVE_EN := 0 +HELIOS_ANTI_DEADLOCK := 0 diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h b/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h deleted file mode 100644 index d42f0681..00000000 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_sched.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2022, Cyancore Team - * - * File Name : cc_os_sched.h - * Description : CC OS Kernel scheduler declaration - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once - -/***************************************************** - * INCLUDES - *****************************************************/ -#include -#include -#include - -/***************************************************** - * DEFINES - *****************************************************/ -#define CC_OS_NULL_PTR NULL -#define CC_OS_DELAY_MAX SIZE_MAX - -#define CC_OS_DYNAMIC CC_OS_USE_DYNAMIC - -#define CC_OS_ASSERT_IF_FALSE(con) RET_ON_FAIL(con, error_func_inval_arg) - -/***************************************************** - * TYPEDEFS - *****************************************************/ -typedef struct cc_sched_tcb cc_sched_tcb_t; -typedef struct cc_sched cc_sched_t; -typedef const char c_char; -typedef void * cc_os_args; -typedef void (*task_fn_t)(cc_os_args args); -typedef void (*cc_cb_hook_t)(cc_os_args args); -typedef enum -{ - cc_sched_task_status_exit = 0x00, ///> Initial State - cc_sched_task_status_running = 0x01, ///> Task currently running - cc_sched_task_status_ready = 0x02, ///> Task Ready to despatch - cc_sched_task_status_wait = 0x03, ///> Task in wait state - cc_sched_task_status_pause = 0x04, ///> Task in pause state - cc_sched_task_status_max = 0xff, ///> Do Nt Use -} cc_sched_task_status_t; - -/* - * @note All negative callbacks are internally used by the scheduler - */ -typedef enum -{ - cc_sched_cb_power_pre_sleep = 0x00, - cc_sched_cb_power_post_sleep = 0x01, - cc_sched_cb_power_sleep = 0x02, - cc_sched_cb_deadlock_notify = 0x03, - cc_sched_cb_max = 0xff -}cc_sched_cb_t; - -typedef enum -{ - cc_task_flag_set_anti_deadlock = (1 << 0) ///> Enable Antideadlock for the task -}cc_task_flag_t; -typedef struct link -{ - cc_sched_tcb_t * prev; - cc_sched_tcb_t * next; -}link_t; - -typedef struct wres -{ - uintptr_t wait_on_resource; ///> Resource on hich the task is waiting on - size_t task_delay_ticks; ///> Time delay in ticks -}wres_t; - -struct cc_sched_tcb -{ - - c_char * name; ///> Name of the Current Task - uint8_t priority; ///> Priority of the task - uint8_t task_flags; ///> Task Flags - uintptr_t stack_ptr; ///> Stack Pointer - task_fn_t task_func; ///> Task Call Function - uintptr_t args_ptr; ///> Task Call argument ptr - wres_t wait_res; ///> Wait Task resource - link_t ready_link; ///> Ready Linked List Pointers - link_t wait_link; ///> Wait Linked List Pointers - uint16_t task_id; ///> Task ID assigned -#if CC_OS_ANTI_DEADLOCK - size_t task_wd_ticks; ///> Tick down counter for Anti Deadlock system -#endif /* CC_OS_ANTI_DEADLOCK */ - cc_sched_task_status_t task_status; ///> Current state of the task -}; - -typedef struct cc_sched_func_cb -{ - cc_cb_hook_t pre_sched; -#if CC_OS_POWER_SAVE_EN - cc_cb_hook_t pre_sleep_cb; - cc_cb_hook_t post_sleep_cb; - cc_cb_hook_t sleep_cb; -#endif /* CC_OS_POWER_SAVE_EN */ -#if CC_OS_ANTI_DEADLOCK - cc_cb_hook_t deadlock_notify; -#endif /* CC_OS_ANTI_DEADLOCK */ -}cc_sched_func_cb_t; - -typedef struct cc_sched_ctrl -{ - cc_sched_tcb_t * ready_list_head; - cc_sched_tcb_t * curr_task; - cc_sched_tcb_t * wait_list_head; - cc_sched_t * selected_sched; - cc_sched_func_cb_t cb_hooks_reg; -}cc_sched_ctrl_t; - -/** - * @brief Prototype of scheduler algorithm function - */ -typedef void (* algo_fn)(cc_sched_ctrl_t * sched_ctrl); - -typedef enum -{ - cc_sched_algo_round_robin = 0x00, ///> Round Robin scheduling algorithm - cc_sched_algo_priority_driven = 0x01, ///> Priority driven Scheduling - cc_sched_algo_max = 0xff -}cc_sched_algo_t; - -typedef struct cc_sched -{ - cc_sched_algo_t cc_selected_algo; ///> Selected Algorithm ID - algo_fn algo_function; ///> Pointer to algorithm function -}cc_sched_t; - -typedef struct cc_sched_anti_deadlock -{ - c_char * name; - task_fn_t task_func; -}cc_sched_anti_deadlock_t; diff --git a/src/include/visor/terravisor/cc_os/cc_os.h b/src/include/visor/terravisor/helios/helios.h similarity index 59% rename from src/include/visor/terravisor/cc_os/cc_os.h rename to src/include/visor/terravisor/helios/helios.h index aaac3656..008e28c6 100644 --- a/src/include/visor/terravisor/cc_os/cc_os.h +++ b/src/include/visor/terravisor/helios/helios.h @@ -2,20 +2,20 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os.h + * File Name : helios.h * Description : CC OS Kernel * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team */ -#ifndef __CC_OS__ -#define __CC_OS__ +#ifndef __HELIOS__ +#define __HELIOS__ /***************************************************** * INCLUDES *****************************************************/ -#include -#include -#include +#include +#include +#include -#endif /* __CC_OS__ */ +#endif /* __HELIOS__ */ diff --git a/src/include/visor/terravisor/cc_os/cc_os_sem.h b/src/include/visor/terravisor/helios/helios_sem.h similarity index 80% rename from src/include/visor/terravisor/cc_os/cc_os_sem.h rename to src/include/visor/terravisor/helios/helios_sem.h index 0f6acf29..8887462c 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_sem.h +++ b/src/include/visor/terravisor/helios/helios_sem.h @@ -2,7 +2,7 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_sem.h + * File Name : helios_sem.h * Description : CC OS semaphore declaration * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team @@ -12,7 +12,7 @@ /***************************************************** * DEFINES *****************************************************/ -#include +#include /***************************************************** * TYPEDEFS *****************************************************/ @@ -26,7 +26,7 @@ typedef struct sem *****************************************************/ #define CC_SEM_INST(_Name) _Name##_sem_inst -#if CC_OS_DYNAMIC == false +#if HELIOS_DYNAMIC == false #define CC_SEM_DEF(_Name) \ static sem_t _Name##_sem = { \ .sem_init = 0, \ @@ -35,7 +35,7 @@ static sem_t _Name##_sem = { \ sem_t * _Name##_sem_inst = &_Name##_sem #else #define CC_SEM_DEF(_Name) \ -sem_t * _Name##_sem_inst = CC_OS_NULL_PTR +sem_t * _Name##_sem_inst = HELIOS_NULL_PTR #endif /***************************************************** * USER FUNCTION DECLARATIONS @@ -49,7 +49,7 @@ sem_t * _Name##_sem_inst = CC_OS_NULL_PTR * * @return status_t */ -status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val); +status_t helios_sem_create (sem_t ** sem_ptr, size_t init_val); /** * @brief Delete a semaphore and de-initialise it @@ -58,7 +58,7 @@ status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val); * * @return status_t */ -status_t cc_os_sem_delete (sem_t ** sem_ptr); +status_t helios_sem_delete (sem_t ** sem_ptr); /** * @brief Decrement a semaphore value @@ -67,7 +67,7 @@ status_t cc_os_sem_delete (sem_t ** sem_ptr); * * @return status_t */ -status_t cc_os_sem_give (sem_t * sem_ptr); +status_t helios_sem_give (sem_t * sem_ptr); /** * @brief Increment a semaphore value @@ -77,7 +77,7 @@ status_t cc_os_sem_give (sem_t * sem_ptr); * * @return status_t */ -status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks); +status_t helios_sem_take (sem_t * sem_ptr, size_t wait_ticks); /** * @brief Get current semaphore value @@ -88,4 +88,4 @@ status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks); * @return status_t */ -status_t cc_os_sem_get_val (const sem_t * sem_ptr, size_t * val); +status_t helios_sem_get_val (const sem_t * sem_ptr, size_t * val); diff --git a/src/include/visor/terravisor/cc_os/cc_os_tasks.h b/src/include/visor/terravisor/helios/helios_tasks.h similarity index 69% rename from src/include/visor/terravisor/cc_os/cc_os_tasks.h rename to src/include/visor/terravisor/helios/helios_tasks.h index 440ed420..b94e96ee 100644 --- a/src/include/visor/terravisor/cc_os/cc_os_tasks.h +++ b/src/include/visor/terravisor/helios/helios_tasks.h @@ -2,7 +2,7 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_task.h + * File Name : helios_task.h * Description : CC OS Kernel Tasks declaration * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team @@ -16,7 +16,7 @@ #include "status.h" #include "stdlib.h" #include "stdint.h" -#include +#include /***************************************************** * TYPEDEFS @@ -25,7 +25,7 @@ * @brief TASK infrastructure * */ -typedef uint16_t cc_os_task_t; +typedef uint16_t helios_task_t; /***************************************************** * MACROS @@ -38,7 +38,7 @@ typedef uint16_t cc_os_task_t; * @brief A Function to add a task to the scheduler * * - * @param cc_os_task[out] Pointer to the TASK_instance + * @param helios_task[out] Pointer to the TASK_instance * @param name[in] Conatant Name string provided by the user * @param task_func[in] Pointer to the task function * @param args[in] Pointer to the argument variable provided to the task @@ -48,55 +48,55 @@ typedef uint16_t cc_os_task_t; * * @return status_t */ -status_t cc_os_add_task ( - cc_os_task_t * cc_os_task, const char* name, - task_fn_t task_func, cc_os_args args, +status_t helios_add_task ( + helios_task_t * helios_task, const char* name, + task_fn_t task_func, helios_args args, uint8_t priority,size_t stack_len, uintptr_t stack_ptr); /** * @brief A function to delete a task from the scheduler by instance * - * @param cc_os_task[in] pointer to the TASK_instance; + * @param helios_task[in] pointer to the TASK_instance; * Pass NULL to point to current task * @return status_t */ -status_t cc_os_del_task(cc_os_task_t cc_os_task); +status_t helios_del_task(helios_task_t helios_task); /** * @brief A Function to pause the task until call resume explicitly using its instance * - * @param cc_os_task[in] pointer to the TASK_instance; + * @param helios_task[in] pointer to the TASK_instance; * Pass NULL to point to current task * @return status_t */ -status_t cc_os_pause_task(cc_os_task_t cc_os_task); +status_t helios_pause_task(helios_task_t helios_task); /** * * @brief A Function to resume paused task using its instance * @note Calling this function for already non-waiting task has no effect. * - * @param cc_os_task[in] pointer to the TASK_instance; + * @param helios_task[in] pointer to the TASK_instance; * Pass NULL to point to current task * @return status_t */ -status_t cc_os_resume_task(cc_os_task_t cc_os_task); +status_t helios_resume_task(helios_task_t helios_task); /** * @brief A Function to pause all the tasks except the current and the IDLE Task - * @note To resume all please use cc_os_resume_all_task() call + * @note To resume all please use helios_resume_all_task() call * * @return status_t */ -status_t cc_os_pause_all_task(void); +status_t helios_pause_all_task(void); /** * @brief A Function to resume all the tasks * * @return status_t */ -status_t cc_os_resume_all_task(void); +status_t helios_resume_all_task(void); /** * @brief A function to set CC OS scheduler algorithm @@ -104,7 +104,7 @@ status_t cc_os_resume_all_task(void); * @param sched_algo[in] The algorithm that needs to be selected to * @return status_t */ -status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo); +status_t helios_set_sched_algo(helios_sched_algo_t sched_algo); /** * @brief A function to set the functional callback hooks @@ -113,7 +113,7 @@ status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo); * @param cb_func[in] Callback hook function associated to the cb_type * @return status_t */ -status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func); +status_t helios_set_callback(const helios_sched_cb_t cb_type, const helios_cb_hook_t cb_func); /** * @brief Get name of current running task @@ -121,45 +121,45 @@ status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_f * @param None * @return Pointer to the current task name */ -const char * cc_os_get_curr_task_name(void); +const char * helios_get_curr_task_name(void); /** * @brief Get name of any task using task handler * - * @param cc_os_task[in] Task handler + * @param helios_task[in] Task handler * @return Pointer to the task name */ -const char *cc_os_get_task_name(cc_os_task_t cc_os_task); +const char *helios_get_task_name(helios_task_t helios_task); /** * @brief A Function to put the current task to a waiting state and yield * @note To just Yeild set ticks to 0 * - * @param ticks[in] Number of CC_OS Ticks + * @param ticks[in] Number of HELIOS Ticks * @return None */ -void cc_os_task_wait(const size_t ticks); +void helios_task_wait(const size_t ticks); /** * @brief A Function to switch to next available task * * @return None */ -void cc_os_task_yield(void); +void helios_task_yield(void); /** * @brief A Function to invoke the kernel * * @return status_t */ -void cc_os_run(void); +void helios_run(void); /** * @brief A function to enable anti-deadlock for the task and feed timer value to scheduler. The same shall be used to reset the task watchdog to keep the task alive. - * @note 1. For this feature user needs to enable CC_OS_ANTI_DEADLOCK flag. - * @note 2. CC_OS does NOT keep the reference of previously set watchdog tick value. + * @note 1. For this feature user needs to enable HELIOS_ANTI_DEADLOCK flag. + * @note 2. HELIOS does NOT keep the reference of previously set watchdog tick value. * It is the responsibility of the user to feed the required number of ticks for the tasks to be considered alive. - * @note 3. User needs to set an user callback of type cc_sched_cb_deadlock_notify using cc_os_set_callback(). + * @note 3. User needs to set an user callback of type helios_sched_cb_deadlock_notify using helios_set_callback(). * @note 4. This fucntion shall be called from the Task atleast once for the timer to get started. * @note 5. This function is only allowed to be called from within the task. * @@ -167,7 +167,7 @@ void cc_os_run(void); * * @return status_t */ -status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks); +status_t helios_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks); /** * @brief A function to disable anti deadlock for the task. @@ -175,4 +175,4 @@ status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks); * * @return status_t */ -status_t cc_os_task_anti_deadlock_disable(void); +status_t helios_task_anti_deadlock_disable(void); diff --git a/src/include/visor/terravisor/cc_os/utils/cc_os_heap.h b/src/include/visor/terravisor/helios/utils/helios_heap.h similarity index 68% rename from src/include/visor/terravisor/cc_os/utils/cc_os_heap.h rename to src/include/visor/terravisor/helios/utils/helios_heap.h index 44ad205a..14dc7506 100644 --- a/src/include/visor/terravisor/cc_os/utils/cc_os_heap.h +++ b/src/include/visor/terravisor/helios/utils/helios_heap.h @@ -2,7 +2,7 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_heap.h + * File Name : helios_heap.h * Description : CC OS Heap declaration (Placeholder) * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team @@ -11,7 +11,7 @@ #include #include #include -#include +#include -void * cc_os_malloc(size_t size); -void cc_os_free(void *addr); +void * helios_malloc(size_t size); +void helios_free(void *addr); diff --git a/src/include/visor/terravisor/helios/utils/helios_sched.h b/src/include/visor/terravisor/helios/utils/helios_sched.h new file mode 100644 index 00000000..83c1d4c1 --- /dev/null +++ b/src/include/visor/terravisor/helios/utils/helios_sched.h @@ -0,0 +1,140 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2022, Cyancore Team + * + * File Name : helios_sched.h + * Description : CC OS Kernel scheduler declaration + * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once + +/***************************************************** + * INCLUDES + *****************************************************/ +#include +#include +#include + +/***************************************************** + * DEFINES + *****************************************************/ +#define HELIOS_NULL_PTR NULL +#define HELIOS_DELAY_MAX SIZE_MAX + +#define HELIOS_DYNAMIC HELIOS_USE_DYNAMIC + +#define HELIOS_ASSERT_IF_FALSE(con) RET_ON_FAIL(con, error_func_inval_arg) + +/***************************************************** + * TYPEDEFS + *****************************************************/ +typedef struct helios_sched_tcb helios_sched_tcb_t; +typedef struct helios_sched helios_sched_t; +typedef const char c_char; +typedef void * helios_args; +typedef void (*task_fn_t)(helios_args args); +typedef void (*helios_cb_hook_t)(helios_args args); +typedef enum +{ + helios_sched_task_status_exit = 0x00, ///> Initial State + helios_sched_task_status_running = 0x01, ///> Task currently running + helios_sched_task_status_ready = 0x02, ///> Task Ready to despatch + helios_sched_task_status_wait = 0x03, ///> Task in wait state + helios_sched_task_status_pause = 0x04, ///> Task in pause state + helios_sched_task_status_max = 0xff, ///> Do Nt Use +} helios_sched_task_status_t; + +/* + * @note All negative callbacks are internally used by the scheduler + */ +typedef enum +{ + helios_sched_cb_power_pre_sleep = 0x00, + helios_sched_cb_power_post_sleep = 0x01, + helios_sched_cb_power_sleep = 0x02, + helios_sched_cb_deadlock_notify = 0x03, + helios_sched_cb_max = 0xff +}helios_sched_cb_t; + +typedef enum +{ + helios_task_flag_set_anti_deadlock = (1 << 0) ///> Enable Antideadlock for the task +}helios_task_flag_t; +typedef struct link +{ + helios_sched_tcb_t * prev; + helios_sched_tcb_t * next; +}link_t; + +typedef struct wres +{ + uintptr_t wait_on_resource; ///> Resource on hich the task is waiting on + size_t task_delay_ticks; ///> Time delay in ticks +}wres_t; + +struct helios_sched_tcb +{ + + c_char * name; ///> Name of the Current Task + uint8_t priority; ///> Priority of the task + uint8_t task_flags; ///> Task Flags + uintptr_t stack_ptr; ///> Stack Pointer + task_fn_t task_func; ///> Task Call Function + uintptr_t args_ptr; ///> Task Call argument ptr + wres_t wait_res; ///> Wait Task resource + link_t ready_link; ///> Ready Linked List Pointers + link_t wait_link; ///> Wait Linked List Pointers + uint16_t task_id; ///> Task ID assigned +#if HELIOS_ANTI_DEADLOCK + size_t task_wd_ticks; ///> Tick down counter for Anti Deadlock system +#endif /* HELIOS_ANTI_DEADLOCK */ + helios_sched_task_status_t task_status; ///> Current state of the task +}; + +typedef struct helios_sched_func_cb +{ + helios_cb_hook_t pre_sched; +#if HELIOS_POWER_SAVE_EN + helios_cb_hook_t pre_sleep_cb; + helios_cb_hook_t post_sleep_cb; + helios_cb_hook_t sleep_cb; +#endif /* HELIOS_POWER_SAVE_EN */ +#if HELIOS_ANTI_DEADLOCK + helios_cb_hook_t deadlock_notify; +#endif /* HELIOS_ANTI_DEADLOCK */ +}helios_sched_func_cb_t; + +typedef struct helios_sched_ctrl +{ + helios_sched_tcb_t * ready_list_head; + helios_sched_tcb_t * curr_task; + helios_sched_tcb_t * wait_list_head; + helios_sched_t * selected_sched; + helios_sched_func_cb_t cb_hooks_reg; +}helios_sched_ctrl_t; + +/** + * @brief Prototype of scheduler algorithm function + */ +typedef void (* algo_fn)(helios_sched_ctrl_t * sched_ctrl); + +typedef enum +{ + helios_sched_algo_round_robin = 0x00, ///> Round Robin scheduling algorithm + helios_sched_algo_priority_driven = 0x01, ///> Priority driven Scheduling + helios_sched_algo_max = 0xff +}helios_sched_algo_t; + +typedef struct helios_sched +{ + helios_sched_algo_t helios_selected_algo; ///> Selected Algorithm ID + algo_fn algo_function; ///> Pointer to algorithm function +}helios_sched_t; + +typedef struct helios_sched_anti_deadlock +{ + c_char * name; + task_fn_t task_func; +}helios_sched_anti_deadlock_t; diff --git a/src/visor/terravisor/services/kernel/cc_os_config.mk b/src/visor/terravisor/services/kernel/cc_os_config.mk index b753b386..96aa435e 100644 --- a/src/visor/terravisor/services/kernel/cc_os_config.mk +++ b/src/visor/terravisor/services/kernel/cc_os_config.mk @@ -3,25 +3,25 @@ # Copyrights (C) 2019, Cyancore Team # # File Name : cc_os_config.mk -# Description : This file consists of CC_OS kernal configuration +# Description : This file consists of HELIOS kernal configuration # Primary Author : Pranjal Chanda[pranjalchanda08@gmail.com] # Organisation : Cyancore Core-Team # -CC_OS_IDLE_TASK_PRIORITY := 1 -CC_OS_USE_DYNAMIC ?= 1 -CC_OS_HEAP_SIZE ?= 1024 -CC_OS_MAX_THREAD ?= 2 -CC_OS_IDLE_TASK_NAME ?= \"CC_OS_IDLE\" -CC_OS_IDLE_TASK_STACK_LEN ?= 255 -CC_OS_POWER_SAVE_EN ?= 0 -CC_OS_ANTI_DEADLOCK ?= 1 +HELIOS_IDLE_TASK_PRIORITY := 1 +HELIOS_USE_DYNAMIC ?= 1 +HELIOS_HEAP_SIZE ?= 1024 +HELIOS_MAX_THREAD ?= 2 +HELIOS_IDLE_TASK_NAME ?= \"HELIOS_IDLE\" +HELIOS_IDLE_TASK_STACK_LEN ?= 255 +HELIOS_POWER_SAVE_EN ?= 0 +HELIOS_ANTI_DEADLOCK ?= 1 -$(eval $(call add_define,CC_OS_USE_DYNAMIC)) -$(eval $(call add_define,CC_OS_HEAP_SIZE)) -$(eval $(call add_define,CC_OS_MAX_THREAD)) -$(eval $(call add_define,CC_OS_IDLE_TASK_NAME)) -$(eval $(call add_define,CC_OS_IDLE_TASK_PRIORITY)) -$(eval $(call add_define,CC_OS_IDLE_TASK_STACK_LEN)) -$(eval $(call add_define,CC_OS_POWER_SAVE_EN)) -$(eval $(call add_define,CC_OS_ANTI_DEADLOCK)) +$(eval $(call add_define,HELIOS_USE_DYNAMIC)) +$(eval $(call add_define,HELIOS_HEAP_SIZE)) +$(eval $(call add_define,HELIOS_MAX_THREAD)) +$(eval $(call add_define,HELIOS_IDLE_TASK_NAME)) +$(eval $(call add_define,HELIOS_IDLE_TASK_PRIORITY)) +$(eval $(call add_define,HELIOS_IDLE_TASK_STACK_LEN)) +$(eval $(call add_define,HELIOS_POWER_SAVE_EN)) +$(eval $(call add_define,HELIOS_ANTI_DEADLOCK)) diff --git a/src/visor/terravisor/services/kernel/cc_os_tasks.c b/src/visor/terravisor/services/kernel/cc_os_tasks.c deleted file mode 100644 index b72a0b4d..00000000 --- a/src/visor/terravisor/services/kernel/cc_os_tasks.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2022, Cyancore Team - * - * File Name : cc_os_tasks.c - * Description : CC OS Kernel tasks related definations definations - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -/***************************************************** - * INCLUDES - *****************************************************/ -#include -#include -#include -#include -#include - -/***************************************************** - * DEFINES - *****************************************************/ -#define CC_OS_PRIORITY_MAX 255 - -/***************************************************** - * INTERNAL EXTERNS FUNCTIONS - *****************************************************/ -extern status_t _cc_os_sched_insert_after(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); -extern status_t _cc_os_sched_insert_before(cc_sched_tcb_t **ptr, cc_sched_tcb_t *new_node, uint8_t link_type); -extern void _cc_sched_send_to_wait(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr, const size_t ticks); -extern void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr); -extern void _cc_sched_send_to_resume(cc_sched_ctrl_t *sched_ctrl, cc_sched_tcb_t *ptr); -extern void _cc_sched_send_back_of_task_prio(cc_sched_tcb_t *node_ptr); -extern void _cc_os_scheduler_despatch(void); -extern void _cc_os_pre_sched(cc_os_args args); -/***************************************************** - * GLOBAL EXTERNS VARIABLES - *****************************************************/ -extern void _cc_os_idle_task_fn(cc_os_args args); -extern cc_sched_t g_cc_sched_list[]; -extern cc_sched_ctrl_t g_sched_ctrl; - -/***************************************************** - * GLOBAL DECLARATIONS - *****************************************************/ -#if CC_OS_DYNAMIC == false -extern cc_sched_tcb_t g_cc_os_tcb_list[]; -#else -extern cc_sched_tcb_t *g_cc_os_tcb_list; -#endif - -#if CC_OS_DYNAMIC == false -uint8_t _cc_os_stack[CC_OS_IDLE_TASK_STACK_LEN]; -#else -uint8_t *_cc_os_stack = CC_OS_NULL_PTR; -#endif -cc_os_task_t cc_os_idle_task; -/***************************************************** - * STATIC VARIABLES - *****************************************************/ -static uint16_t __cc_os_task_id_gen = false; -/***************************************************** - * STATIC FUNCTION DEFINATIONS - *****************************************************/ -static void __cc_init_scheduler(void) -{ - g_sched_ctrl.cb_hooks_reg.pre_sched = &_cc_os_pre_sched; - return; -} - -static uint16_t __cc_os_task_id_generate() -{ - __cc_os_task_id_gen++; - return __cc_os_task_id_gen; -} - -static cc_sched_tcb_t * __cc_os_get_tcb_using_task_id(const uintptr_t task_id) -{ - cc_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head; - bool _is_id_found = false; - while (ptr->ready_link.next != g_sched_ctrl.ready_list_head) - { - if (ptr->task_id == task_id) - { - _is_id_found = true; - break; - } - ptr = ptr->ready_link.next; - } - if (_is_id_found == false) - { - ptr = CC_OS_NULL_PTR; - } - return ptr; -} - -static status_t __cc_os_set_task_flag(cc_sched_tcb_t* cc_os_task, cc_task_flag_t task_flag, bool en) -{ - CC_OS_ASSERT_IF_FALSE( cc_os_task != CC_OS_NULL_PTR); - - if (en) - { - cc_os_task->task_flags |= (uint8_t)task_flag; - } - else - { - cc_os_task->task_flags &= (uint8_t)~task_flag; - } - return success; -} - -static bool __cc_os_is_task_flag(const cc_sched_tcb_t *cc_os_task, cc_task_flag_t task_flag) -{ - if (cc_os_task != CC_OS_NULL_PTR) - { - return (cc_os_task->task_flags & task_flag) == false; - } - - return false; -} - -/***************************************************** - * USER FUNCTION DEFINATIONS - *****************************************************/ -status_t cc_os_add_task( - cc_os_task_t *cc_os_task, - const char *name, - task_fn_t task_func, - cc_os_args args, - uint8_t priority, - size_t stack_len, -#if CC_OS_DYNAMIC - uintptr_t stack_ptr _UNUSED -#else - uintptr_t stack_ptr -#endif /* CC_OS_DYNAMIC */ -) -{ - CC_OS_ASSERT_IF_FALSE(*cc_os_task == (uintptr_t)CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(name != CC_OS_NULL_PTR); -#if CC_OS_DYNAMIC == false - CC_OS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t)CC_OS_NULL_PTR); -#endif - CC_OS_ASSERT_IF_FALSE(task_func != CC_OS_NULL_PTR); - CC_OS_ASSERT_IF_FALSE(stack_len != false); - CC_OS_ASSERT_IF_FALSE(priority >= CC_OS_IDLE_TASK_PRIORITY); - CC_OS_ASSERT_IF_FALSE(priority < CC_OS_PRIORITY_MAX); - - cc_os_pause_all_task(); - - cc_sched_tcb_t *ptr = CC_OS_NULL_PTR; - -#if CC_OS_DYNAMIC == false - /* Static Task Allocation */ - for (size_t i = false; i < CC_OS_MAX_THREAD; i++) - { - /* Get an available node from global tcb list */ - if (g_cc_os_tcb_list[i].task_status == cc_sched_task_status_exit) - { - ptr = &(g_cc_os_tcb_list[i]); - break; - } - } - if (ptr != g_sched_ctrl.ready_list_head) - { - ptr->stack_ptr = stack_ptr; -#else - /* Dynamic Task Declaration */ - ptr = (cc_sched_tcb_t *)cc_os_malloc(sizeof(cc_sched_tcb_t)); - if (ptr != CC_OS_NULL_PTR) - { - ptr->stack_ptr = (uintptr_t)malloc(stack_len); - if (ptr->stack_ptr == (uintptr_t)CC_OS_NULL_PTR) - { - cc_os_resume_all_task(); - return error_memory_low; - } -#endif /* CC_OS_DYNAMIC */ - } - else - { - cc_os_resume_all_task(); - return error_memory_low; - } - /* Fill tcb details */ - ptr->name = name; - ptr->priority = priority; - ptr->task_func = task_func; - ptr->args_ptr = (uintptr_t)args; -#if CC_OS_ANTI_DEADLOCK - ptr->task_wd_ticks = SIZE_MAX; -#endif /* CC_OS_ANTI_DEADLOCK */ - if (g_sched_ctrl.ready_list_head == CC_OS_NULL_PTR) - { - ptr->ready_link.next = ptr->ready_link.prev = g_sched_ctrl.ready_list_head = ptr; - } - /* Insert Tasks in assending order of its priority */ - _cc_sched_send_back_of_task_prio(ptr); - ptr->task_status = cc_sched_task_status_ready; - ptr->task_id = __cc_os_task_id_generate(); - *cc_os_task = ptr->task_id; - cc_os_resume_all_task(); - return success; -} - -status_t cc_os_del_task(cc_os_task_t cc_os_task) -{ - cc_sched_tcb_t * ptr = __cc_os_get_tcb_using_task_id(cc_os_task); - - if (ptr == CC_OS_NULL_PTR) - { - ptr = g_sched_ctrl.curr_task; - } - CC_OS_ASSERT_IF_FALSE(ptr->task_func != &_cc_os_idle_task_fn); - /* Code to handle first node */ - if (ptr == g_sched_ctrl.ready_list_head) - { - /* IDLE Task can not be deleted */ - return error_os_invalid_op; - } - ptr->task_status = cc_sched_task_status_exit; - - if (ptr == g_sched_ctrl.curr_task) - { - cc_os_task_yield(); /* Yeild */ - } - - return success; -} - -status_t cc_os_pause_task(cc_os_task_t cc_os_task) -{ - cc_sched_tcb_t *ptr = __cc_os_get_tcb_using_task_id(cc_os_task); - if (ptr == CC_OS_NULL_PTR) - { - ptr = g_sched_ctrl.curr_task; - } - - _cc_sched_send_to_pause(&g_sched_ctrl, ptr); - - return success; -} - -status_t cc_os_pause_all_task(void) -{ - cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; - if(ptr != CC_OS_NULL_PTR) - { - while (true) - { - if (ptr == g_sched_ctrl.curr_task) - { - /* Do not pause the current task */ - continue; - } - - _cc_sched_send_to_pause(&g_sched_ctrl, ptr); - ptr = ptr->ready_link.next; - - if(ptr == g_sched_ctrl.ready_list_head) - { - break; - } - } - } - - return success; -} - -status_t cc_os_resume_all_task(void) -{ - cc_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; - if (ptr != CC_OS_NULL_PTR) - { - while (true) - { - ptr = ptr->ready_link.next; - _cc_sched_send_to_resume(&g_sched_ctrl, ptr); - if (ptr == g_sched_ctrl.ready_list_head) - { - break; - } - } - } - else - { - return error_os_invalid_op; - } - - return success; -} - -status_t cc_os_resume_task(cc_os_task_t cc_os_task) -{ - cc_sched_tcb_t *ptr = __cc_os_get_tcb_using_task_id(cc_os_task); - CC_OS_ASSERT_IF_FALSE(ptr != CC_OS_NULL_PTR); - - if (ptr->task_status != cc_sched_task_status_pause) - { - _cc_sched_send_to_resume(&g_sched_ctrl, ptr); - } - else - { - return error_os_invalid_op; - } - return success; -} - -status_t cc_os_set_sched_algo(cc_sched_algo_t sched_algo) -{ - CC_OS_ASSERT_IF_FALSE(sched_algo != cc_sched_algo_max); - - g_sched_ctrl.selected_sched = &(g_cc_sched_list[sched_algo]); - - return success; -} - -status_t cc_os_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks _UNUSED) -{ -#if CC_OS_ANTI_DEADLOCK - CC_OS_ASSERT_IF_FALSE((task_wd_ticks > false) && (task_wd_ticks < SIZE_MAX)); - - cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; - if (__cc_os_is_task_flag(ptr, cc_task_flag_set_anti_deadlock)) - { - __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, true); - } - - ptr->task_wd_ticks = task_wd_ticks; - return success; -#else - cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; - if (__cc_os_is_task_flag(ptr, cc_task_flag_set_anti_deadlock)) - { - __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, false); - } - return error_func_inval; -#endif /* CC_OS_ANTI_DEADLOCK */ -} - -status_t cc_os_task_anti_deadlock_disable(void) -{ - cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; - - if (__cc_os_is_task_flag(ptr, cc_task_flag_set_anti_deadlock)) - { - __cc_os_set_task_flag(ptr, cc_task_flag_set_anti_deadlock, false); - } - -#if CC_OS_ANTI_DEADLOCK - ptr->task_wd_ticks = SIZE_MAX; - return success; -#else - return error_func_inval; -#endif /* CC_OS_ANTI_DEADLOCK */ -} -status_t cc_os_set_callback(const cc_sched_cb_t cb_type, const cc_cb_hook_t cb_func _UNUSED) -{ - status_t ret = success; - switch (cb_type) - { - case cc_sched_cb_power_post_sleep: -#if CC_OS_POWER_SAVE_EN - g_sched_ctrl.cb_hooks_reg.post_sleep_cb = cb_func; - break; -#endif - case cc_sched_cb_power_pre_sleep: -#if CC_OS_POWER_SAVE_EN - g_sched_ctrl.cb_hooks_reg.pre_sleep_cb = cb_func; - break; -#endif - case cc_sched_cb_power_sleep: -#if CC_OS_POWER_SAVE_EN - g_sched_ctrl.cb_hooks_reg.power_sleep = cb_func; - break; -#endif - case cc_sched_cb_deadlock_notify: -#if CC_OS_ANTI_DEADLOCK - g_sched_ctrl.cb_hooks_reg.deadlock_notify = cb_func; - break; -#endif - case cc_sched_cb_max: - ret = error_func_inval; - break; - } - return ret; -} - -const char *cc_os_get_curr_task_name(void) -{ - return g_sched_ctrl.curr_task->name; -} - -const char *cc_os_get_task_name(cc_os_task_t cc_os_task) -{ - const cc_sched_tcb_t *ptr = __cc_os_get_tcb_using_task_id(cc_os_task); - if(ptr != CC_OS_NULL_PTR) - { - return ptr->name; - } - return CC_OS_NULL_PTR; -} - -void cc_os_task_wait(const size_t ticks) -{ - cc_sched_tcb_t *ptr = g_sched_ctrl.curr_task; - - if (ticks > false) - { - _cc_sched_send_to_wait(&g_sched_ctrl, ptr, ticks); - } - - cc_os_task_yield(); -} - -void cc_os_task_yield() -{ - _cc_os_scheduler_despatch(); - return; -} - -void cc_os_run(void) -{ - /* OS Init code */ - /* Initialise IDLE Task */ - cc_os_add_task(&cc_os_idle_task, - CC_OS_IDLE_TASK_NAME, - &_cc_os_idle_task_fn, - &g_sched_ctrl, - CC_OS_IDLE_TASK_PRIORITY, - CC_OS_IDLE_TASK_STACK_LEN, - (uintptr_t)_cc_os_stack); - - /* Initialise scheduler */ - __cc_init_scheduler(); - cc_os_task_yield(); /* Yeild */ - while (true) - { - /* Code shall not reach here */ - arch_wfi(); - } -} diff --git a/src/visor/terravisor/services/kernel/cc_os_heap.c b/src/visor/terravisor/services/kernel/helios_heap.c similarity index 86% rename from src/visor/terravisor/services/kernel/cc_os_heap.c rename to src/visor/terravisor/services/kernel/helios_heap.c index e307f9bb..6942085e 100644 --- a/src/visor/terravisor/services/kernel/cc_os_heap.c +++ b/src/visor/terravisor/services/kernel/helios_heap.c @@ -2,7 +2,7 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_heap.c + * File Name : helios_heap.c * Description : CC OS Kernel definations * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team @@ -11,7 +11,7 @@ /***************************************************** * INCLUDES *****************************************************/ -#include +#include /***************************************************** * GLOBAL/STATIC VARIABLE DECLARATIONS @@ -28,11 +28,11 @@ /***************************************************** * USER FUNCTION DEFINATIONS *****************************************************/ -void * cc_os_malloc(size_t size) +void * helios_malloc(size_t size) { return malloc(size); } -void cc_os_free(void *addr ) +void helios_free(void *addr ) { free(addr); } diff --git a/src/visor/terravisor/services/kernel/cc_os_sched.c b/src/visor/terravisor/services/kernel/helios_sched.c similarity index 58% rename from src/visor/terravisor/services/kernel/cc_os_sched.c rename to src/visor/terravisor/services/kernel/helios_sched.c index 9355b111..763bafff 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sched.c +++ b/src/visor/terravisor/services/kernel/helios_sched.c @@ -2,7 +2,7 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_sched.c + * File Name : helios_sched.c * Description : CC OS Kernel scheduler definations * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team @@ -11,50 +11,50 @@ /***************************************************** * INCLUDES *****************************************************/ -#include +#include #include /***************************************************** * DEFINES *****************************************************/ #define CC_SCHED_ALGO(_id, _fn) { \ - .cc_selected_algo = _id, \ + .helios_selected_algo = _id, \ .algo_function = _fn} /***************************************************** * STATIC FUNCTION DECLARATION *****************************************************/ -static void __cc_sched_deadlock_adjustment_and_detection(const cc_sched_ctrl_t * sched_ctrl); -static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl); -static void __cc_sched_algo_round_robin_fn(cc_sched_ctrl_t * sched_ctrl); -static void __cc_sched_algo_priority_driven_fn(cc_sched_ctrl_t * sched_ctrl); +static void __helios_sched_deadlock_adjustment_and_detection(const helios_sched_ctrl_t * sched_ctrl); +static void __helios_sched_wait_list_adjustment(helios_sched_ctrl_t * sched_ctrl); +static void __helios_sched_algo_round_robin_fn(helios_sched_ctrl_t * sched_ctrl); +static void __helios_sched_algo_priority_driven_fn(helios_sched_ctrl_t * sched_ctrl); /***************************************************** * GLOBAL DECLARATIONS *****************************************************/ -#if !CC_OS_USE_DYNAMIC -cc_sched_tcb_t g_cc_os_tcb_list [CC_OS_MAX_THREAD]; +#if !HELIOS_USE_DYNAMIC +helios_sched_tcb_t g_helios_tcb_list [HELIOS_MAX_THREAD]; #else -cc_sched_tcb_t * g_cc_os_tcb_list = CC_OS_NULL_PTR; +helios_sched_tcb_t * g_helios_tcb_list = HELIOS_NULL_PTR; #endif -cc_sched_t g_cc_sched_list [] = +helios_sched_t g_helios_sched_list [] = { - CC_SCHED_ALGO(cc_sched_algo_round_robin, __cc_sched_algo_round_robin_fn), - CC_SCHED_ALGO(cc_sched_algo_priority_driven, __cc_sched_algo_priority_driven_fn), + CC_SCHED_ALGO(helios_sched_algo_round_robin, __helios_sched_algo_round_robin_fn), + CC_SCHED_ALGO(helios_sched_algo_priority_driven, __helios_sched_algo_priority_driven_fn), }; -cc_sched_ctrl_t g_sched_ctrl = +helios_sched_ctrl_t g_sched_ctrl = { -#if !CC_OS_USE_DYNAMIC - .ready_list_head = &(g_cc_os_tcb_list[false]), - .curr_task = &(g_cc_os_tcb_list[false]), +#if !HELIOS_USE_DYNAMIC + .ready_list_head = &(g_helios_tcb_list[false]), + .curr_task = &(g_helios_tcb_list[false]), #else - .ready_list_head = CC_OS_NULL_PTR, - .curr_task = CC_OS_NULL_PTR, + .ready_list_head = HELIOS_NULL_PTR, + .curr_task = HELIOS_NULL_PTR, #endif - .wait_list_head = CC_OS_NULL_PTR, - .selected_sched = &(g_cc_sched_list[cc_sched_algo_round_robin]) + .wait_list_head = HELIOS_NULL_PTR, + .selected_sched = &(g_helios_sched_list[helios_sched_algo_round_robin]) }; /***************************************************** @@ -70,13 +70,13 @@ cc_sched_ctrl_t g_sched_ctrl = * * @return None */ -status_t _cc_os_sched_insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) +status_t _helios_sched_insert_after(helios_sched_tcb_t ** ptr, helios_sched_tcb_t * new_node, uint8_t link_type) { - CC_OS_ASSERT_IF_FALSE(new_node != CC_OS_NULL_PTR); + HELIOS_ASSERT_IF_FALSE(new_node != HELIOS_NULL_PTR); if (link_type == true) { /* Wait Link */ - if (*ptr == CC_OS_NULL_PTR) + if (*ptr == HELIOS_NULL_PTR) { *ptr = new_node; new_node->wait_link.next = new_node; @@ -93,7 +93,7 @@ status_t _cc_os_sched_insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_n else { /* Ready Link */ - if (*ptr == CC_OS_NULL_PTR) + if (*ptr == HELIOS_NULL_PTR) { *ptr = new_node; new_node->ready_link.next = new_node; @@ -119,13 +119,13 @@ status_t _cc_os_sched_insert_after(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_n * * @return None */ -status_t _cc_os_sched_insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_node, uint8_t link_type) +status_t _helios_sched_insert_before(helios_sched_tcb_t ** ptr, helios_sched_tcb_t * new_node, uint8_t link_type) { - CC_OS_ASSERT_IF_FALSE(new_node != CC_OS_NULL_PTR); + HELIOS_ASSERT_IF_FALSE(new_node != HELIOS_NULL_PTR); if (link_type == true) { /* Wait Link */ - if (*ptr == CC_OS_NULL_PTR) + if (*ptr == HELIOS_NULL_PTR) { *ptr = new_node; new_node->wait_link.next = new_node; @@ -142,7 +142,7 @@ status_t _cc_os_sched_insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_ else { /* Ready Link */ - if (*ptr == CC_OS_NULL_PTR) + if (*ptr == HELIOS_NULL_PTR) { *ptr = new_node; new_node->ready_link.next = new_node; @@ -167,16 +167,16 @@ status_t _cc_os_sched_insert_before(cc_sched_tcb_t ** ptr, cc_sched_tcb_t * new_ * * @return None */ -void _cc_sched_send_to_wait(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, const size_t ticks) +void _helios_sched_send_to_wait(helios_sched_ctrl_t * sched_ctrl, helios_sched_tcb_t * ptr, const size_t ticks) { - if (ptr->task_status == cc_sched_task_status_wait) + if (ptr->task_status == helios_sched_task_status_wait) { return; } - if(_cc_os_sched_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) + if(_helios_sched_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) { ptr->wait_res.task_delay_ticks = ticks; - ptr->task_status = cc_sched_task_status_wait; + ptr->task_status = helios_sched_task_status_wait; } } @@ -188,16 +188,16 @@ void _cc_sched_send_to_wait(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr, * * @return None */ -void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) +void _helios_sched_send_to_pause(helios_sched_ctrl_t * sched_ctrl, helios_sched_tcb_t * ptr) { - if (ptr->task_status == cc_sched_task_status_pause) + if (ptr->task_status == helios_sched_task_status_pause) { return; } - if(_cc_os_sched_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) + if(_helios_sched_insert_before(&(sched_ctrl->wait_list_head), ptr, true) == success) { - ptr->wait_res.task_delay_ticks = CC_OS_DELAY_MAX; - ptr->task_status = cc_sched_task_status_pause; + ptr->wait_res.task_delay_ticks = HELIOS_DELAY_MAX; + ptr->task_status = helios_sched_task_status_pause; } } @@ -209,9 +209,9 @@ void _cc_sched_send_to_pause(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) * * @return None */ -void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr) +void _helios_sched_send_to_resume(helios_sched_ctrl_t * sched_ctrl, helios_sched_tcb_t * ptr) { - if (ptr->task_status < cc_sched_task_status_wait) + if (ptr->task_status < helios_sched_task_status_wait) { return; } @@ -223,15 +223,15 @@ void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr if (ptr->wait_link.next == ptr && ptr->wait_link.prev == ptr) { /* Last Wait task left */ - sched_ctrl->wait_list_head = CC_OS_NULL_PTR; + sched_ctrl->wait_list_head = HELIOS_NULL_PTR; } } ptr->wait_link.prev->wait_link.next = ptr->wait_link.next; ptr->wait_link.next->wait_link.prev = ptr->wait_link.prev; - ptr->wait_link.prev = CC_OS_NULL_PTR; - ptr->wait_link.next = CC_OS_NULL_PTR; + ptr->wait_link.prev = HELIOS_NULL_PTR; + ptr->wait_link.next = HELIOS_NULL_PTR; ptr->wait_res.task_delay_ticks = false; - ptr->task_status = cc_sched_task_status_ready; + ptr->task_status = helios_sched_task_status_ready; } /** @@ -242,16 +242,16 @@ void _cc_sched_send_to_resume(cc_sched_ctrl_t * sched_ctrl, cc_sched_tcb_t * ptr * * @return None */ -status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_type) +status_t _helios_sched_node_detach(helios_sched_tcb_t *node_ptr, uint8_t link_type) { - CC_OS_ASSERT_IF_FALSE(node_ptr == CC_OS_NULL_PTR); + HELIOS_ASSERT_IF_FALSE(node_ptr == HELIOS_NULL_PTR); if (link_type == true) { /* Wait Link */ node_ptr->wait_link.prev->wait_link.next = node_ptr->wait_link.next; node_ptr->wait_link.next->wait_link.prev = node_ptr->wait_link.prev; - node_ptr->wait_link.prev = node_ptr->wait_link.next = CC_OS_NULL_PTR; + node_ptr->wait_link.prev = node_ptr->wait_link.next = HELIOS_NULL_PTR; if (node_ptr == g_sched_ctrl.wait_list_head) { g_sched_ctrl.wait_list_head = node_ptr->ready_link.next; @@ -262,7 +262,7 @@ status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_type) /* Ready Link */ node_ptr->ready_link.prev->ready_link.next = node_ptr->ready_link.next; node_ptr->ready_link.next->ready_link.prev = node_ptr->ready_link.prev; - node_ptr->ready_link.prev = node_ptr->ready_link.next = CC_OS_NULL_PTR; + node_ptr->ready_link.prev = node_ptr->ready_link.next = HELIOS_NULL_PTR; if (node_ptr == g_sched_ctrl.ready_list_head) { @@ -279,10 +279,10 @@ status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_type) * * @return None */ -void _cc_sched_send_back_of_task_prio(cc_sched_tcb_t *node_ptr) +void _helios_sched_send_back_of_task_prio(helios_sched_tcb_t *node_ptr) { - cc_sched_tcb_t * ref_ptr = g_sched_ctrl.ready_list_head; - if(ref_ptr != CC_OS_NULL_PTR) + helios_sched_tcb_t * ref_ptr = g_sched_ctrl.ready_list_head; + if(ref_ptr != HELIOS_NULL_PTR) { if (node_ptr == ref_ptr) { @@ -313,7 +313,7 @@ void _cc_sched_send_back_of_task_prio(cc_sched_tcb_t *node_ptr) * New Node * Insert it behind the same priority */ - _cc_os_sched_insert_before(&ref_ptr, node_ptr, false); + _helios_sched_insert_before(&ref_ptr, node_ptr, false); } else { @@ -323,26 +323,26 @@ void _cc_sched_send_back_of_task_prio(cc_sched_tcb_t *node_ptr) * This would help to round robin over the same priority when * scheduling */ - _cc_sched_node_detach(node_ptr, false); - _cc_os_sched_insert_before(&node_ptr, ref_ptr, false); + _helios_sched_node_detach(node_ptr, false); + _helios_sched_insert_before(&node_ptr, ref_ptr, false); } } } /** - * @brief CC_OS pre scheduler callback being called before any task scheduling is done + * @brief HELIOS pre scheduler callback being called before any task scheduling is done * - * @param args[in] cc_os_args (provides scheduler ctrl) + * @param args[in] helios_args (provides scheduler ctrl) * * @return None */ -void _cc_os_pre_sched(cc_os_args args) +void _helios_pre_sched(helios_args args) { - cc_sched_ctrl_t * sched_ctrl = (cc_sched_ctrl_t *) args; - sched_ctrl->curr_task->task_status = cc_sched_task_status_ready; - __cc_sched_wait_list_adjustment(sched_ctrl); - __cc_sched_deadlock_adjustment_and_detection(sched_ctrl); - _cc_sched_send_back_of_task_prio(sched_ctrl->curr_task); + helios_sched_ctrl_t * sched_ctrl = (helios_sched_ctrl_t *) args; + sched_ctrl->curr_task->task_status = helios_sched_task_status_ready; + __helios_sched_wait_list_adjustment(sched_ctrl); + __helios_sched_deadlock_adjustment_and_detection(sched_ctrl); + _helios_sched_send_back_of_task_prio(sched_ctrl->curr_task); } /** @@ -350,12 +350,12 @@ void _cc_os_pre_sched(cc_os_args args) * * @return None */ -void _cc_os_scheduler_despatch(void) +void _helios_scheduler_despatch(void) { if (g_sched_ctrl.cb_hooks_reg.pre_sched != NULL) { /* Call Pre_sched Function */ - g_sched_ctrl.cb_hooks_reg.pre_sched((cc_os_args) &g_sched_ctrl); + g_sched_ctrl.cb_hooks_reg.pre_sched((helios_args) &g_sched_ctrl); } else { @@ -378,34 +378,34 @@ void _cc_os_scheduler_despatch(void) /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ -static void __cc_sched_context_switch(cc_sched_tcb_t * next_task) +static void __helios_sched_context_switch(helios_sched_tcb_t * next_task) { - next_task->task_status = cc_sched_task_status_running; + next_task->task_status = helios_sched_task_status_running; } -static void __cc_sched_deadlock_adjustment_and_detection(const cc_sched_ctrl_t * sched_ctrl _UNUSED) +static void __helios_sched_deadlock_adjustment_and_detection(const helios_sched_ctrl_t * sched_ctrl _UNUSED) { -#if CC_OS_ANTI_DEADLOCK - cc_sched_tcb_t * ptr = sched_ctrl->ready_list_head; - static cc_sched_anti_deadlock_t anti_deadlock_notify; - while (ptr != CC_OS_NULL_PTR) +#if HELIOS_ANTI_DEADLOCK + helios_sched_tcb_t * ptr = sched_ctrl->ready_list_head; + static helios_sched_anti_deadlock_t anti_deadlock_notify; + while (ptr != HELIOS_NULL_PTR) { - if (ptr->task_status != cc_sched_task_status_pause) + if (ptr->task_status != helios_sched_task_status_pause) { ptr->task_wd_ticks--; } - if ((ptr->task_wd_ticks == false) && (sched_ctrl->cb_hooks_reg.deadlock_notify != CC_OS_NULL_PTR)) + if ((ptr->task_wd_ticks == false) && (sched_ctrl->cb_hooks_reg.deadlock_notify != HELIOS_NULL_PTR)) { /* Create notification params */ anti_deadlock_notify.name = ptr->name; anti_deadlock_notify.task_func = ptr->task_func; - if (ptr->task_status != cc_sched_task_status_exit) + if (ptr->task_status != helios_sched_task_status_exit) { - ptr->task_status = cc_sched_task_status_exit; + ptr->task_status = helios_sched_task_status_exit; } /* Notify the user that the task pointed by ptr is dead and has been terminated */ - sched_ctrl->cb_hooks_reg.deadlock_notify((cc_os_args) &anti_deadlock_notify); + sched_ctrl->cb_hooks_reg.deadlock_notify((helios_args) &anti_deadlock_notify); } if (ptr->ready_link.next == sched_ctrl->ready_list_head) { @@ -414,19 +414,19 @@ static void __cc_sched_deadlock_adjustment_and_detection(const cc_sched_ctrl_t * } #else return; -#endif /* CC_OS_ANTI_DEADLOCK */ +#endif /* HELIOS_ANTI_DEADLOCK */ } -static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) +static void __helios_sched_wait_list_adjustment(helios_sched_ctrl_t * sched_ctrl) { - cc_sched_tcb_t * ptr = sched_ctrl->wait_list_head; + helios_sched_tcb_t * ptr = sched_ctrl->wait_list_head; const int * wait_res = (int *)ptr->wait_res.wait_on_resource; - while(ptr != CC_OS_NULL_PTR) + while(ptr != HELIOS_NULL_PTR) { - if (ptr->task_status == cc_sched_task_status_wait) + if (ptr->task_status == helios_sched_task_status_wait) { ptr->wait_res.task_delay_ticks--; /* Tick caliberations required */ - if ((wait_res != CC_OS_NULL_PTR) && *wait_res > false) + if ((wait_res != HELIOS_NULL_PTR) && *wait_res > false) { /* The resource is available can can go to ready state */ ptr->wait_res.task_delay_ticks = false; @@ -434,7 +434,7 @@ static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) } if(ptr->wait_res.task_delay_ticks == false) { - _cc_sched_send_to_resume(sched_ctrl, ptr); + _helios_sched_send_to_resume(sched_ctrl, ptr); } if (ptr->wait_link.next == sched_ctrl->wait_list_head) { @@ -451,39 +451,39 @@ static void __cc_sched_wait_list_adjustment(cc_sched_ctrl_t * sched_ctrl) /***************************************************** * SCHEDULER ALGORITHMS *****************************************************/ -static void __cc_sched_algo_round_robin_fn(cc_sched_ctrl_t * sched_ctrl) +static void __helios_sched_algo_round_robin_fn(helios_sched_ctrl_t * sched_ctrl) { /* do waitlist adjustment */ - cc_sched_tcb_t * ptr = sched_ctrl->curr_task->ready_link.next; + helios_sched_tcb_t * ptr = sched_ctrl->curr_task->ready_link.next; if (ptr == sched_ctrl->ready_list_head) { /* IDLE Task */ - _cc_sched_send_to_resume(&g_sched_ctrl, ptr); + _helios_sched_send_to_resume(&g_sched_ctrl, ptr); } /* Context switch to next task */ - if (ptr->task_status == cc_sched_task_status_ready) + if (ptr->task_status == helios_sched_task_status_ready) { - __cc_sched_context_switch(ptr->ready_link.next); + __helios_sched_context_switch(ptr->ready_link.next); } } -static void __cc_sched_algo_priority_driven_fn(cc_sched_ctrl_t * sched_ctrl) +static void __helios_sched_algo_priority_driven_fn(helios_sched_ctrl_t * sched_ctrl) { /* do waitlist adjustment */ - cc_sched_tcb_t * ptr = sched_ctrl->ready_list_head->ready_link.prev; - if(ptr != CC_OS_NULL_PTR) + helios_sched_tcb_t * ptr = sched_ctrl->ready_list_head->ready_link.prev; + if(ptr != HELIOS_NULL_PTR) { - while (ptr->task_status != cc_sched_task_status_ready) + while (ptr->task_status != helios_sched_task_status_ready) { ptr = ptr->wait_link.prev; if (ptr == sched_ctrl->ready_list_head) { /* IDLE Task */ - _cc_sched_send_to_resume(&g_sched_ctrl, ptr); + _helios_sched_send_to_resume(&g_sched_ctrl, ptr); break; } } - __cc_sched_context_switch(ptr); + __helios_sched_context_switch(ptr); } } diff --git a/src/visor/terravisor/services/kernel/cc_os_sem.c b/src/visor/terravisor/services/kernel/helios_sem.c similarity index 54% rename from src/visor/terravisor/services/kernel/cc_os_sem.c rename to src/visor/terravisor/services/kernel/helios_sem.c index 3703b5db..f45e4558 100644 --- a/src/visor/terravisor/services/kernel/cc_os_sem.c +++ b/src/visor/terravisor/services/kernel/helios_sem.c @@ -2,16 +2,16 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_sem.c + * File Name : helios_sem.c * Description : CC OS Semaphore function definations - * Primary Author : Pranjal Chanda [pranjalchandaCC_OS_FALSE8@gmail.com] + * Primary Author : Pranjal Chanda [pranjalchandaHELIOS_FALSE8@gmail.com] * Organisation : Cyancore Core-Team */ /***************************************************** * INCLUDES *****************************************************/ -#include +#include /***************************************************** * GLOBAL/STATIC VARIABLE DECLARATIONS @@ -20,7 +20,7 @@ /***************************************************** * GLOBAL EXTERNS *****************************************************/ -extern cc_sched_ctrl_t g_sched_ctrl; +extern helios_sched_ctrl_t g_sched_ctrl; /***************************************************** * STATIC FUNCTION DEFINATIONS *****************************************************/ @@ -29,14 +29,14 @@ extern cc_sched_ctrl_t g_sched_ctrl; * USER FUNCTION DEFINATIONS *****************************************************/ -status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val) +status_t helios_sem_create (sem_t ** sem_ptr, size_t init_val) { -#if CC_OS_DYNAMIC == false - CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init == false)); +#if HELIOS_DYNAMIC == false + HELIOS_ASSERT_IF_FALSE((*sem_ptr != HELIOS_NULL_PTR && (*sem_ptr)->sem_init == false)); #else - CC_OS_ASSERT_IF_FALSE(*sem_ptr == CC_OS_NULL_PTR); - *sem_ptr = cc_os_malloc(sizeof(sem_t)); - if (*sem_ptr == CC_OS_NULL_PTR) + HELIOS_ASSERT_IF_FALSE(*sem_ptr == HELIOS_NULL_PTR); + *sem_ptr = helios_malloc(sizeof(sem_t)); + if (*sem_ptr == HELIOS_NULL_PTR) { return error_memory_low; } @@ -46,9 +46,9 @@ status_t cc_os_sem_create (sem_t ** sem_ptr, size_t init_val) return success; } -status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks) +status_t helios_sem_take (sem_t * sem_ptr, size_t wait_ticks) { - CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != false)); + HELIOS_ASSERT_IF_FALSE((sem_ptr != HELIOS_NULL_PTR && sem_ptr->sem_init != false)); if (sem_ptr->sem_val == false) { @@ -58,7 +58,7 @@ status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks) } else { g_sched_ctrl.curr_task->wait_res.wait_on_resource = (uintptr_t) sem_ptr; - cc_os_task_wait(wait_ticks); + helios_task_wait(wait_ticks); } } else @@ -67,30 +67,30 @@ status_t cc_os_sem_take (sem_t * sem_ptr, size_t wait_ticks) } return success; } -status_t cc_os_sem_give (sem_t * sem_ptr) +status_t helios_sem_give (sem_t * sem_ptr) { - CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != false)); + HELIOS_ASSERT_IF_FALSE((sem_ptr != HELIOS_NULL_PTR && sem_ptr->sem_init != false)); sem_ptr->sem_val++; return success; } -status_t cc_os_sem_delete (sem_t ** sem_ptr) +status_t helios_sem_delete (sem_t ** sem_ptr) { - CC_OS_ASSERT_IF_FALSE((*sem_ptr != CC_OS_NULL_PTR && (*sem_ptr)->sem_init != false)); + HELIOS_ASSERT_IF_FALSE((*sem_ptr != HELIOS_NULL_PTR && (*sem_ptr)->sem_init != false)); (*sem_ptr)->sem_init = false; -#if CC_OS_DYNAMIC == true - cc_os_free(*sem_ptr); +#if HELIOS_DYNAMIC == true + helios_free(*sem_ptr); #endif return success; } -status_t cc_os_sem_get_val (const sem_t * sem_ptr, size_t * val) +status_t helios_sem_get_val (const sem_t * sem_ptr, size_t * val) { - CC_OS_ASSERT_IF_FALSE((sem_ptr != CC_OS_NULL_PTR && sem_ptr->sem_init != false)); - CC_OS_ASSERT_IF_FALSE(val != CC_OS_NULL_PTR); + HELIOS_ASSERT_IF_FALSE((sem_ptr != HELIOS_NULL_PTR && sem_ptr->sem_init != false)); + HELIOS_ASSERT_IF_FALSE(val != HELIOS_NULL_PTR); *val = sem_ptr->sem_val; diff --git a/src/visor/terravisor/services/kernel/cc_os_task_idle.c b/src/visor/terravisor/services/kernel/helios_task_idle.c similarity index 53% rename from src/visor/terravisor/services/kernel/cc_os_task_idle.c rename to src/visor/terravisor/services/kernel/helios_task_idle.c index e2a1b41d..ed74ca67 100644 --- a/src/visor/terravisor/services/kernel/cc_os_task_idle.c +++ b/src/visor/terravisor/services/kernel/helios_task_idle.c @@ -2,7 +2,7 @@ * CYANCORE LICENSE * Copyrights (C) 2022, Cyancore Team * - * File Name : cc_os_task_idle.c + * File Name : helios_task_idle.c * Description : CC OS IDLE Task definitions * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] * Organisation : Cyancore Core-Team @@ -11,13 +11,13 @@ /***************************************************** * INCLUDES *****************************************************/ -#include +#include #include /***************************************************** * EXTERN FUNCTION DECLARATION *****************************************************/ -extern status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_type); +extern status_t _helios_sched_node_detach(helios_sched_tcb_t *node_ptr, uint8_t link_type); /***************************************************** * STATIC FUNCTION DECLARATION @@ -26,26 +26,26 @@ extern status_t _cc_sched_node_detach(cc_sched_tcb_t *node_ptr, uint8_t link_typ * @brief This function cleans up the terminated task form the TCB list * * @param ptr[in] Pointer to the TCB being cleaned - * @return cc_sched_tcb_t * Pointer to the next TCB + * @return helios_sched_tcb_t * Pointer to the next TCB */ -static cc_sched_tcb_t * __free_terminated_task(cc_sched_tcb_t * ptr) +static helios_sched_tcb_t * __free_terminated_task(helios_sched_tcb_t * ptr) { - cc_sched_tcb_t * next_ptr = ptr->ready_link.next; - if (ptr->ready_link.next->task_status == cc_sched_task_status_exit) + helios_sched_tcb_t * next_ptr = ptr->ready_link.next; + if (ptr->ready_link.next->task_status == helios_sched_task_status_exit) { - _cc_sched_node_detach(ptr, false); + _helios_sched_node_detach(ptr, false); -#if CC_OS_DYNAMIC == true - cc_os_free((void *)ptr->stack_ptr); - cc_os_free(ptr); +#if HELIOS_DYNAMIC == true + helios_free((void *)ptr->stack_ptr); + helios_free(ptr); #endif } return next_ptr; } -#if CC_OS_POWER_SAVE_EN -static void __cc_power_save_callback(void) +#if HELIOS_POWER_SAVE_EN +static void __helios_power_save_callback(void) { arch_wfi(); } @@ -53,15 +53,15 @@ static void __cc_power_save_callback(void) /***************************************************** * USER FUNCTION DEFINATION *****************************************************/ -void _cc_os_idle_task_fn(cc_os_args args) +void _helios_idle_task_fn(helios_args args) { - static cc_sched_tcb_t * ptr = CC_OS_NULL_PTR; - cc_sched_ctrl_t * sched_ctrl = (cc_sched_ctrl_t *) args; + static helios_sched_tcb_t * ptr = HELIOS_NULL_PTR; + helios_sched_ctrl_t * sched_ctrl = (helios_sched_ctrl_t *) args; ptr = sched_ctrl->ready_list_head; -#if CC_OS_POWER_SAVE_EN - if (sched_ctrl->cb_hooks_reg.sleep_cb == CC_OS_NULL_PTR) +#if HELIOS_POWER_SAVE_EN + if (sched_ctrl->cb_hooks_reg.sleep_cb == HELIOS_NULL_PTR) { - sched_ctrl->cb_hooks_reg.sleep_cb = __cc_power_save_callback; + sched_ctrl->cb_hooks_reg.sleep_cb = __helios_power_save_callback; } #endif while (true) @@ -69,22 +69,22 @@ void _cc_os_idle_task_fn(cc_os_args args) /* Clean up task if terminated */ ptr = __free_terminated_task(ptr); -#if CC_OS_POWER_SAVE_EN +#if HELIOS_POWER_SAVE_EN /* Power Save code */ - if (sched_ctrl->cb_hooks_reg.pre_sleep_cb != CC_OS_NULL_PTR) + if (sched_ctrl->cb_hooks_reg.pre_sleep_cb != HELIOS_NULL_PTR) { sched_ctrl->cb_hooks_reg.pre_sleep_cb(); } - if (sched_ctrl->cb_hooks_reg.sleep_cb != CC_OS_NULL_PTR) + if (sched_ctrl->cb_hooks_reg.sleep_cb != HELIOS_NULL_PTR) { sched_ctrl->cb_hooks_reg.sleep_cb(); } - if (sched_ctrl->cb_hooks_reg.post_sleep_cb != CC_OS_NULL_PTR) + if (sched_ctrl->cb_hooks_reg.post_sleep_cb != HELIOS_NULL_PTR) { sched_ctrl->cb_hooks_reg.post_sleep_cb(); } #endif /* Yield for next available task */ - cc_os_task_yield(); + helios_task_yield(); } } diff --git a/src/visor/terravisor/services/kernel/helios_tasks.c b/src/visor/terravisor/services/kernel/helios_tasks.c new file mode 100644 index 00000000..cc5adbe2 --- /dev/null +++ b/src/visor/terravisor/services/kernel/helios_tasks.c @@ -0,0 +1,442 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2022, Cyancore Team + * + * File Name : helios_tasks.c + * Description : CC OS Kernel tasks related definations definations + * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] + * Organisation : Cyancore Core-Team + */ + +/***************************************************** + * INCLUDES + *****************************************************/ +#include +#include +#include +#include +#include + +/***************************************************** + * DEFINES + *****************************************************/ +#define HELIOS_PRIORITY_MAX 255 + +/***************************************************** + * INTERNAL EXTERNS FUNCTIONS + *****************************************************/ +extern status_t _helios_sched_insert_after(helios_sched_tcb_t **ptr, helios_sched_tcb_t *new_node, uint8_t link_type); +extern status_t _helios_sched_insert_before(helios_sched_tcb_t **ptr, helios_sched_tcb_t *new_node, uint8_t link_type); +extern void _helios_sched_send_to_wait(helios_sched_ctrl_t *sched_ctrl, helios_sched_tcb_t *ptr, const size_t ticks); +extern void _helios_sched_send_to_pause(helios_sched_ctrl_t * sched_ctrl, helios_sched_tcb_t * ptr); +extern void _helios_sched_send_to_resume(helios_sched_ctrl_t *sched_ctrl, helios_sched_tcb_t *ptr); +extern void _helios_sched_send_back_of_task_prio(helios_sched_tcb_t *node_ptr); +extern void _helios_scheduler_despatch(void); +extern void _helios_pre_sched(helios_args args); +/***************************************************** + * GLOBAL EXTERNS VARIABLES + *****************************************************/ +extern void _helios_idle_task_fn(helios_args args); +extern helios_sched_t g_helios_sched_list[]; +extern helios_sched_ctrl_t g_sched_ctrl; + +/***************************************************** + * GLOBAL DECLARATIONS + *****************************************************/ +#if HELIOS_DYNAMIC == false +extern helios_sched_tcb_t g_helios_tcb_list[]; +#else +extern helios_sched_tcb_t *g_helios_tcb_list; +#endif + +#if HELIOS_DYNAMIC == false +uint8_t _helios_stack[HELIOS_IDLE_TASK_STACK_LEN]; +#else +uint8_t *_helios_stack = HELIOS_NULL_PTR; +#endif +helios_task_t helios_idle_task; +/***************************************************** + * STATIC VARIABLES + *****************************************************/ +static uint16_t __helios_task_id_gen = false; +/***************************************************** + * STATIC FUNCTION DEFINATIONS + *****************************************************/ +static void __helios_init_scheduler(void) +{ + g_sched_ctrl.cb_hooks_reg.pre_sched = &_helios_pre_sched; + return; +} + +static uint16_t __helios_task_id_generate() +{ + __helios_task_id_gen++; + return __helios_task_id_gen; +} + +static helios_sched_tcb_t * __helios_get_tcb_using_task_id(const uintptr_t task_id) +{ + helios_sched_tcb_t * ptr = g_sched_ctrl.ready_list_head; + bool _is_id_found = false; + while (ptr->ready_link.next != g_sched_ctrl.ready_list_head) + { + if (ptr->task_id == task_id) + { + _is_id_found = true; + break; + } + ptr = ptr->ready_link.next; + } + if (_is_id_found == false) + { + ptr = HELIOS_NULL_PTR; + } + return ptr; +} + +static status_t __helios_set_task_flag(helios_sched_tcb_t* helios_task, helios_task_flag_t task_flag, bool en) +{ + HELIOS_ASSERT_IF_FALSE( helios_task != HELIOS_NULL_PTR); + + if (en) + { + helios_task->task_flags |= (uint8_t)task_flag; + } + else + { + helios_task->task_flags &= (uint8_t)~task_flag; + } + return success; +} + +static bool __helios_is_task_flag(const helios_sched_tcb_t *helios_task, helios_task_flag_t task_flag) +{ + if (helios_task != HELIOS_NULL_PTR) + { + return (helios_task->task_flags & task_flag) == false; + } + + return false; +} + +/***************************************************** + * USER FUNCTION DEFINATIONS + *****************************************************/ +status_t helios_add_task( + helios_task_t *helios_task, + const char *name, + task_fn_t task_func, + helios_args args, + uint8_t priority, + size_t stack_len, +#if HELIOS_DYNAMIC + uintptr_t stack_ptr _UNUSED +#else + uintptr_t stack_ptr +#endif /* HELIOS_DYNAMIC */ +) +{ + HELIOS_ASSERT_IF_FALSE(*helios_task == (uintptr_t)HELIOS_NULL_PTR); + HELIOS_ASSERT_IF_FALSE(name != HELIOS_NULL_PTR); +#if HELIOS_DYNAMIC == false + HELIOS_ASSERT_IF_FALSE(stack_ptr != (uintptr_t)HELIOS_NULL_PTR); +#endif + HELIOS_ASSERT_IF_FALSE(task_func != HELIOS_NULL_PTR); + HELIOS_ASSERT_IF_FALSE(stack_len != false); + HELIOS_ASSERT_IF_FALSE(priority >= HELIOS_IDLE_TASK_PRIORITY); + HELIOS_ASSERT_IF_FALSE(priority < HELIOS_PRIORITY_MAX); + + helios_pause_all_task(); + + helios_sched_tcb_t *ptr = HELIOS_NULL_PTR; + +#if HELIOS_DYNAMIC == false + /* Static Task Allocation */ + for (size_t i = false; i < HELIOS_MAX_THREAD; i++) + { + /* Get an available node from global tcb list */ + if (g_helios_tcb_list[i].task_status == helios_sched_task_status_exit) + { + ptr = &(g_helios_tcb_list[i]); + break; + } + } + if (ptr != g_sched_ctrl.ready_list_head) + { + ptr->stack_ptr = stack_ptr; +#else + /* Dynamic Task Declaration */ + ptr = (helios_sched_tcb_t *)helios_malloc(sizeof(helios_sched_tcb_t)); + if (ptr != HELIOS_NULL_PTR) + { + ptr->stack_ptr = (uintptr_t)malloc(stack_len); + if (ptr->stack_ptr == (uintptr_t)HELIOS_NULL_PTR) + { + helios_resume_all_task(); + return error_memory_low; + } +#endif /* HELIOS_DYNAMIC */ + } + else + { + helios_resume_all_task(); + return error_memory_low; + } + /* Fill tcb details */ + ptr->name = name; + ptr->priority = priority; + ptr->task_func = task_func; + ptr->args_ptr = (uintptr_t)args; +#if HELIOS_ANTI_DEADLOCK + ptr->task_wd_ticks = SIZE_MAX; +#endif /* HELIOS_ANTI_DEADLOCK */ + if (g_sched_ctrl.ready_list_head == HELIOS_NULL_PTR) + { + ptr->ready_link.next = ptr->ready_link.prev = g_sched_ctrl.ready_list_head = ptr; + } + /* Insert Tasks in assending order of its priority */ + _helios_sched_send_back_of_task_prio(ptr); + ptr->task_status = helios_sched_task_status_ready; + ptr->task_id = __helios_task_id_generate(); + *helios_task = ptr->task_id; + helios_resume_all_task(); + return success; +} + +status_t helios_del_task(helios_task_t helios_task) +{ + helios_sched_tcb_t * ptr = __helios_get_tcb_using_task_id(helios_task); + + if (ptr == HELIOS_NULL_PTR) + { + ptr = g_sched_ctrl.curr_task; + } + HELIOS_ASSERT_IF_FALSE(ptr->task_func != &_helios_idle_task_fn); + /* Code to handle first node */ + if (ptr == g_sched_ctrl.ready_list_head) + { + /* IDLE Task can not be deleted */ + return error_os_invalid_op; + } + ptr->task_status = helios_sched_task_status_exit; + + if (ptr == g_sched_ctrl.curr_task) + { + helios_task_yield(); /* Yeild */ + } + + return success; +} + +status_t helios_pause_task(helios_task_t helios_task) +{ + helios_sched_tcb_t *ptr = __helios_get_tcb_using_task_id(helios_task); + if (ptr == HELIOS_NULL_PTR) + { + ptr = g_sched_ctrl.curr_task; + } + + _helios_sched_send_to_pause(&g_sched_ctrl, ptr); + + return success; +} + +status_t helios_pause_all_task(void) +{ + helios_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; + if(ptr != HELIOS_NULL_PTR) + { + while (true) + { + if (ptr == g_sched_ctrl.curr_task) + { + /* Do not pause the current task */ + continue; + } + + _helios_sched_send_to_pause(&g_sched_ctrl, ptr); + ptr = ptr->ready_link.next; + + if(ptr == g_sched_ctrl.ready_list_head) + { + break; + } + } + } + + return success; +} + +status_t helios_resume_all_task(void) +{ + helios_sched_tcb_t *ptr = g_sched_ctrl.ready_list_head; + if (ptr != HELIOS_NULL_PTR) + { + while (true) + { + ptr = ptr->ready_link.next; + _helios_sched_send_to_resume(&g_sched_ctrl, ptr); + if (ptr == g_sched_ctrl.ready_list_head) + { + break; + } + } + } + else + { + return error_os_invalid_op; + } + + return success; +} + +status_t helios_resume_task(helios_task_t helios_task) +{ + helios_sched_tcb_t *ptr = __helios_get_tcb_using_task_id(helios_task); + HELIOS_ASSERT_IF_FALSE(ptr != HELIOS_NULL_PTR); + + if (ptr->task_status != helios_sched_task_status_pause) + { + _helios_sched_send_to_resume(&g_sched_ctrl, ptr); + } + else + { + return error_os_invalid_op; + } + return success; +} + +status_t helios_set_sched_algo(helios_sched_algo_t sched_algo) +{ + HELIOS_ASSERT_IF_FALSE(sched_algo != helios_sched_algo_max); + + g_sched_ctrl.selected_sched = &(g_helios_sched_list[sched_algo]); + + return success; +} + +status_t helios_task_anti_deadlock_enable_and_feed(size_t task_wd_ticks _UNUSED) +{ +#if HELIOS_ANTI_DEADLOCK + HELIOS_ASSERT_IF_FALSE((task_wd_ticks > false) && (task_wd_ticks < SIZE_MAX)); + + helios_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + if (__helios_is_task_flag(ptr, helios_task_flag_set_anti_deadlock)) + { + __helios_set_task_flag(ptr, helios_task_flag_set_anti_deadlock, true); + } + + ptr->task_wd_ticks = task_wd_ticks; + return success; +#else + helios_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + if (__helios_is_task_flag(ptr, helios_task_flag_set_anti_deadlock)) + { + __helios_set_task_flag(ptr, helios_task_flag_set_anti_deadlock, false); + } + return error_func_inval; +#endif /* HELIOS_ANTI_DEADLOCK */ +} + +status_t helios_task_anti_deadlock_disable(void) +{ + helios_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + + if (__helios_is_task_flag(ptr, helios_task_flag_set_anti_deadlock)) + { + __helios_set_task_flag(ptr, helios_task_flag_set_anti_deadlock, false); + } + +#if HELIOS_ANTI_DEADLOCK + ptr->task_wd_ticks = SIZE_MAX; + return success; +#else + return error_func_inval; +#endif /* HELIOS_ANTI_DEADLOCK */ +} +status_t helios_set_callback(const helios_sched_cb_t cb_type, const helios_cb_hook_t cb_func _UNUSED) +{ + status_t ret = success; + switch (cb_type) + { + case helios_sched_cb_power_post_sleep: +#if HELIOS_POWER_SAVE_EN + g_sched_ctrl.cb_hooks_reg.post_sleep_cb = cb_func; + break; +#endif + case helios_sched_cb_power_pre_sleep: +#if HELIOS_POWER_SAVE_EN + g_sched_ctrl.cb_hooks_reg.pre_sleep_cb = cb_func; + break; +#endif + case helios_sched_cb_power_sleep: +#if HELIOS_POWER_SAVE_EN + g_sched_ctrl.cb_hooks_reg.power_sleep = cb_func; + break; +#endif + case helios_sched_cb_deadlock_notify: +#if HELIOS_ANTI_DEADLOCK + g_sched_ctrl.cb_hooks_reg.deadlock_notify = cb_func; + break; +#endif + case helios_sched_cb_max: + ret = error_func_inval; + break; + } + return ret; +} + +const char *helios_get_curr_task_name(void) +{ + return g_sched_ctrl.curr_task->name; +} + +const char *helios_get_task_name(helios_task_t helios_task) +{ + const helios_sched_tcb_t *ptr = __helios_get_tcb_using_task_id(helios_task); + if(ptr != HELIOS_NULL_PTR) + { + return ptr->name; + } + return HELIOS_NULL_PTR; +} + +void helios_task_wait(const size_t ticks) +{ + helios_sched_tcb_t *ptr = g_sched_ctrl.curr_task; + + if (ticks > false) + { + _helios_sched_send_to_wait(&g_sched_ctrl, ptr, ticks); + } + + helios_task_yield(); +} + +void helios_task_yield() +{ + _helios_scheduler_despatch(); + return; +} + +void helios_run(void) +{ + /* OS Init code */ + /* Initialise IDLE Task */ + helios_add_task(&helios_idle_task, + HELIOS_IDLE_TASK_NAME, + &_helios_idle_task_fn, + &g_sched_ctrl, + HELIOS_IDLE_TASK_PRIORITY, + HELIOS_IDLE_TASK_STACK_LEN, + (uintptr_t)_helios_stack); + + /* Initialise scheduler */ + __helios_init_scheduler(); + helios_task_yield(); /* Yeild */ + while (true) + { + /* Code shall not reach here */ + arch_wfi(); + } +}