Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 1TEST_Flight_Protocol by
eeprom.h@0:c466d770ffa7, 2017-05-17 (annotated)
- Committer:
- skyyoungsik
- Date:
- Wed May 17 11:02:27 2017 +0000
- Revision:
- 0:c466d770ffa7
test1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skyyoungsik | 0:c466d770ffa7 | 1 | #define eeprom_length 256 |
skyyoungsik | 0:c466d770ffa7 | 2 | |
skyyoungsik | 0:c466d770ffa7 | 3 | |
skyyoungsik | 0:c466d770ffa7 | 4 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
skyyoungsik | 0:c466d770ffa7 | 5 | |
skyyoungsik | 0:c466d770ffa7 | 6 | volatile int eeprom_address[eeprom_length],eeprom_data[eeprom_length]; |
skyyoungsik | 0:c466d770ffa7 | 7 | void eeprom_init(){ |
skyyoungsik | 0:c466d770ffa7 | 8 | FILE *file = fopen("/local/eeprom.txt", "r"); // Open "out.txt" on the local file system for writing |
skyyoungsik | 0:c466d770ffa7 | 9 | if(file == NULL){ |
skyyoungsik | 0:c466d770ffa7 | 10 | FILE *file = fopen("/local/eeprom.txt", "w"); // Write "out.txt ~~// |
skyyoungsik | 0:c466d770ffa7 | 11 | for(int i=0; i<eeprom_length; i++){ |
skyyoungsik | 0:c466d770ffa7 | 12 | fprintf(file, "%d\t%d\r\n", i, 0); |
skyyoungsik | 0:c466d770ffa7 | 13 | } |
skyyoungsik | 0:c466d770ffa7 | 14 | fclose(file); |
skyyoungsik | 0:c466d770ffa7 | 15 | }else{ |
skyyoungsik | 0:c466d770ffa7 | 16 | for(int i=0; i<eeprom_length; i++) {eeprom_address[i] = 0; eeprom_data[i] = 0; } |
skyyoungsik | 0:c466d770ffa7 | 17 | for(int i=0; i<eeprom_length; i++){ |
skyyoungsik | 0:c466d770ffa7 | 18 | fscanf(file,"%d\t%d\r\n",&eeprom_address[i], &eeprom_data[i]); |
skyyoungsik | 0:c466d770ffa7 | 19 | } |
skyyoungsik | 0:c466d770ffa7 | 20 | } |
skyyoungsik | 0:c466d770ffa7 | 21 | fclose(file); |
skyyoungsik | 0:c466d770ffa7 | 22 | } |
skyyoungsik | 0:c466d770ffa7 | 23 | |
skyyoungsik | 0:c466d770ffa7 | 24 | void eeprom_refresh(){ |
skyyoungsik | 0:c466d770ffa7 | 25 | /// Write Data to EEPROM // |
skyyoungsik | 0:c466d770ffa7 | 26 | FILE *file = fopen("/local/eeprom.txt", "w"); // Open "out.txt" on the local file system for writing |
skyyoungsik | 0:c466d770ffa7 | 27 | for(int i=0; i<eeprom_length; i++){ |
skyyoungsik | 0:c466d770ffa7 | 28 | fprintf(file,"%d\t%d\r\n",i, eeprom_data[i]); |
skyyoungsik | 0:c466d770ffa7 | 29 | } |
skyyoungsik | 0:c466d770ffa7 | 30 | fclose(file); |
skyyoungsik | 0:c466d770ffa7 | 31 | } |
skyyoungsik | 0:c466d770ffa7 | 32 | |
skyyoungsik | 0:c466d770ffa7 | 33 | void eeprom_write(int addr, int data){ |
skyyoungsik | 0:c466d770ffa7 | 34 | /// Change Data // |
skyyoungsik | 0:c466d770ffa7 | 35 | eeprom_data[addr] = data; |
skyyoungsik | 0:c466d770ffa7 | 36 | } |
skyyoungsik | 0:c466d770ffa7 | 37 | |
skyyoungsik | 0:c466d770ffa7 | 38 | |
skyyoungsik | 0:c466d770ffa7 | 39 | int eeprom_read(int addr){ |
skyyoungsik | 0:c466d770ffa7 | 40 | return eeprom_data[addr]; |
skyyoungsik | 0:c466d770ffa7 | 41 | |
skyyoungsik | 0:c466d770ffa7 | 42 | } |
skyyoungsik | 0:c466d770ffa7 | 43 | |
skyyoungsik | 0:c466d770ffa7 | 44 | void eeprom_reset(){ |
skyyoungsik | 0:c466d770ffa7 | 45 | FILE *file = fopen("/local/eeprom.txt", "w"); // Open "out.txt" on the local file system for writing |
skyyoungsik | 0:c466d770ffa7 | 46 | for(int i=0; i<256; i++){ |
skyyoungsik | 0:c466d770ffa7 | 47 | fprintf(file, "%d\t%d\r\n", i,0); |
skyyoungsik | 0:c466d770ffa7 | 48 | } |
skyyoungsik | 0:c466d770ffa7 | 49 | fclose(file); |
skyyoungsik | 0:c466d770ffa7 | 50 | } |