OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [vpio/] [vpioGpio.h] - Rev 196

Go to most recent revision | Compare with Previous | Blame | View Log

/* $Id: memtest.hh,v 1.8 2008-06-24 10:03:41 sybreon Exp $
** 
** VIRTUAL PERIPHERAL I/O LIBRARY
** Copyright (C) 2009 Shawn Tan <shawn.tan@aeste.net>
**
** This file is part of AEMB.
**
** AEMB is free software: you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** AEMB is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
** License for more details.
**
** You should have received a copy of the GNU General Public License
** along with AEMB.  If not, see <http://www.gnu.org/licenses/>.
*/
 
/*! 
  GPIO C Interface Library.
  @file 
*/
 
#ifndef VPIO_GPIO_H
#define VPIO_GPIO_H
 
/*!
   GPIO Directions.
*/
 
enum vpioGpioTrisType
  {
    GPIO_INPUT  = 0, ///< Define GPIO pin as an input
    GPIO_OUTPUT = 1 ///< Define GPIO pin as an output
  };
 
/*!
   GPIO Register Map.       
   This structure contains the register file of a general-purpose
   I/O. Care should be taken when using it due to endian issues.
*/
 
struct vpioGpioRegs
{
  volatile int regCtrl; ///< GPIO direction register.
  //unsigned int /* unused */ :24;    
  volatile int regLine; ///< GPIO line data register.
  //unsigned int /* unused */ :24;    
};
 
typedef struct vpioGpioRegs vpioGpioRegs;
 
/*!
   Get a port bit.
 
   This function reads the value of a specific bit on a GPIO port. It
   reads the entire port line and masks out the specific bit. The
   result should be interpreted as zero for 0 and non-zero for 1.
 
   @param port Memory-mapped I/O port.
   @param bit Get port bit value.
   @return Value of the port bit.
*/
 
inline
int  vpioGpioGetBit(vpioGpioRegs* port, int bit)
{
  return port->regLine & (1 << bit);  
}
 
/*!
   Set a port bit.
 
   This function sets a specific bit on a GPIO port to 1. It is a
   read-modify-write instruction that reads the port value, masks it
   and writes the new value to the port.
 
   @param port Memory-mapped I/O port.
   @param bit Set port bit to 1.
*/
 
inline
void vpioGpioSetBit(vpioGpioRegs* port, int bit) 
{
  port->regLine |= (1 << bit);
}
 
/*!
   Toggle a port bit.
 
   This function toggles a specific bit on a GPIO port. It is a
   read-modify-write instruction that reads the port value, masks it
   and writes the new value to the port.
 
   @param port Memory-mapped I/O port.
   @param bit Toggle port bit between 0 and 1.
*/
 
inline
void vpioGpioTogBit(vpioGpioRegs* port, int bit) 
{
  port->regLine ^= (1 << bit);
}
 
/*!
   Clear a port bit.
 
   This function clears a specific bit on a GPIO port to 0. It is a
   read-modify-write instruction that reads the port value, masks it
   and writes the new value to the port.
 
   @param port Memory-mapped I/O port.
   @param bit Clear port bit to 0.
 */
 
inline
void vpioGpioClrBit(vpioGpioRegs* port, int bit) 
{
  port->regLine &= ~(1 << bit);
}
 
/*!
   Configure the entire port.
 
   This function configures the entire port, which controls the
   direction of specific bits of the port. It writes the entire port
   mask to the port control register.
 
   @see vpioGpioTrisType
   @param port Memory-mapped I/O port.
   @param mask The entire port config mask.
 */
 
inline
void vpioGpioCfgPort(vpioGpioRegs* port, int mask)
{
  port->regCtrl = mask;
}
 
/*!
   Put data on the port.
 
   This function writes onto the entire data line of the GPIO port. It
   writes the value directly to the port register.
 
   @param port Memory-mapped I/O port.
   @param data The data to write to the port.
 */
 
inline
void vpioGpioPutPort(vpioGpioRegs* port, int data)
{
  port->regLine = data;
}
 
/*!
   Get data from the port.
 
   This function reads the entire data line of the GPIO port. It reads
   the value directly from the port register. Any output port values
   will appear on the input unless something is wrong.   
 
   @param port Memory-mapped I/O port.
   @return The contents of the entire port.
 */
 
inline
int vpioGpioGetPort(vpioGpioRegs* port)
{
  return port->regLine;
}
 
/*!
   Clear the entire port.
 
   This function clears the data pins of the entire GPIO port to 0. It
   writes the value directly to the port register.
 
   @param port Memory-mapped I/O port.
 */
 
inline
void vpioGpioClrPort(vpioGpioRegs* port)
{
  vpioGpioPutPort(port, 0);
}
 
/*!
   Initialise the GPIO port.
 
   This function configures the entire GPIO port as inputs and clears
   the whole port data register. This will restore the port to its
   reset condition.
 
   @param port Memory-mapped I/O port.
 */
 
inline
void vpioGpioIniPort(vpioGpioRegs* port)
{
  vpioGpioCfgPort(port, 0);
  vpioGpioClrPort(port);
}
 
#endif
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.