📄 xsgpio.c
字号:
#if 0
Functions in this list have incomplete comment blocks.
UINT32 XsGpioSetAlternateFunction
UINT32 XsGpioGetLevel
UINT32 XsGpioSetLevel
UINT32 XsGpioSetLevelIsr
void XsGpioSetIcp
void XsGpioSetStuart
void XsGpioSetSimulatedLevelInt
#endif
/******************************************************************************
**
** 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: XsGpio.c
**
** PURPOSE: Driver for the main processor's on-board General Purpose
** Input/Output devices. Includes initialization, API and
** support functions.
**
** EAS VERSION : 2.1
**
** $Modtime: 7/17/03 1:01p $
******************************************************************************/
#define _DEFINING_XSGPIOAPI
#define _DEFINING_XSGPIO
#include "string.h"
#include "systypes.h"
#include "cotulla.h"
#include "dm_errors.h"
#include "platform.h"
#include "XsCp15.h"
#include "XsIntCtrlApi.h"
#include "XsGpioApi.h"
#include "XsGpio.h"
#include "XsGpioPlatform.h"
#include "xsssp.h"
/*
*******************************************************************************
Functions in standard driver API of main processor on-board GPIO handler
*******************************************************************************
*/
/*
*******************************************************************************
*
* FUNCTION: XsGpioSWInit
*
* DESCRIPTION: Init context structure and private table.
*
* INPUT PARAMETERS: None
*
* RETURNS: None
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS:
*
* CALLS:
*
* CALLED BY:
*
* PROTOTYPE: void XsGpioSWInit (void);
*
*******************************************************************************
*/
void XsGpioSWInit (void)
{
// Initialize global regs pointer
XsGpioRegsP = (XsGpioRegsT *) XS_GPIO_REGISTER_BASE;
// Zero GPIO usage table and context structure
memset (&XsGpioCurrentUsageTable, sizeof(XsGpioCurrentUsageTable),0);
memset (&XsGpioContext, sizeof(XsGpioContext),0);
} // End XsGpioSWInit ()
/*
*******************************************************************************
*
* FUNCTION: XsGpioHWSetup
*
* DESCRIPTION: Initialize the main processor GPIO registers and pins based
* on the pre-configured initialization table.
* For each pin, sets direction and alternate function or
* GPIO mode. For output pins, sets initial level before
* setting direction. No interrupts are enabled for input
* GPIO pins. Some pins may be designated as reserved for
* debug monitor in a debug build (not BOOTABLE). A record
* is made of the now-current configuration, including marking
* the reserved pins.
* Register the GPIO interrupt handling subroutine with
* the Interrupt Controller driver module. Enable GPIO
* interrupts at the IC.
*
* INPUT PARAMETERS: None
*
* RETURNS:
* Success: 0 (ERR_NONE)
* Failure: NonZero: Internal error invoking XsIcRegisterHandler()
*
* GLOBAL EFFECTS:
*
* ASSUMPTIONS: All GPIO registers are fresh from reset, which implies
* 0-initialized. The one exception is that some pins may
* be reserved for a debug monitor in debug build.
*
* CALLS:
*
* CALLED BY:
*
* PROTOTYPE: UINT32 XsGpioHWSetup (void);
*
*******************************************************************************
*/
UINT32 XsGpioHWSetup (void)
{
// Assumes that the system is powering up and all GPIO registers are at
// the default values of 0, except for those pins which are known to be
// excluded as indicated by the GPIO_INIT_NO value in the defaultCategory
// member of the default configuration table.
UINT32 status = FALSE;
INT i;
INT regIndex; // For GPIO register addressing.
INT bitOffset; // For GPIO register addressing.
UINT32 tmpReg; // Need to perform clean bit clear / set operations in some cases
XsGpioDefaultEntryT *defltPinCfgP;
XsGpioUsageEntryT *currPinCfgP = XsGpioCurrentUsageTable;
// Select default GPIO configuration based on presence or absence of
// the expansion board.
/*
if (expansionBoardPresent())
{
defltPinCfgP = XsGpioDfltCfgTblWithExpBd;
}
*/
// else
// {
defltPinCfgP = XsGpioDfltCfgTblNoExpBd;
// }
for ( i=0 ; i < XS_GPIO_PIN_COUNT; i++ )
{
// First, determine whether we may play with this pin.
switch (defltPinCfgP->defaultCategory)
{
case GPIO_INIT_NO:
// only processing for untouchable pin is to record that fact.
currPinCfgP->fnCategory = XS_GPIO_UNAVAILABLE;
break;
case GPIO_INIT_CHK_FF:
// Init this pin's function category based on system config
// Assume debug monitor might be using it.
// if (XsGpioOkToUseFfUart())
// {
currPinCfgP->fnCategory = defltPinCfgP->altFunctionSelector;
// }
// else
// {
// Not OK to touch the FFUART pins.
// currPinCfgP->fnCategory = XS_GPIO_UNAVAILABLE;
// }
break;
case GPIO_INIT_CHK_BT:
// Init this pin's function category based on system config
// Assume debug monitor might be using it.
// if (XsGpioOkToUseBtUart())
// {
currPinCfgP->fnCategory = defltPinCfgP->altFunctionSelector;
// }
// else
// {
// Not OK to touch the BTUART pins.
// currPinCfgP->fnCategory = XS_GPIO_UNAVAILABLE;
// }
break;
default:
currPinCfgP->fnCategory = defltPinCfgP->altFunctionSelector;
} // switch (defltPinCfgP->defaultCategory)
// If we own the pin, perform the initialization.
if (XS_GPIO_UNAVAILABLE != currPinCfgP->fnCategory)
{
currPinCfgP->initialLevel = defltPinCfgP->initialLevel;
currPinCfgP->direction = defltPinCfgP->direction;
currPinCfgP->fnCategory = defltPinCfgP->altFunctionSelector;
currPinCfgP->simulatedLevelInt= defltPinCfgP->simulatedLevelInt;
// Order of operations is important in HW access.
// Initial level, direction, then alternate function selection
// Set up addressing for first two register operations
XsGpioRegsCalcLocIndices ( i, ®Index, &bitOffset );
// For output lines only, set the level.
if (XS_GPIO_DIR_OUT == currPinCfgP->direction)
{
// Write-only registers, don't read - "OR" - write .
if (XS_GPIO_PIN_LEVEL_1 == currPinCfgP->initialLevel)
{
XsGpioRegsP->GPSRs[regIndex]
= XS_GPIO_PIN_LEVEL_MSK << bitOffset;
}
else // must be XS_GPIO_PIN_LEVEL_0
{
XsGpioRegsP->GPCRs[regIndex]
= XS_GPIO_PIN_LEVEL_MSK << bitOffset;
}
} // End of output direction
// Get copy of register with target bit cleared
tmpReg = XsGpioRegsP->GPDRs[regIndex]
& ~(XS_GPIO_DIR_MSK << bitOffset);
// Set intended value
XsGpioRegsP->GPDRs[regIndex] =
tmpReg | (currPinCfgP->direction << bitOffset);
// Set up addressing for GAFR access (alternate function regs)
XsGpioRegsCalcLocIndicesGafr ( i, ®Index, &bitOffset );
// Get copy of register with target bit cleared
tmpReg = XsGpioRegsP->GAFRs[regIndex]
& ~(XS_GPIO_GAFR_PIN_MSK << bitOffset);
XsGpioRegsP->GAFRs[regIndex]
= tmpReg | (currPinCfgP->fnCategory << bitOffset);
} // if (XS_GPIO_UNAVAILABLE != currPinCfgP->fnCategory)
defltPinCfgP++;
currPinCfgP++;
} // End of for loop processing all entries in table
// Should eventually have separate handlers for GPIO1 and GPIO2 as well as
// general handler, but will make do without that optimization for now.
status = XsIcRegisterHandler (XSIC_GPIO_0_SGNL,
XsGpioInterruptHandler,
(void *) &XsGpioContext);
if (!status)
{
status = XsIcRegisterHandler (XSIC_GPIO_1_SGNL,
XsGpioInterruptHandler,
(void *) &XsGpioContext);
}
if (!status)
{
status = XsIcRegisterHandler (XSIC_GPIO_2_OR_80_SGNL,
XsGpioInterruptHandler,
(void *) &XsGpioContext);
}
// No problems, now enable the GPIO interrupts at the Interrupt Controller.
// Ignore return values, the parameters were range-checked just above.
if (!status)
{
(void) XsIcEnableIrqDeviceInt (XSIC_GPIO_0_SGNL);
(void) XsIcEnableIrqDeviceInt (XSIC_GPIO_1_SGNL);
(void) XsIcEnableIrqDeviceInt (XSIC_GPIO_2_OR_80_SGNL);
}
return (status);
} // End XsGpioHWSetup ()
/*
*******************************************************************************
*
* FUNCTION: XsGpioSetDirection
*
* DESCRIPTION: For a pin configured as GPIO, and with no interrupt handler
* registered, set the direction. If the direction is output,
* set the initial level first (per processor manual).
*
* INPUT PARAMETERS:
* XsGpioIdT pinID - GPIO pin to set direction for
* XsGpioDirT direction - Input or output
* XsGpioPinLevelT initialLevel- Initial level if output pin, else ignored
*
* RETURNS:
* Success: 0 (ERR_NONE)
* Failure: ERR_T_ILLPARAM - out of range parameter; details in err log
* ERR_T_NOT_AVAIL - pin reserved (for debug monitor)
* ERR_T_WRONG_STATE - pin not configured as GPIO
* ERR_T_REG_HANDLER - interrupt handler is currently registered
* and output direction is specified
*
* GLOBAL EFFECTS:
*
* ASSUMPTIONS:
*
* CALLS:
*
* CALLED BY:
*
* PROTOTYPE: UINT32 XsGpioSetDirection (XsGpioIdT,
* XsGpioDirT,
* GpioPinLevelT)
*
*******************************************************************************
*/
UINT32 XsGpioSetDirection ( XsGpioIdT pinID,
XsGpioDirT direction,
XsGpioPinLevelT initialLevel)
{
// Does not yet address Power Management Register issues.!!!
UINT32 status;
INT badParamNum = 0; // Which param had error. Assume no errors.
INT regIndex; // For GPIO register addressing.
INT bitOffset; // For GPIO register addressing.
UINT32 tempGPDR;
XsGpioUsageEntryT *currPinCfgP;
// Range check the parameters.
status = XsGpioRangeCheckPinId (pinID);
if (status)
{
badParamNum = 1;
}
else if (direction & ~1u)
{
badParamNum = 2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -