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 k_work work;
|
||||||
struct ring_buf rnd_rbuf;
|
struct ring_buf rnd_rbuf;
|
||||||
uint8_t rnd_buf[BUFFER_SIZE];
|
uint8_t rnd_buf[BUFFER_SIZE];
|
||||||
|
busy_sim_cb_t cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct busy_sim_config {
|
struct busy_sim_config {
|
||||||
|
@ -110,6 +111,10 @@ static void counter_alarm_callback(const struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Busy loop */
|
/* Busy loop */
|
||||||
|
if (data->cb) {
|
||||||
|
data->cb();
|
||||||
|
}
|
||||||
|
|
||||||
k_busy_wait(get_timeout(false) / data->us_tick);
|
k_busy_wait(get_timeout(false) / data->us_tick);
|
||||||
|
|
||||||
if (config->pin_spec.port) {
|
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,
|
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;
|
int err;
|
||||||
const struct busy_sim_config *config = get_dev_config(busy_sim_dev);
|
const struct busy_sim_config *config = get_dev_config(busy_sim_dev);
|
||||||
struct busy_sim_data *data = get_dev_data(busy_sim_dev);
|
struct busy_sim_data *data = get_dev_data(busy_sim_dev);
|
||||||
|
|
||||||
|
data->cb = cb;
|
||||||
data->active_avg = active_avg;
|
data->active_avg = active_avg;
|
||||||
data->active_delta = active_delta;
|
data->active_delta = active_delta;
|
||||||
data->idle_avg = idle_avg;
|
data->idle_avg = idle_avg;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#ifndef BUSY_SIM_H__
|
#ifndef BUSY_SIM_H__
|
||||||
#define BUSY_SIM_H__
|
#define BUSY_SIM_H__
|
||||||
|
|
||||||
|
typedef void (*busy_sim_cb_t)(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start busy simulator.
|
* @brief Start busy simulator.
|
||||||
*
|
*
|
||||||
|
@ -16,12 +18,19 @@
|
||||||
* values and keep them in a ring buffer.
|
* values and keep them in a ring buffer.
|
||||||
*
|
*
|
||||||
* @param active_avg Avarage time of busy looping in the counter callback (in microseconds).
|
* @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 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_avg Avarage time of counter alarm timeout (in microseconds).
|
||||||
|
*
|
||||||
* @param idle_delta Specifies deviation from avarage time of counter alarm (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,
|
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. */
|
/** @brief Stop busy simulator. */
|
||||||
void busy_sim_stop(void);
|
void busy_sim_stop(void);
|
||||||
|
|
|
@ -21,7 +21,7 @@ static void test_busy_sim(void)
|
||||||
|
|
||||||
/* Start busy simulator and check that k_busy_wait last longer */
|
/* Start busy simulator and check that k_busy_wait last longer */
|
||||||
t = k_uptime_get_32();
|
t = k_uptime_get_32();
|
||||||
busy_sim_start(500, 200, 1000, 400);
|
busy_sim_start(500, 200, 1000, 400, NULL);
|
||||||
k_busy_wait(1000 * ms);
|
k_busy_wait(1000 * ms);
|
||||||
t = k_uptime_get_32() - t;
|
t = k_uptime_get_32() - t;
|
||||||
busy_ms = (3 * ms) / 2;
|
busy_ms = (3 * ms) / 2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue