Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_MicroappController.h
Go to the documentation of this file.
1#pragma once
2
4#include <cs_MicroappStructs.h>
6#include <ipc/cs_IpcRamData.h>
11
12extern "C" {
14}
15
16static_assert(sizeof(bluenet2microapp_ipcdata_t) <= BLUENET_IPC_RAM_DATA_ITEM_SIZE);
17
18// Do some asserts on the redefinitions in the shared header files
19// These asserts cannot be done where declared since the shared files do not depend on the rest of bluenet
20static_assert(MAC_ADDRESS_LENGTH == MAC_ADDRESS_LEN);
21static_assert(MAX_BLE_ADV_DATA_LENGTH == ADVERTISEMENT_DATA_MAX_SIZE);
22static_assert(MAX_MICROAPP_MESH_PAYLOAD_SIZE == MAX_MESH_MSG_PAYLOAD_SIZE);
23
24static_assert(CS_MICROAPP_SDK_SWITCH_OFF == CS_SWITCH_CMD_VAL_OFF);
25static_assert(CS_MICROAPP_SDK_SWITCH_ON == CS_SWITCH_CMD_VAL_FULLY_ON);
26static_assert(CS_MICROAPP_SDK_SWITCH_TOGGLE == CS_SWITCH_CMD_VAL_TOGGLE);
27static_assert(CS_MICROAPP_SDK_SWITCH_BEHAVIOUR == CS_SWITCH_CMD_VAL_BEHAVIOUR);
28static_assert(CS_MICROAPP_SDK_SWITCH_SMART_ON == CS_SWITCH_CMD_VAL_SMART_ON);
29
36 uintptr_t entry;
37 bluenet_io_buffers_t* ioBuffers;
38};
39
45 MicroappSdkType type = CS_MICROAPP_SDK_TYPE_NONE;
47 uint8_t id = 0;
49 int8_t counter = 0;
50};
51
58};
59
65 bool isScanning = false;
66
68 Service* service = nullptr;
69};
70
76private:
83
93
101
106
111
117 static const uint32_t MICROAPP_MAX_CALL_DURATION_MS = 20;
118
123
128
130 microapp_sdk_ble_scan_filter_t _scanFilter = {.type = CS_MICROAPP_SDK_BLE_SCAN_FILTER_NONE, .rssi = 0};
131
135 uint8_t _tickCounter = 0;
136
141
147
155 void setOperatingState(uint8_t appIndex, MicroappOperatingState state);
156
157protected:
162
171 bool handleAck();
172
183
193 bool stopAfterMicroappRequest(microapp_sdk_header_t* header);
194
198 cs_ret_code_t checkFlashBoundaries(uint8_t appIndex, uintptr_t address);
199
200public:
202 static MicroappController instance;
203 return instance;
204 }
205
209 void setIpcRam();
210
214 uint16_t initMemory(uint8_t appIndex);
215
221 void startMicroapp(uint8_t appIndex);
222
226 void tickMicroapp(uint8_t appIndex);
227
232
237
241 cs_ret_code_t registerSoftInterrupt(MicroappSdkType type, uint8_t id);
242
250
254 bool allowSoftInterrupts(MicroappSdkType type, uint8_t id);
255
262 bool isCpuBusy();
263
268
273
278 cs_ret_code_t setScanFilter(microapp_sdk_ble_scan_filter_t& filter);
279
283 microapp_sdk_ble_scan_filter_t& getScanFilter();
284
291 void setEmptySoftInterruptSlots(uint8_t emptySlots);
292
297
301 void generateSoftInterrupt(MicroappSdkType type, uint8_t id);
302
308
313 void clear(uint8_t appIndex);
314
319};
The class MicroappController has functionality to store a second app (and perhaps in the future even ...
Definition: cs_MicroappController.h:75
microapp_soft_interrupt_registration_t _softInterruptRegistrations[MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS]
Buffer for keeping track of registered interrupts.
Definition: cs_MicroappController.h:122
microapp_data_t microappData
Some runtime data we have to store for a microapp.
Definition: cs_MicroappController.h:318
bool isEventInterruptRegistered(CS_TYPE type)
Returns true when given bluenet event type is registered as interrupt.
static const uint8_t MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS
The maximum number of registered bluenet event interrupts.
Definition: cs_MicroappController.h:110
void clear(uint8_t appIndex)
Clear a microapp state:
void generateSoftInterrupt(MicroappSdkType type, uint8_t id)
Call the microapp in an interrupt context.
uint8_t _emptySoftInterruptSlots
Keeps track of how many empty interrupt slots are available on the microapp side.
Definition: cs_MicroappController.h:146
static const uint32_t MICROAPP_MAX_CALL_DURATION_MS
The maximum time in ms a call to a microapp can take.
Definition: cs_MicroappController.h:117
static const uint8_t MICROAPP_MAX_NUMBER_CONSECUTIVE_CALLS
The maximum number of calls to the main thread of a microapp, per microapp tick.
Definition: cs_MicroappController.h:100
bool handleAck()
Retrieve ack from the outgoing buffer that the microapp may have overwritten.
uint16_t initMemory(uint8_t appIndex)
Initialize memory.
uint8_t _tickCounter
To throttle the ticks themselves.
Definition: cs_MicroappController.h:135
bool isCpuBusy()
Checks whether the CPU is busy.
CS_TYPE _eventInterruptRegistrations[MICROAPP_MAX_BLUENET_EVENT_INTERRUPT_REGISTRATIONS]
Keep up registered bluenet event interrupt registrations.
Definition: cs_MicroappController.h:127
microapp_sdk_ble_scan_filter_t _scanFilter
Keep up the current scan filter.
Definition: cs_MicroappController.h:130
bool handleRequest()
Retrieve request from the microapp and let MicroappRequestHandler handle it.
microapp_soft_interrupt_registration_t * getRegisteredInterrupt(MicroappSdkType type, uint8_t id)
Get the registered soft interrupt of given type.
void tickMicroapp(uint8_t appIndex)
Tick microapp.
void setOperatingState(uint8_t appIndex, MicroappOperatingState state)
Set operating state in IPC ram.
MicroappController(MicroappController const &)
MicroappOperatingState getOperatingState(uint8_t appIndex)
Get operating state from IPC ram.
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.
bool allowSoftInterrupts(MicroappSdkType type, uint8_t id)
Checks whether the microapp has empty interrupt slots to deal with a new softInterrupt.
uint8_t * getInputMicroappBuffer()
Get incoming microapp buffer (from coargs).
static const int8_t MICROAPP_MAX_SOFT_INTERRUPTS_WITHIN_A_TICK
The max number of interrupt calls per type per microapp tick.
Definition: cs_MicroappController.h:92
static const uint8_t MICROAPP_MAX_SOFT_INTERRUPT_REGISTRATIONS
The maximum number of registered interrupts.
Definition: cs_MicroappController.h:105
void operator=(MicroappController const &)
static MicroappController & getInstance()
Definition: cs_MicroappController.h:201
void setEmptySoftInterruptSlots(uint8_t emptySlots)
Set the number of empty interrupt slots.
uint8_t _consecutiveMicroappCallCounter
Counter for consecutive microapp calls.
Definition: cs_MicroappController.h:140
cs_ret_code_t registerBluenetEventInterrupt(CS_TYPE eventType)
Register interrupts for bluenet events.
void callMicroapp()
Resume the previously started coroutine.
void incrementEmptySoftInterruptSlots()
Increment the number of empty interrupt slots.
microapp_sdk_ble_scan_filter_t & getScanFilter()
Get the current scan filter.
void setIpcRam()
Set IPC ram data.
MicroappController()
Singleton, constructor, also copy constructor, is private.
bool stopAfterMicroappRequest(microapp_sdk_header_t *header)
After particular microapp requests we want to stop the microapp (end of loop etc.) and continue with ...
uint8_t * getOutputMicroappBuffer()
Get outgoing microapp buffer (from coargs).
cs_ret_code_t setScanFilter(microapp_sdk_ble_scan_filter_t &filter)
Set a scan filter.
void startMicroapp(uint8_t appIndex)
Actually run the app.
cs_ret_code_t registerSoftInterrupt(MicroappSdkType type, uint8_t id)
Register interrupts that allow generation of interrupts to the microapp.
Base class for a BLE service.
Definition: cs_Service.h:26
constexpr uint8_t ADVERTISEMENT_DATA_MAX_SIZE
Maximum length advertisement data.
Definition: cs_BleConstants.h:41
static constexpr uint8_t MAX_MESH_MSG_PAYLOAD_SIZE
Definition: cs_MeshModelPackets.h:59
MicroappOperatingState
Operating state of a microapp.
Definition: cs_MicroappController.h:55
constexpr uint8_t CS_SWITCH_CMD_VAL_BEHAVIOUR
Switch to the value according to behaviour rules.
Definition: cs_Packets.h:242
constexpr uint8_t CS_SWITCH_CMD_VAL_TOGGLE
Switch OFF when currently on, switch to SMART_ON when currently off.
Definition: cs_Packets.h:239
constexpr uint8_t CS_SWITCH_CMD_VAL_SMART_ON
Switch on, the value will be determined by behaviour rules.
Definition: cs_Packets.h:245
constexpr uint8_t CS_SWITCH_CMD_VAL_OFF
Switch command values.
Definition: cs_Packets.h:230
constexpr uint8_t CS_SWITCH_CMD_VAL_FULLY_ON
Definition: cs_Packets.h:231
static const uint8_t MAC_ADDRESS_LEN
Length of a MAC address.
Definition: cs_Typedefs.h:43
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
CS_TYPE
Types:
Definition: cs_Types.h:79
The IPC buffers can be used to bootstrap communication between microapp and bluenet.
Definition: cs_MicroappController.h:35
uintptr_t entry
Definition: cs_MicroappController.h:36
bluenet_io_buffers_t * ioBuffers
Definition: cs_MicroappController.h:37
Keeps up data for a microapp.
Definition: cs_MicroappController.h:63
bool isScanning
Keeps up whether the microapp is scanning, thus whether BLE scans should generate interrupts.
Definition: cs_MicroappController.h:65
Service * service
Keeps up the microapp service.
Definition: cs_MicroappController.h:68
Struct for keeping track of registered interrupts from the microapp.
Definition: cs_MicroappController.h:43
MicroappSdkType type
Main type of registered interrupt. Set to CS_MICROAPP_SDK_TYPE_NONE when this slot is not filled.
Definition: cs_MicroappController.h:45
int8_t counter
Counter that keeps up how often an interrupt of this type has been called within a tick.
Definition: cs_MicroappController.h:49