OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM9_STR91X_IAR/] [Library/] [source/] [91x_gpio.c] - Blame information for rev 577

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2
* File Name          : 91x_gpio.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 05/18/2006 : Version 1.0
5
* Description        : This file provides all the GPIO software functions.
6
********************************************************************************
7
* History:
8
* 05/24/2006 : Version 1.1
9
* 05/18/2006 : Version 1.0
10
********************************************************************************
11
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
13
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
14
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
15
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
16
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17
*******************************************************************************/
18
 
19
/* Includes ------------------------------------------------------------------*/
20
#include "91x_gpio.h"
21
#include "91x_scu.h"
22
 
23
/* Private typedef -----------------------------------------------------------*/
24
/* Private define ------------------------------------------------------------*/
25
 
26
/* Private macro -------------------------------------------------------------*/
27
/* Private variables ---------------------------------------------------------*/
28
/* Private function prototypes -----------------------------------------------*/
29
   static u8 GPIO_GetGPIONumber(GPIO_TypeDef* GPIOx);
30
 
31
/* Private functions ---------------------------------------------------------*/
32
 
33
/*******************************************************************************
34
* Function Name  : GPIO_DeInit
35
* Description    : Deinitializes the GPIOx peripheral registers to their default
36
*                  reset values.
37
* Input          : GPIOx: where x can be (0..9) to select the GPIO peripheral.
38
* Output         : None
39
* Return         : None
40
*******************************************************************************/
41
void GPIO_DeInit(GPIO_TypeDef* GPIOx)
42
{
43
 
44
  /* Reset the GPIO registers values */
45
  if(GPIOx == GPIO0)
46
  {
47
    SCU_APBPeriphReset(__GPIO0,ENABLE);
48
    SCU_APBPeriphReset(__GPIO0,DISABLE);
49
    SCU->GPIOTYPE[0x00] = 0x0000 ;
50
    SCU->GPIOOUT[0x00]  = 0x0000;
51
    SCU->GPIOIN[0x00]   = 0x0000;
52
  }
53
 
54
   if(GPIOx == GPIO1)
55
  {
56
    SCU_APBPeriphReset(__GPIO1,ENABLE);
57
    SCU_APBPeriphReset(__GPIO1,DISABLE);
58
    SCU->GPIOTYPE[0x01] = 0x0000 ;
59
    SCU->GPIOOUT[0x01]  = 0x0000;
60
    SCU->GPIOIN[0x01]   = 0x0000;
61
  }
62
 
63
   if(GPIOx == GPIO2)
64
  {
65
    SCU_APBPeriphReset(__GPIO2,ENABLE);
66
    SCU_APBPeriphReset(__GPIO2,DISABLE);
67
    SCU->GPIOTYPE[0x02] = 0x0000 ;
68
    SCU->GPIOOUT[0x02]  = 0x0000;
69
    SCU->GPIOIN[0x02]   = 0x0000;
70
  }
71
 
72
   if(GPIOx == GPIO3)
73
  {
74
    SCU_APBPeriphReset(__GPIO3,ENABLE);
75
    SCU_APBPeriphReset(__GPIO3,DISABLE);
76
    SCU->GPIOTYPE[0x03] = 0x0000 ;
77
    SCU->GPIOOUT[0x03]  = 0x0000;
78
    SCU->GPIOIN[0x03]   = 0x0000;
79
  }
80
 
81
   if(GPIOx == GPIO4)
82
  {
83
    SCU_APBPeriphReset(__GPIO4,ENABLE);
84
    SCU_APBPeriphReset(__GPIO4,DISABLE);
85
    SCU->GPIOTYPE[0x04] = 0x0000 ;
86
    SCU->GPIOOUT[0x04]  = 0x0000;
87
    SCU->GPIOIN[0x04]   = 0x0000;
88
    SCU->GPIOANA = 0x00;
89
  }
90
 
91
   if(GPIOx == GPIO5)
92
  {
93
    SCU_APBPeriphReset(__GPIO5,ENABLE);
94
    SCU_APBPeriphReset(__GPIO5,DISABLE);
95
    SCU->GPIOTYPE[0x05] = 0x0000 ;
96
    SCU->GPIOOUT[0x05]  = 0x0000;
97
    SCU->GPIOIN[0x05]   = 0x0000;
98
  }
99
 
100
   if(GPIOx == GPIO6)
101
  {
102
    SCU_APBPeriphReset(__GPIO6,ENABLE);
103
    SCU_APBPeriphReset(__GPIO6,DISABLE);
104
    SCU->GPIOTYPE[0x06] = 0x0000 ;
105
    SCU->GPIOOUT[0x06]  = 0x0000;
106
    SCU->GPIOIN[0x06]   = 0x0000;
107
  }
108
 
109
   if(GPIOx == GPIO7)
110
  {
111
    SCU_APBPeriphReset(__GPIO7,ENABLE);
112
    SCU_APBPeriphReset(__GPIO7,DISABLE);
113
    SCU->GPIOOUT[0x07]  = 0xAAAA;
114
    SCU->GPIOOUT[0x07]  = 0x0000;
115
    SCU->GPIOIN[0x07]   = 0x0000;
116
  }
117
 
118
   if(GPIOx == GPIO8)
119
  {
120
    SCU_APBPeriphReset(__GPIO8,ENABLE);
121
    SCU_APBPeriphReset(__GPIO8,DISABLE);
122
    SCU->GPIOEMI = 0x00;
123
  }
124
 
125
   if(GPIOx == GPIO9)
126
  {
127
    SCU_APBPeriphReset(__GPIO9,ENABLE);
128
    SCU_APBPeriphReset(__GPIO9,DISABLE);
129
    SCU->GPIOEMI = 0x00;
130
  }
131
}
132
/*******************************************************************************
133
* Function Name  : GPIO_Init
134
* Description    : Initializes the GPIOx peripheral according to the specified
135
*                  parameters in the GPIO_InitStruct .
136
* Input          :- GPIOx: where x can be (0..9) to select the GPIO peripheral.
137
*                 - GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that
138
*                   contains the configuration information for the specified GPIO
139
*                   peripheral.
140
* Output         : None
141
* Return         : None
142
*******************************************************************************/
143
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
144
{
145
  /* Select pin direction */
146
  u8 PinNumber = 0;
147
  u8 Counter = 0;
148
  u8 GPIO_Number = 0;
149
 
150
  GPIO_Number = GPIO_GetGPIONumber(GPIOx);
151
 
152
 
153
  if(GPIO_InitStruct->GPIO_Direction == GPIO_PinOutput)
154
  {
155
  GPIOx->DDR |= GPIO_InitStruct->GPIO_Pin;
156
  }
157
  else
158
  {
159
   GPIOx->DDR &= ~GPIO_InitStruct->GPIO_Pin;
160
  }
161
 
162
   for (Counter = 0; Counter < 8;Counter++)
163
    {
164
     /*Search pin number*/
165
     PinNumber = (GPIO_InitStruct->GPIO_Pin & (1 <<Counter));
166
     if((PinNumber >> Counter) == 1)
167
     {
168
        /*Output ALternate 0*/
169
        SCU->GPIOOUT[GPIO_Number] &= ~(0x3 <<(Counter *2));
170
        if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt1)
171
        {
172
          /*Output ALternate 1*/
173
          SCU->GPIOOUT[GPIO_Number] |= 1 << (Counter *2);
174
        }
175
        if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt2)
176
        {
177
          /*Output ALternate 2*/
178
          SCU->GPIOOUT[GPIO_Number] |= 0x2 << (Counter *2);
179
        }
180
        if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt3)
181
        {
182
          /*Output ALternate 3*/
183
          SCU->GPIOOUT[GPIO_Number] |= 0x3 << (Counter *2);
184
        }
185
 
186
       /*Type configuration: PushPull or Open Collector*/
187
        SCU->GPIOTYPE[GPIO_Number] &= ~(0x1 << Counter) ;
188
       if(GPIO_InitStruct->GPIO_Type == GPIO_Type_OpenCollector)
189
       {
190
         /*Open Drain configuration*/
191
        SCU->GPIOTYPE[GPIO_Number] |= 0x1 << Counter;
192
       }
193
 
194
       /*IP Connected disable*/
195
       SCU->GPIOIN[GPIO_Number] &= ~(0x1 << Counter) ;
196
       if(GPIO_InitStruct->GPIO_IPConnected == GPIO_IPConnected_Enable)
197
       {
198
         /*IP Connected enable*/
199
         SCU->GPIOIN[GPIO_Number] |= 0x1 << Counter;
200
       }
201
    }
202
 }
203
}
204
 
205
/*******************************************************************************
206
* Function Name  : GPIO_StructInit
207
* Description    : Initialize the GPIO Init Structure parameters
208
* Input          : GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure
209
*                  which will be initialized.
210
* Output         : None
211
* Return         : None
212
*******************************************************************************/
213
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
214
{
215
  /* Reset GPIO init structure parameters values */
216
  GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
217
  GPIO_InitStruct->GPIO_Direction = GPIO_PinInput;
218
  GPIO_InitStruct->GPIO_Type = GPIO_Type_PushPull;
219
  GPIO_InitStruct->GPIO_IPConnected = GPIO_IPConnected_Disable;
220
  GPIO_InitStruct->GPIO_Alternate = GPIO_InputAlt1;
221
}
222
 
223
/*******************************************************************************
224
* Function Name  : GPIO_ReadBit
225
* Description    : Reads the specified port pin
226
* Input          : - GPIOx: where x can be (0..9) to select the GPIO peripheral.
227
*                : - GPIO_Pin: the Pin number. This parameter can be GPIO_Pin_x
228
*                    where x can be (0..7).
229
* Output         : None
230
* Return         : The port pin value
231
*******************************************************************************/
232
u8 GPIO_ReadBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin)
233
{
234
 if ((((GPIOx->DR[GPIO_Pin<<2])) & GPIO_Pin) != Bit_RESET )
235
  {
236
    return Bit_SET;
237
  }
238
  else
239
  {
240
    return Bit_RESET;
241
  }
242
}
243
 
244
/*******************************************************************************
245
* Function Name  : GPIO_Read
246
* Description    : Reads the specified GPIO data port
247
* Input          : - GPIOx: where x can be (0..9) to select the GPIO peripheral.
248
* Output         : None
249
* Return         : GPIO data port word value.
250
*******************************************************************************/
251
u8 GPIO_Read(GPIO_TypeDef* GPIOx)
252
{
253
  return (GPIOx->DR[0x3FC]);
254
}
255
 
256
/*******************************************************************************
257
* Function Name  : GPIO_WriteBit
258
* Description    : Sets or clears the selected data port bit.
259
* Input          : - GPIOx: where x can be (0..9) to select the GPIO peripheral.
260
*                  - GPIO_Pin: the Pin number. This parameter can be GPIO_Pin_x
261
*                    where x can be (0..7).
262
*                  - BitVal: this parameter specifies the value to be written
263
*                    to the selected bit.
264
*                    BitVal must be one of the BitAction enum values:
265
*                       - Bit_RESET: to clear the port pin
266
*                       - Bit_SET: to set the port pin
267
* Output         : None
268
* Return         : None
269
*******************************************************************************/
270
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin, BitAction BitVal)
271
{
272
  if(BitVal == Bit_SET)
273
  {
274
    GPIOx->DR[GPIO_Pin <<2] = GPIO_Pin;
275
  }
276
  else
277
  {
278
    GPIOx->DR[GPIO_Pin <<2] = 0x00;
279
  }
280
}
281
 
282
/*******************************************************************************
283
* Function Name  : GPIO_Write
284
* Description    : Writes the passed value in the selected data GPIOx port
285
*                  register.
286
* Input          :- GPIOx: where x can be (0..9) to select the GPIO peripheral.
287
*                 - PortVal: the value to be written to the data port register.
288
* Output         : None
289
* Return         : None
290
*******************************************************************************/
291
void GPIO_Write(GPIO_TypeDef* GPIOx, u8 PortVal)
292
{
293
  GPIOx->DR[0x3FC] = PortVal;
294
}
295
 
296
/*******************************************************************************
297
* Function Name  : GPIO_EMIConfig
298
* Description    : Enables or disables GPIO 8 and 9 in EMI mode.
299
* Input          : - NewState: new state of the EMI.
300
*                   This parameter can be: ENABLE or DISABLE.
301
* Output         : None
302
* Return         : None
303
*******************************************************************************/
304
void GPIO_EMIConfig(FunctionalState NewState)
305
{
306
  if(NewState == ENABLE)
307
  {
308
    SCU->GPIOEMI = 0x01;
309
  }
310
  else
311
  {
312
    SCU->GPIOEMI = 0x00;
313
  }
314
}
315
 
316
/*******************************************************************************
317
* Function Name  : GPIO_ANAPinConfig
318
* Description    : Enables or disables pins from GPIO 4 in Analogue mode.
319
* Input          :- GPIO_ANAChannel: selects the ADC channel pin.
320
*                   This parameter can be one of the following values:
321
*                      GPIO_ANAChannel0
322
*                      GPIO_ANAChannel1
323
*                      GPIO_ANAChannel2
324
*                      GPIO_ANAChannel3
325
*                      GPIO_ANAChannel4
326
*                      GPIO_ANAChannel5
327
*                      GPIO_ANAChannel6
328
*                      GPIO_ANAChannel7
329
*                      GPIO_ANAChannelALL
330
*                 - NewState: new state of the port pin.
331
*                   This parameter can be: ENABLE or DISABLE.
332
* Output         : None
333
* Return         : None
334
*******************************************************************************/
335
void GPIO_ANAPinConfig(u8 GPIO_ANAChannel, FunctionalState NewState)
336
{
337
 
338
  if(NewState == ENABLE)
339
  {
340
    if(GPIO_ANAChannel == GPIO_ANAChannelALL)
341
    {
342
      SCU->GPIOOUT[4] = 0x0000;
343
      SCU->GPIOIN[4] = 0x00;
344
    }
345
    else
346
    {
347
      SCU->GPIOOUT[4] &= ~(0x3<<(GPIO_ANAChannel-1));
348
      SCU->GPIOIN[4] &= ~GPIO_ANAChannel;
349
    }
350
    SCU->GPIOANA |= GPIO_ANAChannel;
351
 
352
  }
353
  else
354
  {
355
    SCU->GPIOANA &= ~GPIO_ANAChannel;
356
  }
357
}
358
 
359
/*******************************************************************************
360
* Function Name  : GPIO_GetGPIONumber
361
* Description    : searche the GPIO number.
362
* Input          : GPIOx: where x can be (0..9) to select the GPIO peripheral.
363
* Output         : None
364
* Return         : GPIO number
365
*******************************************************************************/
366
u8 GPIO_GetGPIONumber(GPIO_TypeDef* GPIOx)
367
{
368
 
369
  if(GPIOx == GPIO1)
370
  {
371
    return  1;
372
  }
373
  if(GPIOx == GPIO2)
374
  {
375
    return  2;
376
  }
377
  if(GPIOx == GPIO3)
378
  {
379
    return  3;
380
  }
381
  if(GPIOx == GPIO4)
382
  {
383
    return  4;
384
  }
385
  if(GPIOx == GPIO5)
386
  {
387
    return  5;
388
  }
389
  if(GPIOx == GPIO6)
390
  {
391
    return  6;
392
  }
393
  if(GPIOx == GPIO7)
394
  {
395
    return  7;
396
  }
397
  if(GPIOx == GPIO8)
398
  {
399
    return  8;
400
  }
401
  if(GPIOx == GPIO9)
402
  {
403
    return  9;
404
  }
405
  return 0;
406
}
407
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.