![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Scheduller Demo
Fork of scheduler-demo-cq-lpc11u35 by
led_tsk.cpp@3:d098b01b9dcb, 2014-05-18 (annotated)
- Committer:
- jr1wfh
- Date:
- Sun May 18 03:53:18 2014 +0000
- Revision:
- 3:d098b01b9dcb
- Parent:
- 1:48a906a94c32
Rev.0
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 */ |
jr1wfh | 3:d098b01b9dcb | 20 | DigitalIn s2(P0_2); |
mimi3 | 1:48a906a94c32 | 21 | DigitalOut led1(P0_20); |
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 | 0:79e298c7d4b9 | 25 | |
mimi3 | 0:79e298c7d4b9 | 26 | /******************* |
mimi3 | 0:79e298c7d4b9 | 27 | |
mimi3 | 1:48a906a94c32 | 28 | * Fake PWM class |
mimi3 | 0:79e298c7d4b9 | 29 | |
mimi3 | 0:79e298c7d4b9 | 30 | *******************/ |
mimi3 | 1:48a906a94c32 | 31 | static void pwm_elm( int ms, int max_ms, DigitalOut *led ) |
mimi3 | 0:79e298c7d4b9 | 32 | { |
mimi3 | 1:48a906a94c32 | 33 | *led=0; // negative on |
mimi3 | 0:79e298c7d4b9 | 34 | taskWait( ms ); |
mimi3 | 1:48a906a94c32 | 35 | *led=1; |
mimi3 | 1:48a906a94c32 | 36 | taskWait( max_ms - ms); |
mimi3 | 0:79e298c7d4b9 | 37 | } |
mimi3 | 0:79e298c7d4b9 | 38 | |
mimi3 | 1:48a906a94c32 | 39 | class pwm_fake_t |
mimi3 | 0:79e298c7d4b9 | 40 | { |
mimi3 | 1:48a906a94c32 | 41 | int max_val, val, MIN_VAL, dir, speed; |
mimi3 | 1:48a906a94c32 | 42 | DigitalOut *led; |
mimi3 | 1:48a906a94c32 | 43 | public: |
mimi3 | 1:48a906a94c32 | 44 | pwm_fake_t(DigitalOut *_led, int _speed) { |
mimi3 | 1:48a906a94c32 | 45 | max_val = speed = _speed; |
mimi3 | 1:48a906a94c32 | 46 | val = MIN_VAL = 0; |
mimi3 | 1:48a906a94c32 | 47 | dir =1; |
mimi3 | 1:48a906a94c32 | 48 | led = _led; |
mimi3 | 1:48a906a94c32 | 49 | } |
mimi3 | 1:48a906a94c32 | 50 | void run() { |
mimi3 | 0:79e298c7d4b9 | 51 | if( ( val >= max_val) || ( val <= MIN_VAL) ) { |
mimi3 | 1:48a906a94c32 | 52 | max_val = speed;//sio_get_led_blink_speed() + 3 ; // change period |
mimi3 | 0:79e298c7d4b9 | 53 | max_val <<= 1; // adjust time |
mimi3 | 0:79e298c7d4b9 | 54 | if( val <= MIN_VAL ) { |
mimi3 | 0:79e298c7d4b9 | 55 | dir = 1; |
mimi3 | 0:79e298c7d4b9 | 56 | taskWait( 1000 ); // wait 1src if led off |
mimi3 | 0:79e298c7d4b9 | 57 | } else { |
mimi3 | 0:79e298c7d4b9 | 58 | dir = -1; |
mimi3 | 0:79e298c7d4b9 | 59 | val = max_val; |
mimi3 | 0:79e298c7d4b9 | 60 | } |
mimi3 | 0:79e298c7d4b9 | 61 | } |
mimi3 | 0:79e298c7d4b9 | 62 | val += dir; |
mimi3 | 1:48a906a94c32 | 63 | pwm_elm( val, max_val, led ); |
mimi3 | 1:48a906a94c32 | 64 | } |
mimi3 | 1:48a906a94c32 | 65 | }; |
mimi3 | 1:48a906a94c32 | 66 | |
mimi3 | 1:48a906a94c32 | 67 | /******************* |
mimi3 | 1:48a906a94c32 | 68 | |
mimi3 | 1:48a906a94c32 | 69 | * LED1 task |
mimi3 | 1:48a906a94c32 | 70 | |
mimi3 | 1:48a906a94c32 | 71 | *******************/ |
mimi3 | 1:48a906a94c32 | 72 | void led1_task( void ) |
mimi3 | 1:48a906a94c32 | 73 | { |
mimi3 | 1:48a906a94c32 | 74 | led1_off(); |
jr1wfh | 3:d098b01b9dcb | 75 | taskWait( 1000 ); |
mimi3 | 1:48a906a94c32 | 76 | pwm_fake_t pwm_led( &led1, 10+3); |
mimi3 | 1:48a906a94c32 | 77 | while( 1 ) { |
mimi3 | 1:48a906a94c32 | 78 | pwm_led.run(); |
mimi3 | 0:79e298c7d4b9 | 79 | } |
mimi3 | 0:79e298c7d4b9 | 80 | } |
jr1wfh | 3:d098b01b9dcb | 81 |