Final version of the m3pi software

Dependencies:   mbed m3pi FreeRTOS_V8_2_1_LPC1768

Committer:
JoaoJardim
Date:
Mon Dec 10 10:04:44 2018 +0000
Revision:
6:00f820418d01
Parent:
5:97a449a1e05f
Child:
8:167680431cf4
FreeRTOS "port" to LPC1768

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 6:00f820418d01 15 DigitalOut nRST(p26);
JoaoJardim 4:33929b1afb80 16
JoaoJardim 4:33929b1afb80 17 const portTickType xDelay = 100 / portTICK_RATE_MS;
JoaoJardim 4:33929b1afb80 18
JoaoJardim 4:33929b1afb80 19 const float fVref = 4.0;
JoaoJardim 4:33929b1afb80 20
JoaoJardim 4:33929b1afb80 21
JoaoJardim 4:33929b1afb80 22 void TaskBluetooth (void* pvParameters)
chalikias 0:7f7fa5e631ec 23 {
chalikias 0:7f7fa5e631ec 24 (void) pvParameters; // Just to stop compiler warnings.
JoaoJardim 6:00f820418d01 25
JoaoJardim 6:00f820418d01 26 int i;
JoaoJardim 4:33929b1afb80 27
JoaoJardim 6:00f820418d01 28 nRST = 0;
JoaoJardim 6:00f820418d01 29 vTaskDelay(xDelay);
JoaoJardim 6:00f820418d01 30 nRST = 1;
JoaoJardim 6:00f820418d01 31
JoaoJardim 6:00f820418d01 32 Serial rn41(p28,p27); // Serial rn41(p9,p10);
JoaoJardim 4:33929b1afb80 33
JoaoJardim 4:33929b1afb80 34 rn41.baud(115200);
JoaoJardim 4:33929b1afb80 35 led1 = 1;
JoaoJardim 4:33929b1afb80 36 led2 = 1;
JoaoJardim 4:33929b1afb80 37
chalikias 0:7f7fa5e631ec 38 for (;;) {
JoaoJardim 4:33929b1afb80 39
JoaoJardim 4:33929b1afb80 40 if(m3pi.battery() < fVref) {
JoaoJardim 4:33929b1afb80 41 m3pi.cls();
JoaoJardim 4:33929b1afb80 42 m3pi.locate(0,0);
JoaoJardim 4:33929b1afb80 43 m3pi.print("Low Pwr!", 8);
JoaoJardim 4:33929b1afb80 44 }
JoaoJardim 4:33929b1afb80 45 else{
JoaoJardim 4:33929b1afb80 46 m3pi.cls();
JoaoJardim 4:33929b1afb80 47 m3pi.locate(0,0);
JoaoJardim 4:33929b1afb80 48 m3pi.print("BT Task", 8);
JoaoJardim 4:33929b1afb80 49 }
JoaoJardim 4:33929b1afb80 50
JoaoJardim 4:33929b1afb80 51 if (rn41.readable()) { // When BT is readable
JoaoJardim 4:33929b1afb80 52
JoaoJardim 5:97a449a1e05f 53 i = rn41.getc(); // Reads Bluetooth
JoaoJardim 5:97a449a1e05f 54 led2 = i; // The received[0 / 1] turns [off / on] LED2
JoaoJardim 4:33929b1afb80 55
JoaoJardim 5:97a449a1e05f 56 if(rn41.writeable()) {
JoaoJardim 5:97a449a1e05f 57 rn41.putc(led2); // Send LED2 state to the BT terminal
JoaoJardim 5:97a449a1e05f 58 }
JoaoJardim 5:97a449a1e05f 59
JoaoJardim 4:33929b1afb80 60 }
JoaoJardim 4:33929b1afb80 61
chalikias 0:7f7fa5e631ec 62 led1 = !led1;
JoaoJardim 4:33929b1afb80 63 vTaskDelay(xDelay);
chalikias 0:7f7fa5e631ec 64 }
chalikias 0:7f7fa5e631ec 65 }
chalikias 0:7f7fa5e631ec 66
JoaoJardim 4:33929b1afb80 67
chalikias 0:7f7fa5e631ec 68
chalikias 0:7f7fa5e631ec 69 int main (void)
chalikias 0:7f7fa5e631ec 70 {
JoaoJardim 6:00f820418d01 71 xTaskCreate( TaskBluetooth, ( const char * ) "TaskBluetooth", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
chalikias 0:7f7fa5e631ec 72 vTaskStartScheduler();
chalikias 0:7f7fa5e631ec 73 //should never get here
chalikias 0:7f7fa5e631ec 74 printf("ERORR: vTaskStartScheduler returned!");
chalikias 0:7f7fa5e631ec 75 for (;;);
chalikias 0:7f7fa5e631ec 76 }