]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/CMSISv2p10_LPC18xx_DriverLib/src/debug_frmwrk.c
a50358ed682380b5443967283144e179009709fc
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / CMSISv2p10_LPC18xx_DriverLib / src / debug_frmwrk.c
1 /**********************************************************************\r
2 * $Id$          debug_frmwrk.c          2011-06-02\r
3 *//**\r
4 * @file         debug_frmwrk.c\r
5 * @brief        Contains some utilities that used for debugging through UART\r
6 * @version      1.0\r
7 * @date         02. June. 2011\r
8 * @author       NXP MCU SW Application Team\r
9 *\r
10 * Copyright(C) 2011, NXP Semiconductor\r
11 * All rights reserved.\r
12 *\r
13 ***********************************************************************\r
14 * Software that is described herein is for illustrative purposes only\r
15 * which provides customers with programming information regarding the\r
16 * products. This software is supplied "AS IS" without any warranties.\r
17 * NXP Semiconductors assumes no responsibility or liability for the\r
18 * use of the software, conveys no license or title under any patent,\r
19 * copyright, or mask work right to the product. NXP Semiconductors\r
20 * reserves the right to make changes in the software without\r
21 * notification. NXP Semiconductors also make no representation or\r
22 * warranty that such application will be suitable for the specified\r
23 * use without further testing or modification.\r
24 **********************************************************************/\r
25 \r
26 /* Peripheral group ----------------------------------------------------------- */\r
27 /** @addtogroup DEBUG_FRMWRK\r
28  * @{\r
29  */\r
30 \r
31 #ifndef _DEBUG_FRMWRK_\r
32 #define _DEBUG_FRMWRK_\r
33 \r
34 /* Includes ------------------------------------------------------------------- */\r
35 #include "debug_frmwrk.h"\r
36 #include "lpc18xx_scu.h"\r
37 #include <stdarg.h>\r
38 #include <stdio.h>\r
39 \r
40 #ifdef CDC_DEBUG_MESSEGES\r
41 #include "usbhw.h"\r
42 #include "cdcuser.h"\r
43 #include "CDCdemo.h"\r
44 #include "lpc18xx_utils.h"\r
45 #include <string.h>\r
46 #endif\r
47 \r
48 /* Debug framework */\r
49 \r
50 void (*_db_msg)(LPC_USARTn_Type *UARTx, const void *s);\r
51 void (*_db_msg_)(LPC_USARTn_Type *UARTx, const void *s);\r
52 void (*_db_char)(LPC_USARTn_Type *UARTx, uint8_t ch);\r
53 void (*_db_dec)(LPC_USARTn_Type *UARTx, uint8_t decn);\r
54 void (*_db_dec_16)(LPC_USARTn_Type *UARTx, uint16_t decn);\r
55 void (*_db_dec_32)(LPC_USARTn_Type *UARTx, uint32_t decn);\r
56 void (*_db_hex)(LPC_USARTn_Type *UARTx, uint8_t hexn);\r
57 void (*_db_hex_16)(LPC_USARTn_Type *UARTx, uint16_t hexn);\r
58 void (*_db_hex_32)(LPC_USARTn_Type *UARTx, uint32_t hexn);\r
59 uint8_t (*_db_get_char)(LPC_USARTn_Type *UARTx);\r
60 \r
61 \r
62 \r
63 /*********************************************************************//**\r
64  * @brief               Puts a character to UART port\r
65  * @param[in]   UARTx   Pointer to UART peripheral\r
66  * @param[in]   ch              Character to put\r
67  * @return              None\r
68  **********************************************************************/\r
69 void UARTPutChar (LPC_USARTn_Type *UARTx, uint8_t ch)\r
70 {\r
71         UART_Send(UARTx, &ch, 1, BLOCKING);\r
72 }\r
73 \r
74 \r
75 /*********************************************************************//**\r
76  * @brief               Get a character to UART port\r
77  * @param[in]   UARTx   Pointer to UART peripheral\r
78  * @return              character value that returned\r
79  **********************************************************************/\r
80 uint8_t UARTGetChar (LPC_USARTn_Type *UARTx)\r
81 {\r
82         uint8_t tmp = 0;\r
83         UART_Receive(UARTx, &tmp, 1, BLOCKING);\r
84         return(tmp);\r
85 }\r
86 \r
87 \r
88 /*********************************************************************//**\r
89  * @brief               Puts a string to UART port\r
90  * @param[in]   UARTx   Pointer to UART peripheral\r
91  * @param[in]   str     string to put\r
92  * @return              None\r
93  **********************************************************************/\r
94 void UARTPuts(LPC_USARTn_Type *UARTx, const void *str)\r
95 {\r
96 #ifdef CDC_DEBUG_MESSEGES\r
97         int num_of_bytes=0;\r
98         num_of_bytes = strlen(str);\r
99         timer_delay_us(num_of_bytes);\r
100                 \r
101         USB_WriteEP (CDC_DEP_IN, (unsigned char *)str, num_of_bytes);\r
102 #else\r
103         uint8_t *s = (uint8_t *) str;\r
104 \r
105         while (*s)\r
106         {\r
107                 UARTPutChar(UARTx, *s++);\r
108         }\r
109 #endif  \r
110 }\r
111 \r
112 \r
113 /*********************************************************************//**\r
114  * @brief               Puts a string to UART port and print new line\r
115  * @param[in]   UARTx   Pointer to UART peripheral\r
116  * @param[in]   str             String to put\r
117  * @return              None\r
118  **********************************************************************/\r
119 void UARTPuts_(LPC_USARTn_Type *UARTx, const void *str)\r
120 {\r
121         UARTPuts (UARTx, str);\r
122         UARTPuts (UARTx, "\n\r");\r
123 }\r
124 \r
125 \r
126 /*********************************************************************//**\r
127  * @brief               Puts a decimal number to UART port\r
128  * @param[in]   UARTx   Pointer to UART peripheral\r
129  * @param[in]   decnum  Decimal number (8-bit long)\r
130  * @return              None\r
131  **********************************************************************/\r
132 void UARTPutDec(LPC_USARTn_Type *UARTx, uint8_t decnum)\r
133 {\r
134         uint8_t c1=decnum%10;\r
135         uint8_t c2=(decnum/10)%10;\r
136         uint8_t c3=(decnum/100)%10;\r
137         UARTPutChar(UARTx, '0'+c3);\r
138         UARTPutChar(UARTx, '0'+c2);\r
139         UARTPutChar(UARTx, '0'+c1);\r
140 }\r
141 \r
142 /*********************************************************************//**\r
143  * @brief               Puts a decimal number to UART port\r
144  * @param[in]   UARTx   Pointer to UART peripheral\r
145  * @param[in]   decnum  Decimal number (8-bit long)\r
146  * @return              None\r
147  **********************************************************************/\r
148 void UARTPutDec16(LPC_USARTn_Type *UARTx, uint16_t decnum)\r
149 {\r
150         uint8_t c1=decnum%10;\r
151         uint8_t c2=(decnum/10)%10;\r
152         uint8_t c3=(decnum/100)%10;\r
153         uint8_t c4=(decnum/1000)%10;\r
154         uint8_t c5=(decnum/10000)%10;\r
155         UARTPutChar(UARTx, '0'+c5);\r
156         UARTPutChar(UARTx, '0'+c4);\r
157         UARTPutChar(UARTx, '0'+c3);\r
158         UARTPutChar(UARTx, '0'+c2);\r
159         UARTPutChar(UARTx, '0'+c1);\r
160 }\r
161 \r
162 /*********************************************************************//**\r
163  * @brief               Puts a decimal number to UART port\r
164  * @param[in]   UARTx   Pointer to UART peripheral\r
165  * @param[in]   decnum  Decimal number (8-bit long)\r
166  * @return              None\r
167  **********************************************************************/\r
168 void UARTPutDec32(LPC_USARTn_Type *UARTx, uint32_t decnum)\r
169 {\r
170         uint8_t c1=decnum%10;\r
171         uint8_t c2=(decnum/10)%10;\r
172         uint8_t c3=(decnum/100)%10;\r
173         uint8_t c4=(decnum/1000)%10;\r
174         uint8_t c5=(decnum/10000)%10;\r
175         uint8_t c6=(decnum/100000)%10;\r
176         uint8_t c7=(decnum/1000000)%10;\r
177         uint8_t c8=(decnum/10000000)%10;\r
178         uint8_t c9=(decnum/100000000)%10;\r
179         uint8_t c10=(decnum/1000000000)%10;\r
180         UARTPutChar(UARTx, '0'+c10);\r
181         UARTPutChar(UARTx, '0'+c9);\r
182         UARTPutChar(UARTx, '0'+c8);\r
183         UARTPutChar(UARTx, '0'+c7);\r
184         UARTPutChar(UARTx, '0'+c6);\r
185         UARTPutChar(UARTx, '0'+c5);\r
186         UARTPutChar(UARTx, '0'+c4);\r
187         UARTPutChar(UARTx, '0'+c3);\r
188         UARTPutChar(UARTx, '0'+c2);\r
189         UARTPutChar(UARTx, '0'+c1);\r
190 }\r
191 \r
192 /*********************************************************************//**\r
193  * @brief               Puts a hex number to UART port\r
194  * @param[in]   UARTx   Pointer to UART peripheral\r
195  * @param[in]   hexnum  Hex number (8-bit long)\r
196  * @return              None\r
197  **********************************************************************/\r
198 void UARTPutHex (LPC_USARTn_Type *UARTx, uint8_t hexnum)\r
199 {\r
200         uint8_t nibble, i;\r
201 \r
202         UARTPuts(UARTx, "0x");\r
203         i = 1;\r
204         do {\r
205                 nibble = (hexnum >> (4*i)) & 0x0F;\r
206                 UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));\r
207         } while (i--);\r
208 }\r
209 \r
210 \r
211 /*********************************************************************//**\r
212  * @brief               Puts a hex number to UART port\r
213  * @param[in]   UARTx   Pointer to UART peripheral\r
214  * @param[in]   hexnum  Hex number (16-bit long)\r
215  * @return              None\r
216  **********************************************************************/\r
217 void UARTPutHex16 (LPC_USARTn_Type *UARTx, uint16_t hexnum)\r
218 {\r
219         uint8_t nibble, i;\r
220 \r
221         UARTPuts(UARTx, "0x");\r
222         i = 3;\r
223         do {\r
224                 nibble = (hexnum >> (4*i)) & 0x0F;\r
225                 UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));\r
226         } while (i--);\r
227 }\r
228 \r
229 /*********************************************************************//**\r
230  * @brief               Puts a hex number to UART port\r
231  * @param[in]   UARTx   Pointer to UART peripheral\r
232  * @param[in]   hexnum  Hex number (32-bit long)\r
233  * @return              None\r
234  **********************************************************************/\r
235 void UARTPutHex32 (LPC_USARTn_Type *UARTx, uint32_t hexnum)\r
236 {\r
237         uint8_t nibble, i;\r
238 \r
239         UARTPuts(UARTx, "0x");\r
240         i = 7;\r
241         do {\r
242                 nibble = (hexnum >> (4*i)) & 0x0F;\r
243                 UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));\r
244         } while (i--);\r
245 }\r
246 \r
247 /*********************************************************************//**\r
248  * @brief               print function that supports format as same as printf()\r
249  *                              function of <stdio.h> library\r
250  * @param[in]   format formated string to be print\r
251  * @return              None\r
252  **********************************************************************/\r
253 void  lpc_printf (const  char *format, ...)\r
254 {\r
255     char  buffer[512 + 1];\r
256     va_list vArgs;\r
257     va_start(vArgs, format);\r
258     vsprintf((char *)buffer, (char const *)format, vArgs);\r
259     va_end(vArgs);\r
260 \r
261     _DBG(buffer);\r
262 }\r
263 \r
264 /*********************************************************************//**\r
265  * @brief               Initialize Debug frame work through initializing UART port\r
266  * @param[in]   None\r
267  * @return              None\r
268  **********************************************************************/\r
269 void debug_frmwrk_init(void)\r
270 {\r
271 #ifdef UART_DEBUG_MESSEGES\r
272 \r
273         UART_CFG_Type UARTConfigStruct;\r
274 \r
275 #if (USED_UART_DEBUG_PORT==0)\r
276         /*\r
277          * Initialize UART0 pin connect NGX board\r
278          */\r
279         scu_pinmux(0xF ,10 , MD_PDN|MD_EZI, FUNC1);                     // P6.4 UART0_TXD\r
280         scu_pinmux(0xF ,11 , MD_PDN|MD_EZI, FUNC1);                     // P6.5 UART0_RXD\r
281 #elif (USED_UART_DEBUG_PORT==1)\r
282         /*\r
283          * Initialize UART1 pin connect\r
284          */\r
285         scu_pinmux(0x1 ,13 , MD_PDN, FUNC1);                            // PC.13 : UART1_TXD\r
286         scu_pinmux(0x1 ,14 , MD_PLN|MD_EZI|MD_ZI, FUNC1);       // PC.14 : UART1_RXD\r
287 #endif\r
288 \r
289         /* Initialize UART Configuration parameter structure to default state:\r
290          * Baudrate = 9600bps\r
291          * 8 data bit\r
292          * 1 Stop bit\r
293          * None parity\r
294          */\r
295         UART_ConfigStructInit(&UARTConfigStruct);\r
296 \r
297         // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter\r
298         UART_Init((LPC_USARTn_Type*)DEBUG_UART_PORT, &UARTConfigStruct);\r
299 \r
300         // Enable UART Transmit\r
301         UART_TxCmd((LPC_USARTn_Type*)DEBUG_UART_PORT, ENABLE);\r
302 #endif\r
303 #ifdef CDC_DEBUG_MESSEGES\r
304         CDC_init();             //wait for usb enumeration\r
305 \r
306 #endif\r
307 \r
308         _db_msg = UARTPuts;\r
309         _db_msg_ = UARTPuts_;\r
310         _db_char = UARTPutChar;\r
311         _db_hex = UARTPutHex;\r
312         _db_hex_16 = UARTPutHex16;\r
313         _db_hex_32 = UARTPutHex32;\r
314         _db_dec = UARTPutDec;\r
315         _db_dec_16 = UARTPutDec16;\r
316         _db_dec_32 = UARTPutDec32;\r
317         _db_get_char = UARTGetChar;\r
318 }\r
319 \r
320 #endif /* _DEBUG_FRMWRK_ */\r
321 \r
322 /**\r
323  * @}\r
324  */\r
325 \r
326 /* --------------------------------- End Of File ------------------------------ */\r