UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]
Dependencies: mbed SDFileSystem
main.cpp@6:81a3d517fd56, 2019-05-09 (annotated)
- Committer:
- Inscape_ao
- Date:
- Thu May 09 00:06:21 2019 +0000
- Revision:
- 6:81a3d517fd56
- Parent:
- 5:a37e3a15444b
- Child:
- 7:9ab8809f9693
2019-05-08_small-changed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Inscape_ao | 0:c347f602596d | 1 | /** --- Includes --- */ |
Inscape_ao | 0:c347f602596d | 2 | #include "mbed.h" |
Inscape_ao | 2:a694440145e9 | 3 | #include "SDFileSystem.h" |
Inscape_ao | 2:a694440145e9 | 4 | #include "TimeManager.h" |
Inscape_ao | 0:c347f602596d | 5 | #include "UartReceiver.h" |
Inscape_ao | 0:c347f602596d | 6 | #include "CommandParser.h" |
Inscape_ao | 5:a37e3a15444b | 7 | #include "SDDataStore.h" |
Inscape_ao | 0:c347f602596d | 8 | #include "global.h" |
Inscape_ao | 0:c347f602596d | 9 | #include "string.h" |
Inscape_ao | 0:c347f602596d | 10 | |
Inscape_ao | 0:c347f602596d | 11 | /** --- Global Variables --- */ |
Inscape_ao | 0:c347f602596d | 12 | Serial pc(SERIAL_TX, SERIAL_RX); |
Inscape_ao | 0:c347f602596d | 13 | DigitalOut myled(LED1); |
Inscape_ao | 1:71c9c97c9f3d | 14 | |
Inscape_ao | 6:81a3d517fd56 | 15 | #if 0 |
Inscape_ao | 6:81a3d517fd56 | 16 | SPI spiSield(D11, D12, D13); |
Inscape_ao | 6:81a3d517fd56 | 17 | DigitalOut csSield(D10); |
Inscape_ao | 6:81a3d517fd56 | 18 | |
Inscape_ao | 6:81a3d517fd56 | 19 | static void test(void) |
Inscape_ao | 6:81a3d517fd56 | 20 | { |
Inscape_ao | 6:81a3d517fd56 | 21 | int val; |
Inscape_ao | 6:81a3d517fd56 | 22 | /* spiSield 8bit/mode=3 */ |
Inscape_ao | 6:81a3d517fd56 | 23 | spiSield.format(8, 3); |
Inscape_ao | 6:81a3d517fd56 | 24 | spiSield.frequency(400000); |
Inscape_ao | 6:81a3d517fd56 | 25 | csSield = 1; |
Inscape_ao | 6:81a3d517fd56 | 26 | wait(0.5); |
Inscape_ao | 6:81a3d517fd56 | 27 | pc.printf("test"); |
Inscape_ao | 6:81a3d517fd56 | 28 | csSield = 0; |
Inscape_ao | 6:81a3d517fd56 | 29 | /* set Communication Register */ |
Inscape_ao | 6:81a3d517fd56 | 30 | /* /WEN=0, R/W=1, RS=100, CREAD=0, reserved=0 */ |
Inscape_ao | 6:81a3d517fd56 | 31 | spiSield.write(0x60); |
Inscape_ao | 6:81a3d517fd56 | 32 | /* get ID Register */ |
Inscape_ao | 6:81a3d517fd56 | 33 | /* /WEN=0, R/W=1, RS=100, CREAD=0, reserved=0 */ |
Inscape_ao | 6:81a3d517fd56 | 34 | val = spiSield.write(0x00); |
Inscape_ao | 6:81a3d517fd56 | 35 | csSield = 1; |
Inscape_ao | 6:81a3d517fd56 | 36 | pc.printf("(ID=0x%x)\n", val); |
Inscape_ao | 6:81a3d517fd56 | 37 | } |
Inscape_ao | 6:81a3d517fd56 | 38 | #endif |
Inscape_ao | 6:81a3d517fd56 | 39 | |
Inscape_ao | 0:c347f602596d | 40 | /** --- main --- */ |
Inscape_ao | 0:c347f602596d | 41 | int main() |
Inscape_ao | 0:c347f602596d | 42 | { |
Inscape_ao | 0:c347f602596d | 43 | /** UART Initalizer */ |
Inscape_ao | 0:c347f602596d | 44 | /* setup UART 115200, 8bit, Parity=None, stopbit:1bit */ |
Inscape_ao | 0:c347f602596d | 45 | /* https://os.mbed.com/users/okini3939/notebook/Serial_jp/ */ |
Inscape_ao | 0:c347f602596d | 46 | pc.baud(115200); |
Inscape_ao | 0:c347f602596d | 47 | pc.format(8, Serial::None, 1); |
Inscape_ao | 0:c347f602596d | 48 | |
Inscape_ao | 6:81a3d517fd56 | 49 | //test(); |
Inscape_ao | 6:81a3d517fd56 | 50 | |
Inscape_ao | 2:a694440145e9 | 51 | /* new timer manager */ |
Inscape_ao | 2:a694440145e9 | 52 | pTM = new TimeManager(); |
Inscape_ao | 5:a37e3a15444b | 53 | /* Generate SDDataStore */ |
Inscape_ao | 5:a37e3a15444b | 54 | pSds = new SDDataStore(pTM); |
Inscape_ao | 0:c347f602596d | 55 | /* Receive Buffer Control */ |
Inscape_ao | 0:c347f602596d | 56 | pUR = new UartReceiver(&pc); |
Inscape_ao | 0:c347f602596d | 57 | /* Generate Command parser as DeviceID = 0, ParsingRule = rules */ |
Inscape_ao | 2:a694440145e9 | 58 | pCP = new CommandParser(pUR, 0, rules, getNumOfRules); |
Inscape_ao | 0:c347f602596d | 59 | pCP->run(); |
Inscape_ao | 6:81a3d517fd56 | 60 | |
Inscape_ao | 0:c347f602596d | 61 | pc.printf("Hello World !\n"); |
Inscape_ao | 4:bec3f80dc49c | 62 | |
Inscape_ao | 0:c347f602596d | 63 | while(1) { |
Inscape_ao | 0:c347f602596d | 64 | wait(1); |
Inscape_ao | 0:c347f602596d | 65 | } |
Inscape_ao | 0:c347f602596d | 66 | } |