RTEMS 6.1-rc2
Loading...
Searching...
No Matches
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
48extern "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
80typedef sint8 TaskId;
81typedef 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
116typedef enum {
120 SZ_UINT32 = 4
122
126typedef enum {
133 = -4,
136 TASK_ERR_BD_BUSY = -7,
141
147typedef 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
194typedef struct {
195 uint32 NumBD;
197 union {
198 uint32 MaxBuf;
199 uint32 NumBytes;
200 } Size;
205 sint16 IncrSrc;
208 sint16 IncrDst;
211
218typedef struct {
219 int dummy; /* Some compilers don't like empty struct typedefs */
221
228typedef struct {
229 uint32 Status;
230} TaskBD_t;
231
235typedef struct {
236 uint32 Status;
237 uint32 DataPtr[1];
238} TaskBD1_t;
239
243typedef 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
285const char *TaskVersion(void);
286
287int TasksInitAPI(uint8 *MBarRef);
288
289int TasksInitAPI_VM(uint8 *MBarRef, uint8 *MBarPhys);
290
291void TasksLoadImage(sdma_regs *sdma);
292int TasksAttachImage(sdma_regs *sdma);
293
294int TaskStart(TaskId taskId, uint32 autoStartEnable,
295 TaskId autoStartTask, uint32 intrEnable);
296int TaskStop(TaskId taskId);
297static int TaskStatus(TaskId taskId);
298BDIdx TaskBDAssign(TaskId taskId, void *buffer0, void *buffer1,
299 int size, uint32 bdFlags);
300BDIdx TaskBDRelease(TaskId taskId);
301BDIdx TaskBDReset(TaskId taskId);
302static TaskBD_t *TaskGetBD(TaskId taskId, BDIdx bd);
303static TaskBD_t *TaskGetBDRing(TaskId taskId);
304int TaskDebug(TaskId taskId, TaskDebugParamSet_t *paramSet);
305static int TaskIntClear(TaskId taskId);
306static TaskId TaskIntStatus(TaskId taskId);
307static int TaskIntPending(TaskId taskId);
308static TaskId TaskIntSource(void);
309static uint16 TaskBDInUse(TaskId taskId);
310
311
318static inline int TaskStatus(TaskId taskId)
319{
320 return SDMA_TASK_STATUS(SDMA_TCR, taskId) & 0x8000;
321}
322
333static 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
356static inline TaskBD_t *TaskGetBDRing(TaskId taskId)
357{
358 return (TaskBD_t *) TaskBDIdxTable[taskId].BDTablePtr;
359}
360
366static inline int TaskIntClear(TaskId taskId)
367{
368 SDMA_CLEAR_IEVENT(SDMA_INT_PEND, taskId);
369 return TASK_ERR_NO_ERR; /* success */
370}
371
381static 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
404static 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
425static 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
451static 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 */
int TasksInitAPI_VM(uint8 *MBarRef, uint8 *MBarPhys)
Initialize the API when virtual memory is used.
Definition: bestcomm_api.c:142
int TaskStart(TaskId taskId, uint32 autoStartEnable, TaskId autoStartTask, uint32 intrEnable)
Start an initialized task running.
Definition: bestcomm_api.c:187
BDIdx TaskBDReset(TaskId taskId)
Release all buffers.
Definition: bestcomm_api.c:404
BDIdx TaskBDAssign(TaskId taskId, void *buffer0, void *buffer1, int size, uint32 bdFlags)
Assign a buffer to a buffer descriptor.
Definition: bestcomm_api.c:247
int TaskDebug(TaskId taskId, TaskDebugParamSet_t *paramSet)
Return BestComm debug information.
Definition: bestcomm_api.c:442
const char * TaskVersion(void)
Get a string containing API version information.
Definition: bestcomm_api.c:81
int TaskStop(TaskId taskId)
Stop a running task.
Definition: bestcomm_api.c:217
void TasksLoadImage(sdma_regs *sdma)
Load BestComm tasks into SRAM.
Definition: load_task.c:68
MPC5200Initiator_t
BestComm initiators.
Definition: bestcomm_api.h:147
Sz_t
Data transfer size.
Definition: bestcomm_api.h:116
@ SZ_UINT16
Definition: bestcomm_api.h:119
@ SZ_UINT32
Definition: bestcomm_api.h:120
@ SZ_UINT8
Definition: bestcomm_api.h:118
@ SZ_FLEX
Definition: bestcomm_api.h:117
TaskErr_t
API error codes.
Definition: bestcomm_api.h:126
@ TASK_ERR_NO_ERR
Definition: bestcomm_api.h:127
@ TASK_ERR_BD_BUSY
Definition: bestcomm_api.h:136
@ TASK_ERR_API_ALREADY_INITIALIZED
Definition: bestcomm_api.h:132
@ TASK_ERR_BD_RING_FULL
Definition: bestcomm_api.h:131
@ TASK_ERR_INVALID_ARG
Definition: bestcomm_api.h:130
@ TASK_ERR_TASK_RUNNING
Definition: bestcomm_api.h:138
@ TASK_ERR_SIZE_TOO_LARGE
Definition: bestcomm_api.h:134
@ TASK_ERR_NO_INTR
Definition: bestcomm_api.h:128
@ TASK_ERR_BD_RING_EMPTY
Definition: bestcomm_api.h:135
#define MAX_TASKS
Maximum number of tasks in the system. This number is hardware-dependent and not user configuration.
Definition: bestcomm_api.h:71
#define DEBUG_INTR_ID
Debug interrupt "task ID".
Definition: bestcomm_api.h:87
BDIdx TaskBDRelease(TaskId taskId)
Release last buffer in the buffer descriptor ring.
Definition: bestcomm_api.c:346
#define TEA_INTR_ID
TEA interrupt "task ID".
Definition: bestcomm_api.h:90
int TasksInitAPI(uint8 *MBarRef)
Initialize the API.
Definition: bestcomm_api.c:100
int TasksAttachImage(sdma_regs *sdma)
Deprecated
Definition: bestcomm_api.c:170
This header file defines the RTEMS Classic API.
Single buffer descriptor.
Definition: bestcomm_api.h:235
uint32 Status
Definition: bestcomm_api.h:236
Dual buffer descriptor.
Definition: bestcomm_api.h:243
uint32 Status
Definition: bestcomm_api.h:244
Generic buffer descriptor.
Definition: bestcomm_api.h:228
uint32 Status
Definition: bestcomm_api.h:229
Parameters for TaskDebug()
Definition: bestcomm_api.h:218
Parameters for TaskSetup()
Definition: bestcomm_api.h:194
Sz_t SzDst
Definition: bestcomm_api.h:209
MPC5200Initiator_t Initiator
Definition: bestcomm_api.h:203
uint32 NumBytes
Definition: bestcomm_api.h:199
uint32 StartAddrSrc
Definition: bestcomm_api.h:204
Sz_t SzSrc
Definition: bestcomm_api.h:206
uint32 MaxBuf
Definition: bestcomm_api.h:198
uint32 StartAddrDst
Definition: bestcomm_api.h:207
sint16 IncrSrc
Definition: bestcomm_api.h:205
uint32 NumBD
Definition: bestcomm_api.h:195
sint16 IncrDst
Definition: bestcomm_api.h:208
Definition: sdma.h:28