URL
https://opencores.org/ocsvn/aemb/aemb/trunk
Subversion Repositories aemb
Compare Revisions
- This comparison shows the changes necessary to convert path
/aemb
- from Rev 195 to Rev 196
- ↔ Reverse comparison
Rev 195 → Rev 196
/trunk/sw/vpio/vpioGpio.h
0,0 → 1,208
/* $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 |
/trunk/sw/vpio/vpioGpio.hh
0,0 → 1,72
/* $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. |
@file vpioGpio.hh |
|
This file provides a C++ wrapper class to the low-level C interface. |
*/ |
|
#ifndef VPIO_GPIO_HH |
#define VPIO_GPIO_HH |
|
#ifdef __cplusplus |
extern "C" { |
#endif |
#include "vpioGpio.h" |
#ifdef __cplusplus |
} |
#endif |
|
/*! |
General-Purpose I/O Class. |
|
This is a C++ wrapper class around the low-level C code. |
*/ |
|
class vpioGpioClass : public vpioGpioRegs |
{ |
|
private: |
|
//vpioGpioClass(const vpioGpioClass&); |
//vpioGpioClass(); |
vpioGpioClass& operator=(const vpioGpioClass&); |
|
public: |
|
//void IniPort(int base_addr) { this = (vpioGpioRegs*)base_addr; } |
|
void SetBit(int bit) { vpioGpioSetBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioSetBit |
void ClrBit(int bit) { vpioGpioClrBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioClrBit |
void TogBit(int bit) { vpioGpioTogBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioTogBit |
int GetBit(int bit) { return vpioGpioGetBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioGetBit |
|
// Port Manipulation |
void CfgPort(int mask) { vpioGpioCfgPort( (vpioGpioRegs*)this, mask); } ///< @see vpioGpioCfgPort |
void PutPort(int data) { vpioGpioPutPort( (vpioGpioRegs*)this, data); } ///< @see vpioGpioPutPort |
void ClrPort() { vpioGpioClrPort( (vpioGpioRegs*)this ); } ///< @see vpioGpioClrPort |
int GetPort() { return vpioGpioGetPort( (vpioGpioRegs*)this ); } ///< @see vpioGpioGetPort |
|
}; |
|
#endif |