1 /*****************************************************************************
\r
2 * © 2015 Microchip Technology Inc. and its subsidiaries.
\r
3 * You may use this software and any derivatives exclusively with
\r
4 * Microchip products.
\r
5 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".
\r
6 * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
\r
7 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
\r
8 * AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP
\r
9 * PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
\r
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
\r
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
\r
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
\r
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.
\r
14 * TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
\r
15 * CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF
\r
16 * FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
\r
17 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
\r
19 ******************************************************************************
\r
21 Version Control Information (Perforce)
\r
22 ******************************************************************************
\r
24 $DateTime: 2016/09/22 08:03:49 $
\r
26 Last Change: Updated for tabs
\r
27 ******************************************************************************/
\r
28 /** @file btimer_perphl.c
\r
29 * \brief Basic Timer Peripheral Source file
\r
32 * This file implements the Basic Timer Peripheral functions
\r
33 ******************************************************************************/
\r
35 /** @defgroup Basic_Timer
\r
39 #include "common_lib.h"
\r
42 /** Basic Timer Instance base addresses */
\r
43 static TIMER0_Type * const btmr_inst[BTIMER_MAX_INSTANCE] = {
\r
52 /* ---------------------------------------------------------------------- */
\r
53 /* Functions to set and read Timer Counter Register */
\r
54 /* ---------------------------------------------------------------------- */
\r
56 /** Sets timer counter
\r
57 * @param btimer_id Basic Timer ID
\r
58 * @param count - 32-bit counter
\r
60 void p_btimer_count_set(uint8_t btimer_id, uint32_t count)
\r
62 btmr_inst[btimer_id]->COUNT = count;
\r
65 /** Read the timer counter
\r
66 * @param btimer_id Basic Timer ID
\r
67 * @return count - 32-bit counter
\r
69 uint32_t p_btimer_count_get(uint8_t btimer_id)
\r
71 return btmr_inst[btimer_id]->COUNT;
\r
74 /* ---------------------------------------------------------------------- */
\r
75 /* Function to program the Preload */
\r
76 /* ---------------------------------------------------------------------- */
\r
78 /** Sets preload for the counter
\r
79 * @param btimer_id Basic Timer ID
\r
80 * @param preload_count - 32-bit pre-load value
\r
82 void p_btimer_preload_set(uint8_t btimer_id, uint32_t preload_count)
\r
84 btmr_inst[btimer_id]->PRE_LOAD = preload_count;
\r
87 /* ---------------------------------------------------------------------- */
\r
88 /* Functions for basic timer interrupts */
\r
89 /* ---------------------------------------------------------------------- */
\r
91 /** Reads the interrupt status bit in the timer block
\r
92 * @param btimer_id Basic Timer ID
\r
93 * @return status - 1 if interrupt status set, else 0
\r
95 uint8_t p_btimer_int_status_get(uint8_t btimer_id)
\r
97 return (uint8_t)(btmr_inst[btimer_id]->STATUS);
\r
100 /** Clears interrupt status bit in the timer block
\r
101 * @param btimer_id Basic Timer ID
\r
103 void p_btimer_int_status_clr(uint8_t btimer_id)
\r
105 // Write 1 to clear
\r
106 btmr_inst[btimer_id]->STATUS = 1;
\r
109 /** Sets interrupt enable bit in the timer block
\r
110 * @param btimer_id Basic Timer ID
\r
112 void p_btimer_int_enable_set(uint8_t btimer_id)
\r
114 btmr_inst[btimer_id]->INT_EN = 1;
\r
117 /** Clears interrupt enable bit for the timer block
\r
118 * @param btimer_id Basic Timer ID
\r
120 void p_btimer_int_enable_clr(uint8_t btimer_id)
\r
122 btmr_inst[btimer_id]->INT_EN = 0;
\r
125 /* ---------------------------------------------------------------------- */
\r
126 /* Functions for Control Register */
\r
127 /* ---------------------------------------------------------------------- */
\r
129 /** Writes the control register 32-bits
\r
130 * @param btimer_id Basic Timer ID
\r
131 * @param value - 32-bit value to program
\r
133 void p_btimer_ctrl_write(uint8_t btimer_id, uint32_t value)
\r
135 btmr_inst[btimer_id]->CONTROL.w = value;
\r
138 /** Reads the control register
\r
139 * @param btimer_id Basic Timer ID
\r
140 * @return uint32_t - 32-bit value
\r
142 uint32_t p_btimer_ctrl_read(uint8_t btimer_id)
\r
146 retVal = btmr_inst[btimer_id]->CONTROL.w;
\r
151 /** Sets enable bit in the control register
\r
152 * @param btimer_id Basic Timer ID
\r
154 void p_btimer_ctrl_enable_set(uint8_t btimer_id)
\r
156 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_ENABLE;
\r
159 /** Clears enable bit in the control register
\r
160 * @param btimer_id Basic Timer ID
\r
162 void p_btimer_ctrl_enable_clr(uint8_t btimer_id)
\r
164 btmr_inst[btimer_id]->CONTROL.b[0] &= ~BTIMER_CNTL_ENABLE;
\r
167 /** Sets counter direction bit in the control register
\r
168 * @param btimer_id Basic Timer ID
\r
170 void p_btimer_ctrl_counter_dir_set(uint8_t btimer_id)
\r
172 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_COUNT_UP;
\r
175 /** Clears counter direction bit in the control register
\r
176 * @param btimer_id Basic Timer ID
\r
178 void p_btimer_ctrl_counter_dir_clr(uint8_t btimer_id)
\r
180 btmr_inst[btimer_id]->CONTROL.b[0] &= ~BTIMER_CNTL_COUNT_UP;
\r
183 /** Sets auto restart bit in the control register
\r
184 * @param btimer_id Basic Timer ID
\r
186 void p_btimer_ctrl_auto_restart_set(uint8_t btimer_id)
\r
188 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_AUTO_RESTART;
\r
191 /** Clears auto resetart bit in the control register
\r
192 * @param btimer_id Basic Timer ID
\r
194 void p_btimer_ctrl_auto_restart_clr(uint8_t btimer_id)
\r
196 btmr_inst[btimer_id]->CONTROL.b[0] &= ~BTIMER_CNTL_AUTO_RESTART;
\r
199 /** Sets soft reset bit in the control register
\r
200 * @param btimer_id Basic Timer ID
\r
202 void p_btimer_ctrl_soft_reset_set(uint8_t btimer_id)
\r
204 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_SOFT_RESET;
\r
207 /** Read Soft Reset bit
\r
208 * @param btimer_id Basic Timer ID
\r
209 * @return 0 if soft reset status bit cleared; else non-zero value
\r
211 uint8_t p_btimer_ctrl_soft_reset_sts_get(uint8_t btimer_id)
\r
213 return (btmr_inst[btimer_id]->CONTROL.b[0] & BTIMER_CNTL_SOFT_RESET);
\r
216 /** Sets start bit in the control register
\r
217 * @param btimer_id Basic Timer ID
\r
219 void p_btimer_ctrl_start_set(uint8_t btimer_id)
\r
221 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_START;
\r
224 /** Read start bit in the control register
\r
225 * @param btimer_id Basic Timer ID
\r
226 * @return 0 if start bit not set; else non-zero value
\r
228 uint8_t p_btimer_ctrl_start_get(uint8_t btimer_id)
\r
230 return (btmr_inst[btimer_id]->CONTROL.b[0] & BTIMER_CNTL_START);
\r
233 /** Clears start bit in the control register
\r
234 * @param btimer_id Basic Timer ID
\r
236 void p_btimer_ctrl_start_clr(uint8_t btimer_id)
\r
238 btmr_inst[btimer_id]->CONTROL.b[0] &= ~BTIMER_CNTL_START;
\r
241 /** Sets reload bit in the control register
\r
242 * @param btimer_id Basic Timer ID
\r
244 void p_btimer_ctrl_reload_set(uint8_t btimer_id)
\r
246 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_RELOAD;
\r
249 /** Clears reload bit in the control register
\r
250 * @param btimer_id Basic Timer ID
\r
252 void p_btimer_ctrl_reload_clr(uint8_t btimer_id)
\r
254 btmr_inst[btimer_id]->CONTROL.b[0] &= ~BTIMER_CNTL_RELOAD;
\r
257 /** Sets halt bit in the control register
\r
258 * @param btimer_id Basic Timer ID
\r
260 void p_btimer_ctrl_halt_set(uint8_t btimer_id)
\r
262 btmr_inst[btimer_id]->CONTROL.b[0] |= BTIMER_CNTL_HALT;
\r
265 /** Clears halt bit in the control register
\r
266 * @param btimer_id Basic Timer ID
\r
268 void p_btimer_ctrl_halt_clr(uint8_t btimer_id)
\r
270 btmr_inst[btimer_id]->CONTROL.b[0] &= ~BTIMER_CNTL_HALT;
\r
273 /** Sets prescale value
\r
274 * @param btimer_id Basic Timer ID
\r
275 * @param prescaler - 16-bit pre-scale value
\r
277 void p_btimer_ctrl_prescale_set(uint8_t btimer_id, uint16_t prescaler)
\r
279 btmr_inst[btimer_id]->CONTROL.h[1] = prescaler;
\r
283 /* end btimer_perphl.c */
\r
285 /** @} //Peripheral Basic_Timer
\r