For Cortex-M3,Cortex-M0, Multitask scheduler library. Arduino due compatible
Dependents: scheduler-demo-cq-lpc11u35 scheduler-demo scheduler-demo-cq-lpc11u35 mbed-scli-test
Scheduler.h@0:c68459544a17, 2013-08-25 (annotated)
- Committer:
- dinau
- Date:
- Sun Aug 25 16:48:21 2013 +0900
- Revision:
- 0:c68459544a17
- Child:
- 1:8967b575bb46
for mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dinau | 0:c68459544a17 | 1 | /* |
dinau | 0:c68459544a17 | 2 | * Copyright (C) 2012 audin |
dinau | 0:c68459544a17 | 3 | * This program is licensed under the Apache License, Version 2.0. |
dinau | 0:c68459544a17 | 4 | * Modified 2012/11: v02: |
dinau | 0:c68459544a17 | 5 | * Added external definition of stack size and task number. |
dinau | 0:c68459544a17 | 6 | * Modified 2012/10: v01: |
dinau | 0:c68459544a17 | 7 | * For working on Cortex-M0 and M3. |
dinau | 0:c68459544a17 | 8 | * Defined static tcb option for the cpu that has quite a less SRAM < 8kbyte. |
dinau | 0:c68459544a17 | 9 | * |
dinau | 0:c68459544a17 | 10 | * Original file is arduino-1.5\hardware\arduino\sam\libraries\Scheduler |
dinau | 0:c68459544a17 | 11 | */ |
dinau | 0:c68459544a17 | 12 | |
dinau | 0:c68459544a17 | 13 | /* |
dinau | 0:c68459544a17 | 14 | * Copyright (C) 2012 The Android Open Source Project |
dinau | 0:c68459544a17 | 15 | * |
dinau | 0:c68459544a17 | 16 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dinau | 0:c68459544a17 | 17 | * you may not use this file except in compliance with the License. |
dinau | 0:c68459544a17 | 18 | * You may obtain a copy of the License at |
dinau | 0:c68459544a17 | 19 | * |
dinau | 0:c68459544a17 | 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
dinau | 0:c68459544a17 | 21 | * |
dinau | 0:c68459544a17 | 22 | * Unless required by applicable law or agreed to in writing, software |
dinau | 0:c68459544a17 | 23 | * distributed under the License is distributed on an "AS IS" BASIS, |
dinau | 0:c68459544a17 | 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dinau | 0:c68459544a17 | 25 | * See the License for the specific language governing permissions and |
dinau | 0:c68459544a17 | 26 | * limitations under the License. |
dinau | 0:c68459544a17 | 27 | */ |
dinau | 0:c68459544a17 | 28 | |
dinau | 0:c68459544a17 | 29 | #ifndef _SCHEDULDER_H_ |
dinau | 0:c68459544a17 | 30 | #define _SCHEDULDER_H_ |
dinau | 0:c68459544a17 | 31 | |
dinau | 0:c68459544a17 | 32 | /* |
dinau | 0:c68459544a17 | 33 | * If you explicitly specify stack size, activate below, |
dinau | 0:c68459544a17 | 34 | * or used "Default settings" |
dinau | 0:c68459544a17 | 35 | */ |
dinau | 0:c68459544a17 | 36 | //#define SCHEDULER_TASK_NUM_MAX 4 |
dinau | 0:c68459544a17 | 37 | //#define SCHEDULER_TASK_STACK_SIZE_EACH 200 |
dinau | 0:c68459544a17 | 38 | |
dinau | 0:c68459544a17 | 39 | /* |
dinau | 0:c68459544a17 | 40 | * Otherwise you can add compile option CFLAGS like this, |
dinau | 0:c68459544a17 | 41 | -DSCHEDULER_TASK_NUM_MAX=4 |
dinau | 0:c68459544a17 | 42 | -DSCHEDULER_TASK_STACK_SIZE_EACH=200 |
dinau | 0:c68459544a17 | 43 | */ |
dinau | 0:c68459544a17 | 44 | |
dinau | 0:c68459544a17 | 45 | /* Default settings */ |
dinau | 0:c68459544a17 | 46 | /******************************************************************************************/ |
dinau | 0:c68459544a17 | 47 | #ifndef SCHEDULER_TASK_NUM_MAX |
dinau | 0:c68459544a17 | 48 | #define COOP_TASK_NUM_MAX 4 /* Define max task number( include main loop ) */ |
dinau | 0:c68459544a17 | 49 | #else |
dinau | 0:c68459544a17 | 50 | #define COOP_TASK_NUM_MAX (SCHEDULER_TASK_NUM_MAX) |
dinau | 0:c68459544a17 | 51 | #endif |
dinau | 0:c68459544a17 | 52 | |
dinau | 0:c68459544a17 | 53 | #ifndef SCHEDULER_TASK_STACK_SIZE_EACH |
dinau | 0:c68459544a17 | 54 | #define MIN_STACK_SIZE (200) /* Minimum stack size per task, exclude main loop */ |
dinau | 0:c68459544a17 | 55 | #else |
dinau | 0:c68459544a17 | 56 | #define MIN_STACK_SIZE (SCHEDULER_TASK_STACK_SIZE_EACH) |
dinau | 0:c68459544a17 | 57 | #endif |
dinau | 0:c68459544a17 | 58 | /* Thanks Ms.HI */ |
dinau | 0:c68459544a17 | 59 | /******************************************************************************************/ |
dinau | 0:c68459544a17 | 60 | |
dinau | 0:c68459544a17 | 61 | #include <stdint.h> |
dinau | 0:c68459544a17 | 62 | #ifdef __cplusplus |
dinau | 0:c68459544a17 | 63 | extern "C" { |
dinau | 0:c68459544a17 | 64 | #endif |
dinau | 0:c68459544a17 | 65 | typedef void (*SchedulerTask)(void); |
dinau | 0:c68459544a17 | 66 | typedef void (*SchedulerParametricTask)(void *); |
dinau | 0:c68459544a17 | 67 | |
dinau | 0:c68459544a17 | 68 | void scheduler_init( void ); |
dinau | 0:c68459544a17 | 69 | void scheduler_startLoop( SchedulerTask task ); |
dinau | 0:c68459544a17 | 70 | void scheduler_start( SchedulerTask task ); |
dinau | 0:c68459544a17 | 71 | |
dinau | 0:c68459544a17 | 72 | void wait(uint32_t ms); |
dinau | 0:c68459544a17 | 73 | void yield(); |
dinau | 0:c68459544a17 | 74 | #ifdef __cplusplus |
dinau | 0:c68459544a17 | 75 | } |
dinau | 0:c68459544a17 | 76 | #endif |
dinau | 0:c68459544a17 | 77 | |
dinau | 0:c68459544a17 | 78 | |
dinau | 0:c68459544a17 | 79 | #if __cplusplus |
dinau | 0:c68459544a17 | 80 | class SchedulerClass { |
dinau | 0:c68459544a17 | 81 | public: |
dinau | 0:c68459544a17 | 82 | SchedulerClass(); |
dinau | 0:c68459544a17 | 83 | static void startLoop(SchedulerTask task, uint32_t stackSize = MIN_STACK_SIZE); |
dinau | 0:c68459544a17 | 84 | static void start(SchedulerTask task, uint32_t stackSize = MIN_STACK_SIZE); |
dinau | 0:c68459544a17 | 85 | static void start(SchedulerParametricTask task, void *data, uint32_t stackSize = MIN_STACK_SIZE); |
dinau | 0:c68459544a17 | 86 | |
dinau | 0:c68459544a17 | 87 | static void wait(uint32_t ms) { ::wait(ms); }; |
dinau | 0:c68459544a17 | 88 | static void yield() { ::yield(); }; |
dinau | 0:c68459544a17 | 89 | }; |
dinau | 0:c68459544a17 | 90 | |
dinau | 0:c68459544a17 | 91 | extern SchedulerClass Scheduler; |
dinau | 0:c68459544a17 | 92 | |
dinau | 0:c68459544a17 | 93 | #endif |
dinau | 0:c68459544a17 | 94 | |
dinau | 0:c68459544a17 | 95 | #endif /* _SCHEDULDER_H_ */ |
dinau | 0:c68459544a17 | 96 |