Same as freertos_bluetooth but now with FreeRTOS v_8.2.1
Dependencies: mbed m3pi FreeRTOS_V8_2_1_LPC1768
main.cpp@4:33929b1afb80, 2018-12-05 (annotated)
- Committer:
- JoaoJardim
- Date:
- Wed Dec 05 17:56:16 2018 +0000
- Revision:
- 4:33929b1afb80
- Parent:
- 3:d577dbef65a2
- Child:
- 5:97a449a1e05f
m3pi with RN41XVC-I/RM
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:33929b1afb80 | 27 | char *cBufferBT; |
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 | 4:33929b1afb80 | 48 | sprintf(cBufferBT, "%d", rn41.getc()); // Reads Bluetooth |
JoaoJardim | 4:33929b1afb80 | 49 | m3pi.locate(0,1); // Prints the received message on the LCD |
JoaoJardim | 4:33929b1afb80 | 50 | m3pi.print(cBufferBT, 8); |
JoaoJardim | 4:33929b1afb80 | 51 | |
JoaoJardim | 4:33929b1afb80 | 52 | rn41.putc(6); // Send message to the BT terminal |
JoaoJardim | 4:33929b1afb80 | 53 | led2 = !led2; |
JoaoJardim | 4:33929b1afb80 | 54 | } |
JoaoJardim | 4:33929b1afb80 | 55 | |
chalikias | 0:7f7fa5e631ec | 56 | led1 = !led1; |
JoaoJardim | 4:33929b1afb80 | 57 | vTaskDelay(xDelay); |
chalikias | 0:7f7fa5e631ec | 58 | } |
chalikias | 0:7f7fa5e631ec | 59 | } |
chalikias | 0:7f7fa5e631ec | 60 | |
JoaoJardim | 4:33929b1afb80 | 61 | |
chalikias | 0:7f7fa5e631ec | 62 | |
chalikias | 0:7f7fa5e631ec | 63 | int main (void) |
chalikias | 0:7f7fa5e631ec | 64 | { |
JoaoJardim | 4:33929b1afb80 | 65 | xTaskCreate( TaskBluetooth, ( signed char * ) "TaskBluetooth", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); |
chalikias | 0:7f7fa5e631ec | 66 | vTaskStartScheduler(); |
chalikias | 0:7f7fa5e631ec | 67 | //should never get here |
chalikias | 0:7f7fa5e631ec | 68 | printf("ERORR: vTaskStartScheduler returned!"); |
chalikias | 0:7f7fa5e631ec | 69 | for (;;); |
chalikias | 0:7f7fa5e631ec | 70 | } |