drivers: counter: add counter_get_value(), deprecate counter_read()

Introduce a new counter API function for reading the current counter
value (counter_get_value()) and deprecate the former counter_read() in
favor of this.

Update all drivers and calling code to match the new counter API.

The previous counter driver API function for reading the current value
of the counter (counter_read()) did not support indicating whether the
read suceeded. This is fine for counters internal to the SoC where the
read always succeeds but insufficient for external counters (e.g. I2C
or SPI slaves).

Fixes #21846.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
Henrik Brix Andersen 2020-01-18 15:24:32 +01:00 committed by Anas Nashif
commit c894a6db4d
19 changed files with 162 additions and 58 deletions

View file

@ -124,11 +124,11 @@ static u32_t hinnant(int y, int m, int d)
}
/*
* Returns the Unix epoch time (assuming UTC) read from the CMOS RTC.
* Get the Unix epoch time (assuming UTC) read from the CMOS RTC.
* This function is long, but linear and easy to follow.
*/
u32_t read(struct device *dev)
int get_value(struct device *dev, u32_t *ticks)
{
struct state state, state2;
u64_t *pun = (u64_t *) &state;
@ -188,7 +188,8 @@ u32_t read(struct device *dev)
epoch += state.minute * 60; /* seconds per minute */
epoch += state.second;
return epoch;
*ticks = epoch;
return 0;
}
static int init(struct device *dev)
@ -204,7 +205,7 @@ static const struct counter_config_info info = {
};
static const struct counter_driver_api api = {
.read = read
.get_value = get_value
};
DEVICE_AND_API_INIT(counter_cmos, "CMOS", init, NULL, &info,