EE445M RTOS
Taken at the University of Texas Spring 2015
ping Class Reference

#include <pingpp.hpp>

Inheritance diagram for ping:
Inheritance graph
Collaboration diagram for ping:
Collaboration graph

Public Member Functions

 ping ()
 
 ping (memory_address_t port_base, memory_address_t port_pin, timer_t timer_id, subtimer_t timer_subtimer)
 
void sample (void)
 
virtual void start (void)
 
virtual void stop (void)
 
uint32_t handle_gpio (void)
 
uint32_t handle_timer (void)
 
semaphoreget_sem (void)
 
uint32_t notify (void)
 
int32_t average (void)
 
int32_t distance (void)
 
- Public Member Functions inherited from critical
uint32_t StartCritical (void)
 
void EndCritical (uint32_t primask)
 

Public Attributes

circularbuffer< int32_t, 5 > buf
 

Private Attributes

semaphore sem
 
blinker sig
 
ping_status_t status
 
timer tim
 
uint32_t timer_interrupt
 
memory_address_t base
 
memory_address_t pin
 
uint32_t timer_signal_value
 
uint32_t timer_response_value
 

Additional Inherited Members

- Static Public Member Functions inherited from critical
static uint32_t static_StartCritical (void)
 
static void static_EndCritical (uint32_t primask)
 

Detailed Description

Definition at line 28 of file pingpp.hpp.

Constructor & Destructor Documentation

ping::ping ( )

Definition at line 11 of file pingpp.cpp.

11 {}
ping::ping ( memory_address_t  port_base,
memory_address_t  port_pin,
timer_t  timer_id,
subtimer_t  timer_subtimer 
)

Definition at line 13 of file pingpp.cpp.

References base, buf, ctlsys::enable_periph(), pin, ping_not_active, sem, sig, status, tim, and timer_interrupt.

14  {
15 
17 
18  base = ping_base;
19  pin = ping_pin;
20  sig = blinker(base);
21 
22  sem = semaphore();
24 
25  switch(ping_timer_subtimer) {
26  case TIMER_A:
27  case TIMER_BOTH:
28  timer_interrupt = TIMER_TIMA_TIMEOUT;
29  break;
30  case TIMER_B:
31  timer_interrupt = TIMER_TIMB_TIMEOUT;
32  break;
33  default:
34  while (1) {}
35  }
36 
37  tim = timer(ping_timer_id, ping_timer_subtimer, TIMER_CFG_ONE_SHOT_UP, 0x0fffffe,
39 
41 }
circularbuffer< int32_t, 5 > buf
Definition: pingpp.hpp:66
uint32_t timer_interrupt
Definition: pingpp.hpp:34
memory_address_t pin
Definition: pingpp.hpp:36
semaphore sem
Definition: pingpp.hpp:30
timer tim
Definition: pingpp.hpp:33
memory_address_t base
Definition: pingpp.hpp:35
static void enable_periph(uint32_t sys_periph)
Definition: ctlsysctl.hpp:24
ping_status_t status
Definition: pingpp.hpp:32
blinker sig
Definition: pingpp.hpp:31

Here is the call graph for this function:

Member Function Documentation

int32_t ping::average ( void  )

Definition at line 135 of file pingpp.cpp.

References buf, buffer< T, N >::buf, and buffer< T, N >::len.

Referenced by distance(), and ping_handler().

135  {
136 
137  int32_t i, value;
138  value = 0;
139  for (i=0; i<buf.len; ++i) {
140  value += buf.buf[i];
141  }
142  value /= buf.len;
143  return value;
144 }
circularbuffer< int32_t, 5 > buf
Definition: pingpp.hpp:66
T buf[N]
Definition: bufferpp.hpp:115
uint32_t len
Definition: bufferpp.hpp:113

Here is the caller graph for this function:

int32_t ping::distance ( void  )

Definition at line 146 of file pingpp.cpp.

References average().

Referenced by can_transmitter().

146  {
147 
148  /* The speed of sound is 340 m/s or 29 microseconds per centimeter. */
149  /* The ping travels out and back, so to find the distance of the */
150  /* object we take half of the distance travelled. */
151 
152  /* bus clock is 25/2 ns */
153  /* num bus clocks is in average() */
154  /* time taken for round trip is average()*25/2 in ns */
155 
156  return (average() * 25) / (2492);
157 }
int32_t average(void)
Definition: pingpp.cpp:135

Here is the call graph for this function:

Here is the caller graph for this function:

semaphore * ping::get_sem ( void  )

The ping sensor's semaphore

Definition at line 130 of file pingpp.cpp.

References sem.

Referenced by main().

130  {
131 
132  return &sem;
133 }
semaphore sem
Definition: pingpp.hpp:30

Here is the caller graph for this function:

uint32_t ping::handle_gpio ( void  )

Acknowledge isr for sig.

Definition at line 107 of file pingpp.cpp.

References circularbuffer< T, N >::add(), base, buf, timer::get(), timer::load(), pin, ping_response, ping_sample_delay, ping_signal, timer::reload(), timer::start(), status, tim, timer_response_value, and timer_signal_value.

Referenced by GPIOPortD_Handler().

107  {
108 
109  GPIOIntClear(base, pin);
110 
111  status = ping_status_t(int(status) + 1);
112 
113  if (status == ping_signal) {
114  tim.reload();
116  tim.start();
117  } else if (status == ping_response) {
121  tim.load(SysCtlClockGet()/25);
122  tim.start();
123  } else {
124  /* TODO: do something here? */
125  }
126 
127  return 0xDEADBEEF;
128 }
void load(uint32_t load_value)
Definition: timerpp.cpp:47
circularbuffer< int32_t, 5 > buf
Definition: pingpp.hpp:66
void reload(void)
Definition: timerpp.cpp:42
memory_address_t pin
Definition: pingpp.hpp:36
enum ping_status ping_status_t
uint32_t timer_signal_value
Definition: pingpp.hpp:38
void add(const T ch)
timer tim
Definition: pingpp.hpp:33
uint32_t timer_response_value
Definition: pingpp.hpp:39
virtual void start()
Definition: timerpp.cpp:62
memory_address_t base
Definition: pingpp.hpp:35
virtual uint32_t get()
Definition: timerpp.cpp:90
ping_status_t status
Definition: pingpp.hpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t ping::handle_timer ( void  )

Definition at line 85 of file pingpp.cpp.

References timer::ack(), ping_not_active, ping_response, ping_sample_delay, ping_signal, semaphore::post(), sem, status, and tim.

Referenced by Timer1A_Handler().

85  {
86 
87  tim.ack();
88 
89  if (status == ping_not_active) {
90  /* TODO: remove when done debugging */
91  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
92  } else if (status == ping_signal) {
93  /* TODO: remove when done debugging */
94  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
95  } else if (status == ping_response) {
96  /* TODO: remove when done debugging */
97  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
98  } else if (status == ping_sample_delay) {
100  }
101 
102  /* either a timeout happened or the sensor delay period has been
103  achieved */
104  sem.post();
105 }
void post(void)
Definition: semaphorepp.cpp:45
semaphore sem
Definition: pingpp.hpp:30
timer tim
Definition: pingpp.hpp:33
virtual uint32_t ack()
Definition: timerpp.cpp:74
ping_status_t status
Definition: pingpp.hpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t ping::notify ( void  )

Alert object that the isr watching both edges of sig has been triggered.

void ping::sample ( void  )
Warning
this device should not be sampled more than once every 200 micro-seconds

Definition at line 45 of file pingpp.cpp.

References base, delay::count(), critical::EndCritical(), ctlsys::gpio_int_disable(), ctlsys::gpio_int_enable(), ctlsys::periph_to_int(), pin, ping_not_active, sig, critical::StartCritical(), status, blinker::turn_off(), and blinker::turn_on().

Referenced by ping_handler().

45  {
46 
47  if (status == ping_not_active) {
48  uint32_t intstatus = StartCritical();
49 
50  /* Disable interrupts in SIG */
52  IntDisable(ctlsys::periph_to_int(base));
53 
54  /* Set Ping))) SIG to output */
55  GPIOPinTypeGPIOOutput(base, pin);
56  sig.turn_on(pin);
57  /* Set SIG high for 5usec */
58  delay::count(1);
59  sig.turn_off(pin);
60 
61  /* Set Ping))) SIG to input */
62  GPIOPinTypeGPIOInput(base, pin);
63  GPIOIntTypeSet(base, pin, GPIO_BOTH_EDGES);
64  delay::count(200);
65 
66  /* Enable interupts on SIG */
68  IntEnable(ctlsys::periph_to_int(base));
69 
70  EndCritical(intstatus);
71  }
72 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
memory_address_t pin
Definition: pingpp.hpp:36
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
static void gpio_int_enable(uint32_t base, uint32_t pin, bool clear_int=false)
Definition: ctlsysctl.hpp:99
static void count(uint32_t cycles)
Definition: delay.hpp:15
static void gpio_int_disable(uint32_t base, uint32_t pin)
Definition: ctlsysctl.hpp:93
virtual void turn_off(pin_t pin)
Definition: blinker.cpp:30
virtual void turn_on(pin_t pin)
Definition: blinker.cpp:26
memory_address_t base
Definition: pingpp.hpp:35
static uint32_t periph_to_int(uint32_t periph)
Definition: ctlsysctl.hpp:73
ping_status_t status
Definition: pingpp.hpp:32
blinker sig
Definition: pingpp.hpp:31

Here is the call graph for this function:

Here is the caller graph for this function:

void ping::start ( void  )
virtual

Start the timer monitoring sig.

Definition at line 74 of file pingpp.cpp.

References semaphore::post(), and sem.

Referenced by ping_handler().

74  {
75 
76  /* start the chain */
77  sem.post();
78 }
void post(void)
Definition: semaphorepp.cpp:45
semaphore sem
Definition: pingpp.hpp:30

Here is the call graph for this function:

Here is the caller graph for this function:

void ping::stop ( void  )
virtual

Stop the timer monitoring sig.

Definition at line 80 of file pingpp.cpp.

References semaphore::reset(), and sem.

80  {
81 
82  sem.reset();
83 }
semaphore sem
Definition: pingpp.hpp:30
void reset(void)
Definition: semaphorepp.cpp:28

Here is the call graph for this function:

Member Data Documentation

memory_address_t ping::base
private

Definition at line 35 of file pingpp.hpp.

Referenced by handle_gpio(), ping(), and sample().

circularbuffer< int32_t , 5 > ping::buf

Definition at line 66 of file pingpp.hpp.

Referenced by average(), handle_gpio(), and ping().

memory_address_t ping::pin
private

Definition at line 36 of file pingpp.hpp.

Referenced by handle_gpio(), ping(), and sample().

semaphore ping::sem
private

Definition at line 30 of file pingpp.hpp.

Referenced by get_sem(), handle_timer(), ping(), start(), and stop().

blinker ping::sig
private

Definition at line 31 of file pingpp.hpp.

Referenced by ping(), and sample().

ping_status_t ping::status
private

Definition at line 32 of file pingpp.hpp.

Referenced by handle_gpio(), handle_timer(), ping(), and sample().

timer ping::tim
private

Definition at line 33 of file pingpp.hpp.

Referenced by handle_gpio(), handle_timer(), and ping().

uint32_t ping::timer_interrupt
private

Definition at line 34 of file pingpp.hpp.

Referenced by ping().

uint32_t ping::timer_response_value
private

Definition at line 39 of file pingpp.hpp.

Referenced by handle_gpio().

uint32_t ping::timer_signal_value
private

Definition at line 38 of file pingpp.hpp.

Referenced by handle_gpio().


The documentation for this class was generated from the following files: