Skip to content

Commit

Permalink
Work on config block (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Oct 9, 2018
1 parent 18b4abc commit 9f8e66f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMake/ChibiOS_target_os.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@

#define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@

#define HAS_CONFIG_BLOCK @NF_FEATURE_HAS_CONFIG_BLOCK@
#define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@

#endif /* _TARGET_OS_H_ */
2 changes: 1 addition & 1 deletion CMake/ESP32_target_os.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

#define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@

#define HAS_CONFIG_BLOCK @NF_FEATURE_HAS_CONFIG_BLOCK@
#define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@

#endif /* _TARGET_OS_H_ */
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ endif()
option(NF_FEATURE_HAS_CONFIG_BLOCK "option to enable configuration block storage")

if(NF_FEATURE_HAS_CONFIG_BLOCK)
set(TARGET_HAS_CONFIG_BLOCK TRUE CACHE INTERNAL "Option for config block")
message(STATUS "Configuration block storage is included")
else()
set(TARGET_HAS_CONFIG_BLOCK FALSE CACHE INTERNAL "Option for config block")
message(STATUS "Configuration block storage IS NOT included")
endif()

Expand Down
3 changes: 2 additions & 1 deletion src/HAL/Include/nanoHAL_ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev
void InitialiseWirelessDefaultConfig(HAL_Configuration_Wireless80211 * pconfig, uint32_t configurationIndex);

// Default initialisation for Network interface config blocks
void InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig, uint32_t configurationIndex);
// returns FALSE if it's not possible to create a default config block
bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig, uint32_t configurationIndex);

// helper functions

Expand Down
32 changes: 13 additions & 19 deletions targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ __nfweak bool ConfigurationManager_GetConfigurationBlock(void* configurationBloc
if(g_TargetConfiguration.NetworkInterfaceConfigs->Count == 0)
{
// there is no network config block, init one with default settings
InitialiseNetworkDefaultConfig(NULL, 0);
if(!InitialiseNetworkDefaultConfig(NULL, 0))
{
return FALSE;
}
}
else
{
Expand Down Expand Up @@ -116,10 +119,11 @@ __nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBl

if(configuration == DeviceConfigurationOption_Network)
{
if(g_TargetConfiguration.NetworkInterfaceConfigs->Count == 0 ||
if( g_TargetConfiguration.NetworkInterfaceConfigs->Count == 0 ||
(configurationIndex + 1) > g_TargetConfiguration.NetworkInterfaceConfigs->Count)
{
// there is no room for this block, fail the operation
// there is no room for this block, or there are no blocks stored at all
// failing the operation
return FALSE;
}

Expand All @@ -136,10 +140,11 @@ __nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBl
}
else if(configuration == DeviceConfigurationOption_Wireless80211Network)
{
if(g_TargetConfiguration.Wireless80211Configs->Count == 0 ||
if( g_TargetConfiguration.Wireless80211Configs->Count == 0 ||
(configurationIndex + 1) > g_TargetConfiguration.Wireless80211Configs->Count)
{
// there is no room for this block, fail the operation
// there is no room for this block, or there are no blocks stored at all
// failing the operation
return FALSE;
}

Expand Down Expand Up @@ -281,22 +286,11 @@ __nfweak void InitialiseWirelessDefaultConfig(HAL_Configuration_Wireless80211 *

// Default initialisation for Network interface config blocks
// it's implemented with 'weak' attribute so it can be replaced at target level if different configurations are intended
__nfweak void InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig, uint32_t configurationIndex)
__nfweak bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig, uint32_t configurationIndex)
{
(void)pconfig;
(void)configurationIndex;

HAL_Configuration_NetworkInterface config;

config.InterfaceType = NetworkInterfaceType_Ethernet;

// defaults to DHCP and DNS from DHCP
config.StartupAddressMode = AddressMode_DHCP;
config.AutomaticDNS = TRUE;

// store this to the 0 index block
ConfigurationManager_StoreConfigurationBlock(&config, DeviceConfigurationOption_Network, 0, 0);

// need to update the block count
g_TargetConfiguration.NetworkInterfaceConfigs->Count = 1;
// can't create a "default" network config because we are lacking definition of a MAC address
return FALSE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void InitialiseWirelessDefaultConfig(HAL_Configuration_Wireless80211 * pconfig,
}

// Default initialisation of Network interface config blocks for ESP32 targets
void InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig, uint32_t configurationIndex)
bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig, uint32_t configurationIndex)
{
memset( pconfig, 0, sizeof(HAL_Configuration_NetworkInterface));

Expand All @@ -171,6 +171,9 @@ void InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface * pconfig
pconfig->StartupAddressMode = AddressMode_DHCP;
break;
}

// always good
return TRUE;
}

// Gets a configuration block from the configuration block stored in the NVS block,
Expand Down Expand Up @@ -239,6 +242,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device
}
else if ( configuration == DeviceConfigurationOption_Network )
{
// OK to skip checking return value
InitialiseNetworkDefaultConfig((HAL_Configuration_NetworkInterface *)configurationBlock,configurationIndex);
storeConfig = true;
}
Expand Down

0 comments on commit 9f8e66f

Please sign in to comment.