Browse Source

Cleanup, apply standards to debug_frmwrk.c

Although this is an external contribution, clean up anyway to stop seeing it in global searches for typical flaws.
Scott Lahteine 7 years ago
parent
commit
203f2923a1
1 changed files with 202 additions and 238 deletions
  1. 202
    238
      frameworks/CMSIS/LPC1768/driver/debug_frmwrk.c

+ 202
- 238
frameworks/CMSIS/LPC1768/driver/debug_frmwrk.c View File

1
 /**********************************************************************
1
 /**********************************************************************
2
-* $Id$		debug_frmwrk.c				2010-05-21
3
-*//**
4
-* @file		debug_frmwrk.c
5
-* @brief	Contains some utilities that used for debugging through UART
6
-* @version	2.0
7
-* @date		21. May. 2010
8
-* @author	NXP MCU SW Application Team
2
+* $Id$    debug_frmwrk.c        2010-05-21
3
+*
4
+* @file   debug_frmwrk.c
5
+* @brief  Contains some utilities that used for debugging through UART
6
+* @version  2.0
7
+* @date   21. May. 2010
8
+* @author NXP MCU SW Application Team
9
 *
9
 *
10
 * Copyright(C) 2010, NXP Semiconductor
10
 * Copyright(C) 2010, NXP Semiconductor
11
 * All rights reserved.
11
 * All rights reserved.
37
  * otherwise the default FW library configuration file must be included instead
37
  * otherwise the default FW library configuration file must be included instead
38
  */
38
  */
39
 #ifdef __BUILD_WITH_EXAMPLE__
39
 #ifdef __BUILD_WITH_EXAMPLE__
40
-#include "lpc17xx_libcfg.h"
40
+  #include "lpc17xx_libcfg.h"
41
 #else
41
 #else
42
-#include "lpc17xx_libcfg_default.h"
43
-#endif /* __BUILD_WITH_EXAMPLE__ */
42
+  #include "lpc17xx_libcfg_default.h"
43
+#endif
44
 
44
 
45
 #ifdef _DBGFWK
45
 #ifdef _DBGFWK
46
+
46
 /* Debug framework */
47
 /* Debug framework */
47
 static Bool debug_frmwrk_initialized = FALSE;
48
 static Bool debug_frmwrk_initialized = FALSE;
48
 
49
 
59
 
60
 
60
 
61
 
61
 /*********************************************************************//**
62
 /*********************************************************************//**
62
- * @brief		Puts a character to UART port
63
- * @param[in]	UARTx	Pointer to UART peripheral
64
- * @param[in]	ch		Character to put
65
- * @return		None
63
+ * @brief   Puts a character to UART port
64
+ * @param[in] UARTx Pointer to UART peripheral
65
+ * @param[in] ch    Character to put
66
+ * @return    None
66
  **********************************************************************/
67
  **********************************************************************/
67
-void UARTPutChar (LPC_UART_TypeDef *UARTx, uint8_t ch)
68
-{
68
+void UARTPutChar(LPC_UART_TypeDef *UARTx, uint8_t ch) {
69
   if (debug_frmwrk_initialized)
69
   if (debug_frmwrk_initialized)
70
-	  UART_Send(UARTx, &ch, 1, BLOCKING);
70
+    UART_Send(UARTx, &ch, 1, BLOCKING);
71
 }
71
 }
72
 
72
 
73
-
74
 /*********************************************************************//**
73
 /*********************************************************************//**
75
- * @brief		Get a character to UART port
76
- * @param[in]	UARTx	Pointer to UART peripheral
77
- * @return		character value that returned
74
+ * @brief   Get a character to UART port
75
+ * @param[in] UARTx Pointer to UART peripheral
76
+ * @return    character value that returned
78
  **********************************************************************/
77
  **********************************************************************/
79
-uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx)
80
-{
78
+uint8_t UARTGetChar(LPC_UART_TypeDef *UARTx) {
81
   uint8_t tmp = 0;
79
   uint8_t tmp = 0;
82
-  
80
+
83
   if (debug_frmwrk_initialized)
81
   if (debug_frmwrk_initialized)
84
     UART_Receive(UARTx, &tmp, 1, BLOCKING);
82
     UART_Receive(UARTx, &tmp, 1, BLOCKING);
85
-    
86
-	return(tmp);
87
-}
88
 
83
 
84
+  return(tmp);
85
+}
89
 
86
 
90
 /*********************************************************************//**
87
 /*********************************************************************//**
91
- * @brief		Puts a string to UART port
92
- * @param[in]	UARTx 	Pointer to UART peripheral
93
- * @param[in]	str 	string to put
94
- * @return		None
88
+ * @brief   Puts a string to UART port
89
+ * @param[in] UARTx   Pointer to UART peripheral
90
+ * @param[in] str   string to put
91
+ * @return    None
95
  **********************************************************************/
92
  **********************************************************************/
96
-void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)
97
-{
98
-  uint8_t *s = (uint8_t *) str;
99
-  
100
-  if (!debug_frmwrk_initialized)
101
-    return;
102
-
103
-	while (*s)
104
-	{
105
-		UARTPutChar(UARTx, *s++);
106
-	}
107
-}
93
+void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str) {
94
+  if (!debug_frmwrk_initialized) return;
108
 
95
 
96
+  uint8_t *s = (uint8_t*)str;
97
+  while (*s) UARTPutChar(UARTx, *s++);
98
+}
109
 
99
 
110
 /*********************************************************************//**
100
 /*********************************************************************//**
111
- * @brief		Puts a string to UART port and print new line
112
- * @param[in]	UARTx	Pointer to UART peripheral
113
- * @param[in]	str		String to put
114
- * @return		None
101
+ * @brief   Puts a string to UART port and print new line
102
+ * @param[in] UARTx Pointer to UART peripheral
103
+ * @param[in] str   String to put
104
+ * @return    None
115
  **********************************************************************/
105
  **********************************************************************/
116
-void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str)
117
-{
118
-  if (!debug_frmwrk_initialized)
119
-    return;
106
+void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str) {
107
+  if (!debug_frmwrk_initialized) return;
120
 
108
 
121
-	UARTPuts (UARTx, str);
122
-	UARTPuts (UARTx, "\n\r");
109
+  UARTPuts (UARTx, str);
110
+  UARTPuts (UARTx, "\n\r");
123
 }
111
 }
124
 
112
 
125
-
126
 /*********************************************************************//**
113
 /*********************************************************************//**
127
- * @brief		Puts a decimal number to UART port
128
- * @param[in]	UARTx	Pointer to UART peripheral
129
- * @param[in]	decnum	Decimal number (8-bit long)
130
- * @return		None
114
+ * @brief   Puts a decimal number to UART port
115
+ * @param[in] UARTx Pointer to UART peripheral
116
+ * @param[in] decnum  Decimal number (8-bit long)
117
+ * @return    None
131
  **********************************************************************/
118
  **********************************************************************/
132
-void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum)
133
-{
134
-  if (!debug_frmwrk_initialized)
135
-    return;
136
-
137
-	uint8_t c1=decnum%10;
138
-	uint8_t c2=(decnum/10)%10;
139
-	uint8_t c3=(decnum/100)%10;
140
-	UARTPutChar(UARTx, '0'+c3);
141
-	UARTPutChar(UARTx, '0'+c2);
142
-	UARTPutChar(UARTx, '0'+c1);
119
+void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum) {
120
+  if (!debug_frmwrk_initialized) return;
121
+
122
+  uint8_t c1 = decnum%10;
123
+  uint8_t c2 = (decnum /             10) % 10;
124
+  uint8_t c3 = (decnum /            100) % 10;
125
+  UARTPutChar(UARTx, '0'+c3);
126
+  UARTPutChar(UARTx, '0'+c2);
127
+  UARTPutChar(UARTx, '0'+c1);
143
 }
128
 }
144
 
129
 
145
 /*********************************************************************//**
130
 /*********************************************************************//**
146
- * @brief		Puts a decimal number to UART port
147
- * @param[in]	UARTx	Pointer to UART peripheral
148
- * @param[in]	decnum	Decimal number (8-bit long)
149
- * @return		None
131
+ * @brief   Puts a decimal number to UART port
132
+ * @param[in] UARTx Pointer to UART peripheral
133
+ * @param[in] decnum  Decimal number (8-bit long)
134
+ * @return    None
150
  **********************************************************************/
135
  **********************************************************************/
151
-void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum)
152
-{  
153
-  if (!debug_frmwrk_initialized)
154
-    return;
155
-
156
-	uint8_t c1=decnum%10;
157
-	uint8_t c2=(decnum/10)%10;
158
-	uint8_t c3=(decnum/100)%10;
159
-	uint8_t c4=(decnum/1000)%10;
160
-	uint8_t c5=(decnum/10000)%10;
161
-	UARTPutChar(UARTx, '0'+c5);
162
-	UARTPutChar(UARTx, '0'+c4);
163
-	UARTPutChar(UARTx, '0'+c3);
164
-	UARTPutChar(UARTx, '0'+c2);
165
-	UARTPutChar(UARTx, '0'+c1);
136
+void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum) {
137
+  if (!debug_frmwrk_initialized) return;
138
+
139
+  uint8_t c1 = decnum%10;
140
+  uint8_t c2 = (decnum /             10) % 10;
141
+  uint8_t c3 = (decnum /            100) % 10;
142
+  uint8_t c4 = (decnum /           1000) % 10;
143
+  uint8_t c5 = (decnum /          10000) % 10;
144
+  UARTPutChar(UARTx, '0'+c5);
145
+  UARTPutChar(UARTx, '0'+c4);
146
+  UARTPutChar(UARTx, '0'+c3);
147
+  UARTPutChar(UARTx, '0'+c2);
148
+  UARTPutChar(UARTx, '0'+c1);
166
 }
149
 }
167
 
150
 
168
 /*********************************************************************//**
151
 /*********************************************************************//**
169
- * @brief		Puts a decimal number to UART port
170
- * @param[in]	UARTx	Pointer to UART peripheral
171
- * @param[in]	decnum	Decimal number (8-bit long)
172
- * @return		None
152
+ * @brief   Puts a decimal number to UART port
153
+ * @param[in] UARTx Pointer to UART peripheral
154
+ * @param[in] decnum  Decimal number (8-bit long)
155
+ * @return    None
173
  **********************************************************************/
156
  **********************************************************************/
174
-void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum)
175
-{
176
-  if (!debug_frmwrk_initialized)
177
-    return;
178
-
179
-	uint8_t c1=decnum%10;
180
-	uint8_t c2=(decnum/10)%10;
181
-	uint8_t c3=(decnum/100)%10;
182
-	uint8_t c4=(decnum/1000)%10;
183
-	uint8_t c5=(decnum/10000)%10;
184
-	uint8_t c6=(decnum/100000)%10;
185
-	uint8_t c7=(decnum/1000000)%10;
186
-	uint8_t c8=(decnum/10000000)%10;
187
-	uint8_t c9=(decnum/100000000)%10;
188
-	uint8_t c10=(decnum/1000000000)%10;
189
-	UARTPutChar(UARTx, '0'+c10);
190
-	UARTPutChar(UARTx, '0'+c9);
191
-	UARTPutChar(UARTx, '0'+c8);
192
-	UARTPutChar(UARTx, '0'+c7);
193
-	UARTPutChar(UARTx, '0'+c6);
194
-	UARTPutChar(UARTx, '0'+c5);
195
-	UARTPutChar(UARTx, '0'+c4);
196
-	UARTPutChar(UARTx, '0'+c3);
197
-	UARTPutChar(UARTx, '0'+c2);
198
-	UARTPutChar(UARTx, '0'+c1);
157
+void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum) {
158
+  if (!debug_frmwrk_initialized) return;
159
+
160
+  const uint8_t  c1 =  decnum               % 10,
161
+                 c2 = (decnum /         10) % 10,
162
+                 c3 = (decnum /        100) % 10,
163
+                 c4 = (decnum /       1000) % 10,
164
+                 c5 = (decnum /      10000) % 10,
165
+                 c6 = (decnum /     100000) % 10,
166
+                 c7 = (decnum /    1000000) % 10,
167
+                 c8 = (decnum /   10000000) % 10,
168
+                 c9 = (decnum /  100000000) % 10,
169
+                c10 = (decnum / 1000000000) % 10;
170
+  UARTPutChar(UARTx, '0' + c10);
171
+  UARTPutChar(UARTx, '0' +  c9);
172
+  UARTPutChar(UARTx, '0' +  c8);
173
+  UARTPutChar(UARTx, '0' +  c7);
174
+  UARTPutChar(UARTx, '0' +  c6);
175
+  UARTPutChar(UARTx, '0' +  c5);
176
+  UARTPutChar(UARTx, '0' +  c4);
177
+  UARTPutChar(UARTx, '0' +  c3);
178
+  UARTPutChar(UARTx, '0' +  c2);
179
+  UARTPutChar(UARTx, '0' +  c1);
199
 }
180
 }
200
 
181
 
201
 /*********************************************************************//**
182
 /*********************************************************************//**
202
- * @brief		Puts a hex number to UART port
203
- * @param[in]	UARTx	Pointer to UART peripheral
204
- * @param[in]	hexnum	Hex number (8-bit long)
205
- * @return		None
183
+ * @brief   Puts a hex number to UART port
184
+ * @param[in] UARTx Pointer to UART peripheral
185
+ * @param[in] hexnum  Hex number (8-bit long)
186
+ * @return    None
206
  **********************************************************************/
187
  **********************************************************************/
207
-void UARTPutHex (LPC_UART_TypeDef *UARTx, uint8_t hexnum)
208
-{
209
-	uint8_t nibble, i;
210
-  
211
-  if (!debug_frmwrk_initialized)
212
-    return;
213
-
214
-	UARTPuts(UARTx, "0x");
215
-	i = 1;
216
-	do {
217
-		nibble = (hexnum >> (4*i)) & 0x0F;
218
-		UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
219
-	} while (i--);
188
+void UARTPutHex(LPC_UART_TypeDef *UARTx, uint8_t hexnum) {
189
+  if (!debug_frmwrk_initialized) return;
190
+
191
+  UARTPuts(UARTx, "0x");
192
+  uint8_t nibble, i = 1;
193
+  do {
194
+    nibble = (hexnum >> (4 * i)) & 0x0F;
195
+    UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
196
+  } while (i--);
220
 }
197
 }
221
 
198
 
222
-
223
 /*********************************************************************//**
199
 /*********************************************************************//**
224
- * @brief		Puts a hex number to UART port
225
- * @param[in]	UARTx	Pointer to UART peripheral
226
- * @param[in]	hexnum	Hex number (16-bit long)
227
- * @return		None
200
+ * @brief   Puts a hex number to UART port
201
+ * @param[in] UARTx Pointer to UART peripheral
202
+ * @param[in] hexnum  Hex number (16-bit long)
203
+ * @return    None
228
  **********************************************************************/
204
  **********************************************************************/
229
-void UARTPutHex16 (LPC_UART_TypeDef *UARTx, uint16_t hexnum)
230
-{
231
-	uint8_t nibble, i;
232
-  
233
-  if (!debug_frmwrk_initialized)
234
-    return;
235
-
236
-	UARTPuts(UARTx, "0x");
237
-	i = 3;
238
-	do {
239
-		nibble = (hexnum >> (4*i)) & 0x0F;
240
-		UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
241
-	} while (i--);
205
+void UARTPutHex16(LPC_UART_TypeDef *UARTx, uint16_t hexnum) {
206
+  if (!debug_frmwrk_initialized) return;
207
+
208
+  UARTPuts(UARTx, "0x");
209
+  uint8_t nibble, i = 3;
210
+  do {
211
+    nibble = (hexnum >> (4 * i)) & 0x0F;
212
+    UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
213
+  } while (i--);
242
 }
214
 }
243
 
215
 
244
 /*********************************************************************//**
216
 /*********************************************************************//**
245
- * @brief		Puts a hex number to UART port
246
- * @param[in]	UARTx	Pointer to UART peripheral
247
- * @param[in]	hexnum	Hex number (32-bit long)
248
- * @return		None
217
+ * @brief   Puts a hex number to UART port
218
+ * @param[in] UARTx Pointer to UART peripheral
219
+ * @param[in] hexnum  Hex number (32-bit long)
220
+ * @return    None
249
  **********************************************************************/
221
  **********************************************************************/
250
-void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum)
251
-{
252
-  uint8_t nibble, i;
253
-  
254
-  if (!debug_frmwrk_initialized)
255
-    return;
256
-
257
-	UARTPuts(UARTx, "0x");
258
-	i = 7;
259
-	do {
260
-		nibble = (hexnum >> (4*i)) & 0x0F;
261
-		UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
262
-	} while (i--);
222
+void UARTPutHex32(LPC_UART_TypeDef *UARTx, uint32_t hexnum) {
223
+  if (!debug_frmwrk_initialized) return;
224
+
225
+  UARTPuts(UARTx, "0x");
226
+  uint8_t nibble, i = 7;
227
+  do {
228
+    nibble = (hexnum >> (4 * i)) & 0x0F;
229
+    UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
230
+  } while (i--);
263
 }
231
 }
264
 
232
 
265
-///*********************************************************************//**
266
-// * @brief		print function that supports format as same as printf()
267
-// * 				function of <stdio.h> library
268
-// * @param[in]	None
269
-// * @return		None
270
-// **********************************************************************/
271
-//void  _printf (const  char *format, ...)
272
-//{
273
-//    static  char  buffer[512 + 1];
274
-//            va_list     vArgs;
275
-//            char	*tmp;
276
-//    va_start(vArgs, format);
277
-//    vsprintf((char *)buffer, (char const *)format, vArgs);
278
-//    va_end(vArgs);
233
+/*********************************************************************//**
234
+ * @brief   print function that supports format as same as printf()
235
+ *        function of <stdio.h> library
236
+ * @param[in] None
237
+ * @return    None
238
+ **********************************************************************/
239
+//void  _printf (const  char *format, ...) {
240
+//  static  char  buffer[512 + 1];
241
+//          va_list     vArgs;
242
+//          char  *tmp;
243
+//  va_start(vArgs, format);
244
+//  vsprintf((char *)buffer, (char const *)format, vArgs);
245
+//  va_end(vArgs);
279
 //
246
 //
280
-//    _DBG(buffer);
247
+//  _DBG(buffer);
281
 //}
248
 //}
282
 
249
 
283
 /*********************************************************************//**
250
 /*********************************************************************//**
284
- * @brief		Initialize Debug frame work through initializing UART port
285
- * @param[in]	None
286
- * @return		None
251
+ * @brief   Initialize Debug frame work through initializing UART port
252
+ * @param[in] None
253
+ * @return    None
287
  **********************************************************************/
254
  **********************************************************************/
288
-void debug_frmwrk_init(void)
289
-{
290
-	UART_CFG_Type UARTConfigStruct;
291
-	PINSEL_CFG_Type PinCfg;
292
-
293
-#if (USED_UART_DEBUG_PORT==0)
294
-	/*
295
-	 * Initialize UART0 pin connect
296
-	 */
297
-	PinCfg.Funcnum = 1;
298
-	PinCfg.OpenDrain = 0;
299
-	PinCfg.Pinmode = 0;
300
-	PinCfg.Pinnum = 2;
301
-	PinCfg.Portnum = 0;
302
-	PINSEL_ConfigPin(&PinCfg);
303
-	PinCfg.Pinnum = 3;
304
-	PINSEL_ConfigPin(&PinCfg);
305
-
306
-#elif (USED_UART_DEBUG_PORT==1)
307
-	/*
308
-	 * Initialize UART1 pin connect
309
-	 */
310
-	PinCfg.Funcnum = 1;
311
-	PinCfg.OpenDrain = 0;
312
-	PinCfg.Pinmode = 0;
313
-	PinCfg.Pinnum = 15;
314
-	PinCfg.Portnum = 0;
315
-	PINSEL_ConfigPin(&PinCfg);
316
-	PinCfg.Pinnum = 16;
317
-	PINSEL_ConfigPin(&PinCfg);
318
-#endif
319
-
320
-	/* Initialize UART Configuration parameter structure to default state:
321
-	 * Baudrate = 9600bps
322
-	 * 8 data bit
323
-	 * 1 Stop bit
324
-	 * None parity
325
-	 */
326
-	UART_ConfigStructInit(&UARTConfigStruct);
327
-
328
-	// Re-configure baudrate to 115200bps
329
-	UARTConfigStruct.Baud_rate = 115200;
330
-
331
-	// Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
332
-	UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct);
333
-
334
-	// Enable UART Transmit
335
-	UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE);
255
+void debug_frmwrk_init(void) {
256
+  UART_CFG_Type UARTConfigStruct;
257
+  PINSEL_CFG_Type PinCfg;
258
+
259
+  #if (USED_UART_DEBUG_PORT==0)
260
+    /*
261
+     * Initialize UART0 pin connect
262
+     */
263
+    PinCfg.Funcnum = 1;
264
+    PinCfg.OpenDrain = 0;
265
+    PinCfg.Pinmode = 0;
266
+    PinCfg.Pinnum = 2;
267
+    PinCfg.Portnum = 0;
268
+    PINSEL_ConfigPin(&PinCfg);
269
+    PinCfg.Pinnum = 3;
270
+    PINSEL_ConfigPin(&PinCfg);
271
+
272
+  #elif (USED_UART_DEBUG_PORT==1)
273
+    /*
274
+     * Initialize UART1 pin connect
275
+     */
276
+    PinCfg.Funcnum = 1;
277
+    PinCfg.OpenDrain = 0;
278
+    PinCfg.Pinmode = 0;
279
+    PinCfg.Pinnum = 15;
280
+    PinCfg.Portnum = 0;
281
+    PINSEL_ConfigPin(&PinCfg);
282
+    PinCfg.Pinnum = 16;
283
+    PINSEL_ConfigPin(&PinCfg);
284
+  #endif
285
+
286
+  /* Initialize UART Configuration parameter structure to default state:
287
+   * Baudrate = 9600bps
288
+   * 8 data bit
289
+   * 1 Stop bit
290
+   * None parity
291
+   */
292
+  UART_ConfigStructInit(&UARTConfigStruct);
293
+
294
+  // Re-configure baudrate to 115200bps
295
+  UARTConfigStruct.Baud_rate = 115200;
296
+
297
+  // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
298
+  UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct);
299
+
300
+  // Enable UART Transmit
301
+  UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE);
336
 
302
 
337
   debug_frmwrk_initialized = TRUE;
303
   debug_frmwrk_initialized = TRUE;
338
 }
304
 }
339
-#endif /*_DBGFWK */
340
-
341
 
305
 
342
-/* --------------------------------- End Of File ------------------------------ */
306
+#endif // _DBGFWK

Loading…
Cancel
Save