From b24866225a6301d3a663f874725e83c012dc25d3 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:36:00 +0100 Subject: digital/beacon: add bitcloud stack into common directory digital/zigbit --- .../PersistDataServer/include/pdsDataServer.h | 99 ++++++++++++++++++++++ .../include/private/pdsAuxService.h | 80 +++++++++++++++++ .../include/private/pdsCrcService.h | 73 ++++++++++++++++ .../PersistDataServer/include/private/pdsDbg.h | 37 ++++++++ .../include/private/pdsMemAbstract.h | 70 +++++++++++++++ .../include/private/pdsWriteData.h | 84 ++++++++++++++++++ 6 files changed, 443 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/pdsDataServer.h create mode 100644 digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsAuxService.h create mode 100644 digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsCrcService.h create mode 100644 digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsDbg.h create mode 100644 digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsMemAbstract.h create mode 100644 digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsWriteData.h (limited to 'digital/zigbit/bitcloud/stack/Components/PersistDataServer/include') diff --git a/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/pdsDataServer.h b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/pdsDataServer.h new file mode 100644 index 00000000..67855a66 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/pdsDataServer.h @@ -0,0 +1,99 @@ +/***************************************************************************//** + \file pdsDataServer.h + + \brief The header file describes the Persistence Data Server interface + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 28/09/07 A. Khromykh - Created + 01/11/10 A. Razinkov - Modified +*****************************************************************************/ + +#ifndef _PERSISTDATASERVER_H +#define _PERSISTDATASERVER_H + +/****************************************************************************** + Includes section +******************************************************************************/ +#include + +/****************************************************************************** + Types section +******************************************************************************/ +//! PDS state result after a command call +typedef enum +{ + PDS_SUCCESS, //!< - Command completed successfully + PDS_EEPROM_ERROR, //!< - EEPROM error occurred + PDS_CRC_ERROR, //!< - Wrong CRC + PDS_COMMIT_IN_PROGRESS //!< - Commit to external memory started +} PDS_DataServerState_t; + +#ifdef _COMMISSIONING_ +//! \cond internal +/***************************************************************************//** +\brief Reads all parameters from EEPROM to Config Server memory. + +Reads all parameters from EEPROM to Config Server memory and also checks CRC of +EEPROM stack parameters. In case of wrong CRC ConfigServer should reset EEPROM stack +parameters to default values. +*******************************************************************************/ +void PDS_Init(void); +//! \endcond + +/*****************************************************************************//** +\brief Writes default values of parameters to EEPROM + +\return - PDS state as a result of setting parameters to default state +*******************************************************************************/ +PDS_DataServerState_t PDS_SetToDefault(void); + +/***************************************************************************//** +\brief Must be called from the ::APL_TaskHandler() function only.\n +The function forces writing data from ConfigServer to EEPROM. After returning from the function +all ConfigServer data is stored in EEPROM. +*******************************************************************************/ +void PDS_FlushData(void); + +/***************************************************************************//** +\brief Must be called from the ::APL_TaskHandler() function only.\n +Stops Persist Data Server. +*******************************************************************************/ +void PDS_Stop(void); +#endif /* _COMMISSIONING_ */ + +/*****************************************************************************//** +\brief Must be called from the ::APL_TaskHandler() function only.\n +Reads data from the user area of EEPROM. + +\param[in] offset - data offset +\param[in] data - pointer to user data area +\param[in] length - data length +\param[in] callback - pointer to a callback function; if callback is NULL, then data will be read syncronously + +\return - PDS state as a result of data reading operation +*******************************************************************************/ +PDS_DataServerState_t PDS_ReadUserData(uint16_t offset, uint8_t *data, uint16_t length, void (*callback)(void)); + +/****************************************************************************//** +\brief Must be called only from ::APL_TaskHandler() function.\n +Writes data to user area of EEPROM. + +\param[in] offset - data offset +\param[in] data - pointer to user data area +\param[in] length - data length +\param[in] callback - pointer to a callback function; if callback is NULL, then data will be written syncronously + +\return - PDS state as a result of data writing operation +*******************************************************************************/ +PDS_DataServerState_t PDS_WriteUserData(uint16_t offset, uint8_t *data, uint16_t length, void (*callback)(void)); + +#endif //#ifndef _PERSISTDATASERVER_H + diff --git a/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsAuxService.h b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsAuxService.h new file mode 100644 index 00000000..3735afaa --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsAuxService.h @@ -0,0 +1,80 @@ +/***************************************************************************//** + \file pdsAuxService.h + + \brief The header file describes the auxiliary service of Persistence Data Server + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + + History: + 22/01/08 A. Khromykh - Created + 01/11/10 A. Razinkov - Modified +*****************************************************************************/ + +#ifndef _PDSAUXSERVICE_H +#define _PDSAUXSERVICE_H + +/****************************************************************************** + Includes section +******************************************************************************/ +#ifndef _MAC2_ + #include + #include + #include +#else // _MAC2_ + #include +#endif // _MAC2_ + +/****************************************************************************** + Define(s) section +******************************************************************************/ +/* define for eeprom write highlight */ +//#define USE_LED + +// crc area +#define PDS_CRC_AREA 10 +// user area +#define USER_BASE_EEPROM_ADDRESS (csPersistentMemorySize + PDS_CRC_AREA) + +#define PDS_CS_PARAMETER 0 +#define PDS_CS_MEMORY 1 +#define PDS_STOP_SAVE 2 + +#define EEPROM_BUSY -2 +#define EEPROM_ERROR -1 + +#define STORE_TIMER_TIMEOUT 300000ul // 5 minutes +#define SHORT_TIMEOUT 50ul // 50 msec +#define PDS_LONG_INTERVAL 0 +#define PDS_SHORT_INTERVAL 1 +#define SAVE_IS_STARTED 1 +#define SAVE_IS_STOPED 0 + +#define MAX_CS_PDS_VARIABLE_SIZE 16 + +/****************************************************************************** + Types section +******************************************************************************/ +// crc property +typedef struct +{ + uint8_t crc; + uint16_t position; + PDS_DataServerState_t eepromState; +} PDS_ServiceCrc_t; + +/****************************************************************************** + External global variables section +******************************************************************************/ +extern HAL_AppTimer_t pdsEepromSaveServiceTimer; +extern uint8_t savingIsStarted; +extern const uint8_t csPersistentItemsAmount; +extern const uint16_t csPersistentMemorySize; + +#endif /*_PDSAUXSERVICE_H*/ diff --git a/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsCrcService.h b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsCrcService.h new file mode 100644 index 00000000..cf00f9f4 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsCrcService.h @@ -0,0 +1,73 @@ +/***************************************************************************//** + \file pdsCrcService.h + + \brief The header file describes the interface of crc counting + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 22/01/08 A. Khromykh - Created + 01/11/10 A. Razinkov - Modified +*****************************************************************************/ + +#ifndef _PDSCRCSERVICE_H +#define _PDSCRCSERVICE_H + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include + +#ifdef _COMMISSIONING_ +/****************************************************************************** + Prototypes section +******************************************************************************/ +/****************************************************************************** +\brief Calculate CRC of persistent data stored in persist memory +\ +\param[out] crcStation - pointer to CRC service structure +******************************************************************************/ +void pdsCalculateCrc(PDS_ServiceCrc_t *crcStation); + +/****************************************************************************** +\brief Read CRC of stored data from persist memory +\ +\param[out] crcStation - pointer to CRC service structure +******************************************************************************/ +void pdsReadCrc(PDS_ServiceCrc_t *crcStation); + +/****************************************************************************** +\brief Write CRC of stored data to persist memory. The ring buffer used +\ to increase persist memory life cycle +\ +\param[out] crcStation - pointer to CRC service structure +******************************************************************************/ +PDS_DataServerState_t pdsWriteCrc(void); + +/****************************************************************************** +\brief Clears whole CRC area in persist memory +\ +\return operation result +******************************************************************************/ +PDS_DataServerState_t pdsClearCrcArea(void); + +/****************************************************************************** +\brief Check if any valid data exists in persist memory +\ +\return operation result +******************************************************************************/ +PDS_DataServerState_t pdsCheckPersistMemory(void); + +#ifdef __DBG_PDS__ + void pdsDbgReadAllEeprom(void); +#endif + +#endif /* _COMMISSIONING_ */ +#endif /*_PDSCRCSERVICE_H*/ diff --git a/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsDbg.h b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsDbg.h new file mode 100644 index 00000000..b336095f --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsDbg.h @@ -0,0 +1,37 @@ +/****************************************************************************** + \file csDbg.h + + \brief + Persistent Data Server debug info + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2010 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 29.10.10 A. Razinkov - Created. +******************************************************************************/ + +#ifndef _PDSDBG_H_ +#define _PDSDBG_H_ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include + +/****************************************************************************** + Types section +******************************************************************************/ + +typedef enum +{ + PDS_PDSPREPAREMEMORYACCESS0, + PDS_PDSPREPAREMEMORYACCESS1 +} PDS_DbgCodeId_t; + +#endif /* CSDBG_H_ */ diff --git a/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsMemAbstract.h b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsMemAbstract.h new file mode 100644 index 00000000..ca95f064 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsMemAbstract.h @@ -0,0 +1,70 @@ +/***************************************************************************//** + \file pdsMemAbstract.h + + \brief Memory abstract header + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 6/11/08 A. Khromykh - Created +*****************************************************************************/ +#ifndef _PDSMEMABSTRACT_H +#define _PDSMEMABSTRACT_H + +/* Type of usage memory */ +#define USE_EEPROM + +/* This header file performs persistence memory API redefinition. + * The goal is to achieve memory type independence for persist data server (PDS). + * + * + * MEMORY_DESCRIPTOR - persistence memory descriptor. It is a structure type, which + * includes the following variables: + * uint16_t address - internal persistence memory address to be accessed. + * uint8_t *data - pointer to the variable in RAM to be stored (or to be filled + * by read value from persistence). + * uint16_t length - "data" variable length (bytes). Equal to the number of bytes + * to be exchanged between persistence memory and RAM. + * + * + * WRITE_MEMORY, READ_MEMORY - persistence memory access functions. These functions + * should have the following form: + * int write/read(MEMORY_DESCRIPTOR *memoryDescr, void (*callback)(void)); + * Parameters: + * memoryDescr - pointer to memory descriptor + * callback - pointer to callback function. Callback function will be called + * after read or write persistence memory operation is completed. + * Returns: + * 0 - successful access; + * -1 - the number of bytes to read (write) is too large. + * Persistence memory access functions should perform memory arbitration also, i.e. + * memory busy return status is illegal. + * + * + * IS_MEMORY_BUSY - persistence memory access function, should have the following form: + * bool isMemoryBusy(void); + * Parameters: + * none. + * Returns: + * true - memory is busy + * false - memory is free; +*/ + +#if defined(USE_EEPROM) + +#include + +#define WRITE_MEMORY HAL_WriteEeprom +#define READ_MEMORY HAL_ReadEeprom +#define IS_MEMORY_BUSY HAL_IsEepromBusy +#define MEMORY_DESCRIPTOR HAL_EepromParams_t + +#endif + +#endif /* _PDSMEMABSTRACT_H */ diff --git a/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsWriteData.h b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsWriteData.h new file mode 100644 index 00000000..17cedbc4 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/PersistDataServer/include/private/pdsWriteData.h @@ -0,0 +1,84 @@ +/****************************************************************************** + \file csDbg.h + + \brief + Persistent Periodic data save implementation header + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2010 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 29.10.10 A. Razinkov - Created. +******************************************************************************/ + +#ifndef _PDSWRITEDATA_H_ +#define _PDSWRITEDATA_H_ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include + +#ifdef _COMMISSIONING_ +/****************************************************************************** + Functions prototypes section +******************************************************************************/ +/****************************************************************************** +\brief Update persistent items values in Configuration Server from persist memory +\ +\return Operation result +******************************************************************************/ +PDS_DataServerState_t pdsUpdate(void); + +/****************************************************************************** +\brief Locates parameter by it's index in persistent memory table. And prepares +\ memory descriptor to store parameter's value in EEPROM +\ +\param[in] index - index of the parameter in persistent memory table +\param[out]descriptor - memory descriptor to store parameter value +******************************************************************************/ +void pdsPrepareMemoryAccess(uint8_t index, MEMORY_DESCRIPTOR* descriptor); + +/****************************************************************************** +\brief Timer callback, initiates the commit process. +******************************************************************************/ +void pdsOnTimerSave(void); + +/******************************************************************************* +\brief Start server work +*******************************************************************************/ +void pdsStartPersistServer(void); +#endif /* _COMMISSIONING_ */ + +/****************************************************************************** +\brief Writes data to persist memory +\ +\param[in] descriptor - memory descriptor to store parameter value +\param[out]callback - callback to write-finidhed event handler +******************************************************************************/ +PDS_DataServerState_t pdsWrite(MEMORY_DESCRIPTOR* descriptor, void (*callback)(void)); + +/****************************************************************************** +\brief Read data from persist memory +\ +\param[in] descriptor - memory descriptor to read parameter value +\param[out]callback - callback to read-finished event handler +******************************************************************************/ +PDS_DataServerState_t pdsRead(MEMORY_DESCRIPTOR* descriptor, void (*callback)(void)); + +/****************************************************************************** +\brief Wait until memory be ready for transaction +******************************************************************************/ +void pdsWaitMemoryFree(void); + +/******************************************************************************* +\brief Dummy callback +*******************************************************************************/ +void pdsDummyCallback(void); + +#endif /* _PDSWRITEDATA_H_ */ -- cgit v1.2.3