1 #include <twr_pulse_counter.h>
2 #include <twr_system.h>
12 bool pending_event_flag;
20 static void _twr_pulse_counter_channel_task_update(
void *param);
21 static void _twr_pulse_counter_channel_exti(
twr_exti_line_t line,
void *param);
32 memset(&_twr_module_pulse_counter[channel], 0,
sizeof(_twr_module_pulse_counter[channel]));
38 _twr_module_pulse_counter[channel].channel = channel;
39 _twr_module_pulse_counter[channel].edge = edge;
43 twr_exti_register(twr_pulse_counter_exti_line[channel], (
twr_exti_edge_t) edge, _twr_pulse_counter_channel_exti, &_twr_module_pulse_counter[channel].channel);
48 _twr_module_pulse_counter[channel].event_handler = event_handler;
49 _twr_module_pulse_counter[channel].event_param = event_param;
54 _twr_module_pulse_counter[channel].update_interval = interval;
68 _twr_module_pulse_counter[channel].count = count;
73 return _twr_module_pulse_counter[channel].count;
78 _twr_module_pulse_counter[channel].count = 0;
81 static void _twr_pulse_counter_channel_task_update(
void *param)
85 if (self->pending_event_flag)
87 self->pending_event_flag =
false;
89 if (self->event_handler != NULL)
95 self->pending_event_flag =
true;
108 static void _twr_pulse_counter_channel_exti(
twr_exti_line_t line,
void *param)
113 _twr_module_pulse_counter[channel].count++;
115 _twr_module_pulse_counter[channel].pending_event_flag =
true;
118 if (_twr_module_pulse_counter[channel].count == 0)
void twr_exti_register(twr_exti_line_t line, twr_exti_edge_t edge, void(*callback)(twr_exti_line_t, void *), void *param)
Enable EXTI line interrupt and register callback function.
twr_exti_line_t
EXTI lines.
twr_exti_edge_t
Interrupt edge sensitivity.
@ TWR_EXTI_LINE_PA4
EXTI line PA4.
@ TWR_EXTI_LINE_PA5
EXTI line PA5.
@ TWR_EXTI_LINE_PA6
EXTI line PA6.
void twr_module_sensor_set_mode(twr_module_sensor_channel_t channel, twr_module_sensor_mode_t mode)
Set output mode of Sensor Module channel.
bool twr_module_sensor_init(void)
Initialize Sensor Module.
bool twr_module_sensor_set_pull(twr_module_sensor_channel_t channel, twr_module_sensor_pull_t pull)
Set pull of Sensor Module channel.
twr_module_sensor_channel_t
Sensor Module channels.
@ TWR_MODULE_SENSOR_MODE_INPUT
Channel operates as input.
@ TWR_MODULE_SENSOR_PULL_UP_INTERNAL
Channel has internal pull-up.
void twr_pulse_counter_init(twr_module_sensor_channel_t channel, twr_pulse_counter_edge_t edge)
Initialize pulse counter.
void twr_pulse_counter_set_event_handler(twr_module_sensor_channel_t channel, void(*event_handler)(twr_module_sensor_channel_t, twr_pulse_counter_event_t, void *), void *event_param)
Set callback function.
void twr_pulse_counter_reset(twr_module_sensor_channel_t channel)
Set count to zero.
unsigned int twr_pulse_counter_get(twr_module_sensor_channel_t channel)
Get count.
void twr_pulse_counter_set(twr_module_sensor_channel_t channel, unsigned int count)
Set count.
twr_pulse_counter_edge_t
Pulse counter active edges.
void twr_pulse_counter_set_update_interval(twr_module_sensor_channel_t channel, twr_tick_t interval)
Set update interval.
twr_pulse_counter_event_t
Pulse counter event.
@ TWR_PULSE_COUNTER_EVENT_UPDATE
Update event.
@ TWR_PULSE_COUNTER_EVENT_OVERFLOW
Overflow.
void twr_scheduler_plan_current_relative(twr_tick_t tick)
Schedule current task to tick relative from current spin.
void twr_scheduler_plan_absolute(twr_scheduler_task_id_t task_id, twr_tick_t tick)
Schedule specified task to absolute tick.
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
void twr_scheduler_plan_now(twr_scheduler_task_id_t task_id)
Schedule specified task for immediate execution.
void twr_scheduler_plan_relative(twr_scheduler_task_id_t task_id, twr_tick_t tick)
Schedule specified task to tick relative from current spin.
twr_scheduler_task_id_t twr_scheduler_register(void(*task)(void *), void *param, twr_tick_t tick)
Register task in scheduler.
#define TWR_TICK_INFINITY
Maximum timestamp value.
uint64_t twr_tick_t
Timestamp data type.