![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
For CQ LPC1U35 board. Multitask scheduler demo project.,arduino,due,compatible
Fork of scheduler-demo by
led_tsk.cpp@1:48a906a94c32, 2014-03-07 (annotated)
- Committer:
- mimi3
- Date:
- Fri Mar 07 14:37:12 2014 +0000
- Revision:
- 1:48a906a94c32
- Parent:
- 0:79e298c7d4b9
for cq lpc11u35
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mimi3 | 0:79e298c7d4b9 | 1 | /* |
mimi3 | 0:79e298c7d4b9 | 2 | # |
mimi3 | 1:48a906a94c32 | 3 | # Copyright (C) 2010-2014, audin |
mimi3 | 1:48a906a94c32 | 4 | # 2014/02: Modify for mbed for CQ LPC11U35 |
mimi3 | 0:79e298c7d4b9 | 5 | # 2013/08: Modify for mbed for LPC1114FN28 |
mimi3 | 0:79e298c7d4b9 | 6 | # 2013/07: Modify for LPCOpen Platform. |
mimi3 | 0:79e298c7d4b9 | 7 | # 2011/04, 2012/11 |
mimi3 | 0:79e298c7d4b9 | 8 | # 2010/11 |
mimi3 | 0:79e298c7d4b9 | 9 | # http://avr.paslog.jp |
mimi3 | 0:79e298c7d4b9 | 10 | # This file is licensed under the MIT License. |
mimi3 | 0:79e298c7d4b9 | 11 | # |
mimi3 | 0:79e298c7d4b9 | 12 | */ |
mimi3 | 0:79e298c7d4b9 | 13 | |
mimi3 | 0:79e298c7d4b9 | 14 | #include "mbed.h" |
mimi3 | 0:79e298c7d4b9 | 15 | #include "led_tsk.h" |
mimi3 | 0:79e298c7d4b9 | 16 | #include "Scheduler.h" |
mimi3 | 0:79e298c7d4b9 | 17 | |
mimi3 | 0:79e298c7d4b9 | 18 | |
mimi3 | 1:48a906a94c32 | 19 | /* for CQ ,lpc11u35 */ |
mimi3 | 1:48a906a94c32 | 20 | DigitalOut led1(P0_20); |
mimi3 | 1:48a906a94c32 | 21 | DigitalOut led2(P0_21); |
mimi3 | 1:48a906a94c32 | 22 | |
mimi3 | 0:79e298c7d4b9 | 23 | #define led1_on() led1=0 /* Negative on */ |
mimi3 | 0:79e298c7d4b9 | 24 | #define led1_off() led1=1 |
mimi3 | 1:48a906a94c32 | 25 | #define led2_on() led2=0 /* Negative on */ |
mimi3 | 1:48a906a94c32 | 26 | #define led2_off() led2=1 |
mimi3 | 0:79e298c7d4b9 | 27 | |
mimi3 | 0:79e298c7d4b9 | 28 | /******************* |
mimi3 | 0:79e298c7d4b9 | 29 | |
mimi3 | 1:48a906a94c32 | 30 | * Fake PWM class |
mimi3 | 0:79e298c7d4b9 | 31 | |
mimi3 | 0:79e298c7d4b9 | 32 | *******************/ |
mimi3 | 1:48a906a94c32 | 33 | static void pwm_elm( int ms, int max_ms, DigitalOut *led ) |
mimi3 | 0:79e298c7d4b9 | 34 | { |
mimi3 | 1:48a906a94c32 | 35 | *led=0; // negative on |
mimi3 | 0:79e298c7d4b9 | 36 | taskWait( ms ); |
mimi3 | 1:48a906a94c32 | 37 | *led=1; |
mimi3 | 1:48a906a94c32 | 38 | taskWait( max_ms - ms); |
mimi3 | 0:79e298c7d4b9 | 39 | } |
mimi3 | 0:79e298c7d4b9 | 40 | |
mimi3 | 1:48a906a94c32 | 41 | class pwm_fake_t |
mimi3 | 0:79e298c7d4b9 | 42 | { |
mimi3 | 1:48a906a94c32 | 43 | int max_val, val, MIN_VAL, dir, speed; |
mimi3 | 1:48a906a94c32 | 44 | DigitalOut *led; |
mimi3 | 1:48a906a94c32 | 45 | public: |
mimi3 | 1:48a906a94c32 | 46 | pwm_fake_t(DigitalOut *_led, int _speed) { |
mimi3 | 1:48a906a94c32 | 47 | max_val = speed = _speed; |
mimi3 | 1:48a906a94c32 | 48 | val = MIN_VAL = 0; |
mimi3 | 1:48a906a94c32 | 49 | dir =1; |
mimi3 | 1:48a906a94c32 | 50 | led = _led; |
mimi3 | 1:48a906a94c32 | 51 | } |
mimi3 | 1:48a906a94c32 | 52 | void run() { |
mimi3 | 0:79e298c7d4b9 | 53 | if( ( val >= max_val) || ( val <= MIN_VAL) ) { |
mimi3 | 1:48a906a94c32 | 54 | max_val = speed;//sio_get_led_blink_speed() + 3 ; // change period |
mimi3 | 0:79e298c7d4b9 | 55 | max_val <<= 1; // adjust time |
mimi3 | 0:79e298c7d4b9 | 56 | if( val <= MIN_VAL ) { |
mimi3 | 0:79e298c7d4b9 | 57 | dir = 1; |
mimi3 | 0:79e298c7d4b9 | 58 | taskWait( 1000 ); // wait 1src if led off |
mimi3 | 0:79e298c7d4b9 | 59 | } else { |
mimi3 | 0:79e298c7d4b9 | 60 | dir = -1; |
mimi3 | 0:79e298c7d4b9 | 61 | val = max_val; |
mimi3 | 0:79e298c7d4b9 | 62 | } |
mimi3 | 0:79e298c7d4b9 | 63 | } |
mimi3 | 0:79e298c7d4b9 | 64 | val += dir; |
mimi3 | 1:48a906a94c32 | 65 | pwm_elm( val, max_val, led ); |
mimi3 | 1:48a906a94c32 | 66 | } |
mimi3 | 1:48a906a94c32 | 67 | }; |
mimi3 | 1:48a906a94c32 | 68 | |
mimi3 | 1:48a906a94c32 | 69 | /******************* |
mimi3 | 1:48a906a94c32 | 70 | |
mimi3 | 1:48a906a94c32 | 71 | * LED1 task |
mimi3 | 1:48a906a94c32 | 72 | |
mimi3 | 1:48a906a94c32 | 73 | *******************/ |
mimi3 | 1:48a906a94c32 | 74 | void led1_task( void ) |
mimi3 | 1:48a906a94c32 | 75 | { |
mimi3 | 1:48a906a94c32 | 76 | led1_off(); |
mimi3 | 1:48a906a94c32 | 77 | pwm_fake_t pwm_led( &led1, 10+3); |
mimi3 | 1:48a906a94c32 | 78 | while( 1 ) { |
mimi3 | 1:48a906a94c32 | 79 | pwm_led.run(); |
mimi3 | 0:79e298c7d4b9 | 80 | } |
mimi3 | 0:79e298c7d4b9 | 81 | } |
mimi3 | 0:79e298c7d4b9 | 82 | |
mimi3 | 0:79e298c7d4b9 | 83 | /******************* |
mimi3 | 0:79e298c7d4b9 | 84 | |
mimi3 | 1:48a906a94c32 | 85 | * LED2 task |
mimi3 | 0:79e298c7d4b9 | 86 | |
mimi3 | 0:79e298c7d4b9 | 87 | *******************/ |
mimi3 | 0:79e298c7d4b9 | 88 | void led2_task( void ) |
mimi3 | 0:79e298c7d4b9 | 89 | { |
mimi3 | 1:48a906a94c32 | 90 | led2_off(); |
mimi3 | 1:48a906a94c32 | 91 | taskWait( 666 ); |
mimi3 | 1:48a906a94c32 | 92 | pwm_fake_t pwm_led( &led2, 6+3); |
mimi3 | 0:79e298c7d4b9 | 93 | while( 1 ) { |
mimi3 | 1:48a906a94c32 | 94 | pwm_led.run(); |
mimi3 | 0:79e298c7d4b9 | 95 | } |
mimi3 | 0:79e298c7d4b9 | 96 | } |
mimi3 | 0:79e298c7d4b9 | 97 |