![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Proswift with BLE EV-BL652ARDZ
Fork of ADISense1000_Example_FW by
main.cpp@1:25a2bf666957, 2018-08-24 (annotated)
- Committer:
- nfathurr
- Date:
- Fri Aug 24 08:58:48 2018 +0000
- Revision:
- 1:25a2bf666957
- Parent:
- 0:76fed7dd9235
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seanwilson10 | 0:76fed7dd9235 | 1 | /* |
seanwilson10 | 0:76fed7dd9235 | 2 | ****************************************************************************** |
seanwilson10 | 0:76fed7dd9235 | 3 | * file: main.cpp |
seanwilson10 | 0:76fed7dd9235 | 4 | *----------------------------------------------------------------------------- |
seanwilson10 | 0:76fed7dd9235 | 5 | *****************************************************************************/ |
seanwilson10 | 0:76fed7dd9235 | 6 | #include "mbed.h" |
seanwilson10 | 0:76fed7dd9235 | 7 | #include "inc/adi_sense_api.h" |
seanwilson10 | 0:76fed7dd9235 | 8 | #include "inc/adi_sense_log.h" |
seanwilson10 | 0:76fed7dd9235 | 9 | #include "common/utils.h" |
seanwilson10 | 0:76fed7dd9235 | 10 | |
nfathurr | 1:25a2bf666957 | 11 | //additional libraries |
nfathurr | 1:25a2bf666957 | 12 | #include "adisense1000_boot.h" |
nfathurr | 1:25a2bf666957 | 13 | #include "ble_interface/ble_interface.h" |
nfathurr | 1:25a2bf666957 | 14 | #include "myproswift_eval.h" |
nfathurr | 1:25a2bf666957 | 15 | #include "eeprom_virtual/eeprom.h" |
nfathurr | 1:25a2bf666957 | 16 | #include "myproswift_periph.h" |
nfathurr | 1:25a2bf666957 | 17 | #include "led.h" |
nfathurr | 1:25a2bf666957 | 18 | #include "bootloader.h" |
nfathurr | 1:25a2bf666957 | 19 | #include "rcc_backup_registers.h" |
seanwilson10 | 0:76fed7dd9235 | 20 | |
nfathurr | 1:25a2bf666957 | 21 | #ifdef BL652 |
nfathurr | 1:25a2bf666957 | 22 | #include "ble_interface/bl652.h" |
nfathurr | 1:25a2bf666957 | 23 | #endif |
seanwilson10 | 0:76fed7dd9235 | 24 | |
nfathurr | 1:25a2bf666957 | 25 | |
nfathurr | 1:25a2bf666957 | 26 | int main( void ) |
seanwilson10 | 0:76fed7dd9235 | 27 | { |
nfathurr | 1:25a2bf666957 | 28 | int ret = 1; |
nfathurr | 1:25a2bf666957 | 29 | bool bleActive; |
nfathurr | 1:25a2bf666957 | 30 | |
nfathurr | 1:25a2bf666957 | 31 | // Indicate device is booting |
nfathurr | 1:25a2bf666957 | 32 | Led_Boot(); |
nfathurr | 1:25a2bf666957 | 33 | |
nfathurr | 1:25a2bf666957 | 34 | // Check if device needs to enter bootloader function, this is set via a PC command |
nfathurr | 1:25a2bf666957 | 35 | // Flag is stored in RTC registers that persist while vbat is powered |
nfathurr | 1:25a2bf666957 | 36 | bool_t bBootLoader = Rcc_ReadBackupReg( BOOTLOADER_FLAG_BACKUP_REG ) == 1 ? true : false; |
nfathurr | 1:25a2bf666957 | 37 | if( bBootLoader ) { |
nfathurr | 1:25a2bf666957 | 38 | |
nfathurr | 1:25a2bf666957 | 39 | // Let user know device is entering bootloader mode |
nfathurr | 1:25a2bf666957 | 40 | Pc_ResetSuccess( bBootLoader ); |
nfathurr | 1:25a2bf666957 | 41 | |
nfathurr | 1:25a2bf666957 | 42 | // Jump to bootloader |
nfathurr | 1:25a2bf666957 | 43 | Bootloader_Init(); |
seanwilson10 | 0:76fed7dd9235 | 44 | } |
nfathurr | 1:25a2bf666957 | 45 | |
nfathurr | 1:25a2bf666957 | 46 | // Otherwise, boot main program |
nfathurr | 1:25a2bf666957 | 47 | |
nfathurr | 1:25a2bf666957 | 48 | // Boot the adisense1000 to a known state |
nfathurr | 1:25a2bf666957 | 49 | ret = Adisense1000_Boot(); |
nfathurr | 1:25a2bf666957 | 50 | bool adiSense1000Active = !ret; |
nfathurr | 1:25a2bf666957 | 51 | |
nfathurr | 1:25a2bf666957 | 52 | #ifdef BL652 |
nfathurr | 1:25a2bf666957 | 53 | //boot BLE device |
nfathurr | 1:25a2bf666957 | 54 | ret = Bl652_Boot(); |
nfathurr | 1:25a2bf666957 | 55 | if (ret == 0) { |
nfathurr | 1:25a2bf666957 | 56 | ADI_SENSE_LOG_INFO("BLE Boot success.."); |
nfathurr | 1:25a2bf666957 | 57 | } else { |
nfathurr | 1:25a2bf666957 | 58 | ADI_SENSE_LOG_INFO("BLE Boot unsuccessful.."); |
nfathurr | 1:25a2bf666957 | 59 | } |
nfathurr | 1:25a2bf666957 | 60 | #endif |
seanwilson10 | 0:76fed7dd9235 | 61 | |
nfathurr | 1:25a2bf666957 | 62 | // Set if ble is present or not |
nfathurr | 1:25a2bf666957 | 63 | // If not, the PC interface can still be initialised |
nfathurr | 1:25a2bf666957 | 64 | bleActive = !ret; |
nfathurr | 1:25a2bf666957 | 65 | |
nfathurr | 1:25a2bf666957 | 66 | // Check adisense has booted correctly |
nfathurr | 1:25a2bf666957 | 67 | if( adiSense1000Active ) { |
nfathurr | 1:25a2bf666957 | 68 | Pc_ResetSuccess( bBootLoader ); |
nfathurr | 1:25a2bf666957 | 69 | ADI_SENSE_LOG_INFO("ADIsense boot successful..."); |
seanwilson10 | 0:76fed7dd9235 | 70 | } |
nfathurr | 1:25a2bf666957 | 71 | else { |
nfathurr | 1:25a2bf666957 | 72 | // Cannot continue without adi_sense module |
nfathurr | 1:25a2bf666957 | 73 | exit( 1 ); |
seanwilson10 | 0:76fed7dd9235 | 74 | } |
nfathurr | 1:25a2bf666957 | 75 | |
nfathurr | 1:25a2bf666957 | 76 | // Set led on to indicate boot has completed |
nfathurr | 1:25a2bf666957 | 77 | |
nfathurr | 1:25a2bf666957 | 78 | ADI_SENSE_LOG_INFO("Set LED Idle..."); |
nfathurr | 1:25a2bf666957 | 79 | Led_Idle(); |
nfathurr | 1:25a2bf666957 | 80 | |
nfathurr | 1:25a2bf666957 | 81 | // Begin main program |
nfathurr | 1:25a2bf666957 | 82 | ADI_SENSE_LOG_INFO("Begin main program..."); |
nfathurr | 1:25a2bf666957 | 83 | while(1) { |
nfathurr | 1:25a2bf666957 | 84 | // Read in a command and handle appropriately |
nfathurr | 1:25a2bf666957 | 85 | ret = MyProSwift_Command( bleActive ); |
nfathurr | 1:25a2bf666957 | 86 | if( ret != 0 ) { |
nfathurr | 1:25a2bf666957 | 87 | // Errors should be handled at lower levels, using reponse codes |
nfathurr | 1:25a2bf666957 | 88 | // to the appropriate active interface |
nfathurr | 1:25a2bf666957 | 89 | // exit(1); |
nfathurr | 1:25a2bf666957 | 90 | } |
seanwilson10 | 0:76fed7dd9235 | 91 | } |
seanwilson10 | 0:76fed7dd9235 | 92 | } |
seanwilson10 | 0:76fed7dd9235 | 93 |