
rtos test
Dependencies: LCD_DISCO_F469NI BSP_DISCO_F469NI
Diff: main.cpp
- Revision:
- 1:a2323b3606ab
- Parent:
- 0:172fd6ff0022
- Child:
- 2:b387e91d1513
--- a/main.cpp Thu Jan 27 13:15:20 2022 +0000 +++ b/main.cpp Thu Jan 27 18:05:19 2022 +0400 @@ -1,14 +1,56 @@ #include "mbed.h" #include "LCD_DISCO_F469NI.h" #include "rtos.h" +#include <string> +#include "stdio.h" LCD_DISCO_F469NI lcd; DigitalOut led1(LED1); DigitalOut led2(LED2); -Thread thread; +Thread thread, led_thread, queue_thread; + + + + +#define SAMPLE_FLAG1 (1UL << 0) +#define SAMPLE_FLAG2 (1UL << 9) + +EventFlags event_flags; + + + + + + +typedef struct { + float voltage; /* AD result of measured voltage */ + float current; /* AD result of measured current */ + uint32_t counter; /* A counter value */ +} message_t; -void test(void) +MemoryPool<message_t, 16> mpool; +Queue<message_t, 16> queue; + + + + + + + + +void test_flag(void) +{ + while(true){ + + + ThisThread::sleep_for(1000); + event_flags.set(SAMPLE_FLAG1); + } +} + + +void led_th(void) { while(true){ @@ -17,19 +59,104 @@ } } +void q_thread(void) +{ + int i; + i=0; + while(true){ + i++; // fake data update + message_t *message = mpool.alloc(); + message->voltage = (i * 0.1) * 33; + message->current = (i * 0.1) * 11; + message->counter = i; + queue.put(message); + + ThisThread::sleep_for(700); + } +} + + int main() { + + bool st=false; led1 = 1; led2 = 1; - + uint32_t flags_read = 0; - thread.start(test); + char buffer[50]; + int c = 0; + + printf("start mbed TEST\n\r"); + - lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); - ThisThread::sleep_for(1); + thread.start(test_flag); + led_thread.start(led_th); + queue_thread.start(q_thread); + + + + //lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); + //ThisThread::sleep_for(1); + + + + lcd.Clear(LCD_COLOR_BLUE); + lcd.SetBackColor(LCD_COLOR_BLUE); + + + while(1) { + + flags_read = event_flags.wait_any(SAMPLE_FLAG1, 10); + + if(flags_read&SAMPLE_FLAG1){ + //lcd.Clear(LCD_COLOR_BLUE); + + if(st){ + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"FLAG 0 SET EVERY 1 SEC", LEFT_MODE); + }else{ + lcd.SetTextColor(LCD_COLOR_DARKRED); + lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"FLAG 0 SET EVERY 1 SEC", LEFT_MODE); + + } + st=!st; + } + + + + osEvent evt = queue.get(10); + if (evt.status == osEventMessage) { + message_t *message = (message_t *)evt.value.p; + + c++; + sprintf(buffer, "queue message counter: %d", c); + lcd.SetTextColor(LCD_COLOR_ORANGE); + lcd.DisplayStringAt(0, LINE(4), (uint8_t *)buffer, LEFT_MODE); + + sprintf(buffer, "Voltage: %d", message->voltage); + lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)buffer, LEFT_MODE); + + sprintf(buffer, "Current: %d", message->current); + lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); + lcd.DisplayStringAt(0, LINE(6), (uint8_t *)buffer, LEFT_MODE); + + sprintf(buffer, "Counter: %d", message->counter); + lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); + lcd.DisplayStringAt(0, LINE(7), (uint8_t *)buffer, LEFT_MODE); + + + mpool.free(message); + } + + + + + /* lcd.Clear(LCD_COLOR_BLUE); lcd.SetBackColor(LCD_COLOR_BLUE); lcd.SetTextColor(LCD_COLOR_WHITE); @@ -61,6 +188,7 @@ led1 = !led1; ThisThread::sleep_for(500); + */ } }