Buoyancy Firmware  v1.0
Buoyancy Vehicle Firmware Documentation
main project files

Main project file that contain core program handling and initialization. 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 menu_handler (ble_evt_t const *p_evt)
 Function for handling data received to the application. 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 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...
 

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...
 
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.

Function Documentation

◆ advertising_start()

void advertising_start ( bool  erase_bonds)

Function for starting advertising.

◆ 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.

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.

< Go to failure state to change LED to PINK and float to surface

< handle error

◆ 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 ( void  )

Check if connected to client.

Returns
true If connected
false If not connected

◆ BLEdisconnect()

void BLEdisconnect ( void  )

Disconnect BLE connection.

◆ disableAdvOnDisconnect()

void disableAdvOnDisconnect ( void  )

disable restarted advertising upon disconnection.

◆ enableAdvOnDisconnect()

void enableAdvOnDisconnect ( void  )

enable restarted advertising upon disconnection.

◆ 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

◆ 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.

Note
at this stage limit switches are not yet connected any input pin, and firmware is not yet written to do anything on limit switch interrupt.

◆ limitSwitchTop_handler()

void limitSwitchTop_handler ( void  )

Upper limit switch Interrupt handler.

Note
at this stage limit switches are not yet connected any input pin, and firmware is not yet written to do anything on 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 the possible to make sure they are enabled when motor is running

< make sure vehicle float to surface on reset.

< Call NUS data transmission by setting flag: sendNUS

◆ menu_handler()

void menu_handler ( ble_evt_t const *  p_evt)

Function for handling data received to the application.

Function for handling received data to handle the menu system. The user type operate menu by numeric integer values, and set configuration values in integer or float values.

Parameters
[in]p_evtEvent received from the ble_event Module.

< Copy written data from gatts to the application.

< option variable to hold the menu navigation value, when user navigate menu.

< delimiter ':' to separate incomming values, in case a datavalue follows the menu option -! depricated !

< char pointers to hold tokens from separated incoming data.

< tokenize incoming data separated by ':' - depricated, there are no longer a functional case where a second value is used in the menu handling

< GetValue: configuration value for mission (depth and time), PID, and threshold. transferDataFlag: to send file number to transfer_menu()

◆ 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()

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.

◆ 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 ( void  )

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_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

◆ 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.

◆ motorStopped

bool motorStopped = false

Flag to signal if motor is stopped or need to be 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.