discoverpixy
qqueue.h
1 //
2 // begin license header
3 //
4 // This file is part of Pixy CMUcam5 or "Pixy" for short
5 //
6 // All Pixy source code is provided under the terms of the
7 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
8 // Those wishing to use Pixy source code, software and/or
9 // technologies under different licensing terms should contact us at
10 // cmucam@cs.cmu.edu. Such licensing terms are available for
11 // all portions of the Pixy codebase presented here.
12 //
13 // end license header
14 //
15 #ifndef _QQUEUE_H
16 #define _QQUEUE_H
17 #include <inttypes.h>
18 
19 #define QQ_LOC SRAM4_LOC
20 #ifdef PIXY
21 #define QQ_SIZE 0x3c00
22 #else
23 #define QQ_SIZE 0x30000
24 #endif
25 #define QQ_MEM_SIZE ((QQ_SIZE-sizeof(struct QqueueFields)+sizeof(Qval))/sizeof(Qval))
26 
27 #ifdef __cplusplus
28 struct Qval
29 #else
30 typedef struct
31 #endif
32 {
33 #ifdef __cplusplus
34  Qval()
35  {
36  m_u = m_v = m_y = m_col = 0;
37  }
38 
39  Qval(int16_t u, int16_t v, uint16_t y, uint16_t col)
40  {
41  m_u = u;
42  m_v = v;
43  m_y = y;
44  m_col = col;
45  }
46 #endif
47 
48  uint16_t m_col;
49  int16_t m_v;
50  int16_t m_u;
51  uint16_t m_y;
52 
53 #ifdef __cplusplus
54 };
55 #else
56 } Qval;
57 #endif
58 
59 
60 struct QqueueFields
61 {
62  uint16_t readIndex;
63  uint16_t writeIndex;
64 
65  uint16_t produced;
66  uint16_t consumed;
67 
68  // (array size below doesn't matter-- we're just going to cast a pointer to this struct)
69  Qval data[1]; // data
70 };
71 
72 #ifdef __cplusplus // M4 is C++ and the "consumer" of data
73 
74 class Qqueue
75 {
76 public:
77  Qqueue();
78  ~Qqueue();
79 
80  uint32_t dequeue(Qval *val);
81  uint32_t queued()
82  {
83  return m_fields->produced - m_fields->consumed;
84  }
85 #ifndef PIXY
86  int enqueue(Qval *val);
87 #endif
88 
89  uint32_t readAll(Qval *mem, uint32_t size);
90  void flush();
91 
92 private:
93  QqueueFields *m_fields;
94 };
95 
96 #else // M0 is C and the "producer" of data (Qvals)
97 
98 uint32_t qq_enqueue(const Qval *val);
99 uint16_t qq_free(void);
100 
101 extern struct QqueueFields *g_qqueue;
102 
103 #endif
104 
105 #endif
Definition: qqueue.h:30
Definition: qqueue.h:60