📄 xsost.c
字号:
/******************************************************************************
**
** COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
** This software as well as the software described in it is furnished under
** license and may only be used or copied in accordance with the terms of the
** license. The information in this file is furnished for informational use
** only, is subject to change without notice, and should not be construed as
** a commitment by Intel Corporation. Intel Corporation assumes no
** responsibility or liability for any errors or inaccuracies that may appear
** in this document or any software that may be provided in association with
** this document.
** Except as permitted by such license, no part of this document may be
** reproduced, stored in a retrieval system, or transmitted in any form or by
** any means without the express written consent of Intel Corporation.
**
** FILENAME: xsost.c
**
** PURPOSE: Operating System Timer Functions
**
** LAST MODIFIED: 02/09/2001
******************************************************************************/
/*
*******************************************************************************
* HEADER FILES
*******************************************************************************
*/
#include <stdio.h>
#include "systypes.h"
#include "dm_errors.h"
#include "cotulla.h"
#include "XsDmaApi.h"
#include "XsIntCtrlApi.h"
#include "ROS.h"
#define OST_GLOBALS
#include "XsOstDCS.h"
#include "XsOst.h"
#undef OST_GLOBALS
/*
*******************************************************************************
GLOBAL DEFINITIONS
*******************************************************************************
*/
UINT32 OSTInterruptFlag = 0xFFFFFFFF; // means no interrupt is currently active
static XsOstCallbackFnCtxT XsOstCbFnCtx[XS_OST_MAX_CHANNELS];
XsOstCallbackFnCtxT *XsOstCbFnCtxP = &XsOstCbFnCtx[0];
/*
*******************************************************************************
* LOCAL DEFINITIONS
*******************************************************************************
*/
UINT XsOstChannelsUsed = 0;
UINT XsOstCurrentChannel = 0;
/*
*******************************************************************************
*
* FUNCTION: XsOstComputeTicks
*
* DESCRIPTION: Computes the number of ticks required for the number of
* microseconds desired. We are using integer math here and
* depending on the natural behavior of C to clip off fractional
* parts of a calculation. However, the error is still only on the
* order of .01% for counts larger than a few microseconds.
*
* INPUT PARAMETERS: UINT32 - number of microseconds
*
* RETURNS: UINT32 - number of ticks
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: Assumes the 3.2500 MHz crystal used for Bulverde
*
* CALLS: None
*
* CALLED BY: OSTWaitUs, OSTStartTimer
*
* PROTOTYPE: UINT32 XsOstComputeTicks (UINT32 usecs);
*
*******************************************************************************
*/
UINT32 XsOstComputeTicks(UINT32 usecs)
{
UINT32 numOfTicks;
// If the number of microseconds adds up to more than about 19 minutes,
// I'm going to just limit it to a maximum amount without error, but someone
// may need to re-visit their code if they needs this much delay.
// Compute the number of ticks
numOfTicks = ((3 * usecs) + // Whole part
(2 * usecs/10) + // Fractional parts
(5 * usecs/100) +
(0 * usecs/1000) +
(0 * usecs/10000)
);
if (numOfTicks > 0xFFFFFFF0)
{
numOfTicks = 0xFFFFFFF0;
}
return numOfTicks;
}
/*
*******************************************************************************
*
* FUNCTION: OSTWaitUs
*
* DESCRIPTION: Counts off the number of ticks to wait for a number of
* specified microseconds. This is done with integer math with
* a crystal that is 3.6864 MHz. This means that there are
* 3.6864 ticks per microsecond. Percentage of error is high
* for low numbers of microseconds, but delays of sub-millisecond
* duration should not be very common.
*
* INPUT PARAMETERS: UINT32 - usecs to count
*
* RETURNS: UINT32 - 0 means no error
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: None
*
* CALLED BY: Anyone
*
* PROTOTYPE: UINT32 OSTWaitUs (UINT32 usecs);
*
*******************************************************************************
*/
UINT32 OSTWaitUs (UINT32 usecs)
{
UINT32 numOfTicks;
UINT32 returnValue = 0;
UINT32 start;
volatile OSTRegsT *OstControlRegsP = Ost.regsP;
if (ROS_Tasks && usecs>=10000) {
ROS_Timer(ROS_Task, usecs/10000+1, 0);
ROS_Release();
} else {
numOfTicks = XsOstComputeTicks(usecs);
start = OstControlRegsP->OSCR;
if (usecs>=1000) ROS_Release();
while ((INT32)(OstControlRegsP->OSCR - start - numOfTicks) < 0);
}
return returnValue;
}
/*
*******************************************************************************
*
* FUNCTION: OSTWaitMs
*
* DESCRIPTION: Generates a wait in milliseconds by calling the OSTWaitUs
* procedure with a computed value.
*
* INPUT PARAMETERS: UINT32 - milliseconds to wait
*
* RETURNS: UINT32 - 0 means no error
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: OSTWaitUs
*
* CALLED BY: Anyone
*
* PROTOTYPE: UINT32 OSTWaitMs(UINT32 msecs);
*
*******************************************************************************
*/
UINT32 OSTWaitMs(UINT32 msecs)
{
return OSTWaitUs(msecs * 1000);
}
/*
*******************************************************************************
*
* FUNCTION: OSTWaitS
*
* DESCRIPTION: Generates a wait in seconds by calling the OSTWaitUs
* procedure with a computed value.
*
* INPUT PARAMETERS: UINT32 - seconds to wait
*
* RETURNS: UINT32 - 0 means no error
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: OSTWaitUs
*
* CALLED BY: Anyone
*
* PROTOTYPE: UINT32 OSTWaitS(UINT32 secs);
*
*******************************************************************************
*/
UINT32 OSTWaitS(UINT32 secs)
{
return OSTWaitUs(secs * 1000000);
}
/*
*******************************************************************************
*
* FUNCTION: XsOstModifyChannelUsage
*
* DESCRIPTION: This is an internal access function to read and modify
* a static variable containing the OST channel usage
* information.
*
* INPUT PARAMETERS: Action - get or set a channel
* channel - the channel to set. This parameter is ignored
* if the action is a GET.
*
* RETURNS: channel - that is gotten or set
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
*******************************************************************************
*/
static
UINT32 XsOstModifyChannelUsage(int usage, UINT32 channel)
{
int chan; // internal loop counter
UINT32 returnval;
if (usage == CHANNEL_OP_GET)
{
// shift through the word to find an unused channel
for (chan = 1; chan <= 4; chan++)
{
if((XsOstChannelsUsed & chan) == 0)
{
if(chan == 2)
{
//Do not touch this channel. It is used by
//the low-level init. code, hence, it is reserved.
continue;
}
else
{
//This is a free channel. Mark it as used now.
XsOstChannelsUsed |= chan;
returnval = chan - 1;
break;
}
}
/*if ((UsedWord & 1 << chan) == 0)
{
UsedWord |= 1 << chan;
returnval = chan - 1;
}*/
}
//returnval = -1; // no unused channels
}
if (usage == CHANNEL_OP_RESET)
{
if(channel == 1)
{
//Do not touch this channel. This is for ANGEL's use.
printf(" Error! Cannot clear this channel. This is for ANGEL's use.\r\n");
}
else
{
// unconditionally reset the channel bit. Make no assumptions about
// the previous state.
XsOstChannelsUsed &= ~(0x1 << channel);
returnval = channel;
}
}
/*if (usage == CHANNEL_OP_SET)
{
// unconditionally set the channel bit. Make no assumptions about
// the previous state.
XsOstChannelsUsed |= 1 << channel + 1;
returnval = channel;
}*/
return returnval;
}
/*
*******************************************************************************
*
* FUNCTION: XsOstGetFreeChannel
*
* DESCRIPTION: Finds an unused OST channel. The used channels are stored
* as bits within a static integer.
*
* INPUT PARAMETERS: UINT getChannel - a verb that instructs the procedure to return
* a free channel.
* 0 - This parameter is ignored.
*
* RETURNS: UINT32 channel or -1 if none are free
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: XsOstModifyChannelUsage
*
*******************************************************************************
*/
UINT32 XsOstGetFreeChannel(void)
{
UINT32 freeChannel = XS_OST_MAX_CHANNELS; //Set this to any value above 3
freeChannel = XsOstModifyChannelUsage(CHANNEL_OP_GET, 0);
if ((freeChannel <= 3) && (freeChannel != 2))
{
return freeChannel;
}
else
{
printf(" Error! Could not get free OST channel\r\n");
return freeChannel; //Replace this 'return' with correct ERROR_CODE
}
}
/*
*******************************************************************************
*
* FUNCTION: XsOstFreeChannel
*
* DESCRIPTION: Sets a OST channel to "unused".
*
* INPUT PARAMETERS: Channel - the channel to free
*
* RETURNS: Void
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: Assumes the channel number was derived from
* XsOstGetFreeChannel.
*
*******************************************************************************
*/
void XsOstFreeChannel(UINT32 channel)
{
UINT32 dummy = 0;
dummy = XsOstModifyChannelUsage(CHANNEL_OP_RESET, channel);
return;
}
/*
*******************************************************************************
*
* FUNCTION: XsOstEnableInterrupt
*
* DESCRIPTION: Enable an Interrupt on an OST Channel
*
* INPUT PARAMETERS: UINT -channel
*
* RETURNS: UINT32 - 0 means no error
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: None
*
* CALLED BY:
*
* PROTOTYPE: UINT32 XsOstEnableInterrupt(UINT channel);
*
*******************************************************************************
*/
UINT32 XsOstEnableInterrupt(UINT channel)
{
UINT32 returnValue = 0;
volatile OSTRegsT *OstControlRegsP = Ost.regsP;
switch (channel)
{
case 0:
OstControlRegsP->OIER |= OIER_E0;
break;
case 1:
printf("Enabling ANGEL's OIER bit...!\r\n");
/*OstControlRegsP->OIER |= OIER_E1;*/
break;
case 2:
OstControlRegsP->OIER |= OIER_E2;
break;
case 3:
OstControlRegsP->OIER |= OIER_E3;
break;
default:
LOGERROR(returnValue, ERR_L_XSOST, 0, ERR_T_ILLPARAM, 0, 0, 0);
}
return returnValue;
}
/*
*******************************************************************************
*
* FUNCTION: XsOstDisableInterrupt
*
* DESCRIPTION: Disable an Interrupt on an OST Channel
*
* INPUT PARAMETERS: UINT -channel
*
* RETURNS: UINT32 - 0 means no error
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: None
*
* CALLED BY:
*
* PROTOTYPE: UINT32 XsOstDisableInterrupt(UINT channel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -