mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 15:17:47 +00:00
otInstance Declarations (#473)
* Add otInstance type declaration and update ot APIs to take it as input.
This commit is contained in:
@@ -34,6 +34,7 @@ bin_PROGRAMS = \
|
||||
|
||||
ot_cli_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -26,31 +26,61 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread.h>
|
||||
#include <openthread-config.h>
|
||||
#include <openthread-diag.h>
|
||||
#include <cli/cli-uart.h>
|
||||
#include <platform/platform.h>
|
||||
#include <assert.h>
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
void otSignalTaskletPending(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
otInstance *sInstance;
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
uint64_t otInstanceBufferLength = 0;
|
||||
uint8_t *otInstanceBuffer = NULL;
|
||||
#endif
|
||||
|
||||
PlatformInit(argc, argv);
|
||||
otEnable();
|
||||
otCliUartInit();
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
// Call to query the buffer size
|
||||
(void)otInstanceInit(NULL, &otInstanceBufferLength);
|
||||
|
||||
// Call to allocate the buffer
|
||||
otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength);
|
||||
assert(otInstanceBuffer);
|
||||
|
||||
// Initialize Openthread with the buffer
|
||||
sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
|
||||
#else
|
||||
sInstance = otInstanceInit();
|
||||
#endif
|
||||
assert(sInstance);
|
||||
|
||||
otCliUartInit(sInstance);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
diagInit();
|
||||
diagInit(sInstance);
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
otProcessNextTasklet();
|
||||
PlatformProcessDrivers();
|
||||
otProcessNextTasklet(sInstance);
|
||||
PlatformProcessDrivers(sInstance);
|
||||
}
|
||||
|
||||
// otInstanceFinalize(sInstance);
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
// free(otInstanceBuffer);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ bin_PROGRAMS = \
|
||||
|
||||
ot_ncp_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -26,31 +26,61 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread.h>
|
||||
#include <openthread-config.h>
|
||||
#include <openthread-diag.h>
|
||||
#include <common/debug.hpp>
|
||||
#include <ncp/ncp.h>
|
||||
#include <platform/platform.h>
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
void otSignalTaskletPending(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
otInstance *sInstance;
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
uint64_t otInstanceBufferLength = 0;
|
||||
uint8_t *otInstanceBuffer = NULL;
|
||||
#endif
|
||||
|
||||
PlatformInit(argc, argv);
|
||||
otEnable();
|
||||
otNcpInit();
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
// Call to query the buffer size
|
||||
(void)otInstanceInit(NULL, &otInstanceBufferLength);
|
||||
|
||||
// Call to allocate the buffer
|
||||
otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength);
|
||||
assert(otInstanceBuffer);
|
||||
|
||||
// Initialize Openthread with the buffer
|
||||
sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
|
||||
#else
|
||||
sInstance = otInstanceInit();
|
||||
#endif
|
||||
assert(sInstance);
|
||||
|
||||
otNcpInit(sInstance);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
diagInit();
|
||||
diagInit(sInstance);
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
otProcessNextTasklet();
|
||||
PlatformProcessDrivers();
|
||||
otProcessNextTasklet(sInstance);
|
||||
PlatformProcessDrivers(sInstance);
|
||||
}
|
||||
|
||||
// otInstanceFinalize(sInstance);
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
// free(otInstanceBuffer);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ lib_LIBRARIES = libopenthread-cc2538.a
|
||||
|
||||
libopenthread_cc2538_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
-I$(top_srcdir)/src/core \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include <openthread.h>
|
||||
|
||||
#include <platform/platform.h>
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/diag.h>
|
||||
#include "platform-cc2538.h"
|
||||
@@ -62,19 +65,21 @@ uint32_t otPlatAlarmGetNow(void)
|
||||
return sCounter;
|
||||
}
|
||||
|
||||
void otPlatAlarmStartAt(uint32_t t0, uint32_t dt)
|
||||
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)
|
||||
{
|
||||
(void)aInstance;
|
||||
sAlarmT0 = t0;
|
||||
sAlarmDt = dt;
|
||||
sIsRunning = true;
|
||||
}
|
||||
|
||||
void otPlatAlarmStop(void)
|
||||
void otPlatAlarmStop(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
sIsRunning = false;
|
||||
}
|
||||
|
||||
void cc2538AlarmProcess(void)
|
||||
void cc2538AlarmProcess(otInstance *aInstance)
|
||||
{
|
||||
uint32_t expires;
|
||||
bool fire = false;
|
||||
@@ -106,12 +111,12 @@ void cc2538AlarmProcess(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagAlarmFired();
|
||||
otPlatDiagAlarmFired(aInstance);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatAlarmFired();
|
||||
otPlatAlarmFired(aInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include <openthread.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
|
||||
@@ -26,16 +26,19 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
#include <platform/misc.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
void otPlatReset(void)
|
||||
void otPlatReset(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
HWREG(SYS_CTRL_PWRDBG) = SYS_CTRL_PWRDBG_FORCE_WARM_RESET;
|
||||
}
|
||||
|
||||
otPlatResetReason otPlatGetResetReason(void)
|
||||
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
// TODO: Write me!
|
||||
return kPlatResetReason_PowerOn;
|
||||
}
|
||||
|
||||
@@ -36,9 +36,13 @@
|
||||
#define PLATFORM_CC2538_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <openthread-types.h>
|
||||
|
||||
#include "cc2538-reg.h"
|
||||
|
||||
// Global OpenThread instance structure
|
||||
extern otInstance *sInstance;
|
||||
|
||||
/**
|
||||
* This function initializes the alarm service used by OpenThread.
|
||||
*
|
||||
@@ -48,8 +52,10 @@ void cc2538AlarmInit(void);
|
||||
/**
|
||||
* This function performs alarm driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void cc2538AlarmProcess(void);
|
||||
void cc2538AlarmProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the radio service used by OpenThread.
|
||||
@@ -60,8 +66,10 @@ void cc2538RadioInit(void);
|
||||
/**
|
||||
* This function performs radio driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void cc2538RadioProcess(void);
|
||||
void cc2538RadioProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the random number service used by OpenThread.
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include <platform/uart.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
otInstance *sInstance;
|
||||
|
||||
void PlatformInit(int argc, char *argv[])
|
||||
{
|
||||
cc2538AlarmInit();
|
||||
@@ -46,11 +48,13 @@ void PlatformInit(int argc, char *argv[])
|
||||
(void)argv;
|
||||
}
|
||||
|
||||
void PlatformProcessDrivers(void)
|
||||
void PlatformProcessDrivers(otInstance *aInstance)
|
||||
{
|
||||
sInstance = aInstance;
|
||||
|
||||
// should sleep and wait for interrupts here
|
||||
|
||||
cc2538UartProcess();
|
||||
cc2538RadioProcess();
|
||||
cc2538AlarmProcess();
|
||||
cc2538RadioProcess(aInstance);
|
||||
cc2538AlarmProcess(aInstance);
|
||||
}
|
||||
|
||||
@@ -33,9 +33,11 @@
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
#include <openthread.h>
|
||||
#include <openthread-config.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/platform.h>
|
||||
#include <platform/radio.h>
|
||||
#include <platform/diag.h>
|
||||
#include "platform-cc2538.h"
|
||||
@@ -109,9 +111,10 @@ void setChannel(uint8_t channel)
|
||||
HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetPanId(uint16_t panid)
|
||||
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateTransmit)
|
||||
{
|
||||
@@ -123,9 +126,10 @@ ThreadError otPlatRadioSetPanId(uint16_t panid)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
|
||||
ThreadError otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateTransmit)
|
||||
{
|
||||
@@ -142,9 +146,10 @@ ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetShortAddress(uint16_t address)
|
||||
ThreadError otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateTransmit)
|
||||
{
|
||||
@@ -183,9 +188,10 @@ void cc2538RadioInit(void)
|
||||
HWREG(RFCORE_XREG_SRCMATCH) = 0;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(void)
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateDisabled)
|
||||
{
|
||||
@@ -196,9 +202,10 @@ ThreadError otPlatRadioEnable(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(void)
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateDisabled || sState == kStateSleep)
|
||||
{
|
||||
@@ -209,14 +216,16 @@ ThreadError otPlatRadioDisable(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
bool otPlatRadioIsEnabled(void)
|
||||
bool otPlatRadioIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (sState != kStateDisabled) ? true : false;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSleep(void)
|
||||
ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateReceive)
|
||||
{
|
||||
@@ -228,9 +237,10 @@ ThreadError otPlatRadioSleep(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioReceive(uint8_t aChannel)
|
||||
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateDisabled)
|
||||
{
|
||||
@@ -244,9 +254,10 @@ ThreadError otPlatRadioReceive(uint8_t aChannel)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioTransmit(void)
|
||||
ThreadError otPlatRadioTransmit(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateReceive)
|
||||
{
|
||||
@@ -291,28 +302,34 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
RadioPacket *otPlatRadioGetTransmitBuffer(void)
|
||||
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return &sTransmitFrame;
|
||||
}
|
||||
|
||||
int8_t otPlatRadioGetRssi(void)
|
||||
int8_t otPlatRadioGetRssi(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return 0;
|
||||
}
|
||||
|
||||
otRadioCaps otPlatRadioGetCaps(void)
|
||||
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return kRadioCapsNone;
|
||||
}
|
||||
|
||||
bool otPlatRadioGetPromiscuous(void)
|
||||
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPromiscuous(bool aEnable)
|
||||
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
if (aEnable)
|
||||
{
|
||||
HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;
|
||||
@@ -363,7 +380,7 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void cc2538RadioProcess(void)
|
||||
void cc2538RadioProcess(otInstance *aInstance)
|
||||
{
|
||||
readFrame();
|
||||
|
||||
@@ -373,12 +390,12 @@ void cc2538RadioProcess(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioReceiveDone(&sReceiveFrame, sReceiveError);
|
||||
otPlatDiagRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioReceiveDone(&sReceiveFrame, sReceiveError);
|
||||
otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,12 +409,12 @@ void cc2538RadioProcess(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(false, sTransmitError);
|
||||
otPlatDiagRadioTransmitDone(aInstance, false, sTransmitError);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone(false, sTransmitError);
|
||||
otPlatRadioTransmitDone(aInstance, false, sTransmitError);
|
||||
}
|
||||
}
|
||||
else if (sReceiveFrame.mLength == IEEE802154_ACK_LENGTH &&
|
||||
@@ -410,12 +427,12 @@ void cc2538RadioProcess(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
otPlatDiagRadioTransmitDone(aInstance, (sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
otPlatRadioTransmitDone(aInstance, (sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,11 +103,11 @@ ThreadError otPlatRandomSecureGet(uint16_t aInputLength, uint8_t *aOutput, uint1
|
||||
|
||||
VerifyOrExit(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
|
||||
|
||||
if (otPlatRadioIsEnabled())
|
||||
if (otPlatRadioIsEnabled(sInstance))
|
||||
{
|
||||
channel = 11 + (HWREG(RFCORE_XREG_FREQCTRL) - 11) / 5;
|
||||
otPlatRadioSleep();
|
||||
otPlatRadioDisable();
|
||||
otPlatRadioSleep(sInstance);
|
||||
otPlatRadioDisable(sInstance);
|
||||
}
|
||||
|
||||
generateRandom(aInputLength, aOutput, aOutputLength);
|
||||
@@ -115,8 +115,8 @@ ThreadError otPlatRandomSecureGet(uint16_t aInputLength, uint8_t *aOutput, uint1
|
||||
if (channel)
|
||||
{
|
||||
cc2538RadioInit();
|
||||
otPlatRadioEnable();
|
||||
otPlatRadioReceive(channel);
|
||||
otPlatRadioEnable(sInstance);
|
||||
otPlatRadioReceive(sInstance, channel);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
@@ -32,6 +32,7 @@ lib_LIBRARIES = libopenthread-posix.a
|
||||
|
||||
libopenthread_posix_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-D_GNU_SOURCE \
|
||||
$(NULL)
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <openthread-config.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/diag.h>
|
||||
#include "platform-posix.h"
|
||||
@@ -55,14 +57,16 @@ uint32_t otPlatAlarmGetNow(void)
|
||||
return (uint32_t)((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
|
||||
}
|
||||
|
||||
void otPlatAlarmStartAt(uint32_t t0, uint32_t dt)
|
||||
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)
|
||||
{
|
||||
(void)aInstance;
|
||||
s_alarm = t0 + dt;
|
||||
s_is_running = true;
|
||||
}
|
||||
|
||||
void otPlatAlarmStop(void)
|
||||
void otPlatAlarmStop(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
s_is_running = false;
|
||||
}
|
||||
|
||||
@@ -97,7 +101,7 @@ void posixAlarmUpdateTimeout(struct timeval *aTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
void posixAlarmProcess(void)
|
||||
void posixAlarmProcess(otInstance *aInstance)
|
||||
{
|
||||
int32_t remaining;
|
||||
|
||||
@@ -113,12 +117,12 @@ void posixAlarmProcess(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagAlarmFired();
|
||||
otPlatDiagAlarmFired(aInstance);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatAlarmFired();
|
||||
otPlatAlarmFired(aInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include <openthread.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include "platform-posix.h"
|
||||
|
||||
|
||||
@@ -26,15 +26,18 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
#include <platform/misc.h>
|
||||
#include "platform-posix.h"
|
||||
|
||||
void otPlatReset(void)
|
||||
void otPlatReset(otInstance *aInstance)
|
||||
{
|
||||
// This function does nothing on the Posix platform.
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
otPlatResetReason otPlatGetResetReason(void)
|
||||
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return kPlatResetReason_PowerOn;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
/**
|
||||
* Unique node ID.
|
||||
*
|
||||
@@ -68,8 +70,10 @@ void posixAlarmUpdateTimeout(struct timeval *tv);
|
||||
/**
|
||||
* This function performs alarm driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void posixAlarmProcess(void);
|
||||
void posixAlarmProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the radio service used by OpenThread.
|
||||
@@ -90,8 +94,10 @@ void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
|
||||
/**
|
||||
* This function performs radio driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void posixRadioProcess(void);
|
||||
void posixRadioProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the random number service used by OpenThread.
|
||||
|
||||
@@ -71,7 +71,7 @@ void PlatformInit(int argc, char *argv[])
|
||||
otPlatUartEnable();
|
||||
}
|
||||
|
||||
void PlatformProcessDrivers(void)
|
||||
void PlatformProcessDrivers(otInstance *aInstance)
|
||||
{
|
||||
fd_set read_fds;
|
||||
fd_set write_fds;
|
||||
@@ -88,7 +88,7 @@ void PlatformProcessDrivers(void)
|
||||
posixRadioUpdateFdSet(&read_fds, &write_fds, &max_fd);
|
||||
posixAlarmUpdateTimeout(&timeout);
|
||||
|
||||
if (!otAreTaskletsPending())
|
||||
if (!otAreTaskletsPending(aInstance))
|
||||
{
|
||||
rval = select(max_fd + 1, &read_fds, &write_fds, &error_fds, &timeout);
|
||||
|
||||
@@ -100,7 +100,7 @@ void PlatformProcessDrivers(void)
|
||||
}
|
||||
|
||||
posixUartProcess();
|
||||
posixRadioProcess();
|
||||
posixAlarmProcess();
|
||||
posixRadioProcess(aInstance);
|
||||
posixAlarmProcess(aInstance);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <openthread-config.h>
|
||||
|
||||
#include <platform/radio.h>
|
||||
#include <platform/diag.h>
|
||||
|
||||
@@ -95,9 +97,9 @@ struct OT_TOOL_PACKED_BEGIN RadioMessage
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
static void radioTransmit(const struct RadioMessage *msg, const struct RadioPacket *pkt);
|
||||
static void radioSendMessage(void);
|
||||
static void radioSendMessage(otInstance *aInstance);
|
||||
static void radioSendAck(void);
|
||||
static void radioProcessFrame(void);
|
||||
static void radioProcessFrame(otInstance *aInstance);
|
||||
|
||||
static PhyState sState = kStateDisabled;
|
||||
static struct RadioMessage sReceiveMessage;
|
||||
@@ -258,9 +260,10 @@ static inline void getExtAddress(const uint8_t *frame, otExtAddress *address)
|
||||
}
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetPanId(uint16_t panid)
|
||||
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateTransmit)
|
||||
{
|
||||
@@ -271,9 +274,10 @@ ThreadError otPlatRadioSetPanId(uint16_t panid)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
|
||||
ThreadError otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateTransmit)
|
||||
{
|
||||
@@ -290,9 +294,10 @@ ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetShortAddress(uint16_t address)
|
||||
ThreadError otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateTransmit)
|
||||
{
|
||||
@@ -303,8 +308,9 @@ ThreadError otPlatRadioSetShortAddress(uint16_t address)
|
||||
return error;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPromiscuous(bool aEnable)
|
||||
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
(void)aInstance;
|
||||
sPromiscuous = aEnable;
|
||||
}
|
||||
|
||||
@@ -351,9 +357,10 @@ void posixRadioInit(void)
|
||||
sAckFrame.mPsdu = sAckMessage.mPsdu;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(void)
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateDisabled)
|
||||
{
|
||||
@@ -364,9 +371,10 @@ ThreadError otPlatRadioEnable(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(void)
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateDisabled || sState == kStateSleep)
|
||||
{
|
||||
@@ -377,14 +385,16 @@ ThreadError otPlatRadioDisable(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
bool otPlatRadioIsEnabled(void)
|
||||
bool otPlatRadioIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (sState != kStateDisabled) ? true : false;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSleep(void)
|
||||
ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateReceive)
|
||||
{
|
||||
@@ -395,9 +405,10 @@ ThreadError otPlatRadioSleep(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioReceive(uint8_t aChannel)
|
||||
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateDisabled)
|
||||
{
|
||||
@@ -410,9 +421,10 @@ ThreadError otPlatRadioReceive(uint8_t aChannel)
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioTransmit(void)
|
||||
ThreadError otPlatRadioTransmit(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if ((sState == kStateTransmit && !sAckWait) || sState == kStateReceive)
|
||||
{
|
||||
@@ -423,27 +435,31 @@ ThreadError otPlatRadioTransmit(void)
|
||||
return error;
|
||||
}
|
||||
|
||||
RadioPacket *otPlatRadioGetTransmitBuffer(void)
|
||||
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return &sTransmitFrame;
|
||||
}
|
||||
|
||||
int8_t otPlatRadioGetRssi(void)
|
||||
int8_t otPlatRadioGetRssi(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return 0;
|
||||
}
|
||||
|
||||
otRadioCaps otPlatRadioGetCaps(void)
|
||||
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return kRadioCapsNone;
|
||||
}
|
||||
|
||||
bool otPlatRadioGetPromiscuous(void)
|
||||
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return sPromiscuous;
|
||||
}
|
||||
|
||||
void radioReceive(void)
|
||||
void radioReceive(otInstance *aInstance)
|
||||
{
|
||||
ssize_t rval = recvfrom(sSockFd, &sReceiveMessage, sizeof(sReceiveMessage), 0, NULL, NULL);
|
||||
|
||||
@@ -467,22 +483,22 @@ void radioReceive(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
otPlatDiagRadioTransmitDone(aInstance, isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
otPlatRadioTransmitDone(aInstance, isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
}
|
||||
}
|
||||
else if ((sState == kStateReceive || sState == kStateTransmit) &&
|
||||
(sReceiveFrame.mChannel == sReceiveMessage.mChannel))
|
||||
{
|
||||
radioProcessFrame();
|
||||
radioProcessFrame(aInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void radioSendMessage(void)
|
||||
void radioSendMessage(otInstance *aInstance)
|
||||
{
|
||||
sTransmitMessage.mChannel = sTransmitFrame.mChannel;
|
||||
|
||||
@@ -498,12 +514,12 @@ void radioSendMessage(void)
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(false, kThreadError_None);
|
||||
otPlatDiagRadioTransmitDone(aInstance, false, kThreadError_None);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone(false, kThreadError_None);
|
||||
otPlatRadioTransmitDone(aInstance, false, kThreadError_None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -531,19 +547,19 @@ void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
|
||||
}
|
||||
}
|
||||
|
||||
void posixRadioProcess(void)
|
||||
void posixRadioProcess(otInstance *aInstance)
|
||||
{
|
||||
const int flags = POLLIN | POLLRDNORM | POLLERR | POLLNVAL | POLLHUP;
|
||||
struct pollfd pollfd = { sSockFd, flags, 0 };
|
||||
|
||||
if (poll(&pollfd, 1, 0) > 0 && (pollfd.revents & flags) != 0)
|
||||
{
|
||||
radioReceive();
|
||||
radioReceive(aInstance);
|
||||
}
|
||||
|
||||
if (sState == kStateTransmit && !sAckWait)
|
||||
{
|
||||
radioSendMessage();
|
||||
radioSendMessage(aInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,7 +611,7 @@ void radioSendAck(void)
|
||||
radioTransmit(&sAckMessage, &sAckFrame);
|
||||
}
|
||||
|
||||
void radioProcessFrame(void)
|
||||
void radioProcessFrame(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
otPanId dstpan;
|
||||
@@ -644,12 +660,12 @@ exit:
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
otPlatDiagRadioReceiveDone(aInstance, error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
otPlatRadioReceiveDone(aInstance, error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user