EE445M RTOS
Taken at the University of Texas Spring 2015
timerpp.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset: 4; */
2 /* Created by Hershal Bhave and Eric Crosson on <2015-03-15 Sun> */
3 /* Revision History: Look in Git FGT */
4 #include "timerpp.hpp"
5 
6 #include "inc/hw_memmap.h"
7 #include "inc/hw_ints.h"
8 #include "driverlib/interrupt.h"
9 
11 
12 timer::timer(timer_t timer_id, subtimer_t timer_subtimer,
13  uint32_t timer_configuration, reload_t timer_load_val,
14  uint32_t timer_interrupt, bool timer_start) {
15 
16  id = timer_id;
17  base = TIMER0_BASE + 0x1000 * timer_id;
18  subtimer = timer_subtimer;
19  reload_value = timer_load_val;
20  configuration = timer_configuration;
21  interrupt = timer_interrupt;
22 
23  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0 + id);
24  TimerConfigure(base, configuration);
25 
26  switch(subtimer) {
27  case TIMER_A:
28  case TIMER_BOTH:
29  IntEnable(INT_TIMER0A + id*2);
30  break;
31  case TIMER_B:
32  IntEnable(INT_TIMER0A + id*2 + 1);
33  break;
34  default:
35  while (1) {}
36  }
37 
38  reload();
39  if (timer_start) { start(); }
40 }
41 
42 void timer::reload() {
43 
45 }
46 
47 void timer::load(uint32_t load_value) {
48 
49  switch(subtimer) {
50  case TIMER_A:
51  case TIMER_BOTH:
52  TimerLoadSet(base, TIMER_A, load_value);
53  break;
54  case TIMER_B:
55  TimerLoadSet(base, TIMER_B, load_value);
56  break;
57  default:
58  while (1) {}
59  }
60 }
61 
62 void timer::start() {
63 
64  TimerIntEnable(base, interrupt);
65  TimerEnable(base, subtimer);
66 }
67 
68 void timer::stop() {
69 
70  TimerIntDisable(base, interrupt);
71  TimerDisable(base, subtimer);
72 }
73 
74 uint32_t timer::ack() {
75 
76  switch(subtimer) {
77  case TIMER_A:
78  case TIMER_BOTH:
79  TimerIntClear(base, INT_TIMER0A + id*2);
80  break;
81  case TIMER_B:
82  TimerIntClear(base, INT_TIMER0A + id*2 + 1);
83  break;
84  default:
85  while (1) {}
86  }
87  return 0xDEADBEEF;
88 }
89 
90 uint32_t timer::get() {
91 
92  switch(subtimer) {
93  case TIMER_A:
94  case TIMER_BOTH:
95  TimerValueGet(base, TIMER_A);
96  break;
97  case TIMER_B:
98  TimerValueGet(base, TIMER_B);
99  break;
100  default:
101  while (1) {}
102  }
103 }
104 
106  return subtimer;
107 }
108 
109 const uint32_t timer::get_base() {
110  return base;
111 }
112 
113 
114 /* Local Variables: */
115 /* firestarter: (compile "make -k -j32 -C ~/workspace/ee445m-labs/build/") */
116 /* End: */
void load(uint32_t load_value)
Definition: timerpp.cpp:47
void reload(void)
Definition: timerpp.cpp:42
uint8_t timer_t
Definition: timerpp.hpp:20
timer()
Definition: timerpp.cpp:10
const uint32_t get_base()
Definition: timerpp.cpp:109
reload_t reload_value
Definition: timerpp.hpp:38
uint32_t configuration
Definition: timerpp.hpp:42
uint32_t interrupt
Definition: timerpp.hpp:46
virtual uint32_t ack()
Definition: timerpp.cpp:74
virtual void start()
Definition: timerpp.cpp:62
uint32_t subtimer_t
Definition: timerpp.hpp:21
uint32_t base
Definition: timerpp.hpp:32
subtimer_t subtimer
Definition: timerpp.hpp:35
virtual uint32_t get()
Definition: timerpp.cpp:90
const subtimer_t get_subtimer()
Definition: timerpp.cpp:105
uint32_t reload_t
Definition: timerpp.hpp:22
virtual void stop()
Definition: timerpp.cpp:68