Appiko
aux_clk.h
1 /*
2  * aux_clk.c : Module to handle auxiliary clock used by different modules
3  * Copyright (C) 2019 Appiko
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef AUX_CLK_H
20 #define AUX_CLK_H
21 
33 #include "stdint.h"
34 #include "nrf_util.h"
35 #include "nrf.h"
36 
37 #if SYS_CFG_PRESENT == 1
38 #include "sys_config.h"
39 #endif
40 
41 #ifndef AUX_CLK_PPI_CHANNELS_USED
42 #define AUX_CLK_PPI_CHANNELS_USED 2
43 #endif
44 
45 #ifndef AUX_CLK_PPI_CHANNEL_BASE
46 #define AUX_CLK_PPI_CHANNEL_BASE 5
47 #endif
48 
49 #ifndef AUX_CLK_PPI_CHANNEL_0
50 #define AUX_CLK_PPI_CHANNEL_0 (AUX_CLK_PPI_CHANNEL_BASE + 0)
51 #endif
52 
53 #ifndef AUX_CLK_PPI_CHANNEL_1
54 #define AUX_CLK_PPI_CHANNEL_1 (AUX_CLK_PPI_CHANNEL_BASE + 1)
55 #endif
56 
57 #if (AUX_CLK_PPI_CHANNELS_USED > 2)
58 #ifndef AUX_CLK_PPI_CHANNEL_2
59 #define AUX_CLK_PPI_CHANNEL_2 (AUX_CLK_PPI_CHANNEL_BASE + 2)
60 #endif
61 
62 #if (AUX_CLK_PPI_CHANNELS_USED > 3)
63 #ifndef AUX_CLK_PPI_CHANNEL_3
64 #define AUX_CLK_PPI_CHANNEL_3 (AUX_CLK_PPI_CHANNEL_BASE + 3)
65 #endif
66 
67 #if (AUX_CLK_PPI_CHANNELS_USED > 4)
68 #error "Auxiliary clock module cannot handle more than 4 PPI channels"
69 #endif
70 #endif
71 #endif
72 
73 #ifndef AUX_CLK_LFCLK_RTC_USED
74 #define AUX_CLK_LFCLK_RTC_USED 0
75 #endif
76 
77 #ifndef AUX_CLK_HFCLK_TIMER_USED
78 #define AUX_CLK_HFCLK_TIMER_USED 2
79 #endif
80 
81 #ifndef AUX_CLK_HFCLK_SOLO_MODULE
82 #define AUX_CLK_HFCLK_SOLO_MODULE 1
83 #endif
84 #define AUX_CLK_NO_IRQ 0xFFFFFFFF
85 
86 #define AUX_CLK_MAX_CHANNELS 4
87 
88 
89 
91 typedef enum
92 {
98 
100 typedef enum
101 {
113 
115 typedef enum
116 {
124 
126 typedef struct
127 {
130  uint32_t event;
133  uint32_t task1;
136  uint32_t task2;
138 
140 typedef struct
141 {
149  void (* callback_handler) (uint8_t events);
151  uint32_t arr_cc_ms[AUX_CLK_MAX_CHANNELS];
155  uint8_t events_en;
157  aux_clk_ppi_t arr_ppi_cnf[AUX_CLK_PPI_CHANNELS_USED];
159 
167 void aux_clk_set (aux_clk_setup_t * aux_clk);
168 
174 
180 void aux_clk_update_cc (uint32_t cc_id,uint32_t new_val_ms);
181 
188 void aux_clk_update_ppi (uint32_t ppi_channel, aux_clk_ppi_t * new_ppi);
189 
194 uint32_t aux_clk_get_ms (void);
195 
199 void aux_clk_start ();
200 
204 void aux_clk_stop ();
205 
209 void aux_clk_clear ();
210 
215 void aux_clk_en_evt (uint8_t events);
216 
221 void aux_clk_dis_evt (uint8_t events);
222 
228 
233 #endif /* AUX_CLK_H */
void aux_clk_en_evt(uint8_t events)
Function to enable one or more events from aux_clk_evt_t.
Definition: aux_clk.c:332
void aux_clk_set(aux_clk_setup_t *aux_clk)
Function to setup the Auxiliary clock module.
Definition: aux_clk.c:281
aux_clk_source_t source
Definition: aux_clk.h:143
uint32_t aux_clk_get_ms(void)
Function to get ms since Auxiliary clock has started or cleared.
Definition: aux_clk.c:371
aux_clk_tsk_t
Definition: aux_clk.h:115
void aux_clk_start()
Definition: aux_clk.c:308
uint32_t task1
Definition: aux_clk.h:133
void aux_clk_select_src(aux_clk_source_t source)
Function to select the clock source for auxiliary clock module.
Definition: aux_clk.c:264
app_irq_priority_t
Priority levels that the application can use based on whether the SoftDevice (SD) is used.
Definition: nrf_util.h:63
void aux_clk_dis_evt(uint8_t events)
Function to disable one or more events from aux_clk_evt_t.
Definition: aux_clk.c:339
uint32_t event
Definition: aux_clk.h:130
void aux_clk_stop()
Function to stop clock.
Definition: aux_clk.c:314
void aux_clk_update_irq_priority(app_irq_priority_t new_priority)
Function to change IRQ Priority if needed.
Definition: aux_clk.c:366
aux_clk_source_t
Definition: aux_clk.h:91
void aux_clk_clear()
Function to clear clock counter value.
Definition: aux_clk.c:326
app_irq_priority_t irq_priority
Definition: aux_clk.h:147
uint8_t events_en
Definition: aux_clk.h:155
aux_clk_evt_t
Definition: aux_clk.h:100
void aux_clk_update_cc(uint32_t cc_id, uint32_t new_val_ms)
Function to update the given CC value for clock channel.
Definition: aux_clk.c:360
void aux_clk_update_ppi(uint32_t ppi_channel, aux_clk_ppi_t *new_ppi)
Function to Update PPI settings for given ppi channel.
Definition: aux_clk.c:346
uint32_t task2
Definition: aux_clk.h:136