Buoyancy Firmware  1.0
Buoyancy Vehicle Firmware Documentation
main project files

Main project file that contain core program handling and initialization. More...

Macros

#define DEVICE_NAME   "Buoyancy"
 Name of device. More...
 
#define MANUFACTURER_NAME   "NTNU"
 Manufacturer. More...
 
#define APP_ADV_INTERVAL   64
 The advertising interval (in units of 0.625 ms. More...
 
#define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN
 UUID type for the Nordic UART Service (vendor specific). More...
 
#define APP_ADV_DURATION   18000
 The advertising duration (180 seconds) in units of 10 milliseconds. More...
 
#define APP_BLE_OBSERVER_PRIO   3
 Application's BLE observer priority. More...
 
#define APP_BLE_CONN_CFG_TAG   1
 A tag identifying the SoftDevice BLE configuration. More...
 
#define MIN_CONN_INTERVAL   MSEC_TO_UNITS(7.5, UNIT_1_25_MS)
 Minimum acceptable connection interval (7.5 ms). More...
 
#define MAX_CONN_INTERVAL   MSEC_TO_UNITS(75, UNIT_1_25_MS)
 Maximum acceptable connection interval (75 second). More...
 
#define SLAVE_LATENCY   0
 Slave latency. More...
 
#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)
 Connection supervisory timeout (4 seconds). More...
 
#define FIRST_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000)
 Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). More...
 
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)
 Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). More...
 
#define MAX_CONN_PARAMS_UPDATE_COUNT   6
 Number of attempts before giving up the connection parameter negotiation. More...
 
#define SEC_PARAM_BOND   1
 Perform bonding. More...
 
#define SEC_PARAM_MITM   0
 Man In The Middle protection not required. More...
 
#define SEC_PARAM_LESC   0
 LE Secure Connections not enabled. More...
 
#define SEC_PARAM_KEYPRESS   0
 Keypress notifications not enabled. More...
 
#define SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_NONE
 No I/O capabilities. More...
 
#define SEC_PARAM_OOB   0
 Out Of Band data not available. More...
 
#define SEC_PARAM_MIN_KEY_SIZE   7
 Minimum encryption key size. More...
 
#define SEC_PARAM_MAX_KEY_SIZE   16
 Maximum encryption key size. More...
 
#define DEAD_BEEF   0xDEADBEEF
 Value used as error code on stack dump, can be used to identify stack location on stack unwind. More...
 
#define UART_TX_BUF_SIZE   256
 UART TX buffer size. More...
 
#define UART_RX_BUF_SIZE   256
 UART RX buffer size. More...
 
#define TXD_PIN   (6UL)
 White wire. More...
 
#define RXD_PIN   (8UL)
 Gray/brown wire. More...
 
#define MOTION_INT   13UL
 ICM motion sensor interrupt. More...
 
#define TMP_ALERT   15UL
 TMP117 temperature sensor interrupt. More...
 
#define HALLEFFECT_INT   17UL
 Hall Effect sensor interrupt. More...
 
#define TOP_LIMIT   29UL
 Top Limit switch - Max Depth. More...
 
#define BOTTOM_LIMIT   28UL
 Bottom Limit switch - Water Surface. More...
 
#define PRESSURE_SWITCH   20UL
 Signal to switch on or off pressure sensor power. More...
 
#define LOW_POWER_THRESHOLD   8700
 SAADC value at 12.8 V - Go to LOWPOWER state. More...
 

Functions

 BLE_NUS_DEF (m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT)
 BLE NUS service instance. More...
 
 NRF_BLE_GATT_DEF (m_gatt)
 GATT module instance. More...
 
 NRF_BLE_QWR_DEF (m_qwr)
 Context for the Queued Write module. More...
 
 BLE_ADVERTISING_DEF (m_advertising)
 Advertising module instance. More...
 
void hallEffectInterrupt_handler (void)
 Hall Effect button Interrupt handler. More...
 
void limitSwitchBottom_handler (void)
 Bottom limit switch Interrupt handler. More...
 
void limitSwitchTop_handler (void)
 Upper limit switch Interrupt handler. More...
 
void TMP_temp_Alert_Interrupt_handler (void)
 TMP117 Temperature Alert Interrupt handler. More...
 
void motionSensorInterrupt_handler (void)
 ICM20948 Motion Sensor Interrupt handler. More...
 
void assert_nrf_callback (uint16_t line_num, const uint8_t *p_file_name)
 Callback function for asserts in the SoftDevice. More...
 
void pm_evt_handler (pm_evt_t const *p_evt)
 Function for handling Peer Manager events. More...
 
void gatt_evt_handler (nrf_ble_gatt_t *p_gatt, nrf_ble_gatt_evt_t const *p_evt)
 Function for handling events from the GATT library. More...
 
void uart_event_handle (app_uart_evt_t *p_event)
 Function for handling app_uart events. More...
 
void idle_state_handle (void)
 
More...
 
void gatt_init (void)
 Function for initializing the GATT library. More...
 
void enablePressureSensor ()
 Function to enable pressure sensor. More...
 
void disablePressureSensor ()
 Function to disable pressure sensor. More...
 
void sleep_mode_enter (void)
 Function for putting the chip into sleep mode. More...
 
void nus_send (uint8_t data[], uint16_t length)
 Send data over BLE Nordic UART Service (NUS) More...
 
void advertising_start (bool erase_bonds)
 Function for starting advertising. More...
 
void HFCLKstart ()
 Start HFCLK from crystal oscillator, this will give the PWM and SAADC higher accuracy. More...
 
void BLEdisconnect ()
 Disconnect BLE connection. More...
 
void disableAdvOnDisconnect (void)
 disable restarted advertising upon disconnection. More...
 
void enableAdvOnDisconnect (void)
 enable restarted advertising upon disconnection. More...
 
bool BLEconnected ()
 Check if connected to client. More...
 
void stopAdvertising ()
 stop advertising More...
 
void readTMP117 (uint8_t *tempMSB, uint8_t *tempLSB)
 Read TMP117 16 bit temperature register. More...
 
int main (void)
 Function for application main entry. More...
 
void nus_send (uint8_t *, uint16_t)
 
void printLine (uint8_t data[], uint16_t)
 
void anotherPrint (void)
 
void handleRXdata (ble_evt_t const *)
 
void uart_error_handle (app_uart_evt_t *)
 
void advLEDoff (void)
 

Variables

bool getValue = false
 Menu is waiting for value from BLE application. More...
 
bool transferDataFlag = false
 Menu is in the process of transfering data to BLE application. More...
 
bool updateFSM = true
 Init to true in order to access state machine. More...
 
bool sendNUS = false
 Flag to signal Nordic UART Service to send data. More...
 
bool motorStopped = false
 Flag to signal if motor is stopped or need to be stopped. More...
 
bool isAdvertising = false
 Flag to signal if advertising or not. More...
 
bool bottomLimit = false
 Flag to signal when bottom limit switch is reached. More...
 
mission_t mission
 Create mission struct instance. More...
 
FSM_t fsm
 Create Finite State Machine struct instance. More...
 
enum menu currentMenu
 Create menu enumeration instance to keep track of menu operations. More...
 

Detailed Description

Main project file that contain core program handling and initialization.

Macro Definition Documentation

◆ APP_ADV_DURATION

#define APP_ADV_DURATION   18000

The advertising duration (180 seconds) in units of 10 milliseconds.

◆ APP_ADV_INTERVAL

#define APP_ADV_INTERVAL   64

The advertising interval (in units of 0.625 ms.

This value corresponds to 40 ms).

◆ APP_BLE_CONN_CFG_TAG

#define APP_BLE_CONN_CFG_TAG   1

A tag identifying the SoftDevice BLE configuration.

◆ APP_BLE_OBSERVER_PRIO

#define APP_BLE_OBSERVER_PRIO   3

Application's BLE observer priority.

You shouldn't need to modify this value.

◆ BOTTOM_LIMIT

#define BOTTOM_LIMIT   28UL

Bottom Limit switch - Water Surface.

◆ CONN_SUP_TIMEOUT

#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)

Connection supervisory timeout (4 seconds).

◆ DEAD_BEEF

#define DEAD_BEEF   0xDEADBEEF

Value used as error code on stack dump, can be used to identify stack location on stack unwind.

UART FIFO BUFFER SIZE

◆ DEVICE_NAME

#define DEVICE_NAME   "Buoyancy"

Name of device.

Will be included in the advertising data.

◆ FIRST_CONN_PARAMS_UPDATE_DELAY

#define FIRST_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000)

Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds).

◆ HALLEFFECT_INT

#define HALLEFFECT_INT   17UL

Hall Effect sensor interrupt.

◆ LOW_POWER_THRESHOLD

#define LOW_POWER_THRESHOLD   8700

SAADC value at 12.8 V - Go to LOWPOWER state.

◆ MANUFACTURER_NAME

#define MANUFACTURER_NAME   "NTNU"

Manufacturer.

Will be passed to Device Information Service.

◆ MAX_CONN_INTERVAL

#define MAX_CONN_INTERVAL   MSEC_TO_UNITS(75, UNIT_1_25_MS)

Maximum acceptable connection interval (75 second).

◆ MAX_CONN_PARAMS_UPDATE_COUNT

#define MAX_CONN_PARAMS_UPDATE_COUNT   6

Number of attempts before giving up the connection parameter negotiation.

◆ MIN_CONN_INTERVAL

#define MIN_CONN_INTERVAL   MSEC_TO_UNITS(7.5, UNIT_1_25_MS)

Minimum acceptable connection interval (7.5 ms).

◆ MOTION_INT

#define MOTION_INT   13UL

ICM motion sensor interrupt.

◆ NEXT_CONN_PARAMS_UPDATE_DELAY

#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)

Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds).

◆ NUS_SERVICE_UUID_TYPE

#define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN

UUID type for the Nordic UART Service (vendor specific).

◆ PRESSURE_SWITCH

#define PRESSURE_SWITCH   20UL

Signal to switch on or off pressure sensor power.

◆ RXD_PIN

#define RXD_PIN   (8UL)

Gray/brown wire.

GPIOTE input Interrupt

◆ SEC_PARAM_BOND

#define SEC_PARAM_BOND   1

Perform bonding.

◆ SEC_PARAM_IO_CAPABILITIES

#define SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_NONE

No I/O capabilities.

◆ SEC_PARAM_KEYPRESS

#define SEC_PARAM_KEYPRESS   0

Keypress notifications not enabled.

◆ SEC_PARAM_LESC

#define SEC_PARAM_LESC   0

LE Secure Connections not enabled.

◆ SEC_PARAM_MAX_KEY_SIZE

#define SEC_PARAM_MAX_KEY_SIZE   16

Maximum encryption key size.

◆ SEC_PARAM_MIN_KEY_SIZE

#define SEC_PARAM_MIN_KEY_SIZE   7

Minimum encryption key size.

◆ SEC_PARAM_MITM

#define SEC_PARAM_MITM   0

Man In The Middle protection not required.

◆ SEC_PARAM_OOB

#define SEC_PARAM_OOB   0

Out Of Band data not available.

◆ SLAVE_LATENCY

#define SLAVE_LATENCY   0

Slave latency.

◆ TMP_ALERT

#define TMP_ALERT   15UL

TMP117 temperature sensor interrupt.

◆ TOP_LIMIT

#define TOP_LIMIT   29UL

Top Limit switch - Max Depth.

◆ TXD_PIN

#define TXD_PIN   (6UL)

White wire.

◆ UART_RX_BUF_SIZE

#define UART_RX_BUF_SIZE   256

UART RX buffer size.

UART

◆ UART_TX_BUF_SIZE

#define UART_TX_BUF_SIZE   256

UART TX buffer size.

Function Documentation

◆ advertising_start()

void advertising_start ( bool  erase_bonds)

Function for starting advertising.

◆ advLEDoff()

void advLEDoff ( void  )

◆ anotherPrint()

void anotherPrint ( void  )

◆ assert_nrf_callback()

void assert_nrf_callback ( uint16_t  line_num,
const uint8_t p_file_name 
)

Callback function for asserts in the SoftDevice.

This function will be called in case of an assert in the SoftDevice, FAILUREstate is called to float buoyancy vehicle to surface and change LED to PINK.

Warning
This handler is an example only and does not fit a final product. You need to analyze how your product is supposed to react in case of Assert.
On assert from the SoftDevice, the system can only recover on reset.
Parameters
[in]line_numLine number of the failing ASSERT call.
[in]file_nameFile name of the failing ASSERT call.

◆ BLE_ADVERTISING_DEF()

BLE_ADVERTISING_DEF ( m_advertising  )

Advertising module instance.

◆ BLE_NUS_DEF()

BLE_NUS_DEF ( m_nus  ,
NRF_SDH_BLE_TOTAL_LINK_COUNT   
)

BLE NUS service instance.

◆ BLEconnected()

bool BLEconnected ( )

Check if connected to client.

Returns
true If connected
false If not connected

◆ BLEdisconnect()

void BLEdisconnect ( )

Disconnect BLE connection.

◆ disableAdvOnDisconnect()

void disableAdvOnDisconnect ( void  )

disable restarted advertising upon disconnection.

◆ disablePressureSensor()

void disablePressureSensor ( )

Function to disable pressure sensor.

◆ enableAdvOnDisconnect()

void enableAdvOnDisconnect ( void  )

enable restarted advertising upon disconnection.

◆ enablePressureSensor()

void enablePressureSensor ( )

Function to enable pressure sensor.

◆ gatt_evt_handler()

void gatt_evt_handler ( nrf_ble_gatt_t *  p_gatt,
nrf_ble_gatt_evt_t const *  p_evt 
)

Function for handling events from the GATT library.

◆ gatt_init()

void gatt_init ( void  )

Function for initializing the GATT library.

This function sets up all the necessary GAP (Generic Access Profile) parameters of the device.

◆ hallEffectInterrupt_handler()

void hallEffectInterrupt_handler ( void  )

Hall Effect button Interrupt handler.

< Notify FSM that hall effect interrupt has occured

◆ handleRXdata()

void handleRXdata ( ble_evt_t const *  )

◆ HFCLKstart()

void HFCLKstart ( )

Start HFCLK from crystal oscillator, this will give the PWM and SAADC higher accuracy.

◆ idle_state_handle()

void idle_state_handle ( void  )

Function for handling the idle state (main loop).

If there is no pending log operation, then sleep until next the next event occurs.

◆ limitSwitchBottom_handler()

void limitSwitchBottom_handler ( void  )

Bottom limit switch Interrupt handler.

< Debounce delay.

◆ limitSwitchTop_handler()

void limitSwitchTop_handler ( void  )

Upper limit switch Interrupt handler.

Note
at this point firmware is not yet written to do anything upper limit switch interrupt.

◆ main()

int main ( void  )

Function for application main entry.

< Initialize PWM before anything else to avoid the LED on full strength when uninitialized.

< variable to measure motor speed while returning to lower limit switch

< Enable limit switches as soon as possible to make sure they are enabled when motor is running

< Call NUS data transmission by setting flag: sendNUS

◆ motionSensorInterrupt_handler()

void motionSensorInterrupt_handler ( void  )

ICM20948 Motion Sensor Interrupt handler.

Note
at this stage ICM20948 motion sensor is not yet configured, and firmware is not yet written to do anything on motion sensor interrupt.

◆ NRF_BLE_GATT_DEF()

NRF_BLE_GATT_DEF ( m_gatt  )

GATT module instance.

◆ NRF_BLE_QWR_DEF()

NRF_BLE_QWR_DEF ( m_qwr  )

Context for the Queued Write module.

◆ nus_send() [1/2]

void nus_send ( uint8_t ,
uint16_t   
)

◆ nus_send() [2/2]

void nus_send ( uint8_t  data[],
uint16_t  length 
)

Send data over BLE Nordic UART Service (NUS)

Parameters
[in]datastring array to be sent over NUS
[in]lengthLength of string array

◆ pm_evt_handler()

void pm_evt_handler ( pm_evt_t const *  p_evt)

Function for handling Peer Manager events.

Parameters
[in]p_evtPeer Manager event.

◆ printLine()

void printLine ( uint8_t  data[],
uint16_t   
)

◆ readTMP117()

void readTMP117 ( uint8_t tempMSB,
uint8_t tempLSB 
)

Read TMP117 16 bit temperature register.

Parameters
[out]tempMSB8 most significant bits representing temperature
[out]tempLSB8 least significant bits representing temperature

<Temperature register within TMP117

◆ sleep_mode_enter()

void sleep_mode_enter ( void  )

Function for putting the chip into sleep mode.

Note
This function trigger system-off mode (this function will not return), wakeup will cause a reset

◆ stopAdvertising()

void stopAdvertising ( )

stop advertising

Warning
If called when not advertising SoftDevice will return NRF_ERROR_INVALID_STATE

◆ TMP_temp_Alert_Interrupt_handler()

void TMP_temp_Alert_Interrupt_handler ( void  )

TMP117 Temperature Alert Interrupt handler.

Note
at this stage TMP117 temperature sensor is not yet configured, and firmware is not yet written to do anything on temperature alert interrupt.

◆ uart_error_handle()

void uart_error_handle ( app_uart_evt_t *  )

◆ uart_event_handle()

void uart_event_handle ( app_uart_evt_t *  p_event)

Function for handling app_uart events.

This function will receive the reply message from motor controller interface, through the app_uart module, and append it to a data buffer array. The data buffer will be summed to verify correct checksum and sent to receiveReply().

Parameters
[in]p_eventUART event

< UART Rx - Receive reply from motor controller.

< Go to FAILUREstate() to change LED to PINK and float to surface

< Go to FAILUREstate() to change LED to PINK and float to surface

Variable Documentation

◆ bottomLimit

bool bottomLimit = false

Flag to signal when bottom limit switch is reached.

◆ currentMenu

enum menu currentMenu

Create menu enumeration instance to keep track of menu operations.

◆ fsm

FSM_t fsm

Create Finite State Machine struct instance.

◆ getValue

bool getValue = false

Menu is waiting for value from BLE application.

◆ isAdvertising

bool isAdvertising = false

Flag to signal if advertising or not.

◆ mission

mission_t mission

Create mission struct instance.

mission structure instance

◆ motorStopped

bool motorStopped = false

Flag to signal if motor is stopped or need to be stopped.

Flag to signal motor stopped.

◆ sendNUS

bool sendNUS = false

Flag to signal Nordic UART Service to send data.

◆ transferDataFlag

bool transferDataFlag = false

Menu is in the process of transfering data to BLE application.

◆ updateFSM

bool updateFSM = true

Init to true in order to access state machine.