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