DA14580 Bluetooth Smart IC writer library
Dependents: 11u35_usbLocalFilesystem
Revision 9:e2e84de053fc, committed 2016-08-12
- Comitter:
- k4zuki
- Date:
- Fri Aug 12 06:34:58 2016 +0000
- Parent:
- 8:af5210dbfe64
- Commit message:
- load() handles filename
Changed in this revision
DA14580.cpp | Show annotated file Show diff for this revision Revisions of this file |
DA14580.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r af5210dbfe64 -r e2e84de053fc DA14580.cpp --- a/DA14580.cpp Thu Jul 07 01:26:52 2016 +0000 +++ b/DA14580.cpp Fri Aug 12 06:34:58 2016 +0000 @@ -1,7 +1,6 @@ /* @file DA14580.cpp */ -//#include "mbed.h" #include "DA14580.h" #include "loader.h" @@ -25,7 +24,8 @@ { _reset.write(_RESET); - _loadersize = sizeof(loader)/sizeof(loader[0]); +// _loadersize = sizeof(loader)/sizeof(loader[0]); + _loadersize = 0; _crc = 0x00; _recieve = 0; _read = 0; @@ -35,19 +35,21 @@ _status = SUCCESS; } -int DA14580::load() +int DA14580::load(char *filename) { _reset.write(_RESET); _status = SUCCESS; -/* - _fp = fopen(TARGET_FILE, "r" ); + + _fp = fopen(filename, "rb" ); if (_fp) { - _filesize = file_size(_fp); + _loadersize = file_size(_fp); + } else if( (!_fp) && (filename == LOADER_FILE) ){ + _fp = (FILE*) loader; } else { _status = E_FILE_NOT_FOUND; } -*/ + if(_status == SUCCESS) { _reset.write(_BOOT); wait_us(1); @@ -75,7 +77,7 @@ if(_status == SUCCESS) { for(int i = 0; i < _loadersize; i++) { - _read = loader[i]; + _read = getc(_fp); _ble.putc(_read); _crc = _crc ^ _read; } @@ -91,13 +93,13 @@ } } } -/* + fclose(_fp); #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler #warning "free(_fp)" free(_fp); #endif -*/ + return _status; }
diff -r af5210dbfe64 -r e2e84de053fc DA14580.h --- a/DA14580.h Thu Jul 07 01:26:52 2016 +0000 +++ b/DA14580.h Fri Aug 12 06:34:58 2016 +0000 @@ -75,12 +75,18 @@ @param E_CRC_MISMATCH = '5' */ enum DA14580_STATUS { - SUCCESS = '0', - E_NOT_CONNECTED = '1', - E_FILE_NOT_FOUND = '2', - E_TIMEOUT_STX = '3', - E_ACK_NOT_RETURNED = '4', - E_CRC_MISMATCH = '5' +// SUCCESS = '0', +// E_NOT_CONNECTED = '1', +// E_FILE_NOT_FOUND = '2', +// E_TIMEOUT_STX = '3', +// E_ACK_NOT_RETURNED = '4', +// E_CRC_MISMATCH = '5' + SUCCESS = 0, + E_NOT_CONNECTED = 1, + E_FILE_NOT_FOUND = 2, + E_TIMEOUT_STX = 3, + E_ACK_NOT_RETURNED = 4, + E_CRC_MISMATCH = 5 }; /** Constructor @@ -111,7 +117,7 @@ /** Load bootloader executable into device through UART * the target binary should be defined by LOADER_FILE */ - int load(); + int load(char *filename = LOADER_FILE); /** Returns file size: copied from ika_shouyu_poppoyaki * @param *fp File pointer