This is library for storing data array in internal flash memory of MCU LPC1768. The flash data is empty every time we download program to MCU so it can be used in project where we don't have acces to file system like mbed development board uses.
Dependencies: IAP
Flash.cpp@0:0414cef3e9d6, 2017-01-15 (annotated)
- Committer:
- bosko1523
- Date:
- Sun Jan 15 20:37:39 2017 +0000
- Revision:
- 0:0414cef3e9d6
This is library for storing data array in internal flash memory of MCU LPC1768. The flash data is empty every time we download program to MCU so it can be used in project where we don't have acces to file system like mbed development board uses.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko1523 | 0:0414cef3e9d6 | 1 | #include "Flash.h" |
bosko1523 | 0:0414cef3e9d6 | 2 | |
bosko1523 | 0:0414cef3e9d6 | 3 | Flash::Flash() { |
bosko1523 | 0:0414cef3e9d6 | 4 | |
bosko1523 | 0:0414cef3e9d6 | 5 | } |
bosko1523 | 0:0414cef3e9d6 | 6 | |
bosko1523 | 0:0414cef3e9d6 | 7 | void Flash::writeFlash(char data[MEM_SIZE]) { |
bosko1523 | 0:0414cef3e9d6 | 8 | __disable_irq(); |
bosko1523 | 0:0414cef3e9d6 | 9 | |
bosko1523 | 0:0414cef3e9d6 | 10 | // varijabla za spremanje odgovora |
bosko1523 | 0:0414cef3e9d6 | 11 | int r; |
bosko1523 | 0:0414cef3e9d6 | 12 | // provijera ako je sektor flasha prazan, nakon svakog novog programiranja se flash prazni |
bosko1523 | 0:0414cef3e9d6 | 13 | r = iap.blank_check(TARGET_SECTOR, TARGET_SECTOR); |
bosko1523 | 0:0414cef3e9d6 | 14 | // brisanje sektora ako je potrebno |
bosko1523 | 0:0414cef3e9d6 | 15 | if (r == SECTOR_NOT_BLANK) { |
bosko1523 | 0:0414cef3e9d6 | 16 | iap.prepare(TARGET_SECTOR, TARGET_SECTOR); |
bosko1523 | 0:0414cef3e9d6 | 17 | r = iap.erase(TARGET_SECTOR, TARGET_SECTOR); |
bosko1523 | 0:0414cef3e9d6 | 18 | } |
bosko1523 | 0:0414cef3e9d6 | 19 | // pisanje podataka u memoriju |
bosko1523 | 0:0414cef3e9d6 | 20 | iap.prepare(TARGET_SECTOR, TARGET_SECTOR); |
bosko1523 | 0:0414cef3e9d6 | 21 | iap.write(data, sector_start_adress[TARGET_SECTOR], MEM_SIZE); |
bosko1523 | 0:0414cef3e9d6 | 22 | |
bosko1523 | 0:0414cef3e9d6 | 23 | __enable_irq(); |
bosko1523 | 0:0414cef3e9d6 | 24 | } |
bosko1523 | 0:0414cef3e9d6 | 25 | |
bosko1523 | 0:0414cef3e9d6 | 26 | void Flash::readFlash(char *data) { |
bosko1523 | 0:0414cef3e9d6 | 27 | __disable_irq(); |
bosko1523 | 0:0414cef3e9d6 | 28 | |
bosko1523 | 0:0414cef3e9d6 | 29 | memcpy(data, sector_start_adress[TARGET_SECTOR], MEM_SIZE); |
bosko1523 | 0:0414cef3e9d6 | 30 | |
bosko1523 | 0:0414cef3e9d6 | 31 | __enable_irq(); |
bosko1523 | 0:0414cef3e9d6 | 32 | } |