]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_LM3S102_GCC/hw_include/pdc.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_LM3S102_GCC / hw_include / pdc.c
1 //*****************************************************************************\r
2 //\r
3 // pdc.c - Driver for the Peripheral Device Controller (PDC) on the Stellaris\r
4 //         development board.\r
5 //\r
6 // Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.\r
7 //\r
8 // Software License Agreement\r
9 //\r
10 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
11 // exclusively on LMI's Stellaris Family of microcontroller products.\r
12 //\r
13 // The software is owned by LMI and/or its suppliers, and is protected under\r
14 // applicable copyright laws.  All rights are reserved.  Any use in violation\r
15 // of the foregoing restrictions may subject the user to criminal sanctions\r
16 // under applicable laws, as well as to civil liability for the breach of the\r
17 // terms and conditions of this license.\r
18 //\r
19 // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
20 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
22 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
23 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
24 //\r
25 // This is part of revision 523 of the Stellaris Driver Library.\r
26 //\r
27 //*****************************************************************************\r
28 \r
29 //*****************************************************************************\r
30 //\r
31 //! \addtogroup utilities_api\r
32 //! @{\r
33 //\r
34 //*****************************************************************************\r
35 \r
36 #include "hw_memmap.h"\r
37 #include "hw_types.h"\r
38 #include "gpio.h"\r
39 #include "ssi.h"\r
40 #include "sysctl.h"\r
41 #include "pdc.h"\r
42 \r
43 //*****************************************************************************\r
44 //\r
45 //! Initializes the connection to the PDC.\r
46 //!\r
47 //! This function will enable clocking to the SSI and GPIO A modules, configure\r
48 //! the GPIO pins to be used for an SSI interface, and it will configure the\r
49 //! SSI as a 1Mb master device, operating in MOTO mode.  It will also enable\r
50 //! the SSI module, and will enable the chip select for the PDC on the\r
51 //! Stellaris development board.\r
52 //!\r
53 //! This function is contained in <tt>utils/pdc.c</tt>, with\r
54 //! <tt>utils/pdc.h</tt> containing the API definition for use by applications.\r
55 //!\r
56 //! \return None.\r
57 //\r
58 //*****************************************************************************\r
59 void\r
60 PDCInit(void)\r
61 {\r
62     //\r
63     // Enable the peripherals used to drive the PDC.\r
64     //\r
65     SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI);\r
66     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);\r
67 \r
68     //\r
69     // Configure the appropriate pins to be SSI instead of GPIO.\r
70     //\r
71     GPIODirModeSet(GPIO_PORTA_BASE, SSI_CLK | SSI_TX | SSI_RX,\r
72                    GPIO_DIR_MODE_HW);\r
73     GPIODirModeSet(GPIO_PORTA_BASE, SSI_CS, GPIO_DIR_MODE_OUT);\r
74     GPIOPadConfigSet(GPIO_PORTA_BASE, SSI_CLK, GPIO_STRENGTH_4MA,\r
75                      GPIO_PIN_TYPE_STD_WPU);\r
76 \r
77     //\r
78     // Configure the SSI port.\r
79     //\r
80     SSIConfig(SSI_BASE, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8);\r
81     SSIEnable(SSI_BASE);\r
82 \r
83     //\r
84     // Reset the PDC SSI state machine.  The chip select needs to be held low\r
85     // for 100ns; the procedure call overhead more than accounts for this time.\r
86     //\r
87     GPIOPinWrite(GPIO_PORTA_BASE, PDC_CS, 0);\r
88     GPIOPinWrite(GPIO_PORTA_BASE, PDC_CS, PDC_CS);\r
89 }\r
90 \r
91 //*****************************************************************************\r
92 //\r
93 //! Write a PDC register.\r
94 //!\r
95 //! \param ucAddr specifies the PDC register to write.\r
96 //! \param ucData specifies the data to write.\r
97 //!\r
98 //! This function will perform the SSI transfers required to write a register\r
99 //! in the PDC on the Stellaris development board.\r
100 //!\r
101 //! This function is contained in <tt>utils/pdc.c</tt>, with\r
102 //! <tt>utils/pdc.h</tt> containing the API definition for use by applications.\r
103 //!\r
104 //! \return None.\r
105 //\r
106 //*****************************************************************************\r
107 void\r
108 PDCWrite(unsigned char ucAddr, unsigned char ucData)\r
109 {\r
110     unsigned long ulTemp;\r
111 \r
112     //\r
113     // Send address and write command.\r
114     //\r
115     SSIDataPut(SSI_BASE, (ucAddr & 0x0F) | PDC_WR);\r
116 \r
117     //\r
118     // Write the data.\r
119     //\r
120     SSIDataPut(SSI_BASE, ucData);\r
121 \r
122     //\r
123     // Flush data read during address write.\r
124     //\r
125     SSIDataGet(SSI_BASE, &ulTemp);\r
126 \r
127     //\r
128     // Flush data read during data write.\r
129     //\r
130     SSIDataGet(SSI_BASE, &ulTemp);\r
131 }\r
132 \r