testsuite: busy_sim: Add callback to the interrupt
Add optional callback which is called from the busy interrupt context. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
551b12b4a3
commit
f2e75a7140
3 changed files with 18 additions and 3 deletions
|
@ -21,6 +21,7 @@ struct busy_sim_data {
|
|||
struct k_work work;
|
||||
struct ring_buf rnd_rbuf;
|
||||
uint8_t rnd_buf[BUFFER_SIZE];
|
||||
busy_sim_cb_t cb;
|
||||
};
|
||||
|
||||
struct busy_sim_config {
|
||||
|
@ -110,6 +111,10 @@ static void counter_alarm_callback(const struct device *dev,
|
|||
}
|
||||
|
||||
/* Busy loop */
|
||||
if (data->cb) {
|
||||
data->cb();
|
||||
}
|
||||
|
||||
k_busy_wait(get_timeout(false) / data->us_tick);
|
||||
|
||||
if (config->pin_spec.port) {
|
||||
|
@ -123,12 +128,13 @@ static void counter_alarm_callback(const struct device *dev,
|
|||
}
|
||||
|
||||
void busy_sim_start(uint32_t active_avg, uint32_t active_delta,
|
||||
uint32_t idle_avg, uint32_t idle_delta)
|
||||
uint32_t idle_avg, uint32_t idle_delta, busy_sim_cb_t cb)
|
||||
{
|
||||
int err;
|
||||
const struct busy_sim_config *config = get_dev_config(busy_sim_dev);
|
||||
struct busy_sim_data *data = get_dev_data(busy_sim_dev);
|
||||
|
||||
data->cb = cb;
|
||||
data->active_avg = active_avg;
|
||||
data->active_delta = active_delta;
|
||||
data->idle_avg = idle_avg;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#ifndef BUSY_SIM_H__
|
||||
#define BUSY_SIM_H__
|
||||
|
||||
typedef void (*busy_sim_cb_t)(void);
|
||||
|
||||
/**
|
||||
* @brief Start busy simulator.
|
||||
*
|
||||
|
@ -16,12 +18,19 @@
|
|||
* values and keep them in a ring buffer.
|
||||
*
|
||||
* @param active_avg Avarage time of busy looping in the counter callback (in microseconds).
|
||||
*
|
||||
* @param active_delta Specifies deviation from avarage time of busy looping (in microseconds).
|
||||
*
|
||||
* @param idle_avg Avarage time of counter alarm timeout (in microseconds).
|
||||
*
|
||||
* @param idle_delta Specifies deviation from avarage time of counter alarm (in microseconds).
|
||||
*
|
||||
* @param cb Callback called from the context of the busy simulator timeout. If ZLI interrupt
|
||||
* is used for busy simulator counter then kernel API cannot be used from that callback.
|
||||
* Callback is called before busy waiting.
|
||||
*/
|
||||
void busy_sim_start(uint32_t active_avg, uint32_t active_delta,
|
||||
uint32_t idle_avg, uint32_t idle_delta);
|
||||
uint32_t idle_avg, uint32_t idle_delta, busy_sim_cb_t cb);
|
||||
|
||||
/** @brief Stop busy simulator. */
|
||||
void busy_sim_stop(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue