Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:52

0001 /******************************************************************************
0002 *
0003 * Copyright (c) 2004 Freescale Semiconductor, Inc.
0004 *
0005 * Permission is hereby granted, free of charge, to any person obtaining a
0006 * copy of this software and associated documentation files (the "Software"),
0007 * to deal in the Software without restriction, including without limitation
0008 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009 * and/or sell copies of the Software, and to permit persons to whom the
0010 * Software is furnished to do so, subject to the following conditions:
0011 *
0012 * The above copyright notice and this permission notice shall be included
0013 * in all copies or substantial portions of the Software.
0014 *
0015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0018 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021 * OTHER DEALINGS IN THE SOFTWARE.
0022 *
0023 ******************************************************************************/
0024 
0025 #include <assert.h>
0026 
0027 #include <bsp/bestcomm/bestcomm_api.h>
0028 #include <bsp/bestcomm/bestcomm_glue.h>
0029 #include <bsp/bestcomm/task_api/tasksetup_bdtable.h>
0030 #include <bsp/bestcomm/include/mgt5200/mgt5200.h>
0031 
0032 #ifdef __MWERKS__
0033 __declspec(section ".text") extern const uint32 taskTable;
0034 __declspec(section ".text") extern const uint32 taskTableBytes;
0035 __declspec(section ".text") extern const uint32 taskTableTasks;
0036 __declspec(section ".text") extern const uint32 offsetEntry;
0037 #else
0038 extern const uint32 taskTable;
0039 extern const uint32 taskTableBytes;
0040 extern const uint32 taskTableTasks;
0041 extern const uint32 offsetEntry;
0042 #endif
0043 
0044 TaskBDIdxTable_t TaskBDIdxTable[MAX_TASKS];
0045 
0046 void TaskSetup_BDTable(volatile uint32 *BasePtr, volatile uint32 *LastPtr, volatile uint32 *StartPtr,
0047                        int TaskNum, uint32 NumBD, uint16 MaxBD,
0048                        uint8 NumPtr, ApiConfig_t ApiConfig, uint32 Status)
0049 {
0050     int i, j;
0051     uint32 *ptr;
0052 
0053     /*
0054      * First time through the Buffer Descriptor table configuration
0055      * set the buffer descriptor table with parameters that will not
0056      * change since they are determined by the task itself. The
0057      * SramOffsetGlobal variable must be updated to reflect the new SRAM
0058      * space used by the buffer descriptor table.  The next time through
0059      * this function (i.e. TaskSetup called again) the only parameters
0060      * that should be changed are the LastPtr pointers and the NumBD part
0061      * of the table.
0062      */
0063     if (TaskBDIdxTable[TaskNum].BDTablePtr == 0) {
0064         size_t AllocSize = 0;
0065         void *AllocBegin = NULL;
0066 
0067         switch (NumPtr) {
0068             case 1:
0069                 AllocSize += MaxBD*sizeof(TaskBD1_t);
0070                 break;
0071             case 2:
0072                 AllocSize += MaxBD*sizeof(TaskBD2_t);
0073                 break;
0074             default:
0075                 assert(0);
0076                 break;
0077         }
0078 
0079         AllocBegin = bestcomm_malloc(AllocSize);
0080         assert(AllocBegin != NULL);
0081 
0082         TaskBDIdxTable[TaskNum].BDTablePtr  = AllocBegin;
0083         TaskBDIdxTable[TaskNum].numPtr      = NumPtr;
0084         TaskBDIdxTable[TaskNum].apiConfig   = ApiConfig;
0085         TaskBDIdxTable[TaskNum].BDStartPtr  = StartPtr;
0086 
0087         *StartPtr = *BasePtr  = (uint32)((uint32)TaskBDIdxTable[TaskNum].BDTablePtr
0088                     + MBarPhysOffsetGlobal);
0089     }
0090 
0091     TaskBDIdxTable[TaskNum].currBDInUse = 0;
0092     TaskBDIdxTable[TaskNum].numBD       = (uint16)NumBD;
0093     switch (NumPtr) {
0094         case 1:
0095             *LastPtr = (uint32)(*BasePtr + sizeof(TaskBD1_t) * (NumBD - 1));
0096             break;
0097         case 2:
0098             *LastPtr = (uint32)(*BasePtr + sizeof(TaskBD2_t) * (NumBD - 1));
0099             break;
0100         default:
0101             /* error */
0102             break;
0103     }
0104 
0105     /*
0106      * Set the status bits. Clear the data pointers.
0107      */
0108     if (MaxBD > 0) {
0109         ptr = TaskBDIdxTable[TaskNum].BDTablePtr;
0110         for (i = 0; i < NumBD; i++) {
0111             *(ptr++) = Status;
0112             for (j = 0; j < NumPtr; j++) {
0113                 *(ptr++) = 0x0;
0114             }
0115         }
0116     }
0117 }