rtos test
Dependencies: LCD_DISCO_F469NI BSP_DISCO_F469NI
main.cpp@5:3118045d33a2, 2022-01-31 (annotated)
- Committer:
- misha83
- Date:
- Mon Jan 31 12:04:09 2022 +0400
- Revision:
- 5:3118045d33a2
- Parent:
- 4:22d1c1776155
tes
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 | 5:3118045d33a2 | 6 | |
misha83 | 5:3118045d33a2 | 7 | |
misha83 | 5:3118045d33a2 | 8 | #include <errno.h> |
misha83 | 5:3118045d33a2 | 9 | #include <functional> |
misha83 | 5:3118045d33a2 | 10 | |
misha83 | 5:3118045d33a2 | 11 | #include "BlockDevice.h" |
misha83 | 5:3118045d33a2 | 12 | |
misha83 | 5:3118045d33a2 | 13 | |
misha83 | 5:3118045d33a2 | 14 | #include "LittleFileSystem.h" |
misha83 | 5:3118045d33a2 | 15 | |
misha83 | 5:3118045d33a2 | 16 | |
misha83 | 0:172fd6ff0022 | 17 | LCD_DISCO_F469NI lcd; |
misha83 | 0:172fd6ff0022 | 18 | |
misha83 | 0:172fd6ff0022 | 19 | DigitalOut led1(LED1); |
misha83 | 0:172fd6ff0022 | 20 | DigitalOut led2(LED2); |
misha83 | 5:3118045d33a2 | 21 | DigitalOut led3(LED3); |
misha83 | 0:172fd6ff0022 | 22 | |
misha83 | 5:3118045d33a2 | 23 | Thread thread, led_thread, queue_thread, button_thread; |
misha83 | 1:a2323b3606ab | 24 | |
misha83 | 1:a2323b3606ab | 25 | |
misha83 | 1:a2323b3606ab | 26 | |
misha83 | 5:3118045d33a2 | 27 | #define BUFFER_MAX_LEN 10 |
misha83 | 5:3118045d33a2 | 28 | #define FORCE_REFORMAT true |
misha83 | 5:3118045d33a2 | 29 | |
misha83 | 1:a2323b3606ab | 30 | |
misha83 | 1:a2323b3606ab | 31 | #define SAMPLE_FLAG1 (1UL << 0) |
misha83 | 1:a2323b3606ab | 32 | #define SAMPLE_FLAG2 (1UL << 9) |
misha83 | 1:a2323b3606ab | 33 | |
misha83 | 1:a2323b3606ab | 34 | EventFlags event_flags; |
misha83 | 1:a2323b3606ab | 35 | |
misha83 | 1:a2323b3606ab | 36 | |
misha83 | 1:a2323b3606ab | 37 | |
misha83 | 1:a2323b3606ab | 38 | |
misha83 | 3:ba7197f10216 | 39 | //mikoriko test |
misha83 | 1:a2323b3606ab | 40 | |
misha83 | 1:a2323b3606ab | 41 | typedef struct { |
misha83 | 1:a2323b3606ab | 42 | float voltage; /* AD result of measured voltage */ |
misha83 | 1:a2323b3606ab | 43 | float current; /* AD result of measured current */ |
misha83 | 1:a2323b3606ab | 44 | uint32_t counter; /* A counter value */ |
misha83 | 1:a2323b3606ab | 45 | } message_t; |
misha83 | 0:172fd6ff0022 | 46 | |
misha83 | 1:a2323b3606ab | 47 | MemoryPool<message_t, 16> mpool; |
misha83 | 1:a2323b3606ab | 48 | Queue<message_t, 16> queue; |
misha83 | 1:a2323b3606ab | 49 | |
misha83 | 1:a2323b3606ab | 50 | |
misha83 | 1:a2323b3606ab | 51 | |
misha83 | 5:3118045d33a2 | 52 | BlockDevice *bd = BlockDevice::get_default_instance(); |
misha83 | 5:3118045d33a2 | 53 | LittleFileSystem fs("fs"); |
misha83 | 1:a2323b3606ab | 54 | |
misha83 | 1:a2323b3606ab | 55 | |
misha83 | 1:a2323b3606ab | 56 | |
misha83 | 1:a2323b3606ab | 57 | |
misha83 | 1:a2323b3606ab | 58 | |
misha83 | 1:a2323b3606ab | 59 | void test_flag(void) |
misha83 | 1:a2323b3606ab | 60 | { |
misha83 | 1:a2323b3606ab | 61 | while(true){ |
misha83 | 1:a2323b3606ab | 62 | |
misha83 | 1:a2323b3606ab | 63 | |
misha83 | 1:a2323b3606ab | 64 | ThisThread::sleep_for(1000); |
misha83 | 1:a2323b3606ab | 65 | event_flags.set(SAMPLE_FLAG1); |
misha83 | 1:a2323b3606ab | 66 | } |
misha83 | 1:a2323b3606ab | 67 | } |
misha83 | 1:a2323b3606ab | 68 | |
misha83 | 1:a2323b3606ab | 69 | |
misha83 | 1:a2323b3606ab | 70 | void led_th(void) |
misha83 | 0:172fd6ff0022 | 71 | { |
misha83 | 0:172fd6ff0022 | 72 | while(true){ |
misha83 | 0:172fd6ff0022 | 73 | |
misha83 | 0:172fd6ff0022 | 74 | led2=!led2; |
misha83 | 0:172fd6ff0022 | 75 | ThisThread::sleep_for(300); |
misha83 | 0:172fd6ff0022 | 76 | } |
misha83 | 0:172fd6ff0022 | 77 | } |
misha83 | 0:172fd6ff0022 | 78 | |
misha83 | 1:a2323b3606ab | 79 | void q_thread(void) |
misha83 | 1:a2323b3606ab | 80 | { |
misha83 | 1:a2323b3606ab | 81 | int i; |
misha83 | 1:a2323b3606ab | 82 | i=0; |
misha83 | 1:a2323b3606ab | 83 | while(true){ |
misha83 | 1:a2323b3606ab | 84 | i++; // fake data update |
misha83 | 1:a2323b3606ab | 85 | message_t *message = mpool.alloc(); |
misha83 | 1:a2323b3606ab | 86 | message->voltage = (i * 0.1) * 33; |
misha83 | 1:a2323b3606ab | 87 | message->current = (i * 0.1) * 11; |
misha83 | 1:a2323b3606ab | 88 | message->counter = i; |
misha83 | 1:a2323b3606ab | 89 | queue.put(message); |
misha83 | 1:a2323b3606ab | 90 | |
misha83 | 1:a2323b3606ab | 91 | ThisThread::sleep_for(700); |
misha83 | 1:a2323b3606ab | 92 | } |
misha83 | 1:a2323b3606ab | 93 | } |
misha83 | 1:a2323b3606ab | 94 | |
misha83 | 1:a2323b3606ab | 95 | |
misha83 | 5:3118045d33a2 | 96 | void erase() { |
misha83 | 5:3118045d33a2 | 97 | printf("Initializing the block device... "); |
misha83 | 5:3118045d33a2 | 98 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 99 | int err = bd->init(); |
misha83 | 5:3118045d33a2 | 100 | printf("%s\n", (err ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 101 | if (err) { |
misha83 | 5:3118045d33a2 | 102 | error("error: %s (%d)\n", strerror(-err), err); |
misha83 | 5:3118045d33a2 | 103 | } |
misha83 | 5:3118045d33a2 | 104 | |
misha83 | 5:3118045d33a2 | 105 | printf("Erasing the block device... "); |
misha83 | 5:3118045d33a2 | 106 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 107 | err = bd->erase(0, bd->size()); |
misha83 | 5:3118045d33a2 | 108 | printf("%s\n", (err ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 109 | if (err) { |
misha83 | 5:3118045d33a2 | 110 | error("error: %s (%d)\n", strerror(-err), err); |
misha83 | 5:3118045d33a2 | 111 | } |
misha83 | 5:3118045d33a2 | 112 | |
misha83 | 5:3118045d33a2 | 113 | printf("Deinitializing the block device... "); |
misha83 | 5:3118045d33a2 | 114 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 115 | err = bd->deinit(); |
misha83 | 5:3118045d33a2 | 116 | printf("%s\n", (err ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 117 | if (err) { |
misha83 | 5:3118045d33a2 | 118 | error("error: %s (%d)\n", strerror(-err), err); |
misha83 | 5:3118045d33a2 | 119 | } |
misha83 | 5:3118045d33a2 | 120 | } |
misha83 | 5:3118045d33a2 | 121 | |
misha83 | 5:3118045d33a2 | 122 | |
misha83 | 5:3118045d33a2 | 123 | void mount(void) |
misha83 | 5:3118045d33a2 | 124 | { |
misha83 | 5:3118045d33a2 | 125 | // Try to mount the filesystem |
misha83 | 5:3118045d33a2 | 126 | printf("Mounting the filesystem... "); |
misha83 | 5:3118045d33a2 | 127 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 128 | int err = fs.mount(bd); |
misha83 | 5:3118045d33a2 | 129 | printf("%s\n", (err ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 130 | if (err || FORCE_REFORMAT) { |
misha83 | 5:3118045d33a2 | 131 | // Reformat if we can't mount the filesystem |
misha83 | 5:3118045d33a2 | 132 | printf("formatting... "); |
misha83 | 5:3118045d33a2 | 133 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 134 | err = fs.reformat(bd); |
misha83 | 5:3118045d33a2 | 135 | printf("%s\n", (err ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 136 | if (err) { |
misha83 | 5:3118045d33a2 | 137 | error("error: %s (%d)\n", strerror(-err), err); |
misha83 | 5:3118045d33a2 | 138 | } |
misha83 | 5:3118045d33a2 | 139 | } |
misha83 | 5:3118045d33a2 | 140 | |
misha83 | 5:3118045d33a2 | 141 | // Open the numbers file |
misha83 | 5:3118045d33a2 | 142 | printf("Opening \"/fs/numbers.txt\"... "); |
misha83 | 5:3118045d33a2 | 143 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 144 | FILE *f = fopen("/fs/numbers.txt", "r+"); |
misha83 | 5:3118045d33a2 | 145 | printf("%s\n", (!f ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 146 | if (!f) { |
misha83 | 5:3118045d33a2 | 147 | // Create the numbers file if it doesn't exist |
misha83 | 5:3118045d33a2 | 148 | printf("No file found, creating a new file... "); |
misha83 | 5:3118045d33a2 | 149 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 150 | f = fopen("/fs/numbers.txt", "w+"); |
misha83 | 5:3118045d33a2 | 151 | printf("%s\n", (!f ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 152 | if (!f) { |
misha83 | 5:3118045d33a2 | 153 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 154 | } |
misha83 | 5:3118045d33a2 | 155 | |
misha83 | 5:3118045d33a2 | 156 | for (int i = 0; i < 10; i++) { |
misha83 | 5:3118045d33a2 | 157 | printf("\rWriting numbers (%d/%d)... ", i, 10); |
misha83 | 5:3118045d33a2 | 158 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 159 | err = fprintf(f, " %d\n", i); |
misha83 | 5:3118045d33a2 | 160 | if (err < 0) { |
misha83 | 5:3118045d33a2 | 161 | printf("Fail :(\n"); |
misha83 | 5:3118045d33a2 | 162 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 163 | } |
misha83 | 5:3118045d33a2 | 164 | } |
misha83 | 5:3118045d33a2 | 165 | printf("\rWriting numbers (%d/%d)... OK\n", 10, 10); |
misha83 | 5:3118045d33a2 | 166 | |
misha83 | 5:3118045d33a2 | 167 | printf("Seeking file... "); |
misha83 | 5:3118045d33a2 | 168 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 169 | err = fseek(f, 0, SEEK_SET); |
misha83 | 5:3118045d33a2 | 170 | printf("%s\n", (err < 0 ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 171 | if (err < 0) { |
misha83 | 5:3118045d33a2 | 172 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 173 | } |
misha83 | 5:3118045d33a2 | 174 | } |
misha83 | 5:3118045d33a2 | 175 | |
misha83 | 5:3118045d33a2 | 176 | // Go through and increment the numbers |
misha83 | 5:3118045d33a2 | 177 | for (int i = 0; i < 10; i++) { |
misha83 | 5:3118045d33a2 | 178 | printf("\rIncrementing numbers (%d/%d)... ", i, 10); |
misha83 | 5:3118045d33a2 | 179 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 180 | |
misha83 | 5:3118045d33a2 | 181 | // Get current stream position |
misha83 | 5:3118045d33a2 | 182 | long pos = ftell(f); |
misha83 | 5:3118045d33a2 | 183 | |
misha83 | 5:3118045d33a2 | 184 | // Parse out the number and increment |
misha83 | 5:3118045d33a2 | 185 | char buf[BUFFER_MAX_LEN]; |
misha83 | 5:3118045d33a2 | 186 | if (!fgets(buf, BUFFER_MAX_LEN, f)) { |
misha83 | 5:3118045d33a2 | 187 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 188 | } |
misha83 | 5:3118045d33a2 | 189 | char *endptr; |
misha83 | 5:3118045d33a2 | 190 | int32_t number = strtol(buf, &endptr, 10); |
misha83 | 5:3118045d33a2 | 191 | if ( |
misha83 | 5:3118045d33a2 | 192 | (errno == ERANGE) || // The number is too small/large |
misha83 | 5:3118045d33a2 | 193 | (endptr == buf) || // No character was read |
misha83 | 5:3118045d33a2 | 194 | (*endptr && *endptr != '\n') // The whole input was not converted |
misha83 | 5:3118045d33a2 | 195 | ) { |
misha83 | 5:3118045d33a2 | 196 | continue; |
misha83 | 5:3118045d33a2 | 197 | } |
misha83 | 5:3118045d33a2 | 198 | number += 1; |
misha83 | 5:3118045d33a2 | 199 | |
misha83 | 5:3118045d33a2 | 200 | // Seek to beginning of number |
misha83 | 5:3118045d33a2 | 201 | fseek(f, pos, SEEK_SET); |
misha83 | 5:3118045d33a2 | 202 | |
misha83 | 5:3118045d33a2 | 203 | // Store number |
misha83 | 5:3118045d33a2 | 204 | fprintf(f, " %d\n", number); |
misha83 | 5:3118045d33a2 | 205 | |
misha83 | 5:3118045d33a2 | 206 | // Flush between write and read on same file |
misha83 | 5:3118045d33a2 | 207 | fflush(f); |
misha83 | 5:3118045d33a2 | 208 | } |
misha83 | 5:3118045d33a2 | 209 | printf("\rIncrementing numbers (%d/%d)... OK\n", 10, 10); |
misha83 | 5:3118045d33a2 | 210 | |
misha83 | 5:3118045d33a2 | 211 | // Close the file which also flushes any cached writes |
misha83 | 5:3118045d33a2 | 212 | printf("Closing \"/fs/numbers.txt\"... "); |
misha83 | 5:3118045d33a2 | 213 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 214 | err = fclose(f); |
misha83 | 5:3118045d33a2 | 215 | printf("%s\n", (err < 0 ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 216 | if (err < 0) { |
misha83 | 5:3118045d33a2 | 217 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 218 | } |
misha83 | 5:3118045d33a2 | 219 | |
misha83 | 5:3118045d33a2 | 220 | // Display the root directory |
misha83 | 5:3118045d33a2 | 221 | printf("Opening the root directory... "); |
misha83 | 5:3118045d33a2 | 222 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 223 | DIR *d = opendir("/fs/"); |
misha83 | 5:3118045d33a2 | 224 | printf("%s\n", (!d ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 225 | if (!d) { |
misha83 | 5:3118045d33a2 | 226 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 227 | } |
misha83 | 5:3118045d33a2 | 228 | |
misha83 | 5:3118045d33a2 | 229 | printf("root directory:\n"); |
misha83 | 5:3118045d33a2 | 230 | while (true) { |
misha83 | 5:3118045d33a2 | 231 | struct dirent *e = readdir(d); |
misha83 | 5:3118045d33a2 | 232 | if (!e) { |
misha83 | 5:3118045d33a2 | 233 | break; |
misha83 | 5:3118045d33a2 | 234 | } |
misha83 | 5:3118045d33a2 | 235 | |
misha83 | 5:3118045d33a2 | 236 | printf(" %s\n", e->d_name); |
misha83 | 5:3118045d33a2 | 237 | } |
misha83 | 5:3118045d33a2 | 238 | |
misha83 | 5:3118045d33a2 | 239 | printf("Closing the root directory... "); |
misha83 | 5:3118045d33a2 | 240 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 241 | err = closedir(d); |
misha83 | 5:3118045d33a2 | 242 | printf("%s\n", (err < 0 ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 243 | if (err < 0) { |
misha83 | 5:3118045d33a2 | 244 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 245 | } |
misha83 | 5:3118045d33a2 | 246 | |
misha83 | 5:3118045d33a2 | 247 | // Display the numbers file |
misha83 | 5:3118045d33a2 | 248 | printf("Opening \"/fs/numbers.txt\"... "); |
misha83 | 5:3118045d33a2 | 249 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 250 | f = fopen("/fs/numbers.txt", "r"); |
misha83 | 5:3118045d33a2 | 251 | printf("%s\n", (!f ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 252 | if (!f) { |
misha83 | 5:3118045d33a2 | 253 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 254 | } |
misha83 | 5:3118045d33a2 | 255 | |
misha83 | 5:3118045d33a2 | 256 | printf("numbers:\n"); |
misha83 | 5:3118045d33a2 | 257 | while (!feof(f)) { |
misha83 | 5:3118045d33a2 | 258 | int c = fgetc(f); |
misha83 | 5:3118045d33a2 | 259 | printf("%c", c); |
misha83 | 5:3118045d33a2 | 260 | } |
misha83 | 5:3118045d33a2 | 261 | |
misha83 | 5:3118045d33a2 | 262 | printf("\rClosing \"/fs/numbers.txt\"... "); |
misha83 | 5:3118045d33a2 | 263 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 264 | err = fclose(f); |
misha83 | 5:3118045d33a2 | 265 | printf("%s\n", (err < 0 ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 266 | if (err < 0) { |
misha83 | 5:3118045d33a2 | 267 | error("error: %s (%d)\n", strerror(errno), -errno); |
misha83 | 5:3118045d33a2 | 268 | } |
misha83 | 5:3118045d33a2 | 269 | |
misha83 | 5:3118045d33a2 | 270 | // Tidy up |
misha83 | 5:3118045d33a2 | 271 | printf("Unmounting... "); |
misha83 | 5:3118045d33a2 | 272 | fflush(stdout); |
misha83 | 5:3118045d33a2 | 273 | err = fs.unmount(); |
misha83 | 5:3118045d33a2 | 274 | printf("%s\n", (err < 0 ? "Fail :(" : "OK")); |
misha83 | 5:3118045d33a2 | 275 | if (err < 0) { |
misha83 | 5:3118045d33a2 | 276 | error("error: %s (%d)\n", strerror(-err), err); |
misha83 | 5:3118045d33a2 | 277 | } |
misha83 | 5:3118045d33a2 | 278 | |
misha83 | 5:3118045d33a2 | 279 | printf("Mbed OS filesystem example done!\n"); |
misha83 | 5:3118045d33a2 | 280 | } |
misha83 | 5:3118045d33a2 | 281 | |
misha83 | 5:3118045d33a2 | 282 | |
misha83 | 5:3118045d33a2 | 283 | |
misha83 | 5:3118045d33a2 | 284 | |
misha83 | 5:3118045d33a2 | 285 | |
misha83 | 5:3118045d33a2 | 286 | |
misha83 | 5:3118045d33a2 | 287 | DigitalIn mypin(BUTTON1); |
misha83 | 5:3118045d33a2 | 288 | void button_test(void) |
misha83 | 5:3118045d33a2 | 289 | { |
misha83 | 5:3118045d33a2 | 290 | int stat=0, butinf; |
misha83 | 5:3118045d33a2 | 291 | |
misha83 | 5:3118045d33a2 | 292 | mypin.mode(PullNone); |
misha83 | 5:3118045d33a2 | 293 | |
misha83 | 5:3118045d33a2 | 294 | while(1) |
misha83 | 5:3118045d33a2 | 295 | { |
misha83 | 5:3118045d33a2 | 296 | |
misha83 | 5:3118045d33a2 | 297 | butinf = mypin.read(); |
misha83 | 5:3118045d33a2 | 298 | if(stat==0 && butinf==1){ |
misha83 | 5:3118045d33a2 | 299 | stat = 1; |
misha83 | 5:3118045d33a2 | 300 | led3=!led3; |
misha83 | 5:3118045d33a2 | 301 | printf("button presed \n\r"); |
misha83 | 5:3118045d33a2 | 302 | |
misha83 | 5:3118045d33a2 | 303 | //erase(); |
misha83 | 5:3118045d33a2 | 304 | mount(); |
misha83 | 5:3118045d33a2 | 305 | |
misha83 | 5:3118045d33a2 | 306 | |
misha83 | 5:3118045d33a2 | 307 | }else{ |
misha83 | 5:3118045d33a2 | 308 | if(butinf==0){stat=0;} |
misha83 | 5:3118045d33a2 | 309 | } |
misha83 | 5:3118045d33a2 | 310 | |
misha83 | 5:3118045d33a2 | 311 | ThisThread::sleep_for(10); |
misha83 | 5:3118045d33a2 | 312 | } |
misha83 | 5:3118045d33a2 | 313 | // mtx.lock(); |
misha83 | 5:3118045d33a2 | 314 | // led3=!led3; |
misha83 | 5:3118045d33a2 | 315 | // mtx.unlock(); |
misha83 | 5:3118045d33a2 | 316 | } |
misha83 | 5:3118045d33a2 | 317 | |
misha83 | 5:3118045d33a2 | 318 | |
misha83 | 5:3118045d33a2 | 319 | |
misha83 | 5:3118045d33a2 | 320 | |
misha83 | 0:172fd6ff0022 | 321 | int main() |
misha83 | 0:172fd6ff0022 | 322 | { |
misha83 | 1:a2323b3606ab | 323 | |
misha83 | 1:a2323b3606ab | 324 | bool st=false; |
misha83 | 0:172fd6ff0022 | 325 | led1 = 1; |
misha83 | 0:172fd6ff0022 | 326 | led2 = 1; |
misha83 | 5:3118045d33a2 | 327 | uint32_t flags_read = 0; |
misha83 | 0:172fd6ff0022 | 328 | |
misha83 | 5:3118045d33a2 | 329 | char buffer[50]; |
misha83 | 5:3118045d33a2 | 330 | int c = 0; |
misha83 | 1:a2323b3606ab | 331 | |
misha83 | 5:3118045d33a2 | 332 | printf("start mbed TEST START \n\r"); |
misha83 | 5:3118045d33a2 | 333 | |
misha83 | 5:3118045d33a2 | 334 | |
misha83 | 0:172fd6ff0022 | 335 | |
misha83 | 1:a2323b3606ab | 336 | thread.start(test_flag); |
misha83 | 5:3118045d33a2 | 337 | led_thread.start(led_th); |
misha83 | 5:3118045d33a2 | 338 | queue_thread.start(q_thread); |
misha83 | 5:3118045d33a2 | 339 | button_thread.start(button_test); |
misha83 | 1:a2323b3606ab | 340 | |
misha83 | 1:a2323b3606ab | 341 | |
misha83 | 1:a2323b3606ab | 342 | |
misha83 | 1:a2323b3606ab | 343 | //lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); |
misha83 | 1:a2323b3606ab | 344 | //ThisThread::sleep_for(1); |
misha83 | 0:172fd6ff0022 | 345 | |
misha83 | 1:a2323b3606ab | 346 | |
misha83 | 1:a2323b3606ab | 347 | |
misha83 | 1:a2323b3606ab | 348 | |
misha83 | 1:a2323b3606ab | 349 | lcd.Clear(LCD_COLOR_BLUE); |
misha83 | 1:a2323b3606ab | 350 | lcd.SetBackColor(LCD_COLOR_BLUE); |
misha83 | 1:a2323b3606ab | 351 | |
misha83 | 1:a2323b3606ab | 352 | |
misha83 | 1:a2323b3606ab | 353 | |
misha83 | 0:172fd6ff0022 | 354 | while(1) |
misha83 | 0:172fd6ff0022 | 355 | { |
misha83 | 1:a2323b3606ab | 356 | |
misha83 | 1:a2323b3606ab | 357 | flags_read = event_flags.wait_any(SAMPLE_FLAG1, 10); |
misha83 | 1:a2323b3606ab | 358 | |
misha83 | 1:a2323b3606ab | 359 | if(flags_read&SAMPLE_FLAG1){ |
misha83 | 1:a2323b3606ab | 360 | //lcd.Clear(LCD_COLOR_BLUE); |
misha83 | 1:a2323b3606ab | 361 | |
misha83 | 1:a2323b3606ab | 362 | if(st){ |
misha83 | 1:a2323b3606ab | 363 | lcd.SetTextColor(LCD_COLOR_WHITE); |
misha83 | 1:a2323b3606ab | 364 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"FLAG 0 SET EVERY 1 SEC", LEFT_MODE); |
misha83 | 1:a2323b3606ab | 365 | }else{ |
misha83 | 1:a2323b3606ab | 366 | lcd.SetTextColor(LCD_COLOR_DARKRED); |
misha83 | 1:a2323b3606ab | 367 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"FLAG 0 SET EVERY 1 SEC", LEFT_MODE); |
misha83 | 1:a2323b3606ab | 368 | |
misha83 | 1:a2323b3606ab | 369 | } |
misha83 | 1:a2323b3606ab | 370 | st=!st; |
misha83 | 1:a2323b3606ab | 371 | } |
misha83 | 1:a2323b3606ab | 372 | |
misha83 | 1:a2323b3606ab | 373 | |
misha83 | 1:a2323b3606ab | 374 | |
misha83 | 1:a2323b3606ab | 375 | osEvent evt = queue.get(10); |
misha83 | 1:a2323b3606ab | 376 | if (evt.status == osEventMessage) { |
misha83 | 1:a2323b3606ab | 377 | message_t *message = (message_t *)evt.value.p; |
misha83 | 1:a2323b3606ab | 378 | |
misha83 | 1:a2323b3606ab | 379 | c++; |
misha83 | 1:a2323b3606ab | 380 | sprintf(buffer, "queue message counter: %d", c); |
misha83 | 1:a2323b3606ab | 381 | lcd.SetTextColor(LCD_COLOR_ORANGE); |
misha83 | 1:a2323b3606ab | 382 | lcd.DisplayStringAt(0, LINE(4), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 383 | |
misha83 | 1:a2323b3606ab | 384 | sprintf(buffer, "Voltage: %d", message->voltage); |
misha83 | 1:a2323b3606ab | 385 | lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); |
misha83 | 1:a2323b3606ab | 386 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 387 | |
misha83 | 1:a2323b3606ab | 388 | sprintf(buffer, "Current: %d", message->current); |
misha83 | 1:a2323b3606ab | 389 | lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); |
misha83 | 1:a2323b3606ab | 390 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 391 | |
misha83 | 1:a2323b3606ab | 392 | sprintf(buffer, "Counter: %d", message->counter); |
misha83 | 1:a2323b3606ab | 393 | lcd.SetTextColor(LCD_COLOR_LIGHTGREEN); |
misha83 | 1:a2323b3606ab | 394 | lcd.DisplayStringAt(0, LINE(7), (uint8_t *)buffer, LEFT_MODE); |
misha83 | 1:a2323b3606ab | 395 | |
misha83 | 1:a2323b3606ab | 396 | |
misha83 | 1:a2323b3606ab | 397 | mpool.free(message); |
misha83 | 1:a2323b3606ab | 398 | } |
misha83 | 1:a2323b3606ab | 399 | |
misha83 | 1:a2323b3606ab | 400 | |
misha83 | 1:a2323b3606ab | 401 | |
misha83 | 1:a2323b3606ab | 402 | |
misha83 | 1:a2323b3606ab | 403 | /* |
misha83 | 0:172fd6ff0022 | 404 | lcd.Clear(LCD_COLOR_BLUE); |
misha83 | 0:172fd6ff0022 | 405 | lcd.SetBackColor(LCD_COLOR_BLUE); |
misha83 | 0:172fd6ff0022 | 406 | lcd.SetTextColor(LCD_COLOR_WHITE); |
misha83 | 0:172fd6ff0022 | 407 | ThisThread::sleep_for(300); |
misha83 | 0:172fd6ff0022 | 408 | lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY", CENTER_MODE); |
misha83 | 0:172fd6ff0022 | 409 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F469NI", CENTER_MODE); |
misha83 | 0:172fd6ff0022 | 410 | ThisThread::sleep_for(1000); |
misha83 | 0:172fd6ff0022 | 411 | |
misha83 | 0:172fd6ff0022 | 412 | lcd.Clear(LCD_COLOR_GREEN); |
misha83 | 0:172fd6ff0022 | 413 | |
misha83 | 0:172fd6ff0022 | 414 | lcd.SetTextColor(LCD_COLOR_BLUE); |
misha83 | 0:172fd6ff0022 | 415 | lcd.FillRect(10, 20, 50, 50); |
misha83 | 0:172fd6ff0022 | 416 | ThisThread::sleep_for(100); |
misha83 | 0:172fd6ff0022 | 417 | lcd.SetTextColor(LCD_COLOR_BROWN); |
misha83 | 0:172fd6ff0022 | 418 | lcd.FillCircle(80, 80, 50); |
misha83 | 0:172fd6ff0022 | 419 | ThisThread::sleep_for(100); |
misha83 | 0:172fd6ff0022 | 420 | lcd.SetTextColor(LCD_COLOR_YELLOW); |
misha83 | 0:172fd6ff0022 | 421 | lcd.FillEllipse(150, 150, 50, 100); |
misha83 | 0:172fd6ff0022 | 422 | ThisThread::sleep_for(100); |
misha83 | 0:172fd6ff0022 | 423 | lcd.SetTextColor(LCD_COLOR_RED); |
misha83 | 0:172fd6ff0022 | 424 | lcd.FillCircle(200, 200, 40); |
misha83 | 0:172fd6ff0022 | 425 | ThisThread::sleep_for(1000); |
misha83 | 0:172fd6ff0022 | 426 | |
misha83 | 0:172fd6ff0022 | 427 | lcd.SetBackColor(LCD_COLOR_ORANGE); |
misha83 | 0:172fd6ff0022 | 428 | lcd.SetTextColor(LCD_COLOR_CYAN); |
misha83 | 0:172fd6ff0022 | 429 | BSP_LCD_SetFont(&Font20); |
misha83 | 0:172fd6ff0022 | 430 | lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); |
misha83 | 0:172fd6ff0022 | 431 | ThisThread::sleep_for(1000); |
misha83 | 0:172fd6ff0022 | 432 | |
misha83 | 0:172fd6ff0022 | 433 | led1 = !led1; |
misha83 | 0:172fd6ff0022 | 434 | ThisThread::sleep_for(500); |
misha83 | 1:a2323b3606ab | 435 | */ |
misha83 | 0:172fd6ff0022 | 436 | } |
misha83 | 0:172fd6ff0022 | 437 | } |
misha83 | 0:172fd6ff0022 | 438 |