rtos test
Dependencies: LCD_DISCO_F469NI BSP_DISCO_F469NI
main.cpp@1:a2323b3606ab, 2022-01-27 (annotated)
- Committer:
- misha83
- Date:
- Thu Jan 27 18:05:19 2022 +0400
- Revision:
- 1:a2323b3606ab
- Parent:
- 0:172fd6ff0022
- Child:
- 2:b387e91d1513
test 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
misha83 | 0:172fd6ff0022 | 1 | #include "mbed.h" |
misha83 | 0:172fd6ff0022 | 2 | #include "LCD_DISCO_F469NI.h" |
misha83 | 0:172fd6ff0022 | 3 | #include "rtos.h" |
misha83 | 1:a2323b3606ab | 4 | #include <string> |
misha83 | 1:a2323b3606ab | 5 | #include "stdio.h" |
misha83 | 0:172fd6ff0022 | 6 | LCD_DISCO_F469NI lcd; |
misha83 | 0:172fd6ff0022 | 7 | |
misha83 | 0:172fd6ff0022 | 8 | DigitalOut led1(LED1); |
misha83 | 0:172fd6ff0022 | 9 | DigitalOut led2(LED2); |
misha83 | 0:172fd6ff0022 | 10 | |
misha83 | 1:a2323b3606ab | 11 | Thread thread, led_thread, queue_thread; |
misha83 | 1:a2323b3606ab | 12 | |
misha83 | 1:a2323b3606ab | 13 | |
misha83 | 1:a2323b3606ab | 14 | |
misha83 | 1:a2323b3606ab | 15 | |
misha83 | 1:a2323b3606ab | 16 | #define SAMPLE_FLAG1 (1UL << 0) |
misha83 | 1:a2323b3606ab | 17 | #define SAMPLE_FLAG2 (1UL << 9) |
misha83 | 1:a2323b3606ab | 18 | |
misha83 | 1:a2323b3606ab | 19 | EventFlags event_flags; |
misha83 | 1:a2323b3606ab | 20 | |
misha83 | 1:a2323b3606ab | 21 | |
misha83 | 1:a2323b3606ab | 22 | |
misha83 | 1:a2323b3606ab | 23 | |
misha83 | 1:a2323b3606ab | 24 | |
misha83 | 1:a2323b3606ab | 25 | |
misha83 | 1:a2323b3606ab | 26 | typedef struct { |
misha83 | 1:a2323b3606ab | 27 | float voltage; /* AD result of measured voltage */ |
misha83 | 1:a2323b3606ab | 28 | float current; /* AD result of measured current */ |
misha83 | 1:a2323b3606ab | 29 | uint32_t counter; /* A counter value */ |
misha83 | 1:a2323b3606ab | 30 | } message_t; |
misha83 | 0:172fd6ff0022 | 31 | |
misha83 | 1:a2323b3606ab | 32 | MemoryPool<message_t, 16> mpool; |
misha83 | 1:a2323b3606ab | 33 | Queue<message_t, 16> queue; |
misha83 | 1:a2323b3606ab | 34 | |
misha83 | 1:a2323b3606ab | 35 | |
misha83 | 1:a2323b3606ab | 36 | |
misha83 | 1:a2323b3606ab | 37 | |
misha83 | 1:a2323b3606ab | 38 | |
misha83 | 1:a2323b3606ab | 39 | |
misha83 | 1:a2323b3606ab | 40 | |
misha83 | 1:a2323b3606ab | 41 | |
misha83 | 1:a2323b3606ab | 42 | void test_flag(void) |
misha83 | 1:a2323b3606ab | 43 | { |
misha83 | 1:a2323b3606ab | 44 | while(true){ |
misha83 | 1:a2323b3606ab | 45 | |
misha83 | 1:a2323b3606ab | 46 | |
misha83 | 1:a2323b3606ab | 47 | ThisThread::sleep_for(1000); |
misha83 | 1:a2323b3606ab | 48 | event_flags.set(SAMPLE_FLAG1); |
misha83 | 1:a2323b3606ab | 49 | } |
misha83 | 1:a2323b3606ab | 50 | } |
misha83 | 1:a2323b3606ab | 51 | |
misha83 | 1:a2323b3606ab | 52 | |
misha83 | 1:a2323b3606ab | 53 | void led_th(void) |
misha83 | 0:172fd6ff0022 | 54 | { |
misha83 | 0:172fd6ff0022 | 55 | while(true){ |
misha83 | 0:172fd6ff0022 | 56 | |
misha83 | 0:172fd6ff0022 | 57 | led2=!led2; |
misha83 | 0:172fd6ff0022 | 58 | ThisThread::sleep_for(300); |
misha83 | 0:172fd6ff0022 | 59 | } |
misha83 | 0:172fd6ff0022 | 60 | } |
misha83 | 0:172fd6ff0022 | 61 | |
misha83 | 1:a2323b3606ab | 62 | void q_thread(void) |
misha83 | 1:a2323b3606ab | 63 | { |
misha83 | 1:a2323b3606ab | 64 | int i; |
misha83 | 1:a2323b3606ab | 65 | i=0; |
misha83 | 1:a2323b3606ab | 66 | while(true){ |
misha83 | 1:a2323b3606ab | 67 | i++; // fake data update |
misha83 | 1:a2323b3606ab | 68 | message_t *message = mpool.alloc(); |
misha83 | 1:a2323b3606ab | 69 | message->voltage = (i * 0.1) * 33; |
misha83 | 1:a2323b3606ab | 70 | message->current = (i * 0.1) * 11; |
misha83 | 1:a2323b3606ab | 71 | message->counter = i; |
misha83 | 1:a2323b3606ab | 72 | queue.put(message); |
misha83 | 1:a2323b3606ab | 73 | |
misha83 | 1:a2323b3606ab | 74 | ThisThread::sleep_for(700); |
misha83 | 1:a2323b3606ab | 75 | } |
misha83 | 1:a2323b3606ab | 76 | } |
misha83 | 1:a2323b3606ab | 77 | |
misha83 | 1:a2323b3606ab | 78 | |
misha83 | 0:172fd6ff0022 | 79 | int main() |
misha83 | 0:172fd6ff0022 | 80 | { |
misha83 | 1:a2323b3606ab | 81 | |
misha83 | 1:a2323b3606ab | 82 | bool st=false; |
misha83 | 0:172fd6ff0022 | 83 | led1 = 1; |
misha83 | 0:172fd6ff0022 | 84 | led2 = 1; |
misha83 | 1:a2323b3606ab | 85 | uint32_t flags_read = 0; |
misha83 | 0:172fd6ff0022 | 86 | |
misha83 | 1:a2323b3606ab | 87 | char buffer[50]; |
misha83 | 1:a2323b3606ab | 88 | int c = 0; |
misha83 | 1:a2323b3606ab | 89 | |
misha83 | 1:a2323b3606ab | 90 | printf("start mbed TEST\n\r"); |
misha83 | 1:a2323b3606ab | 91 | |
misha83 | 0:172fd6ff0022 | 92 | |
misha83 | 1:a2323b3606ab | 93 | thread.start(test_flag); |
misha83 | 1:a2323b3606ab | 94 | led_thread.start(led_th); |
misha83 | 1:a2323b3606ab | 95 | queue_thread.start(q_thread); |
misha83 | 1:a2323b3606ab | 96 | |
misha83 | 1:a2323b3606ab | 97 | |
misha83 | 1:a2323b3606ab | 98 | |
misha83 | 1:a2323b3606ab | 99 | //lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); |
misha83 | 1:a2323b3606ab | 100 | //ThisThread::sleep_for(1); |
misha83 | 0:172fd6ff0022 | 101 | |
misha83 | 1:a2323b3606ab | 102 | |
misha83 | 1:a2323b3606ab | 103 | |
misha83 | 1:a2323b3606ab | 104 | |
misha83 | 1:a2323b3606ab | 105 | lcd.Clear(LCD_COLOR_BLUE); |
misha83 | 1:a2323b3606ab | 106 | lcd.SetBackColor(LCD_COLOR_BLUE); |
misha83 | 1:a2323b3606ab | 107 | |
misha83 | 1:a2323b3606ab | 108 | |
misha83 | 1:a2323b3606ab | 109 | |
misha83 | 0:172fd6ff0022 | 110 | while(1) |
misha83 | 0:172fd6ff0022 | 111 | { |
misha83 | 1:a2323b3606ab | 112 | |
misha83 | 1:a2323b3606ab | 113 | flags_read = event_flags.wait_any(SAMPLE_FLAG1, 10); |
misha83 | 1:a2323b3606ab | 114 | |
misha83 | 1:a2323b3606ab | 115 | if(flags_read&SAMPLE_FLAG1){ |
misha83 | 1:a2323b3606ab | 116 | //lcd.Clear(LCD_COLOR_BLUE); |
misha83 | 1:a2323b3606ab | 117 | |
misha83 | 1:a2323b3606ab | 118 | if(st){ |
misha83 | 1:a2323b3606ab | 119 | lcd.SetTextColor(LCD_COLOR_WHITE); |
misha83 | 1:a2323b3606ab | 120 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"FLAG 0 SET EVERY 1 SEC", LEFT_MODE); |
misha83 | 1:a2323b3606ab | 121 | }else{ |
misha83 | 1:a2323b3606ab | 122 | lcd.SetTextColor(LCD_COLOR_DARKRED); |
misha83 | 1:a2323b3606ab | 123 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"FLAG 0 SET EVERY 1 SEC", LEFT_MODE); |
misha83 | 1:a2323b3606ab | 124 | |
misha83 | 1:a2323b3606ab | 125 | } |
misha83 | 1:a2323b3606ab | 126 | st=!st; |
misha83 | 1:a2323b3606ab | 127 | } |
misha83 | 1:a2323b3606ab | 128 | |
misha83 | 1:a2323b3606ab | 129 | |
misha83 | 1:a2323b3606ab | 130 | |
misha83 | 1:a2323b3606ab | 131 | osEvent evt = queue.get(10); |
misha83 | 1:a2323b3606ab | 132 | if (evt.status == osEventMessage) { |
misha83 | 1:a2323b3606ab | 133 | message_t *message = (message_t *)evt.value.p; |
misha83 | 1:a2323b3606ab | 134 | |
misha83 | 1:a2323b3606ab | 135 | c++; |
misha83 | 1:a2323b3606ab | 136 | sprintf(buffer, "queue message counter: %d", c); |
misha83 | 1:a2323b3606ab | 137 | lcd.SetTextColor(LCD_COLOR_ORANGE); |
misha83 | 1:a2323b3606ab | 138 | lcd.DisplayStringAt(0, LINE(4), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 139 | |
misha83 | 1:a2323b3606ab | 140 | sprintf(buffer, "Voltage: %d", message->voltage); |
misha83 | 1:a2323b3606ab | 141 | lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); |
misha83 | 1:a2323b3606ab | 142 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 143 | |
misha83 | 1:a2323b3606ab | 144 | sprintf(buffer, "Current: %d", message->current); |
misha83 | 1:a2323b3606ab | 145 | lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); |
misha83 | 1:a2323b3606ab | 146 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 147 | |
misha83 | 1:a2323b3606ab | 148 | sprintf(buffer, "Counter: %d", message->counter); |
misha83 | 1:a2323b3606ab | 149 | lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); |
misha83 | 1:a2323b3606ab | 150 | lcd.DisplayStringAt(0, LINE(7), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 151 | |
misha83 | 1:a2323b3606ab | 152 | |
misha83 | 1:a2323b3606ab | 153 | mpool.free(message); |
misha83 | 1:a2323b3606ab | 154 | } |
misha83 | 1:a2323b3606ab | 155 | |
misha83 | 1:a2323b3606ab | 156 | |
misha83 | 1:a2323b3606ab | 157 | |
misha83 | 1:a2323b3606ab | 158 | |
misha83 | 1:a2323b3606ab | 159 | /* |
misha83 | 0:172fd6ff0022 | 160 | lcd.Clear(LCD_COLOR_BLUE); |
misha83 | 0:172fd6ff0022 | 161 | lcd.SetBackColor(LCD_COLOR_BLUE); |
misha83 | 0:172fd6ff0022 | 162 | lcd.SetTextColor(LCD_COLOR_WHITE); |
misha83 | 0:172fd6ff0022 | 163 | ThisThread::sleep_for(300); |
misha83 | 0:172fd6ff0022 | 164 | lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY", CENTER_MODE); |
misha83 | 0:172fd6ff0022 | 165 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F469NI", CENTER_MODE); |
misha83 | 0:172fd6ff0022 | 166 | ThisThread::sleep_for(1000); |
misha83 | 0:172fd6ff0022 | 167 | |
misha83 | 0:172fd6ff0022 | 168 | lcd.Clear(LCD_COLOR_GREEN); |
misha83 | 0:172fd6ff0022 | 169 | |
misha83 | 0:172fd6ff0022 | 170 | lcd.SetTextColor(LCD_COLOR_BLUE); |
misha83 | 0:172fd6ff0022 | 171 | lcd.FillRect(10, 20, 50, 50); |
misha83 | 0:172fd6ff0022 | 172 | ThisThread::sleep_for(100); |
misha83 | 0:172fd6ff0022 | 173 | lcd.SetTextColor(LCD_COLOR_BROWN); |
misha83 | 0:172fd6ff0022 | 174 | lcd.FillCircle(80, 80, 50); |
misha83 | 0:172fd6ff0022 | 175 | ThisThread::sleep_for(100); |
misha83 | 0:172fd6ff0022 | 176 | lcd.SetTextColor(LCD_COLOR_YELLOW); |
misha83 | 0:172fd6ff0022 | 177 | lcd.FillEllipse(150, 150, 50, 100); |
misha83 | 0:172fd6ff0022 | 178 | ThisThread::sleep_for(100); |
misha83 | 0:172fd6ff0022 | 179 | lcd.SetTextColor(LCD_COLOR_RED); |
misha83 | 0:172fd6ff0022 | 180 | lcd.FillCircle(200, 200, 40); |
misha83 | 0:172fd6ff0022 | 181 | ThisThread::sleep_for(1000); |
misha83 | 0:172fd6ff0022 | 182 | |
misha83 | 0:172fd6ff0022 | 183 | lcd.SetBackColor(LCD_COLOR_ORANGE); |
misha83 | 0:172fd6ff0022 | 184 | lcd.SetTextColor(LCD_COLOR_CYAN); |
misha83 | 0:172fd6ff0022 | 185 | BSP_LCD_SetFont(&Font20); |
misha83 | 0:172fd6ff0022 | 186 | lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); |
misha83 | 0:172fd6ff0022 | 187 | ThisThread::sleep_for(1000); |
misha83 | 0:172fd6ff0022 | 188 | |
misha83 | 0:172fd6ff0022 | 189 | led1 = !led1; |
misha83 | 0:172fd6ff0022 | 190 | ThisThread::sleep_for(500); |
misha83 | 1:a2323b3606ab | 191 | */ |
misha83 | 0:172fd6ff0022 | 192 | } |
misha83 | 0:172fd6ff0022 | 193 | } |
misha83 | 0:172fd6ff0022 | 194 |