/** * @file include/di_fw/config.h * @brief Persistent configuration for device firmware * @copyright 2015 Dual Inventive Technology Centre B.V. */ #ifndef INCLUDE_DI_FW_DEVICE_H_ #define INCLUDE_DI_FW_DEVICE_H_ #include /** * the item uids are split over libdi_fw and the application * the first 6 config items are managed by libdi_fw, the application * takes care of the config items from entry DI_FW_CONFIG_ITEM_APPLICATION_START * * in case the application wants to add his own config item(s), it should provide * the config item uid, starting with DI_FW_CONFIG_ITEM_APPLICATION_START: */ enum di_fw_config_item_uids { DI_FW_CONFIG_ITEM_DEVICE_TOKEN_UID, DI_FW_CONFIG_ITEM_DEVICE_ACTIVATION_UID, DI_FW_CONFIG_ITEM_DEVICE_SERVICE_UID, DI_FW_CONFIG_ITEM_SELFTEST_UID, DI_FW_CONFIG_ITEM_DEVICE_UID_UID, // Keep last in EEPROM layout (config item struct in application) DI_FW_CONFIG_ITEM_FACTORY_DEFAULTS_UID, // Start configuration UID for application DI_FW_CONFIG_ITEM_APPLICATION_START }; /** * point to a specific EEPROM device for read or write operations * used as index in an array, don't change! */ enum di_fw_config_devices { DI_FW_CONFIG_PRIMARY_DEVICE = 0, DI_FW_CONFIG_SECUNDARY_DEVICE = 1 }; #define DI_FW_CONFIG_ITEM_SELFTEST_FIRST_VALUE 0x55 #define DI_FW_CONFIG_ITEM_SELFTEST_SECOND_VALUE 0xaa #define DI_FW_CONFIG_ITEM_SELFTEST_DEFAULT_VALUE DI_FW_CONFIG_ITEM_SELFTEST_FIRST_VALUE #define DI_FW_CONFIG_ITEM_SELFTEST { \ DI_FW_CONFIG_ITEM_SELFTEST_UID, \ sizeof(uint8_t), \ DI_CONFIG_ITEM_DEFAULT_UINT8(DI_FW_CONFIG_ITEM_SELFTEST_DEFAULT_VALUE) } #define DI_FW_CONFIG_ITEM_FACTORY_DEFAULTS { \ DI_FW_CONFIG_ITEM_FACTORY_DEFAULTS_UID, \ sizeof(bool), \ DI_CONFIG_ITEM_DEFAULT_BOOL(false)} #define DI_FW_CONFIG_ITEM_DEVICE_TOKEN { \ DI_FW_CONFIG_ITEM_DEVICE_TOKEN_UID, \ sizeof(uint32_t), \ DI_DEVICE_CONFIG_DEFAULT_TOKEN } #define DI_FW_CONFIG_ITEM_DEVICE_ACTIVATION { \ DI_FW_CONFIG_ITEM_DEVICE_ACTIVATION_UID, \ sizeof(bool), \ DI_DEVICE_CONFIG_DEFAULT_ACTIVATION } #define DI_FW_CONFIG_ITEM_DEVICE_SERVICE { \ DI_FW_CONFIG_ITEM_DEVICE_SERVICE_UID, \ sizeof(bool), \ DI_DEVICE_CONFIG_DEFAULT_SERVICE } #define DI_FW_CONFIG_ITEM_DEVICE_UID { \ DI_FW_CONFIG_ITEM_DEVICE_UID_UID, \ DI_DEVICE_UID_LEN, \ DI_DEVICE_CONFIG_DEFAULT_UID } /** * struct to store EEPROM device info (addresses and availability) * needed in a redundant setup */ struct di_fw_config_device_info { uint16_t address; bool available; }; /** * Initially set/get the token in/from the EEPROM */ di_errno_t di_fw_config_init_device_token(void); /** * Initially set/get the activation in/from the EEPROM */ di_errno_t di_fw_config_init_device_activation(void); /** * Initially set/get the service in/from the EEPROM */ di_errno_t di_fw_config_init_device_service(void); /** * Selftest configuration item to test config and lowlevel I/O for self-testing purposes * It toggles between: * - DI_FW_CONFIG_ITEM_SELFTEST_FIRST_VALUE * - DI_FW_CONFIG_ITEM_SELFTEST_SECOND_VALUE * @pre di_fw_config_init must be called before this function is used * @retval DNOK when scratchpad has been successfully toggled, !DNOK otherwise */ di_errno_t di_fw_config_selftest(void); /** * Factory defaults checks if the configuration item DI_FW_CONFIG_ITEM_FACTORY_DEFAULTS_UID is in * the correct state else it will load all the defaults from the config item list * @pre di_fw_config_init must be called before this function */ di_errno_t di_fw_config_factory_defaults(void); /** * Setting all config parameters to the right value. * Calling this function multiple times is ignored * @note this function calls the config selftest and sets defaults if needed * @warning When !DNOK is returned it is not possible to reinitialize again * @return DNOK when configuration is succesfull initialized. !DNOK otherwise */ di_errno_t di_fw_config_init(const struct di_config_item *item_list, const size_t size); /** * Function to get config of device */ struct di_config_ctx *di_fw_config_get_ctx(void); #ifdef DI_DEBUG /** * Erase underlaying physical media of configuration subsystem * @retval DNOK when successful, !DNOK otherwise */ di_errno_t di_fw_config_erase(void); #endif #endif