summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/gen5200/bestcomm/tasksetup_bdtable.c
blob: 58f5e683ca177c81ea202a4bacf1d7c559923574 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/******************************************************************************
*
* Copyright (c) 2004 Freescale Semiconductor, Inc.
* 
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
******************************************************************************/

#include "bestcomm_api.h"
#include "task_api/tasksetup_bdtable.h"
#include "include/mgt5200/mgt5200.h"

#ifdef __MWERKS__
__declspec(section ".text") extern const uint32 taskTable;
__declspec(section ".text") extern const uint32 taskTableBytes;
__declspec(section ".text") extern const uint32 taskTableTasks;
__declspec(section ".text") extern const uint32 offsetEntry;
#else
extern const uint32 taskTable;
extern const uint32 taskTableBytes;
extern const uint32 taskTableTasks;
extern const uint32 offsetEntry;
#endif

TaskBDIdxTable_t TaskBDIdxTable[MAX_TASKS];

static uint8 *TaskTableFree = 0;

void TaskSetup_BDTable(volatile uint32 *BasePtr, volatile uint32 *LastPtr, volatile uint32 *StartPtr,
					   int TaskNum, uint32 NumBD, uint16 MaxBD,
					   uint8 NumPtr, ApiConfig_t ApiConfig, uint32 Status)
{
	int i, j;
	uint32 *ptr;

	/*
	 * If another process has not used SRAM already, then the start value
	 * will have to be passed in using the TasksSetSramOffset() function.
	 */
	if (SramOffsetGlobal == 0) {
		SramOffsetGlobal = taskTableBytes;
	}

	TaskTableFree = MBarGlobal + MBAR_SRAM + SramOffsetGlobal;

	/*
	 * First time through the Buffer Descriptor table configuration
	 * set the buffer descriptor table with parameters that will not
	 * change since they are determined by the task itself.	The
	 * SramOffsetGlobal variable must be updated to reflect the new SRAM
	 * space used by the buffer descriptor table.  The next time through
	 * this function (i.e. TaskSetup called again) the only parameters
	 * that should be changed are the LastPtr pointers and the NumBD part
	 * of the table.
	 */
	if (TaskBDIdxTable[TaskNum].BDTablePtr == 0) {
		TaskBDIdxTable[TaskNum].BDTablePtr  = TaskTableFree;
		TaskBDIdxTable[TaskNum].numPtr      = NumPtr;
		TaskBDIdxTable[TaskNum].apiConfig   = ApiConfig;
		TaskBDIdxTable[TaskNum].BDStartPtr  = StartPtr;

		*StartPtr = *BasePtr  = (uint32)((uint32)TaskBDIdxTable[TaskNum].BDTablePtr
			 		+ MBarPhysOffsetGlobal);

		switch (NumPtr) {
			case 1:
				SramOffsetGlobal += MaxBD*sizeof(TaskBD1_t);
				break;
			case 2:
				SramOffsetGlobal += MaxBD*sizeof(TaskBD2_t);
				break;
			default:
				/* error */
				break;
		}
	}

	TaskBDIdxTable[TaskNum].currBDInUse	= 0;
	TaskBDIdxTable[TaskNum].numBD		= (uint16)NumBD;
	switch (NumPtr) {
		case 1:
			*LastPtr = (uint32)(*BasePtr + sizeof(TaskBD1_t) * (NumBD - 1));
			break;
		case 2:
			*LastPtr = (uint32)(*BasePtr + sizeof(TaskBD2_t) * (NumBD - 1));
			break;
		default:
			/* error */
			break;
	}

	/*
	 * Set the status bits. Clear the data pointers.
	 */
	if (MaxBD > 0) {
		ptr = TaskBDIdxTable[TaskNum].BDTablePtr;
		for (i = 0; i < NumBD; i++) {
			*(ptr++) = Status;
			for (j = 0; j < NumPtr; j++) {
				*(ptr++) = 0x0;
			}
		}
	}
}