Point Labs / Mbed OS HelloANNA
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 20 Point Labs, LLC.
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "ANNA-B112.h"
00008 #include "platform/mbed_thread.h"
00009 
00010 // Blinking rate in milliseconds
00011 #define BLINKING_RATE_MS    500
00012 
00013 
00014 DigitalOut led(LED_B);
00015 UARTSerial radio(TX_PIN, RX_PIN, 115200);
00016 
00017 static Thread echoThread( osPriorityNormal, OS_STACK_SIZE / 2, NULL, "echo_thread" );
00018 void echoTask()
00019 {
00020     while(true){
00021         uint8_t inbuf[64];
00022         int size;
00023         if(radio.readable()){
00024             size = radio.read(inbuf,sizeof(inbuf));  
00025             radio.write(inbuf,size);
00026         }
00027     }
00028 }
00029 
00030 static Thread blinkThread( osPriorityNormal, OS_STACK_SIZE / 2, NULL, "pc_thread" );
00031 void blinkTask()
00032 {
00033     while (true) {
00034         led = !led;
00035         thread_sleep_for(BLINKING_RATE_MS);
00036     }  
00037 }
00038 
00039 int main()
00040 {
00041     // Initialise the digital pin state
00042     led = 1;
00043     
00044     // Start the threads
00045     echoThread.start(echoTask);
00046     blinkThread.start(blinkTask);
00047 
00048     while (true) {
00049         thread_sleep_for(1000); // Just get out of the way
00050     }
00051 }