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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_STR75x_GCC/] [STLibrary/] [src/] [75x_gpio.c] - Blame information for rev 584

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2
* File Name          : 75x_gpio.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 03/10/2006
5
* Description        : This file provides all the GPIO software functions.
6
********************************************************************************
7
* History:
8
* 07/17/2006 : V1.0
9
* 03/10/2006 : V0.1
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 "75x_gpio.h"
21
#include "75x_mrcc.h"
22
 
23
/* Private typedef -----------------------------------------------------------*/
24
/* Private define ------------------------------------------------------------*/
25
#define GPIO_Remap_Mask    0x1F       /* GPIO remapping mask */
26
#define GPIO_Pin_Mask      0x000FFFFF /* GPIO1 and GPIO2 all pins mask */
27
 
28
/* Private macro -------------------------------------------------------------*/
29
/* Private variables ---------------------------------------------------------*/
30
/* Private function prototypes -----------------------------------------------*/
31
/* Private functions ---------------------------------------------------------*/
32
 
33
/*******************************************************************************
34
* Function Name  : GPIO_DeInit
35
* Description    : Deinitializes the GPIOx peripheral registers to their default
36
*                  reset values.
37
*                  The I/O remapping register 0 and 1 are not reset by this function.
38
* Input          : GPIOx: where x can be 0,1 or 2 to select the GPIO peripheral.
39
* Output         : None
40
* Return         : None
41
*******************************************************************************/
42
void GPIO_DeInit(GPIO_TypeDef* GPIOx)
43
{
44
  /* Reset the GPIOx registers values */
45
  GPIOx->PC0 = 0xFFFFFFFF;
46
  GPIOx->PC1 = 0x0;
47
  GPIOx->PC2 = 0x0;
48
  GPIOx->PM = 0x0;
49
}
50
 
51
/*******************************************************************************
52
* Function Name  : GPIO_Init
53
* Description    : Initializes the GPIOx peripheral according to the specified
54
*                  parameters in the GPIO_InitStruct. This function will not
55
*                  change the configuration for a pin if the corresponding mask
56
*                  bit is set, except pins configured as input pull-up or pull-down.
57
*                  These pins are automatically masked after each configuration.
58
* Input          :- GPIOx: where x can be (0..2) to select the GPIO peripheral.
59
*                 - GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that
60
*                   contains the configuration information for the specified GPIO
61
*                   peripheral.
62
* Output         : None
63
* Return         : None
64
*******************************************************************************/
65
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
66
{
67
  /* GPIOx Mode and Pins Set */
68
  if((GPIOx != GPIO0) && (GPIO_InitStruct->GPIO_Pin == GPIO_Pin_All))
69
  {
70
    GPIO_InitStruct->GPIO_Pin = GPIO_Pin_Mask;
71
  }
72
 
73
  switch(GPIO_InitStruct->GPIO_Mode)
74
  {
75
    case GPIO_Mode_AIN:
76
      GPIOx->PC0 &= ~GPIO_InitStruct->GPIO_Pin;
77
      GPIOx->PC1 &= ~GPIO_InitStruct->GPIO_Pin;
78
      GPIOx->PC2 &= ~GPIO_InitStruct->GPIO_Pin;
79
      break;
80
 
81
    case GPIO_Mode_IN_FLOATING:
82
      GPIOx->PC0 |=  GPIO_InitStruct->GPIO_Pin;
83
      GPIOx->PC1 &= ~GPIO_InitStruct->GPIO_Pin;
84
      GPIOx->PC2 &= ~GPIO_InitStruct->GPIO_Pin;
85
      break;
86
 
87
    case GPIO_Mode_IPD:
88
      GPIOx->PM  &= ~GPIO_InitStruct->GPIO_Pin;
89
      GPIOx->PC0 |=  GPIO_InitStruct->GPIO_Pin;
90
      GPIOx->PC1 |=  GPIO_InitStruct->GPIO_Pin;
91
      GPIOx->PC2 &= ~GPIO_InitStruct->GPIO_Pin;
92
      GPIOx->PD  &= ~GPIO_InitStruct->GPIO_Pin;
93
      GPIOx->PM  |=  GPIO_InitStruct->GPIO_Pin;
94
      break;
95
 
96
    case GPIO_Mode_IPU:
97
      GPIOx->PM  &= ~GPIO_InitStruct->GPIO_Pin;
98
      GPIOx->PC0 |=  GPIO_InitStruct->GPIO_Pin;
99
      GPIOx->PC1 |=  GPIO_InitStruct->GPIO_Pin;
100
      GPIOx->PC2 &= ~GPIO_InitStruct->GPIO_Pin;
101
      GPIOx->PD  |=  GPIO_InitStruct->GPIO_Pin;
102
      GPIOx->PM  |=  GPIO_InitStruct->GPIO_Pin;
103
      break;
104
 
105
    case GPIO_Mode_Out_OD:
106
      GPIOx->PC0 &= ~GPIO_InitStruct->GPIO_Pin;
107
      GPIOx->PC1 &= ~GPIO_InitStruct->GPIO_Pin;
108
      GPIOx->PC2 |=  GPIO_InitStruct->GPIO_Pin;
109
      break;
110
 
111
    case GPIO_Mode_Out_PP:
112
      GPIOx->PC0 |=  GPIO_InitStruct->GPIO_Pin;
113
      GPIOx->PC1 &= ~GPIO_InitStruct->GPIO_Pin;
114
      GPIOx->PC2 |=  GPIO_InitStruct->GPIO_Pin;
115
      break;
116
 
117
    case GPIO_Mode_AF_OD:
118
      GPIOx->PD  |=  GPIO_InitStruct->GPIO_Pin;
119
      GPIOx->PC1 |=  GPIO_InitStruct->GPIO_Pin;
120
      GPIOx->PC0 &= ~GPIO_InitStruct->GPIO_Pin;
121
      GPIOx->PC2 |=  GPIO_InitStruct->GPIO_Pin;
122
      break;
123
 
124
    case GPIO_Mode_AF_PP:
125
      GPIOx->PC0 |=  GPIO_InitStruct->GPIO_Pin;
126
      GPIOx->PC1 |=  GPIO_InitStruct->GPIO_Pin;
127
      GPIOx->PC2 |=  GPIO_InitStruct->GPIO_Pin;
128
      break;
129
 
130
    default :
131
      GPIOx->PC0 |=  GPIO_InitStruct->GPIO_Pin;
132
      GPIOx->PC1 &= ~GPIO_InitStruct->GPIO_Pin;
133
      GPIOx->PC2 &= ~GPIO_InitStruct->GPIO_Pin;
134
      break;
135
  }
136
}
137
 
138
/*******************************************************************************
139
* Function Name  : GPIO_StructInit
140
* Description    : Fills each GPIO_InitStruct member with its default value.
141
* Input          : GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure
142
*                  which will be initialized.
143
* Output         : None
144
* Return         : None
145
*******************************************************************************/
146
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
147
{
148
  /* Reset GPIO init structure parameters values */
149
  GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
150
  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
151
}
152
 
153
/*******************************************************************************
154
* Function Name  : GPIO_Read
155
* Description    : Reads the specified GPIO data port.
156
* Input          : GPIOx: where x can be 0,1 or 2 to select the GPIO peripheral.
157
* Output         : None
158
* Return         : GPIO data port word value.
159
*******************************************************************************/
160
u32 GPIO_Read(GPIO_TypeDef* GPIOx)
161
{
162
  return GPIOx->PD;
163
}
164
 
165
/*******************************************************************************
166
* Function Name  : GPIO_ReadBit
167
* Description    : Reads the specified data port bit.
168
* Input          : - GPIOx: where x can be (0..2) to select the GPIO peripheral.
169
*                : - GPIO_Pin:  specifies the port bit to read.
170
*                    This parameter can be GPIO_Pin_x where x can be (0..31) for
171
*                    GPIO0 and x(0..19) for GPIO1 and GPIO2.
172
* Output         : None
173
* Return         : The port pin value
174
*******************************************************************************/
175
u8 GPIO_ReadBit(GPIO_TypeDef* GPIOx, u32 GPIO_Pin)
176
{
177
  if ((GPIOx->PD & GPIO_Pin) != Bit_RESET)
178
  {
179
    return Bit_SET;
180
  }
181
  else
182
  {
183
    return Bit_RESET;
184
  }
185
}
186
 
187
/*******************************************************************************
188
* Function Name  : GPIO_Write
189
* Description    : Writes data to the specified GPIO data port.
190
* Input          :- GPIOx: where x can be 0,1 or 2 to select the GPIO peripheral.
191
*                 - PortVal: specifies the value to be written to the data port
192
*                   register.
193
* Output         : None
194
* Return         : None
195
*******************************************************************************/
196
void GPIO_Write(GPIO_TypeDef* GPIOx, u32 PortVal)
197
{
198
  GPIOx->PD = PortVal;
199
}
200
 
201
/*******************************************************************************
202
* Function Name  : GPIO_WriteBit
203
* Description    : Sets or clears the selected data port bit.
204
* Input          : - GPIOx: where x can be (0..2) to select the GPIO peripheral.
205
*                  - GPIO_Pin: specifies the port bit to be written.
206
*                    This parameter can be GPIO_Pin_x where x can be (0..31) for
207
*                    GPIO0 and x(0..19) for GPIO1 and GPIO2.
208
*                  - BitVal: specifies the value to be written to the selected bit.
209
*                    This parameter must be one of the BitAction enum values:
210
*                       - Bit_RESET: to clear the port pin
211
*                       - Bit_SET: to set the port pin
212
* Output         : None
213
* Return         : None
214
*******************************************************************************/
215
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u32 GPIO_Pin, BitAction BitVal)
216
{
217
  if(BitVal != Bit_RESET)
218
  {
219
    GPIOx->PD |= GPIO_Pin;
220
  }
221
  else
222
  {
223
    GPIOx->PD &= ~GPIO_Pin;
224
  }
225
}
226
 
227
/*******************************************************************************
228
* Function Name  : GPIO_PinMaskConfig
229
* Description    : Enables or disables write protection to the selected bits in
230
*                  the I/O port registers (PxC2, PxC1, PxC0 and PxD).
231
* Input          :- GPIOx: where x can be 0,1 or 2 to select the GPIO peripheral.
232
*                 - GPIO_Pin: specifies the port bit to be protected.
233
*                   This parameter can be GPIO_Pin_x where x can be (0..31) for
234
*                   GPIO0 and x(0..19) for GPIO1 and GPIO2.
235
*                 - NewState: new state of the port pin.
236
*                   This parameter can be: ENABLE or DISABLE.
237
* Output         : None
238
* Return         : None
239
*******************************************************************************/
240
void GPIO_PinMaskConfig(GPIO_TypeDef* GPIOx, u32 GPIO_Pin, FunctionalState NewState)
241
{
242
  if(NewState == ENABLE)
243
  {
244
    GPIOx->PM |= GPIO_Pin;
245
  }
246
  else
247
  {
248
    GPIOx->PM &= ~GPIO_Pin;
249
  }
250
}
251
 
252
/*******************************************************************************
253
* Function Name  : GPIO_GetPortMask
254
* Description    : Gets the GPIOx port mask value.
255
* Input          : GPIOx: where x can be 0,1 or 2 to select the GPIO peripheral.
256
* Output         : None
257
* Return         : GPIO port mask value.
258
*******************************************************************************/
259
u32 GPIO_GetPortMask(GPIO_TypeDef* GPIOx)
260
{
261
  return GPIOx->PM;
262
}
263
 
264
/*******************************************************************************
265
* Function Name  : GPIO_PinRemapConfig
266
* Description    : Changes the mapping of the specified pin.
267
* Input          :- GPIO_Remap: selects the pin to remap.
268
*                   This parameter can be one of the following values:
269
*                     - GPIO_Remap_SMI_CS3_EN: Enable SMI CS3
270
*                     - GPIO_Remap_SMI_CS2_EN: Enable SMI CS2
271
*                     - GPIO_Remap_SMI_CS1_EN: Enable SMI CS1
272
*                     - GPIO_Remap_SMI_EN: Enable SMI Alternate Functions:
273
*                       SMI_CS0, SMI_CK, SMI_DIN and SMI_DOUT
274
*                     - GPIO_Remap_DBGOFF: JTAG Disable
275
*                     - GPIO_Remap_UART1: UART1 Alternate Function mapping
276
*                     - GPIO_Remap_UART2: UART2 Alternate Function mapping
277
*                     - GPIO_Remap_SSP1: SSP1 Alternate Function mapping
278
*                     - GPIO_Remap_TIM2: TIM2 Alternate Function mapping
279
*                     - GPIO_Remap_TIM0: TIM0 Alternate Function mapping
280
*                 - NewState: new state of the port pin.
281
*                   This parameter can be: ENABLE or DISABLE.
282
* Output         : None
283
* Return         : None
284
*******************************************************************************/
285
void GPIO_PinRemapConfig(u16 GPIO_Remap, FunctionalState NewState)
286
{
287
  u32 GPIOReg = 0;
288
  u32 PinPos = 0;
289
 
290
  /* Get the GPIO register index */
291
  GPIOReg = GPIO_Remap >> 5;
292
 
293
  /* Get the pin position */
294
  PinPos = GPIO_Remap & GPIO_Remap_Mask;
295
 
296
  if(GPIOReg == 1) /* The pin to remap is in REMAP0R register */
297
  {
298
    if(NewState == ENABLE)
299
    {
300
      GPIOREMAP->REMAP0R |= (1 << PinPos);
301
    }
302
    else
303
    {
304
      GPIOREMAP->REMAP0R &= ~(1 << PinPos);
305
    }
306
  }
307
  else if(GPIOReg == 2) /* The pin to remap is in REMAP1R register */
308
  {
309
    if(NewState == ENABLE)
310
    {
311
      GPIOREMAP->REMAP1R |= (1 << PinPos);
312
    }
313
    else
314
    {
315
      GPIOREMAP->REMAP1R &= ~(1 << PinPos);
316
    }
317
  }
318
}
319
 
320
/******************* (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.