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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3S811_IAR/] [LuminaryCode/] [gpio.c] - Blame information for rev 728

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

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//
3
// gpio.c - API for GPIO ports
4
//
5
// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
6
//
7
// Software License Agreement
8
//
9
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10
// exclusively on LMI's Stellaris Family of microcontroller products.
11
//
12
// The software is owned by LMI and/or its suppliers, and is protected under
13
// applicable copyright laws.  All rights are reserved.  Any use in violation
14
// of the foregoing restrictions may subject the user to criminal sanctions
15
// under applicable laws, as well as to civil liability for the breach of the
16
// terms and conditions of this license.
17
//
18
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
//
24
// This is part of revision 991 of the Stellaris Driver Library.
25
//
26
//*****************************************************************************
27
 
28
//*****************************************************************************
29
//
30
//! \addtogroup gpio_api
31
//! @{
32
//
33
//*****************************************************************************
34
 
35
#include "../hw_gpio.h"
36
#include "../hw_ints.h"
37
#include "../hw_memmap.h"
38
#include "../hw_types.h"
39
#include "debug.h"
40
#include "gpio.h"
41
#include "interrupt.h"
42
 
43
//*****************************************************************************
44
//
45
//! \internal
46
//! Get GPIO interrupt number.
47
//!
48
//! \param ulPort base address of the selected GPIO port
49
//!
50
//! Given a GPIO base address, returns the corresponding interrupt number.
51
//!
52
//! \return Returns a GPIO interrupt number, or -1 if \e ulPort is invalid.
53
//
54
//*****************************************************************************
55
#if defined(GROUP_getintnumber) || defined(BUILD_ALL)
56
long
57
GPIOGetIntNumber(unsigned long ulPort)
58
{
59
    unsigned int ulInt;
60
 
61
    //
62
    // Determine the GPIO interrupt number for the given module.
63
    //
64
    switch(ulPort)
65
    {
66
        case GPIO_PORTA_BASE:
67
        {
68
            ulInt = INT_GPIOA;
69
            break;
70
        }
71
 
72
        case GPIO_PORTB_BASE:
73
        {
74
            ulInt = INT_GPIOB;
75
            break;
76
        }
77
 
78
        case GPIO_PORTC_BASE:
79
        {
80
            ulInt = INT_GPIOC;
81
            break;
82
        }
83
 
84
        case GPIO_PORTD_BASE:
85
        {
86
            ulInt = INT_GPIOD;
87
            break;
88
        }
89
 
90
        case GPIO_PORTE_BASE:
91
        {
92
            ulInt = INT_GPIOE;
93
            break;
94
        }
95
 
96
        default:
97
        {
98
            return(-1);
99
        }
100
    }
101
 
102
    //
103
    // Return GPIO interrupt number.
104
    //
105
    return(ulInt);
106
}
107
#else
108
extern long GPIOGetIntNumber(unsigned long ulPort);
109
#endif
110
 
111
//*****************************************************************************
112
//
113
//! Sets the direction and mode of the specified pins of the selected
114
//! GPIO port.
115
//!
116
//! \param ulPort base address of the selected GPIO port
117
//! \param ucPins bit-packed representation of the specified pins
118
//! \param ulPinIO pin direction and/or mode
119
//!
120
//! This function will set the specified pins on the selected GPIO port
121
//! as either an input or output under software control, or it will set the
122
//! pin to be under hardware control.
123
//!
124
//! The parameter \e ulPinIO is an enumerated data type that can be one of
125
//! the following values:
126
//!
127
//! - \b GPIO_DIR_MODE_IN
128
//! - \b GPIO_DIR_MODE_OUT
129
//! - \b GPIO_DIR_MODE_HW
130
//!
131
//! where \b GPIO_DIR_MODE_IN specifies that the pin will be programmed as
132
//! a software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin
133
//! will be programmed as a software controlled output, and
134
//! \b GPIO_DIR_MODE_HW specifies that the pin will be placed under
135
//! hardware control.
136
//!
137
//! The pins are specified using a bit-packed byte, where each bit that is
138
//! set identifies the pin to be accessed, and where bit 0 of the byte
139
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
140
//!
141
//! \return None.
142
//
143
//*****************************************************************************
144
#if defined(GROUP_dirmodeset) || defined(BUILD_ALL) || defined(DOXYGEN)
145
void
146
GPIODirModeSet(unsigned long ulPort, unsigned char ucPins,
147
               unsigned long ulPinIO)
148
{
149
    //
150
    // Check the arguments.
151
    //
152
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
153
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
154
           (ulPort == GPIO_PORTE_BASE));
155
    ASSERT((ulPinIO == GPIO_DIR_MODE_IN) || (ulPinIO == GPIO_DIR_MODE_OUT) ||
156
           (ulPinIO == GPIO_DIR_MODE_HW));
157
 
158
    //
159
    // Set the pin direction and mode.
160
    //
161
    HWREG(ulPort + GPIO_O_DIR) = ((ulPinIO & 1) ?
162
                                  (HWREG(ulPort + GPIO_O_DIR) | ucPins) :
163
                                  (HWREG(ulPort + GPIO_O_DIR) & ~(ucPins)));
164
    HWREG(ulPort + GPIO_O_AFSEL) = ((ulPinIO & 2) ?
165
                                    (HWREG(ulPort + GPIO_O_AFSEL) | ucPins) :
166
                                    (HWREG(ulPort + GPIO_O_AFSEL) &
167
                                     ~(ucPins)));
168
}
169
#endif
170
 
171
//*****************************************************************************
172
//
173
//! Gets the direction and mode of a specified pin of the selected
174
//! GPIO port.
175
//!
176
//! \param ulPort base address of the selected GPIO port
177
//! \param ucPin pin number of the specified pin, relative to the selected
178
//! GPIO port.
179
//!
180
//! This function gets the direction and control mode for a specified pin on
181
//! the selected GPIO port. The pin can be configured as either an input or
182
//! output under software control, or it can be under hardware control. The
183
//! type of control and direction are returned as an enumerated data type.
184
//!
185
//! \return Returns one of the enumerated data types described for
186
//! GPIODirModeSet().
187
//
188
//*****************************************************************************
189
#if defined(GROUP_dirmodeget) || defined(BUILD_ALL) || defined(DOXYGEN)
190
unsigned long
191
GPIODirModeGet(unsigned long ulPort, unsigned char ucPin)
192
{
193
    unsigned long ulDir, ulAFSEL;
194
 
195
    //
196
    // Check the arguments.
197
    //
198
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
199
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
200
           (ulPort == GPIO_PORTE_BASE));
201
    ASSERT(ucPin < 8);
202
 
203
    //
204
    // Convert from a pin number to a bit position.
205
    //
206
    ucPin = 1 << ucPin;
207
 
208
    //
209
    // Return the pin direction and mode.
210
    //
211
    ulDir = HWREG(ulPort + GPIO_O_DIR);
212
    ulAFSEL = HWREG(ulPort + GPIO_O_AFSEL);
213
    return(((ulDir & ucPin) ? 1 : 0) | ((ulAFSEL & ucPin) ? 2 : 0));
214
}
215
#endif
216
 
217
//*****************************************************************************
218
//
219
//! Sets the interrupt type for the specified pins of the selected GPIO
220
//! port.
221
//!
222
//! \param ulPort base address of the selected GPIO port
223
//! \param ucPins bit-packed representation of the specified pins
224
//! \param ulIntType specifies the type of interrupt trigger mechanism
225
//!
226
//! This function sets up the various interrupt trigger mechanisms for the
227
//! specified pins on the selected GPIO port.
228
//!
229
//! The parameter \e ulIntType is an enumerated data type that can be one of
230
//! the following values:
231
//!
232
//! - \b GPIO_FALLING_EDGE
233
//! - \b GPIO_RISING_EDGE
234
//! - \b GPIO_BOTH_EDGES
235
//! - \b GPIO_LOW_LEVEL
236
//! - \b GPIO_HIGH_LEVEL
237
//!
238
//! where the different values describe the interrupt detection mechanism
239
//! (edge or level) and the particular triggering event (falling, rising,
240
//! or both edges for edge detect, low or high for level detect).
241
//!
242
//! The pins are specified using a bit-packed byte, where each bit that is
243
//! set identifies the pin to be accessed, and where bit 0 of the byte
244
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
245
//!
246
//! \note In order to avoid any spurious interrupts, the user must
247
//! ensure that the GPIO inputs remain stable for the duration of
248
//! this function.
249
//!
250
//! \return None.
251
//
252
//*****************************************************************************
253
#if defined(GROUP_inttypeset) || defined(BUILD_ALL) || defined(DOXYGEN)
254
void
255
GPIOIntTypeSet(unsigned long ulPort, unsigned char ucPins,
256
               unsigned long ulIntType)
257
{
258
    //
259
    // Check the arguments.
260
    //
261
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
262
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
263
           (ulPort == GPIO_PORTE_BASE));
264
    ASSERT((ulIntType == GPIO_FALLING_EDGE) ||
265
           (ulIntType == GPIO_RISING_EDGE) ||
266
           (ulIntType == GPIO_BOTH_EDGES) ||
267
           (ulIntType == GPIO_LOW_LEVEL) ||
268
           (ulIntType == GPIO_HIGH_LEVEL));
269
 
270
    //
271
    // Set the pin interrupt type.
272
    //
273
    HWREG(ulPort + GPIO_O_IBE) = ((ulIntType & 1) ?
274
                                  (HWREG(ulPort + GPIO_O_IBE) | ucPins) :
275
                                  (HWREG(ulPort + GPIO_O_IBE) & ~(ucPins)));
276
    HWREG(ulPort + GPIO_O_IS) = ((ulIntType & 2) ?
277
                                 (HWREG(ulPort + GPIO_O_IS) | ucPins) :
278
                                 (HWREG(ulPort + GPIO_O_IS) & ~(ucPins)));
279
    HWREG(ulPort + GPIO_O_IEV) = ((ulIntType & 4) ?
280
                                  (HWREG(ulPort + GPIO_O_IEV) | ucPins) :
281
                                  (HWREG(ulPort + GPIO_O_IEV) & ~(ucPins)));
282
}
283
#endif
284
 
285
//*****************************************************************************
286
//
287
//! Gets the interrupt type for the specified pin of the selected GPIO
288
//! port.
289
//!
290
//! \param ulPort base address of the selected GPIO port
291
//! \param ucPin pin number of the specified pin, relative to the selected
292
//! GPIO port.
293
//!
294
//! This function gets the interrupt type for a specified pin on the selected
295
//! GPIO port. The pin can be configured as a falling edge, rising edge, or
296
//! both edge detected interrupt, or it can be configured as a low level or
297
//! high level detected interrupt. The type of interrupt detection mechanism
298
//! is returned as an enumerated data type.
299
//!
300
//! \return Returns one of the enumerated data types described for
301
//! GPIOIntTypeSet().
302
//
303
//*****************************************************************************
304
#if defined(GROUP_inttypeget) || defined(BUILD_ALL) || defined(DOXYGEN)
305
unsigned long
306
GPIOIntTypeGet(unsigned long ulPort, unsigned char ucPin)
307
{
308
    unsigned long ulIBE, ulIS, ulIEV;
309
 
310
    //
311
    // Check the arguments.
312
    //
313
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
314
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
315
           (ulPort == GPIO_PORTE_BASE));
316
    ASSERT(ucPin < 8);
317
 
318
    //
319
    // Convert from a pin number to a bit position.
320
    //
321
    ucPin = 1 << ucPin;
322
 
323
    //
324
    // Return the pin interrupt type.
325
    //
326
    ulIBE = HWREG(ulPort + GPIO_O_IBE);
327
    ulIS = HWREG(ulPort + GPIO_O_IS);
328
    ulIEV = HWREG(ulPort + GPIO_O_IEV);
329
    return(((ulIBE & ucPin) ? 1 : 0) | ((ulIS & ucPin) ? 2 : 0) |
330
           ((ulIEV & ucPin) ? 4 : 0));
331
}
332
#endif
333
 
334
//*****************************************************************************
335
//
336
//! Sets the pad configuration for the specified pins of the selected GPIO
337
//! port.
338
//!
339
//! \param ulPort is the base address of the GPIO port.
340
//! \param ucPins bit-packed representation of the specified pins.
341
//! \param ulStrength specifies the output drive strength.
342
//! \param ulPinType specifies the pin type.
343
//!
344
//! This function sets the drive strength and type for the specified pins
345
//! on the selected GPIO port.  For pins configured as input ports, the
346
//! pad is configured as requested, but the only real effect on the input
347
//! is the configuration of the pull-up or pull-down termination.
348
//!
349
//! The parameter \e ulStrength can be one of the following values:
350
//!
351
//! - \b GPIO_STRENGTH_2MA
352
//! - \b GPIO_STRENGTH_4MA
353
//! - \b GPIO_STRENGTH_8MA
354
//! - \b GPIO_STRENGTH_8MA_SC
355
//!
356
//! where \b GPIO_STRENGTH_xMA specifies either 2, 4, or 8 mA output drive
357
//! strength, and \b GPIO_OUT_STRENGTH_8MA_SC specifies 8 mA output drive with
358
//! slew control.
359
//!
360
//! The parameter \e ulPinType can be one of the following values:
361
//!
362
//! - \b GPIO_PIN_TYPE_STD
363
//! - \b GPIO_PIN_TYPE_STD_WPU
364
//! - \b GPIO_PIN_TYPE_STD_WPD
365
//! - \b GPIO_PIN_TYPE_OD
366
//! - \b GPIO_PIN_TYPE_OD_WPU
367
//! - \b GPIO_PIN_TYPE_OD_WPD
368
//! - \b GPIO_PIN_TYPE_ANALOG
369
//!
370
//! where \b GPIO_PIN_TYPE_STD* specifies a push-pull pin, \b GPIO_PIN_TYPE_OD*
371
//! specifies an open-drain pin, \b *_WPU specifies a weak pull-up, \b *_WPD
372
//! specifies a weak pull-down, and \b GPIO_PIN_TYPE_ANALOG specifies an
373
//! analog input (for the comparators).
374
//!
375
//! The pins are specified using a bit-packed byte, where each bit that is
376
//! set identifies the pin to be accessed, and where bit 0 of the byte
377
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
378
//!
379
//! \return None.
380
//
381
//*****************************************************************************
382
#if defined(GROUP_padconfigset) || defined(BUILD_ALL) || defined(DOXYGEN)
383
void
384
GPIOPadConfigSet(unsigned long ulPort, unsigned char ucPins,
385
                 unsigned long ulStrength, unsigned long ulPinType)
386
{
387
    //
388
    // Check the arguments.
389
    //
390
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
391
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
392
           (ulPort == GPIO_PORTE_BASE));
393
    ASSERT((ulStrength == GPIO_STRENGTH_2MA) ||
394
           (ulStrength == GPIO_STRENGTH_4MA) ||
395
           (ulStrength == GPIO_STRENGTH_8MA) ||
396
           (ulStrength == GPIO_STRENGTH_8MA_SC));
397
    ASSERT((ulPinType == GPIO_PIN_TYPE_STD) ||
398
           (ulPinType == GPIO_PIN_TYPE_STD_WPU) ||
399
           (ulPinType == GPIO_PIN_TYPE_STD_WPD) ||
400
           (ulPinType == GPIO_PIN_TYPE_OD) ||
401
           (ulPinType == GPIO_PIN_TYPE_OD_WPU) ||
402
           (ulPinType == GPIO_PIN_TYPE_OD_WPD) ||
403
           (ulPinType == GPIO_PIN_TYPE_ANALOG))
404
 
405
    //
406
    // Set the output drive strength.
407
    //
408
    HWREG(ulPort + GPIO_O_DR2R) = ((ulStrength & 1) ?
409
                                   (HWREG(ulPort + GPIO_O_DR2R) | ucPins) :
410
                                   (HWREG(ulPort + GPIO_O_DR2R) & ~(ucPins)));
411
    HWREG(ulPort + GPIO_O_DR4R) = ((ulStrength & 2) ?
412
                                   (HWREG(ulPort + GPIO_O_DR4R) | ucPins) :
413
                                   (HWREG(ulPort + GPIO_O_DR4R) & ~(ucPins)));
414
    HWREG(ulPort + GPIO_O_DR8R) = ((ulStrength & 4) ?
415
                                   (HWREG(ulPort + GPIO_O_DR8R) | ucPins) :
416
                                   (HWREG(ulPort + GPIO_O_DR8R) & ~(ucPins)));
417
    HWREG(ulPort + GPIO_O_SLR) = ((ulStrength & 8) ?
418
                                  (HWREG(ulPort + GPIO_O_SLR) | ucPins) :
419
                                  (HWREG(ulPort + GPIO_O_SLR) & ~(ucPins)));
420
 
421
    //
422
    // Set the pin type.
423
    //
424
    HWREG(ulPort + GPIO_O_ODR) = ((ulPinType & 1) ?
425
                                  (HWREG(ulPort + GPIO_O_ODR) | ucPins) :
426
                                  (HWREG(ulPort + GPIO_O_ODR) & ~(ucPins)));
427
    HWREG(ulPort + GPIO_O_PUR) = ((ulPinType & 2) ?
428
                                  (HWREG(ulPort + GPIO_O_PUR) | ucPins) :
429
                                  (HWREG(ulPort + GPIO_O_PUR) & ~(ucPins)));
430
    HWREG(ulPort + GPIO_O_PDR) = ((ulPinType & 4) ?
431
                                  (HWREG(ulPort + GPIO_O_PDR) | ucPins) :
432
                                  (HWREG(ulPort + GPIO_O_PDR) & ~(ucPins)));
433
    HWREG(ulPort + GPIO_O_DEN) = ((ulPinType & 8) ?
434
                                  (HWREG(ulPort + GPIO_O_DEN) | ucPins) :
435
                                  (HWREG(ulPort + GPIO_O_DEN) & ~(ucPins)));
436
}
437
#endif
438
 
439
//*****************************************************************************
440
//
441
//! Gets the pad configuration for the specified pin of the selected GPIO
442
//! port.
443
//!
444
//! \param ulPort base address of the selected GPIO port
445
//! \param ucPin pin number of the specified pin, relative to the selected
446
//! GPIO port.
447
//! \param pulStrength pointer to storage for the output drive strength
448
//! \param pulPinType pointer to storage for the output drive type
449
//!
450
//! This function gets the pad configuration for a specified pin on the
451
//! selected GPIO port. The values returned in \e eStrength and \e eOutType
452
//! correspond to the values used in GPIOPadConfigSet(). This function also
453
//! works for pins configured as input pins; however, the only meaningful
454
//! data returned is whether the pin is terminated with a pull-up or
455
//! down resistor.
456
//!
457
//! \return None
458
//
459
//*****************************************************************************
460
#if defined(GROUP_padconfigget) || defined(BUILD_ALL) || defined(DOXYGEN)
461
void
462
GPIOPadConfigGet(unsigned long ulPort, unsigned char ucPin,
463
                 unsigned long *pulStrength, unsigned long *pulPinType)
464
{
465
    unsigned long ulTemp1, ulTemp2, ulTemp3, ulTemp4;
466
 
467
    //
468
    // Check the arguments.
469
    //
470
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
471
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
472
           (ulPort == GPIO_PORTE_BASE));
473
    ASSERT(ucPin < 8);
474
 
475
    //
476
    // Convert from a pin number to a bit position.
477
    //
478
    ucPin = (1 << ucPin);
479
 
480
    //
481
    // Get the drive strength for this pin.
482
    //
483
    ulTemp1 = HWREG(ulPort + GPIO_O_DR2R);
484
    ulTemp2 = HWREG(ulPort + GPIO_O_DR4R);
485
    ulTemp3 = HWREG(ulPort + GPIO_O_DR8R);
486
    ulTemp4 = HWREG(ulPort + GPIO_O_SLR);
487
    *pulStrength = (((ulTemp1 & ucPin) ? 1 : 0) | ((ulTemp2 & ucPin) ? 2 : 0) |
488
                    ((ulTemp3 & ucPin) ? 4 : 0) | ((ulTemp4 & ucPin) ? 8 : 0));
489
 
490
    //
491
    // Get the pin type.
492
    //
493
    ulTemp1 = HWREG(ulPort + GPIO_O_ODR);
494
    ulTemp2 = HWREG(ulPort + GPIO_O_PUR);
495
    ulTemp3 = HWREG(ulPort + GPIO_O_PDR);
496
    ulTemp4 = HWREG(ulPort + GPIO_O_DEN);
497
    *pulPinType = (((ulTemp1 & ucPin) ? 1 : 0) | ((ulTemp2 & ucPin) ? 2 : 0) |
498
                   ((ulTemp3 & ucPin) ? 4 : 0) | ((ulTemp4 & ucPin) ? 8 : 0));
499
}
500
#endif
501
 
502
//*****************************************************************************
503
//
504
//! Enables interrupts for the specified pins of the selected GPIO port.
505
//!
506
//! \param ulPort base address of the selected GPIO port
507
//! \param ucPins bit-packed representation of the specified pins
508
//!
509
//! Unmasks the interrupt for the specified pins.
510
//!
511
//! The pins are specified using a bit-packed byte, where each bit that is
512
//! set identifies the pin to be accessed, and where bit 0 of the byte
513
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
514
//!
515
//! \return None.
516
//
517
//*****************************************************************************
518
#if defined(GROUP_pinintenable) || defined(BUILD_ALL) || defined(DOXYGEN)
519
void
520
GPIOPinIntEnable(unsigned long ulPort, unsigned char ucPins)
521
{
522
    //
523
    // Check the arguments.
524
    //
525
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
526
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
527
           (ulPort == GPIO_PORTE_BASE));
528
 
529
    //
530
    // Enable the interrupts.
531
    //
532
    HWREG(ulPort + GPIO_O_IM) |= ucPins;
533
}
534
#endif
535
 
536
//*****************************************************************************
537
//
538
//! Disables interrupts for the specified pins of the selected GPIO port.
539
//!
540
//! \param ulPort base address of the selected GPIO port
541
//! \param ucPins bit-packed representation of the specified pins
542
//!
543
//! Masks the interrupt for the specified pins.
544
//!
545
//! The pins are specified using a bit-packed byte, where each bit that is
546
//! set identifies the pin to be accessed, and where bit 0 of the byte
547
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
548
//!
549
//! \return None.
550
//
551
//*****************************************************************************
552
#if defined(GROUP_pinintdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
553
void
554
GPIOPinIntDisable(unsigned long ulPort, unsigned char ucPins)
555
{
556
    //
557
    // Check the arguments.
558
    //
559
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
560
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
561
           (ulPort == GPIO_PORTE_BASE));
562
 
563
    //
564
    // Disable the interrupts.
565
    //
566
    HWREG(ulPort + GPIO_O_IM) &= ~(ucPins);
567
}
568
#endif
569
 
570
//*****************************************************************************
571
//
572
//! Gets interrupt status for all the pins of the selected GPIO port.
573
//!
574
//! \param ulPort base address of the selected GPIO port
575
//! \param bMasked specifies whether masked or raw interrupt
576
//! status is returned
577
//!
578
//! If \e bMasked is set as \b true, then the masked interrupt status is
579
//! returned; otherwise, the raw interrupt status will be returned.
580
//!
581
//! \return Returns a bit-packed byte, where each bit that is set identifies
582
//! an active masked or raw interrupt, and where bit 0 of the byte
583
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc. Bits
584
//! 31:8 should be ignored.
585
//
586
//*****************************************************************************
587
#if defined(GROUP_pinintstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
588
long
589
GPIOPinIntStatus(unsigned long ulPort, tBoolean bMasked)
590
{
591
    //
592
    // Check the arguments.
593
    //
594
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
595
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
596
           (ulPort == GPIO_PORTE_BASE));
597
 
598
    //
599
    // Return the interrupt status.
600
    //
601
    if(bMasked)
602
    {
603
        return(HWREG(ulPort + GPIO_O_MIS));
604
    }
605
    else
606
    {
607
        return(HWREG(ulPort + GPIO_O_RIS));
608
    }
609
}
610
#endif
611
 
612
//*****************************************************************************
613
//
614
//! Clears the interrupt for the specified pins of the selected GPIO port.
615
//!
616
//! \param ulPort base address of the selected GPIO port
617
//! \param ucPins bit-packed representation of the specified pins
618
//!
619
//! Clears the interrupt for the specified pins.
620
//!
621
//! The pins are specified using a bit-packed byte, where each bit that is
622
//! set identifies the pin to be accessed, and where bit 0 of the byte
623
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
624
//!
625
//! \return None.
626
//
627
//*****************************************************************************
628
#if defined(GROUP_pinintclear) || defined(BUILD_ALL) || defined(DOXYGEN)
629
void
630
GPIOPinIntClear(unsigned long ulPort, unsigned char ucPins)
631
{
632
    //
633
    // Check the arguments.
634
    //
635
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
636
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
637
           (ulPort == GPIO_PORTE_BASE));
638
 
639
    //
640
    // Clear the interrupts.
641
    //
642
    HWREG(ulPort + GPIO_O_ICR) = ucPins;
643
}
644
#endif
645
 
646
//*****************************************************************************
647
//
648
//! Registers an interrupt handler for the selected GPIO port.
649
//!
650
//! \param ulPort base address of the selected GPIO port
651
//! \param pfIntHandler pointer to the GPIO port interrupt handling function
652
//!
653
//! This function will ensure that the interrupt handler specified by \e
654
//! pfIntHandler is called when an interrupt is detected from the selected
655
//! GPIO port. This function will also enable the corresponding GPIO
656
//! interrupt in the interrupt controller; individual pin interrupts and
657
//! interrupt sources must be enabled with GPIOPinIntEnable().
658
//!
659
//! \sa IntRegister() for important information about registering interrupt
660
//! handlers.
661
//!
662
//! \return None.
663
//
664
//*****************************************************************************
665
#if defined(GROUP_portintregister) || defined(BUILD_ALL) || defined(DOXYGEN)
666
void
667
GPIOPortIntRegister(unsigned long ulPort, void (*pfIntHandler)(void))
668
{
669
    //
670
    // Check the arguments.
671
    //
672
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
673
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
674
           (ulPort == GPIO_PORTE_BASE));
675
 
676
    //
677
    // Get the interrupt number associated with the specified GPIO.
678
    //
679
    ulPort = GPIOGetIntNumber(ulPort);
680
 
681
    //
682
    // Register the interrupt handler.
683
    //
684
    IntRegister(ulPort, pfIntHandler);
685
 
686
    //
687
    // Enable the GPIO interrupt.
688
    //
689
    IntEnable(ulPort);
690
}
691
#endif
692
 
693
//*****************************************************************************
694
//
695
//! Removes an interrupt handler for the selected GPIO port.
696
//!
697
//! \param ulPort base address of the selected GPIO port
698
//!
699
//! This function will unregister the interrupt handler for the specified
700
//! GPIO port.  This function will also disable the corresponding
701
//! GPIO port interrupt in the interrupt controller; individual GPIO interrupts
702
//! and interrupt sources must be disabled with GPIOPinIntDisable().
703
//!
704
//! \sa IntRegister() for important information about registering interrupt
705
//! handlers.
706
//!
707
//! \return None.
708
//
709
//*****************************************************************************
710
#if defined(GROUP_portintunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
711
void
712
GPIOPortIntUnregister(unsigned long ulPort)
713
{
714
    //
715
    // Check the arguments.
716
    //
717
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
718
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
719
           (ulPort == GPIO_PORTE_BASE));
720
 
721
    //
722
    // Get the interrupt number associated with the specified GPIO.
723
    //
724
    ulPort = GPIOGetIntNumber(ulPort);
725
 
726
    //
727
    // Disable the GPIO interrupt.
728
    //
729
    IntDisable(ulPort);
730
 
731
    //
732
    // Unregister the interrupt handler.
733
    //
734
    IntUnregister(ulPort);
735
}
736
#endif
737
 
738
//*****************************************************************************
739
//
740
//! Reads the values present at the specified pins of the selected GPIO port.
741
//!
742
//! \param ulPort base address of the selected GPIO port
743
//! \param ucPins bit-packed representation of the specified pins
744
//!
745
//! The values at the specified pins are read, as specified by \e ucPins.
746
//! Values are returned for both input and output pins, and the value
747
//! for pins that are not specified by \e ucPins are set to 0.
748
//!
749
//! The pins are specified using a bit-packed byte, where each bit that is
750
//! set identifies the pin to be accessed, and where bit 0 of the byte
751
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
752
//!
753
//! \return Returns a bit-packed byte providing the state of the specified
754
//! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents
755
//! GPIO port pin 1, etc. Any bit that is not specified by \e ucPins
756
//! is returned as a 0. Bits 31:8 should be ignored.
757
//
758
//*****************************************************************************
759
#if defined(GROUP_pinread) || defined(BUILD_ALL) || defined(DOXYGEN)
760
long
761
GPIOPinRead(unsigned long ulPort, unsigned char ucPins)
762
{
763
    //
764
    // Check the arguments.
765
    //
766
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
767
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
768
           (ulPort == GPIO_PORTE_BASE));
769
 
770
    //
771
    // Return the pin value(s).
772
    //
773
    return(HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))));
774
}
775
#endif
776
 
777
//*****************************************************************************
778
//
779
//! Writes a value at the specified pins of the selected GPIO port.
780
//!
781
//! \param ulPort base address of the selected GPIO port
782
//! \param ucPins bit-packed representation of the specified pins
783
//! \param ucVal value to write to the specified pins
784
//!
785
//! Writes the corresponding bit values to the output pins specified
786
//! by \e ucPins. Writing to a pin configured as an input pin has no
787
//! effect.
788
//!
789
//! The pins are specified using a bit-packed byte, where each bit that is
790
//! set identifies the pin to be accessed, and where bit 0 of the byte
791
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
792
//!
793
//! \return None.
794
//
795
//*****************************************************************************
796
#if defined(GROUP_pinwrite) || defined(BUILD_ALL) || defined(DOXYGEN)
797
void
798
GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal)
799
{
800
    //
801
    // Check the arguments.
802
    //
803
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
804
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
805
           (ulPort == GPIO_PORTE_BASE));
806
 
807
    //
808
    // Write the pins.
809
    //
810
    HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))) = ucVal;
811
}
812
#endif
813
 
814
//*****************************************************************************
815
//
816
//! Configures pin(s) for use as an analog comparator input.
817
//!
818
//! \param ulPort base address of the selected GPIO port
819
//! \param ucPins bit-packed representation of the specified pins
820
//!
821
//! The analog comparator input pins must be properly configured for the analog
822
//! comparator to function correctly.  This function provides the proper
823
//! configuration for those pins.
824
//!
825
//! \note This cannot be used to turn any pin into an analog comparator input;
826
//! it only configures an analog comparator pin for proper operation.
827
//!
828
//! \return None.
829
//
830
//*****************************************************************************
831
#if defined(GROUP_pintypecomparator) || defined(BUILD_ALL) || defined(DOXYGEN)
832
void
833
GPIOPinTypeComparator(unsigned long ulPort, unsigned char ucPins)
834
{
835
    //
836
    // Check the arguments.
837
    //
838
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
839
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
840
           (ulPort == GPIO_PORTE_BASE));
841
 
842
    //
843
    // Make the pin(s) be inputs.
844
    //
845
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
846
 
847
    //
848
    // Set the pad(s) for analog operation.
849
    //
850
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
851
}
852
#endif
853
 
854
//*****************************************************************************
855
//
856
//! Configures pin(s) for use by the I2C peripheral.
857
//!
858
//! \param ulPort base address of the selected GPIO port
859
//! \param ucPins bit-packed representation of the specified pins
860
//!
861
//! The I2C pins must be properly configured for the I2C peripheral to function
862
//! correctly.  This function provides the proper configuration for those pins.
863
//!
864
//! \note This cannot be used to turn any pin into an I2C pin; it only
865
//! configures an I2C pin for proper operation.
866
//!
867
//! \return None.
868
//
869
//*****************************************************************************
870
#if defined(GROUP_pintypei2c) || defined(BUILD_ALL) || defined(DOXYGEN)
871
void
872
GPIOPinTypeI2C(unsigned long ulPort, unsigned char ucPins)
873
{
874
    //
875
    // Check the arguments.
876
    //
877
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
878
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
879
           (ulPort == GPIO_PORTE_BASE));
880
 
881
    //
882
    // Make the pin(s) be peripheral controlled.
883
    //
884
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
885
 
886
    //
887
    // Set the pad(s) for open-drain operation with a weak pull-up.
888
    //
889
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);
890
}
891
#endif
892
 
893
//*****************************************************************************
894
//
895
//! Configures pin(s) for use by the PWM peripheral.
896
//!
897
//! \param ulPort base address of the selected GPIO port
898
//! \param ucPins bit-packed representation of the specified pins
899
//!
900
//! The PWM pins must be properly configured for the PWM peripheral to function
901
//! correctly.  This function provides a typical configuration for those pins;
902
//! other configurations may work as well depending upon the board setup (for
903
//! example, using the on-chip pull-ups).
904
//!
905
//! \note This cannot be used to turn any pin into a PWM pin; it only
906
//! configures a PWM pin for proper operation.
907
//!
908
//! \return None.
909
//
910
//*****************************************************************************
911
#if defined(GROUP_pintypepwm) || defined(BUILD_ALL) || defined(DOXYGEN)
912
void
913
GPIOPinTypePWM(unsigned long ulPort, unsigned char ucPins)
914
{
915
    //
916
    // Check the arguments.
917
    //
918
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
919
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
920
           (ulPort == GPIO_PORTE_BASE));
921
 
922
    //
923
    // Make the pin(s) be peripheral controlled.
924
    //
925
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
926
 
927
    //
928
    // Set the pad(s) for standard push-pull operation.
929
    //
930
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
931
}
932
#endif
933
 
934
//*****************************************************************************
935
//
936
//! Configures pin(s) for use by the QEI peripheral.
937
//!
938
//! \param ulPort base address of the selected GPIO port
939
//! \param ucPins bit-packed representation of the specified pins
940
//!
941
//! The QEI pins must be properly configured for the QEI peripheral to function
942
//! correctly.  This function provides a typical configuration for those pins;
943
//! other configurations may work as well depending upon the board setup (for
944
//! example, not using the on-chip pull-ups).
945
//!
946
//! \note This cannot be used to turn any pin into a QEI pin; it only
947
//! configures a QEI pin for proper operation.
948
//!
949
//! \return None.
950
//
951
//*****************************************************************************
952
#if defined(GROUP_pintypeqei) || defined(BUILD_ALL) || defined(DOXYGEN)
953
void
954
GPIOPinTypeQEI(unsigned long ulPort, unsigned char ucPins)
955
{
956
    //
957
    // Check the arguments.
958
    //
959
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
960
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
961
           (ulPort == GPIO_PORTE_BASE));
962
 
963
    //
964
    // Make the pin(s) be peripheral controlled.
965
    //
966
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
967
 
968
    //
969
    // Set the pad(s) for standard push-pull operation with a weak pull-up.
970
    //
971
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
972
}
973
#endif
974
 
975
//*****************************************************************************
976
//
977
//! Configures pin(s) for use by the SSI peripheral.
978
//!
979
//! \param ulPort base address of the selected GPIO port
980
//! \param ucPins bit-packed representation of the specified pins
981
//!
982
//! The SSI pins must be properly configured for the SSI peripheral to function
983
//! correctly.  This function provides a typical configuration for those pins;
984
//! other configurations may work as well depending upon the board setup (for
985
//! example, using the on-chip pull-ups).
986
//!
987
//! \note This cannot be used to turn any pin into a SSI pin; it only
988
//! configures a SSI pin for proper operation.
989
//!
990
//! \return None.
991
//
992
//*****************************************************************************
993
#if defined(GROUP_pintypessi) || defined(BUILD_ALL) || defined(DOXYGEN)
994
void
995
GPIOPinTypeSSI(unsigned long ulPort, unsigned char ucPins)
996
{
997
    //
998
    // Check the arguments.
999
    //
1000
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
1001
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
1002
           (ulPort == GPIO_PORTE_BASE));
1003
 
1004
    //
1005
    // Make the pin(s) be peripheral controlled.
1006
    //
1007
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1008
 
1009
    //
1010
    // Set the pad(s) for standard push-pull operation.
1011
    //
1012
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1013
}
1014
#endif
1015
 
1016
//*****************************************************************************
1017
//
1018
//! Configures pin(s) for use by the Timer peripheral.
1019
//!
1020
//! \param ulPort base address of the selected GPIO port
1021
//! \param ucPins bit-packed representation of the specified pins
1022
//!
1023
//! The CCP pins must be properly configured for the timer peripheral to
1024
//! function correctly.  This function provides a typical configuration for
1025
//! those pins; other configurations may work as well depending upon the board
1026
//! setup (for example, using the on-chip pull-ups).
1027
//!
1028
//! \note This cannot be used to turn any pin into a timer pin; it only
1029
//! configures a timer pin for proper operation.
1030
//!
1031
//! \return None.
1032
//
1033
//*****************************************************************************
1034
#if defined(GROUP_pintypetimer) || defined(BUILD_ALL) || defined(DOXYGEN)
1035
void
1036
GPIOPinTypeTimer(unsigned long ulPort, unsigned char ucPins)
1037
{
1038
    //
1039
    // Check the arguments.
1040
    //
1041
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
1042
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
1043
           (ulPort == GPIO_PORTE_BASE));
1044
 
1045
    //
1046
    // Make the pin(s) be peripheral controlled.
1047
    //
1048
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1049
 
1050
    //
1051
    // Set the pad(s) for standard push-pull operation.
1052
    //
1053
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1054
}
1055
#endif
1056
 
1057
//*****************************************************************************
1058
//
1059
//! Configures pin(s) for use by the UART peripheral.
1060
//!
1061
//! \param ulPort base address of the selected GPIO port
1062
//! \param ucPins bit-packed representation of the specified pins
1063
//!
1064
//! The UART pins must be properly configured for the UART peripheral to
1065
//! function correctly.  This function provides a typical configuration for
1066
//! those pins; other configurations may work as well depending upon the board
1067
//! setup (for example, using the on-chip pull-ups).
1068
//!
1069
//! \note This cannot be used to turn any pin into a UART pin; it only
1070
//! configures a UART pin for proper operation.
1071
//!
1072
//! \return None.
1073
//
1074
//*****************************************************************************
1075
#if defined(GROUP_pintypeuart) || defined(BUILD_ALL) || defined(DOXYGEN)
1076
void
1077
GPIOPinTypeUART(unsigned long ulPort, unsigned char ucPins)
1078
{
1079
    //
1080
    // Check the arguments.
1081
    //
1082
    ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
1083
           (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
1084
           (ulPort == GPIO_PORTE_BASE));
1085
 
1086
    //
1087
    // Make the pin(s) be peripheral controlled.
1088
    //
1089
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1090
 
1091
    //
1092
    // Set the pad(s) for standard push-pull operation.
1093
    //
1094
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1095
}
1096
#endif
1097
 
1098
//*****************************************************************************
1099
//
1100
// Close the Doxygen group.
1101
//! @}
1102
//
1103
//*****************************************************************************

powered by: WebSVN 2.1.0

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