Blame view

app/app-prime-modbus/include/common/tgpio.h 11.1 KB
8c2952457   김태훈   응용 프로그램 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  /**    
      @file     tgpio.h
      @date     2010/1/4
      @author   오재경 freefrug@falinux.com  FALinux.Co.,Ltd.
      @brief    gpio 를 드라이버없이 mmap를 이용하여 제어한다.
                Ver 0.6.0
               
                
      @modify   
      @todo     
      @bug     
      @remark   
      @warning 
  */
  //----------------------------------------------------------------------------
  
  
  #ifndef _TGPIO_HEADER_
  #define _TGPIO_HEADER_
  
  #define  MCU_AM3874        3874
  #define  MCU_S5PV210       210
  #define  MCU_S3C6410       6410
  #define  MCU_S3C2440       2440
  #define  MCU_PXA270        270
  #define  MCU_PXA255        255
  #define  MCU_IXP420        420
  #define  MCU_IXP430        430
  #define  MCU_IXP435        435
  #define  MCU_iMX6	       1006
  #define  MCU_iMX6_STR     "imx6"
  
  
  #define  MCU_iMX6_GPIO_GRP_CNT         7
  #define  MCU_iMX6_GPIO1_PHYS           0x0209C000
  #define  MCU_iMX6_GPIO2_PHYS           0x020A0000
  #define  MCU_iMX6_GPIO3_PHYS           0x020A4000
  #define  MCU_iMX6_GPIO4_PHYS           0x020A8000
  #define  MCU_iMX6_GPIO5_PHYS           0x020AC000
  #define  MCU_iMX6_GPIO6_PHYS           0x020B0000
  #define  MCU_iMX6_GPIO7_PHYS           0x020B4000
  #define  MCU_iMX6_GPIO_PHYS_SIZE       0x1000
  
  #define  MCU_iMX6_GPIO_DAT_OFS         0x00
  #define  MCU_iMX6_GPIO_DIR_OFS         0x04
  #define  iMX6_GPIO_DATPORT(base)       *(volatile unsigned long *)( (int)(base) + MCU_iMX6_GPIO_DAT_OFS  )
  #define  iMX6_GPIO_DIRPORT(base)       *(volatile unsigned long *)( (int)(base) + MCU_iMX6_GPIO_DIR_OFS  )
  #define  MCU_iMX6_GPIO_DIR_INPUT       0
  #define  MCU_iMX6_GPIO_DIR_OUTPUT      1
  
  
  #define  MCU_AM3874_GPIO_GRP_CNT	   4
  #define  MCU_AM3874_GPIO0_PHYS		   0x48032000
  #define  MCU_AM3874_GPIO1_PHYS		   0x4804C000
  #define  MCU_AM3874_GPIO2_PHYS		   0x481AC000
  #define  MCU_AM3874_GPIO3_PHYS		   0x481AE000
  #define  MCU_AM3874_MMAP_GPIO_SIZE     0x1000
  
  #define  MCU_AM3874_GPIO_SYSCONF	   0x010
  #define  MCU_AM3874_GPIO_CON		   0x130
  #define  MCU_AM3874_GPIO_OE	           0x134
  #define  MCU_AM3874_GPIO_DATAIN        0x138
  #define  MCU_AM3874_GPIO_DATAOUT       0x13C
  #define  AM3874_GPIO_SYSCONF(base)     *(volatile unsigned long *)( (int)(base) + MCU_AM3874_GPIO_SYSCONF )
  #define  AM3874_GPIO_CTRL(base)        *(volatile unsigned long *)( (int)(base) + MCU_AM3874_GPIO_CON     )
  #define  AM3874_GPIO_OE(base)          *(volatile unsigned long *)( (int)(base) + MCU_AM3874_GPIO_OE      )
  #define  AM3874_GPIO_DATAIN(base)      *(volatile unsigned long *)( (int)(base) + MCU_AM3874_GPIO_DATAIN  )
  #define  AM3874_GPIO_DATAOUT(base)     *(volatile unsigned long *)( (int)(base) + MCU_AM3874_GPIO_DATAOUT )
  
  #define  MCU_AM3874_PIN_MUX_PHYS	   0x48140800
  #define  MCU_AM3874_PIN_MUX_SIZE	   0x8000
  #define  MCU_AM3874_PIN_MUX_GPIO       (0x80)
  #define  MCU_AM3874_PIN_MUX_IDIS       (0 << 18)
  #define  MCU_AM3874_PIN_MUX_IEN        (1 << 18)
  #define  MCU_AM3874_PIN_MUX_IPD        (0 << 16)
  #define  MCU_AM3874_PIN_MUX_IPU        (2 << 16)
  #define  MCU_AM3874_PIN_MUX_IPDIS      (1 << 16)
  #define  AM3874_PIN_CTRL(base,pin)     *(volatile unsigned long *)( (int)(base) + (pin-1)*4 )
  
  #define  MCU_S5PV210_MMAP_GPIO_PHYS    0xe0200000
  #define  MCU_S5PV210_MMAP_GPIO_SIZE    0x1000
  
  #define  MCU_S3C6410_MMAP_GPIO_PHYS    0x7f008000
  #define  MCU_S3C6410_MMAP_GPIO_SIZE    0x1000
  
  #define  MCU_S3C2440_MMAP_GPIO_PHYS    0x56000000
  #define  MCU_S3C2440_MMAP_GPIO_SIZE    0x100
  
  #define  MCU_PXA270_MMAP_GPIO_PHYS     0x40E00000
  #define  MCU_PXA270_MMAP_GPIO_SIZE     0x200
  
  #define  MCU_PXA255_MMAP_GPIO_PHYS     0x40E00000
  #define  MCU_PXA255_MMAP_GPIO_SIZE     0x200
  
  #define  MCU_IXP4XX_MMAP_GPIO_PHYS	   0xC8004000
  #define  MCU_IXP4XX_MMAP_GPIO_SIZE	   0x10
  
  
  /// PXA 관련 레지스터 
  #define  PXA_GPIO_bit(x)         (1 << ((x) & 0x1f))
  #define  PXA_REG_OFFSET(x)       ( ((x) < 96) ? ((x)/32)*4 : 0x100  )
  
  #define  PXA_GPIO_INOUT(nr)     *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + GAFR0_L + PXA_REG_OFFSET(nr*2) ) &= ~(3<<(((nr)&0xf)*2))
  #define  PXA_DIR_OUT(nr)        *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + GPDR0   + PXA_REG_OFFSET(nr)   ) |=  PXA_GPIO_bit(nr)
  #define  PXA_DIR_IN(nr)         *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + GPDR0   + PXA_REG_OFFSET(nr)   ) &= ~PXA_GPIO_bit(nr)
  #define  PXA_OUT_CLR(nr)        *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + GPCR0   + PXA_REG_OFFSET(nr)   )  =  PXA_GPIO_bit(nr)
  #define  PXA_OUT_SET(nr)        *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + GPSR0   + PXA_REG_OFFSET(nr)   )  =  PXA_GPIO_bit(nr)
  #define  PXA_IN_DAT(nr)       ( *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + GPLR0   + PXA_REG_OFFSET(nr)   ) & PXA_GPIO_bit(nr) )
  
  
  #define  GPLR0     0x000     // GPIO Pin-Level Register GPIO<31:0> 
  #define  GPLR1     0x004     // GPIO Pin-Level Register GPIO<63:32> 
  #define  GPLR2     0x008     // GPIO Pin-Level Register GPIO<80:64> 
                               // 
  #define  GPDR0     0x00C     // GPIO Pin Direction Register GPIO<31:0> 
  #define  GPDR1     0x010     // GPIO Pin Direction Register GPIO<63:32> 
  #define  GPDR2     0x014     // GPIO Pin Direction Register GPIO<80:64> 
                               // 
  #define  GPSR0     0x018     // GPIO Pin Output Set Register GPIO<31:0> 
  #define  GPSR1     0x01C     // GPIO Pin Output Set Register GPIO<63:32> 
  #define  GPSR2     0x020     // GPIO Pin Output Set Register GPIO<80:64> 
                               // 
  #define  GPCR0     0x024     // GPIO Pin Output Clear Register GPIO<31:0> 
  #define  GPCR1     0x028     // GPIO Pin Output Clear Register GPIO <63:32> 
  #define  GPCR2     0x02C     // GPIO Pin Output Clear Register GPIO <80:64> 
                               // 
  #define  GRER0     0x030     // GPIO Rising-Edge Detect Register GPIO<31:0> 
  #define  GRER1     0x034     // GPIO Rising-Edge Detect Register GPIO<63:32> 
  #define  GRER2     0x038     // GPIO Rising-Edge Detect Register GPIO<80:64> 
                               // 
  #define  GFER0     0x03C     // GPIO Falling-Edge Detect Register GPIO<31:0> 
  #define  GFER1     0x040     // GPIO Falling-Edge Detect Register GPIO<63:32>
  #define  GFER2     0x044     // GPIO Falling-Edge Detect Register GPIO<80:64>
                               // 
  #define  GEDR0     0x048     // GPIO Edge Detect Status Register GPIO<31:0>
  #define  GEDR1     0x04C     // GPIO Edge Detect Status Register GPIO<63:32>
  #define  GEDR2     0x050     // GPIO Edge Detect Status Register GPIO<80:64> 
                               // 
  #define  GAFR0_L   0x054     // GPIO Alternate Function Select Register GPIO<15:0> 
  #define  GAFR0_U   0x058     // GPIO Alternate Function Select Register GPIO<31:16> 
  #define  GAFR1_L   0x05C     // GPIO Alternate Function Select Register GPIO<47:32> 
  #define  GAFR1_U   0x060     // GPIO Alternate Function Select Register GPIO<63:48> 
  #define  GAFR2_L   0x064     // GPIO Alternate Function Select Register GPIO<79:64> 
  #define  GAFR2_U   0x068     // GPIO Alternate Function Select Register GPIO<95-80> 
  #define  GAFR3_L   0x06C     // GPIO Alternate Function Select Register GPIO<111:96> 
  #define  GAFR3_U   0x070     // GPIO Alternate Function Select Register GPIO<127:112>
                               // 
  #define  GPLR3     0x100     // GPIO Pin-Level Register GPIO<127:96> 
  #define  GPDR3     0x10C     // GPIO Pin Direction Register GPIO<127:96> 
  #define  GPSR3     0x118     // GPIO Pin Output Set Register GPIO<127:96>
  #define  GPCR3     0x124     // GPIO Pin Output Clear Register GPIO<127:96> 
  #define  GRER3     0x130     // GPIO Rising-Edge Detect Register GPIO<127:96> 
  #define  GFER3     0x13C     // GPIO Falling-Edge Detect Register GPIO<127:96>
  #define  GEDR3     0x148     // GPIO Edge Detect Status Register GPIO<127:96> 
  
  /// IXP 관련 레지스터 
  #define IXP4XX_GPIO_GPOUTR		*(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + IXP4XX_GPIO_GPOUTR_OFFSET )
  #define IXP4XX_GPIO_GPOER       *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + IXP4XX_GPIO_GPOER_OFFSET  )
  #define IXP4XX_GPIO_GPINR       *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + IXP4XX_GPIO_GPINR_OFFSET  )
  #define IXP4XX_GPIO_GPISR       *(volatile unsigned long *)( (int)(mcu_gpio.mmap_base) + IXP4XX_GPIO_GPISR_OFFSET  )
  
  #define IXP4XX_GPIO_GPOUTR_OFFSET    0x00
  #define IXP4XX_GPIO_GPOER_OFFSET     0x04
  #define IXP4XX_GPIO_GPINR_OFFSET     0x08
  #define IXP4XX_GPIO_GPISR_OFFSET     0x0C
  
  
  
  //======================================================================================================================
  
  /// tgpio_dir_input() 함수 사용시  pull_up 옵션
  typedef enum {	
  	GPIO_PULL_NONE = 0,
  	GPIO_PULL_UP,
  	GPIO_PULL_DN
  } gpio_pulled_t;
  
  
  /// GPIO 그룹이 GRP0, GRP1 등으로 나뉠때  번호로써 구분한다.
  #define GP_NR_GRP		1000
  
  #include <famap.h>
  
  /// gpio 관련 내부관리 구조체
  typedef struct {
  
  	int   mcu_nr;
  	char  grp_begin;
  	char  grp_end;
  	unsigned long  phys_base;
  	unsigned long  phys_size;
  
  	mmap_alloc_t   map_info;		// 0.7.0 부터 추가
  	unsigned long  mmap_base;
  	
  	void  (*close     )( void );
  	void  (*dir_input )( char grp, int gp_nr, gpio_pulled_t pull_up );
  	void  (*dir_output)( char grp, int gp_nr, int gp_val  );
  	int   (*input     )( char grp, int gp_nr );
  	void  (*output    )( char grp, int gp_nr, int gp_val  );
  
  	unsigned long  (*get_input_port  )( char grp, int gp_nr );
  	unsigned long  (*get_output_port )( char grp, int gp_nr );
  
  	void  *private;
  
  } mcu_gpio_fops_t;
  
  /// gpio 관련 iMX 레지스터 구조체
  typedef struct 
  {
  	unsigned long  phys;
  	mmap_alloc_t   map_gpio;
  	unsigned long  mmap_base;
  
  } imx6_gpio_register_t;
  
  
  /// gpio 관련 AM3xxx 레지스터 구조체
  typedef struct {
  
  	unsigned long  phys;
  	mmap_alloc_t   map_gpio;
  	unsigned long  mmap_base;
  	unsigned short pin_ctrl[32];	// 1 ~ n
  
  } am3x_gpio_register_t;
  
  /// gpio 관련 s3c 레지스터 구조체
  typedef struct {
  
  	int            gpcnt;
  	int            con_mask_bitcnt;
  	unsigned long  ofs_con;
  	unsigned long  ofs_dat;
  	unsigned long  ofs_pup;
  
  } s3c_gpio_register_t;
  
  
  /// gpio 관련 pxa 정보 구조체
  typedef struct {
  
  	int            gpcnt;
  
  } pxa_gpio_info_t;
  
  
  /// gpio 번호 구조체
  typedef struct {
  
  	char            grp;
  	unsigned short  nr;
  
  } gpio_number_t;
  
  #endif //
  
  
  #ifdef __cplusplus 
  extern "C" { 
  #endif 	
  
  /// @{
  /// @brief   tgpio.h 에서 제공하는 함수 리스트 
  
  extern int   tgpio_open      ( int mcu ); /// mcu 를 선택한 후 mmap 메모리를 맵핑한다.
  extern void  tgpio_close     ( void    ); /// gpio 맵핑을 해제한다.
  extern void  tgpio_dir_input ( char grp, int gp_nr, gpio_pulled_t pull_up ); /// gpio 를 입력으로 설정한다.
  extern void  tgpio_dir_output( char grp, int gp_nr, int gp_val  ); /// gpio 를 출력으로 설정한다.
  extern int   tgpio_input     ( char grp, int gp_nr              ); /// gpio 의 입력값을 읽는다.
  extern void  tgpio_output    ( char grp, int gp_nr, int gp_val  ); /// gpio 에 값을 쓴다
  
  extern unsigned long tgpio_get_input_port ( char grp, int gp_nr ); /// gpio 의 입력 포트 포인터를 얻는다.
  extern unsigned long tgpio_get_output_port( char grp, int gp_nr ); /// gpio 의 출력 포트 포인터를 얻는다.
  
  /// @}
  
  #ifdef __cplusplus 
  }
  #endif