EE445M RTOS
Taken at the University of Texas Spring 2015
comp.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // comp.c - Driver for the analog comparator.
4 //
5 // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 //*****************************************************************************
41 //
44 //
45 //*****************************************************************************
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "inc/hw_comp.h"
50 #include "inc/hw_ints.h"
51 #include "inc/hw_memmap.h"
52 #include "inc/hw_types.h"
53 #include "driverlib/comp.h"
54 #include "driverlib/debug.h"
55 #include "driverlib/interrupt.h"
56 
57 //*****************************************************************************
58 //
110 //
111 //*****************************************************************************
112 void
113 ComparatorConfigure(uint32_t ui32Base, uint32_t ui32Comp, uint32_t ui32Config)
114 {
115  //
116  // Check the arguments.
117  //
118  ASSERT(ui32Base == COMP_BASE);
119  ASSERT(ui32Comp < 3);
120 
121  //
122  // Configure this comparator.
123  //
124  HWREG(ui32Base + (ui32Comp * 0x20) + COMP_O_ACCTL0) = ui32Config;
125 }
126 
127 //*****************************************************************************
128 //
168 //
169 //*****************************************************************************
170 void
171 ComparatorRefSet(uint32_t ui32Base, uint32_t ui32Ref)
172 {
173  //
174  // Check the arguments.
175  //
176  ASSERT(ui32Base == COMP_BASE);
177 
178  //
179  // Set the voltage reference voltage as requested.
180  //
181  HWREG(ui32Base + COMP_O_ACREFCTL) = ui32Ref;
182 }
183 
184 //*****************************************************************************
185 //
195 //
196 //*****************************************************************************
197 bool
198 ComparatorValueGet(uint32_t ui32Base, uint32_t ui32Comp)
199 {
200  //
201  // Check the arguments.
202  //
203  ASSERT(ui32Base == COMP_BASE);
204  ASSERT(ui32Comp < 3);
205 
206  //
207  // Return the appropriate value based on the comparator's present output
208  // value.
209  //
210  if(HWREG(ui32Base + (ui32Comp * 0x20) + COMP_O_ACSTAT0) &
212  {
213  return(true);
214  }
215  else
216  {
217  return(false);
218  }
219 }
220 
221 //*****************************************************************************
222 //
239 //
240 //*****************************************************************************
241 void
242 ComparatorIntRegister(uint32_t ui32Base, uint32_t ui32Comp,
243  void (*pfnHandler)(void))
244 {
245  //
246  // Check the arguments.
247  //
248  ASSERT(ui32Base == COMP_BASE);
249  ASSERT(ui32Comp < 3);
250 
251  //
252  // Register the interrupt handler, returning an error if an error occurs.
253  //
254  IntRegister(INT_COMP0_TM4C123 + ui32Comp, pfnHandler);
255 
256  //
257  // Enable the interrupt in the interrupt controller.
258  //
259  IntEnable(INT_COMP0_TM4C123 + ui32Comp);
260 
261  //
262  // Enable the comparator interrupt.
263  //
264  HWREG(ui32Base + COMP_O_ACINTEN) |= 1 << ui32Comp;
265 }
266 
267 //*****************************************************************************
268 //
282 //
283 //*****************************************************************************
284 void
285 ComparatorIntUnregister(uint32_t ui32Base, uint32_t ui32Comp)
286 {
287  //
288  // Check the arguments.
289  //
290  ASSERT(ui32Base == COMP_BASE);
291  ASSERT(ui32Comp < 3);
292 
293  //
294  // Disable the comparator interrupt.
295  //
296  HWREG(ui32Base + COMP_O_ACINTEN) &= ~(1 << ui32Comp);
297 
298  //
299  // Disable the interrupt in the interrupt controller.
300  //
301  IntDisable(INT_COMP0_TM4C123 + ui32Comp);
302 
303  //
304  // Unregister the interrupt handler.
305  //
306  IntUnregister(INT_COMP0_TM4C123 + ui32Comp);
307 }
308 
309 //*****************************************************************************
310 //
321 //
322 //*****************************************************************************
323 void
324 ComparatorIntEnable(uint32_t ui32Base, uint32_t ui32Comp)
325 {
326  //
327  // Check the arguments.
328  //
329  ASSERT(ui32Base == COMP_BASE);
330  ASSERT(ui32Comp < 3);
331 
332  //
333  // Enable the comparator interrupt.
334  //
335  HWREG(ui32Base + COMP_O_ACINTEN) |= 1 << ui32Comp;
336 }
337 
338 //*****************************************************************************
339 //
350 //
351 //*****************************************************************************
352 void
353 ComparatorIntDisable(uint32_t ui32Base, uint32_t ui32Comp)
354 {
355  //
356  // Check the arguments.
357  //
358  ASSERT(ui32Base == COMP_BASE);
359  ASSERT(ui32Comp < 3);
360 
361  //
362  // Disable the comparator interrupt.
363  //
364  HWREG(ui32Base + COMP_O_ACINTEN) &= ~(1 << ui32Comp);
365 }
366 
367 //*****************************************************************************
368 //
381 //
382 //*****************************************************************************
383 bool
384 ComparatorIntStatus(uint32_t ui32Base, uint32_t ui32Comp, bool bMasked)
385 {
386  //
387  // Check the arguments.
388  //
389  ASSERT(ui32Base == COMP_BASE);
390  ASSERT(ui32Comp < 3);
391 
392  //
393  // Return either the interrupt status or the raw interrupt status as
394  // requested.
395  //
396  if(bMasked)
397  {
398  return(((HWREG(ui32Base + COMP_O_ACMIS) >> ui32Comp) & 1) ? true :
399  false);
400  }
401  else
402  {
403  return(((HWREG(ui32Base + COMP_O_ACRIS) >> ui32Comp) & 1) ? true :
404  false);
405  }
406 }
407 
408 //*****************************************************************************
409 //
430 //
431 //*****************************************************************************
432 void
433 ComparatorIntClear(uint32_t ui32Base, uint32_t ui32Comp)
434 {
435  //
436  // Check the arguments.
437  //
438  ASSERT(ui32Base == COMP_BASE);
439  ASSERT(ui32Comp < 3);
440 
441  //
442  // Clear the interrupt.
443  //
444  HWREG(ui32Base + COMP_O_ACMIS) = 1 << ui32Comp;
445 }
446 
447 //*****************************************************************************
448 //
449 // Close the Doxygen group.
451 //
452 //*****************************************************************************
#define COMP_O_ACREFCTL
Definition: hw_comp.h:54
#define COMP_O_ACINTEN
Definition: hw_comp.h:52
#define HWREG(x)
Definition: hw_types.h:48
#define COMP_O_ACRIS
Definition: hw_comp.h:50
#define ASSERT(expr)
Definition: debug.h:67
void ComparatorIntEnable(uint32_t ui32Base, uint32_t ui32Comp)
Definition: comp.c:324
void ComparatorConfigure(uint32_t ui32Base, uint32_t ui32Comp, uint32_t ui32Config)
Definition: comp.c:113
void ComparatorIntUnregister(uint32_t ui32Base, uint32_t ui32Comp)
Definition: comp.c:285
#define COMP_BASE
Definition: hw_memmap.h:91
#define INT_COMP0_TM4C123
Definition: hw_ints.h:89
void ComparatorIntDisable(uint32_t ui32Base, uint32_t ui32Comp)
Definition: comp.c:353
void ComparatorIntClear(uint32_t ui32Base, uint32_t ui32Comp)
Definition: comp.c:433
bool ComparatorIntStatus(uint32_t ui32Base, uint32_t ui32Comp, bool bMasked)
Definition: comp.c:384
void IntUnregister(uint32_t ui32Interrupt)
Definition: interrupt.c:381
#define COMP_O_ACSTAT0
Definition: hw_comp.h:56
void ComparatorIntRegister(uint32_t ui32Base, uint32_t ui32Comp, void(*pfnHandler)(void))
Definition: comp.c:242
#define COMP_ACSTAT0_OVAL
Definition: hw_comp.h:111
bool ComparatorValueGet(uint32_t ui32Base, uint32_t ui32Comp)
Definition: comp.c:198
#define COMP_O_ACMIS
Definition: hw_comp.h:48
void ComparatorRefSet(uint32_t ui32Base, uint32_t ui32Ref)
Definition: comp.c:171
void IntDisable(uint32_t ui32Interrupt)
Definition: interrupt.c:684
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Definition: interrupt.c:309
void IntEnable(uint32_t ui32Interrupt)
Definition: interrupt.c:610
#define COMP_O_ACCTL0
Definition: hw_comp.h:57