| BlueNRG-1 Peripherals drivers APIs

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

BlueNRG1_mft.c
Go to the documentation of this file.
1
22 /* Includes ------------------------------------------------------------------*/
23 #include "BlueNRG1_mft.h"
24
25
84 void MFT_DeInit(MFT_Type* MFTx)
85 {
86 MFTx->TNPRSC = 0x00000000;
87 MFTx->TNCKC = 0x00000000;
88 MFTx->TNMCTRL = 0x00000000;
89 MFTx->TNICLR = 0x0000000F;
90
91 }
92
93
102 void MFT_Init(MFT_Type* MFTx, MFT_InitType* MFT_InitStruct)
103 {
104
105 /* Check the parameters */
106 assert_param(IS_MFT(MFTx));
107 assert_param(IS_MFT_MODE(MFT_InitStruct->MFT_Mode));
108 assert_param(IS_MFT_CLOCK_SEL(MFT_InitStruct->MFT_Clock1));
109 assert_param(IS_MFT_CLOCK_SEL(MFT_InitStruct->MFT_Clock2));
110
111 MFTx->TNMCTRL_b.TNAEN = RESET;
112 MFTx->TNMCTRL_b.TNBEN = RESET;
113
114 MFTx->TNCKC_b.TNC1CSEL = MFT_NO_CLK;
115 MFTx->TNCKC_b.TNC2CSEL = MFT_NO_CLK;
116
117 if(MFT_InitStruct->MFT_Mode == MFT_MODE_1a) {
118 MFTx->TNMCTRL_b.TNMDSEL = MFT_MODE_1;
119 MFTx->TNMCTRL_b.TNPTEN = SET;
120 }
121 else {
122 MFTx->TNMCTRL_b.TNMDSEL = MFT_InitStruct->MFT_Mode;
123 MFTx->TNMCTRL_b.TNPTEN = RESET;
124 }
125
126 MFTx->TNPRSC = MFT_InitStruct->MFT_Prescaler;
127 MFTx->TNMCTRL_b.TNEN = SET;
128 MFTx->TNCRA = MFT_InitStruct->MFT_CRA;
129 MFTx->TNCRB = MFT_InitStruct->MFT_CRB;
130 MFTx->TNMCTRL_b.TNEN = RESET;
131
132 MFTx->TNCKC_b.TNC1CSEL = MFT_InitStruct->MFT_Clock1;
133 MFTx->TNCKC_b.TNC2CSEL = MFT_InitStruct->MFT_Clock2;
134 }
135
142 void MFT_StructInit(MFT_InitType* MFT_InitStruct)
143 {
144 /* Reset MFT init structure parameters values */
145 MFT_InitStruct->MFT_Clock1 = MFT_NO_CLK;
146 MFT_InitStruct->MFT_Clock2 = MFT_NO_CLK;
147 MFT_InitStruct->MFT_CRA = 0;
148 MFT_InitStruct->MFT_CRB = 0;
149 MFT_InitStruct->MFT_Mode = MFT_MODE_1;
150 MFT_InitStruct->MFT_Prescaler = 0;
151 }
152
160 void MFT_Cmd(MFT_Type* MFTx, FunctionalState NewState)
161 {
162 /* Check the parameters */
163 assert_param(IS_MFT(MFTx));
164 assert_param(IS_FUNCTIONAL_STATE(NewState));
165
166 if (NewState == ENABLE) {
167 MFTx->TNMCTRL_b.TNEN = SET;
168 }
169 else {
170 MFTx->TNMCTRL_b.TNEN = RESET;
171 }
172 }
173
174
184 void MFT_TnEDGES(MFT_Type* MFTx, uint32_t MFT_TnA_edge, uint32_t MFT_TnB_edge)
185 {
186 /* Check the parameters */
187 assert_param(IS_MFT(MFTx));
188 assert_param(IS_MFT_Tn_EDGE(MFT_TnA_edge));
189 assert_param(IS_MFT_Tn_EDGE(MFT_TnB_edge));
190
191 MFTx->TNMCTRL_b.TNAEDG = MFT_TnA_edge;
192 MFTx->TNMCTRL_b.TNBEDG = MFT_TnB_edge;
193 }
194
203 void MFT_PulseTrainTriggerSelect(MFT_Type* MFTx, uint32_t MFT_Trigger)
204 {
205 /* Check the parameters */
206 assert_param(IS_MFT(MFTx));
207 assert_param(IS_MFT_PULSETRAIN_TRIGGER(MFT_Trigger));
208
209 MFTx->TNMCTRL_b.TNPTSE = MFT_Trigger;
210 }
211
217 void MFT_PulseTrainSoftwareTrigger(MFT_Type* MFTx)
218 {
219 /* Check the parameters */
220 assert_param(IS_MFT(MFTx));
221
222 MFTx->TNMCTRL_b.TNPTET = SET;
223 }
224
235 void MFT_TnXEN(MFT_Type* MFTx, uint8_t TnX, FunctionalState NewState)
236 {
237 /* Check the parameters */
238 assert_param(IS_MFT(MFTx));
239 assert_param(IS_MFT_TnX(TnX));
240 assert_param(IS_FUNCTIONAL_STATE(NewState));
241
242 if(TnX == MFT_TnA) {
243 MFTx->TNMCTRL_b.TNAEN = NewState;
244 }
245 else if(TnX == MFT_TnB) {
246 MFTx->TNMCTRL_b.TNBEN = NewState;
247 }
248 }
249
250
261 void MFT_SelectCapturePin( uint32_t MFT_TimerType, uint8_t MFT_Pin)
262 {
263 /* Check the parameters */
264 assert_param(IS_MFT_TIMER(MFT_TimerType));
265 assert_param(IS_MFT_INPUT_IO(MFT_Pin));
266
267 /* set counter */
268 if(MFT_TimerType == MFT1_TIMERA) {
269 GPIO->MFTX_b.MFT1_TIMER_A = MFT_Pin;
270 }
271 else if(MFT_TimerType == MFT1_TIMERB) {
272 GPIO->MFTX_b.MFT1_TIMER_B = MFT_Pin;
273 }
274 else if(MFT_TimerType == MFT2_TIMERA) {
275 GPIO->MFTX_b.MFT2_TIMER_A = MFT_Pin;
276 }
277 else if(MFT_TimerType == MFT2_TIMERB) {
278 GPIO->MFTX_b.MFT2_TIMER_B = MFT_Pin;
279 }
280
281 }
282
283
291 void MFT_SetCounter(MFT_Type* MFTx, uint16_t MFT_Cnt1, uint16_t MFT_Cnt2)
292 {
293 /* Check the parameters */
294 assert_param(IS_MFT(MFTx));
295
296 /* Set counters */
297 MFTx->TNCNT1 = MFT_Cnt1;
298 MFTx->TNCNT2 = MFT_Cnt2;
299 }
300
301
308 void MFT_SetCounter1(MFT_Type* MFTx, uint16_t MFT_Cnt)
309 {
310 /* Check the parameters */
311 assert_param(IS_MFT(MFTx));
312
313 /* Set counter */
314 MFTx->TNCNT1 = MFT_Cnt;
315 }
316
323 uint16_t MFT_GetCounter1(MFT_Type* MFTx)
324 {
325 /* Check the parameters */
326 assert_param(IS_MFT(MFTx));
327
328 /* Return counter */
329 return MFTx->TNCNT1;
330 }
331
338 void MFT_SetCounter2(MFT_Type* MFTx, uint16_t MFT_Cnt)
339 {
340 /* Check the parameters */
341 assert_param(IS_MFT(MFTx));
342
343 /* set counter */
344 MFTx->TNCNT2 = MFT_Cnt;
345 }
346
353 uint16_t MFT_GetCounter2(MFT_Type* MFTx)
354 {
355 /* Check the parameters */
356 assert_param(IS_MFT(MFTx));
357
358 /* Return counter */
359 return MFTx->TNCNT2;
360 }
361
374 void MFT_EnableIT(MFT_Type* MFTx, uint8_t MFT_IrqSource, FunctionalState NewState)
375 {
376 /* Check the parameters */
377 assert_param(IS_MFT(MFTx));
378 assert_param(IS_MFT_INTERRUPT(MFT_IrqSource));
379 assert_param(IS_FUNCTIONAL_STATE(NewState));
380
381 if (NewState == ENABLE) {
382 SET_BIT(MFTx->TNICTRL, (MFT_IrqSource << 4));
383 }
384 else {
385 CLEAR_BIT(MFTx->TNICTRL, (MFT_IrqSource << 4));
386 }
387 }
388
399 void MFT_ClearIT(MFT_Type* MFTx, uint8_t MFT_IrqSource)
400 {
401 /* Check the parameters */
402 assert_param(IS_MFT(MFTx));
403 assert_param(IS_MFT_INTERRUPT(MFT_IrqSource));
404
405 SET_BIT(MFTx->TNICLR, MFT_IrqSource);
406 }
407
419 ITStatus MFT_StatusIT(MFT_Type* MFTx, uint8_t MFT_IrqSource)
420 {
421 /* Check the parameters */
422 assert_param(IS_MFT(MFTx));
423 assert_param(IS_MFT_INTERRUPT(MFT_IrqSource));
424
425 if((MFTx->TNICTRL & MFT_IrqSource) != (uint32_t)RESET) {
426 return SET;
427 }
428 else {
429 return RESET;
430 }
431 }
432
445 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
MFT_TnA
#define MFT_TnA
Definition: BlueNRG1_mft.h:174
MFT_GetCounter2
uint16_t MFT_GetCounter2(MFT_Type *MFTx)
Get the timer counter2.
Definition: BlueNRG1_mft.c:353
IS_MFT_TIMER
#define IS_MFT_TIMER(VALUE)
Definition: BlueNRG1_mft.h:206
MFT_MODE_1
#define MFT_MODE_1
Definition: BlueNRG1_mft.h:92
MFT2_TIMERA
#define MFT2_TIMERA
Definition: BlueNRG1_mft.h:203
IS_MFT_TnX
#define IS_MFT_TnX(VALUE)
Definition: BlueNRG1_mft.h:177
MFT_NO_CLK
#define MFT_NO_CLK
Definition: BlueNRG1_mft.h:127
MFT2_TIMERB
#define MFT2_TIMERB
Definition: BlueNRG1_mft.h:204
IS_MFT_INTERRUPT
#define IS_MFT_INTERRUPT(IT)
Definition: BlueNRG1_mft.h:117
MFT_StructInit
void MFT_StructInit(MFT_InitType *MFT_InitStruct)
Fills each MFT_InitStruct member with its default value.
Definition: BlueNRG1_mft.c:142
MFT_SetCounter
void MFT_SetCounter(MFT_Type *MFTx, uint16_t MFT_Cnt1, uint16_t MFT_Cnt2)
Set the timer counter.
Definition: BlueNRG1_mft.c:291
MFT_EnableIT
void MFT_EnableIT(MFT_Type *MFTx, uint8_t MFT_IrqSource, FunctionalState NewState)
Enable specific MFT interrupt.
Definition: BlueNRG1_mft.c:374
MFT_PulseTrainSoftwareTrigger
void MFT_PulseTrainSoftwareTrigger(MFT_Type *MFTx)
Pulse-train trigger generation in Mode 1a.
Definition: BlueNRG1_mft.c:217
MFT_InitType::MFT_CRB
uint16_t MFT_CRB
Definition: BlueNRG1_mft.h:64
MFT_TnB
#define MFT_TnB
Definition: BlueNRG1_mft.h:175
MFT_InitType::MFT_Clock1
uint8_t MFT_Clock1
Definition: BlueNRG1_mft.h:54
MFT_StatusIT
ITStatus MFT_StatusIT(MFT_Type *MFTx, uint8_t MFT_IrqSource)
Return interrupt status.
Definition: BlueNRG1_mft.c:419
MFT_InitType::MFT_Prescaler
uint8_t MFT_Prescaler
Definition: BlueNRG1_mft.h:60
MFT_SetCounter2
void MFT_SetCounter2(MFT_Type *MFTx, uint16_t MFT_Cnt)
Set the timer counter2.
Definition: BlueNRG1_mft.c:338
MFT_Init
void MFT_Init(MFT_Type *MFTx, MFT_InitType *MFT_InitStruct)
Initializes the MFTx peripheral according to the specified parameters in the MFT_InitStruct.
Definition: BlueNRG1_mft.c:102
MFT_InitType
Structure definition of MFT initialization.
Definition: BlueNRG1_mft.h:49
MFT1_TIMERB
#define MFT1_TIMERB
Definition: BlueNRG1_mft.h:202
IS_MFT_MODE
#define IS_MFT_MODE(MODE)
Definition: BlueNRG1_mft.h:98
MFT_PulseTrainTriggerSelect
void MFT_PulseTrainTriggerSelect(MFT_Type *MFTx, uint32_t MFT_Trigger)
Select trigger source for pulse-train generation in Mode 1a.
Definition: BlueNRG1_mft.c:203
MFT_SetCounter1
void MFT_SetCounter1(MFT_Type *MFTx, uint16_t MFT_Cnt)
Set the timer counter1.
Definition: BlueNRG1_mft.c:308
BlueNRG1_mft.h
This file contains all the functions prototypes for the MFT firmware library.
MFT_TnXEN
void MFT_TnXEN(MFT_Type *MFTx, uint8_t TnX, FunctionalState NewState)
Set or Reset TnAEN bit.
Definition: BlueNRG1_mft.c:235
MFT_TnEDGES
void MFT_TnEDGES(MFT_Type *MFTx, uint32_t MFT_TnA_edge, uint32_t MFT_TnB_edge)
Configure edges sensibility of TnA and TnB.
Definition: BlueNRG1_mft.c:184
MFT_InitType::MFT_Clock2
uint8_t MFT_Clock2
Definition: BlueNRG1_mft.h:57
MFT1_TIMERA
#define MFT1_TIMERA
Definition: BlueNRG1_mft.h:201
MFT_SelectCapturePin
void MFT_SelectCapturePin(uint32_t MFT_TimerType, uint8_t MFT_Pin)
Set or Reset TnAEN bit.
Definition: BlueNRG1_mft.c:261
MFT_InitType::MFT_CRA
uint16_t MFT_CRA
Definition: BlueNRG1_mft.h:62
IS_MFT
#define IS_MFT(PERIPH)
Definition: BlueNRG1_mft.h:82
IS_MFT_CLOCK_SEL
#define IS_MFT_CLOCK_SEL(MODE)
Definition: BlueNRG1_mft.h:133
MFT_InitType::MFT_Mode
uint8_t MFT_Mode
Definition: BlueNRG1_mft.h:51
IS_MFT_Tn_EDGE
#define IS_MFT_Tn_EDGE(REG)
Definition: BlueNRG1_mft.h:151
IS_MFT_INPUT_IO
#define IS_MFT_INPUT_IO(VALUE)
Definition: BlueNRG1_mft.h:208
MFT_ClearIT
void MFT_ClearIT(MFT_Type *MFTx, uint8_t MFT_IrqSource)
Clear specific MFT interrupt.
Definition: BlueNRG1_mft.c:399
MFT_MODE_1a
#define MFT_MODE_1a
Definition: BlueNRG1_mft.h:93
IS_MFT_PULSETRAIN_TRIGGER
#define IS_MFT_PULSETRAIN_TRIGGER(MODE)
Definition: BlueNRG1_mft.h:164
MFT_Cmd
void MFT_Cmd(MFT_Type *MFTx, FunctionalState NewState)
Enable/Disable the MFT.
Definition: BlueNRG1_mft.c:160
MFT_GetCounter1
uint16_t MFT_GetCounter1(MFT_Type *MFTx)
Get the timer counter1.
Definition: BlueNRG1_mft.c:323
MFT_DeInit
void MFT_DeInit(MFT_Type *MFTx)
DeInit the MFTx peripheral.
Definition: BlueNRG1_mft.c:84