xtensa/esp32: Added driver api to reload counter instantly
This commit is contained in:
parent
c612c068e1
commit
65f39fc0c7
@ -88,6 +88,7 @@ static int esp32_tim_getcounter(FAR struct esp32_tim_dev_s *dev,
|
||||
uint64_t *value);
|
||||
static int esp32_tim_setcounter(FAR struct esp32_tim_dev_s *dev,
|
||||
uint64_t value);
|
||||
static int esp32_tim_reload_now(FAR struct esp32_tim_dev_s *dev);
|
||||
static int esp32_tim_getalarmvalue(FAR struct esp32_tim_dev_s *dev,
|
||||
uint64_t *value);
|
||||
static int esp32_tim_setalarmvalue(FAR struct esp32_tim_dev_s *dev,
|
||||
@ -119,6 +120,7 @@ struct esp32_tim_ops_s esp32_tim_ops =
|
||||
.setpre = esp32_tim_setpre,
|
||||
.getconfig = esp32_tim_getconfig,
|
||||
.setcounter = esp32_tim_setcounter,
|
||||
.reloadnow = esp32_tim_reload_now,
|
||||
.getalarmvalue = esp32_tim_getalarmvalue,
|
||||
.setalarmvalue = esp32_tim_setalarmvalue,
|
||||
.setalarm = esp32_tim_setalarm,
|
||||
@ -286,16 +288,13 @@ static int esp32_tim_stop(FAR struct esp32_tim_dev_s *dev)
|
||||
|
||||
static int esp32_tim_clear(FAR struct esp32_tim_dev_s *dev)
|
||||
{
|
||||
uint32_t clear_value = 0;
|
||||
uint64_t clear_value = 0;
|
||||
|
||||
DEBUGASSERT(dev);
|
||||
|
||||
esp32_tim_putreg(dev, TIM_LOAD_LO_OFFSET, clear_value);
|
||||
esp32_tim_putreg(dev, TIM_LOAD_HI_OFFSET, clear_value);
|
||||
esp32_tim_setcounter(dev, clear_value);
|
||||
|
||||
/* Dummy value to trigger reload the counter with the previous value */
|
||||
|
||||
esp32_tim_putreg(dev, TIM_LOAD_OFFSET, BIT(0));
|
||||
esp32_tim_reload_now(dev);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -503,7 +502,10 @@ static int esp32_tim_getcounter(FAR struct esp32_tim_dev_s *dev,
|
||||
*
|
||||
* Description:
|
||||
* Set the value to be loaded to the counter
|
||||
* It may be loaded at an alarm or instantly
|
||||
* If you want the counter to be loaded at an alarm, enable the alarm and
|
||||
* the auto-reload before.
|
||||
* I you want the counter to be loaded instantly, call esp32_tim_reload_now
|
||||
* after.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@ -523,6 +525,25 @@ static int esp32_tim_setcounter(FAR struct esp32_tim_dev_s *dev,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_tim_reload_now
|
||||
*
|
||||
* Description:
|
||||
* Reloads the counter instantly. May be called after esp32_tim_setcounter.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int esp32_tim_reload_now(FAR struct esp32_tim_dev_s *dev)
|
||||
{
|
||||
DEBUGASSERT(dev);
|
||||
|
||||
/* Dummy value to trigger reloading */
|
||||
|
||||
esp32_tim_putreg(dev, TIM_LOAD_OFFSET, BIT(0));
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_tim_getalarmvalue
|
||||
*
|
||||
|
@ -46,6 +46,7 @@
|
||||
#define ESP32_TIM_GETCONFIG(d, v) ((d)->ops->getconfig(d, v))
|
||||
#define ESP32_TIM_GETCTR(d, v) ((d)->ops->getcounter(d, v))
|
||||
#define ESP32_TIM_SETCTR(d, v) ((d)->ops->setcounter(d, v))
|
||||
#define ESP32_TIM_RLD_NOW(d) ((d)->ops->reloadnow(d))
|
||||
#define ESP32_TIM_GETALRVL(d, v) ((d)->ops->getalarmvalue(d, v))
|
||||
#define ESP32_TIM_SETALRVL(d, v) ((d)->ops->setalarmvalue(d, v))
|
||||
#define ESP32_TIM_SETALRM(d, e) ((d)->ops->setalarm(d, e))
|
||||
@ -101,6 +102,7 @@ struct esp32_tim_ops_s
|
||||
CODE int (*getconfig)(FAR struct esp32_tim_dev_s *dev, uint32_t *value);
|
||||
CODE int (*getcounter)(FAR struct esp32_tim_dev_s *dev, uint64_t *value);
|
||||
CODE int (*setcounter)(FAR struct esp32_tim_dev_s *dev, uint64_t value);
|
||||
CODE int (*reloadnow)(FAR struct esp32_tim_dev_s *dev);
|
||||
CODE int (*getalarmvalue)(FAR struct esp32_tim_dev_s *dev,
|
||||
uint64_t *value);
|
||||
CODE int (*setalarmvalue)(FAR struct esp32_tim_dev_s *dev, uint64_t value);
|
||||
|
Loading…
Reference in New Issue
Block a user