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 Sean_AdiSense1000_V21 by
Diff: main.cpp
- Revision:
- 34:029fc3b83f78
- Parent:
- 33:640b6bebda17
- Child:
- 35:853be4d80ff3
--- a/main.cpp Tue Sep 18 16:46:40 2018 +0000
+++ b/main.cpp Mon Sep 24 11:39:35 2018 +0000
@@ -62,162 +62,101 @@
#include "inc/adi_sense_log.h"
#include "common/utils.h"
-extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config;
-
-extern ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[];
-extern ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[];
-extern unsigned sample_lut_num_tables;
-
-/* Change the following pointer to select any of the configurations above */
-static ADI_SENSE_CONFIG *pSelectedConfig = &sensor2_bridge_6w_pressure_config;
+//additional libraries
+#include "adisense1000_boot.h"
+#include "ble_interface/ble_interface.h"
+#include "myproswift_eval.h"
+#include "eeprom_virtual/eeprom.h"
+#include "myproswift_periph.h"
+#include "led.h"
+#include "bootloader.h"
+#include "rcc_backup_registers.h"
-static ADI_SENSE_CONNECTION connectionInfo = {
- .type = ADI_SENSE_CONNECTION_TYPE_SPI,
- .spi = {
- .mosiPin = SPI_MOSI,
- .misoPin = SPI_MISO,
- .sckPin = SPI_SCK,
- .csPin = D10,
- .maxSpeedHz = 2000000,
- },
- .gpio = {
- .resetPin = D6,
- .errorPin = D3,
- .alertPin = D4,
- .datareadyPin = D5,
- },
- .log = {
- .txPin = D1,
- .rxPin = D0,
- .baudRate = 115200,
- .disableLogs = false,
- },
-};
-
-int main()
-{
- ADI_SENSE_RESULT res;
- ADI_SENSE_STATUS status;
- ADI_SENSE_DEVICE_HANDLE hDevice;
- ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL;
- bool_t bDeviceReady;
+#ifdef BL652
+#include "ble_interface/bl652.h"
+#endif
- /*
- * Open an ADI Sense device instance.
- */
- res = adi_sense_Open(0, &connectionInfo, &hDevice);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to open device instance");
- return res;
- }
+/*BLE COMMAND
+* REQ_REG_PACKET_COUNT = 0x21, //'!'
+* REQ_REG_PACKETS = 0x40, //'@'
+* REQ_FIELD_NAMES = 0x23, //'#'
+* START_STREAM = 0x24, //'$'
+* STOP_STREAM = 0x25, //'%'
+*/
- /*
- * Reset the given ADI Sense device....
- */
- ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait...");
- res = adi_sense_Reset(hDevice);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to reset device");
- return res;
- }
- /*
- * ...and wait until the device is ready.
- */
- do {
- wait_ms(100);
- res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to get device ready-state");
- return res;
- }
- } while (! bDeviceReady);
- ADI_SENSE_LOG_INFO("ADI Sense device ready");
-
- /*
- * Write configuration settings to the device registers.
- * Settings are not applied until adi_sense_ApplyConfigUpdates() is called.
- */
- ADI_SENSE_LOG_INFO("Setting device configuration");
- res = adi_sense_SetConfig(hDevice, pSelectedConfig);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to set device configuration");
- return res;
+int main( void )
+{
+ int ret = 1;
+ bool bleActive;
+
+ // Indicate device is booting
+ Led_Boot();
+
+ // Check if device needs to enter bootloader function, this is set via a PC command
+ // Flag is stored in RTC registers that persist while vbat is powered
+ bool_t bBootLoader = Rcc_ReadBackupReg( BOOTLOADER_FLAG_BACKUP_REG ) == 1 ? true : false;
+
+ if( bBootLoader ) {
+
+ // Let user know device is entering bootloader mode
+ Pc_ResetSuccess( bBootLoader );
+
+ // Jump to bootloader
+ Bootloader_Init();
}
- unsigned lutBufferSize = ADI_SENSE_LUT_MAX_SIZE;
- ADI_SENSE_1000_LUT *pLutBuffer = (ADI_SENSE_1000_LUT *) ::operator new (lutBufferSize);
- if (pLutBuffer == NULL)
- {
- ADI_SENSE_LOG_ERROR("Failed to allocate memory for user-defined LUT data buffer");
- return ADI_SENSE_NO_MEM;
- }
+ // Otherwise, boot main program
+
+ // Boot the adisense1000 to a known state
+ ret = Adisense1000_Boot();
+ bool adiSense1000Active = !ret;
+
+#ifdef BL652
+ //boot BLE device
+ ret = Bl652_Boot();
+ if (ret == 0) {
+ ADI_SENSE_LOG_INFO("BLE Boot success..");
+ } else {
+ ADI_SENSE_LOG_INFO("BLE Boot unsuccessful..");
+ }
+#endif
- ADI_SENSE_LOG_INFO("Assembling LUT data");
- res = adi_sense_1000_AssembleLutData(pLutBuffer, lutBufferSize,
- sample_lut_num_tables,
- sample_lut_desc_list,
- sample_lut_data_list);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to assemble user-defined LUT data");
- return res;
- }
-
- /*
- * Write assembled user-defined Look-Up Table data structure to the device
- * User-defined LUT data is not applied until adi_sense_ApplyConfigUpdates() is called.
- */
- ADI_SENSE_LOG_INFO("Setting LUT data");
- res = adi_sense_1000_SetLutData(hDevice, pLutBuffer);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to set user-defined LUT data");
- return res;
- }
-
- delete pLutBuffer;
-
+ // Set if ble is present or not
+ // If not, the PC interface can still be initialised
+ bleActive = !ret;
- res = adi_sense_ApplyConfigUpdates(hDevice);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to apply device configuration");
- return res;
+ // Check adisense has booted correctly
+ if( adiSense1000Active ) {
+ Pc_ResetSuccess( bBootLoader );
+ ADI_SENSE_LOG_INFO("ADIsense boot successful 19/09/2018");
+ ADI_SENSE_LOG_INFO("Firmware Version 2.1");
+ ADI_SENSE_LOG_INFO("Available BLE COMMAND");
+ ADI_SENSE_LOG_INFO("REQ_REG_PACKET_COUNT = 0x21, //'!'");
+ ADI_SENSE_LOG_INFO("REQ_REG_PACKETS = 0x40, //'@'");
+ ADI_SENSE_LOG_INFO("REQ_FIELD_NAMES = 0x23 0x0, //'#'");
+ ADI_SENSE_LOG_INFO("START_STREAM = 0x24, //'$'");
+ ADI_SENSE_LOG_INFO("STOP_STREAM = 0x25, //'percentage symbol'");
}
- /*
- * Check device status after updating the configuration
- */
- res = adi_sense_GetStatus(hDevice, &status);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to retrieve device status");
- return res;
- }
- if (status.deviceStatus &
- (ADI_SENSE_DEVICE_STATUS_ERROR | ADI_SENSE_DEVICE_STATUS_ALERT))
- {
- utils_printStatus(&status);
+ else {
+ // Cannot continue without adi_sense module
+ exit( 1 );
}
-
- /*
- * Kick off the measurement cycle here
- */
- ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles");
- utils_runMeasurement(hDevice, eMeasurementMode);
+
+ // Set led on to indicate boot has completed
+
+ ADI_SENSE_LOG_INFO("Set LED Idle...");
+ Led_Idle();
+
+ // Begin main program
+ ADI_SENSE_LOG_INFO("Begin main program...");
+ while(1) {
+ // Read in a command and handle appropriately
+ ret = MyProSwift_Command( bleActive );
+ if( ret != 0 ) {
+ // Errors should be handled at lower levels, using reponse codes
+ // to the appropriate active interface
+ // exit(1);
+ }
+ }
+}
- /*
- * Clean up and exit
- */
- res = adi_sense_Close(hDevice);
- if (res != ADI_SENSE_SUCCESS)
- {
- ADI_SENSE_LOG_ERROR("Failed to close device instance");
- return res;
- }
-
- return 0;
-}
