Skip to content

Commit 5ce6783

Browse files
CloudyPadmalbessman
authored andcommitted
refactor: ic modules with comments and combined blocks
1 parent 47538a9 commit 5ce6783

File tree

6 files changed

+344
-9
lines changed

6 files changed

+344
-9
lines changed

src/registers/comparators/ic1.h

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,66 @@ extern "C" {
277277
inline static void IC1_CombineOddEvenICModules(void) {
278278
IC1CON2bits.IC32 = 1;
279279
}
280-
280+
281+
/**
282+
@Summary
283+
Sets the trigger event for capture complete interrupt
284+
285+
@Description
286+
This routine sets the trigger event for the input capture module to
287+
notify the ISR that a capture event is complete
288+
289+
@Preconditions
290+
IC1_Initialize function should have been called
291+
292+
@Param
293+
IC_PARAMS_CAPTURE_INTERRUPT
294+
295+
@Returns
296+
None
297+
*/
298+
inline static void IC1_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
299+
IC1CON1bits.ICI = i;
300+
}
301+
302+
/**
303+
@Summary
304+
Defines the purpose of input capture pin source
305+
306+
@Description
307+
This routine defines if the pin attached to IC module is used either to
308+
trigger the IC1TMR or to synchronize the timer with another timer module.
309+
310+
@Preconditions
311+
IC1_Initialize function should have been called
312+
313+
@Param
314+
IC_PARAMS_SOURCE_TASK
315+
316+
@Returns
317+
None
318+
*/
281319
inline static void IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
282320
IC1CON2bits.ICTRIG = t;
283321
}
284-
322+
323+
/**
324+
@Summary
325+
Clears the set interrupt flag of IC1 capture interrupt
326+
327+
@Description
328+
This routine will clear the interrupt flag of the IC1 capture
329+
module.
330+
331+
@Preconditions
332+
IC1_Initialize function should have been called
333+
334+
@Param
335+
None
336+
337+
@Returns
338+
None
339+
*/
285340
inline static void IC1_InterruptFlagClear(void) {
286341
IFS0bits.IC1IF = 0;
287342
}

src/registers/comparators/ic2.h

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,66 @@ extern "C" {
283283
inline static void IC2_CombineOddEvenICModules(void) {
284284
IC2CON2bits.IC32 = 1;
285285
}
286-
286+
287+
/**
288+
@Summary
289+
Sets the trigger event for capture complete interrupt
290+
291+
@Description
292+
This routine sets the trigger event for the input capture module to
293+
notify the ISR that a capture event is complete
294+
295+
@Preconditions
296+
IC2_Initialize function should have been called
297+
298+
@Param
299+
IC_PARAMS_CAPTURE_INTERRUPT
300+
301+
@Returns
302+
None
303+
*/
304+
inline static void IC2_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
305+
IC2CON1bits.ICI = i;
306+
}
307+
308+
/**
309+
@Summary
310+
Defines the purpose of input capture pin source
311+
312+
@Description
313+
This routine defines if the pin attached to IC module is used either to
314+
trigger the IC2TMR or to synchronize the timer with another timer module.
315+
316+
@Preconditions
317+
IC2_Initialize function should have been called
318+
319+
@Param
320+
IC_PARAMS_SOURCE_TASK
321+
322+
@Returns
323+
None
324+
*/
287325
inline static void IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
288326
IC2CON2bits.ICTRIG = t;
289327
}
290-
328+
329+
/**
330+
@Summary
331+
Clears the set interrupt flag of IC2 capture interrupt
332+
333+
@Description
334+
This routine will clear the interrupt flag of the IC2 capture
335+
module.
336+
337+
@Preconditions
338+
IC2_Initialize function should have been called
339+
340+
@Param
341+
None
342+
343+
@Returns
344+
None
345+
*/
291346
inline static void IC2_InterruptFlagClear(void) {
292347
IFS0bits.IC2IF = 0;
293348
}

src/registers/comparators/ic3.h

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,66 @@ extern "C" {
283283
inline static void IC3_CombineOddEvenICModules(void) {
284284
IC3CON2bits.IC32 = 1;
285285
}
286-
286+
287+
/**
288+
@Summary
289+
Sets the trigger event for capture complete interrupt
290+
291+
@Description
292+
This routine sets the trigger event for the input capture module to
293+
notify the ISR that a capture event is complete
294+
295+
@Preconditions
296+
IC3_Initialize function should have been called
297+
298+
@Param
299+
IC_PARAMS_CAPTURE_INTERRUPT
300+
301+
@Returns
302+
None
303+
*/
304+
inline static void IC3_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
305+
IC3CON1bits.ICI = i;
306+
}
307+
308+
/**
309+
@Summary
310+
Defines the purpose of input capture pin source
311+
312+
@Description
313+
This routine defines if the pin attached to IC module is used either to
314+
trigger the IC3TMR or to synchronize the timer with another timer module.
315+
316+
@Preconditions
317+
IC3_Initialize function should have been called
318+
319+
@Param
320+
IC_PARAMS_SOURCE_TASK
321+
322+
@Returns
323+
None
324+
*/
287325
inline static void IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
288326
IC3CON2bits.ICTRIG = t;
289327
}
290-
328+
329+
/**
330+
@Summary
331+
Clears the set interrupt flag of IC3 capture interrupt
332+
333+
@Description
334+
This routine will clear the interrupt flag of the IC3 capture
335+
module.
336+
337+
@Preconditions
338+
IC3_Initialize function should have been called
339+
340+
@Param
341+
None
342+
343+
@Returns
344+
None
345+
*/
291346
inline static void IC3_InterruptFlagClear(void) {
292347
IFS2bits.IC3IF = 0;
293348
}

src/registers/comparators/ic4.h

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,89 @@ extern "C" {
283283
inline static void IC4_CombineOddEvenICModules(void) {
284284
IC4CON2bits.IC32 = 1;
285285
}
286-
286+
287+
/**
288+
@Summary
289+
Defines the purpose of input capture pin source
290+
291+
@Description
292+
This routine defines if the pin attached to IC module is used either to
293+
trigger the IC4TMR or to synchronize the timer with another timer module.
294+
295+
@Preconditions
296+
IC4_Initialize function should have been called
297+
298+
@Param
299+
IC_PARAMS_SOURCE_TASK
300+
301+
@Returns
302+
None
303+
*/
287304
inline static void IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
288305
IC4CON2bits.ICTRIG = t;
289306
}
290307

308+
/**
309+
@Summary
310+
Clears the set interrupt flag of IC4 capture interrupt
311+
312+
@Description
313+
This routine will clear the interrupt flag of the IC4 capture
314+
module.
315+
316+
@Preconditions
317+
IC4_Initialize function should have been called
318+
319+
@Param
320+
None
321+
322+
@Returns
323+
None
324+
*/
291325
inline static void IC4_InterruptFlagClear(void) {
292326
IFS2bits.IC4IF = 0;
293327
}
294-
328+
329+
/**
330+
@Summary
331+
Enable IC4 interrupt
332+
333+
@Description
334+
This routine will enable IC4 interrupt.
335+
336+
@Preconditions
337+
IC4_Initialize function should have been called
338+
339+
@Param
340+
None
341+
342+
@Returns
343+
None
344+
*/
295345
inline static void IC4_InterruptEnable(void) {
296346
IEC2bits.IC4IE = 1;
297347
}
348+
349+
/**
350+
@Summary
351+
Sets the trigger event for capture complete interrupt
352+
353+
@Description
354+
This routine sets the trigger event for the input capture module to
355+
notify the ISR that a capture event is complete
356+
357+
@Preconditions
358+
IC4_Initialize function should have been called
359+
360+
@Param
361+
IC_PARAMS_CAPTURE_INTERRUPT
362+
363+
@Returns
364+
None
365+
*/
366+
inline static void IC4_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
367+
IC4CON1bits.ICI = i;
368+
}
298369

299370
inline static void IC4_InterruptDisable(void) {
300371
IEC2bits.IC4IE = 0;

src/registers/comparators/ic_params.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ic2.h"
33
#include "ic3.h"
44
#include "ic4.h"
5+
#include "../system/pin_manager.h"
56

67
void IC_PARAMS_InitiateAll(void) {
78
IC1_Initialize();
@@ -63,4 +64,52 @@ void IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER t) {
6364
IC2_SetCaptureTimer(t);
6465
IC3_SetCaptureTimer(t);
6566
IC4_SetCaptureTimer(t);
66-
}
67+
}
68+
69+
void IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(uint8_t pin,
70+
IC_PARAMS_CAPTURE_TIMER timer,
71+
IC_PARAMS_CAPTURE_INTERRUPT interrupt,
72+
IC_PARAMS_CAPTURE_MODE mode) {
73+
74+
IC1_InterruptFlagClear();
75+
76+
RPINR7bits.IC1R = PIN_MANAGER_DIGITAL_PINS[pin];
77+
78+
IC1_Initialize();
79+
IC1_CombineOddEvenICModules();
80+
IC1_SetCaptureTimer(timer);
81+
IC1_InputCaptureInterruptOn(interrupt);
82+
IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
83+
IC1_SetCaptureMode(mode);
84+
85+
IC2_Initialize();
86+
IC2_CombineOddEvenICModules();
87+
IC2_SetCaptureTimer(timer);
88+
IC2_InputCaptureInterruptOn(interrupt);
89+
IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
90+
IC2_SetCaptureMode(mode);
91+
}
92+
93+
void IC_PARAMS_ConfigureIntervalCaptureWithIC3AndIC4(uint8_t pin,
94+
IC_PARAMS_CAPTURE_TIMER timer,
95+
IC_PARAMS_CAPTURE_INTERRUPT interrupt,
96+
IC_PARAMS_CAPTURE_MODE mode) {
97+
98+
IC3_InterruptFlagClear();
99+
100+
RPINR8bits.IC3R = PIN_MANAGER_DIGITAL_PINS[pin];
101+
102+
IC3_Initialize();
103+
IC3_CombineOddEvenICModules();
104+
IC3_SetCaptureTimer(timer);
105+
IC3_InputCaptureInterruptOn(interrupt);
106+
IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
107+
IC3_SetCaptureMode(mode);
108+
109+
IC4_Initialize();
110+
IC4_CombineOddEvenICModules();
111+
IC4_SetCaptureTimer(timer);
112+
IC4_InputCaptureInterruptOn(interrupt);
113+
IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
114+
IC4_SetCaptureMode(mode);
115+
}

0 commit comments

Comments
 (0)