📄 bestcomm_api.c
字号:
/******************************************************************************
*
* 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.
*
* Filename: $Source: /proj/cvsroot/mgt/MGT5200/bestcomm/capi/bestcomm_api.c,v $
* Author: $Author: r21894 $
* Locker: $Locker: $
* State: $State: Exp $
* Revision: $Revision: 1.53 $
*
******************************************************************************/
/*!
* \mainpage Introduction
*
* \author Motorola Semiconductor Products Sector
* \date 2 Apr 2004
*/
/*!
* \file bestcomm_api.c
*
* Bestcomm_api.c implements most of the BestComm C API. The
* TaskSetup() function is generated by the BestComm Task API tools
* in capi/task_api/tasksetup_general.h as configured and included by
* code_dma/image_rtos?/task_capi/*.c. Other functions are defined as
* inline in capi/bestcomm_api.h.
*/
#include "ppctypes.h"
#include "bestcomm_api.h"
#include "task_api/bestcomm_cntrl.h"
#include "task_api/bestcomm_api_mem.h"
#include "task_api/tasksetup_bdtable.h"
/***********************************************************************
*/
static const char* const TaskVersionString = "BestComm API v2.2 20041209";
/*
* Hidden API data per task.
*/
static BDIdx BDHead[MAX_TASKS];
static BDIdx BDTail[MAX_TASKS];
/*
* Virtual memory location of the MBAR. System registers and SRAM are
* offset from this address.
*/
uint8 *MBarGlobal;
/*
* Offset from MBarGlobal to get the physical memory address of the
* MBAR. This will be zero for systems that do not use virtual memory in
* their device driver model.
*/
sint64 MBarPhysOffsetGlobal;
/*
* Offset to free space in SRAM after task code and buffer descriptors.
*/
uint32 SramOffsetGlobal = 0;
/*
* This flag is false when TaskStart() has not yet been called on a
* task newly configured by TaskSetup() or TaskStop() has been called.
* Otherwise it is true. It is possible that a task disabled itself
* (transfer complete or BD ring empty) which will not show up in this
* flag.
*
* It is really only useful for BD tasks that assign buffers (via
* TaskBDAssign()) before TaskStart() or after TaskStop() are called.
*/
int TaskRunning[MAX_TASKS];
/*!
* \brief Get a string containing API version information.
* \returns Pointer to the API version string
*/
const char *TaskVersion(void)
{
return TaskVersionString;
}
/*!
* \brief Initialize the API.
* \param MBarRef Reference pointer to the device register memory
* map.
*
* \returns TASK_ERR_NO_ERR on successful initialization.
* or TASK_ERR_API_ALREADY_INITIALIZED.
*
* This function is only used with physical addresses.
*
* This function will also initialize API internal variables. The return
* value TASK_ERR_API_ALREADY_INITIALIZED is intended to help determine if
* another process has already instantiated a version of the API.
*/
int TasksInitAPI(uint8 *MBarRef)
{
/*
* Copy pointer of register space to global variable.
* for use by other functions.
*/
MBarGlobal = MBarRef;
/*
* The offset is 0 if physical and virtual are the same.
*/
MBarPhysOffsetGlobal = 0;
/*
* IF API has not been initialized yet then...
* Make sure all BestComm interrupts are disabled and not pending.
* Make sure all tasks are disabled.
* This feature can only be put in after a way has been found to
* communicaticate with other processes.
*/
return TASK_ERR_NO_ERR;
}
/*!
* \brief Initialize the API when virtual memory is used.
* \param MBarRef Reference pointer to the device register memory
* map.
* \param MBarPhys Actual physical location of MBAR device register
* memory map.
*
* \returns TASK_ERR_NO_ERR on successful initialization.
* or TASK_ERR_API_ALREADY_INITIALIZED.
*
* This function allows using virtual memory addresses as well as physical
* addresses. All device registers are offset to the address supplied here,
* so the virtual memory space should include enough space for the entire
* register set of the device to include the SRAM space.
*
* This function will also initialize API internal variables. The return
* value TASK_ERR_API_ALREADY_INITIALIZED is intended to help determine if
* another process has already instantiated a version of the API.
*/
int TasksInitAPI_VM(uint8 *MBarRef, uint8 *MBarPhys)
{
/*
* Copy pointer of register space to global variable.
* for use by other functions.
*/
MBarGlobal = MBarRef;
MBarPhysOffsetGlobal = MBarPhys - MBarRef;
/*
* If API has not been initialized yet then...
* Make sure all BestComm interrupts are disabled and not pending.
* Make sure all tasks are disabled.
* This feature can only be put in after a way has been found to
* communicaticate with other processes.
*/
return TASK_ERR_NO_ERR;
}
/*!
* \brief \em Deprecated
* \param sdma Base address of the BestComm register set
*
* \returns TASK_ERR_NO_ERR
*
* Use of this function is no longer necessary. It is retained for
* compatibility with previous versions of the API.
*/
int TasksAttachImage(bestcomm_sdma_regs *sdma)
{
sdma; /* avoid compiler warnings */
return TASK_ERR_NO_ERR;
}
/*!
* \brief This function returns the value of the internal variable
* used to keep track of used space in SRAM.
*
* \returns The number of bytes from the beginning of SRAM to the end
* used space in the SRAM.
*
* This function will return the offset to free space in the SRAM
* not used by the CAPI. \b Note: The returned value is based
* on what is in TasksSetSramOffset. This function can
* not determine what SRAM space was used by another process. There must
* be some way external to the CAPI to keep track of SRAM space. This
* function only returns the internal variable used to keep track of buffer
* descriptors.
*/
uint32 TasksGetSramOffset(void)
{
return SramOffsetGlobal;
}
/*!
* \brief This function stores the number of bytes from the
* beginning of SRAM to the end of the used space.
*
* \param sram_offset Number of bytes until the beginning of
* free space in the SRAM.
*
* This function sets the free space offset in SRAM. It must be called
* before setup in multi-task environments. It is the application's
* job to determine where the free space in SRAM is. This sets the
* base offset for the buffer descriptor variables during setup, so to
* deallocate buffers that have already been set this function should be
* called with a new offset.
*/
void TasksSetSramOffset(uint32 sram_offset)
{
/*
* Set the SramOffsetGlobal variable to be used by TaskSetup_BDTable
*/
SramOffsetGlobal = sram_offset;
}
/*!
* \brief Start an initialized task running.
* \param taskId Task handle passed back from a successful TaskSetup()
* \param autoStartEnable Boolean for whether autostart bit is enabled.
* If this is set then the parameter autoStartTask
* defines the task to auto start.
* \param autoStartTask TaskId for task to autostart. If autoStartEnable
* is not set then this parameter is a don't care.
* \param intrEnable Boolean for interrupt enable for this task.
* \returns TASK_ERR_NO_ERR on success or TASK_ERR_INVALID_ARG if taskId
* is invalid.
*/
int TaskStart(TaskId taskId, uint32 autoStartEnable, TaskId autoStartTask,
uint32 intrEnable)
{
if (intrEnable) {
SDMA_INT_ENABLE(SDMA_INT_MASK, taskId);
} else {
SDMA_INT_DISABLE(SDMA_INT_MASK, taskId);
}
SDMA_TASK_AUTO_START(SDMA_TCR, taskId, autoStartEnable, autoStartTask)
SDMA_TASK_ENABLE(SDMA_TCR, taskId);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -