From: AceVest Date: Mon, 18 Jun 2018 08:08:43 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/FAQ?a=commitdiff_plain;h=0540ae27a93ef7b88b41739b53c5d527296747e0;p=acecode.git ... --- diff --git a/arduino/hardware/ace/avr/cores/avr/AceAvr.h b/arduino/hardware/ace/avr/cores/avr/AceAvr.h index 9324add..5bae26b 100644 --- a/arduino/hardware/ace/avr/cores/avr/AceAvr.h +++ b/arduino/hardware/ace/avr/cores/avr/AceAvr.h @@ -13,6 +13,9 @@ #include #include +#include +#include + #define LOW 0 #define HIGH 1 diff --git a/arduino/hardware/ace/avr/cores/avr/app.cpp b/arduino/hardware/ace/avr/cores/avr/app.cpp new file mode 100644 index 0000000..1806ef3 --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/app.cpp @@ -0,0 +1,49 @@ +/* + * ------------------------------------------------------------------------ + * File Name: app.cpp + * Author: Zhao Yanbai + * 2018-06-18 16:01:26 Monday CST + * Description: none + * ------------------------------------------------------------------------ + */ +#include + +uint8_t debug_task_stack[TASK_STACK_SIZE]; +void debug_task() { + while(1) { + Serial.println("debug task"); + task_delay(1000); + } +} + +uint8_t led_task_stack[TASK_STACK_SIZE]; +void led_task() { + uint8_t pin = 13; + set_digital_pin_mode(pin, OUTPUT); + while(1) { + digital_write(pin, HIGH); + task_delay(10); + digital_write(pin, LOW); + task_delay(10); + } +} + +uint8_t user_task1_stack[TASK_STACK_SIZE]; +void user_task1() { + while(1) { + Serial.println("user task 1"); + task_delay(100); + } +} + + + + +void app_main() { + Serial.begin(9600); + create_task(led_task, led_task_stack, 0); + create_task(user_task1, user_task1_stack, 1); + create_task(debug_task, debug_task_stack, 3); +} + + diff --git a/arduino/hardware/ace/avr/cores/avr/kernel.cpp b/arduino/hardware/ace/avr/cores/avr/kernel.cpp index df4f042..64a571f 100644 --- a/arduino/hardware/ace/avr/cores/avr/kernel.cpp +++ b/arduino/hardware/ace/avr/cores/avr/kernel.cpp @@ -8,7 +8,6 @@ */ #include #include -#include void delay(unsigned long ms); @@ -25,46 +24,15 @@ int8_t kernel_initialized = 0; void task_scheduler(); -uint8_t debug_task_stack[TASK_STACK_SIZE]; -void debug_task() { - Serial.begin(9600); - - while(1) { - Serial.println("fuck"); - task_delay(100); - } - - while(1) task_delay(1000); - uint8_t pin = 12; - set_digital_pin_mode(pin, OUTPUT); - while(1) { - digital_write(pin, HIGH); - task_delay(20); - digital_write(pin, LOW); - task_delay(20); - } -} - -uint8_t led_task_stack[TASK_STACK_SIZE]; -void led_task() { - uint8_t pin = 13; - set_digital_pin_mode(pin, OUTPUT); - while(1) { - digital_write(pin, HIGH); - task_delay(10); - digital_write(pin, LOW); - task_delay(10); - } -} - - // idle_task 在没有进程READY的情况下都会调度运行 // 所以task_delay不能在此进程生效 uint8_t idle_task_stack[TASK_STACK_SIZE]; uint32_t idle_cnt = 0; +void app_main(); void idle_task() { sei(); kernel_initialized = 1; + app_main(); uint8_t pin = 12; set_digital_pin_mode(pin, OUTPUT); uint8_t state = LOW; @@ -296,8 +264,6 @@ void init_tasks() { t->delay_ticks = 0; } - create_task(led_task, led_task_stack, 0); - create_task(debug_task, debug_task_stack, 1); create_task(idle_task, idle_task_stack, idle_task_priority); current_task = IDLE_TASK; IDLE_TASK->stack = idle_task_stack+TASK_STACK_SIZE - 3; diff --git a/arduino/hardware/ace/avr/cores/avr/kernel.h b/arduino/hardware/ace/avr/cores/avr/kernel.h index 6cf0863..517f19e 100644 --- a/arduino/hardware/ace/avr/cores/avr/kernel.h +++ b/arduino/hardware/ace/avr/cores/avr/kernel.h @@ -32,7 +32,7 @@ struct task { }; void init_tasks(); -void create_task(void (*handler)(), char *stack, uint8_t priority); +void create_task(void (*handler)(), uint8_t *stack, uint8_t priority); void task_switch(struct task *prev, struct task *next); void task_delay(uint16_t ticks); //void yield(void);