Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
MicroappController Class Reference

The class MicroappController has functionality to store a second app (and perhaps in the future even more apps) on another part of the flash memory. More...

#include <cs_MicroappController.h>

Collaboration diagram for MicroappController:

Public Member Functions

void setIpcRam ()
 Set IPC ram data. More...
 
uint16_t initMemory (uint8_t appIndex)
 Initialize memory. More...
 
void startMicroapp (uint8_t appIndex)
 Actually run the app. More...
 
void tickMicroapp (uint8_t appIndex)
 Tick microapp. More...
 
uint8_t * getInputMicroappBuffer ()
 Get incoming microapp buffer (from coargs). More...
 
uint8_t * getOutputMicroappBuffer ()
 Get outgoing microapp buffer (from coargs). More...
 
cs_ret_code_t registerSoftInterrupt (MicroappSdkType type, uint8_t id)
 Register interrupts that allow generation of interrupts to the microapp. More...
 
microapp_soft_interrupt_registration_tgetRegisteredInterrupt (MicroappSdkType type, uint8_t id)
 Get the registered soft interrupt of given type. More...
 
bool allowSoftInterrupts (MicroappSdkType type, uint8_t id)
 Checks whether the microapp has empty interrupt slots to deal with a new softInterrupt. More...
 
bool isCpuBusy ()
 Checks whether the CPU is busy. More...
 
cs_ret_code_t registerBluenetEventInterrupt (CS_TYPE eventType)
 Register interrupts for bluenet events. More...
 
bool isEventInterruptRegistered (CS_TYPE type)
 Returns true when given bluenet event type is registered as interrupt. More...
 
cs_ret_code_t setScanFilter (microapp_sdk_ble_scan_filter_t &filter)
 Set a scan filter. More...
 
microapp_sdk_ble_scan_filter_t & getScanFilter ()
 Get the current scan filter. More...
 
void setEmptySoftInterruptSlots (uint8_t emptySlots)
 Set the number of empty interrupt slots. More...
 
void incrementEmptySoftInterruptSlots ()
 Increment the number of empty interrupt slots. More...
 
void generateSoftInterrupt (MicroappSdkType type, uint8_t id)
 Call the microapp in an interrupt context. More...
 
MicroappOperatingState getOperatingState (uint8_t appIndex)
 Get operating state from IPC ram. More...
 
void clear (uint8_t appIndex)
 Clear a microapp state: More...
 

Static Public Member Functions

static MicroappControllergetInstance ()
 

Public Attributes

microapp_data_t microappData
 Some runtime data we have to store for a microapp. More...
 

Protected Member Functions

void callMicroapp ()
 Resume the previously started coroutine. More...
 
bool handleAck ()
 Retrieve ack from the outgoing buffer that the microapp may have overwritten. More...
 
bool handleRequest ()
 Retrieve request from the microapp and let MicroappRequestHandler handle it. More...
 
bool stopAfterMicroappRequest (microapp_sdk_header_t *header)
 After particular microapp requests we want to stop the microapp (end of loop etc.) and continue with bluenet. More...
 
cs_ret_code_t checkFlashBoundaries (uint8_t appIndex, uintptr_t address)
 Check if start address of the microapp is within the flash boundaries assigned to the microapps. More...
 

Private Member Functions

 MicroappController ()
 Singleton, constructor, also copy constructor, is private. More...
 
 MicroappController (MicroappController const &)
 
void operator= (MicroappController const &)
 
void setOperatingState (uint8_t appIndex, MicroappOperatingState state)
 Set operating state in IPC ram. More...
 

Private Attributes

microapp_soft_interrupt_registration_t _softInterruptRegistrations [MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS]
 Buffer for keeping track of registered interrupts. More...
 
CS_TYPE _eventInterruptRegistrations [MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS]
 Keep up registered bluenet event interrupt registrations. More...
 
microapp_sdk_ble_scan_filter_t _scanFilter = {.type = CS_MICROAPP_SDK_BLE_SCAN_FILTER_NONE, .rssi = 0}
 Keep up the current scan filter. More...
 
uint8_t _tickCounter = 0
 To throttle the ticks themselves. More...
 
uint8_t _consecutiveMicroappCallCounter = 0
 Counter for consecutive microapp calls. More...
 
uint8_t _emptySoftInterruptSlots = 1
 Keeps track of how many empty interrupt slots are available on the microapp side. More...
 

Static Private Attributes

static const int8_t MICROAPP_MAX_SOFT_INTERRUPTS_WITHIN_A_TICK = 3
 The max number of interrupt calls per type per microapp tick. More...
 
static const uint8_t MICROAPP_MAX_NUMBER_CONSECUTIVE_CALLS = 3
 The maximum number of calls to the main thread of a microapp, per microapp tick. More...
 
static const uint8_t MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS = 10
 The maximum number of registered interrupts. More...
 
static const uint8_t MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS = 10
 The maximum number of registered bluenet event interrupts. More...
 
static const uint32_t MICROAPP_MAX_CALL_DURATION_MS = 20
 The maximum time in ms a call to a microapp can take. More...
 

Detailed Description

The class MicroappController has functionality to store a second app (and perhaps in the future even more apps) on another part of the flash memory.

Constructor & Destructor Documentation

◆ MicroappController() [1/2]

Singleton, constructor, also copy constructor, is private.

◆ MicroappController() [2/2]

Member Function Documentation

◆ allowSoftInterrupts()

bool MicroappController::allowSoftInterrupts ( MicroappSdkType  type,
uint8_t  id 
)

Checks whether the microapp has empty interrupt slots to deal with a new softInterrupt.

◆ callMicroapp()

void MicroappController::callMicroapp ( )
protected

Resume the previously started coroutine.

◆ checkFlashBoundaries()

cs_ret_code_t MicroappController::checkFlashBoundaries ( uint8_t  appIndex,
uintptr_t  address 
)
protected

Check if start address of the microapp is within the flash boundaries assigned to the microapps.

◆ clear()

void MicroappController::clear ( uint8_t  appIndex)

Clear a microapp state:

  • Remove all registered interrupts.

◆ generateSoftInterrupt()

void MicroappController::generateSoftInterrupt ( MicroappSdkType  type,
uint8_t  id 
)

Call the microapp in an interrupt context.

◆ getInputMicroappBuffer()

uint8_t * MicroappController::getInputMicroappBuffer ( )

Get incoming microapp buffer (from coargs).

◆ getInstance()

static MicroappController & MicroappController::getInstance ( )
inlinestatic

◆ getOperatingState()

MicroappOperatingState MicroappController::getOperatingState ( uint8_t  appIndex)

Get operating state from IPC ram.

Parameters
[in]appIndexCurrently, only appIndex 0 is supported.

◆ getOutputMicroappBuffer()

uint8_t * MicroappController::getOutputMicroappBuffer ( )

Get outgoing microapp buffer (from coargs).

◆ getRegisteredInterrupt()

microapp_soft_interrupt_registration_t * MicroappController::getRegisteredInterrupt ( MicroappSdkType  type,
uint8_t  id 
)

Get the registered soft interrupt of given type.

Returns
Null pointer when the given type is not registered.
The registered interrupt of the given type.

◆ getScanFilter()

microapp_sdk_ble_scan_filter_t & MicroappController::getScanFilter ( )

Get the current scan filter.

◆ handleAck()

bool MicroappController::handleAck ( )
protected

Retrieve ack from the outgoing buffer that the microapp may have overwritten.

Particularly check if the microapp exit was on finishing an interrupt. In that case, ignore the request made by the microapp

Returns
true if the request in the incoming buffer should be handled
false if the request in the incoming buffer should be ignored

◆ handleRequest()

bool MicroappController::handleRequest ( )
protected

Retrieve request from the microapp and let MicroappRequestHandler handle it.

Return whether the microapp should be called again immediately or not. This depends on both the type of request (i.e. for YIELDs do not call again) and on whether the max number of consecutive calls has been reached

Returns
true if the microapp should be called again
false if the microapp should not be called again

◆ incrementEmptySoftInterruptSlots()

void MicroappController::incrementEmptySoftInterruptSlots ( )

Increment the number of empty interrupt slots.

◆ initMemory()

uint16_t MicroappController::initMemory ( uint8_t  appIndex)

Initialize memory.

◆ isCpuBusy()

bool MicroappController::isCpuBusy ( )

Checks whether the CPU is busy.

This is done by checking if:

  • The scheduler is almost full.
  • ADC buffers have been skipped.

◆ isEventInterruptRegistered()

bool MicroappController::isEventInterruptRegistered ( CS_TYPE  type)

Returns true when given bluenet event type is registered as interrupt.

◆ operator=()

void MicroappController::operator= ( MicroappController const &  )
private

◆ registerBluenetEventInterrupt()

cs_ret_code_t MicroappController::registerBluenetEventInterrupt ( CS_TYPE  eventType)

Register interrupts for bluenet events.

◆ registerSoftInterrupt()

cs_ret_code_t MicroappController::registerSoftInterrupt ( MicroappSdkType  type,
uint8_t  id 
)

Register interrupts that allow generation of interrupts to the microapp.

◆ setEmptySoftInterruptSlots()

void MicroappController::setEmptySoftInterruptSlots ( uint8_t  emptySlots)

Set the number of empty interrupt slots.

Should be called on microapp yield requests, which contain an emptyInterruptSlots field.

Parameters
emptySlotsThe new value

◆ setIpcRam()

void MicroappController::setIpcRam ( )

Set IPC ram data.

◆ setOperatingState()

void MicroappController::setOperatingState ( uint8_t  appIndex,
MicroappOperatingState  state 
)
private

Set operating state in IPC ram.

This can be used after (an accidental) boot to decide if a microapp has been the reason for that reboot. In that case the microapp can be disabled so not to cause more havoc.

Parameters
[in]appIndexCurrently, only appIndex 0 is supported.
[in]stateThe state (running or not running) of this microapp.

◆ setScanFilter()

cs_ret_code_t MicroappController::setScanFilter ( microapp_sdk_ble_scan_filter_t &  filter)

Set a scan filter.

Validity of the filter is not checked.

◆ startMicroapp()

void MicroappController::startMicroapp ( uint8_t  appIndex)

Actually run the app.

Parameters
[in]appIndex(currently ignored)

◆ stopAfterMicroappRequest()

bool MicroappController::stopAfterMicroappRequest ( microapp_sdk_header_t *  header)
protected

After particular microapp requests we want to stop the microapp (end of loop etc.) and continue with bluenet.

This function returns true for such requests.

Parameters
[in]headerHeader of the microapp request
Returns
true if the microapp is yielding
false if the microapp is not yielding

◆ tickMicroapp()

void MicroappController::tickMicroapp ( uint8_t  appIndex)

Tick microapp.

Member Data Documentation

◆ _consecutiveMicroappCallCounter

uint8_t MicroappController::_consecutiveMicroappCallCounter = 0
private

Counter for consecutive microapp calls.

Limited to MICROAPP_MAX_NUMBER_CONSECUTIVE_CALLS

◆ _emptySoftInterruptSlots

uint8_t MicroappController::_emptySoftInterruptSlots = 1
private

Keeps track of how many empty interrupt slots are available on the microapp side.

Start with 1, but will be set to the correct value in the request handler.

◆ _eventInterruptRegistrations

CS_TYPE MicroappController::_eventInterruptRegistrations[MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS]
private

Keep up registered bluenet event interrupt registrations.

◆ _scanFilter

microapp_sdk_ble_scan_filter_t MicroappController::_scanFilter = {.type = CS_MICROAPP_SDK_BLE_SCAN_FILTER_NONE, .rssi = 0}
private

Keep up the current scan filter.

◆ _softInterruptRegistrations

microapp_soft_interrupt_registration_t MicroappController::_softInterruptRegistrations[MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS]
private

Buffer for keeping track of registered interrupts.

◆ _tickCounter

uint8_t MicroappController::_tickCounter = 0
private

To throttle the ticks themselves.

◆ MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS

const uint8_t MicroappController::MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS = 10
staticprivate

The maximum number of registered bluenet event interrupts.

◆ MICROAPP_MAX_CALL_DURATION_MS

const uint32_t MicroappController::MICROAPP_MAX_CALL_DURATION_MS = 20
staticprivate

The maximum time in ms a call to a microapp can take.

Take into account that real interrupts are included in this time.

◆ MICROAPP_MAX_NUMBER_CONSECUTIVE_CALLS

const uint8_t MicroappController::MICROAPP_MAX_NUMBER_CONSECUTIVE_CALLS = 3
staticprivate

The maximum number of calls to the main thread of a microapp, per microapp tick.

Any call passed this, will be executed later. We want at least 3, so you can set the RGB values of a led together.

◆ MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS

const uint8_t MicroappController::MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS = 10
staticprivate

The maximum number of registered interrupts.

◆ MICROAPP_MAX_SOFT_INTERRUPTS_WITHIN_A_TICK

const int8_t MicroappController::MICROAPP_MAX_SOFT_INTERRUPTS_WITHIN_A_TICK = 3
staticprivate

The max number of interrupt calls per type per microapp tick.

Any interrupt passed this, will be dropped. We can use a low value, because service discovery is not limited.

Suggestion: allow for bursts by setting a higher threshold, but decrease the counter only by N every tick.

◆ microappData

microapp_data_t MicroappController::microappData

Some runtime data we have to store for a microapp.


The documentation for this class was generated from the following file: