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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [vpio/] [vpioGpio.h] - Diff between revs 196 and 197

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 196 Rev 197
Line 25... Line 25...
*/
*/
 
 
#ifndef VPIO_GPIO_H
#ifndef VPIO_GPIO_H
#define VPIO_GPIO_H
#define VPIO_GPIO_H
 
 
 
typedef char gpioData;
 
 
/*!
/*!
   GPIO Directions.
   GPIO Directions.
*/
*/
 
 
enum vpioGpioTrisType
enum gpioTrisType
  {
  {
    GPIO_INPUT  = 0, ///< Define GPIO pin as an input
    GPIO_INPUT  = 0, ///< Define GPIO pin as an input
    GPIO_OUTPUT = 1 ///< Define GPIO pin as an output
    GPIO_OUTPUT = 1 ///< Define GPIO pin as an output
  };
  };
 
 
 
typedef enum gpioTrisType gpioTrisType;
 
 
/*!
/*!
   GPIO Register Map.
   GPIO Register Map.
   This structure contains the register file of a general-purpose
   This structure contains the register file of a general-purpose
   I/O. Care should be taken when using it due to endian issues.
   I/O. Care should be taken when using it due to endian issues.
*/
*/
 
 
struct vpioGpioRegs
struct gpioRegs
{
{
  volatile int regCtrl; ///< GPIO direction register.
  volatile gpioData regCtrl; ///< GPIO direction register.
  //unsigned int /* unused */ :24;    
  unsigned int /* unused */ :24;
  volatile int regLine; ///< GPIO line data register.
  volatile gpioData regLine; ///< GPIO line data register.
  //unsigned int /* unused */ :24;    
  unsigned int /* unused */ :24;
};
};
 
 
typedef struct vpioGpioRegs vpioGpioRegs;
typedef struct gpioRegs gpioRegs;
 
 
 
// ==== GPIO INTERFACE ====
 
 
 
gpioData gpioGetBit(gpioRegs* port, gpioData bit);
 
void gpioSetBit(gpioRegs* port, gpioData bit);
 
void gpioTogBit(gpioRegs* port, gpioData bit);
 
void gpioClrBit(gpioRegs* port, gpioData bit);
 
 
 
//void gpioPutTris(gpioRegs* port, gpioData mask);
 
void gpioSetTris(gpioRegs* port, gpioData mask);
 
void gpioPutData(gpioRegs* port, gpioData data);
 
//gpioData gpioGetTris(gpioRegs* port);
 
gpioData gpioGetData(gpioRegs* port);
 
 
 
void gpioInit(gpioRegs* port);
 
 
 
 
/*!
/*!
   Get a port bit.
   Get a port bit.
 
 
   This function reads the value of a specific bit on a GPIO port. It
   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
   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.
   result should be gpioDataerpreted as zero for 0 and non-zero for 1.
 
 
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @param bit Get port bit value.
   @param bit Get port bit value.
   @return Value of the port bit.
   @return Value of the port bit.
*/
*/
 
 
inline
inline
int  vpioGpioGetBit(vpioGpioRegs* port, int bit)
gpioData  gpioGetBit(gpioRegs* port, gpioData bit)
{
{
  return port->regLine & (1 << bit);
  return port->regLine & (1 << bit);
}
}
 
 
/*!
/*!
Line 81... Line 101...
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @param bit Set port bit to 1.
   @param bit Set port bit to 1.
*/
*/
 
 
inline
inline
void vpioGpioSetBit(vpioGpioRegs* port, int bit)
void gpioSetBit(gpioRegs* port, gpioData bit)
{
{
  port->regLine |= (1 << bit);
  port->regLine |= (1 << bit);
}
}
 
 
/*!
/*!
Line 98... Line 118...
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @param bit Toggle port bit between 0 and 1.
   @param bit Toggle port bit between 0 and 1.
*/
*/
 
 
inline
inline
void vpioGpioTogBit(vpioGpioRegs* port, int bit)
void gpioTogBit(gpioRegs* port, gpioData bit)
{
{
  port->regLine ^= (1 << bit);
  port->regLine ^= (1 << bit);
}
}
 
 
/*!
/*!
Line 115... Line 135...
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @param bit Clear port bit to 0.
   @param bit Clear port bit to 0.
 */
 */
 
 
inline
inline
void vpioGpioClrBit(vpioGpioRegs* port, int bit)
void gpioClrBit(gpioRegs* port, gpioData bit)
{
{
  port->regLine &= ~(1 << bit);
  port->regLine &= ~(1 << bit);
}
}
 
 
/*!
/*!
Line 127... Line 147...
 
 
   This function configures the entire port, which controls the
   This function configures the entire port, which controls the
   direction of specific bits of the port. It writes the entire port
   direction of specific bits of the port. It writes the entire port
   mask to the port control register.
   mask to the port control register.
 
 
   @see vpioGpioTrisType
   @see gpioTrisType
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @param mask The entire port config mask.
   @param mask The entire port config mask.
 */
 */
 
 
inline
inline
void vpioGpioCfgPort(vpioGpioRegs* port, int mask)
void gpioSetTris(gpioRegs* port, gpioData mask)
{
{
  port->regCtrl = mask;
  port->regCtrl = mask;
}
}
 
 
 
 
 
/*!
 
   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 gpioTrisType
 
   @param port Memory-mapped I/O port.
 
   @param mask The entire port config mask.
 
 */
 
 
 
inline
 
gpioData gpioGetTris(gpioRegs* port)
 
{
 
  //port->regCtrl = mask;
 
  return port->regCtrl;
 
}
 
 
/*!
/*!
   Put data on the port.
   Put data on the port.
 
 
   This function writes onto the entire data line of the GPIO port. It
   This function writes onto the entire data line of the GPIO port. It
   writes the value directly to the port register.
   writes the value directly to the port register.
Line 149... Line 189...
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @param data The data to write to the port.
   @param data The data to write to the port.
 */
 */
 
 
inline
inline
void vpioGpioPutPort(vpioGpioRegs* port, int data)
void gpioPutData(gpioRegs* port, gpioData data)
{
{
  port->regLine = data;
  port->regLine = data;
}
}
 
 
/*!
/*!
Line 166... Line 206...
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
   @return The contents of the entire port.
   @return The contents of the entire port.
 */
 */
 
 
inline
inline
int vpioGpioGetPort(vpioGpioRegs* port)
gpioData gpioGetData(gpioRegs* port)
{
{
  return port->regLine;
  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.
   Initialise the GPIO port.
 
 
   This function configures the entire GPIO port as inputs and clears
   This function configures the entire GPIO port as inputs and clears
   the whole port data register. This will restore the port to its
   the whole port data register. This will restore the port to its
   reset condition.
   reset condition.
 
 
   @param port Memory-mapped I/O port.
   @param port Memory-mapped I/O port.
 */
 */
 
 
inline
inline
void vpioGpioIniPort(vpioGpioRegs* port)
void gpioInit(gpioRegs* port)
{
{
  vpioGpioCfgPort(port, 0);
  gpioSetTris(port, 0);
  vpioGpioClrPort(port);
  gpioPutData(port, 0);
}
}
 
 
#endif
#endif
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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