EE445M RTOS
Taken at the University of Texas Spring 2015
buffer< T, N > Class Template Reference

#include <bufferpp.hpp>

Inheritance diagram for buffer< T, N >:
Inheritance graph
Collaboration diagram for buffer< T, N >:
Collaboration graph

Public Member Functions

 buffer ()
 
 buffer (semaphore *sem)
 
void clear ()
 
void init ()
 
void notify (const T data)
 
bool add (const T data)
 
peek ()
 
get (bool &ok)
 
bool full ()
 
bool empty ()
 
uint32_t length ()
 

Public Attributes

uint32_t pos
 
uint32_t len
 
semaphoresem
 
buf [N]
 
uint32_t error_overflow
 
uint32_t error_underflow
 

Detailed Description

template<typename T, uint32_t N>
class buffer< T, N >

Definition at line 16 of file bufferpp.hpp.

Constructor & Destructor Documentation

template<typename T, uint32_t N>
buffer< T, N >::buffer ( )
inline

Definition at line 20 of file bufferpp.hpp.

20  {
21 
22  init();
23  }
void init()
Definition: bufferpp.hpp:40
template<typename T, uint32_t N>
buffer< T, N >::buffer ( semaphore sem)
inline

Sem is only incremented on successful add

Definition at line 26 of file bufferpp.hpp.

26  {
27 
28  this->sem = sem;
29  *(this->sem) = semaphore();
30  init();
31  }
void init()
Definition: bufferpp.hpp:40
semaphore * sem
Definition: bufferpp.hpp:114

Member Function Documentation

template<typename T, uint32_t N>
bool buffer< T, N >::add ( const T  data)
inline

warning: drops Ts if buffer is full

Definition at line 56 of file bufferpp.hpp.

Referenced by buffer< int32_t, N >::notify(), and shell::type().

56  {
57 
58  if (full()) {
60  return false;
61  }
62  buf[pos++] = (T) data;
63  return true;
64  }
T buf[N]
Definition: bufferpp.hpp:115
bool full()
Definition: bufferpp.hpp:96
uint32_t error_overflow
Definition: bufferpp.hpp:117
uint32_t pos
Definition: bufferpp.hpp:112

Here is the caller graph for this function:

template<typename T, uint32_t N>
void buffer< T, N >::clear ( )
inline

Definition at line 33 of file bufferpp.hpp.

Referenced by shell::clear_buffer(), buffer< int32_t, N >::init(), and shell::print_ps1().

33  {
34 
35  while(pos>0) {
36  buf[--pos] = 0;
37  }
38  }
T buf[N]
Definition: bufferpp.hpp:115
uint32_t pos
Definition: bufferpp.hpp:112

Here is the caller graph for this function:

template<typename T, uint32_t N>
bool buffer< T, N >::empty ( )
inline

Definition at line 101 of file bufferpp.hpp.

101  {
102 
103  return pos == 0;
104  }
uint32_t pos
Definition: bufferpp.hpp:112
template<typename T, uint32_t N>
bool buffer< T, N >::full ( )
inline

Definition at line 96 of file bufferpp.hpp.

Referenced by buffer< int32_t, N >::add(), and shell::type().

96  {
97 
98  return pos == len;
99  }
uint32_t len
Definition: bufferpp.hpp:113
uint32_t pos
Definition: bufferpp.hpp:112

Here is the caller graph for this function:

template<typename T, uint32_t N>
T buffer< T, N >::get ( bool &  ok)
inline

warning: returns 0 if no more Ts in buffer

Definition at line 76 of file bufferpp.hpp.

Referenced by shell::backspace(), and shell_handler().

76  {
77 
78  /* base case */
79  if (pos <= 0) {
81  ok = false;
82  return 0;
83  }
84 
85  /* normal operation */
86  ok = true;
87 
88  T ret = buf[--pos];
89 
90  /*buf is always null-terminated*/
91  buf[pos] = 0;
92 
93  return ret;
94  }
uint32_t error_underflow
Definition: bufferpp.hpp:118
T buf[N]
Definition: bufferpp.hpp:115
uint32_t pos
Definition: bufferpp.hpp:112

Here is the caller graph for this function:

template<typename T, uint32_t N>
void buffer< T, N >::init ( )
inline

Definition at line 40 of file bufferpp.hpp.

Referenced by buffer< int32_t, N >::buffer().

40  {
41  error_overflow = 0;
42  error_underflow = 0;
43  pos = 0;
44  len = N;
45  clear();
46  }
void clear()
Definition: bufferpp.hpp:33
uint32_t error_underflow
Definition: bufferpp.hpp:118
uint32_t len
Definition: bufferpp.hpp:113
uint32_t error_overflow
Definition: bufferpp.hpp:117
uint32_t pos
Definition: bufferpp.hpp:112

Here is the caller graph for this function:

template<typename T, uint32_t N>
uint32_t buffer< T, N >::length ( )
inline

Definition at line 106 of file bufferpp.hpp.

Referenced by shell::execute_command().

106  {
107 
108  return pos;
109  }
uint32_t pos
Definition: bufferpp.hpp:112

Here is the caller graph for this function:

template<typename T, uint32_t N>
void buffer< T, N >::notify ( const T  data)
inline

Definition at line 48 of file bufferpp.hpp.

Referenced by UART0_Handler().

48  {
49 
50  if (add(data)) {
51  sem->post();
52  }
53  }
void post(void)
Definition: semaphorepp.cpp:45
bool add(const T data)
Definition: bufferpp.hpp:56
semaphore * sem
Definition: bufferpp.hpp:114

Here is the caller graph for this function:

template<typename T, uint32_t N>
T buffer< T, N >::peek ( )
inline

Definition at line 66 of file bufferpp.hpp.

66  {
67 
68  if (pos == 0) {
69  return buf[len-1];
70  } else {
71  return buf[pos-1];
72  }
73  }
T buf[N]
Definition: bufferpp.hpp:115
uint32_t len
Definition: bufferpp.hpp:113
uint32_t pos
Definition: bufferpp.hpp:112

Member Data Documentation

template<typename T, uint32_t N>
uint32_t buffer< T, N >::error_overflow

Definition at line 117 of file bufferpp.hpp.

Referenced by buffer< int32_t, N >::add(), and buffer< int32_t, N >::init().

template<typename T, uint32_t N>
uint32_t buffer< T, N >::error_underflow

Definition at line 118 of file bufferpp.hpp.

Referenced by buffer< int32_t, N >::get(), and buffer< int32_t, N >::init().

template<typename T, uint32_t N>
semaphore* buffer< T, N >::sem

Definition at line 114 of file bufferpp.hpp.

Referenced by buffer< int32_t, N >::buffer(), and buffer< int32_t, N >::notify().


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