Same as freertos_bluetooth but now with FreeRTOS v_8.2.1

Dependencies:   mbed m3pi FreeRTOS_V8_2_1_LPC1768

Committer:
JoaoJardim
Date:
Wed Dec 05 18:13:24 2018 +0000
Revision:
5:97a449a1e05f
Parent:
4:33929b1afb80
Child:
6:00f820418d01
The terminal should send [0 / 1] to turn [off / on] the LED2 and receive its state back;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chalikias 2:7a112956091c 1 // N.C. Freertos mbed minimal example based on below:
chalikias 2:7a112956091c 2 // https://developer.mbed.org/users/rgrover1/code/FreeRTOS/
chalikias 0:7f7fa5e631ec 3 // http://www.radekdostal.com/content/freertos-610-minimal-example
chalikias 0:7f7fa5e631ec 4
chalikias 0:7f7fa5e631ec 5 #include "mbed.h"
chalikias 0:7f7fa5e631ec 6 #include "FreeRTOS.h"
chalikias 0:7f7fa5e631ec 7 #include "task.h"
JoaoJardim 4:33929b1afb80 8 #include "m3pi.h"
JoaoJardim 4:33929b1afb80 9
JoaoJardim 4:33929b1afb80 10 m3pi m3pi;
chalikias 0:7f7fa5e631ec 11
chalikias 0:7f7fa5e631ec 12 DigitalOut led1(LED1);
chalikias 0:7f7fa5e631ec 13 DigitalOut led2(LED2);
chalikias 0:7f7fa5e631ec 14
JoaoJardim 4:33929b1afb80 15 Serial rn41(p28,p27); // Serial rn41(p9,p10);
JoaoJardim 4:33929b1afb80 16
JoaoJardim 4:33929b1afb80 17
JoaoJardim 4:33929b1afb80 18 const portTickType xDelay = 100 / portTICK_RATE_MS;
JoaoJardim 4:33929b1afb80 19
JoaoJardim 4:33929b1afb80 20 const float fVref = 4.0;
JoaoJardim 4:33929b1afb80 21
JoaoJardim 4:33929b1afb80 22
JoaoJardim 4:33929b1afb80 23 void TaskBluetooth (void* pvParameters)
chalikias 0:7f7fa5e631ec 24 {
chalikias 0:7f7fa5e631ec 25 (void) pvParameters; // Just to stop compiler warnings.
JoaoJardim 4:33929b1afb80 26
JoaoJardim 5:97a449a1e05f 27 int i;
JoaoJardim 4:33929b1afb80 28
JoaoJardim 4:33929b1afb80 29 rn41.baud(115200);
JoaoJardim 4:33929b1afb80 30 led1 = 1;
JoaoJardim 4:33929b1afb80 31 led2 = 1;
JoaoJardim 4:33929b1afb80 32
chalikias 0:7f7fa5e631ec 33 for (;;) {
JoaoJardim 4:33929b1afb80 34
JoaoJardim 4:33929b1afb80 35 if(m3pi.battery() < fVref) {
JoaoJardim 4:33929b1afb80 36 m3pi.cls();
JoaoJardim 4:33929b1afb80 37 m3pi.locate(0,0);
JoaoJardim 4:33929b1afb80 38 m3pi.print("Low Pwr!", 8);
JoaoJardim 4:33929b1afb80 39 }
JoaoJardim 4:33929b1afb80 40 else{
JoaoJardim 4:33929b1afb80 41 m3pi.cls();
JoaoJardim 4:33929b1afb80 42 m3pi.locate(0,0);
JoaoJardim 4:33929b1afb80 43 m3pi.print("BT Task", 8);
JoaoJardim 4:33929b1afb80 44 }
JoaoJardim 4:33929b1afb80 45
JoaoJardim 4:33929b1afb80 46 if (rn41.readable()) { // When BT is readable
JoaoJardim 4:33929b1afb80 47
JoaoJardim 5:97a449a1e05f 48 i = rn41.getc(); // Reads Bluetooth
JoaoJardim 5:97a449a1e05f 49 led2 = i; // The received[0 / 1] turns [off / on] LED2
JoaoJardim 4:33929b1afb80 50
JoaoJardim 5:97a449a1e05f 51 if(rn41.writeable()) {
JoaoJardim 5:97a449a1e05f 52 rn41.putc(led2); // Send LED2 state to the BT terminal
JoaoJardim 5:97a449a1e05f 53 }
JoaoJardim 5:97a449a1e05f 54
JoaoJardim 4:33929b1afb80 55 }
JoaoJardim 4:33929b1afb80 56
chalikias 0:7f7fa5e631ec 57 led1 = !led1;
JoaoJardim 4:33929b1afb80 58 vTaskDelay(xDelay);
chalikias 0:7f7fa5e631ec 59 }
chalikias 0:7f7fa5e631ec 60 }
chalikias 0:7f7fa5e631ec 61
JoaoJardim 4:33929b1afb80 62
chalikias 0:7f7fa5e631ec 63
chalikias 0:7f7fa5e631ec 64 int main (void)
chalikias 0:7f7fa5e631ec 65 {
JoaoJardim 4:33929b1afb80 66 xTaskCreate( TaskBluetooth, ( signed char * ) "TaskBluetooth", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
chalikias 0:7f7fa5e631ec 67 vTaskStartScheduler();
chalikias 0:7f7fa5e631ec 68 //should never get here
chalikias 0:7f7fa5e631ec 69 printf("ERORR: vTaskStartScheduler returned!");
chalikias 0:7f7fa5e631ec 70 for (;;);
chalikias 0:7f7fa5e631ec 71 }