EE445M RTOS
Taken at the University of Texas Spring 2015
switchpp.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 
5 #include "switchpp.hpp"
6 #include "ctlsysctl.hpp"
7 
8 #include "driverlib/interrupt.h"
9 
10 #include "inc/hw_types.h"
11 #include "inc/hw_gpio.h"
12 
13 #define NULL 0x00
14 
16 
17  this->sem = NULL;
18 }
19 
21  semaphore *sem, timer_t timer_id, subtimer_t timer_subtimer,
22  uint32_t switch_interrupt, uint32_t interrupt_mask, bool start) {
23 
24  base = lswitch_base;
25  pin = lswitch_pin;
26 
28  GPIOPinTypeGPIOInput(base, pin);
29  GPIODirModeSet(base, pin, GPIO_DIR_MODE_IN);
30 
31  if ((base == GPIO_PORTF_BASE) && (pin & GPIO_PIN_0)) {
32  HWREG(base + GPIO_O_LOCK) = GPIO_LOCK_KEY;
33  HWREG(base + GPIO_O_CR) = 0x01;
34  HWREG(base + GPIO_O_LOCK) = 0;
35 
36  GPIOPadConfigSet(base, pin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
37  }
38 
39  /* other solution: timer scoreboard */
40  this->tim = timer(timer_id, timer_subtimer, TIMER_CFG_ONE_SHOT, SysCtlClockGet() / 50,
41  ctlsys::timer_timeout_from_subtimer(timer_subtimer));
42 
43  GPIOIntTypeSet(base, pin, switch_interrupt);
44  IntEnable(interrupt_mask);
45 
46  this->sem = sem;
47  *(this->sem) = semaphore();
48 
49  if (start) {
50  this->start();
51  }
52 }
53 
55 
56  GPIOIntEnable(base, pin);
57 }
58 
59 void lswitch::stop() {
60 
61  GPIOIntDisable(base, pin);
62 }
63 
66 
67  tim.start();
68 }
69 
70 /* todo: remove need for external (client) isr's by changing the isr
71  * at runtime in tis lib */
72 
75 
76  tim.ack();
77  if(NULL != sem) {
78  sem->post();
79  }
80  return sample();
81 }
82 
83 uint32_t lswitch::ack() {
84 
85  GPIOIntClear(base, pin);
86 }
87 
88 uint32_t lswitch::sample() {
89 
90  return debounced_data = GPIOPinRead(base, pin);
91 }
92 
93 /* Local Variables: */
94 /* firestarter: (compile "make -k -j32 -C ~/workspace/ee445m-labs/build/") */
95 /* End: */
uint32_t memory_address_t
Definition: adcpp.hpp:16
memory_address_t pin
Definition: switchpp.hpp:19
uint8_t timer_t
Definition: timerpp.hpp:20
void post(void)
Definition: semaphorepp.cpp:45
#define NULL
Definition: switchpp.cpp:13
uint32_t end_debounce(void)
Definition: switchpp.cpp:74
uint32_t debounced_data
Definition: switchpp.hpp:40
virtual uint32_t ack(void)
Definition: switchpp.cpp:83
semaphore * sem
Definition: switchpp.hpp:20
virtual uint32_t ack()
Definition: timerpp.cpp:74
virtual void start()
Definition: timerpp.cpp:62
uint32_t sample(void)
Definition: switchpp.cpp:88
static uint32_t timer_timeout_from_subtimer(uint32_t subtimer)
Definition: ctlsysctl.hpp:47
virtual void stop(void)
Definition: switchpp.cpp:59
lswitch()
Definition: switchpp.cpp:15
virtual void start(void)
Definition: switchpp.cpp:54
uint32_t subtimer_t
Definition: timerpp.hpp:21
timer tim
Definition: switchpp.hpp:21
void debounce(void)
Definition: switchpp.cpp:65
static void enable_periph(uint32_t sys_periph)
Definition: ctlsysctl.hpp:24
memory_address_t base
Definition: switchpp.hpp:18