]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_SimpleLink_CC3220SF_CCS/ti/devices/cc32xx/driverlib/pin.c
Add SimpleLink CC3220SF demo.
[freertos] / FreeRTOS / Demo / CORTEX_M4_SimpleLink_CC3220SF_CCS / ti / devices / cc32xx / driverlib / pin.c
1 /*
2  * -------------------------------------------
3  *    CC3220 SDK - v0.10.00.00 
4  * -------------------------------------------
5  *
6  *  Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 
7  *  
8  *  Redistribution and use in source and binary forms, with or without 
9  *  modification, are permitted provided that the following conditions 
10  *  are met:
11  *
12  *    Redistributions of source code must retain the above copyright 
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  *    Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the 
17  *    documentation and/or other materials provided with the   
18  *    distribution.
19  *
20  *    Neither the name of Texas Instruments Incorporated nor the names of
21  *    its contributors may be used to endorse or promote products derived
22  *    from this software without specific prior written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
25  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
26  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
28  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
29  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
30  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
33  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
34  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *  
36  */
37 //*****************************************************************************
38 //
39 //  pin.c
40 //
41 //  Mapping of peripherals to pins.
42 //
43 //*****************************************************************************
44
45 //*****************************************************************************
46 //
47 //! \addtogroup pin_api
48 //! @{
49 //
50 //*****************************************************************************
51
52 #include "inc/hw_types.h"
53 #include "inc/hw_memmap.h"
54 #include "inc/hw_ocp_shared.h"
55 #include "pin.h"
56
57 //*****************************************************************************
58 // Macros
59 //*****************************************************************************
60 #define PAD_MODE_MASK           0x0000000F
61 #define PAD_STRENGTH_MASK       0x000000E0
62 #define PAD_TYPE_MASK           0x00000310
63 #define PAD_CONFIG_BASE         ((OCP_SHARED_BASE + \
64                                   OCP_SHARED_O_GPIO_PAD_CONFIG_0))
65
66 //*****************************************************************************
67 // PIN to PAD matrix
68 //*****************************************************************************
69 static const unsigned long g_ulPinToPadMap[64] =
70 {
71         10,11,12,13,14,15,16,17,255,255,18,
72         19,20,21,22,23,24,40,28,29,25,255,
73         255,255,255,255,255,255,255,255,255,255,255,
74         255,255,255,255,255,255,255,255,255,255,255,
75         31,255,255,255,255,0,255,32,30,255,1,
76         255,2,3,4,5,6,7,8,9
77 };
78
79
80 //*****************************************************************************
81 //
82 //! Configures pin mux for the specified pin.
83 //!
84 //! \param ulPin is a valid pin.
85 //! \param ulPinMode is one of the valid mode
86 //!
87 //! This function configures the pin mux that selects the peripheral function
88 //! associated with a particular SOC pin. Only one peripheral function at a
89 //! time can be associated with a pin, and each peripheral function should
90 //! only be associated with a single pin at a time.
91 //!
92 //! \return none
93 //
94 //*****************************************************************************
95 void PinModeSet(unsigned long ulPin,unsigned long ulPinMode)
96 {
97
98   unsigned long ulPad;
99
100   //
101   // Get the corresponding Pad
102   //
103   ulPad = g_ulPinToPadMap[ulPin & 0x3F];
104
105   //
106   // Calculate the register address
107   //
108   ulPad = ((ulPad << 2) + PAD_CONFIG_BASE);
109
110   //
111   // Set the mode.
112   //
113   HWREG(ulPad) = (((HWREG(ulPad) & ~PAD_MODE_MASK) |  ulPinMode) & ~(3<<10));
114
115 }
116
117 //*****************************************************************************
118 //
119 //! Gets current pin mux configuration of specified pin.
120 //!
121 //! \param ulPin is a valid pin.
122 //!
123 //! This function get the current configuration of the pin mux.
124 //!
125 //! \return Returns current pin mode if \e ulPin is valid, 0xFF otherwise.
126 //
127 //*****************************************************************************
128 unsigned long PinModeGet(unsigned long ulPin)
129 {
130
131   unsigned long ulPad;
132
133
134   //
135   // Get the corresponding Pad
136   //
137   ulPad = g_ulPinToPadMap[ulPin & 0x3F];
138
139
140   //
141   // Calculate the register address
142   //
143   ulPad = ((ulPad << 2) + PAD_CONFIG_BASE) ;
144
145   //
146   // return the mode.
147   //
148   return (HWREG(ulPad) & PAD_MODE_MASK);
149
150 }
151
152 //*****************************************************************************
153 //
154 //! Sets the direction of the specified pin(s).
155 //!
156 //! \param ulPin is one of the valid pin.
157 //! \param ulPinIO is the pin direction and/or mode.
158 //!
159 //! This function configures the specified pin(s) as either input only or
160 //! output only or it configures the pin to be under hardware control.
161 //!
162 //! The parameter \e ulPinIO is an enumerated data type that can be one of
163 //! the following values:
164 //!
165 //! - \b PIN_DIR_MODE_IN
166 //! - \b PIN_DIR_MODE_OUT
167 //! - \b PIN_DIR_MODE_HW
168 //!
169 //! where \b PIN_DIR_MODE_IN specifies that the pin is programmed as a
170 //! input only, \b PIN_DIR_MODE_OUT specifies that the pin is
171 //! programmed output only, and \b PIN_DIR_MODE_HW specifies that the pin is
172 //! placed under hardware control.
173 //!
174 //!
175 //! \return None.
176 //
177 //*****************************************************************************
178 void PinDirModeSet(unsigned long ulPin, unsigned long ulPinIO)
179 {
180   unsigned long ulPad;
181
182   //
183   // Get the corresponding Pad
184   //
185   ulPad = g_ulPinToPadMap[ulPin & 0x3F];
186
187   //
188   // Calculate the register address
189   //
190   ulPad = ((ulPad << 2) + PAD_CONFIG_BASE);
191
192   //
193   // Set the direction
194   //
195   HWREG(ulPad) = ((HWREG(ulPad) & ~0xC00) | ulPinIO);
196 }
197
198 //*****************************************************************************
199 //
200 //! Gets the direction of a pin.
201 //!
202 //! \param ulPin is one of the valid pin.
203 //!
204 //! This function gets the direction and control mode for a specified pin on
205 //! the selected GPIO port.  The pin can be configured as either an input only
206 //! or output only, or it can be under hardware control.  The type of control
207 //! and direction are returned as an enumerated data type.
208 //!
209 //! \return Returns one of the enumerated data types described for
210 //! GPIODirModeSet().
211 //
212 //*****************************************************************************
213 unsigned long PinDirModeGet(unsigned long ulPin)
214 {
215   unsigned long ulPad;
216
217   //
218   // Get the corresponding Pad
219   //
220   ulPad = g_ulPinToPadMap[ulPin & 0x3F];
221
222   //
223   // Calculate the register address
224   //
225   ulPad = ((ulPad << 2) + PAD_CONFIG_BASE);
226
227   //
228   // Return the direction
229   //
230   return ((HWREG(ulPad) & 0xC00));
231 }
232
233 //*****************************************************************************
234 //
235 //! Gets Pin output drive strength and Type
236 //!
237 //! \param ulPin is one of the valid pin
238 //! \param pulPinStrength is pointer to storage for output drive strength
239 //! \param pulPinType is pinter to storage for pin type
240 //!
241 //! This function gets the pin type and output drive strength for the pin
242 //! specified by \e ulPin parameter. Parameters \e pulPinStrength and
243 //! \e pulPinType corresponds to the values used in PinConfigSet().
244 //!
245 //!
246 //! \return None.
247 //
248 //*****************************************************************************
249 void PinConfigGet(unsigned long ulPin,unsigned long  *pulPinStrength,
250                                                 unsigned long *pulPinType)
251 {
252
253   unsigned long ulPad;
254
255
256   //
257   // Get the corresponding Pad
258   //
259   ulPad = g_ulPinToPadMap[ulPin & 0x3F];
260
261
262   //
263   // Calculate the register address
264   //
265   ulPad = ((ulPad << 2) + PAD_CONFIG_BASE);
266
267
268   //
269   // Get the type
270   //
271   *pulPinType = (HWREG(ulPad) & PAD_TYPE_MASK);
272
273   //
274   // Get the output drive strength
275   //
276   *pulPinStrength = (HWREG(ulPad) & PAD_STRENGTH_MASK);
277
278 }
279
280 //*****************************************************************************
281 //
282 //! Configure Pin output drive strength and Type
283 //!
284 //! \param ulPin is one of the valid pin
285 //! \param ulPinStrength is logical OR of valid output drive strengths.
286 //! \param ulPinType is one of the valid pin type.
287 //!
288 //!  This function sets the pin type and strength for the pin specified by
289 //! \e ulPin parameter.
290 //!
291 //! The parameter \e ulPinStrength should be one of the following
292 //! - \b PIN_STRENGTH_2MA
293 //! - \b PIN_STRENGTH_4MA
294 //! - \b PIN_STRENGTH_6MA
295 //!
296 //!
297 //! The parameter \e ulPinType should be one of the following
298 //! For standard type
299 //!
300 //! - \b PIN_TYPE_STD
301 //! - \b PIN_TYPE_STD_PU
302 //! - \b PIN_TYPE_STD_PD
303 //!
304 //! And for Open drain type
305 //!
306 //! - \b PIN_TYPE_OD
307 //! - \b PIN_TYPE_OD_PU
308 //! - \b PIN_TYPE_OD_PD
309 //!
310 //! \return None.
311 //
312 //*****************************************************************************
313 void PinConfigSet(unsigned long ulPin,unsigned long  ulPinStrength,
314                                                 unsigned long ulPinType)
315 {
316
317   unsigned long ulPad;
318
319   //
320   // Get the corresponding Pad
321   //
322   ulPad = g_ulPinToPadMap[ulPin & 0x3F];
323
324   //
325   // Write the register
326   //
327   if(ulPinType == PIN_TYPE_ANALOG)
328   {
329     //
330     // Isolate the input
331     //
332     HWREG(0x4402E144) |= ((0x80 << ulPad) & (0x1E << 8));
333
334     //
335     // Calculate the register address
336     //
337     ulPad = ((ulPad << 2) + PAD_CONFIG_BASE);
338
339     //
340     // Isolate the output
341     //
342     HWREG(ulPad) = 0xC00;
343
344   }
345   else
346   {
347     //
348     // Enable the input
349     //
350     HWREG(0x4402E144) &= ~((0x80 << ulPad) & (0x1E << 8));
351
352     //
353     // Calculate the register address
354     //
355     ulPad = ((ulPad << 2) + PAD_CONFIG_BASE);
356
357     //
358     // Write the configuration
359     //
360     HWREG(ulPad) = ((HWREG(ulPad) & ~(PAD_STRENGTH_MASK | PAD_TYPE_MASK)) |
361                                 (ulPinStrength | ulPinType ));
362   }
363
364
365 }
366
367 //*****************************************************************************
368 //
369 //! Sets the pin mode and configures the pin for use by UART peripheral
370 //!
371 //! \param ulPin is one of the valid pin.
372 //! \param ulPinMode is one of the valid pin mode.
373 //!
374 //! The UART pins must be properly configured for the peripheral to
375 //! function correctly.  This function provides a typical configuration for
376 //! those pin(s); other configurations may work as well depending upon the
377 //! board setup (for example, using the on-chip pull-ups).
378 //!
379 //!
380 //! \note This function cannot be used to turn any pin into a UART pin; it
381 //! only sets the pin mode and configures it for proper UART operation.
382 //!
383 //!
384 //! \return None.
385 //
386 //*****************************************************************************
387 void PinTypeUART(unsigned long ulPin,unsigned long ulPinMode)
388 {
389     //
390     // Set the pin to specified mode
391     //
392     PinModeSet(ulPin,ulPinMode);
393
394     //
395     // Set the pin for standard operation
396     //
397     PinConfigSet(ulPin,PIN_STRENGTH_2MA,PIN_TYPE_STD);
398 }
399
400
401 //*****************************************************************************
402 //
403 //! Sets the pin mode and configures the pin for use by I2C peripheral
404 //!
405 //! \param ulPin is one of the valid pin.
406 //! \param ulPinMode is one of the valid pin mode.
407 //!
408 //! The I2C pins must be properly configured for the peripheral to
409 //! function correctly.  This function provides a typical configuration for
410 //! the pin.
411 //!
412 //!
413 //! \note This function cannot be used to turn any pin into a I2C pin; it
414 //! only sets the pin mode and configures it for proper I2C operation.
415 //!
416 //!
417 //! \return None.
418 //
419 //*****************************************************************************
420 void PinTypeI2C(unsigned long ulPin,unsigned long ulPinMode)
421 {
422     //
423     // Set the pin to specified mode
424     //
425     PinModeSet(ulPin,ulPinMode);
426
427     //
428     // Set the pin for open-drain operation with a weak pull-up.
429     //
430     PinConfigSet(ulPin,PIN_STRENGTH_2MA,PIN_TYPE_OD_PU);
431 }
432
433
434 //*****************************************************************************
435 //
436 //! Sets the pin mode and configures the pin for use by SPI peripheral
437 //!
438 //! \param ulPin is one of the valid pin.
439 //! \param ulPinMode is one of the valid pin mode.
440 //!
441 //! The SPI pins must be properly configured for the peripheral to
442 //! function correctly.  This function provides a typical configuration for
443 //! those pin.
444 //!
445 //!
446 //! \note This function cannot be used to turn any pin into a SPI pin; it
447 //! only sets the pin mode and configures it for proper SPI operation.
448 //!
449 //!
450 //! \return None.
451 //
452 //*****************************************************************************
453 void PinTypeSPI(unsigned long ulPin,unsigned long ulPinMode)
454 {
455
456     //
457     // Set the pin to specified mode
458     //
459     PinModeSet(ulPin,ulPinMode);
460
461     //
462     // Set the pin for standard operation
463     //
464     PinConfigSet(ulPin,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD);
465
466 }
467
468
469 //*****************************************************************************
470 //
471 //! Sets the pin mode and configures the pin for use by I2S peripheral
472 //!
473 //! \param ulPin is one of the valid pin.
474 //! \param ulPinMode is one of the valid pin mode.
475 //!
476 //! The I2S pins must be properly configured for the peripheral to
477 //! function correctly.  This function provides a typical configuration for
478 //! those pin.
479 //!
480 //!
481 //! \note This function cannot be used to turn any pin into a I2S pin; it
482 //! only sets the pin mode and configures it for proper I2S operation.
483 //!
484 //! \return None.
485 //
486 //*****************************************************************************
487 void PinTypeI2S(unsigned long ulPin,unsigned long ulPinMode)
488 {
489
490     //
491     // Set the pin to specified mode
492     //
493     PinModeSet(ulPin,ulPinMode);
494
495     //
496     // Set the pin for standard operation
497     //
498     PinConfigSet(ulPin,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD);
499
500 }
501
502
503 //*****************************************************************************
504 //
505 //! Sets the pin mode and configures the pin for use by Timer peripheral
506 //!
507 //! \param ulPin is one of the valid pin.
508 //! \param ulPinMode is one of the valid pin mode.
509 //!
510 //! The timer PWM pins must be properly configured for the Timer peripheral to
511 //! function correctly.  This function provides a typical configuration for
512 //! those pin; other configurations may work as well depending upon the
513 //! board setup (for example, using the on-chip pull-ups).
514 //!
515 //!
516 //! \note This function cannot be used to turn any pin into a timer PWM pin; it
517 //! only sets the pin mode and configures it for proper timer PWM operation.
518 //!
519 //! \return None.
520 //
521 //*****************************************************************************
522 void PinTypeTimer(unsigned long ulPin,unsigned long ulPinMode)
523 {
524
525     //
526     // Set the pin to specified mode
527     //
528     PinModeSet(ulPin,ulPinMode);
529
530     //
531     // Set the pin for standard operation
532     //
533     PinConfigSet(ulPin,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD);
534 }
535
536
537 //*****************************************************************************
538 //
539 //! Sets the pin mode and configures the pin for use by Camera peripheral
540 //!
541 //! \param ulPin is one of the valid pin.
542 //! \param ulPinMode is one of the valid pin mode.
543 //!
544 //! The Camera pins must be properly configured for the peripheral to
545 //! function correctly.  This function provides a typical configuration for
546 //! those pin.
547 //!
548 //!
549 //! \note This function cannot be used to turn any pin into a Camera pin; it
550 //! only sets the pin mode and configures it for proper Camera operation.
551 //!
552 //! \return None.
553 //
554 //*****************************************************************************
555 void PinTypeCamera(unsigned long ulPin,unsigned long ulPinMode)
556 {
557
558     //
559     // Set the pin to specified mode
560     //
561     PinModeSet(ulPin,ulPinMode);
562
563     //
564     // Set the pin for standard operation
565     //
566     PinConfigSet(ulPin,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD);
567
568 }
569
570
571 //*****************************************************************************
572 //
573 //! Sets the pin mode and configures the pin for use by GPIO peripheral
574 //!
575 //! \param ulPin is one of the valid pin.
576 //! \param ulPinMode is one of the valid pin mode.
577 //! \param bOpenDrain is one to decide either OpenDrain or STD
578 //!
579 //! The GPIO pins must be properly configured for the peripheral to
580 //! function correctly.  This function provides a typical configuration for
581 //! those pin.
582 //!
583 //!
584 //! \return None.
585 //
586 //*****************************************************************************
587 void PinTypeGPIO(unsigned long ulPin,unsigned long ulPinMode,tBoolean bOpenDrain)
588 {
589
590     //
591     // Set the pin for standard push-pull operation.
592     //
593     if(bOpenDrain)
594     {
595             PinConfigSet(ulPin, PIN_STRENGTH_2MA, PIN_TYPE_OD);
596     }
597     else
598     {
599             PinConfigSet(ulPin, PIN_STRENGTH_2MA, PIN_TYPE_STD);
600     }
601
602     //
603     // Set the pin to specified mode
604     //
605     PinModeSet(ulPin, ulPinMode);
606
607 }
608
609 //*****************************************************************************
610 //
611 //! Sets the pin mode and configures the pin for use by ADC
612 //!
613 //! \param ulPin is one of the valid pin.
614 //! \param ulPinMode is one of the valid pin mode.
615 //!
616 //! The ADC pins must be properly configured for the peripheral to
617 //! function correctly.  This function provides a typical configuration for
618 //! those pin.
619 //!
620 //!
621 //! \note This function cannot be used to turn any pin into a ADC pin; it
622 //! only sets the pin mode and configures it for proper ADC operation.
623 //!
624 //! \return None.
625 //
626 //*****************************************************************************
627 void PinTypeADC(unsigned long ulPin,unsigned long ulPinMode)
628 {
629   //
630   // Configure the Pin
631   //
632   PinConfigSet(ulPin,PIN_STRENGTH_2MA,PIN_TYPE_ANALOG);
633 }
634
635 //*****************************************************************************
636 //
637 //! Sets the pin mode and configures the pin for use by SD Host peripheral
638 //!
639 //! \param ulPin is one of the valid pin.
640 //! \param ulPinMode is one of the valid pin mode.
641 //!
642 //! The MMC pins must be properly configured for the peripheral to
643 //! function correctly.  This function provides a typical configuration for
644 //! those pin.
645 //!
646 //!
647 //! \note This function cannot be used to turn any pin into a SD Host pin; it
648 //! only sets the pin mode and configures it for proper SD Host operation.
649 //!
650 //! \return None.
651 //
652 //*****************************************************************************
653 void PinTypeSDHost(unsigned long ulPin,unsigned long ulPinMode)
654 {
655   //
656   // Set pin mode
657   //
658   PinModeSet(ulPin,ulPinMode);
659
660   //
661   // Configure the Pin
662   //
663   PinConfigSet(ulPin,PIN_STRENGTH_2MA,PIN_TYPE_STD);
664
665 }
666
667
668 //*****************************************************************************
669 //
670 //! Sets the hysteresis for all the pins
671 //!
672 //! \param ulHysteresis is one of the valid predefined hysterisys values
673 //!
674 //! This function sets the hysteresis vlaue for all the pins. The parameter
675 //! \e ulHysteresis can be on one the following:
676 //! -\b PIN_HYSTERESIS_OFF - To turn Off hysteresis, default on POR
677 //! -\b PIN_HYSTERESIS_10  - To turn On hysteresis, 10%
678 //! -\b PIN_HYSTERESIS_20  - To turn On hysteresis, 20%
679 //! -\b PIN_HYSTERESIS_30  - To turn On hysteresis, 30%
680 //! -\b PIN_HYSTERESIS_40  - To turn On hysteresis, 40%
681 //!
682 //! \return None.
683 //
684 //*****************************************************************************
685 void PinHysteresisSet(unsigned long ulHysteresis)
686 {
687   unsigned long ulRegValue;
688
689   //
690   // Read the current value
691   //
692   ulRegValue =  (HWREG( OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CMN_CONFIG )
693                 & ~(0x0000001C));
694
695   //
696   // Set the new Hysteresis
697   //
698   if( ulHysteresis != PIN_HYSTERESIS_OFF )
699   {
700       ulRegValue |= (ulHysteresis & 0x0000001C);
701   }
702
703   //
704   // Write the new value
705   //
706   HWREG( OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CMN_CONFIG ) = ulRegValue;
707 }
708
709 //*****************************************************************************
710 //
711 //! Sets the level of the pin when locked
712 //!
713 //! \param ulPin is one of the valid pin.
714 //! \param ucLevel is the level the pin drives when locked
715 //!
716 //! This function sets the pin level when the pin is locked using
717 //! \sa PinLock() API.
718 //!
719 //! By default all pins are set to drive 0.
720 //!
721 //! \note Use case is to park the pins when entering LPDS
722 //!
723 //! \return None.
724 //
725 //*****************************************************************************
726 void PinLockLevelSet(unsigned long ulPin, unsigned char ucLevel)
727 {
728   unsigned long ulPad;
729
730   //
731   // Supported only in ES2.00 and Later devices i.e. ROM Version 2.x.x or greater
732   //
733   if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
734   {
735     //
736     // Get the corresponding Pad
737     //
738     ulPad = g_ulPinToPadMap[ulPin & 0x3F];
739
740     //
741     // Get the required bit
742     //
743     ulPad = 1 << ulPad;
744
745     if(ucLevel)
746     {
747       HWREG( OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_6 ) |= ulPad;
748     }
749     else
750     {
751       HWREG( OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_6 ) &= ~ulPad;
752     }
753   }
754 }
755
756 //*****************************************************************************
757 //
758 //! Locks all the pins to configured level(s).
759 //!
760 //! \param ulOutEnable the bit-packed representation of pins to be set as output
761 //!
762 //! This function locks all the pins to the pre-configure level. By default
763 //! the pins are set to drive 0. Default level can be changed using
764 //! \sa PinLockLevelSet() API.
765 //!
766 //! The \e ulOutEnable paramter is bit-packed representation of pins that
767 //! are required to be enabled as output. If a bit is set 1, the corresponding
768 //! pin (as shown below) are set  and locked as output.
769 //!
770 //!    |------|-----------------------------------------------|
771 //!    |  Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|
772 //!    |------|-----------------------------------------------|
773 //!    |  Pin |xx|xx|20|19|30|29|21|17|16|15|14|13|12|11|08|07|
774 //!    |------|-----------------------------------------------|
775 //!
776 //!    |------|-----------------------------------------------|
777 //!    |  Bit |15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
778 //!    |------|-----------------------------------------------|
779 //!    |  Pin |06|05|04|03|02|01|64|63|62|61|60|59|58|57|55|50|
780 //!    |------|-----------------------------------------------|
781 //!
782 //!
783 //! \note Use case is to park the pins when entering LPDS
784 //!
785 //! \return None.
786 //
787 //*****************************************************************************
788 void PinLock(unsigned long ulOutEnable)
789 {
790   //
791   // Supported only in ES2.00 and Later devices i.e. ROM Version 2.x.x or greater
792   //
793   if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
794   {
795     //
796     // Enable/disable the pin(s) output
797     //
798     HWREG( OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_7 ) = ~ulOutEnable;
799
800     //
801     // Lock the pins to selected levels
802     //
803     HWREG( OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_5 ) |= (3 << 24);
804   }
805 }
806
807 //*****************************************************************************
808 //
809 //! Unlocks all the pins.
810 //!
811 //! This function unlocks all the pins and can be used for peripheral function.
812 //!
813 //! By default all the pins are in unlocked state.
814 //!
815 //! \note Use case is to un-park the pins when exiting LPDS
816 //!
817 //! \return None.
818 //
819 //*****************************************************************************
820 void PinUnlock()
821 {
822   //
823   // Supported only in ES2.00 and Later devices i.e. ROM Version 2.x.x or greater
824   //
825   if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
826   {
827     //
828     // Unlock the pins
829     //
830     HWREG( OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_5 ) &= ~(3 << 24);
831   }
832 }
833
834 //*****************************************************************************
835 //
836 // Gets pad number from pin number
837 //
838 // \param ulPin is a valid pin number
839 //
840 // This function return the pad corresponding to the specified pin
841 //
842 // \return Pad number on success, 0xFF otherwise
843 //
844 //*****************************************************************************
845 unsigned long PinToPadGet(unsigned long ulPin)
846 {
847         //
848     // Return the corresponding Pad
849     //
850     return g_ulPinToPadMap[ulPin & 0x3F];
851 }
852
853
854 //*****************************************************************************
855 //
856 // Gets pin number from pad number
857 //
858 // \param ulPad is a valid pad number
859 //
860 // This function return the pin corresponding to the specified pad
861 //
862 // \return Pin number on success, 0xFF otherwise
863 //
864 //*****************************************************************************
865 unsigned long PinFromPadGet(unsigned long ulPad)
866 {
867         unsigned long ulPin;
868         
869         //
870         // search and return the pin number
871         //
872         for(ulPin=0; ulPin < sizeof(g_ulPinToPadMap)/4; ulPin++)
873         {
874                 if(g_ulPinToPadMap[ulPin] == ulPad)
875                 {
876                         return ulPin;
877                 }
878         }
879         
880         return 0xFF;
881 }
882
883 //*****************************************************************************
884 //
885 // Close the Doxygen group.
886 //! @}
887 //
888 //*****************************************************************************