📄 au1500gpio.c
字号:
/* au1500Gpio.c - AMD AU1500 GPIO driver */
/* Copyright Copyright 2002-2004 Founder Communications, Inc. */
/*
modification history
--------------------
01a,18mar05,fhchen written
*/
/*
DESCRIPTION
This module contains the AU1500 primary and secondary GPIO driver routines.
*/
/* includes */
#include <vxWorks.h>
#include "sysGpio.h"
#include "au1500Gpio.h"
/* globals */
AU1500_GPIO2 * const gpio2 = (AU1500_GPIO2 *)PHYS_TO_K1(GPIO2_PHYS_ADDR);
AU1500_SYS * const sys = (AU1500_SYS *)PHYS_TO_K1(SYS_PHYS_ADDR);
/***********************************************************************
*
* au1500GpioInit - initialize AU1500 GPIOs
*
* This routines put primary and secondary GPIOs to a known state:
* registers are set in the default value.
*
* RETURNS: N/A
*/
void au1500GpioInit(void)
{
/* todo: set all pins in a known state */
}
/***********************************************************************
*
* au1500PriGpioRead - get logic level of a primary GPIO pin
*
* This routines read the data from a primary GPIO pin.
*
* RETURNS:
* - LOGIC_HIGH or LOGIC_LOW on success.
* - ERROR if pin is invalid.
*/
int au1500PriGpioRead(int pin)
{
/* check parameter */
if(pin & INVALID_PRIMARY_GPIO)
return (ERROR);
/* tristating the pin first */
sys->sys_trioutclr = pin; /* be careful here, do not use | */
/* read sys_pinstaterd to get the pin level */
if((sys->sys_pinstaterd & pin) == 0)
return LOGIC_LOW;
else
return LOGIC_HIGH;
}
/***********************************************************************
*
* au1500SecGpioRead - get logic level of a secondary GPIO pin
*
* This routines read the data from a secondary GPIO pin.
*
* RETURNS:
* - LOGIC_HIGH or LOGIC_LOW on success.
* - ERROR if pin is invalid.
*/
int au1500SecGpioRead(int pin)
{
/* check parameter */
if(pin & INVALID_SECONDARY_GPIO)
return (ERROR);
/* set direction as input */
gpio2->gpio2_dir &= ~pin;
/* get logic level */
if((gpio2->gpio2_pinstate & pin) == 0)
return LOGIC_LOW;
else
return LOGIC_HIGH;
}
/***********************************************************************
*
* au1500PriGpioWrite - write data to a primary GPIO pin
*
* This routines write data to a primary GPIO pin.
*
* NOTE:
* - nothing happens on invalid pin
*
* RETURNS: N/A
*/
void au1500PriGpioWrite
(
int pin,
int level
)
{
/* check parameter */
if(pin & INVALID_PRIMARY_GPIO)
return;
/*
* output logic level using outputset/outputclr, this will also brings
* the pin out of tristate and enables the output.
*/
if(LOGIC_HIGH == level)
sys->sys_outputset |= pin;
else
sys->sys_outputclr = pin; /* be careful here, do not use | */
}
/***********************************************************************
*
* au1500SecGpioWrite - write data to a secondary GPIO pin
*
* This routines write data to a secondary GPIO pin.
*
* NOTE:
* - nothing happens on invalid pin
* - perform SINGLE OPERATION on gpio2_output to turn high or low.
*
* RETURNS: N/A
*/
void au1500SecGpioWrite
(
int pin,
int level
)
{
int val = 0;
/* check parameter */
if(pin & INVALID_SECONDARY_GPIO)
return;
/* set direction as output */
gpio2->gpio2_dir |= pin;
/* get current pin state */
val = gpio2->gpio2_pinstate;
/* set logic level */
if(LOGIC_HIGH == level)
val |= (pin | (pin << 16));
else
{
val &= ~pin;
val |= (pin << 16);
}
/* output logic level */
gpio2->gpio2_output = val; /* be carefule, operation should be atomic */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -