mirror of
https://github.com/espressif/openthread.git
synced 2026-10-26 09:13:52 +00:00
[posix] extract co-processor init out of otSysInit (#10344)
This commit adds a new posix sys API `otSysInitCoprocessor` which only initializes the platform spinel component. (Reset the co-processor and get the type) The intention is to let the app to get the co-processor type without creating the otInstance. Currently only `otSysInit` can be called which creates the otInstance. However in some cases, we don't want to create the instance at the early stage.
This commit is contained in:
+5
-3
@@ -275,12 +275,14 @@ static void ParseArg(int aArgCount, char *aArgVector[], PosixConfig *aConfig)
|
|||||||
|
|
||||||
for (; optind < aArgCount; optind++)
|
for (; optind < aArgCount; optind++)
|
||||||
{
|
{
|
||||||
VerifyOrDie(aConfig->mPlatformConfig.mRadioUrlNum < OT_ARRAY_LENGTH(aConfig->mPlatformConfig.mRadioUrls),
|
VerifyOrDie(aConfig->mPlatformConfig.mCoprocessorUrls.mNum <
|
||||||
|
OT_ARRAY_LENGTH(aConfig->mPlatformConfig.mCoprocessorUrls.mUrls),
|
||||||
OT_EXIT_INVALID_ARGUMENTS);
|
OT_EXIT_INVALID_ARGUMENTS);
|
||||||
aConfig->mPlatformConfig.mRadioUrls[aConfig->mPlatformConfig.mRadioUrlNum++] = aArgVector[optind];
|
aConfig->mPlatformConfig.mCoprocessorUrls.mUrls[aConfig->mPlatformConfig.mCoprocessorUrls.mNum++] =
|
||||||
|
aArgVector[optind];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aConfig->mPlatformConfig.mRadioUrlNum == 0)
|
if (aConfig->mPlatformConfig.mCoprocessorUrls.mNum == 0)
|
||||||
{
|
{
|
||||||
PrintUsage(aArgVector[0], stderr, OT_EXIT_INVALID_ARGUMENTS);
|
PrintUsage(aArgVector[0], stderr, OT_EXIT_INVALID_ARGUMENTS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,25 +69,49 @@ enum
|
|||||||
OT_PLATFORM_CONFIG_MAX_RADIO_URLS = 2, ///< Max number of Radio URLs.
|
OT_PLATFORM_CONFIG_MAX_RADIO_URLS = 2, ///< Max number of Radio URLs.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the Co-processor URLs.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef struct otPlatformCoprocessorUrls
|
||||||
|
{
|
||||||
|
const char *mUrls[OT_PLATFORM_CONFIG_MAX_RADIO_URLS]; ///< Co-processor URLs.
|
||||||
|
uint8_t mNum; ///< Number of Co-processor URLs.
|
||||||
|
} otPlatformCoprocessorUrls;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents platform specific configurations.
|
* Represents platform specific configurations.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct otPlatformConfig
|
typedef struct otPlatformConfig
|
||||||
{
|
{
|
||||||
const char *mBackboneInterfaceName; ///< Backbone network interface name.
|
const char *mBackboneInterfaceName; ///< Backbone network interface name.
|
||||||
const char *mInterfaceName; ///< Thread network interface name.
|
const char *mInterfaceName; ///< Thread network interface name.
|
||||||
const char *mRadioUrls[OT_PLATFORM_CONFIG_MAX_RADIO_URLS]; ///< Radio URLs.
|
otPlatformCoprocessorUrls mCoprocessorUrls; ///< Coprocessor URLs.
|
||||||
uint8_t mRadioUrlNum; ///< Number of Radio URLs.
|
int mRealTimeSignal; ///< The real-time signal for microsecond timer.
|
||||||
int mRealTimeSignal; ///< The real-time signal for microsecond timer.
|
uint32_t mSpeedUpFactor; ///< Speed up factor.
|
||||||
uint32_t mSpeedUpFactor; ///< Speed up factor.
|
bool mPersistentInterface; ///< Whether persistent the interface
|
||||||
bool mPersistentInterface; ///< Whether persistent the interface
|
bool mDryRun; ///< If 'DryRun' is set, the posix daemon will exit
|
||||||
bool mDryRun; ///< If 'DryRun' is set, the posix daemon will exit
|
///< directly after initialization.
|
||||||
///< directly after initialization.
|
CoprocessorType mCoprocessorType; ///< The co-processor type. This field is used to pass
|
||||||
CoprocessorType mCoprocessorType; ///< The co-processor type. This field is used to pass
|
///< the type to the app layer.
|
||||||
///< the type to the app layer.
|
|
||||||
} otPlatformConfig;
|
} otPlatformConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the co-processor and the spinel driver.
|
||||||
|
*
|
||||||
|
* @note This API will initialize the co-processor by resetting it and return the co-processor type.
|
||||||
|
* If this API is called, the upcoming call of `otSysInit` won't initialize the co-processor
|
||||||
|
* and the spinel driver again, unless `otSysDeinit` is called. This API is used to get the
|
||||||
|
* co-processor type without calling `otSysInit`.
|
||||||
|
*
|
||||||
|
* @param[in] aUrls The URLs to initialize the co-processor.
|
||||||
|
*
|
||||||
|
* @returns The co-processor type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
CoprocessorType otSysInitCoprocessor(otPlatformCoprocessorUrls *aUrls);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs all platform-specific initialization of OpenThread's drivers and initializes the OpenThread
|
* Performs all platform-specific initialization of OpenThread's drivers and initializes the OpenThread
|
||||||
* instance.
|
* instance.
|
||||||
|
|||||||
@@ -82,20 +82,20 @@ static void processStateChange(otChangedFlags aFlags, void *aContext)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *get802154RadioUrl(otPlatformConfig *aPlatformConfig)
|
static const char *get802154RadioUrl(const otPlatformCoprocessorUrls &aUrls)
|
||||||
{
|
{
|
||||||
const char *radioUrl = nullptr;
|
const char *radioUrl = nullptr;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < aPlatformConfig->mRadioUrlNum; i++)
|
for (uint8_t i = 0; i < aUrls.mNum; i++)
|
||||||
{
|
{
|
||||||
ot::Posix::RadioUrl url(aPlatformConfig->mRadioUrls[i]);
|
ot::Posix::RadioUrl url(aUrls.mUrls[i]);
|
||||||
|
|
||||||
if (strcmp(url.GetProtocol(), "trel") == 0)
|
if (strcmp(url.GetProtocol(), "trel") == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
radioUrl = aPlatformConfig->mRadioUrls[i];
|
radioUrl = aUrls.mUrls[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +108,13 @@ static const char *getTrelRadioUrl(otPlatformConfig *aPlatformConfig)
|
|||||||
{
|
{
|
||||||
const char *radioUrl = nullptr;
|
const char *radioUrl = nullptr;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < aPlatformConfig->mRadioUrlNum; i++)
|
for (uint8_t i = 0; i < aPlatformConfig->mCoprocessorUrls.mNum; i++)
|
||||||
{
|
{
|
||||||
ot::Posix::RadioUrl url(aPlatformConfig->mRadioUrls[i]);
|
ot::Posix::RadioUrl url(aPlatformConfig->mCoprocessorUrls.mUrls[i]);
|
||||||
|
|
||||||
if (strcmp(url.GetProtocol(), "trel") == 0)
|
if (strcmp(url.GetProtocol(), "trel") == 0)
|
||||||
{
|
{
|
||||||
radioUrl = aPlatformConfig->mRadioUrls[i];
|
radioUrl = aPlatformConfig->mCoprocessorUrls.mUrls[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ void otSysSetInfraNetif(const char *aInfraNetifName, int aIcmp6Socket)
|
|||||||
|
|
||||||
void platformInitRcpMode(otPlatformConfig *aPlatformConfig)
|
void platformInitRcpMode(otPlatformConfig *aPlatformConfig)
|
||||||
{
|
{
|
||||||
platformRadioInit(get802154RadioUrl(aPlatformConfig));
|
platformRadioInit(get802154RadioUrl(aPlatformConfig->mCoprocessorUrls));
|
||||||
|
|
||||||
// For Dry-Run option, only init the co-processor.
|
// For Dry-Run option, only init the co-processor.
|
||||||
VerifyOrExit(!aPlatformConfig->mDryRun);
|
VerifyOrExit(!aPlatformConfig->mDryRun);
|
||||||
@@ -181,7 +181,10 @@ void platformInit(otPlatformConfig *aPlatformConfig)
|
|||||||
|
|
||||||
platformAlarmInit(aPlatformConfig->mSpeedUpFactor, aPlatformConfig->mRealTimeSignal);
|
platformAlarmInit(aPlatformConfig->mSpeedUpFactor, aPlatformConfig->mRealTimeSignal);
|
||||||
|
|
||||||
sCoprocessorType = platformSpinelManagerInit(get802154RadioUrl(aPlatformConfig));
|
if (sCoprocessorType == OT_COPROCESSOR_UNKNOWN)
|
||||||
|
{
|
||||||
|
sCoprocessorType = platformSpinelManagerInit(get802154RadioUrl(aPlatformConfig->mCoprocessorUrls));
|
||||||
|
}
|
||||||
|
|
||||||
switch (sCoprocessorType)
|
switch (sCoprocessorType)
|
||||||
{
|
{
|
||||||
@@ -249,6 +252,12 @@ exit:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoprocessorType otSysInitCoprocessor(otPlatformCoprocessorUrls *aUrls)
|
||||||
|
{
|
||||||
|
sCoprocessorType = platformSpinelManagerInit(get802154RadioUrl(*aUrls));
|
||||||
|
return sCoprocessorType;
|
||||||
|
}
|
||||||
|
|
||||||
otInstance *otSysInit(otPlatformConfig *aPlatformConfig)
|
otInstance *otSysInit(otPlatformConfig *aPlatformConfig)
|
||||||
{
|
{
|
||||||
OT_ASSERT(gInstance == nullptr);
|
OT_ASSERT(gInstance == nullptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user