Nikolai Trushnikov
/
FlashExample
rwiteandread
main.cpp@0:c2e4e593b284, 2020-06-25 (annotated)
- Committer:
- nikmaos
- Date:
- Thu Jun 25 10:22:06 2020 +0000
- Revision:
- 0:c2e4e593b284
Structure writing and reading.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikmaos | 0:c2e4e593b284 | 1 | #include "mbed.h" |
nikmaos | 0:c2e4e593b284 | 2 | #include "flashwrapper.h" |
nikmaos | 0:c2e4e593b284 | 3 | |
nikmaos | 0:c2e4e593b284 | 4 | int main() |
nikmaos | 0:c2e4e593b284 | 5 | { |
nikmaos | 0:c2e4e593b284 | 6 | typedef struct |
nikmaos | 0:c2e4e593b284 | 7 | { |
nikmaos | 0:c2e4e593b284 | 8 | float a; |
nikmaos | 0:c2e4e593b284 | 9 | uint32_t b; |
nikmaos | 0:c2e4e593b284 | 10 | uint16_t c; |
nikmaos | 0:c2e4e593b284 | 11 | uint8_t d; |
nikmaos | 0:c2e4e593b284 | 12 | }bab_t; |
nikmaos | 0:c2e4e593b284 | 13 | |
nikmaos | 0:c2e4e593b284 | 14 | char q=sizeof(bab_t)/sizeof(uint32_t); |
nikmaos | 0:c2e4e593b284 | 15 | typedef union { |
nikmaos | 0:c2e4e593b284 | 16 | bab_t a; |
nikmaos | 0:c2e4e593b284 | 17 | uint32_t b[sizeof(bab_t)/sizeof(uint32_t)/*+другие структуры так же*/]; |
nikmaos | 0:c2e4e593b284 | 18 | }RW_t; |
nikmaos | 0:c2e4e593b284 | 19 | |
nikmaos | 0:c2e4e593b284 | 20 | RW_t bufer; |
nikmaos | 0:c2e4e593b284 | 21 | |
nikmaos | 0:c2e4e593b284 | 22 | bufer.a.a=0.67; |
nikmaos | 0:c2e4e593b284 | 23 | bufer.a.b=5000000; |
nikmaos | 0:c2e4e593b284 | 24 | bufer.a.c=60000; |
nikmaos | 0:c2e4e593b284 | 25 | bufer.a.d=150; |
nikmaos | 0:c2e4e593b284 | 26 | |
nikmaos | 0:c2e4e593b284 | 27 | flashWrite(0,bufer.b,q); |
nikmaos | 0:c2e4e593b284 | 28 | for(int i=0;i<q;i++) |
nikmaos | 0:c2e4e593b284 | 29 | {bufer.b[i]=flashRead(i*4);} |
nikmaos | 0:c2e4e593b284 | 30 | |
nikmaos | 0:c2e4e593b284 | 31 | printf("Value = %f\r\n",bufer.a.a); |
nikmaos | 0:c2e4e593b284 | 32 | printf("Value = %d\r\n",bufer.a.b); |
nikmaos | 0:c2e4e593b284 | 33 | printf("Value = %d\r\n",bufer.a.c); |
nikmaos | 0:c2e4e593b284 | 34 | printf("Value = %d\r\n",bufer.a.d); |
nikmaos | 0:c2e4e593b284 | 35 | |
nikmaos | 0:c2e4e593b284 | 36 | |
nikmaos | 0:c2e4e593b284 | 37 | } |