-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ticker_HAL.h
117 lines (85 loc) · 2.9 KB
/
Ticker_HAL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Ticker_HAL.h
*
* Created on: Dic 2017
* Author: raulMrello
*
* Módulo para definir la forma en la que la clase Ticker se conectará con el hardware. En este caso la plataforma
* ESP-IDF ESP32
*
*/
#ifndef TICKER_HAL_H
#define TICKER_HAL_H
#include "mbed_api.h"
#include "List.h"
#include "Thread.h"
#include "Queue.h"
#include "Mutex.h"
/** Base abstraction for timer interrupts
*
* @note Synchronization level: Interrupt safe
* @ingroup drivers
*/
class Ticker_HAL {
public:
/** Clave para activar la depuración en tiempo de compilación */
static const bool DEBUG = true;
/** Divisor del reloj asociado al timer hardware */
static const int TimerDivider = 16;
/** Escala del timer acorde al divisor establecido */
static const int TimerScale = (TIMER_BASE_CLK / TimerDivider);
/** Grupo del timer utilizado para implementar objetos tipo Ticker */
static const timer_group_t TimerGroup = TIMER_GROUP_0;
/** Timer dentro del grupo selecciónado */
static const timer_idx_t TimerIdx = TIMER_0;
/** Estructura de control de tickers
*/
struct TickerData_t {
int32_t uuid; /// Identificador del objeto
Callback<void()> func; /// Callback a invocar en los siguientes eventos
uint64_t next_event; /// Timestamp del siguiente evento en el que se ejecuta
uint64_t timeout; /// Temporización en us
};
/** Inicia la ejecución del TimerManager
*/
static void start();
/** Obtiene el valor del contador actual
* @return Contador actual
*/
static uint64_t getRawCounter();
/** Obtiene el valor del timestamp en milisegundos
* @return Contador actual
*/
static uint64_t getTimestamp();
/** Añade un offset al timestamp para sincronizar con relojes externos
* @return Contador actual
*/
static void setTimestampOffset(uint64_t offset) {_offset = offset; }
/** Obtiene el valor del offset aplicado al timestamp
* @return Offset
*/
static uint64_t getTimestampOffset() { return _offset; }
/** Instala un Ticker en la lista de objetos en ejecución
* @param tickData Objeto a instalar
* @return Objeto instalado o NULL en caso de error
*/
static TickerData_t* attach(TickerData_t* tickdata);
/** Desinstala un objeto de la lista de ejecución
* @param tickData Objeto a desinstalar
*/
static void detach(TickerData_t* tickdata);
/** Rutina de atención a la interrupción de alarmas
*/
static void tickerISR();
protected:
static List<TickerData_t> *_ticker_list; /// Lista de objetos instalados
static TickerData_t *_curr_ticker; /// Puntero al objeto actual
static uint64_t _offset; /// Offset aplicado al timestamp
/** Rutina de ejecución (Thread) del TimerManager
*/
static void task();
/** Obtiene el siguiente ticker a cargar en el timer hardware iniciándolo
*/
static void executeNext();
};
#endif