Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
platform.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
40 #ifndef CA821X_OPENTHREAD_PLATFORM_PLATFORM_H_
41 #define CA821X_OPENTHREAD_PLATFORM_PLATFORM_H_
42 
43 #include <stdint.h>
44 #include "openthread/instance.h"
45 #include "openthread/platform/radio.h"
46 #include "ca821x_api.h"
47 
49 
50 extern otInstance *OT_INSTANCE;
51 
52 #define SuccessOrExit(aCondition) \
53  do \
54  { \
55  if ((aCondition) != 0) \
56  { \
57  goto exit; \
58  } \
59  } while (0)
60 
62 {
65 };
66 
68 static const uint16_t joiner_credential_key = 0xCA50;
70 static const uint16_t autostart_key = 0xCA51;
72 static const uint16_t sensordemo_key = 0xCA5C;
74 static const uint16_t actuatordemo_key = 0xCA5D;
76 static const uint16_t stack_profiler_key = 0xCA5E;
78 static const uint16_t OC_SETTINGS_KEY = 0xe107;
80 static const uint16_t OC_ENCRYPTION_KEY_KEY = 0xe108;
81 
88 struct ca821x_dev *PlatformGetDeviceRef(void);
89 
98 int PlatformRadioInit(void);
99 
110 int PlatformRadioInitWithDev(struct ca821x_dev *pDeviceRef);
111 
123 int PlatformRadioInitWithDevEui64(struct ca821x_dev *apDeviceRef, uint8_t *pEui64);
124 
135 
140 void PlatformRadioStop(void);
141 
145 void PlatformAlarmInit(void);
146 
154 otError PlatformSleep(uint32_t aSleepTime);
155 
162 bool PlatformCanSleep(otInstance *aInstance);
163 
172 otError PlatformUartReceive(const uint8_t *aBuf, uint16_t aBufLength);
173 
188 otError PlatformTryJoin(struct ca821x_dev *pDeviceRef, otInstance *aInstance);
189 
203 otError PlatformTryJoinWithCustomPoll(struct ca821x_dev *pDeviceRef, otInstance *aInstance, void (*poll_func)(void));
204 
222 otError PlatformTryJoinWithPskd(struct ca821x_dev *pDeviceRef, otInstance *aInstance, const char *aPskd);
223 
238 otError PlatformTryJoinWithPskdWithCustomPoll(struct ca821x_dev *pDeviceRef,
239  otInstance *aInstance,
240  const char *aPskd,
241  void (*poll_func)(void));
242 
255 otError PlatformPrintJoinerCredentials(struct ca821x_dev *pDeviceRef, otInstance *aInstance, uint32_t aMaxWaitMs);
256 
270 otError PlatformPrintJoinerCredentialsWithPskd(struct ca821x_dev *pDeviceRef,
271  otInstance *aInstance,
272  uint32_t aMaxWaitMs,
273  const char *aPskd);
274 
280 otError PlatformEraseJoinerCredentials(otInstance *aInstance);
281 
288 const char *PlatformGetJoinerCredential(otInstance *aInstance);
289 
308 otError otPlatSettingsGetAddress(uint16_t aKey, int aIndex, void **aValue, uint16_t *aValueLength);
309 
337 otError otPlatSettingsAddVector(otInstance *aInstance, uint16_t aKey, struct settingBuffer *aVector, size_t aCount);
338 
349 otError PlatformGetQRString(char *aBufOut, size_t bufferSize, otInstance *aInstance);
350 
351 #endif /* CA821X_OPENTHREAD_PLATFORM_PLATFORM_H_ */
352 
The main ca821x-api include file.
This file includes platform abstraction for non-volatile storage of settings.
openthread_message_codes
Definition: platform.h:62
otError PlatformGetQRString(char *aBufOut, size_t bufferSize, otInstance *aInstance)
Get the QR text string format to be read as a Thread Connect QR Code, enabling external commissioning...
Definition: misc.c:396
int PlatformIsExpectingIndication(void)
Determines whether or not an MCPS-DATA-INDICATION is currently expected, based on the result of the p...
Definition: radio.c:704
int PlatformRadioInitWithDev(struct ca821x_dev *pDeviceRef)
Initialise the openthread platform layer with apDeviceRef as the device.
Definition: radio.c:652
otError PlatformTryJoinWithPskdWithCustomPoll(struct ca821x_dev *pDeviceRef, otInstance *aInstance, const char *aPskd, void(*poll_func)(void))
Identiacl to PlatformTryJoinWithPsdk(), except that an additional poll function can be provided,...
Definition: misc.c:261
otError PlatformEraseJoinerCredentials(otInstance *aInstance)
Helper function to erase the joiner credentials of this device.
Definition: misc.c:345
otError PlatformUartReceive(const uint8_t *aBuf, uint16_t aBufLength)
Handle received serial data.
Definition: serial.c:72
bool PlatformCanSleep(otInstance *aInstance)
Check whether the platform is able to sleep.
Definition: misc.c:86
otError PlatformSleep(uint32_t aSleepTime)
Sends the platform and cax to sleep for the given number of milliseconds.
Definition: misc.c:79
otInstance * OT_INSTANCE
Definition: thread_dev_main.c:34
otError otPlatSettingsGetAddress(uint16_t aKey, int aIndex, void **aValue, uint16_t *aValueLength)
Get the address at which a setting is stored, so that it can be read without copying it,...
Definition: settings.c:118
otError otPlatSettingsAddVector(otInstance *aInstance, uint16_t aKey, struct settingBuffer *aVector, size_t aCount)
This function adds the value to a setting identified by aKey, without replacing any existing values.
Definition: settings.c:141
otError PlatformTryJoin(struct ca821x_dev *pDeviceRef, otInstance *aInstance)
Helper function to attempt the Thread joining process.
Definition: misc.c:328
int PlatformRadioInit(void)
Initialise the openthread platform layer with the internal device struct.
Definition: radio.c:668
void PlatformAlarmInit(void)
Initialise the platform alarm subsystem.
Definition: alarm.c:65
struct ca821x_dev * PlatformGetDeviceRef(void)
Following Initialisation, this can be used to obtain the pDeviceRef that openthread is using.
Definition: radio.c:78
otError PlatformTryJoinWithPskd(struct ca821x_dev *pDeviceRef, otInstance *aInstance, const char *aPskd)
Helper function to attempt the Thread joining process, with an explicit passcode.
Definition: misc.c:225
int PlatformRadioInitWithDevEui64(struct ca821x_dev *apDeviceRef, uint8_t *pEui64)
Initialise the openthread platform layer with pDeviceRef as the device, and pEui64 as the EUI64.
Definition: radio.c:660
const char * PlatformGetJoinerCredential(otInstance *aInstance)
Helper function to get the joiner credential of this device.
Definition: misc.c:176
otError PlatformPrintJoinerCredentials(struct ca821x_dev *pDeviceRef, otInstance *aInstance, uint32_t aMaxWaitMs)
Helper function to print the Thread Joiner credentials (for instance, upon boot).
Definition: misc.c:339
otError PlatformTryJoinWithCustomPoll(struct ca821x_dev *pDeviceRef, otInstance *aInstance, void(*poll_func)(void))
Identical to PlatformTryJoin(), except that an additional poll function can be provided,...
Definition: misc.c:333
void PlatformRadioStop(void)
Stop and reset the CA-821x.
Definition: radio.c:599
otError PlatformPrintJoinerCredentialsWithPskd(struct ca821x_dev *pDeviceRef, otInstance *aInstance, uint32_t aMaxWaitMs, const char *aPskd)
Helper function to print the Thread Joiner credentials, with an explicit passcode (for instance,...
Definition: misc.c:302
@ OT_SERIAL_DOWNLINK
Definition: platform.h:63
@ OT_SERIAL_UPLINK
Definition: platform.h:64
CA-821x Device reference struct.
Definition: ca821x_api.h:123
Data structure for vectored I/O using caUtilSettingsAddVector.
Definition: cascoda_settings.h:56