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