Fri, 13 Aug 2010 10:41:29 +0100
Initial commit, GPIO v3.1
1 /****************************************************************************
2 **
3 ** Name: MicoGPIO.h
4 **
5 ** Description:
6 ** Declares GPIO register structure and
7 ** macros/functions for manipulating GPIO
8 **
9 ** $Revision: $
10 **
11 ** Disclaimer:
12 **
13 ** This source code is intended as a design reference which
14 ** illustrates how these types of functions can be implemented. It
15 ** is the user's responsibility to verify their design for
16 ** consistency and functionality through the use of formal
17 ** verification methods. Lattice Semiconductor provides no warranty
18 ** regarding the use or functionality of this code.
19 **
20 ** --------------------------------------------------------------------
21 **
22 ** Lattice Semiconductor Corporation
23 ** 5555 NE Moore Court
24 ** Hillsboro, OR 97214
25 ** U.S.A
26 **
27 ** TEL: 1-800-Lattice (USA and Canada)
28 ** (503)268-8001 (other locations)
29 **
30 ** web: http://www.latticesemi.com
31 ** email: techsupport@latticesemi.com
32 **
33 ** --------------------------------------------------------------------------
34 **
35 ** Change History (Latest changes on top)
36 **
37 ** Ver Date Description
38 ** --------------------------------------------------------------------------
39 **
40 ** 3.1 Oct-23-2008 Updated macros to provide for
41 ** reading of the interrupt-mask register
42 ** and writing to the edge-capture register
43 ** Updated comments in the GPIO register
44 ** structure definition
45 ** 3.0 Mar-25-2008 Added Header
46 **
47 **
48 **---------------------------------------------------------------------------
49 *****************************************************************************/
51 #ifndef MICO32_MICOGPIO_HEADER_FILE
52 #define MICO32_MICOGPIO_HEADER_FILE
54 #include "MicoTypes.h"
55 #include "DDStructs.h"
57 /****************************************************************************
58 * Mico-GPIO driver does not provide any specific user-routine other than *
59 * linking it to GPIO services for lookup capability. *
60 *--------------------------------------------------------------------------*
61 * Mico GPIOs must be located in a non-cached region to use this driver *
62 ****************************************************************************/
65 #ifdef __cplusplus
66 extern "C"
67 {
68 #endif /* __cplusplus */
70 /*
71 *****************************************
72 *****************************************
73 GPIO REGISTER MAPPING
74 *****************************************
75 *****************************************
76 */
77 typedef struct st_MicoGPIO_t{
78 volatile unsigned int data; /* R/W:
79 R for in-only GPIO,
80 W for out-only GPIO,
81 R/W for tristates */
82 volatile unsigned int tristate; /* R/W:
83 tristate enable reg for
84 tristate GPIOs */
85 volatile unsigned int irqMask; /* R/W:
86 irq mask for interrupt-
87 enabled GPIOs */
88 volatile unsigned int edgeCapture; /* R/W:
89 applicable to GPIOs with
90 edge-capture ability */
91 }MicoGPIO_t;
95 /*
96 ********************************************
97 ********************************************
98 MACROS FOR ACCESSING GPIO REGISTERS
99 ********************************************
100 NOTE: FOR THE MACROS, THE FOLLOWING RULES
101 APPLY:
102 X is pointer to a valid MicoGPIOCtx_t structure
103 Y is unsigned int variable
104 */
107 /* reads data register */
108 #define MICO_GPIO_READ_DATA(X,Y) \
109 (Y)=((volatile MicoGPIO_t *)((X)->base))->data
112 /* writes data-register */
113 #define MICO_GPIO_WRITE_DATA(X,Y) \
114 ((volatile MicoGPIO_t *)((X)->base))->data=(Y)
117 /* reads tristate register */
118 #define MICO_GPIO_READ_TRISTATE(X,Y) \
119 (Y) = ((volatile MicoGPIO_t *)((X)->base))->tristate
122 /* writes tristate register */
123 #define MICO_GPIO_WRITE_TRISTATE(X,Y) \
124 ((volatile MicoGPIO_t *)((X)->base))->tristate = (Y)
127 /* reads irq-mask register */
128 #define MICO_GPIO_READ_IRQ_MASK(X,Y) \
129 (Y) = ((volatile MicoGPIO_t *)((X)->base))->irqMask
132 /* writes irq-mask register */
133 #define MICO_GPIO_WRITE_IRQ_MASK(X,Y) \
134 ((volatile MicoGPIO_t *)((X)->base))->irqMask = (Y)
137 /* reads edge-capture register */
138 #define MICO_GPIO_READ_EDGE_CAPTURE(X,Y) \
139 (Y) = ((volatile MicoGPIO_t *)((X)->base))->edgeCapture
142 /* writes edge-capture register */
143 #define MICO_GPIO_WRITE_EDGE_CAPTURE(X,Y) \
144 ((volatile MicoGPIO_t *)((X)->base))->edgeCapture = (Y)
147 /******************************************************************************
148 * functions *
149 ******************************************************************************/
151 /* initializes Mico32 GPIO peripheral */
152 void MicoGPIOInit( MicoGPIOCtx_t *ctx );
155 #ifdef __cplusplus
156 };
157 #endif /* __cplusplus */
160 #endif /*MICO32_MICOGPIO_HEADER_FILE */