RTEMS  5.1
bestcomm_api.h
Go to the documentation of this file.
1 #ifndef __BESTCOMM_API_H
2 #define __BESTCOMM_API_H 1
3 
4 /******************************************************************************
5 *
6 * Copyright (c) 2004 Freescale Semiconductor, Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 ******************************************************************************/
27 
39 #include <rtems.h>
40 
41 #include "include/ppctypes.h"
42 #include "include/mgt5200/sdma.h"
43 #include "task_api/tasksetup_bdtable.h"
44 #include "task_api/bestcomm_cntrl.h"
45 #include "task_api/bestcomm_api_mem.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif /* __cplusplus */
50 
65 #define DEBUG_BESTCOMM_API 0
66 
71 #define MAX_TASKS 16
72 
73 /*
74  * This may need to be removed in certain implementations.
75  */
76 #ifndef NULL
77 # define NULL ((void *)0)
78 #endif /* NULL */
79 
80 typedef sint8 TaskId;
81 typedef sint32 BDIdx;
82 
83 /*
84  * Special "task IDs" for interrupt handling API functions
85  */
87 #define DEBUG_INTR_ID SDMA_INT_BIT_DBG
88 
90 #define TEA_INTR_ID SDMA_INT_BIT_TEA
91 
93 #define TASK_AUTOSTART_ENABLE 1
94 
96 #define TASK_AUTOSTART_DISABLE 0
97 
99 #define TASK_INTERRUPT_ENABLE 1
100 
102 #define TASK_INTERRUPT_DISABLE 0
103 
104 /*
105  * Buffer descriptor flags to pass to TaskBDAssign().
106  */
108 #define TASK_BD_TFD (1 << SDMA_DRD_BIT_TFD)
109 
111 #define TASK_BD_INT (1 << SDMA_DRD_BIT_INT)
112 
116 typedef enum {
117  SZ_FLEX = 3,
118  SZ_UINT8 = 1,
119  SZ_UINT16 = 2,
121 } Sz_t;
122 
126 typedef enum {
133  = -4,
140 } TaskErr_t;
141 
147 typedef enum {
148 
149  INITIATOR_ALWAYS = 0,
150  INITIATOR_SCTMR_0 = 1,
151  INITIATOR_SCTMR_1 = 2,
152  INITIATOR_FEC_RX = 3,
153  INITIATOR_FEC_TX = 4,
154  INITIATOR_ATA_RX = 5,
155  INITIATOR_ATA_TX = 6,
156  INITIATOR_SCPCI_RX = 7,
157  INITIATOR_SCPCI_TX = 8,
158  INITIATOR_PSC3_RX = 9,
159  INITIATOR_PSC3_TX = 10,
160  INITIATOR_PSC2_RX = 11,
161  INITIATOR_PSC2_TX = 12,
162  INITIATOR_PSC1_RX = 13,
163  INITIATOR_PSC1_TX = 14,
164  INITIATOR_SCTMR_2 = 15,
165 
166  INITIATOR_SCLPC = 16,
167  INITIATOR_PSC5_RX = 17,
168  INITIATOR_PSC5_TX = 18,
169  INITIATOR_PSC4_RX = 19,
170  INITIATOR_PSC4_TX = 20,
171  INITIATOR_I2C2_RX = 21,
172  INITIATOR_I2C2_TX = 22,
173  INITIATOR_I2C1_RX = 23,
174  INITIATOR_I2C1_TX = 24,
175  INITIATOR_PSC6_RX = 25,
176  INITIATOR_PSC6_TX = 26,
177  INITIATOR_IRDA_RX = 25,
178  INITIATOR_IRDA_TX = 26,
179  INITIATOR_SCTMR_3 = 27,
180  INITIATOR_SCTMR_4 = 28,
181  INITIATOR_SCTMR_5 = 29,
182  INITIATOR_SCTMR_6 = 30,
183  INITIATOR_SCTMR_7 = 31
184 
186 
194 typedef struct {
195  uint32 NumBD;
197  union {
198  uint32 MaxBuf;
199  uint32 NumBytes;
200  } Size;
204  uint32 StartAddrSrc;
205  sint16 IncrSrc;
207  uint32 StartAddrDst;
208  sint16 IncrDst;
211 
218 typedef struct {
219  int dummy; /* Some compilers don't like empty struct typedefs */
221 
228 typedef struct {
229  uint32 Status;
230 } TaskBD_t;
231 
235 typedef struct {
236  uint32 Status;
237  uint32 DataPtr[1];
238 } TaskBD1_t;
239 
243 typedef struct {
244  uint32 Status;
245  uint32 DataPtr[2];
246 } TaskBD2_t;
247 
248 
249 
250 /***************************
251  * Start of API Prototypes
252  ***************************/
253 
254 #include "bestcomm_priv.h"
255 #include "dma_image.capi.h"
256 
280 #define TaskSetupHelper(TaskName, TaskSetupParams) \
281  TaskSetup_ ## TaskName (TaskName ## _api, TaskSetupParams)
282 #define TaskSetup(TaskName, TaskSetupParams) \
283  TaskSetupHelper(TaskName, TaskSetupParams)
284 
285 const char *TaskVersion(void);
286 
287 int TasksInitAPI(uint8 *MBarRef);
288 
289 int TasksInitAPI_VM(uint8 *MBarRef, uint8 *MBarPhys);
290 
291 void TasksLoadImage(sdma_regs *sdma);
292 int TasksAttachImage(sdma_regs *sdma);
293 
294 int TaskStart(TaskId taskId, uint32 autoStartEnable,
295  TaskId autoStartTask, uint32 intrEnable);
296 int TaskStop(TaskId taskId);
297 static int TaskStatus(TaskId taskId);
298 BDIdx TaskBDAssign(TaskId taskId, void *buffer0, void *buffer1,
299  int size, uint32 bdFlags);
300 BDIdx TaskBDRelease(TaskId taskId);
301 BDIdx TaskBDReset(TaskId taskId);
302 static TaskBD_t *TaskGetBD(TaskId taskId, BDIdx bd);
303 static TaskBD_t *TaskGetBDRing(TaskId taskId);
304 int TaskDebug(TaskId taskId, TaskDebugParamSet_t *paramSet);
305 static int TaskIntClear(TaskId taskId);
306 static TaskId TaskIntStatus(TaskId taskId);
307 static int TaskIntPending(TaskId taskId);
308 static TaskId TaskIntSource(void);
309 static uint16 TaskBDInUse(TaskId taskId);
310 
311 
318 static inline int TaskStatus(TaskId taskId)
319 {
320  return SDMA_TASK_STATUS(SDMA_TCR, taskId) & 0x8000;
321 }
322 
333 static inline TaskBD_t *TaskGetBD(TaskId taskId, BDIdx bd)
334 {
335  void *bdTab;
336 
337  bdTab = TaskBDIdxTable[taskId].BDTablePtr;
338  if (TaskBDIdxTable[taskId].numPtr == 1) {
339  return (TaskBD_t *)&(((TaskBD1_t *)bdTab)[bd]);
340  } else {
341  return (TaskBD_t *)&(((TaskBD2_t *)bdTab)[bd]);
342  }
343 }
344 
356 static inline TaskBD_t *TaskGetBDRing(TaskId taskId)
357 {
358  return (TaskBD_t *) TaskBDIdxTable[taskId].BDTablePtr;
359 }
360 
366 static inline int TaskIntClear(TaskId taskId)
367 {
368  SDMA_CLEAR_IEVENT(SDMA_INT_PEND, taskId);
369  return TASK_ERR_NO_ERR; /* success */
370 }
371 
381 static inline TaskId TaskIntStatus(TaskId taskId)
382 {
383  uint32 pending;
384 
385  pending = SDMA_INT_PENDING(SDMA_INT_PEND, SDMA_INT_MASK);
386 
387  if (SDMA_INT_TEST(pending, taskId)) {
388  return taskId;
389  } else if (SDMA_INT_TEST(pending, DEBUG_INTR_ID)) {
390  return DEBUG_INTR_ID;
391  } else if (SDMA_INT_TEST(pending, TEA_INTR_ID)) {
392  return TEA_INTR_ID;
393  }
394 
395  return TASK_ERR_NO_INTR;
396 }
397 
404 static inline int TaskIntPending(TaskId taskId)
405 {
406  uint32 pending;
407 
408  pending = SDMA_INT_PENDING(SDMA_INT_PEND, SDMA_INT_MASK);
409  if (SDMA_INT_TEST(pending, taskId)) {
410  return 1;
411  } else {
412  return 0;
413  }
414 }
415 
425 static inline TaskId TaskIntSource(void)
426 {
427  uint32 pending;
428  uint32 mask = 1 << (MAX_TASKS - 1);
429  TaskId i;
430 
431  pending = SDMA_INT_PENDING(SDMA_INT_PEND, SDMA_INT_MASK);
432 
433  if (SDMA_INT_TEST(pending, SDMA_INT_BIT_TEA)) {
434  return (TaskId)SDMA_TEA_SOURCE(SDMA_INT_PEND);
435  }
436 
437  for (i = (MAX_TASKS - 1); i >= 0; --i, mask >>= 1) {
438  if (pending & mask) {
439  return i;
440  }
441  }
442 
443  return TASK_ERR_NO_INTR;
444 }
445 
451 static inline uint16 TaskBDInUse(TaskId taskId)
452 {
453  return TaskBDIdxTable[taskId].currBDInUse;
454 }
455 
456 #ifdef __cplusplus
457 }
458 #endif /* __cplusplus */
459 
460 #endif /* __BESTCOMM_API_H */
#define TEA_INTR_ID
TEA interrupt "task ID".
Definition: bestcomm_api.h:90
uint32 StartAddrSrc
Definition: bestcomm_api.h:204
Definition: bestcomm_api.h:117
Single buffer descriptor.
Definition: bestcomm_api.h:235
#define MAX_TASKS
Maximum number of tasks in the system. This number is hardware-dependent and not user configuration.
Definition: bestcomm_api.h:71
sint16 IncrDst
Definition: bestcomm_api.h:208
MPC5200Initiator_t Initiator
Definition: bestcomm_api.h:203
const char * TaskVersion(void)
Get a string containing API version information.
Definition: bestcomm_api.c:81
Sz_t SzDst
Definition: bestcomm_api.h:209
uint32 StartAddrDst
Definition: bestcomm_api.h:207
uint32 NumBytes
Definition: bestcomm_api.h:199
Definition: bestcomm_api.h:118
uint32 Status
Definition: bestcomm_api.h:236
Definition: bestcomm_api.h:136
int TaskStart(TaskId taskId, uint32 autoStartEnable, TaskId autoStartTask, uint32 intrEnable)
Start an initialized task running.
Definition: bestcomm_api.c:187
Definition: bestcomm_api.h:127
Definition: bestcomm_api.h:130
int TasksInitAPI_VM(uint8 *MBarRef, uint8 *MBarPhys)
Initialize the API when virtual memory is used.
Definition: bestcomm_api.c:142
Definition: bestcomm_api.h:120
uint32 NumBD
Definition: bestcomm_api.h:195
Parameters for TaskSetup()
Definition: bestcomm_api.h:194
BDIdx TaskBDRelease(TaskId taskId)
Release last buffer in the buffer descriptor ring.
Definition: bestcomm_api.c:346
int TaskDebug(TaskId taskId, TaskDebugParamSet_t *paramSet)
Return BestComm debug information.
Definition: bestcomm_api.c:442
Definition: bestcomm_api.h:135
int TaskStop(TaskId taskId)
Stop a running task.
Definition: bestcomm_api.c:217
Definition: bestcomm_api.h:138
Generic buffer descriptor.
Definition: bestcomm_api.h:228
#define DEBUG_INTR_ID
Debug interrupt "task ID".
Definition: bestcomm_api.h:87
TaskErr_t
API error codes.
Definition: bestcomm_api.h:126
BDIdx TaskBDReset(TaskId taskId)
Release all buffers.
Definition: bestcomm_api.c:404
uint32 Status
Definition: bestcomm_api.h:244
Definition: bestcomm_api.h:132
sint16 IncrSrc
Definition: bestcomm_api.h:205
Parameters for TaskDebug()
Definition: bestcomm_api.h:218
Definition: sdma.h:28
int TasksAttachImage(sdma_regs *sdma)
Deprecated
Definition: bestcomm_api.c:170
Sz_t SzSrc
Definition: bestcomm_api.h:206
Dual buffer descriptor.
Definition: bestcomm_api.h:243
int TasksInitAPI(uint8 *MBarRef)
Initialize the API.
Definition: bestcomm_api.c:100
Sz_t
Data transfer size.
Definition: bestcomm_api.h:116
Definition: bestcomm_api.h:134
uint32 MaxBuf
Definition: bestcomm_api.h:198
MPC5200Initiator_t
BestComm initiators.
Definition: bestcomm_api.h:147
Definition: bestcomm_api.h:131
Definition: bestcomm_api.h:128
unsigned size
Definition: tte.h:74
uint32 Status
Definition: bestcomm_api.h:229
BDIdx TaskBDAssign(TaskId taskId, void *buffer0, void *buffer1, int size, uint32 bdFlags)
Assign a buffer to a buffer descriptor.
Definition: bestcomm_api.c:247
void TasksLoadImage(sdma_regs *sdma)
Load BestComm tasks into SRAM.
Definition: load_task.c:68
Definition: bestcomm_api.h:119