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