source: rtems/c/src/lib/libbsp/powerpc/gen5200/bestcomm/bestcomm_api.h @ ddd5640

4.115
Last change on this file since ddd5640 was ddd5640, checked in by Sebastian Huber <sebastian.huber@…>, on 11/15/10 at 10:55:02

2010-11-12 Sebastian Huber <sebastian.huber@…>

  • make/custom/dp2.cfg, startup/linkcmds.dp2: New files.
  • Makefile.am, preinstall.am: Reflect change above. Install <bsp/utility.h>. Install BestComm? header files.
  • configure.ac: Changed BSP options.
  • include/mpc5200.h: Added module structures and register defines.
  • bestcomm/bestcomm_api.c, bestcomm/bestcomm_api.h, bestcomm/bestcomm_glue.c, bestcomm/bestcomm_glue.h, bestcomm/bestcomm_priv.h, bestcomm/load_task.c, bestcomm/tasksetup_bdtable.c, bestcomm/task_api/bestcomm_cntrl.h: C++ compatibility. Use special heap to manage the SRAM region. Use interrupt extension API. Fixed warnings.
  • console/console.c: Fixed console registration. Fixed warnings. Added GPS module registration.
  • ide/pcmcia_ide.h: Fixed clock value macros.
  • ide/pcmcia_ide.c: Update for BestComm? API changes. DP2 specific initialization. Removed zero loop in PIO receive function.
  • include/bsp.h: Added DP2 variant. Removed obsolete defines.
  • include/mscan-base.h, mscan/mscan-base.c: Use volatile qualifier. Format.
  • irq/irq.c: Fixed peripheral interrupt handling.
  • network_5200/network.c: Update for BestComm? API changes.
  • start/start.S: U-Boot fixes.
  • startup/cpuinit.c: Enable write-back cache strategy. Added special memory regions.
  • startup/linkcmds.brs5l: Fixed memory size.
  • Property mode set to 100644
File size: 13.5 KB
Line 
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
28/*!
29 * \file        bestcomm_api.h
30 *
31 * Bestcomm_api.h is the only header necessary for inclusion by user
32 * code. The include path the C compiler searches to find .h files
33 * should contain bestcomm/capi and one of bestcomm/code_dma/image_*.
34 * This second entry selects which set of BestComm tasks will be used.
35 * Of course the appropriate files in image_* must also be compiled and
36 * linked.
37 */
38
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
51/*!
52 * \brief       TaskSetup() debugging
53 *
54 * Define this macro as follows for debugging printf()s to see
55 * what the API receives and sets from the TaskSetupParamSet_t
56 * struct. Implemented in capi/task_api/tasksetup_general.h.
57 *
58 * \verbatim
59 * >0  : print basic debug messages
60 * >=10: also print C-API interface variables
61 * >=20: also print task API interface variables
62 * else: do nothing
63 * \endverbatim
64 */
65#define DEBUG_BESTCOMM_API 0
66
67/*!
68 * \brief       Maximum number of tasks in the system.
69 * This number is hardware-dependent and not user configuration.
70 */
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 */
86/*! \brief      Debug interrupt "task ID" */
87#define DEBUG_INTR_ID   SDMA_INT_BIT_DBG
88
89/*! \brief      TEA interrupt "task ID" */
90#define TEA_INTR_ID             SDMA_INT_BIT_TEA
91
92/*! \brief      Task start autostart enable */
93#define TASK_AUTOSTART_ENABLE   1
94
95/*! \brief      Task start autostart disable */
96#define TASK_AUTOSTART_DISABLE  0
97
98/*! \brief      Task start interrupt enable */
99#define TASK_INTERRUPT_ENABLE   1
100
101/*! \brief      Task start interrupt disable */
102#define TASK_INTERRUPT_DISABLE  0
103
104/*
105 * Buffer descriptor flags to pass to TaskBDAssign().
106 */
107/*! \brief      Transmit frame done */
108#define TASK_BD_TFD     (1 << SDMA_DRD_BIT_TFD)
109
110/*! \brief      Interrupt on frame done */
111#define TASK_BD_INT     (1 << SDMA_DRD_BIT_INT)
112
113/*!
114 * \brief       Data transfer size
115 */
116typedef enum {
117        SZ_FLEX         = 3,    /*!< invalid for TaskSetupParamSet_t */
118        SZ_UINT8        = 1,    /*!< 1-byte     */
119        SZ_UINT16       = 2,    /*!< 2-byte     */
120        SZ_UINT32       = 4             /*!< 4-byte     */
121} Sz_t;
122
123/*!
124 * \brief       API error codes
125 */
126typedef enum {
127        TASK_ERR_NO_ERR                 = -1,   /*!< No error                                   */
128        TASK_ERR_NO_INTR                = TASK_ERR_NO_ERR,
129                                                                        /*!< No interrupt                               */
130        TASK_ERR_INVALID_ARG    = -2,   /*!< Invalid function argument  */
131        TASK_ERR_BD_RING_FULL   = -3,   /*!< Buffer descriptor ring full*/
132        TASK_ERR_API_ALREADY_INITIALIZED
133                                                        = -4,   /*!< API has already been initialized */
134        TASK_ERR_SIZE_TOO_LARGE = -5,   /*!< Buffer descriptor cannot support size parameter */
135        TASK_ERR_BD_RING_EMPTY  = -6,   /*!< Buffer descriptor ring is empty*/
136        TASK_ERR_BD_BUSY                = -7,   /*!< The buffer descriptor is in use
137                                                                                 by the BestComm                        */
138        TASK_ERR_TASK_RUNNING   = -8    /*!< The task is running.               */
139
140} TaskErr_t;
141
142/*!
143 * \brief       BestComm initiators
144 *
145 * These are assigned by TaskSetup().
146 */
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
185} MPC5200Initiator_t;
186
187/*!
188 * \brief       Parameters for TaskSetup()
189 *
190 * All parameters can be hard-coded by the task API. Hard-coded values
191 * will be changed in the struct passed to TaskSetup() for the user to
192 * examine later.
193 */
194typedef struct {
195        uint32  NumBD;                  /*!< Number of buffer descriptors                               */
196
197        union {
198           uint32 MaxBuf;               /*!< Maximum buffer size                                                */
199           uint32 NumBytes;             /*!< Number of bytes to transfer                                */
200        } Size;                                 /*!< Buffer size union for BD and non-BD tasks  */
201
202        MPC5200Initiator_t
203                        Initiator;              /*!< BestComm initiator (ignored if hard-wired) */
204        uint32  StartAddrSrc;   /*!< Address of the DMA source (e.g. a FIFO)    */
205        sint16  IncrSrc;                /*!< Amount to increment source pointer                 */
206        Sz_t    SzSrc;                  /*!< Size of source data access                                 */
207        uint32  StartAddrDst;   /*!< Address of the DMA destination (e.g. a FIFO) */
208        sint16  IncrDst;                /*!< Amount to increment data pointer                   */
209        Sz_t    SzDst;                  /*!< Size of destination data access                    */
210} TaskSetupParamSet_t;
211
212/*!
213 * \brief       Parameters for TaskDebug()
214 *
215 * TaskDebug() and the contents of this data structure are yet to be
216 * determined.
217 */
218typedef struct {
219        int dummy;                              /* Some compilers don't like empty struct typedefs */
220} TaskDebugParamSet_t;
221
222/*!
223 * \brief       Generic buffer descriptor.
224 *
225 * It is generally used as a pointer which should be cast to one of the
226 * other BD types based on the number of buffers per descriptor.
227 */
228typedef struct {
229        uint32 Status;                  /*!< Status and length bits             */
230} TaskBD_t;
231
232/*!
233 * \brief       Single buffer descriptor.
234 */
235typedef struct {
236        uint32 Status;                  /*!< Status and length bits             */
237        uint32 DataPtr[1];              /*!< Pointer to data buffer             */
238} TaskBD1_t;
239
240/*!
241 * \brief       Dual buffer descriptor.
242 */
243typedef struct {
244        uint32 Status;                  /*!< Status and length bits             */
245        uint32 DataPtr[2];              /*!< Pointer to data buffers    */
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
257/*!
258 * \brief       Initialize a single task.
259 * \param       TaskName        Type of task to initialize. E.g. PCI transmit,
260 *                                              ethernet receive, general purpose dual-pointer.
261 *                                              Values expected can be found in the TaskName_t
262 *                                              enum defined in dma_image.capi.h.
263 * \param       TaskSetupParams Task-specific parameters. The user must fill out
264 *                                              the pertinent parts of a TaskSetupParamSet_t
265 *                                              data structure.
266 * \returns TaskId task identification token which is a required
267 *                      parameter for most other API functions.
268 *
269 * This function returns a task identification token which is a required
270 * parameter for most other API functions.
271 *
272 * Certain values of the structure pointed to by TaskParams are set
273 * as a side-effect based on task type. These may be examined after
274 * a successful call to TaskSetup(). User-specified values may be
275 * overridden.
276 *
277 * TaskId TaskSetup( TaskName_t TaskName,
278 *                   TaskSetupParamSet_t *TaskSetupParams );
279 */
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
312/*!
313 * \brief       Get the enable/disable status of a task.
314 * \param       taskId  Task handle passed back from a successful TaskSetup()
315 * \returns     Boolean true indicates enabled or false indicates disabled
316 *                      or invalid taskId.
317 */
318static inline int TaskStatus(TaskId taskId)
319{
320        return SDMA_TASK_STATUS(SDMA_TCR, taskId) & 0x8000;
321}
322
323/*!
324 * \brief       Return a pointer to a buffer descriptor at index BDIdx
325 * \param       taskId  Task handle passed back from a successful TaskSetup()
326 * \param       bd              Buffer descriptor handle returned by
327 *                                      TaskBDAssign() or TaskBDRelease().
328 * \returns     Pointer to the requested buffer descriptor or NULL on error.
329 *
330 * The returned pointer should be cast to the appropriate buffer
331 * descriptor type, TaskBD1_t or TaskBD2_t.
332 */
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
345/*!
346 * \brief       Return a pointer to the first buffer descriptor in the ring.
347 * \param       taskId  Task handle passed back from a successful TaskSetup()
348 * \returns     Pointer to the array of buffer descriptors making up the
349 *                      ring or NULL on error.
350 *
351 * A device driver author may choose to use this in lieu of
352 * TaskBDAssign()/TaskBDRelease() to get direct access to the
353 * BD ring with the warning that the underlying data structure may change.
354 * Use at one's own discretion.
355 */
356static inline TaskBD_t *TaskGetBDRing(TaskId taskId)
357{
358        return (TaskBD_t *) TaskBDIdxTable[taskId].BDTablePtr;
359}
360
361/*!
362 * \brief       Clear the interrupt for a given BestComm task.
363 * \param       taskId  Task handle passed back from a successful TaskSetup()
364 * \returns     TASK_ERR_NO_ERR (which is not really an error) for success
365 */
366static inline int TaskIntClear(TaskId taskId)
367{
368        SDMA_CLEAR_IEVENT(SDMA_INT_PEND, taskId);
369        return TASK_ERR_NO_ERR; /* success */
370}
371
372/*!
373 * \brief       Get the interrupt status for a given task.
374 * \param       taskId  Task handle passed back from a successful TaskSetup()
375 * \returns     TASK_ERR_NO_INTR (which is not really an error) for no interrupt
376 *                      pending, taskId for a regular interrupt, DEBUG_INTR_ID for
377 *                      a debug interrupt and TEA_INTR_ID for a TEA interrupt.
378 *                      \b Note: TaskIntStatus() may return 0, but this means that that
379 *                      taskId 0 is interrupt pending.
380 */
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
398/*!
399 * \brief       Get the interrupt pending status for a given task.
400 * \param       taskId  Task handle passed back from a successful TaskSetup()
401 * \returns     0 if task does not have a pending interrupt. 1 if the task
402 *                      has an interrupt pending.
403 */
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
416/*!
417 * \brief       Returns the task ID of an interrupting BestComm task.
418 * \returns     TASK_ERR_NO_INTR (which is not really an error) for no interrupt
419 *                      pending or the taskId of the interrupting task.
420 *
421 * The user must query TaskIntStatus() to discover if this is a debug
422 * or TEA interrupt. This function is designed for use by an operating
423 * system interrupt handler.
424 */
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
446/*!
447 * \brief       Get a count of in-use buffer descriptors.
448 * \param       taskId  Task handle passed back from a successful TaskSetup()
449 * \returns     Count of the current number of BDs in use by the given task.
450 */
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 */
Note: See TracBrowser for help on using the repository browser.