From a248ca45167180854e19cc43f8a5a0746aee4b9e Mon Sep 17 00:00:00 2001 From: Padmal Date: Sun, 18 Sep 2022 10:24:50 +0200 Subject: [PATCH] feat: frequency measurements --- src/commands.c | 10 +- src/helpers/interval.c | 111 ++++- src/helpers/interval.h | 120 ++++- src/instruments/multimeter.c | 145 +++++- src/instruments/multimeter.h | 73 ++- src/registers/comparators/ic1.c | 126 ++--- src/registers/comparators/ic1.h | 641 +++++++++++++----------- src/registers/comparators/ic2.c | 126 ++--- src/registers/comparators/ic2.h | 653 +++++++++++++----------- src/registers/comparators/ic3.h | 653 +++++++++++++----------- src/registers/comparators/ic4.h | 693 ++++++++++++++------------ src/registers/comparators/ic_params.c | 51 +- src/registers/comparators/ic_params.h | 48 ++ src/registers/timers/tmr2.h | 308 +++++++----- src/registers/timers/tmr3.c | 102 ++-- src/registers/timers/tmr3.h | 268 +++++----- src/registers/timers/tmr5.h | 419 ++++++++-------- 17 files changed, 2708 insertions(+), 1839 deletions(-) diff --git a/src/commands.c b/src/commands.c index 9bd8a3c..1ce863c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -228,13 +228,13 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1 }, { // 10 TIMING // 0 1 GET_TIMING 2 3 - Undefined, Unimplemented, Undefined, Undefined, + Undefined, INTERVAL_UntilEvent, Undefined, Undefined, // 4 START_ONE_CHAN_LA 5 START_TWO_CHAN_LA 6 START_FOUR_CHAN_LA 7 FETCH_DMA_DATA LOGICANALYZER_OneChannel, LOGICANALYZER_TwoChannel, LOGICANALYZER_FourChannel, Removed, // 8 FETCH_INT_DMA_DATA 9 FETCH_LONG_DMA_DATA 10 COMPARATOR_TO_LA 11 GET_INITIAL_STATES BUFFER_FetchInt, BUFFER_FetchLong, Unimplemented, INTERVAL_GetState, // 12 TIMING_MEASUREMENTS 13 INTERVAL_MEASUREMENTS 14 CONFIGURE_COMPARATOR 15 START_ALTERNATE_ONE_CHAN_LA - Unimplemented, Unimplemented, Removed, LOGICANALYZER_OneChannelAlt, + INTERVAL_TimeMeasure, INTERVAL_IntervalMeasure, Removed, LOGICANALYZER_OneChannelAlt, // 16 START_THREE_CHAN_LA 17 STOP_LA 18 19 LOGICANALYZER_ThreeChannel, LOGICANALYZER_Stop, Undefined, Undefined, // 20 21 22 23 @@ -244,17 +244,17 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1 }, { // 11 COMMON // 0 1 GET_CTMU_VOLTAGE 2 GET_CAPACITANCE 3 GET_FREQUENCY - Undefined, MULTIMETER_GetCTMUVolts, MULTIMETER_GetCapacitance, Unimplemented, + Undefined, MULTIMETER_GetCTMUVolts, MULTIMETER_GetCapacitance, MULTIMETER_LowFrequency, // 4 GET_INDUCTANCE 5 GET_VERSION 6 7 Unimplemented, DEVICE_GetVersion, Undefined, Undefined, // 8 RETRIEVE_BUFFER 9 GET_HIGH_FREQUENCY 10 CLEAR_BUFFER 11 SET_RGB1 - BUFFER_Retrieve, Unimplemented, BUFFER_Clear, Removed, + BUFFER_Retrieve, MULTIMETER_HighFrequency, BUFFER_Clear, Removed, // 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS Removed, Removed, DEVICE_ReadRegisterData, DEVICE_WriteRegisterData, // 16 GET_CAP_RANGE 17 SET_RGB2 18 READ_LOG 19 RESTORE_STANDALONE Unimplemented, Removed, Removed, DEVICE_Reset, // 20 GET_ALTERNATE_HIGH_FREQUENCY 21 SET_RGB_COMMON 22 SET_RGB3 23 START_CTMU - Unimplemented, LIGHT_RGBPin, Removed, CTMU_Start, + MULTIMETER_HighFrequencyAlt, LIGHT_RGBPin, Removed, CTMU_Start, // 24 STOP_CTMU 25 START_COUNTING 26 FETCH_COUNT 27 FILL_BUFFER CTMU_Stop, SENSORS_StartCounter, SENSORS_GetCounter, BUFFER_Fill, }, diff --git a/src/helpers/interval.c b/src/helpers/interval.c index 89bbc9c..16484f5 100644 --- a/src/helpers/interval.c +++ b/src/helpers/interval.c @@ -9,6 +9,7 @@ #include "../registers/memory/dma.h" #include "../registers/system/interrupt_manager.h" #include "../registers/system/pin_manager.h" +#include "../registers/system/watchdog.h" #include "../registers/timers/tmr2.h" #include "buffer.h" @@ -170,7 +171,7 @@ void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler) { RPINR8bits.IC4R = PIN_MANAGER_DIGITAL_PINS_LA4; TMR2_Initialize(); - TMR2_PrescalerSet(prescaler & 0xF); + TMR2_SetPrescaler(prescaler & 0xF); TMR2_Counter16BitSet(1); IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER2); @@ -196,3 +197,111 @@ response_t INTERVAL_GetState(void) { return SUCCESS; } + +response_t INTERVAL_IntervalMeasure(void) { + + uint16_t timeout = UART1_ReadInt(); // t * 64e6 >> 16 + uint8_t pins = UART1_Read(); + uint8_t modes = UART1_Read(); + + IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(pins & 0xF, + IC_PARAMS_CAPTURE_TIMER_PERIPHERAL, + IC_PARAMS_CAPTURE_INTERRUPT_EVERY_EVENT, modes & 0x7); + IC_PARAMS_ConfigureIntervalCaptureWithIC3AndIC4((pins >> 4) & 0xF, + IC_PARAMS_CAPTURE_TIMER_PERIPHERAL, + IC_PARAMS_CAPTURE_INTERRUPT_EVERY_EVENT, (modes >> 3) & 0x7); + + IC_PARAMS_ManualTriggerAll(); + + while ((!_IC1IF) && (IC2TMR < timeout)) WATCHDOG_TimerClear(); + UART1_WriteInt(IC1BUF); + UART1_WriteInt(IC2BUF); + + while ((!_IC3IF) && (IC2TMR < timeout)) WATCHDOG_TimerClear(); + UART1_WriteInt(IC3BUF); + UART1_WriteInt(IC4BUF); + UART1_WriteInt(IC2TMR); + + IC_PARAMS_DisableAllModules(); + + return SUCCESS; +} + +response_t INTERVAL_TimeMeasure(void) { + + uint16_t timeout = UART1_ReadInt(); // t * 64e6 >> 16 + uint8_t pins = UART1_Read(); + uint8_t modes = UART1_Read(); + uint8_t intrpts = UART1_Read(); + + if ((pins & 0xF) == 4 || ((pins >> 4) & 0xF) == 4) { + CMP4_SetupComparator(); + CVR_SetupComparator(); + } + + IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(pins & 0xF, + IC_PARAMS_CAPTURE_TIMER2, (intrpts & 0xF) - 1, modes & 0x7); + IC_PARAMS_ConfigureIntervalCaptureWithIC3AndIC4((pins >> 4) & 0xF, + IC_PARAMS_CAPTURE_TIMER2, ((intrpts >> 4) & 0xF) - 1, (modes >> 3) & 0x7); + + TMR2_Initialize(); + + SetDefaultDIGITAL_STATES(); + + IC_PARAMS_ManualTriggerAll(); + TMR2_Start(); + + if ((modes >> 6) & 0x1) { + RPOR5bits.RP54R = RPN_DEFAULT_PORT; // Disconnect SQR1 pin + ((modes >> 7) & 0x1) ? SQR1_SetHigh() : SQR1_SetLow(); + } + + while ((!_IC1IF || !_IC3IF) && (IC2TMR < timeout)) WATCHDOG_TimerClear(); + + uint8_t i; + for (i = 0; i < (intrpts & 0xF); i++) { + UART1_WriteInt(IC1BUF); + UART1_WriteInt(IC2BUF); + } + for (i = 0; i < ((intrpts >> 4) & 0xF); i++) { + UART1_WriteInt(IC3BUF); + UART1_WriteInt(IC4BUF); + } + + IC1_InterruptFlagClear(); + IC3_InterruptFlagClear(); + + UART1_WriteInt(IC2TMR); + + IC_PARAMS_DisableAllModules(); + TMR2_Stop(); + + return SUCCESS; +} + +response_t INTERVAL_UntilEvent(void) { + + uint16_t timeout = UART1_ReadInt(); // t * 64e6 >> 16 + uint8_t mode = UART1_Read(); + uint8_t pin = UART1_Read(); + + IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(pin & 0xF, + IC_PARAMS_CAPTURE_TIMER_PERIPHERAL, (mode & 0x3) - 1, mode & 0x7); + + while (!_IC1IF && (IC2TMR < timeout)) WATCHDOG_TimerClear(); + + IC1_InterruptFlagClear(); + + UART1_WriteInt(IC2TMR); + + uint8_t i; + for (i = 0; i < (mode & 0x3); i++) { + UART1_WriteInt(IC1BUF); + UART1_WriteInt(IC2BUF); + } + + IC_PARAMS_DisableAllModules(); + TMR2_Stop(); + + return SUCCESS; +} diff --git a/src/helpers/interval.h b/src/helpers/interval.h index bbe1608..0757c3b 100644 --- a/src/helpers/interval.h +++ b/src/helpers/interval.h @@ -86,8 +86,126 @@ extern "C" { * @return None */ void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler); - + + /** + * @brief Reads DMA status registry data + * + * @description + * This method will sequentially read register addresses at BUFFER pointer + * and all four DMA channel pointers. It will also read digital state parameters. + * + * There are no input parameters to this method. The output of this method should + * be read over serial in the following order. + * 1. (int) BUFFER pointer + * 2. (int) DMA Channel 0 pointer + * 3. (int) DMA Channel 1 pointer + * 4. (int) DMA Channel 2 pointer + * 5. (int) DMA Channel 3 pointer + * 6. (char) Digital states + * 7. (char) Digital states error + * + * @return SUCCESS + */ response_t INTERVAL_GetState(void); + + /** + * @brief Measures the time interval between two pin state change events + * + * @description + * This method will count the time difference between two pin change events + * attached to two pins. + * The events can be any event defined at the list of events in `IC_PARAMS_CAPTURE_MODE`. + * The pins should be any pin in the list of `PIN_MANAGER_DIGITAL_PINS`. + * + * @param timeout : period of wait until the operation is aborted + * @param pins : input pins defined at `PIN_MANAGER_DIGITAL_PINS` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | PIN EVENT 2 | PIN EVENT 1 | + * @param modes : pin change event defined at `IC_PARAMS_CAPTURE_MODE` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | X | X | EVENT 2 | EVENT 1 | + * + * The output of this method should be read over serial in the following order. + * 1. (int) IC1BUF - LSW + * 2. (int) IC2BUF - MSW + * Combine 1. and 2. to get the trigger time of the event 1 + * 3. (int) IC3BUF - LSW + * 4. (int) IC4BUF - MSW + * Combine 3. and 4. to get the trigger time of the event 2 + * 5. (int) IC2TMR + * + * @return SUCCESS + */ + response_t INTERVAL_IntervalMeasure(void); + + /** + * @brief Measures the time between multiple pin state change events + * + * @description + * This method will log time units for multiple changes occurred on + * defined digital pins. Unlike `INTERVAL_IntervalMeasure` where it + * measure only a single change of states, this method will measure + * upto 4 change of pin states. + * The events can be any event defined at the list of events in `IC_PARAMS_CAPTURE_MODE`. + * The pins should be any pin in the list of `PIN_MANAGER_DIGITAL_PINS`. + * + * @param timeout : period of wait until the operation is aborted + * @param pins : input pins defined at `PIN_MANAGER_DIGITAL_PINS` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | PIN EVENT 2 | PIN EVENT 1 | + * @param modes : pin change event defined at `IC_PARAMS_CAPTURE_MODE` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | X | X | EVENT 2 | EVENT 1 | + * @param intrpts : input pins defined at `PIN_MANAGER_DIGITAL_PINS` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | INTERRUPT 2 | INTERRUPT 1 | + * + * The output of this method should be read over serial in the following order. + * 1. (int) IC1BUF - LSW + * 2. (int) IC2BUF - MSW + * Combine 1. and 2. to get the trigger time of the change event. Depending on the + * intrpts, the two registers (1. and 2.) may need to be read repeatedly to capture + * timing data for each event occurrence. + * 3. (int) IC3BUF - LSW + * 4. (int) IC4BUF - MSW + * Combine 3. and 4. to get the trigger time of the change event. Depending on the + * intrpts, the two registers (3. and 4.) may need to be read repeatedly to capture + * timing data for each event occurrence. + * Note: ICxBUF is a 4-level buffer that can store time log for four change events. + * 5. (int) IC2TMR + * + * @return SUCCESS + */ + response_t INTERVAL_TimeMeasure(void); + + /** + * @brief Measures the time until a pin state change event occurs + * + * @description + * This method will stop counting time when the defined pin change event occurred. + * The event can be any event defined at the list of events in `IC_PARAMS_CAPTURE_MODE`. + * The pin should be any pin in the list of `PIN_MANAGER_DIGITAL_PINS`. + * + * @param timeout : period of wait until the operation is aborted + * @param mode : pin change event defined at `IC_PARAMS_CAPTURE_MODE` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | X | X | X | X | X | EVENT | + * @param pin : input pin defined at `PIN_MANAGER_DIGITAL_PINS` + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | X | X | X | X | PIN EVENT | + * + * The output of this method should be read over serial in the following order. + * 1. (int) IC2TMR + * 2. (int) IC1BUF - LSW + * 3. (int) IC2BUF - MSW + * Combine 2. and 3. to get the trigger time of the change event. Depending on the mode, + * the last two registers (2. and 3.) may need to be read repeatedly to capture timing + * data for each event occurrence. + * Note: ICxBUF is a 4-level buffer that can store time log for four change events. + * + * @return SUCCESS + */ + response_t INTERVAL_UntilEvent(void); // Getters and setters diff --git a/src/instruments/multimeter.c b/src/instruments/multimeter.c index 5438351..fa86d94 100644 --- a/src/instruments/multimeter.c +++ b/src/instruments/multimeter.c @@ -1,10 +1,19 @@ #include "../commands.h" #include "../bus/uart/uart1.h" #include "../helpers/delay.h" +#include "../helpers/interval.h" +#include "../registers/comparators/ic1.h" +#include "../registers/comparators/ic2.h" +#include "../registers/comparators/ic_params.h" #include "../registers/converters/adc1.h" #include "../registers/converters/ctmu.h" +#include "../registers/comparators/cmp4.h" +#include "../registers/comparators/cvr.h" #include "../registers/memory/dma.h" #include "../registers/system/pin_manager.h" +#include "../registers/timers/timer_params.h" +#include "../registers/timers/tmr2.h" +#include "../registers/timers/tmr3.h" #include "../registers/timers/tmr5.h" #include "multimeter.h" @@ -47,7 +56,7 @@ void GetCapacitance_InitCTMU_TMR5(uint8_t current_range, uint8_t trim, CTMUICONbits.IRNG = current_range; TMR5_Initialize(); - TMR5_PrescalerSet(TMR_PRESCALER_64); + TMR5_SetPrescaler(TMR_PRESCALER_64); TMR5_Period16BitSet(charge_time); } @@ -193,6 +202,140 @@ response_t MULTIMETER_GetCapacitance(void) { return SUCCESS; } +response_t MULTIMETER_HighFrequency(void) { + + uint8_t config = UART1_Read(); + + LED_SetLow(); + + if ((config & 0xF) == 4) { + CVR_SetupComparator(); + CMP4_SetupComparator(); + } + + RPINR3bits.T2CKR = PIN_MANAGER_DIGITAL_PINS[config & 0xF]; + + TMR2_Initialize(); + TMR3_Initialize(); + TMR5_Initialize(); + + TMR2_CombineWithTimer3(); + TMR2_SetExternalClockAsSource(); + TMR2_SetPrescaler((config >> 4) & 0x4); + TMR5_SetPrescaler(TMR_PRESCALER_256); + TMR5_Period16BitSet(25000); // 100 millisecond sampling + + _T5IP = 0x01; // Set Timer5 Interrupt Priority Level + TMR5_InterruptEnable(); + TMR2_Start(); + TMR5_Start(); + + TMR5_WaitForInterruptEvent(); + + LED_SetHigh(); + UART1_Write(1); // Scaling factor + UART1_WriteInt(TMR2_Counter16BitGet()); + UART1_WriteInt(TMR3_Carry16BitGet()); + + return SUCCESS; +} + +response_t MULTIMETER_HighFrequencyAlt(void) { + + uint8_t config = UART1_Read(); + + LED_SetLow(); + + if ((config & 0xF) == 4) { + CVR_SetupComparator(); + CMP4_SetupComparator(); + } + + TMR2_Initialize(); + TMR2_SetExternalClockAsSource(); + TMR2_SetPrescaler((config >> 4) & 0x4); + TMR5_Initialize(); + IC1_Initialize(); + IC2_Initialize(); + + RPINR7bits.IC1R = RPN_DEFAULT_PORT; + RPINR7bits.IC2R = RPN_DEFAULT_PORT; + RPINR3bits.T2CKR = PIN_MANAGER_DIGITAL_PINS[config & 0xF]; + + IC1_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER2); + IC1_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT_EVERY_SECOND); + IC1_CombineOddEvenICModules(); + IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER); + IC1_SetCaptureMode(IC_PARAMS_CAPTURE_MODE_EVERY_16TH_RISING_EDGE); + + IC2_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER2); + IC2_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT_EVERY_SECOND); + IC2_CombineOddEvenICModules(); + IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER); + IC2_SetCaptureMode(IC_PARAMS_CAPTURE_MODE_EVERY_16TH_RISING_EDGE); + + TMR5_SetPrescaler(TMR_PRESCALER_256); + TMR5_Period16BitSet(25000); // 100 millisecond sampling + + _T5IP = 0x01; + TMR2_Start(); + TMR5_Start(); + IC1_ManualTriggerSet(); + IC1_ManualTriggerSet(); + + TMR5_WaitForInterruptEvent(); + + LED_SetHigh(); + UART1_Write(1); // Scaling factor + UART1_WriteInt(IC1TMR); + UART1_WriteInt(IC2TMR); + + return SUCCESS; +} + +response_t MULTIMETER_LowFrequency(void) { + + uint16_t timeout = UART1_ReadInt(); + uint8_t config = UART1_Read(); + + RPINR7bits.IC1R = PIN_MANAGER_DIGITAL_PINS[config & 0xF]; + + IC1_Initialize(); + IC1_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER_PERIPHERAL); + IC1_CombineOddEvenICModules(); + IC1_SetCaptureMode(IC_PARAMS_CAPTURE_MODE_EVERY_16TH_RISING_EDGE); + IC1_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT_EVERY_SECOND); + + IC2_Initialize(); + IC2_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER_PERIPHERAL); + IC2_CombineOddEvenICModules(); + IC2_SetCaptureMode(IC_PARAMS_CAPTURE_MODE_EVERY_16TH_RISING_EDGE); + IC2_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT_EVERY_SECOND); + + IC1_ManualTriggerSet(); + IC2_ManualTriggerSet(); + SetDefaultDIGITAL_STATES(); + + IC1_InterruptFlagClear(); + while ((IC2TMR < timeout) && (!_IC1IF)); + IC1_InterruptFlagClear(); + + RPINR7bits.IC1R = RPN_DEFAULT_PORT; + + if ((IC2TMR() >= timeout) || + (IC2_HasCaptureBufferOverflowed())) { + UART1_Write(1); + } else { + UART1_Write(0); + } + + UART1_WriteInt(IC1_CaptureDataRead()); + UART1_WriteInt(IC2_CaptureDataRead()); + IC_PARAMS_DisableAllModules(); + + return SUCCESS; +} + response_t MULTIMETER_GetCTMUVolts(void) { uint8_t config = UART1_Read(); diff --git a/src/instruments/multimeter.h b/src/instruments/multimeter.h index 1e5aa5c..22c3f90 100644 --- a/src/instruments/multimeter.h +++ b/src/instruments/multimeter.h @@ -28,7 +28,78 @@ extern "C" { * @return SUCCESS */ response_t MULTIMETER_GetCapacitance(void); - + + /** + * @brief Count the frequency (occurrence) of a signal over a + * 100 ms time period using only timer registers + * + * @description + * This command function takes one argument over serial: + * 1. (uint8) Configuration byte: + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | PRE-SCALER | PIN | + * PIN: Pin from PIN_MANAGER_DIGITAL_PINS + * PRE-SCALER: Scaling factor from TIMER_PARAMS_PRESCALER + * + * This method will output the following data over serial + * 1. (char) scaling factor + * 2. (int) TIMER 2 (Least significant potion) + * 3. (int) TIMER 3 (Most significant potion) + * Combine 3. and 2. to structure the full timing data + * + * @return SUCCESS + */ + response_t MULTIMETER_HighFrequency(void); + + /** + * @brief Count the frequency (occurrence) of a signal over a + * 100 ms time period using input capture registers. Unlike + * `MULTIMETER_HighFrequency`, this method will down-sample the + * input signal frequency by a factor of 16 supporting higher + * frequency measurements. + * + * @description + * This command function takes one argument over serial: + * 1. (uint8) Configuration byte: + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | PRE-SCALER | PIN | + * PIN: Pin from PIN_MANAGER_DIGITAL_PINS + * PRE-SCALER: Scaling factor from TIMER_PARAMS_PRESCALER + * + * This method will output the following data over serial + * 1. (char) scaling factor + * 2. (int) IC1TMR (Least significant potion) + * 3. (int) IC2TMR (Most significant potion) + * Combine 3. and 2. to structure the full timing data + * + * @return SUCCESS + */ + response_t MULTIMETER_HighFrequencyAlt(void); + + /** + * @brief Count the frequency (occurrence) of a signal. This method + * is to be used for low frequency measurements as it only measures + * the time interval for 32 rising edges. This will have much finer + * granularity than high frequency measurement methods. + * + * @description + * This command function takes one argument over serial: + * 1. (uint16) Timeout: period of wait until the operation is aborted + * 1. (uint8) Configuration byte: + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | X | X | X | X | PIN | + * PIN: Pin from PIN_MANAGER_DIGITAL_PINS + * + * This method will output the following data over serial + * 1. (char) overflow flag + * 2. (int) IC1BUF (Least significant potion) + * 3. (int) IC2BUF (Most significant potion) + * Combine 3. and 2. to structure the full timing data + * + * @return SUCCESS + */ + response_t MULTIMETER_LowFrequency(void); + /** * @brief Measurements using Charge Time Measurement Unit * diff --git a/src/registers/comparators/ic1.c b/src/registers/comparators/ic1.c index eb8b0d9..c6ab02e 100644 --- a/src/registers/comparators/ic1.c +++ b/src/registers/comparators/ic1.c @@ -1,63 +1,63 @@ -#include "ic1.h" - -void IC1_Initialize(void) { - IC1_InitializeCON1(); - IC1_InitializeCON2(); -} - -void IC1_InitializeCON1(void) { - // Input capture continues to operate in CPU idle mode - IC1CON1bits.ICSIDL = 0; - // Input capture clock source is set to timer 3 - IC1CON1bits.ICTSEL = IC_PARAMS_CAPTURE_TIMER3; - // Interrupt on every capture event - IC1CON1bits.ICI = IC_PARAMS_CAPTURE_INTERRUPT_EVERY_EVENT; - // Capture event flags (Read Only; but settable) - IC1CON1bits.ICOV = 0; // No overflow - IC1CON1bits.ICBNE = 0; // Buffer empty - // Input capture mode is turned off - IC1CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; -} - -void IC1_InitializeCON2(void) { - // Input capture modules are not concatenated - IC1CON2bits.IC32 = 0; - // Input source is used to sync the capture timer - IC1CON2bits.ICTRIG = 0; - // IC1TMR is cleared and not triggered - IC1CON2bits.TRIGSTAT = 0; - // Input capture source is none - IC1CON2bits.SYNCSEL = IC_PARAMS_CAPTURE_SOURCE_NONE; -} - -void IC1_Start(IC_PARAMS_CAPTURE_MODE mode) { - IC1CON1bits.ICM = mode; -} - -void IC1_Stop(void) { - IC1CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; -} - -uint16_t IC1_CaptureDataRead(void) { - return (IC1BUF); -} - -void IC1_ManualTriggerSet(void) { - IC1CON2bits.TRIGSTAT = true; -} - -bool IC1_TriggerStatusGet(void) { - return (IC1CON2bits.TRIGSTAT); -} - -void IC1_TriggerStatusClear(void) { - IC1CON2bits.TRIGSTAT = 0; -} - -bool IC1_HasCaptureBufferOverflowed(void) { - return (IC1CON1bits.ICOV); -} - -bool IC1_IsCaptureBufferEmpty(void) { - return (!IC1CON1bits.ICBNE); -} +#include "ic1.h" + +void IC1_Initialize(void) { + IC1_InitializeCON1(); + IC1_InitializeCON2(); +} + +void IC1_InitializeCON1(void) { + // Input capture continues to operate in CPU idle mode + IC1CON1bits.ICSIDL = 0; + // Input capture clock source is set to timer 3 + IC1CON1bits.ICTSEL = IC_PARAMS_CAPTURE_TIMER3; + // Interrupt on every capture event + IC1CON1bits.ICI = IC_PARAMS_CAPTURE_INTERRUPT_EVERY_EVENT; + // Capture event flags (Read Only; but settable) + IC1CON1bits.ICOV = 0; // No overflow + IC1CON1bits.ICBNE = 0; // Buffer empty + // Input capture mode is turned off + IC1CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; +} + +void IC1_InitializeCON2(void) { + // Input capture modules are not concatenated + IC1CON2bits.IC32 = 0; + // Input source is used to sync the capture timer + IC1CON2bits.ICTRIG = 0; + // IC1TMR is cleared and not triggered + IC1CON2bits.TRIGSTAT = 0; + // Input capture source is none + IC1CON2bits.SYNCSEL = IC_PARAMS_CAPTURE_SOURCE_NONE; +} + +void IC1_Start(IC_PARAMS_CAPTURE_MODE mode) { + IC1CON1bits.ICM = mode; +} + +void IC1_Stop(void) { + IC1CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; +} + +uint16_t IC1_CaptureDataRead(void) { + return (IC1BUF); +} + +void IC1_ManualTriggerSet(void) { + IC1CON2bits.TRIGSTAT = true; +} + +bool IC1_TriggerStatusGet(void) { + return (IC1CON2bits.TRIGSTAT); +} + +void IC1_TriggerStatusClear(void) { + IC1CON2bits.TRIGSTAT = 0; +} + +bool IC1_HasCaptureBufferOverflowed(void) { + return (IC1CON1bits.ICOV); +} + +bool IC1_IsCaptureBufferEmpty(void) { + return (!IC1CON1bits.ICBNE); +} diff --git a/src/registers/comparators/ic1.h b/src/registers/comparators/ic1.h index 84de5db..8f02f25 100644 --- a/src/registers/comparators/ic1.h +++ b/src/registers/comparators/ic1.h @@ -1,293 +1,348 @@ -#ifndef _IC1_H -#define _IC1_H - -#include -#include -#include -#include "ic_params.h" - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - void IC1_Initialize(void); - - void IC1_InitializeCON1(void); - void IC1_InitializeCON2(void); - - /** - @Summary - Enables the IC module with the corresponding operation mode. - - @Description - This routine enables the IC module with the corresponding operation mode. - - @Preconditions - IC1_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None. - */ - void IC1_Start(IC_PARAMS_CAPTURE_MODE mode); - - /** - @Summary - Disables the IC module. - - @Description - This routine disables the IC module. - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC1_Initialize() for an example - - */ - void IC1_Stop(void); - - /** - @Summary - Reads the captured data from buffer. - - @Description - This routine reads the captured data from buffer. - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - Read data from buffer. - - @Example - Refer to IC1_Initialize() for an example - - */ - uint16_t IC1_CaptureDataRead(void); - - /** - @Summary - Sets the manual trigger - - @Description - This routine sets the manual trigger - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC1_TriggerStatusGet() for an example - */ - void IC1_ManualTriggerSet(void); - - /** - @Summary - Gets the status of the timer trigger. - - @Description - This routine gets the status of the timer trigger source if it has been triggered. - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the timer trigger status. - true : When the timer source has triggered and is running - false : When the timer has not triggered and being held clear - - @Example - <\code> - if(IC1_TriggerStatusGet()) - { - IC1_TriggerStatusClear(); - } - <\code> - */ - bool IC1_TriggerStatusGet(void); - - /** - @Summary - Clears the status of the timer trigger. - - @Description - This routine clears the status of the timer trigger. - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC1_TriggerStatusGet() for an example - */ - void IC1_TriggerStatusClear(void); - - /** - @Summary - Gets the buffer overflow status. - - @Description - This routine gets the buffer overflow status. - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer overflow status. - true : When the capture buffer has overflowed - false : When the capture buffer has not overflowed - - @Example - <\code> - bool status; - - status = IC1_HasCaptureBufferOverflowed(); - <\code> - */ - bool IC1_HasCaptureBufferOverflowed(void); - - /** - @Summary - Gets the buffer empty status. - - @Description - This routine gets the buffer empty status. - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer empty status. - True- If buffer empty - False-If buffer not empty - - @Example - Refer to IC1_Initialize() for an example - */ - bool IC1_IsCaptureBufferEmpty(void); - - /** - @Summary - Sets the timer source - - @Description - This routine sets the timer source for input capture module. - - @Preconditions - IC1_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_TIMER - - @Returns - None - */ - inline static void IC1_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { - IC1CON1bits.ICTSEL = timer; - } - - /** - @Summary - Sets the capture source - - @Description - This routine sets the capture source for input capture module. - - @Preconditions - IC1_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_SOURCE - - @Returns - None - */ - inline static void IC1_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { - IC1CON2bits.SYNCSEL = source; - } - - /** - @Summary - Sets the capture mode - - @Description - This routine sets the capture mode for input capture module. - - @Preconditions - IC1_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None - */ - inline static void IC1_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { - IC1CON1bits.ICM = mode; - } - - /** - @Summary - Combine IC modules - - @Description - This routine combines odd and even input capture modules to form a 32 bit - capture module. Need to set this for both odd and even IC modules - - @Preconditions - IC1_Initialize function should have been called - - @Param - None - - @Returns - None - */ - inline static void IC1_CombineOddEvenICModules(void) { - IC1CON2bits.IC32 = 1; - } - - inline static void IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { - IC1CON2bits.ICTRIG = t; - } - - inline static void IC1_InterruptFlagClear(void) { - IFS0bits.IC1IF = 0; - } - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_IC1_H +#ifndef _IC1_H +#define _IC1_H + +#include +#include +#include +#include "ic_params.h" + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + void IC1_Initialize(void); + + void IC1_InitializeCON1(void); + void IC1_InitializeCON2(void); + + /** + @Summary + Enables the IC module with the corresponding operation mode. + + @Description + This routine enables the IC module with the corresponding operation mode. + + @Preconditions + IC1_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None. + */ + void IC1_Start(IC_PARAMS_CAPTURE_MODE mode); + + /** + @Summary + Disables the IC module. + + @Description + This routine disables the IC module. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC1_Initialize() for an example + + */ + void IC1_Stop(void); + + /** + @Summary + Reads the captured data from buffer. + + @Description + This routine reads the captured data from buffer. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + Read data from buffer. + + @Example + Refer to IC1_Initialize() for an example + + */ + uint16_t IC1_CaptureDataRead(void); + + /** + @Summary + Sets the manual trigger + + @Description + This routine sets the manual trigger + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC1_TriggerStatusGet() for an example + */ + void IC1_ManualTriggerSet(void); + + /** + @Summary + Gets the status of the timer trigger. + + @Description + This routine gets the status of the timer trigger source if it has been triggered. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the timer trigger status. + true : When the timer source has triggered and is running + false : When the timer has not triggered and being held clear + + @Example + <\code> + if(IC1_TriggerStatusGet()) + { + IC1_TriggerStatusClear(); + } + <\code> + */ + bool IC1_TriggerStatusGet(void); + + /** + @Summary + Clears the status of the timer trigger. + + @Description + This routine clears the status of the timer trigger. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC1_TriggerStatusGet() for an example + */ + void IC1_TriggerStatusClear(void); + + /** + @Summary + Gets the buffer overflow status. + + @Description + This routine gets the buffer overflow status. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer overflow status. + true : When the capture buffer has overflowed + false : When the capture buffer has not overflowed + + @Example + <\code> + bool status; + + status = IC1_HasCaptureBufferOverflowed(); + <\code> + */ + bool IC1_HasCaptureBufferOverflowed(void); + + /** + @Summary + Gets the buffer empty status. + + @Description + This routine gets the buffer empty status. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer empty status. + True- If buffer empty + False-If buffer not empty + + @Example + Refer to IC1_Initialize() for an example + */ + bool IC1_IsCaptureBufferEmpty(void); + + /** + @Summary + Sets the timer source + + @Description + This routine sets the timer source for input capture module. + + @Preconditions + IC1_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_TIMER + + @Returns + None + */ + inline static void IC1_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { + IC1CON1bits.ICTSEL = timer; + } + + /** + @Summary + Sets the capture source + + @Description + This routine sets the capture source for input capture module. + + @Preconditions + IC1_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_SOURCE + + @Returns + None + */ + inline static void IC1_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { + IC1CON2bits.SYNCSEL = source; + } + + /** + @Summary + Sets the capture mode + + @Description + This routine sets the capture mode for input capture module. + + @Preconditions + IC1_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None + */ + inline static void IC1_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { + IC1CON1bits.ICM = mode; + } + + /** + @Summary + Combine IC modules + + @Description + This routine combines odd and even input capture modules to form a 32 bit + capture module. Need to set this for both odd and even IC modules + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC1_CombineOddEvenICModules(void) { + IC1CON2bits.IC32 = 1; + } + + /** + @Summary + Sets the trigger event for capture complete interrupt + + @Description + This routine sets the trigger event for the input capture module to + notify the ISR that a capture event is complete + + @Preconditions + IC1_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_INTERRUPT + + @Returns + None + */ + inline static void IC1_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) { + IC1CON1bits.ICI = i; + } + + /** + @Summary + Defines the purpose of input capture pin source + + @Description + This routine defines if the pin attached to IC module is used either to + trigger the IC1TMR or to synchronize the timer with another timer module. + + @Preconditions + IC1_Initialize function should have been called + + @Param + IC_PARAMS_SOURCE_TASK + + @Returns + None + */ + inline static void IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { + IC1CON2bits.ICTRIG = t; + } + + /** + @Summary + Clears the set interrupt flag of IC1 capture interrupt + + @Description + This routine will clear the interrupt flag of the IC1 capture + module. + + @Preconditions + IC1_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC1_InterruptFlagClear(void) { + IFS0bits.IC1IF = 0; + } + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_IC1_H diff --git a/src/registers/comparators/ic2.c b/src/registers/comparators/ic2.c index 62f8fae..748e2e3 100644 --- a/src/registers/comparators/ic2.c +++ b/src/registers/comparators/ic2.c @@ -1,63 +1,63 @@ -#include "ic2.h" - -void IC2_Initialize(void) { - IC2_InitializeCON1(); - IC2_InitializeCON2(); -} - -void IC2_InitializeCON1(void) { - // Input capture continues to operate in CPU idle mode - IC2CON1bits.ICSIDL = 0; - // Input capture clock source is set to timer 3 - IC2CON1bits.ICTSEL = IC_PARAMS_CAPTURE_TIMER3; - // Interrupt on every capture event - IC2CON1bits.ICI = IC_PARAMS_CAPTURE_INTERRUPT_EVERY_EVENT; - // Capture event flags (Read Only; but settable) - IC2CON1bits.ICOV = 0; // No overflow - IC2CON1bits.ICBNE = 0; // Buffer empty - // Input capture mode is turned off - IC2CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; -} - -void IC2_InitializeCON2(void) { - // Input capture modules are not concatenated - IC2CON2bits.IC32 = 0; - // Input source is used to sync the capture timer - IC2CON2bits.ICTRIG = 0; - // IC2TMR is cleared and not triggered - IC2CON2bits.TRIGSTAT = 0; - // Input capture source is none - IC2CON2bits.SYNCSEL = IC_PARAMS_CAPTURE_SOURCE_NONE; -} - -void IC2_Start(IC_PARAMS_CAPTURE_MODE mode) { - IC2CON1bits.ICM = mode; -} - -void IC2_Stop(void) { - IC2CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; -} - -uint16_t IC2_CaptureDataRead(void) { - return (IC2BUF); -} - -void IC2_ManualTriggerSet(void) { - IC2CON2bits.TRIGSTAT = true; -} - -bool IC2_TriggerStatusGet(void) { - return (IC2CON2bits.TRIGSTAT); -} - -void IC2_TriggerStatusClear(void) { - IC2CON2bits.TRIGSTAT = 0; -} - -bool IC2_HasCaptureBufferOverflowed(void) { - return (IC2CON1bits.ICOV); -} - -bool IC2_IsCaptureBufferEmpty(void) { - return (!IC2CON1bits.ICBNE); -} +#include "ic2.h" + +void IC2_Initialize(void) { + IC2_InitializeCON1(); + IC2_InitializeCON2(); +} + +void IC2_InitializeCON1(void) { + // Input capture continues to operate in CPU idle mode + IC2CON1bits.ICSIDL = 0; + // Input capture clock source is set to timer 3 + IC2CON1bits.ICTSEL = IC_PARAMS_CAPTURE_TIMER3; + // Interrupt on every capture event + IC2CON1bits.ICI = IC_PARAMS_CAPTURE_INTERRUPT_EVERY_EVENT; + // Capture event flags (Read Only; but settable) + IC2CON1bits.ICOV = 0; // No overflow + IC2CON1bits.ICBNE = 0; // Buffer empty + // Input capture mode is turned off + IC2CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; +} + +void IC2_InitializeCON2(void) { + // Input capture modules are not concatenated + IC2CON2bits.IC32 = 0; + // Input source is used to sync the capture timer + IC2CON2bits.ICTRIG = 0; + // IC2TMR is cleared and not triggered + IC2CON2bits.TRIGSTAT = 0; + // Input capture source is none + IC2CON2bits.SYNCSEL = IC_PARAMS_CAPTURE_SOURCE_NONE; +} + +void IC2_Start(IC_PARAMS_CAPTURE_MODE mode) { + IC2CON1bits.ICM = mode; +} + +void IC2_Stop(void) { + IC2CON1bits.ICM = IC_PARAMS_CAPTURE_MODE_OFF; +} + +uint16_t IC2_CaptureDataRead(void) { + return (IC2BUF); +} + +void IC2_ManualTriggerSet(void) { + IC2CON2bits.TRIGSTAT = true; +} + +bool IC2_TriggerStatusGet(void) { + return (IC2CON2bits.TRIGSTAT); +} + +void IC2_TriggerStatusClear(void) { + IC2CON2bits.TRIGSTAT = 0; +} + +bool IC2_HasCaptureBufferOverflowed(void) { + return (IC2CON1bits.ICOV); +} + +bool IC2_IsCaptureBufferEmpty(void) { + return (!IC2CON1bits.ICBNE); +} diff --git a/src/registers/comparators/ic2.h b/src/registers/comparators/ic2.h index 0ab6865..59ada3c 100644 --- a/src/registers/comparators/ic2.h +++ b/src/registers/comparators/ic2.h @@ -1,299 +1,354 @@ -#ifndef _IC2_H -#define _IC2_H - -#include -#include -#include -#include "ic_params.h" - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - void IC2_Initialize(void); - - void IC2_InitializeCON1(void); - void IC2_InitializeCON2(void); - - /** - @Summary - Enables the IC module with the corresponding operation mode. - - @Description - This routine enables the IC module with the corresponding operation mode. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC2_Initialize() for an example - - */ - void IC2_Start(IC_PARAMS_CAPTURE_MODE mode); - - /** - @Summary - Disables the IC module. - - @Description - This routine disables the IC module. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC2_Initialize() for an example - - */ - void IC2_Stop(void); - - /** - @Summary - Reads the captured data from buffer. - - @Description - This routine reads the captured data from buffer. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - Read data from buffer. - - @Example - Refer to IC2_Initialize() for an example - - */ - uint16_t IC2_CaptureDataRead(void); - - /** - @Summary - Sets the manual trigger - - @Description - This routine sets the manual trigger - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC2_TriggerStatusGet() for an example - - */ - void IC2_ManualTriggerSet(void); - - /** - @Summary - Gets the status of the timer trigger. - - @Description - This routine gets the status of the timer trigger source if it has been triggered. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the timer trigger status. - true : When the timer source has triggered and is running - false : When the timer has not triggered and being held clear - - @Example - <\code> - if(IC2_TriggerStatusGet()) - { - IC2_TriggerStatusClear(); - } - <\code> - */ - bool IC2_TriggerStatusGet(void); - - /** - @Summary - Clears the status of the timer trigger. - - @Description - This routine clears the status of the timer trigger. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC2_TriggerStatusGet() for an example - - */ - void IC2_TriggerStatusClear(void); - - /** - @Summary - Gets the buffer overflow status. - - @Description - This routine gets the buffer overflow status. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer overflow status. - true : When the capture buffer has overflowed - false : When the capture buffer has not overflowed - - @Example - <\code> - bool status; - - status = IC2_HasCaptureBufferOverflowed(); - <\code> - */ - bool IC2_HasCaptureBufferOverflowed(void); - - /** - @Summary - Gets the buffer empty status. - - @Description - This routine gets the buffer empty status. - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer empty status. - True- If buffer empty - False-If buffer not empty - - @Example - Refer to IC2_Initialize() for an example - */ - bool IC2_IsCaptureBufferEmpty(void); - - /** - @Summary - Sets the timer source - - @Description - This routine sets the timer source for input capture module. - - @Preconditions - IC2_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_TIMER - - @Returns - None - */ - inline static void IC2_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { - IC2CON1bits.ICTSEL = timer; - } - - /** - @Summary - Sets the capture source - - @Description - This routine sets the capture source for input capture module. - - @Preconditions - IC2_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_SOURCE - - @Returns - None - */ - inline static void IC2_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { - IC2CON2bits.SYNCSEL = source; - } - - /** - @Summary - Sets the capture mode - - @Description - This routine sets the capture mode for input capture module. - - @Preconditions - IC2_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None - */ - inline static void IC2_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { - IC2CON1bits.ICM = mode; - } - - /** - @Summary - Combine IC modules - - @Description - This routine combines odd and even input capture modules to form a 32 bit - capture module. Need to set this for both odd and even IC modules - - @Preconditions - IC2_Initialize function should have been called - - @Param - None - - @Returns - None - */ - inline static void IC2_CombineOddEvenICModules(void) { - IC2CON2bits.IC32 = 1; - } - - inline static void IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { - IC2CON2bits.ICTRIG = t; - } - - inline static void IC2_InterruptFlagClear(void) { - IFS0bits.IC2IF = 0; - } - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_IC2_H +#ifndef _IC2_H +#define _IC2_H + +#include +#include +#include +#include "ic_params.h" + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + void IC2_Initialize(void); + + void IC2_InitializeCON1(void); + void IC2_InitializeCON2(void); + + /** + @Summary + Enables the IC module with the corresponding operation mode. + + @Description + This routine enables the IC module with the corresponding operation mode. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC2_Initialize() for an example + + */ + void IC2_Start(IC_PARAMS_CAPTURE_MODE mode); + + /** + @Summary + Disables the IC module. + + @Description + This routine disables the IC module. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC2_Initialize() for an example + + */ + void IC2_Stop(void); + + /** + @Summary + Reads the captured data from buffer. + + @Description + This routine reads the captured data from buffer. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + Read data from buffer. + + @Example + Refer to IC2_Initialize() for an example + + */ + uint16_t IC2_CaptureDataRead(void); + + /** + @Summary + Sets the manual trigger + + @Description + This routine sets the manual trigger + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC2_TriggerStatusGet() for an example + + */ + void IC2_ManualTriggerSet(void); + + /** + @Summary + Gets the status of the timer trigger. + + @Description + This routine gets the status of the timer trigger source if it has been triggered. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the timer trigger status. + true : When the timer source has triggered and is running + false : When the timer has not triggered and being held clear + + @Example + <\code> + if(IC2_TriggerStatusGet()) + { + IC2_TriggerStatusClear(); + } + <\code> + */ + bool IC2_TriggerStatusGet(void); + + /** + @Summary + Clears the status of the timer trigger. + + @Description + This routine clears the status of the timer trigger. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC2_TriggerStatusGet() for an example + + */ + void IC2_TriggerStatusClear(void); + + /** + @Summary + Gets the buffer overflow status. + + @Description + This routine gets the buffer overflow status. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer overflow status. + true : When the capture buffer has overflowed + false : When the capture buffer has not overflowed + + @Example + <\code> + bool status; + + status = IC2_HasCaptureBufferOverflowed(); + <\code> + */ + bool IC2_HasCaptureBufferOverflowed(void); + + /** + @Summary + Gets the buffer empty status. + + @Description + This routine gets the buffer empty status. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer empty status. + True- If buffer empty + False-If buffer not empty + + @Example + Refer to IC2_Initialize() for an example + */ + bool IC2_IsCaptureBufferEmpty(void); + + /** + @Summary + Sets the timer source + + @Description + This routine sets the timer source for input capture module. + + @Preconditions + IC2_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_TIMER + + @Returns + None + */ + inline static void IC2_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { + IC2CON1bits.ICTSEL = timer; + } + + /** + @Summary + Sets the capture source + + @Description + This routine sets the capture source for input capture module. + + @Preconditions + IC2_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_SOURCE + + @Returns + None + */ + inline static void IC2_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { + IC2CON2bits.SYNCSEL = source; + } + + /** + @Summary + Sets the capture mode + + @Description + This routine sets the capture mode for input capture module. + + @Preconditions + IC2_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None + */ + inline static void IC2_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { + IC2CON1bits.ICM = mode; + } + + /** + @Summary + Combine IC modules + + @Description + This routine combines odd and even input capture modules to form a 32 bit + capture module. Need to set this for both odd and even IC modules + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC2_CombineOddEvenICModules(void) { + IC2CON2bits.IC32 = 1; + } + + /** + @Summary + Sets the trigger event for capture complete interrupt + + @Description + This routine sets the trigger event for the input capture module to + notify the ISR that a capture event is complete + + @Preconditions + IC2_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_INTERRUPT + + @Returns + None + */ + inline static void IC2_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) { + IC2CON1bits.ICI = i; + } + + /** + @Summary + Defines the purpose of input capture pin source + + @Description + This routine defines if the pin attached to IC module is used either to + trigger the IC2TMR or to synchronize the timer with another timer module. + + @Preconditions + IC2_Initialize function should have been called + + @Param + IC_PARAMS_SOURCE_TASK + + @Returns + None + */ + inline static void IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { + IC2CON2bits.ICTRIG = t; + } + + /** + @Summary + Clears the set interrupt flag of IC2 capture interrupt + + @Description + This routine will clear the interrupt flag of the IC2 capture + module. + + @Preconditions + IC2_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC2_InterruptFlagClear(void) { + IFS0bits.IC2IF = 0; + } + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_IC2_H diff --git a/src/registers/comparators/ic3.h b/src/registers/comparators/ic3.h index 2d96dd5..54ebe3f 100644 --- a/src/registers/comparators/ic3.h +++ b/src/registers/comparators/ic3.h @@ -1,299 +1,354 @@ -#ifndef _IC3_H -#define _IC3_H - -#include -#include -#include -#include "ic_params.h" - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - void IC3_Initialize(void); - - void IC3_InitializeCON1(void); - void IC3_InitializeCON2(void); - - /** - @Summary - Enables the IC module with the corresponding operation mode. - - @Description - This routine enables the IC module with the corresponding operation mode. - - @Preconditions - IC3_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None. - - @Example - Refer to IC3_Initialize() for an example - - */ - void IC3_Start(IC_PARAMS_CAPTURE_MODE mode); - - /** - @Summary - Disables the IC module. - - @Description - This routine disables the IC module. - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC3_Initialize() for an example - - */ - void IC3_Stop(void); - - /** - @Summary - Reads the captured data from buffer. - - @Description - This routine reads the captured data from buffer. - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - Read data from buffer. - - @Example - Refer to IC3_Initialize() for an example - - */ - uint16_t IC3_CaptureDataRead(void); - - /** - @Summary - Sets the manual trigger - - @Description - This routine sets the manual trigger - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC3_TriggerStatusGet() for an example - - */ - void IC3_ManualTriggerSet(void); - - /** - @Summary - Gets the status of the timer trigger. - - @Description - This routine gets the status of the timer trigger source if it has been triggered. - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the timer trigger status. - true : When the timer source has triggered and is running - false : When the timer has not triggered and being held clear - - @Example - <\code> - if(IC3_TriggerStatusGet()) - { - IC3_TriggerStatusClear(); - } - <\code> - */ - bool IC3_TriggerStatusGet(void); - - /** - @Summary - Clears the status of the timer trigger. - - @Description - This routine clears the status of the timer trigger. - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC3_TriggerStatusGet() for an example - - */ - void IC3_TriggerStatusClear(void); - - /** - @Summary - Gets the buffer overflow status. - - @Description - This routine gets the buffer overflow status. - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer overflow status. - true : When the capture buffer has overflowed - false : When the capture buffer has not overflowed - - @Example - <\code> - bool status; - - status = IC3_HasCaptureBufferOverflowed(); - <\code> - */ - bool IC3_HasCaptureBufferOverflowed(void); - - /** - @Summary - Gets the buffer empty status. - - @Description - This routine gets the buffer empty status. - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer empty status. - True- If buffer empty - False-If buffer not empty - - @Example - Refer to IC3_Initialize() for an example - */ - bool IC3_IsCaptureBufferEmpty(void); - - /** - @Summary - Sets the timer source - - @Description - This routine sets the timer source for input capture module. - - @Preconditions - IC3_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_TIMER - - @Returns - None - */ - inline static void IC3_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { - IC3CON1bits.ICTSEL = timer; - } - - /** - @Summary - Sets the capture source - - @Description - This routine sets the capture source for input capture module. - - @Preconditions - IC3_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_SOURCE - - @Returns - None - */ - inline static void IC3_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { - IC3CON2bits.SYNCSEL = source; - } - - /** - @Summary - Sets the capture mode - - @Description - This routine sets the capture mode for input capture module. - - @Preconditions - IC3_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None - */ - inline static void IC3_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { - IC3CON1bits.ICM = mode; - } - - /** - @Summary - Combine IC modules - - @Description - This routine combines odd and even input capture modules to form a 32 bit - capture module. Need to set this for both odd and even IC modules - - @Preconditions - IC3_Initialize function should have been called - - @Param - None - - @Returns - None - */ - inline static void IC3_CombineOddEvenICModules(void) { - IC3CON2bits.IC32 = 1; - } - - inline static void IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { - IC3CON2bits.ICTRIG = t; - } - - inline static void IC3_InterruptFlagClear(void) { - IFS2bits.IC3IF = 0; - } - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_IC3_H +#ifndef _IC3_H +#define _IC3_H + +#include +#include +#include +#include "ic_params.h" + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + void IC3_Initialize(void); + + void IC3_InitializeCON1(void); + void IC3_InitializeCON2(void); + + /** + @Summary + Enables the IC module with the corresponding operation mode. + + @Description + This routine enables the IC module with the corresponding operation mode. + + @Preconditions + IC3_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None. + + @Example + Refer to IC3_Initialize() for an example + + */ + void IC3_Start(IC_PARAMS_CAPTURE_MODE mode); + + /** + @Summary + Disables the IC module. + + @Description + This routine disables the IC module. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC3_Initialize() for an example + + */ + void IC3_Stop(void); + + /** + @Summary + Reads the captured data from buffer. + + @Description + This routine reads the captured data from buffer. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + Read data from buffer. + + @Example + Refer to IC3_Initialize() for an example + + */ + uint16_t IC3_CaptureDataRead(void); + + /** + @Summary + Sets the manual trigger + + @Description + This routine sets the manual trigger + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC3_TriggerStatusGet() for an example + + */ + void IC3_ManualTriggerSet(void); + + /** + @Summary + Gets the status of the timer trigger. + + @Description + This routine gets the status of the timer trigger source if it has been triggered. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the timer trigger status. + true : When the timer source has triggered and is running + false : When the timer has not triggered and being held clear + + @Example + <\code> + if(IC3_TriggerStatusGet()) + { + IC3_TriggerStatusClear(); + } + <\code> + */ + bool IC3_TriggerStatusGet(void); + + /** + @Summary + Clears the status of the timer trigger. + + @Description + This routine clears the status of the timer trigger. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC3_TriggerStatusGet() for an example + + */ + void IC3_TriggerStatusClear(void); + + /** + @Summary + Gets the buffer overflow status. + + @Description + This routine gets the buffer overflow status. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer overflow status. + true : When the capture buffer has overflowed + false : When the capture buffer has not overflowed + + @Example + <\code> + bool status; + + status = IC3_HasCaptureBufferOverflowed(); + <\code> + */ + bool IC3_HasCaptureBufferOverflowed(void); + + /** + @Summary + Gets the buffer empty status. + + @Description + This routine gets the buffer empty status. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer empty status. + True- If buffer empty + False-If buffer not empty + + @Example + Refer to IC3_Initialize() for an example + */ + bool IC3_IsCaptureBufferEmpty(void); + + /** + @Summary + Sets the timer source + + @Description + This routine sets the timer source for input capture module. + + @Preconditions + IC3_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_TIMER + + @Returns + None + */ + inline static void IC3_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { + IC3CON1bits.ICTSEL = timer; + } + + /** + @Summary + Sets the capture source + + @Description + This routine sets the capture source for input capture module. + + @Preconditions + IC3_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_SOURCE + + @Returns + None + */ + inline static void IC3_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { + IC3CON2bits.SYNCSEL = source; + } + + /** + @Summary + Sets the capture mode + + @Description + This routine sets the capture mode for input capture module. + + @Preconditions + IC3_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None + */ + inline static void IC3_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { + IC3CON1bits.ICM = mode; + } + + /** + @Summary + Combine IC modules + + @Description + This routine combines odd and even input capture modules to form a 32 bit + capture module. Need to set this for both odd and even IC modules + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC3_CombineOddEvenICModules(void) { + IC3CON2bits.IC32 = 1; + } + + /** + @Summary + Sets the trigger event for capture complete interrupt + + @Description + This routine sets the trigger event for the input capture module to + notify the ISR that a capture event is complete + + @Preconditions + IC3_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_INTERRUPT + + @Returns + None + */ + inline static void IC3_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) { + IC3CON1bits.ICI = i; + } + + /** + @Summary + Defines the purpose of input capture pin source + + @Description + This routine defines if the pin attached to IC module is used either to + trigger the IC3TMR or to synchronize the timer with another timer module. + + @Preconditions + IC3_Initialize function should have been called + + @Param + IC_PARAMS_SOURCE_TASK + + @Returns + None + */ + inline static void IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { + IC3CON2bits.ICTRIG = t; + } + + /** + @Summary + Clears the set interrupt flag of IC3 capture interrupt + + @Description + This routine will clear the interrupt flag of the IC3 capture + module. + + @Preconditions + IC3_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC3_InterruptFlagClear(void) { + IFS2bits.IC3IF = 0; + } + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_IC3_H diff --git a/src/registers/comparators/ic4.h b/src/registers/comparators/ic4.h index 19413c6..9bd200a 100644 --- a/src/registers/comparators/ic4.h +++ b/src/registers/comparators/ic4.h @@ -1,311 +1,382 @@ -#ifndef _IC4_H -#define _IC4_H - -#include -#include -#include -#include "ic_params.h" - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - void IC4_Initialize(void); - - void IC4_InitializeCON1(void); - void IC4_InitializeCON2(void); - - /** - @Summary - Enables the IC module with the corresponding operation mode. - - @Description - This routine enables the IC module with the corresponding operation mode. - - @Preconditions - IC4_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None. - - @Example - Refer to IC4_Initialize() for an example - - */ - void IC4_Start(IC_PARAMS_CAPTURE_MODE mode); - - /** - @Summary - Disables the IC module. - - @Description - This routine disables the IC module. - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC4_Initialize() for an example - - */ - void IC4_Stop(void); - - /** - @Summary - Reads the captured data from buffer. - - @Description - This routine reads the captured data from buffer. - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - Read data from buffer. - - @Example - Refer to IC4_Initialize() for an example - - */ - uint16_t IC4_CaptureDataRead(void); - - /** - @Summary - Sets the manual trigger - - @Description - This routine sets the manual trigger - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC4_TriggerStatusGet() for an example - - */ - void IC4_ManualTriggerSet(void); - - /** - @Summary - Gets the status of the timer trigger. - - @Description - This routine gets the status of the timer trigger source if it has been triggered. - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the timer trigger status. - true : When the timer source has triggered and is running - false : When the timer has not triggered and being held clear - - @Example - <\code> - if(IC4_TriggerStatusGet()) - { - IC4_TriggerStatusClear(); - } - <\code> - */ - bool IC4_TriggerStatusGet(void); - - /** - @Summary - Clears the status of the timer trigger. - - @Description - This routine clears the status of the timer trigger. - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - None. - - @Example - Refer to IC4_TriggerStatusGet() for an example - - */ - void IC4_TriggerStatusClear(void); - - /** - @Summary - Gets the buffer overflow status. - - @Description - This routine gets the buffer overflow status. - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer overflow status. - true : When the capture buffer has overflowed - false : When the capture buffer has not overflowed - - @Example - <\code> - bool status; - - status = IC4_HasCaptureBufferOverflowed(); - <\code> - */ - bool IC4_HasCaptureBufferOverflowed(void); - - /** - @Summary - Gets the buffer empty status. - - @Description - This routine gets the buffer empty status. - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - Boolean value describing the buffer empty status. - True- If buffer empty - False-If buffer not empty - - @Example - Refer to IC4_Initialize() for an example - */ - bool IC4_IsCaptureBufferEmpty(void); - - /** - @Summary - Sets the timer source - - @Description - This routine sets the timer source for input capture module. - - @Preconditions - IC4_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_TIMER - - @Returns - None - */ - inline static void IC4_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { - IC4CON1bits.ICTSEL = timer; - } - - /** - @Summary - Sets the capture source - - @Description - This routine sets the capture source for input capture module. - - @Preconditions - IC4_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_SOURCE - - @Returns - None - */ - inline static void IC4_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { - IC4CON2bits.SYNCSEL = source; - } - - /** - @Summary - Sets the capture mode - - @Description - This routine sets the capture mode for input capture module. - - @Preconditions - IC4_Initialize function should have been called - - @Param - IC_PARAMS_CAPTURE_MODE - - @Returns - None - */ - inline static void IC4_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { - IC4CON1bits.ICM = mode; - } - - /** - @Summary - Combine IC modules - - @Description - This routine combines odd and even input capture modules to form a 32 bit - capture module. Need to set this for both odd and even IC modules - - @Preconditions - IC4_Initialize function should have been called - - @Param - None - - @Returns - None - */ - inline static void IC4_CombineOddEvenICModules(void) { - IC4CON2bits.IC32 = 1; - } - - inline static void IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { - IC4CON2bits.ICTRIG = t; - } - - inline static void IC4_InterruptFlagClear(void) { - IFS2bits.IC4IF = 0; - } - - inline static void IC4_InterruptEnable(void) { - IEC2bits.IC4IE = 1; - } - - inline static void IC4_InterruptDisable(void) { - IEC2bits.IC4IE = 0; - } - - inline static void IC4_InterruptHighPriority(void) { - IPC9bits.IC4IP = 7; - } - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_IC4_H +#ifndef _IC4_H +#define _IC4_H + +#include +#include +#include +#include "ic_params.h" + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + void IC4_Initialize(void); + + void IC4_InitializeCON1(void); + void IC4_InitializeCON2(void); + + /** + @Summary + Enables the IC module with the corresponding operation mode. + + @Description + This routine enables the IC module with the corresponding operation mode. + + @Preconditions + IC4_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None. + + @Example + Refer to IC4_Initialize() for an example + + */ + void IC4_Start(IC_PARAMS_CAPTURE_MODE mode); + + /** + @Summary + Disables the IC module. + + @Description + This routine disables the IC module. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC4_Initialize() for an example + + */ + void IC4_Stop(void); + + /** + @Summary + Reads the captured data from buffer. + + @Description + This routine reads the captured data from buffer. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + Read data from buffer. + + @Example + Refer to IC4_Initialize() for an example + + */ + uint16_t IC4_CaptureDataRead(void); + + /** + @Summary + Sets the manual trigger + + @Description + This routine sets the manual trigger + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC4_TriggerStatusGet() for an example + + */ + void IC4_ManualTriggerSet(void); + + /** + @Summary + Gets the status of the timer trigger. + + @Description + This routine gets the status of the timer trigger source if it has been triggered. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the timer trigger status. + true : When the timer source has triggered and is running + false : When the timer has not triggered and being held clear + + @Example + <\code> + if(IC4_TriggerStatusGet()) + { + IC4_TriggerStatusClear(); + } + <\code> + */ + bool IC4_TriggerStatusGet(void); + + /** + @Summary + Clears the status of the timer trigger. + + @Description + This routine clears the status of the timer trigger. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + None. + + @Example + Refer to IC4_TriggerStatusGet() for an example + + */ + void IC4_TriggerStatusClear(void); + + /** + @Summary + Gets the buffer overflow status. + + @Description + This routine gets the buffer overflow status. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer overflow status. + true : When the capture buffer has overflowed + false : When the capture buffer has not overflowed + + @Example + <\code> + bool status; + + status = IC4_HasCaptureBufferOverflowed(); + <\code> + */ + bool IC4_HasCaptureBufferOverflowed(void); + + /** + @Summary + Gets the buffer empty status. + + @Description + This routine gets the buffer empty status. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + Boolean value describing the buffer empty status. + True- If buffer empty + False-If buffer not empty + + @Example + Refer to IC4_Initialize() for an example + */ + bool IC4_IsCaptureBufferEmpty(void); + + /** + @Summary + Sets the timer source + + @Description + This routine sets the timer source for input capture module. + + @Preconditions + IC4_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_TIMER + + @Returns + None + */ + inline static void IC4_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER timer) { + IC4CON1bits.ICTSEL = timer; + } + + /** + @Summary + Sets the capture source + + @Description + This routine sets the capture source for input capture module. + + @Preconditions + IC4_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_SOURCE + + @Returns + None + */ + inline static void IC4_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE source) { + IC4CON2bits.SYNCSEL = source; + } + + /** + @Summary + Sets the capture mode + + @Description + This routine sets the capture mode for input capture module. + + @Preconditions + IC4_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_MODE + + @Returns + None + */ + inline static void IC4_SetCaptureMode(IC_PARAMS_CAPTURE_MODE mode) { + IC4CON1bits.ICM = mode; + } + + /** + @Summary + Combine IC modules + + @Description + This routine combines odd and even input capture modules to form a 32 bit + capture module. Need to set this for both odd and even IC modules + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC4_CombineOddEvenICModules(void) { + IC4CON2bits.IC32 = 1; + } + + /** + @Summary + Defines the purpose of input capture pin source + + @Description + This routine defines if the pin attached to IC module is used either to + trigger the IC4TMR or to synchronize the timer with another timer module. + + @Preconditions + IC4_Initialize function should have been called + + @Param + IC_PARAMS_SOURCE_TASK + + @Returns + None + */ + inline static void IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK t) { + IC4CON2bits.ICTRIG = t; + } + + /** + @Summary + Clears the set interrupt flag of IC4 capture interrupt + + @Description + This routine will clear the interrupt flag of the IC4 capture + module. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC4_InterruptFlagClear(void) { + IFS2bits.IC4IF = 0; + } + + /** + @Summary + Enable IC4 interrupt + + @Description + This routine will enable IC4 interrupt. + + @Preconditions + IC4_Initialize function should have been called + + @Param + None + + @Returns + None + */ + inline static void IC4_InterruptEnable(void) { + IEC2bits.IC4IE = 1; + } + + /** + @Summary + Sets the trigger event for capture complete interrupt + + @Description + This routine sets the trigger event for the input capture module to + notify the ISR that a capture event is complete + + @Preconditions + IC4_Initialize function should have been called + + @Param + IC_PARAMS_CAPTURE_INTERRUPT + + @Returns + None + */ + inline static void IC4_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) { + IC4CON1bits.ICI = i; + } + + inline static void IC4_InterruptDisable(void) { + IEC2bits.IC4IE = 0; + } + + inline static void IC4_InterruptHighPriority(void) { + IPC9bits.IC4IP = 7; + } + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_IC4_H diff --git a/src/registers/comparators/ic_params.c b/src/registers/comparators/ic_params.c index 0cd53fd..0f01e09 100644 --- a/src/registers/comparators/ic_params.c +++ b/src/registers/comparators/ic_params.c @@ -2,6 +2,7 @@ #include "ic2.h" #include "ic3.h" #include "ic4.h" +#include "../system/pin_manager.h" void IC_PARAMS_InitiateAll(void) { IC1_Initialize(); @@ -63,4 +64,52 @@ void IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER t) { IC2_SetCaptureTimer(t); IC3_SetCaptureTimer(t); IC4_SetCaptureTimer(t); -} \ No newline at end of file +} + +void IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(uint8_t pin, + IC_PARAMS_CAPTURE_TIMER timer, + IC_PARAMS_CAPTURE_INTERRUPT intrpt, + IC_PARAMS_CAPTURE_MODE mode) { + + IC1_InterruptFlagClear(); + + RPINR7bits.IC1R = PIN_MANAGER_DIGITAL_PINS[pin]; + + IC1_Initialize(); + IC1_CombineOddEvenICModules(); + IC1_SetCaptureTimer(timer); + IC1_InputCaptureInterruptOn(intrpt); + IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER); + IC1_SetCaptureMode(mode); + + IC2_Initialize(); + IC2_CombineOddEvenICModules(); + IC2_SetCaptureTimer(timer); + IC2_InputCaptureInterruptOn(intrpt); + IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER); + IC2_SetCaptureMode(mode); +} + +void IC_PARAMS_ConfigureIntervalCaptureWithIC3AndIC4(uint8_t pin, + IC_PARAMS_CAPTURE_TIMER timer, + IC_PARAMS_CAPTURE_INTERRUPT intrpt, + IC_PARAMS_CAPTURE_MODE mode) { + + IC3_InterruptFlagClear(); + + RPINR8bits.IC3R = PIN_MANAGER_DIGITAL_PINS[pin]; + + IC3_Initialize(); + IC3_CombineOddEvenICModules(); + IC3_SetCaptureTimer(timer); + IC3_InputCaptureInterruptOn(intrpt); + IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER); + IC3_SetCaptureMode(mode); + + IC4_Initialize(); + IC4_CombineOddEvenICModules(); + IC4_SetCaptureTimer(timer); + IC4_InputCaptureInterruptOn(intrpt); + IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER); + IC4_SetCaptureMode(mode); +} diff --git a/src/registers/comparators/ic_params.h b/src/registers/comparators/ic_params.h index 90659d4..45af699 100644 --- a/src/registers/comparators/ic_params.h +++ b/src/registers/comparators/ic_params.h @@ -88,6 +88,54 @@ extern "C" { void IC_PARAMS_CombineOddEvenModules(void); void IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER); + + /** + @Summary + Combines IC1 and IC2 modules to enable concatenated operation + + @Description + This routine combines both IC1 and IC2 capture modules to act + them as 32-bit counters + + @Preconditions + None + + @Param + timer: timer to run the capture modules (IC_PARAMS_CAPTURE_TIMER) + intrpt: interrupt trigger event (IC_PARAMS_CAPTURE_INTERRUPT) + mode: capture event (IC_PARAMS_CAPTURE_MODE) + + @Returns + None. + */ + void IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(uint8_t pin, + IC_PARAMS_CAPTURE_TIMER timer, + IC_PARAMS_CAPTURE_INTERRUPT intrpt, + IC_PARAMS_CAPTURE_MODE mode); + + /** + @Summary + Combines IC3 and IC4 modules to enable concatenated operation + + @Description + This routine combines both IC3 and IC4 capture modules to act + them as 32-bit counters + + @Preconditions + None + + @Param + timer: timer to run the capture modules (IC_PARAMS_CAPTURE_TIMER) + intrpt: interrupt trigger event (IC_PARAMS_CAPTURE_INTERRUPT) + mode: capture event (IC_PARAMS_CAPTURE_MODE) + + @Returns + None. + */ + void IC_PARAMS_ConfigureIntervalCaptureWithIC3AndIC4(uint8_t pin, + IC_PARAMS_CAPTURE_TIMER timer, + IC_PARAMS_CAPTURE_INTERRUPT intrpt, + IC_PARAMS_CAPTURE_MODE mode); #ifdef __cplusplus } diff --git a/src/registers/timers/tmr2.h b/src/registers/timers/tmr2.h index 46b03a9..ec8eab9 100644 --- a/src/registers/timers/tmr2.h +++ b/src/registers/timers/tmr2.h @@ -1,129 +1,179 @@ -#ifndef _TMR2_H -#define _TMR2_H - -#include -#include -#include -#include "timer_params.h" - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - /** - @Summary - Initializes hardware and data for the given instance of the TMR module - - @Description - This routine initializes hardware for the instance of the TMR module, - using the hardware initialization given data. It also initializes all - necessary internal data. - - @Param - None. - - @Returns - None - */ - void TMR2_Initialize(void); - - /** - @Summary - Updates 16-bit timer value - - @Description - This routine updates 16-bit timer value - - @Param - None. - - @Returns - None - */ - void TMR2_Period16BitSet(uint16_t value); - - /** - @Summary - Provides the timer 16-bit period value - - @Description - This routine provides the timer 16-bit period value - - @Param - None. - - @Returns - Timer 16-bit period value - */ - uint16_t TMR2_Period16BitGet(void); - - /** - @Summary - Updates the timer's 16-bit value - - @Description - This routine updates the timer's 16-bit value - - @Param - None. - - @Returns - None - */ - void TMR2_Counter16BitSet(uint16_t value); - - /** - @Summary - Provides 16-bit current counter value - - @Description - This routine provides 16-bit current counter value - - @Param - None. - - @Returns - 16-bit current counter value - */ - uint16_t TMR2_Counter16BitGet(void); - - - /** - @Summary - Starts the TMR - - @Description - This routine starts the TMR - - @Param - None. - - @Returns - None - */ - void TMR2_Start(void); - - /** - @Summary - Stops the TMR - - @Description - This routine stops the TMR - - @Param - None. - - @Returns - None - */ - void TMR2_Stop(void); - - inline static void TMR2_PrescalerSet(TIMER_PARAMS_PRESCALER scale) { - T2CONbits.TCKPS = scale; - } - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_TMR2_H +#ifndef _TMR2_H +#define _TMR2_H + +#include +#include +#include +#include "timer_params.h" + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + /** + @Summary + Initializes hardware and data for the given instance of the TMR module + + @Description + This routine initializes hardware for the instance of the TMR module, + using the hardware initialization given data. It also initializes all + necessary internal data. + + @Param + None. + + @Returns + None + */ + void TMR2_Initialize(void); + + /** + @Summary + Updates 16-bit timer value + + @Description + This routine updates 16-bit timer value + + @Param + None. + + @Returns + None + */ + void TMR2_Period16BitSet(uint16_t value); + + /** + @Summary + Provides the timer 16-bit period value + + @Description + This routine provides the timer 16-bit period value + + @Param + None. + + @Returns + Timer 16-bit period value + */ + uint16_t TMR2_Period16BitGet(void); + + /** + @Summary + Updates the timer's 16-bit value + + @Description + This routine updates the timer's 16-bit value + + @Param + None. + + @Returns + None + */ + void TMR2_Counter16BitSet(uint16_t value); + + /** + @Summary + Provides 16-bit current counter value + + @Description + This routine provides 16-bit current counter value + + @Param + None. + + @Returns + 16-bit current counter value + */ + uint16_t TMR2_Counter16BitGet(void); + + + /** + @Summary + Starts the TMR + + @Description + This routine starts the TMR + + @Param + None. + + @Returns + None + */ + void TMR2_Start(void); + + /** + @Summary + Stops the TMR + + @Description + This routine stops the TMR + + @Param + None. + + @Returns + None + */ + void TMR2_Stop(void); + + /** + @Summary + Combines Timer 2 and Timer 3 modules + + @Description + This routine combines Timer 2 and Timer 3 modules to form + a 32-bit timer module + + @Param + None + + @Returns + None. + */ + inline static void TMR2_CombineWithTimer3(void) { + T2CONbits.T32 = 1; + } + + /** + @Summary + Enable an external pin as timer clock source + + @Description + This routine enables one of the available external pins + to become the clock source for the Timer 2 module + + @Param + None + + @Returns + None. + */ + inline static void TMR2_SetExternalClockAsSource(void) { + T2CONbits.TCS = 1; + } + + /** + @Summary + Sets pre-scaler for Timer 2 module + + @Description + This routine defines the down sample rate for the operating frequency + of Timer 2 module + + @Param + scale: pre-scaler ratio (TIMER_PARAMS_PRESCALER) + + @Returns + None. + */ + inline static void TMR2_SetPrescaler(TIMER_PARAMS_PRESCALER scale) { + T2CONbits.TCKPS = scale; + } + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_TMR2_H diff --git a/src/registers/timers/tmr3.c b/src/registers/timers/tmr3.c index 8869b12..2759fc1 100644 --- a/src/registers/timers/tmr3.c +++ b/src/registers/timers/tmr3.c @@ -1,47 +1,55 @@ -#include -#include "tmr3.h" - -void TMR3_Initialize(void) { - // Clear timer 4 register - TMR3 = 0x00; - //Period = 0 s; Frequency = 64000000 Hz; PR4 0; - PR3 = 0x00; - // Stops timer - T3CONbits.TON = 0; - // Continues module operation in Idle mode - T3CONbits.TSIDL = 0; - // Gated time accumulation is disabled - T3CONbits.TGATE = 0; - // Timer4 Input Clock Pre scale Select bits as 1:1 - T3CONbits.TCKPS = 0b00; - // Internal clock (FP) - T3CONbits.TCS = 0; -} - -void TMR3_Period16BitSet(uint16_t value) { - /* Update the counter values */ - PR3 = value; -} - -uint16_t TMR3_Period16BitGet(void) { - return (PR3); -} - -void TMR3_Counter16BitSet(uint16_t value) { - /* Update the counter values */ - TMR3 = value; -} - -uint16_t TMR3_Counter16BitGet(void) { - return (TMR3); -} - -void TMR3_Start(void) { - /* Start the Timer */ - T3CONbits.TON = 1; -} - -void TMR3_Stop(void) { - /* Stop the Timer */ - T3CONbits.TON = false; -} +#include +#include "tmr3.h" + +void TMR3_Initialize(void) { + // Clear timer 3 register + TMR3 = 0x00; + TMR3HLD = 0x00; + //Period = 0 s; Frequency = 64000000 Hz; PR4 0; + PR3 = 0x00; + // Stops timer + T3CONbits.TON = 0; + // Continues module operation in Idle mode + T3CONbits.TSIDL = 0; + // Gated time accumulation is disabled + T3CONbits.TGATE = 0; + // Timer4 Input Clock Pre scale Select bits as 1:1 + T3CONbits.TCKPS = 0b00; + // Internal clock (FP) + T3CONbits.TCS = 0; + // Disable interrupts + _T3IE = 0; + _T3IF = 0; +} + +void TMR3_Period16BitSet(uint16_t value) { + /* Update the counter values */ + PR3 = value; +} + +uint16_t TMR3_Period16BitGet(void) { + return (PR3); +} + +void TMR3_Counter16BitSet(uint16_t value) { + /* Update the counter values */ + TMR3 = value; +} + +uint16_t TMR3_Counter16BitGet(void) { + return (TMR3); +} + +uint16_t TMR3_Carry16BitGet(void) { + return TMR3HLD; +} + +void TMR3_Start(void) { + /* Start the Timer */ + T3CONbits.TON = 1; +} + +void TMR3_Stop(void) { + /* Stop the Timer */ + T3CONbits.TON = false; +} diff --git a/src/registers/timers/tmr3.h b/src/registers/timers/tmr3.h index 5e9286b..2280dc9 100644 --- a/src/registers/timers/tmr3.h +++ b/src/registers/timers/tmr3.h @@ -1,124 +1,144 @@ -#ifndef _TMR3_H -#define _TMR3_H - -#include -#include -#include - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - /** - @Summary - Initializes hardware and data for the given instance of the TMR module - - @Description - This routine initializes hardware for the instance of the TMR module, - using the hardware initialization given data. It also initializes all - necessary internal data. - - @Param - None. - - @Returns - None - */ - void TMR3_Initialize(void); - - /** - @Summary - Updates 16-bit timer value - - @Description - This routine updates 16-bit timer value - - @Param - None. - - @Returns - None - */ - void TMR3_Period16BitSet(uint16_t value); - - /** - - @Summary - Provides the timer 16-bit period value - - @Description - This routine provides the timer 16-bit period value - - @Param - None. - - @Returns - Timer 16-bit period value - */ - uint16_t TMR3_Period16BitGet(void); - - /** - @Summary - Updates the timer's 16-bit value - - @Description - This routine updates the timer's 16-bit value - - @Param - None. - - @Returns - None - */ - void TMR3_Counter16BitSet(uint16_t value); - - /** - @Summary - Provides 16-bit current counter value - - @Description - This routine provides 16-bit current counter value - - @Param - None. - - @Returns - 16-bit current counter value - */ - uint16_t TMR3_Counter16BitGet(void); - - /** - @Summary - Starts the TMR - - @Description - This routine starts the TMR - - @Param - None. - - @Returns - None - */ - void TMR3_Start(void); - - /** - @Summary - Stops the TMR - - @Description - This routine stops the TMR - - @Param - None. - - @Returns - None - */ - void TMR3_Stop(void); - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_TMR3_H +#ifndef _TMR3_H +#define _TMR3_H + +#include +#include +#include + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + /** + @Summary + Initializes hardware and data for the given instance of the TMR module + + @Description + This routine initializes hardware for the instance of the TMR module, + using the hardware initialization given data. It also initializes all + necessary internal data. + + @Param + None. + + @Returns + None + */ + void TMR3_Initialize(void); + + /** + @Summary + Updates 16-bit timer value + + @Description + This routine updates 16-bit timer value + + @Param + None. + + @Returns + None + */ + void TMR3_Period16BitSet(uint16_t value); + + /** + + @Summary + Provides the timer 16-bit period value + + @Description + This routine provides the timer 16-bit period value + + @Param + None. + + @Returns + Timer 16-bit period value + */ + uint16_t TMR3_Period16BitGet(void); + + /** + @Summary + Updates the timer's 16-bit value + + @Description + This routine updates the timer's 16-bit value + + @Param + None. + + @Returns + None + */ + void TMR3_Counter16BitSet(uint16_t value); + + /** + @Summary + Provides 16-bit current counter value + + @Description + This routine provides 16-bit current counter value + + @Param + None. + + @Returns + 16-bit current counter value + */ + uint16_t TMR3_Counter16BitGet(void); + + /** + @Summary + Provides 16-bit hold carry counter value + + @Description + When TMR2 and TMR3 are cascaded to form a single 32-bit timer, + TMR2 hold the Least Significant Word (LSW) and TMR3 holds the + Most Significant Word (MSW). When the LSW is read from TMR2, + the current value of TMR3 is moved to the TMR3HLD register. + The MSW can then be read from TMR3HLD without worrying about + the delay between reads. + + @Param + None. + + @Returns + 16-bit current hold carry value + */ + uint16_t TMR3_Carry16BitGet(void); + + /** + @Summary + Starts the TMR + + @Description + This routine starts the TMR + + @Param + None. + + @Returns + None + */ + void TMR3_Start(void); + + /** + @Summary + Stops the TMR + + @Description + This routine stops the TMR + + @Param + None. + + @Returns + None + */ + void TMR3_Stop(void); + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_TMR3_H diff --git a/src/registers/timers/tmr5.h b/src/registers/timers/tmr5.h index dcec9cd..a80cb12 100644 --- a/src/registers/timers/tmr5.h +++ b/src/registers/timers/tmr5.h @@ -1,201 +1,218 @@ -#ifndef _TMR5_H -#define _TMR5_H - -#include -#include -#include -#include "timer_params.h" - -#ifdef __cplusplus // Provide C++ Compatibility -extern "C" { -#endif - - /** - @Summary - Initializes hardware and data for the given instance of the TMR module - - @Description - This routine initializes hardware for the instance of the TMR module, - using the hardware initialization given data. It also initializes all - necessary internal data. - - @Param - None. - - @Returns - None - */ - void TMR5_Initialize(void); - - /** - @Summary - Updates 16-bit timer value - - @Description - This routine updates 16-bit timer value - - @Param - None. - - @Returns - None - */ - void TMR5_Period16BitSet(uint16_t value); - - /** - - @Summary - Provides the timer 16-bit period value - - @Description - This routine provides the timer 16-bit period value - - @Param - None. - - @Returns - Timer 16-bit period value - */ - - uint16_t TMR5_Period16BitGet(void); - - /** - @Summary - Updates the timer's 16-bit value - - @Description - This routine updates the timer's 16-bit value - - @Param - None. - - @Returns - None - */ - void TMR5_Counter16BitSet(uint16_t value); - - /** - @Summary - Provides 16-bit current counter value - - @Description - This routine provides 16-bit current counter value - - @Param - None. - - @Returns - 16-bit current counter value - */ - uint16_t TMR5_Counter16BitGet(void); - - - /** - @Summary - Starts the TMR - - @Description - This routine starts the TMR - - @Param - None. - - @Returns - None - */ - void TMR5_Start(void); - - /** - @Summary - Stops the TMR - - @Description - This routine stops the TMR - - @Param - None. - - @Returns - None - */ - void TMR5_Stop(void); - - /** - @Summary - Stops the TMR when MCU idles. - - @Description - This routine stops the TMR when the MCU is in idle mode. - - @Param - None. - - @Returns - None - */ - inline static void TMR5_StopWhenIdle(void) { - T5CONbits.TSIDL = 1; - } - - /** - @Summary - Slows down the TMR. - - @Description - This routine sets a prescaler which slows down the TMR by a factor. - - @Param - Pass the desired prescaler from the TIMER_PARAMS_PRESCALER list. - - @Returns - None - */ - inline static void TMR5_SetPrescaler(TIMER_PARAMS_PRESCALER prescaler) { - T5CONbits.TCKPS = prescaler; - } - - /** - @Summary - Disables the TMR interrupt. - - @Description - This routine disables the TMR interrupt. - - @Param - None. - - @Returns - None - */ - inline static void TMR5_InterruptDisable(void) { - IEC1bits.T5IE = 0; - } - - /** - @Summary - Clears the TMR interrupt flag. - - @Description - This routine clears the TMR interrupt flag. - - @Param - None. - - @Returns - None - */ - inline static void TMR5_InterruptFlagClear(void) { - IFS1bits.T5IF = 0; - } - - inline static void TMR5_PrescalerSet(TIMER_PARAMS_PRESCALER scale) { - T5CONbits.TCKPS = scale; - } - - void TMR5_WaitForInterruptEvent(void); - -#ifdef __cplusplus // Provide C++ Compatibility -} -#endif - -#endif //_TMR5_H +#ifndef _TMR5_H +#define _TMR5_H + +#include +#include +#include +#include "timer_params.h" + +#ifdef __cplusplus // Provide C++ Compatibility +extern "C" { +#endif + + /** + @Summary + Initializes hardware and data for the given instance of the TMR module + + @Description + This routine initializes hardware for the instance of the TMR module, + using the hardware initialization given data. It also initializes all + necessary internal data. + + @Param + None. + + @Returns + None + */ + void TMR5_Initialize(void); + + /** + @Summary + Updates 16-bit timer value + + @Description + This routine updates 16-bit timer value + + @Param + None. + + @Returns + None + */ + void TMR5_Period16BitSet(uint16_t value); + + /** + + @Summary + Provides the timer 16-bit period value + + @Description + This routine provides the timer 16-bit period value + + @Param + None. + + @Returns + Timer 16-bit period value + */ + + uint16_t TMR5_Period16BitGet(void); + + /** + @Summary + Updates the timer's 16-bit value + + @Description + This routine updates the timer's 16-bit value + + @Param + None. + + @Returns + None + */ + void TMR5_Counter16BitSet(uint16_t value); + + /** + @Summary + Provides 16-bit current counter value + + @Description + This routine provides 16-bit current counter value + + @Param + None. + + @Returns + 16-bit current counter value + */ + uint16_t TMR5_Counter16BitGet(void); + + + /** + @Summary + Starts the TMR + + @Description + This routine starts the TMR + + @Param + None. + + @Returns + None + */ + void TMR5_Start(void); + + /** + @Summary + Stops the TMR + + @Description + This routine stops the TMR + + @Param + None. + + @Returns + None + */ + void TMR5_Stop(void); + + /** + @Summary + Stops the TMR when MCU idles. + + @Description + This routine stops the TMR when the MCU is in idle mode. + + @Param + None. + + @Returns + None + */ + inline static void TMR5_StopWhenIdle(void) { + T5CONbits.TSIDL = 1; + } + + /** + @Summary + Slows down the TMR. + + @Description + This routine sets a prescaler which slows down the TMR by a factor. + + @Param + Pass the desired prescaler from the TIMER_PARAMS_PRESCALER list. + + @Returns + None + */ + inline static void TMR5_SetPrescaler(TIMER_PARAMS_PRESCALER prescaler) { + T5CONbits.TCKPS = prescaler; + } + + /** + @Summary + Disables the TMR interrupt. + + @Description + This routine disables the TMR interrupt. + + @Param + None. + + @Returns + None + */ + inline static void TMR5_InterruptDisable(void) { + IEC1bits.T5IE = 0; + } + + /** + @Summary + Enables the TMR interrupt. + + @Description + This routine enables the TMR interrupt. + + @Param + None. + + @Returns + None + */ + inline static void TMR5_InterruptEnable(void) { + IEC1bits.T5IE = 1; + } + + /** + @Summary + Clears the TMR interrupt flag. + + @Description + This routine clears the TMR interrupt flag. + + @Param + None. + + @Returns + None + */ + inline static void TMR5_InterruptFlagClear(void) { + IFS1bits.T5IF = 0; + } + + inline static void TMR5_PrescalerSet(TIMER_PARAMS_PRESCALER scale) { + T5CONbits.TCKPS = scale; + } + + void TMR5_WaitForInterruptEvent(void); + +#ifdef __cplusplus // Provide C++ Compatibility +} +#endif + +#endif //_TMR5_H