1
|
/**
|
2
|
* \file tcDspUpp.h
|
3
|
*
|
4
|
* \brief DSP uPP driver header file
|
5
|
*
|
6
|
* o 0
|
7
|
* | / Copyright (c) 2005-2011
|
8
|
* (CL)---o Critical Link, LLC
|
9
|
* \
|
10
|
* O
|
11
|
*/
|
12
|
|
13
|
//TODO:
|
14
|
// -Think about interleave mode...
|
15
|
|
16
|
#ifndef _DSPUPP_H_
|
17
|
#define _DSPUPP_H_
|
18
|
|
19
|
#include <stdint.h>
|
20
|
#include <std.h>
|
21
|
#include <mbx.h>
|
22
|
#include <sem.h>
|
23
|
#include <tsk.h>
|
24
|
|
25
|
#include "regs_upp.h"
|
26
|
|
27
|
namespace MityDSP
|
28
|
{
|
29
|
|
30
|
class tcDspUpp
|
31
|
{
|
32
|
public:
|
33
|
|
34
|
// Enumerations for uPP channels.
|
35
|
enum teUppChan
|
36
|
{
|
37
|
eeChanA,
|
38
|
eeChanB
|
39
|
};
|
40
|
|
41
|
// Channel data transfer directionality.
|
42
|
enum teChanDir
|
43
|
{
|
44
|
eeTransmit,
|
45
|
eeReceive,
|
46
|
eeDisabled
|
47
|
};
|
48
|
|
49
|
// Channel data bit width.
|
50
|
enum teChanBitWidth
|
51
|
{
|
52
|
ee8Bit = 0,
|
53
|
ee9Bit = 1,
|
54
|
ee10Bit = 2,
|
55
|
ee11Bit = 3,
|
56
|
ee12Bit = 4,
|
57
|
ee13Bit = 5,
|
58
|
ee14Bit = 6,
|
59
|
ee15Bit = 7,
|
60
|
ee16Bit = 8
|
61
|
};
|
62
|
|
63
|
// Read/Transmit threshold for UPTCR register bits
|
64
|
enum teThreshold
|
65
|
{
|
66
|
ee64Bytes = 0,
|
67
|
ee128Bytes = 1,
|
68
|
ee256Bytes = 3
|
69
|
};
|
70
|
|
71
|
// uPP Transmit clock selection options
|
72
|
enum teTxClockSel
|
73
|
{
|
74
|
eeUPP_2xTXCLK = 0, //!< External Tx clock source
|
75
|
eePLL0_SYSCLK2 = 1, //!< Same as uPP Module clock. Runs at
|
76
|
//!< 1/2 CPU speed
|
77
|
eePLL1_SYSCLK2 = 2 //!< PLL1_SYSCLK2
|
78
|
};
|
79
|
|
80
|
// Structure for configuring the uPP device.
|
81
|
struct tsDspUppConfig
|
82
|
{
|
83
|
uint32_t nHWInterruptLevel; //!< Interrupt level. Must be
|
84
|
//!< between 4 and 15.
|
85
|
uint32_t nTskPriorityChanA; //!< Priority for thread handling
|
86
|
//!< DMA programming for Channel A.
|
87
|
uint32_t nTskPriorityChanB; //!< Priority for thread handling
|
88
|
//!< DMA programming for Channel B.
|
89
|
teChanDir eChanADir; //!< Directionality of Channel A.
|
90
|
teChanDir eChanBDir; //!< Directionality of Channel B.
|
91
|
teChanBitWidth eChanBitWidthA; //!< Chan A data bit width.
|
92
|
teChanBitWidth eChanBitWidthB; //!< Chan B data bit width.
|
93
|
bool bChanAUseXData; //!< Use XData[7:0] for ChanA[15:8]
|
94
|
//!< even if ChanB is disabled. See Table 3 in uPP
|
95
|
//!< User's Guide for details.
|
96
|
uint32_t nMbxLenA; //!< Size of MBX for Channel A.
|
97
|
uint32_t nMbxLenB; //!< Size of MBX for Channel B.
|
98
|
uint8_t nChanAClkDiv; //!< Clock divider for Channel A
|
99
|
//!< (only in transmit mode). See Section 2.1.1 in uPP
|
100
|
//!< User's Guide for details. Value must be between 0
|
101
|
//!< and 15.
|
102
|
uint8_t nChanBClkDiv; //!< Clock divider for Channel B
|
103
|
//!< (only in transmit mode). See Section 2.1.1 in uPP
|
104
|
//!< User's Guide for details. Value must be between 0
|
105
|
//!< and 15.
|
106
|
teThreshold eThresholdTxA; //!< Chan A Transmit Thresh.
|
107
|
teThreshold eThresholdRxA; //!< Chan A Receive Thresh.
|
108
|
teThreshold eThresholdTxB; //!< Chan B Transmit Thresh.
|
109
|
teThreshold eThresholdRxB; //!< Chan B Receive Thresh.
|
110
|
bool bChanAUseStart; //!< Use start signal for Chan A.
|
111
|
bool bChanBUseStart; //!< Use start signal for Chan B.
|
112
|
teTxClockSel eTxClockSel; //!< Select transmit clock source.
|
113
|
//!< Only used if Chan A or Chan B is set to transmit.
|
114
|
uint8_t nDmaMasterPriority; //!< Set the DMA master priority
|
115
|
//!< for uPP. Valid number, range 0-7. 0 is highest
|
116
|
//!< priority.
|
117
|
// Chan A single/double data rate?
|
118
|
// Chan B single/double data rate?
|
119
|
// Multiplexing/interleaving mode options?
|
120
|
// Chan A data packing format?
|
121
|
// Chan B data packing format?
|
122
|
};
|
123
|
|
124
|
// MBX message structure.
|
125
|
struct tsMbxMsg
|
126
|
{
|
127
|
uint8_t* pBufPtr; //!< Pointer to filled/emptied buffer.
|
128
|
uint16_t nByteCnt; //!< # bytes per line DMAed to/from buf.
|
129
|
uint16_t nLineCnt; //!< DMA line count.
|
130
|
uint16_t nLineOffset; //!< DMA offset between lines.
|
131
|
void* pOptArg; //!< Pointer to optional additional arguments.
|
132
|
};
|
133
|
|
134
|
// Typdef for error callback function
|
135
|
typedef int (*tfErrorCallback)(uint32_t anErrNum);
|
136
|
|
137
|
/**
|
138
|
* Get instance of tcDspUpp.
|
139
|
*
|
140
|
* \return Poiner to the tcDspUpp object or NULL on failure.
|
141
|
*/
|
142
|
static tcDspUpp* getInstance();
|
143
|
|
144
|
/**
|
145
|
* Perform software reset of the uPP.
|
146
|
*
|
147
|
* @return None.
|
148
|
*/
|
149
|
void reset();
|
150
|
|
151
|
/**
|
152
|
* Intiailize the uPP device.
|
153
|
*
|
154
|
* \param apDspUppConfig Specifies configuration options.
|
155
|
*
|
156
|
* \return 0 on success, negative on failure.
|
157
|
*/
|
158
|
int initialize(tsDspUppConfig const* apDspUppConfig);
|
159
|
|
160
|
/**
|
161
|
* Get handle to mailbox for associated channel where info on
|
162
|
* processed buffers are stored.
|
163
|
*
|
164
|
* \param aeChan The uPP channel.
|
165
|
*
|
166
|
* \return Handle to the channel's mailbox or NULL on failure.
|
167
|
*/
|
168
|
MBX_Handle getMBX(teUppChan aeChan);
|
169
|
|
170
|
/**
|
171
|
* Queue transmit of given data buffer. Use getMBX() to get
|
172
|
* corresponding mailbox where pointer info will be posted once data
|
173
|
* has been tramsmitted.
|
174
|
*
|
175
|
* \param aeChan The uPP channel to transmit on. Note: If the given
|
176
|
* channel is not configured for transmit, function call
|
177
|
* will fail.
|
178
|
* \param apXmitData Pointer to transmit data. (note: Address must be
|
179
|
* be 64-bit aligned).
|
180
|
* \param anByteCnte Number of bytes in a line to DMA. (must be even).
|
181
|
* \param anLineCnt (Optional) Set the number of lines in the DMA
|
182
|
* channel window. If set > 1 and anLineOffset = 0,
|
183
|
* apXmitData will tranmist anLineCnt times.
|
184
|
* \param anLineOffset (Optional) Set the offset address between lines
|
185
|
* within DMA channel. (must be 64-bit aligned).
|
186
|
*
|
187
|
* \return 0 on succes, negative on failure.
|
188
|
*/
|
189
|
int transmit(teUppChan aeChan, const uint8_t* apXmitData,
|
190
|
uint16_t anByteCnt, uint16_t anLineCnt = 1,
|
191
|
uint16_t anLineOffset = 0);
|
192
|
|
193
|
/**
|
194
|
* Add buffer to receive queue. Use getMBX() to get corresponding
|
195
|
* mailbox where pointer info will be posted once data has been
|
196
|
* received.
|
197
|
*
|
198
|
* \param aeChan The uPP channel to receive on. Note: If the given
|
199
|
* channel is not configured for receive, function call
|
200
|
* will fail.
|
201
|
* \param apRcvData Pointer to location where to store receive data.
|
202
|
* (note: Address must be 64-bit aligned).
|
203
|
* \param anByteCnte Number of bytes in a line to DMA. (must be even).
|
204
|
* \param anLineCnt (Optional) Set the number of lines in the DMA
|
205
|
* channel window.
|
206
|
* \param anLineOffset (Optional) Set the offset address between lines
|
207
|
* within DMA channel. (must be 64-bit aligned).
|
208
|
*
|
209
|
* \return 0 on succes, negative on failure.
|
210
|
*/
|
211
|
int receive(teUppChan aeChan, uint8_t* apRcvData, uint16_t anByteCnt,
|
212
|
uint16_t anLineCnt = 1, uint16_t anLineOffset = 0);
|
213
|
|
214
|
/**
|
215
|
* Register an error callback function.
|
216
|
*
|
217
|
* \param afErrorCallback The error callback function.
|
218
|
*
|
219
|
* return None.
|
220
|
*/
|
221
|
void registerErrorCallback(tfErrorCallback afErrorCallback);
|
222
|
|
223
|
private:
|
224
|
|
225
|
/**
|
226
|
* Thread for programming the DMA for the specified channel.
|
227
|
*
|
228
|
* \param apDspUpp Pointer to singleton.
|
229
|
* \param aeChan The specified channel.
|
230
|
*
|
231
|
* \return None.
|
232
|
*/
|
233
|
static void programDMA(tcDspUpp* apDspUpp, teUppChan aeChan);
|
234
|
|
235
|
/**
|
236
|
* Handle any uPP related interrupts that might occur.
|
237
|
*
|
238
|
* \param apDspUpp Pointer to singleton.
|
239
|
*
|
240
|
* \return 0 on success, negative on failure.
|
241
|
*/
|
242
|
static int isr(tcDspUpp* acDspUpp);
|
243
|
|
244
|
/**
|
245
|
* Private constructor.
|
246
|
*/
|
247
|
tcDspUpp();
|
248
|
|
249
|
/**
|
250
|
* Private destructor.
|
251
|
*/
|
252
|
~tcDspUpp();
|
253
|
|
254
|
/**
|
255
|
* Private Copy Constructor to enforce use of getInstance().
|
256
|
*/
|
257
|
tcDspUpp(tcDspUpp const&); // Note implemented.
|
258
|
/**
|
259
|
* Private assignment operator to enforce use of getInstance().
|
260
|
*/
|
261
|
tcDspUpp& operator=(tcDspUpp const&); // Not implemented
|
262
|
|
263
|
|
264
|
tfErrorCallback mpErrorCallback; //!< Callback function for errors.
|
265
|
|
266
|
volatile tsUppRegs* const mpUppRegs; //!< Constant pointer to uPP Control Regs.
|
267
|
|
268
|
static tcDspUpp* mpDspUpp; //!< Singleton object.
|
269
|
|
270
|
static SEM_Handle mhGetInstSem; //!< Static semaphore to be used in
|
271
|
//!< getInstance method so that we do not accidentally
|
272
|
//!< instantiate too many objects.
|
273
|
|
274
|
bool mbFirstInit; //!< True if we have not been initialized before.
|
275
|
|
276
|
teChanDir meChanADir; //!< Directionality of Channel A.
|
277
|
teChanDir meChanBDir; //!< Directionality of Channel B.
|
278
|
|
279
|
TSK_Handle mhDmaTskA; //!< Task for programming Channel A DMA.
|
280
|
TSK_Handle mhDmaTskB; //!< Task for programming Channel B DMA.
|
281
|
|
282
|
MBX_Handle mhMbxDoneA; //!< MBX for eeChanA or eeInterleave to store
|
283
|
//!< pointers than have been filled or transmitted.
|
284
|
MBX_Handle mhMbxDoneB; //!< MBX for eeChanB to store pointers that
|
285
|
//!< have been filled or transmitted.
|
286
|
|
287
|
MBX_Handle mhMbxIntA; //!< Intermdiate MBX holding info on pointers
|
288
|
//!< that have been sent for DMAing on Chan A.
|
289
|
MBX_Handle mhMbxIntB; //!< Intermdiate MBX holding info on pointers
|
290
|
//!< that have been sent for DMAing on Chan B.
|
291
|
|
292
|
MBX_Handle mhMbxQueueA; //!< Queue of pointers to be transmitted or
|
293
|
//!< filled by eeChanA or eeInterleave.
|
294
|
MBX_Handle mhMbxQueueB; //!< Queue of pointers to be transmitted or
|
295
|
//!< filled by eeChanB.
|
296
|
};
|
297
|
|
298
|
}
|
299
|
|
300
|
#endif
|
301
|
|