00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00036
00037
00038
00039 #ifndef GPIO_H
00040 #define GPIO_H
00041
00042 #include "TIMotorLIB.h"
00043 #include GENERATE_FLEX_INC(Device.h)
00044
00045 #define QUAL_OFFSET 0x1
00046 #define MUX_OFFSET 0x3
00047 #define DIR_OFFSET 0x5
00048 #define PUD_OFFSET 0x6
00049 #define DAT_OFFSET 0x0
00050 #define SET_OFFSET 0x1
00051 #define CLEAR_OFFSET 0x2
00052 #define TOGGLE_OFFSET 0x3
00053
00054 #define GPIO_BIT_2_NAME(bit) GPIO ## bit
00055 #define GPIO_PORT_BIT_2_NAME(port, bit) GPIO ## bit + (port<<3)
00056
00057 #define GET_MUX_BIT(bit) (bit < 16 ? bit : (bit-16))
00058
00065 #define _GPIO0 GPIOA, 0
00066 #define _GPIO1 GPIOA, 1
00067 #define _GPIO2 GPIOA, 2
00068 #define _GPIO3 GPIOA, 3
00069 #define _GPIO4 GPIOA, 4
00070 #define _GPIO5 GPIOA, 5
00071 #define _GPIO6 GPIOA, 6
00072 #define _GPIO7 GPIOA, 7
00073 #define _GPIO8 GPIOA, 8
00074 #define _GPIO9 GPIOA, 9
00075 #define _GPIO10 GPIOA, 10
00076 #define _GPIO11 GPIOA, 11
00077 #define _GPIO12 GPIOA, 12
00078 #define _GPIO13 GPIOA, 13
00079 #define _GPIO14 GPIOA, 14
00080 #define _GPIO15 GPIOA, 15
00081 #define _GPIO16 GPIOA, 16
00082 #define _GPIO17 GPIOA, 17
00083 #define _GPIO18 GPIOA, 18
00084 #define _GPIO19 GPIOA, 19
00085 #define _GPIO20 GPIOA, 20
00086 #define _GPIO21 GPIOA, 21
00087 #define _GPIO22 GPIOA, 22
00088 #define _GPIO23 GPIOA, 23
00089 #define _GPIO24 GPIOA, 24
00090 #define _GPIO25 GPIOA, 25
00091 #define _GPIO26 GPIOA, 26
00092 #define _GPIO27 GPIOA, 27
00093 #define _GPIO28 GPIOA, 28
00094 #define _GPIO29 GPIOA, 29
00095 #define _GPIO30 GPIOA, 30
00096 #define _GPIO31 GPIOA, 31
00097
00098 #define _GPIO32 GPIOB, 0
00099 #define _GPIO33 GPIOB, 1
00100 #define _GPIO34 GPIOB, 2
00101 #define _GPIO35 GPIOB, 3
00102 #define _GPIO36 GPIOB, 4
00103 #define _GPIO37 GPIOB, 5
00104 #define _GPIO38 GPIOB, 6
00105 #define _GPIO39 GPIOB, 7
00106 #define _GPIO40 GPIOB, 8
00107 #define _GPIO41 GPIOB, 9
00108 #define _GPIO42 GPIOB, 10
00109 #define _GPIO43 GPIOB, 11
00110 #define _GPIO44 GPIOB, 12
00111 #define _GPIO45 GPIOB, 13
00112 #define _GPIO46 GPIOB, 14
00113 #define _GPIO47 GPIOB, 15
00114 #define _GPIO48 GPIOB, 16
00115 #define _GPIO49 GPIOB, 17
00116 #define _GPIO50 GPIOB, 18
00117 #define _GPIO51 GPIOB, 19
00118 #define _GPIO52 GPIOB, 20
00119 #define _GPIO53 GPIOB, 21
00120 #define _GPIO54 GPIOB, 22
00121 #define _GPIO55 GPIOB, 23
00122 #define _GPIO56 GPIOB, 24
00123 #define _GPIO57 GPIOB, 25
00124 #define _GPIO58 GPIOB, 26
00125 #define _GPIO59 GPIOB, 27
00126 #define _GPIO60 GPIOB, 28
00127 #define _GPIO61 GPIOB, 29
00128 #define _GPIO62 GPIOB, 30
00129 #define _GPIO63 GPIOB, 31
00130
00131 #define _GPIO64 GPIOC, 0
00132 #define _GPIO65 GPIOC, 1
00133 #define _GPIO66 GPIOC, 2
00134 #define _GPIO67 GPIOC, 3
00135 #define _GPIO68 GPIOC, 4
00136 #define _GPIO69 GPIOC, 5
00137 #define _GPIO70 GPIOC, 6
00138 #define _GPIO71 GPIOC, 7
00139 #define _GPIO72 GPIOC, 8
00140 #define _GPIO73 GPIOC, 9
00141 #define _GPIO74 GPIOC, 10
00142 #define _GPIO75 GPIOC, 11
00143 #define _GPIO76 GPIOC, 12
00144 #define _GPIO77 GPIOC, 13
00145 #define _GPIO78 GPIOC, 14
00146 #define _GPIO79 GPIOC, 15
00147 #define _GPIO80 GPIOC, 16
00148 #define _GPIO81 GPIOC, 17
00149 #define _GPIO82 GPIOC, 18
00150 #define _GPIO83 GPIOC, 19
00151 #define _GPIO84 GPIOC, 20
00152 #define _GPIO85 GPIOC, 21
00153 #define _GPIO86 GPIOC, 22
00154 #define _GPIO87 GPIOC, 23
00155
00157 #define GPIO_LOW (Uint32)0
00158 #define GPIO_HIGH (Uint32)1
00159
00160
00161
00162
00163
00165 typedef enum {
00166 GPIOA=0,
00167 GPIOB=0x4,
00168 GPIOC=0x8
00169 } GPIO_PORT;
00170
00172 typedef enum {
00173 GPIO_INPUT,
00174 GPIO_OUTPUT
00175 } GPIO_DIR;
00176
00178 typedef enum {
00179 GPIO_PULL_EN,
00180 GPIO_PULL_DIS
00181 } GPIO_PUD;
00182
00184 typedef enum {
00185 GPIO,
00186 PERPH_1,
00187 PERPH_2,
00188 PERPH_3
00189 } GPIO_PERPH;
00190
00191
00192
00193
00194 static inline void ConfigureGPIOPort(GPIO_PORT port, Uint16 bit, GPIO_DIR dir,
00195 GPIO_PERPH perPh, GPIO_PUD pud, Uint32 val);
00196 static inline void WriteGPIOPort(GPIO_PORT port, Uint16 bit, Uint32 val);
00197 static inline void ToggleGPIOPort(GPIO_PORT port, Uint16 bit);
00198 static inline void SetGPIOPort(GPIO_PORT port, Uint16 bit);
00199 static inline void ClearGPIOPort(GPIO_PORT port, Uint16 bit);
00200 static inline unsigned ReadGPIOPort(GPIO_PORT port, Uint16 bit);
00201
00202
00203
00204
00205
00206
00207
00208
00211
00229
00230
00231
00232
00233
00234
00235
00236
00237 static inline void ConfigureGPIOPort(GPIO_PORT port, Uint16 bit, GPIO_DIR dir,
00238 GPIO_PERPH perPh, GPIO_PUD pud, Uint32 val)
00239 {
00240 volatile Uint32* gpioPtr = 0;
00241 volatile Uint32* gpioDat = 0;
00242 EALLOW;
00243 gpioPtr = &GpioCtrlRegs.GPACTRL.all + (Uint16)(port<<1);
00244 gpioDat = &GpioDataRegs.GPADAT.all + port;
00245 *(gpioPtr + PUD_OFFSET) |= (Uint32)pud << bit;
00246 if (dir == GPIO_OUTPUT)
00247 *(gpioDat + SET_OFFSET) |= val << bit;
00248 *(gpioPtr + MUX_OFFSET + (Uint16)(bit>>4) ) |= (Uint32)perPh << (GET_MUX_BIT(bit) << 1);
00249 *(gpioPtr + DIR_OFFSET) |= (Uint32)dir << bit;
00250 EDIS;
00251 }
00252
00253
00254
00255
00260
00261 static inline void WriteGPIOPort(GPIO_PORT port, Uint16 bit, Uint32 val)
00262 {
00263 volatile Uint32* gpioDat = &GpioDataRegs.GPADAT.all + port;
00264 *(gpioDat + DAT_OFFSET) |= val << bit;
00265 }
00266
00267
00268
00269
00273
00274 static inline void ToggleGPIOPort(GPIO_PORT port, Uint16 bit)
00275 {
00276 volatile Uint32* gpioDat = &GpioDataRegs.GPADAT.all + port;
00277 *(gpioDat + TOGGLE_OFFSET) |= (Uint32)1 << bit;
00278
00279 }
00280
00281
00282
00283
00287
00288 static inline void SetGPIOPort(GPIO_PORT port, Uint16 bit)
00289 {
00290 volatile Uint32* gpioDat = &GpioDataRegs.GPADAT.all + port;
00291 *(gpioDat + SET_OFFSET) |= (Uint32)1 << bit;
00292
00293 }
00294
00295
00296
00297
00301
00302 static inline void ClearGPIOPort(GPIO_PORT port, Uint16 bit)
00303 {
00304 volatile Uint32* gpioDat = &GpioDataRegs.GPADAT.all + port;
00305 *(gpioDat + CLEAR_OFFSET) |= (Uint32)1 << bit;
00306 }
00307
00308
00309
00310
00315
00316 static inline unsigned ReadGPIOPort(GPIO_PORT port, Uint16 bit)
00317 {
00318 volatile Uint32* gpioDat = &GpioDataRegs.GPADAT.all + port;
00319 return *(gpioDat + DAT_OFFSET) & ((Uint32)1 << bit);
00320 }
00321
00322
00323
00324
00325
00326
00327 #endif
00328
00329
00330
00331