Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_MicroappPackets.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Jun 3, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
10#include <cfg/cs_AutoConfig.h>
11#include <cfg/cs_StaticConfig.h>
12#include <cs_MemoryLayout.h>
13
14#include <cstdint>
15
22constexpr uint16_t MICROAPP_UPLOAD_MAX_CHUNK_SIZE = 256;
23
28
32constexpr uint8_t MICROAPP_SDK_MAJOR = 1;
33
37constexpr uint8_t MICROAPP_SDK_MINOR = 0;
38
40constexpr uint16_t MICROAPP_MAX_SIZE = (g_FLASH_MICROAPP_PAGES * CS_FLASH_PAGE_SIZE);
41
43constexpr uint8_t MICROAPP_INDEX_NONE = 255;
44
51struct __attribute__((__packed__)) microapp_binary_header_t {
52 uint8_t sdkVersionMajor; // Similar to microapp_sdk_version_t
54 uint16_t size; // Size of the binary, including this header.
55
56 uint16_t checksum; // Checksum (CRC16-CCITT) of the binary, after this header.
57 uint16_t checksumHeader; // Checksum (CRC16-CCITT) of this header, with this field set to 0.
58
59 uint32_t appBuildVersion; // Build version of this microapp.
60
61 uint16_t startOffset; // Offset in bytes of the first instruction to execute.
62 uint16_t reserved; // Reserved for future use, must be 0 for now.
63
64 uint32_t reserved2; // Reserved for future use, must be 0 for now.
65};
66
67struct __attribute__((packed)) microapp_ctrl_header_t {
68 // Protocol of the microapp command and result packets.
69 uint8_t protocol;
70 // Index of the microapp on the firmware.
71 uint8_t index;
72};
73
74struct __attribute__((packed)) microapp_upload_t {
76 // Offset in bytes of this chunk of data. Must be a multiple of 4.
77 uint16_t offset;
78 // Followed by a chunk of the microapp binary.
79};
80
81struct __attribute__((packed)) microapp_message_t {
83 uint8_t payload[0];
84};
85
89struct __attribute__((packed)) microapp_sdk_version_t {
90 uint8_t major;
91 uint8_t minor;
92};
93
99};
100
101const uint8_t MICROAPP_FUNCTION_NONE = 255;
102
108struct __attribute__((packed)) microapp_state_t {
109 // Checksum of the microapp, should be equal to the checksum field of the binary.
110 uint16_t checksum;
111 // Checksum of the microapp, should be equal to the checksumHeader field of the binary.
113 // Whether the storage space of this app contains data.
114 bool hasData : 1;
115 // values: MICROAPP_TEST_STATE
116 uint8_t checksumTest : 2;
117 // Whether the microapp is enabled.
118 bool enabled : 1;
119 // Values: MICROAPP_TEST_STATE. Checks if the microapp starts, registers callback function in
120 // IPC, and returns to firmware.
121 uint8_t bootTest : 2;
122 // values: ok, excessive
123 uint8_t memoryUsage : 1;
124 // Did reboot
125 uint8_t didReboot : 1;
126 // Whether a call to the microapp took too long to yield.
128 // Reserved, must be 0 for now.
129 uint16_t reservedTest : 7;
130 // Index of registered function that didn't pass yet, and that we are calling now. MICROAPP_FUNCTION_NONE for none.
131 uint8_t tryingFunction = MICROAPP_FUNCTION_NONE;
132 // Index of registered function that was tried, but didn't pass. MICROAPP_FUNCTION_NONE for none.
133 uint8_t failedFunction = MICROAPP_FUNCTION_NONE;
134 // Bitmask of registered functions that were called and returned to firmware successfully.
136};
137
141struct __attribute__((packed)) microapp_status_t {
142 uint32_t buildVersion; // Build version of this microapp.
143 microapp_sdk_version_t sdkVersion; // SDK version this microapp was built for.
145};
146
150struct __attribute__((packed)) microapp_info_t {
151 // Protocol of this packet, and the microapp command packets.
153 uint8_t maxApps = g_MICROAPP_COUNT; // Maximum number of microapps.
154 uint16_t maxAppSize = MICROAPP_MAX_SIZE; // Maximum binary size of a microapp.
155 uint16_t maxChunkSize = MICROAPP_UPLOAD_MAX_CHUNK_SIZE; // Maximum chunk size for uploading a microapp.
156 uint16_t maxRamUsage = g_RAM_MICROAPP_AMOUNT; // Maximum RAM usage of a microapp.
157 microapp_sdk_version_t sdkVersion; // SDK version the firmware supports.
158 microapp_status_t appsStatus[g_MICROAPP_COUNT]; // Status of each microapp.
159};
const uint16_t g_RAM_MICROAPP_AMOUNT
Amount of ram each microapp can use.
constexpr uint16_t MICROAPP_MAX_SIZE
Max flash size of a microapp, must be a multiple of flash page size.
Definition: cs_MicroappPackets.h:40
constexpr uint16_t MICROAPP_UPLOAD_MAX_CHUNK_SIZE
Max allowed chunk size when uploading a microapp.
Definition: cs_MicroappPackets.h:22
constexpr uint8_t MICROAPP_SDK_MAJOR
SDK major version of the data going back and forth between microapp and bluenet within the mutually s...
Definition: cs_MicroappPackets.h:32
const uint8_t MICROAPP_FUNCTION_NONE
Definition: cs_MicroappPackets.h:101
constexpr uint8_t MICROAPP_INDEX_NONE
Invalid microapp index.
Definition: cs_MicroappPackets.h:43
constexpr uint8_t MICROAPP_CONTROL_COMMAND_PROTOCOL
Protocol version of the communication over the command handler, the microapp command and result packe...
Definition: cs_MicroappPackets.h:27
MICROAPP_TEST_STATE
Definition: cs_MicroappPackets.h:94
@ MICROAPP_TEST_STATE_TRYING
Definition: cs_MicroappPackets.h:96
@ MICROAPP_TEST_STATE_FAILED
Definition: cs_MicroappPackets.h:97
@ MICROAPP_TEST_STATE_PASSED
Definition: cs_MicroappPackets.h:98
@ MICROAPP_TEST_STATE_UNTESTED
Definition: cs_MicroappPackets.h:95
constexpr uint8_t MICROAPP_SDK_MINOR
SDK minor version of the data going back and forth between microapp and bluenet within the mutually s...
Definition: cs_MicroappPackets.h:37
Header of a microapp binary.
Definition: cs_MicroappPackets.h:51
uint16_t size
Definition: cs_MicroappPackets.h:54
uint8_t sdkVersionMinor
Definition: cs_MicroappPackets.h:53
uint16_t checksumHeader
Definition: cs_MicroappPackets.h:57
uint8_t sdkVersionMajor
Definition: cs_MicroappPackets.h:52
uint32_t reserved2
Definition: cs_MicroappPackets.h:64
uint16_t startOffset
Definition: cs_MicroappPackets.h:61
uint16_t checksum
Definition: cs_MicroappPackets.h:56
uint32_t appBuildVersion
Definition: cs_MicroappPackets.h:59
uint16_t reserved
Definition: cs_MicroappPackets.h:62
Definition: cs_MicroappPackets.h:67
uint8_t protocol
Definition: cs_MicroappPackets.h:69
uint8_t index
Definition: cs_MicroappPackets.h:71
Packet with all info required to upload a microapp, and to see the status of already uploaded microap...
Definition: cs_MicroappPackets.h:150
microapp_sdk_version_t sdkVersion
Definition: cs_MicroappPackets.h:157
Definition: cs_MicroappPackets.h:81
microapp_ctrl_header_t header
Definition: cs_MicroappPackets.h:82
SDK version: determines the API / protocol between microapp and firmware.
Definition: cs_MicroappPackets.h:89
uint8_t minor
Definition: cs_MicroappPackets.h:91
uint8_t major
Definition: cs_MicroappPackets.h:90
State of tests of a microapp, also stored in flash.
Definition: cs_MicroappPackets.h:108
uint8_t checksumTest
Definition: cs_MicroappPackets.h:116
uint8_t memoryUsage
Definition: cs_MicroappPackets.h:123
uint8_t bootTest
Definition: cs_MicroappPackets.h:121
uint16_t reservedTest
Definition: cs_MicroappPackets.h:129
bool enabled
Definition: cs_MicroappPackets.h:118
bool exceededCallDuration
Definition: cs_MicroappPackets.h:127
bool hasData
Definition: cs_MicroappPackets.h:114
uint16_t checksum
Definition: cs_MicroappPackets.h:110
uint16_t checksumHeader
Definition: cs_MicroappPackets.h:112
uint8_t didReboot
Definition: cs_MicroappPackets.h:125
uint32_t passedFunctions
Definition: cs_MicroappPackets.h:135
Status of a microapp.
Definition: cs_MicroappPackets.h:141
microapp_sdk_version_t sdkVersion
Definition: cs_MicroappPackets.h:143
microapp_state_t state
Definition: cs_MicroappPackets.h:144
uint32_t buildVersion
Definition: cs_MicroappPackets.h:142
Definition: cs_MicroappPackets.h:74
microapp_ctrl_header_t header
Definition: cs_MicroappPackets.h:75
uint16_t offset
Definition: cs_MicroappPackets.h:77