git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7543 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2014-11-27 15:07:26 +00:00
parent 5e580ea572
commit e40082e1d6
10 changed files with 218 additions and 26 deletions

View File

@ -111,7 +111,7 @@
* @brief Enables the RTC subsystem.
*/
#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
#define HAL_USE_RTC FALSE
#define HAL_USE_RTC TRUE
#endif
/**

View File

@ -46,17 +46,17 @@
/**
* @brief No error return code.
*/
#define FILE_OK (fileoffset_t)STM_OK
#define FILE_OK STM_OK
/**
* @brief Error code from the file stream methods.
*/
#define FILE_ERROR (fileoffset_t)STM_TIMEOUT
#define FILE_ERROR STM_TIMEOUT
/**
* @brief End-of-file condition for file get/put methods.
*/
#define FILE_EOF (fileoffset_t)STM_RESET
#define FILE_EOF STM_RESET
/** @} */
/**
@ -70,15 +70,15 @@ typedef uint32_t fileoffset_t;
#define _file_stream_methods \
_base_sequential_stream_methods \
/* File close method.*/ \
uint32_t (*close)(void *instance); \
msg_t (*close)(void *instance); \
/* Get last error code method.*/ \
int (*geterror)(void *instance); \
msg_t (*geterror)(void *instance); \
/* File get size method.*/ \
fileoffset_t (*getsize)(void *instance); \
msg_t (*getsize)(void *instance); \
/* File get current position method.*/ \
fileoffset_t (*getposition)(void *instance); \
msg_t (*getposition)(void *instance); \
/* File seek method.*/ \
uint32_t (*lseek)(void *instance, fileoffset_t offset);
msg_t (*lseek)(void *instance, fileoffset_t offset);
/**
* @brief @p FileStream specific data.

View File

@ -115,6 +115,7 @@ typedef struct {
extern "C" {
#endif
void rtcInit(void);
void rtcObjectInit(RTCDriver *rtcp);
void rtcSetTime(RTCDriver *rtcp, const RTCDateTime *timespec);
void rtcGetTime(RTCDriver *rtcp, RTCDateTime *timespec);
#if RTC_ALARMS > 0

View File

@ -204,6 +204,9 @@ void rtc_lld_set_prescaler(void) {
*/
void rtc_lld_init(void) {
/* RTC object initialization.*/
rtcObjectInit(&RTCD1);
/* RTC pointer initialization.*/
RTCD1.rtc = RTC;

View File

@ -35,6 +35,9 @@
/* Driver constants. */
/*===========================================================================*/
/**
* @name Implementation capabilities
*/
/**
* @brief This RTC implementation supports callbacks.
*/
@ -45,6 +48,12 @@
*/
#define RTC_ALARMS 1
/**
* @brief Presence of a local persistent storage.
*/
#define RTC_HAS_STORAGE FALSE
/** @} */
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
@ -75,16 +84,17 @@
/* 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.
*/
typedef struct RTCAlarm RTCAlarm;
/**
* @brief Type of a structure representing an RTC callbacks config.
*/
typedef struct RTCCallbackConfig RTCCallbackConfig;
/**
* @brief Type of an RTC alarm.
* @details Meaningful on platforms with more than 1 alarm comparator.
@ -105,16 +115,6 @@ typedef enum {
*/
typedef void (*rtccb_t)(RTCDriver *rtcp, rtcevent_t event);
/**
* @brief Structure representing an RTC callbacks config.
*/
struct RTCCallbackConfig{
/**
* @brief Generic RTC callback pointer.
*/
rtccb_t callback;
};
/**
* @brief Structure representing an RTC alarm time stamp.
*/
@ -125,17 +125,33 @@ struct RTCAlarm {
uint32_t tv_sec;
};
#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
/**
* @brief Pointer to the RTC registers block.
*/
RTC_TypeDef *rtc;
/**
* @brief Callback pointer.
* @brief Callback pointer.
*/
rtccb_t callback;
};
@ -150,6 +166,9 @@ struct RTCDriver{
#if !defined(__DOXYGEN__)
extern RTCDriver RTCD1;
#if RTC_HAS_STORAGE
extern struct RTCDriverVMT _rtc_lld_vmt;
#endif
#endif
#ifdef __cplusplus

View File

@ -197,6 +197,84 @@ static uint32_t rtc_encode_date(const RTCDateTime *timespec) {
return dr;
}
static size_t _write(void *instance, const uint8_t *bp, size_t n) {
(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)offset;
return FILE_OK;
}
/**
* @brief VMT for the RTC storage file interface.
*/
struct RTCDriverVMT _rtc_lld_vmt = {
_write, _read, _put, _get,
_close, _geterror, _getsize, _getposition, _lseek
};
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
@ -212,6 +290,9 @@ static uint32_t rtc_encode_date(const RTCDateTime *timespec) {
*/
void rtc_lld_init(void) {
/* RTC object initialization.*/
rtcObjectInit(&RTCD1);
/* RTC pointer initialization.*/
RTCD1.rtc = RTC;

View File

@ -35,6 +35,9 @@
/* Driver constants. */
/*===========================================================================*/
/**
* @name Implementation capabilities
*/
/**
* @brief Callback support int the driver.
*/
@ -45,6 +48,12 @@
*/
#define RTC_ALARMS STM32_RTC_NUM_ALARMS
/**
* @brief Presence of a local persistent storage.
*/
#define RTC_HAS_STORAGE TRUE
/** @} */
/**
* @brief RTC PRER register initializer.
*/
@ -122,6 +131,12 @@
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief FileStream specific methods.
*/
#define _rtc_driver_methods \
_file_stream_methods
/**
* @brief Type of an RTC alarm number.
*/
@ -150,10 +165,28 @@ typedef struct {
} RTCWakeup;
#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
/* End of the mandatory fields.*/
/**
* @brief Pointer to the RTC registers block.
*/
@ -170,6 +203,9 @@ struct RTCDriver {
#if !defined(__DOXYGEN__)
extern RTCDriver RTCD1;
#if RTC_HAS_STORAGE
extern struct RTCDriverVMT _rtc_lld_vmt;
#endif
#endif
#ifdef __cplusplus

View File

@ -73,6 +73,22 @@ void rtcInit(void) {
rtc_lld_init();
}
/**
* @brief Initializes a generic RTC driver object.
* @details The HW dependent part of the initialization has to be performed
* outside, usually in the hardware initialization code.
*
* @param[out] rtcp pointer to RTC driver structure
*
* @init
*/
void rtcObjectInit(RTCDriver *rtcp) {
#if RTC_HAS_STORAGE
rtcp->vmt = &_rtc_lld_vmt;
#endif
}
/**
* @brief Set current time.
* @note This function can be called from any context but limitations

View File

@ -66,6 +66,8 @@ RTCDriver RTCD1;
*/
void rtc_lld_init(void) {
/* RTC object initialization.*/
rtcObjectInit(&RTCD1);
}
/**

View File

@ -35,6 +35,9 @@
/* Driver constants. */
/*===========================================================================*/
/**
* @name Implementation capabilities
*/
/**
* @brief Callback support int the driver.
*/
@ -44,6 +47,11 @@
* @brief Number of alarms available.
*/
#define RTC_ALARMS PLATFORM_RTC_NUM_ALARMS
/**
* @brief Presence of a local persistent storage.
*/
#define RTC_HAS_STORAGE FALSE
/** @} */
/*===========================================================================*/
@ -64,6 +72,12 @@
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief FileStream specific methods.
*/
#define _rtc_driver_methods \
_file_stream_methods
/**
* @brief Type of an RTC alarm number.
*/
@ -77,10 +91,27 @@ typedef struct {
uint32_t dummy;
} RTCAlarm;
#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
/* End of the mandatory fields.*/
uint32_t dummy;
};
@ -95,6 +126,9 @@ struct RTCDriver {
#if !defined(__DOXYGEN__)
extern RTCDriver RTCD1;
#if RTC_HAS_STORAGE
extern struct RTCDriverVMT _rtc_lld_vmt;
#endif
#endif
#ifdef __cplusplus