1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/drivers/device/MicoGPIO.h Fri Aug 13 10:41:29 2010 +0100 1.3 @@ -0,0 +1,161 @@ 1.4 +/**************************************************************************** 1.5 +** 1.6 +** Name: MicoGPIO.h 1.7 +** 1.8 +** Description: 1.9 +** Declares GPIO register structure and 1.10 +** macros/functions for manipulating GPIO 1.11 +** 1.12 +** $Revision: $ 1.13 +** 1.14 +** Disclaimer: 1.15 +** 1.16 +** This source code is intended as a design reference which 1.17 +** illustrates how these types of functions can be implemented. It 1.18 +** is the user's responsibility to verify their design for 1.19 +** consistency and functionality through the use of formal 1.20 +** verification methods. Lattice Semiconductor provides no warranty 1.21 +** regarding the use or functionality of this code. 1.22 +** 1.23 +** -------------------------------------------------------------------- 1.24 +** 1.25 +** Lattice Semiconductor Corporation 1.26 +** 5555 NE Moore Court 1.27 +** Hillsboro, OR 97214 1.28 +** U.S.A 1.29 +** 1.30 +** TEL: 1-800-Lattice (USA and Canada) 1.31 +** (503)268-8001 (other locations) 1.32 +** 1.33 +** web: http://www.latticesemi.com 1.34 +** email: techsupport@latticesemi.com 1.35 +** 1.36 +** -------------------------------------------------------------------------- 1.37 +** 1.38 +** Change History (Latest changes on top) 1.39 +** 1.40 +** Ver Date Description 1.41 +** -------------------------------------------------------------------------- 1.42 +** 1.43 +** 3.1 Oct-23-2008 Updated macros to provide for 1.44 +** reading of the interrupt-mask register 1.45 +** and writing to the edge-capture register 1.46 +** Updated comments in the GPIO register 1.47 +** structure definition 1.48 +** 3.0 Mar-25-2008 Added Header 1.49 +** 1.50 +** 1.51 +**--------------------------------------------------------------------------- 1.52 +*****************************************************************************/ 1.53 + 1.54 +#ifndef MICO32_MICOGPIO_HEADER_FILE 1.55 +#define MICO32_MICOGPIO_HEADER_FILE 1.56 + 1.57 +#include "MicoTypes.h" 1.58 +#include "DDStructs.h" 1.59 + 1.60 +/**************************************************************************** 1.61 + * Mico-GPIO driver does not provide any specific user-routine other than * 1.62 + * linking it to GPIO services for lookup capability. * 1.63 + *--------------------------------------------------------------------------* 1.64 + * Mico GPIOs must be located in a non-cached region to use this driver * 1.65 + ****************************************************************************/ 1.66 + 1.67 + 1.68 +#ifdef __cplusplus 1.69 +extern "C" 1.70 +{ 1.71 +#endif /* __cplusplus */ 1.72 + 1.73 + /* 1.74 + ***************************************** 1.75 + ***************************************** 1.76 + GPIO REGISTER MAPPING 1.77 + ***************************************** 1.78 + ***************************************** 1.79 + */ 1.80 + typedef struct st_MicoGPIO_t{ 1.81 + volatile unsigned int data; /* R/W: 1.82 + R for in-only GPIO, 1.83 + W for out-only GPIO, 1.84 + R/W for tristates */ 1.85 + volatile unsigned int tristate; /* R/W: 1.86 + tristate enable reg for 1.87 + tristate GPIOs */ 1.88 + volatile unsigned int irqMask; /* R/W: 1.89 + irq mask for interrupt- 1.90 + enabled GPIOs */ 1.91 + volatile unsigned int edgeCapture; /* R/W: 1.92 + applicable to GPIOs with 1.93 + edge-capture ability */ 1.94 + }MicoGPIO_t; 1.95 + 1.96 + 1.97 + 1.98 + /* 1.99 + ******************************************** 1.100 + ******************************************** 1.101 + MACROS FOR ACCESSING GPIO REGISTERS 1.102 + ******************************************** 1.103 + NOTE: FOR THE MACROS, THE FOLLOWING RULES 1.104 + APPLY: 1.105 + X is pointer to a valid MicoGPIOCtx_t structure 1.106 + Y is unsigned int variable 1.107 + */ 1.108 + 1.109 + 1.110 + /* reads data register */ 1.111 + #define MICO_GPIO_READ_DATA(X,Y) \ 1.112 + (Y)=((volatile MicoGPIO_t *)((X)->base))->data 1.113 + 1.114 + 1.115 + /* writes data-register */ 1.116 + #define MICO_GPIO_WRITE_DATA(X,Y) \ 1.117 + ((volatile MicoGPIO_t *)((X)->base))->data=(Y) 1.118 + 1.119 + 1.120 + /* reads tristate register */ 1.121 + #define MICO_GPIO_READ_TRISTATE(X,Y) \ 1.122 + (Y) = ((volatile MicoGPIO_t *)((X)->base))->tristate 1.123 + 1.124 + 1.125 + /* writes tristate register */ 1.126 + #define MICO_GPIO_WRITE_TRISTATE(X,Y) \ 1.127 + ((volatile MicoGPIO_t *)((X)->base))->tristate = (Y) 1.128 + 1.129 + 1.130 + /* reads irq-mask register */ 1.131 + #define MICO_GPIO_READ_IRQ_MASK(X,Y) \ 1.132 + (Y) = ((volatile MicoGPIO_t *)((X)->base))->irqMask 1.133 + 1.134 + 1.135 + /* writes irq-mask register */ 1.136 + #define MICO_GPIO_WRITE_IRQ_MASK(X,Y) \ 1.137 + ((volatile MicoGPIO_t *)((X)->base))->irqMask = (Y) 1.138 + 1.139 + 1.140 + /* reads edge-capture register */ 1.141 + #define MICO_GPIO_READ_EDGE_CAPTURE(X,Y) \ 1.142 + (Y) = ((volatile MicoGPIO_t *)((X)->base))->edgeCapture 1.143 + 1.144 + 1.145 + /* writes edge-capture register */ 1.146 + #define MICO_GPIO_WRITE_EDGE_CAPTURE(X,Y) \ 1.147 + ((volatile MicoGPIO_t *)((X)->base))->edgeCapture = (Y) 1.148 + 1.149 + 1.150 +/****************************************************************************** 1.151 + * functions * 1.152 + ******************************************************************************/ 1.153 + 1.154 +/* initializes Mico32 GPIO peripheral */ 1.155 +void MicoGPIOInit( MicoGPIOCtx_t *ctx ); 1.156 + 1.157 + 1.158 +#ifdef __cplusplus 1.159 +}; 1.160 +#endif /* __cplusplus */ 1.161 + 1.162 + 1.163 +#endif /*MICO32_MICOGPIO_HEADER_FILE */ 1.164 +