Devchannel Team
/
TestsRTOS
Learn how to use embedded RTOS (Beta version RTOS)
main.cpp@0:5bd42710f2e7, 2015-09-03 (annotated)
- Committer:
- leonardoaraujosantos
- Date:
- Thu Sep 03 00:06:32 2015 +0000
- Revision:
- 0:5bd42710f2e7
- Child:
- 1:4d067c712d03
Starting simple code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leonardoaraujosantos | 0:5bd42710f2e7 | 1 | #include "mbed.h" |
leonardoaraujosantos | 0:5bd42710f2e7 | 2 | #include "rtos.h" |
leonardoaraujosantos | 0:5bd42710f2e7 | 3 | |
leonardoaraujosantos | 0:5bd42710f2e7 | 4 | //------------------------------------ |
leonardoaraujosantos | 0:5bd42710f2e7 | 5 | // Serial configuration (Put on hyperterminal or Putty) |
leonardoaraujosantos | 0:5bd42710f2e7 | 6 | // 115200 bauds, 8-bit data, no parity |
leonardoaraujosantos | 0:5bd42710f2e7 | 7 | //------------------------------------ |
leonardoaraujosantos | 0:5bd42710f2e7 | 8 | |
leonardoaraujosantos | 0:5bd42710f2e7 | 9 | Serial serialIO(SERIAL_TX, SERIAL_RX); |
leonardoaraujosantos | 0:5bd42710f2e7 | 10 | |
leonardoaraujosantos | 0:5bd42710f2e7 | 11 | DigitalOut led1(LED1); |
leonardoaraujosantos | 0:5bd42710f2e7 | 12 | DigitalOut led2(LED2); |
leonardoaraujosantos | 0:5bd42710f2e7 | 13 | |
leonardoaraujosantos | 0:5bd42710f2e7 | 14 | void led2_thread(void const *args) { |
leonardoaraujosantos | 0:5bd42710f2e7 | 15 | while (true) { |
leonardoaraujosantos | 0:5bd42710f2e7 | 16 | led2 = !led2; |
leonardoaraujosantos | 0:5bd42710f2e7 | 17 | Thread::wait(800); |
leonardoaraujosantos | 0:5bd42710f2e7 | 18 | } |
leonardoaraujosantos | 0:5bd42710f2e7 | 19 | } |
leonardoaraujosantos | 0:5bd42710f2e7 | 20 | |
leonardoaraujosantos | 0:5bd42710f2e7 | 21 | int main() |
leonardoaraujosantos | 0:5bd42710f2e7 | 22 | { |
leonardoaraujosantos | 0:5bd42710f2e7 | 23 | int i = 1; |
leonardoaraujosantos | 0:5bd42710f2e7 | 24 | // Configure the serial speed. |
leonardoaraujosantos | 0:5bd42710f2e7 | 25 | serialIO.baud(115200); |
leonardoaraujosantos | 0:5bd42710f2e7 | 26 | serialIO.printf("Learning Microcontrollers with mbed !\n"); |
leonardoaraujosantos | 0:5bd42710f2e7 | 27 | |
leonardoaraujosantos | 0:5bd42710f2e7 | 28 | // Start a thread to togle the led |
leonardoaraujosantos | 0:5bd42710f2e7 | 29 | Thread thread(led2_thread); |
leonardoaraujosantos | 0:5bd42710f2e7 | 30 | // Lock forever here... |
leonardoaraujosantos | 0:5bd42710f2e7 | 31 | while(1) { |
leonardoaraujosantos | 0:5bd42710f2e7 | 32 | wait(1); |
leonardoaraujosantos | 0:5bd42710f2e7 | 33 | serialIO.printf("This program runs since %d seconds.\n", i++); |
leonardoaraujosantos | 0:5bd42710f2e7 | 34 | led1 = !led1; |
leonardoaraujosantos | 0:5bd42710f2e7 | 35 | } |
leonardoaraujosantos | 0:5bd42710f2e7 | 36 | } |