]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_boardcontrol.c
456fff1e0e73ffea880c85a7d69f1d4e86725f6e
[freertos] / FreeRTOS / Demo / CORTEX_EFMG890F128_IAR / bsp / dvk_boardcontrol.c
1 /**************************************************************************//**\r
2  * @file\r
3  * @brief DVK Peripheral Board Control API implementation\r
4  * @author Energy Micro AS\r
5  * @version 1.0.1\r
6  ******************************************************************************\r
7  * @section License\r
8  * <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>\r
9  ******************************************************************************\r
10  *\r
11  * This source code is the property of Energy Micro AS. The source and compiled\r
12  * code may only be used on Energy Micro "EFM32" microcontrollers.\r
13  *\r
14  * This copyright notice may not be removed from the source code nor changed.\r
15  *\r
16  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no\r
17  * obligation to support this Software. Energy Micro AS is providing the\r
18  * Software "AS IS", with no express or implied warranties of any kind,\r
19  * including, but not limited to, any implied warranties of merchantability\r
20  * or fitness for any particular purpose or warranties against infringement\r
21  * of any proprietary rights of a third party.\r
22  *\r
23  * Energy Micro AS will not be liable for any consequential, incidental, or\r
24  * special damages, or any other relief, or for any claim by any third party,\r
25  * arising from your use of this Software.\r
26  *\r
27  *****************************************************************************/\r
28 \r
29 #include "efm32.h"\r
30 #include "dvk.h"\r
31 #include "dvk_boardcontrol.h"\r
32 #include "dvk_bcregisters.h"\r
33 \r
34 /**************************************************************************//**\r
35  * @brief Enable EFM32 access to periheral on DVK board\r
36  * @param peri Peripheral to enable\r
37  *****************************************************************************/\r
38 void DVK_enablePeripheral(DVKPeripheral peri)\r
39 {\r
40   uint16_t bit;\r
41   uint16_t tmp;\r
42 \r
43   /* Calculate which bit to set */\r
44   bit = (uint16_t) peri;\r
45 \r
46   /* Read peripheral control register */\r
47   tmp = DVK_readRegister(BC_PERCTRL);\r
48 \r
49   /* Enable peripheral */\r
50   tmp |= bit;\r
51 \r
52   /* Special case for RS232, if enabled disable shutdown */\r
53   if ((peri == DVK_RS232A) || (peri == DVK_RS232B))\r
54   {\r
55     /* clear shutdown bit */\r
56     tmp &= ~(BC_PERCTRL_RS232_SHUTDOWN);\r
57   }\r
58 \r
59   /* Special case for IRDA if enabled disable shutdown */\r
60   if (peri == DVK_IRDA)\r
61   {\r
62     /* clear shutdown bit */\r
63     tmp &= ~(BC_PERCTRL_IRDA_SHUTDOWN);\r
64   }\r
65 \r
66   DVK_writeRegister(BC_PERCTRL, tmp);\r
67 }\r
68 \r
69 /**************************************************************************//**\r
70  * @brief Disable EFM32 access to peripheral on DVK board\r
71  * @param peri Peripheral to disable\r
72  *****************************************************************************/\r
73 void DVK_disablePeripheral(DVKPeripheral peri)\r
74 {\r
75   uint16_t bit;\r
76   uint16_t tmp;\r
77 \r
78   /* Calculate which bit to set */\r
79   bit = (uint16_t) peri;\r
80 \r
81   /* Read peripheral control register */\r
82   tmp = DVK_readRegister(BC_PERCTRL);\r
83 \r
84   /* Disable peripheral */\r
85   tmp &= ~(bit);\r
86 \r
87   /* Special case for RS232, if enabled disable shutdown */\r
88   if ((peri == DVK_RS232A) || (peri == DVK_RS232B))\r
89   {\r
90     /* Set shutdown bit */\r
91     tmp |= (BC_PERCTRL_RS232_SHUTDOWN);\r
92   }\r
93 \r
94   /* Special case for IRDA */\r
95   if (peri == DVK_IRDA)\r
96   {\r
97     /* Set shutdown bit */\r
98     tmp |= (BC_PERCTRL_IRDA_SHUTDOWN);\r
99   }\r
100 \r
101 \r
102   DVK_writeRegister(BC_PERCTRL, tmp);\r
103 }\r
104 \r
105 \r
106 /**************************************************************************//**\r
107  * @brief Enable BUS access\r
108  *****************************************************************************/\r
109 void DVK_enableBus(void)\r
110 {\r
111   /* Enable bus access */\r
112   DVK_writeRegister(BC_BUS_CFG, 1);\r
113 }\r
114 \r
115 \r
116 /**************************************************************************//**\r
117  * @brief Disable BUS access\r
118  *****************************************************************************/\r
119 void DVK_disableBus(void)\r
120 {\r
121   DVK_writeRegister(BC_BUS_CFG, 0);\r
122 }\r
123 \r
124 \r
125 /**************************************************************************//**\r
126  * @brief Inform AEM about current energy mode\r
127  * @param energyMode What energy mode we are going to use next\r
128  *****************************************************************************/\r
129 void DVK_setEnergyMode(uint16_t energyMode)\r
130 {\r
131   DVK_writeRegister(BC_EM, energyMode);\r
132 }\r
133 \r
134 \r
135 /**************************************************************************//**\r
136  * @brief Get status of bush buttons\r
137  * @return Status of push buttons\r
138  *****************************************************************************/\r
139 uint16_t DVK_getPushButtons(void)\r
140 {\r
141   uint16_t tmp;\r
142 \r
143   tmp = (~(DVK_readRegister(BC_PUSHBUTTON))) & 0x000f;\r
144   return tmp;\r
145 }\r
146 \r
147 /**************************************************************************//**\r
148  * @brief Get joystick button status\r
149  * @return Joystick controller status\r
150  *****************************************************************************/\r
151 uint16_t DVK_getJoystick(void)\r
152 {\r
153   uint16_t tmp;\r
154 \r
155   tmp = (~(DVK_readRegister(BC_JOYSTICK))) & 0x001f;\r
156   return tmp;\r
157 }\r
158 \r
159 /**************************************************************************//**\r
160  * @brief Get dipswitch status\r
161  *        The DIP switches are free for user programmable purposes\r
162  * @return Joystick controller status\r
163  *****************************************************************************/\r
164 uint16_t DVK_getDipSwitch(void)\r
165 {\r
166   uint16_t tmp;\r
167 \r
168   tmp = (~(DVK_readRegister(BC_DIPSWITCH))) & 0x00ff;\r
169   return tmp;\r
170 }\r
171 \r
172 /**************************************************************************//**\r
173  * @brief Sets user leds\r
174  * @param leds 16-bits which enables or disables the board "User leds"\r
175  *****************************************************************************/\r
176 void DVK_setLEDs(uint16_t leds)\r
177 {\r
178   DVK_writeRegister(BC_LED, leds);\r
179 }\r
180 \r
181 /**************************************************************************//**\r
182  * @brief Get status of user LEDs\r
183  * @return Status of 16 user leds, bit 1 = on, bit 0 = off\r
184  *****************************************************************************/\r
185 uint16_t DVK_getLEDs(void)\r
186 {\r
187   return DVK_readRegister(BC_LED);\r
188 }\r
189 \r
190 /**************************************************************************//**\r
191  * @brief Enable "Control" buttons/joystick/dip switch interrupts\r
192  * @param flags Board control interrupt flags, BC_INTEN_<something>\r
193  *****************************************************************************/\r
194 void DVK_enableInterrupt(uint16_t flags)\r
195 {\r
196   uint16_t tmp;\r
197 \r
198   /* Add flags to interrupt enable register */\r
199   tmp  = DVK_readRegister(BC_INTEN);\r
200   tmp |= flags;\r
201   DVK_writeRegister(BC_INTEN, tmp);\r
202 }\r
203 \r
204 /**************************************************************************//**\r
205  * @brief Disable "Control" buttons/joystick/dip switch interrupts\r
206  * @param flags Board control interrupt flags, BC_INTEN_<something>\r
207  *****************************************************************************/\r
208 void DVK_disableInterrupt(uint16_t flags)\r
209 {\r
210   uint16_t tmp;\r
211 \r
212   /* Clear flags from interrupt enable register */\r
213   tmp   = DVK_readRegister(BC_INTEN);\r
214   flags = ~(flags);\r
215   tmp  &= flags;\r
216   DVK_writeRegister(BC_INTEN, tmp);\r
217 }\r
218 \r
219 /**************************************************************************//**\r
220  * @brief Clear interrupts\r
221  * @param flags Board control interrupt flags, BC_INTEN_<something>\r
222  *****************************************************************************/\r
223 void DVK_clearInterruptFlags(uint16_t flags)\r
224 {\r
225   DVK_writeRegister(BC_INTFLAG, flags);\r
226 }\r
227 \r
228 /**************************************************************************//**\r
229  * @brief Read interrupt flags\r
230  * @return Returns currently triggered interrupts\r
231  *****************************************************************************/\r
232 uint16_t DVK_getInterruptFlags(void)\r
233 {\r
234   return DVK_readRegister(BC_INTFLAG);\r
235 }\r