ic_pal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 - 2018 NXP
3  * All rights reserved.
4  *
5  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
6  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
9  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
11  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
12  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
13  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
14  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
15  * THE POSSIBILITY OF SUCH DAMAGE.
16  */
28 #ifndef IC_PAL_H
29 #define IC_PAL_H
30 
31 #include "ic_pal_mapping.h"
32 #include "ic_pal_cfg.h"
33 #include "status.h"
34 #include "callbacks.h"
35 
36 
46 /*******************************************************************************
47  * Definitions
48  ******************************************************************************/
49 
50 #if (defined(IC_PAL_OVER_EMIOS))
51 
56 typedef enum
57 {
58  IC_BUS_SEL_A = 0x00U,
59  IC_BUS_SEL_B = 0x01U,
60  IC_BUS_SEL_C = 0x02U,
61  IC_BUS_SEL_D = 0x03U,
62  IC_BUS_SEL_E = 0x04U,
63  IC_BUS_SEL_F = 0x05U,
64  IC_BUS_SEL_INTERNAL = 0x06U
65 } ic_bus_select_t;
66 
71 typedef enum
72 {
73  IC_CLOCK_DIVID_BY_1 = 0x00U,
74  IC_CLOCK_DIVID_BY_2 = 0x01U,
75  IC_CLOCK_DIVID_BY_3 = 0x02U,
76  IC_CLOCK_DIVID_BY_4 = 0x03U,
77  IC_CLOCK_DIVID_BY_5 = 0x04U,
78  IC_CLOCK_DIVID_BY_6 = 0x05U,
79  IC_CLOCK_DIVID_BY_7 = 0x06U,
80  IC_CLOCK_DIVID_BY_8 = 0x07U,
81  IC_CLOCK_DIVID_BY_9 = 0x08U,
82  IC_CLOCK_DIVID_BY_10 = 0x09U,
83  IC_CLOCK_DIVID_BY_11 = 0x0AU,
84  IC_CLOCK_DIVID_BY_12 = 0x0BU,
85  IC_CLOCK_DIVID_BY_13 = 0x0CU,
86  IC_CLOCK_DIVID_BY_14 = 0x0DU,
87  IC_CLOCK_DIVID_BY_15 = 0x0EU,
88  IC_CLOCK_DIVID_BY_16 = 0x0FU
89 } ic_internal_ps_t;
90 #endif
91 
92 #if (defined(IC_PAL_OVER_ETIMER))
93 
100 typedef enum
101 {
102  IC_CLOCK_DIVID_1 = 0x18U,
103  IC_CLOCK_DIVID_2 = 0x19U,
104  IC_CLOCK_DIVID_4 = 0x1AU,
105  IC_CLOCK_DIVID_8 = 0x1BU,
106  IC_CLOCK_DIVID_16 = 0x1CU,
107  IC_CLOCK_DIVID_32 = 0x1DU,
108  IC_CLOCK_DIVID_64 = 0x1EU,
109  IC_CLOCK_DIVID_128 = 0x1FU,
110 } ic_source_prescaler_t;
111 #endif
112 
117 typedef enum
118 {
128 
134 typedef struct
135 {
136  uint8_t hwChannelId;
138  bool filterEn;
139  uint16_t filterValue;
144 
150 typedef struct
151 {
152  uint8_t nNumChannels;
154  void * extension;
155 } ic_config_t;
156 
157 #if (defined(IC_PAL_OVER_FTM))
158 
164 typedef struct
165 {
166  bool continuousModeEn;
167 } channel_extension_ftm_for_ic_t;
168 
175 typedef struct
176 {
177  ftm_clock_source_t ftmClockSource;
178  ftm_clock_ps_t ftmPrescaler;
180 } extension_ftm_for_ic_t;
181 #endif
182 
183 #if (defined(IC_PAL_OVER_EMIOS))
184 
190 typedef struct
191 {
192  ic_bus_select_t timebase;
193  ic_internal_ps_t prescaler;
194 } channel_extension_emios_for_ic_t;
195 
202 typedef struct
203 {
204  uint16_t clkDivVal;
205  bool enableGlobalPrescaler;
206  bool enableGlobalTimeBase;
207 } extension_emios_for_ic_t;
208 #endif
209 
210 #if (defined(IC_PAL_OVER_ETIMER))
211 
217 typedef struct
218 {
219  ic_source_prescaler_t prescaler;
220  bool continuousModeEn;
221  uint8_t rate;
223 } channel_extension_etimer_for_ic_t;
224 #endif
225 
234 typedef struct
235 {
237  uint8_t nNumChannels;
238  ic_option_mode_t icChannelType[IC_PAL_NUM_OF_CHANNEL_MAX];
239  uint8_t channelConfigArray[IC_PAL_NUM_OF_CHANNEL_MAX];
240  bool enableContinuousMode[IC_PAL_NUM_OF_CHANNEL_MAX];
241 #if (defined(IC_PAL_OVER_EMIOS))
242  emios_bus_select_t timeBaseSelection[IC_PAL_NUM_OF_CHANNEL_MAX];
243  emios_input_filter_t filterInput[IC_PAL_NUM_OF_CHANNEL_MAX];
244  bool filterEn[IC_PAL_NUM_OF_CHANNEL_MAX];
245 #endif
246 #if (defined(IC_PAL_OVER_ETIMER))
247  uint16_t measurementResults[IC_PAL_NUM_OF_CHANNEL_MAX];
248 #endif
249  bool enableNotification[IC_PAL_NUM_OF_CHANNEL_MAX];
250  void * channelCallbackParams[IC_PAL_NUM_OF_CHANNEL_MAX];
251  ic_callback_t channelCallbacks[IC_PAL_NUM_OF_CHANNEL_MAX];
254 
255 /*******************************************************************************
256  * API
257  ******************************************************************************/
258 
259 #if defined(__cplusplus)
260 extern "C" {
261 #endif
262 
277 status_t IC_Init(const ic_instance_t * const instance,
278  const ic_config_t * configPtr);
279 
291 status_t IC_Deinit(const ic_instance_t * const instance);
292 
301 void IC_StartChannel(const ic_instance_t * const instance,
302  uint8_t channel);
303 
312 void IC_StopChannel(const ic_instance_t * const instance,
313  uint8_t channel);
314 
324 status_t IC_SetChannelMode(const ic_instance_t * const instance,
325  uint8_t channel,
326  ic_option_mode_t channelMode);
327 
337 uint16_t IC_GetMeasurement(const ic_instance_t * const instance,
338  uint8_t channel);
339 
348 void IC_EnableNotification(const ic_instance_t * const instance,
349  uint8_t channel);
350 
359 void IC_DisableNotification(const ic_instance_t * const instance,
360  uint8_t channel);
361 
362 #if defined(__cplusplus)
363 }
364 #endif
365 
367 #endif /* IC_PAL_H */
368 
369 
370 /*******************************************************************************
371  * EOF
372  ******************************************************************************/
uint8_t hwChannelId
Definition: ic_pal.h:136
void * extension
Definition: ic_pal.h:154
Structure storing PAL instance information.
status_t IC_Init(const ic_instance_t *const instance, const ic_config_t *configPtr)
Initializes the input capture mode.
Definition: ic_pal.c:677
void * channelExtension
Definition: ic_pal.h:140
void IC_DisableNotification(const ic_instance_t *const instance, uint8_t channel)
Disable channel notifications.
Definition: ic_pal.c:1064
void IC_EnableNotification(const ic_instance_t *const instance, uint8_t channel)
Enable channel notifications.
Definition: ic_pal.c:1035
uint8_t nNumChannels
Definition: ic_pal.h:152
void IC_StopChannel(const ic_instance_t *const instance, uint8_t channel)
Stop the counter.
Definition: ic_pal.c:849
status_t IC_Deinit(const ic_instance_t *const instance)
De-initialize a input capture instance.
Definition: ic_pal.c:736
The configuration structure of input capture parameters for each channel.
Definition: ic_pal.h:134
Defines the configuration structures are used in the input capture mode.
Definition: ic_pal.h:150
uint16_t filterValue
Definition: ic_pal.h:139
void * channelCallbackParams
Definition: ic_pal.h:141
ftm_clock_ps_t
FlexTimer pre-scaler factor selection for the clock source. In quadrature decoder mode set FTM_CLOCK_...
Definition: ftm_common.h:252
status_t IC_SetChannelMode(const ic_instance_t *const instance, uint8_t channel, ic_option_mode_t channelMode)
Get the measured value.
Definition: ic_pal.c:886
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
void(* ic_callback_t)(ic_event_t event, void *userData)
Definition: callbacks.h:185
ftm_clock_source_t
FlexTimer clock source selection.
Definition: ftm_common.h:238
ic_callback_t channelCallbacks
Definition: ic_pal.h:142
The internal context structure.
Definition: ic_pal.h:234
ic_option_mode_t
The measurement type for input capture mode Implements : ic_option_mode_t_Class.
Definition: ic_pal.h:117
const ic_input_ch_param_t * inputChConfig
Definition: ic_pal.h:153
ic_option_mode_t inputCaptureMode
Definition: ic_pal.h:137
void IC_StartChannel(const ic_instance_t *const instance, uint8_t channel)
Start the counter.
Definition: ic_pal.c:805
uint16_t IC_GetMeasurement(const ic_instance_t *const instance, uint8_t channel)
Get the measured value.
Definition: ic_pal.c:987