Changes to the RTC driver to use the persistent storage interface,
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12366 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
parent
8ec0f1a753
commit
dbf616f8b3
|
@ -49,7 +49,7 @@
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PS_NO_ERROR = 0, /* No error. */
|
PS_NO_ERROR = 0, /* No error. */
|
||||||
PS_ERROR_READ = 2, /* ECC or other error during read operation.*/
|
PS_ERROR_READ = 2, /* ECC or other error during read operation.*/
|
||||||
PS_ERROR_PROGRAM = 3, /* Program operation failed. */
|
PS_ERROR_WRITE= 3, /* Program operation failed. */
|
||||||
PS_ERROR_VERIFY = 5, /* Verify operation failed. */
|
PS_ERROR_VERIFY = 5, /* Verify operation failed. */
|
||||||
PS_ERROR_HW_FAILURE = 6 /* Controller or communication error. */
|
PS_ERROR_HW_FAILURE = 6 /* Controller or communication error. */
|
||||||
} ps_error_t;
|
} ps_error_t;
|
||||||
|
|
|
@ -87,6 +87,11 @@
|
||||||
*/
|
*/
|
||||||
typedef struct RTCDriver RTCDriver;
|
typedef struct RTCDriver RTCDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of an RTC alarm number.
|
||||||
|
*/
|
||||||
|
typedef unsigned int rtcalarm_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of a structure representing an RTC date/time stamp.
|
* @brief Type of a structure representing an RTC date/time stamp.
|
||||||
*/
|
*/
|
||||||
|
@ -101,8 +106,56 @@ typedef struct {
|
||||||
/*lint -restore*/
|
/*lint -restore*/
|
||||||
} RTCDateTime;
|
} RTCDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief BasePersistentStorage specific methods.
|
||||||
|
*/
|
||||||
|
#define _rtc_driver_methods \
|
||||||
|
_base_persistent_storage_methods
|
||||||
|
|
||||||
#include "hal_rtc_lld.h"
|
#include "hal_rtc_lld.h"
|
||||||
|
|
||||||
|
/* Some more checks, must happen after inclusion of the LLD header, this is
|
||||||
|
why are placed here.*/
|
||||||
|
#if !defined(RTC_SUPPORTS_CALLBACKS)
|
||||||
|
#error "RTC LLD does not define the required RTC_SUPPORTS_CALLBACKS macro"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(RTC_ALARMS)
|
||||||
|
#error "RTC LLD does not define the required RTC_ALARMS macro"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(RTC_HAS_STORAGE)
|
||||||
|
#error "RTC LLD does not define the required RTC_HAS_STORAGE macro"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if RTC_HAS_STORAGE || defined(__DOXYGEN__)
|
||||||
|
/**
|
||||||
|
* @extends FileStream
|
||||||
|
*
|
||||||
|
* @brief @p RTCDriver virtual methods table.
|
||||||
|
*/
|
||||||
|
struct RTCDriverVMT {
|
||||||
|
_rtc_driver_methods
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Structure representing an RTC driver.
|
||||||
|
*/
|
||||||
|
struct RTCDriver {
|
||||||
|
#if RTC_HAS_STORAGE || defined(__DOXYGEN__)
|
||||||
|
/**
|
||||||
|
* @brief Virtual Methods Table.
|
||||||
|
*/
|
||||||
|
const struct RTCDriverVMT *vmt;
|
||||||
|
#endif
|
||||||
|
#if defined(RTC_DRIVER_EXT_FIELDS)
|
||||||
|
RTC_DRIVER_EXT_FIELDS
|
||||||
|
#endif
|
||||||
|
/* End of the mandatory fields.*/
|
||||||
|
_rtc_lld_driver_fields
|
||||||
|
};
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -111,6 +164,13 @@ typedef struct {
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#if !defined(__DOXYGEN__)
|
||||||
|
extern RTCDriver RTCD1;
|
||||||
|
#if RTC_HAS_STORAGE == TRUE
|
||||||
|
extern struct RTCDriverVMT _rtc_lld_vmt;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -84,23 +84,11 @@
|
||||||
/* Driver data structures and types. */
|
/* Driver data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief FileStream specific methods.
|
|
||||||
*/
|
|
||||||
#define _rtc_driver_methods \
|
|
||||||
_file_stream_methods
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of a structure representing an RTC alarm time stamp.
|
* @brief Type of a structure representing an RTC alarm time stamp.
|
||||||
*/
|
*/
|
||||||
typedef struct RTCAlarm RTCAlarm;
|
typedef struct RTCAlarm RTCAlarm;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of an RTC alarm.
|
|
||||||
* @details Meaningful on platforms with more than 1 alarm comparator.
|
|
||||||
*/
|
|
||||||
typedef uint32_t rtcalarm_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of an RTC event.
|
* @brief Type of an RTC event.
|
||||||
*/
|
*/
|
||||||
|
@ -125,36 +113,14 @@ struct RTCAlarm {
|
||||||
uint32_t tv_sec;
|
uint32_t tv_sec;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if RTC_HAS_STORAGE || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @extends FileStream
|
* @brief Implementation-specific @p RTCDriver fields.
|
||||||
*
|
|
||||||
* @brief @p RTCDriver virtual methods table.
|
|
||||||
*/
|
*/
|
||||||
struct RTCDriverVMT {
|
#define _rtc_lld_driver_fields \
|
||||||
_rtc_driver_methods
|
/* Pointer to the RTC registers block.*/ \
|
||||||
};
|
RTC_TypeDef *rtc; \
|
||||||
#endif
|
/* Callback pointer.*/ \
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing an RTC driver.
|
|
||||||
*/
|
|
||||||
struct RTCDriver{
|
|
||||||
#if RTC_HAS_STORAGE || defined(__DOXYGEN__)
|
|
||||||
/**
|
|
||||||
* @brief Virtual Methods Table.
|
|
||||||
*/
|
|
||||||
const struct RTCDriverVMT *vmt;
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @brief Pointer to the RTC registers block.
|
|
||||||
*/
|
|
||||||
RTC_TypeDef *rtc;
|
|
||||||
/**
|
|
||||||
* @brief Callback pointer.
|
|
||||||
*/
|
|
||||||
rtccb_t callback;
|
rtccb_t callback;
|
||||||
};
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
|
@ -164,13 +130,6 @@ struct RTCDriver{
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if !defined(__DOXYGEN__)
|
|
||||||
extern RTCDriver RTCD1;
|
|
||||||
#if RTC_HAS_STORAGE
|
|
||||||
extern struct RTCDriverVMT _rtc_lld_vmt;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -199,86 +199,37 @@ static uint32_t rtc_encode_date(const RTCDateTime *timespec) {
|
||||||
return dr;
|
return dr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RTC_HAS_STORAGE
|
#if RTC_HAS_STORAGE == TRUE
|
||||||
/* TODO: Map on the backup SRAM on devices that have it.*/
|
/* TODO: Map on the backup SRAM on devices that have it.*/
|
||||||
static size_t _write(void *instance, const uint8_t *bp, size_t n) {
|
static size_t _read(void *instance, ps_offset_t offset,
|
||||||
|
size_t n, uint8_t *rp) {
|
||||||
(void)instance;
|
|
||||||
(void)bp;
|
|
||||||
(void)n;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t _read(void *instance, uint8_t *bp, size_t n) {
|
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
(void)bp;
|
|
||||||
(void)n;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _put(void *instance, uint8_t b) {
|
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
(void)b;
|
|
||||||
|
|
||||||
return FILE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _get(void *instance) {
|
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
|
|
||||||
return FILE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _close(void *instance) {
|
|
||||||
|
|
||||||
/* Close is not supported.*/
|
|
||||||
(void)instance;
|
|
||||||
|
|
||||||
return FILE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _geterror(void *instance) {
|
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
|
|
||||||
return (msg_t)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _getsize(void *instance) {
|
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _getposition(void *instance) {
|
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t _lseek(void *instance, fileoffset_t offset) {
|
|
||||||
|
|
||||||
(void)instance;
|
(void)instance;
|
||||||
(void)offset;
|
(void)offset;
|
||||||
|
(void)n;
|
||||||
|
(void)rp;
|
||||||
|
|
||||||
return FILE_OK;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ps_error_t _write(void *instance, ps_offset_t offset,
|
||||||
|
size_t n, const uint8_t *wp) {
|
||||||
|
|
||||||
|
(void)instance;
|
||||||
|
(void)offset;
|
||||||
|
(void)n;
|
||||||
|
(void)wp;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief VMT for the RTC storage file interface.
|
* @brief VMT for the RTC storage file interface.
|
||||||
*/
|
*/
|
||||||
struct RTCDriverVMT _rtc_lld_vmt = {
|
struct RTCDriverVMT _rtc_lld_vmt = {
|
||||||
_write, _read, _put, _get,
|
_getsize, _read, _write
|
||||||
_close, _geterror, _getsize, _getposition, _lseek
|
|
||||||
};
|
};
|
||||||
#endif /* RTC_HAS_STORAGE */
|
#endif /* RTC_HAS_STORAGE == TRUE */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver interrupt handlers. */
|
/* Driver interrupt handlers. */
|
||||||
|
|
|
@ -133,17 +133,6 @@
|
||||||
/* Driver data structures and types. */
|
/* Driver data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief FileStream specific methods.
|
|
||||||
*/
|
|
||||||
#define _rtc_driver_methods \
|
|
||||||
_file_stream_methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of an RTC alarm number.
|
|
||||||
*/
|
|
||||||
typedef uint32_t rtcalarm_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of a structure representing an RTC alarm time stamp.
|
* @brief Type of a structure representing an RTC alarm time stamp.
|
||||||
*/
|
*/
|
||||||
|
@ -168,33 +157,12 @@ typedef struct {
|
||||||
} RTCWakeup;
|
} RTCWakeup;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if RTC_HAS_STORAGE || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @extends FileStream
|
* @brief Implementation-specific @p RTCDriver fields.
|
||||||
*
|
|
||||||
* @brief @p RTCDriver virtual methods table.
|
|
||||||
*/
|
*/
|
||||||
struct RTCDriverVMT {
|
#define _rtc_lld_driver_fields \
|
||||||
_rtc_driver_methods
|
/* Pointer to the RTC registers block.*/ \
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing an RTC driver.
|
|
||||||
*/
|
|
||||||
struct RTCDriver {
|
|
||||||
#if RTC_HAS_STORAGE || defined(__DOXYGEN__)
|
|
||||||
/**
|
|
||||||
* @brief Virtual Methods Table.
|
|
||||||
*/
|
|
||||||
const struct RTCDriverVMT *vmt;
|
|
||||||
#endif
|
|
||||||
/* End of the mandatory fields.*/
|
|
||||||
/**
|
|
||||||
* @brief Pointer to the RTC registers block.
|
|
||||||
*/
|
|
||||||
RTC_TypeDef *rtc;
|
RTC_TypeDef *rtc;
|
||||||
};
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
|
@ -204,13 +172,6 @@ struct RTCDriver {
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if !defined(__DOXYGEN__)
|
|
||||||
extern RTCDriver RTCD1;
|
|
||||||
#if RTC_HAS_STORAGE
|
|
||||||
extern struct RTCDriverVMT _rtc_lld_vmt;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -80,17 +80,6 @@
|
||||||
/* Driver data structures and types. */
|
/* Driver data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief FileStream specific methods.
|
|
||||||
*/
|
|
||||||
#define _rtc_driver_methods \
|
|
||||||
_file_stream_methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of an RTC alarm number.
|
|
||||||
*/
|
|
||||||
typedef uint32_t rtcalarm_t;
|
|
||||||
|
|
||||||
#if (RTC_SUPPORTS_CALLBACKS == TRUE) || defined(__DOXYGEN__)
|
#if (RTC_SUPPORTS_CALLBACKS == TRUE) || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Type of an RTC event.
|
* @brief Type of an RTC event.
|
||||||
|
@ -113,30 +102,11 @@ typedef struct {
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
} RTCAlarm;
|
} RTCAlarm;
|
||||||
|
|
||||||
#if (RTC_HAS_STORAGE == TRUE) || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @extends FileStream
|
* @brief Implementation-specific @p RTCDriver fields.
|
||||||
*
|
|
||||||
* @brief @p RTCDriver virtual methods table.
|
|
||||||
*/
|
*/
|
||||||
struct RTCDriverVMT {
|
#define _rtc_lld_driver_fields \
|
||||||
_rtc_driver_methods
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing an RTC driver.
|
|
||||||
*/
|
|
||||||
struct RTCDriver {
|
|
||||||
#if (RTC_HAS_STORAGE == TRUE) || defined(__DOXYGEN__)
|
|
||||||
/**
|
|
||||||
* @brief Virtual Methods Table.
|
|
||||||
*/
|
|
||||||
const struct RTCDriverVMT *vmt;
|
|
||||||
#endif
|
|
||||||
/* End of the mandatory fields.*/
|
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
};
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
|
@ -150,10 +120,6 @@ struct RTCDriver {
|
||||||
extern RTCDriver RTCD1;
|
extern RTCDriver RTCD1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (RTC_HAS_STORAGE == TRUE) && !defined(__DOXYGEN__)
|
|
||||||
extern struct RTCDriverVMT _rtc_lld_vmt;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -75,6 +75,8 @@
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
|
|
||||||
*** Next ***
|
*** Next ***
|
||||||
|
- NEW_ Modified the RTC driver to implement the persistent storage interface
|
||||||
|
instead of files interface.
|
||||||
- NEW: Added a new "persistent storage" base class to HAL.
|
- NEW: Added a new "persistent storage" base class to HAL.
|
||||||
- NEW: Added support for TIM21 and TIM22 in STM32 GPT driver.
|
- NEW: Added support for TIM21 and TIM22 in STM32 GPT driver.
|
||||||
- NEW: Reinforced checks in TIM-related drivers.
|
- NEW: Reinforced checks in TIM-related drivers.
|
||||||
|
|
Loading…
Reference in New Issue