My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

debug_frmwrk.c 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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
  9. *
  10. * Copyright(C) 2010, NXP Semiconductor
  11. * All rights reserved.
  12. *
  13. ***********************************************************************
  14. * Software that is described herein is for illustrative purposes only
  15. * which provides customers with programming information regarding the
  16. * products. This software is supplied "AS IS" without any warranties.
  17. * NXP Semiconductors assumes no responsibility or liability for the
  18. * use of the software, conveys no license or title under any patent,
  19. * copyright, or mask work right to the product. NXP Semiconductors
  20. * reserves the right to make changes in the software without
  21. * notification. NXP Semiconductors also make no representation or
  22. * warranty that such application will be suitable for the specified
  23. * use without further testing or modification.
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors'
  26. * relevant copyright in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. **********************************************************************/
  31. #include "debug_frmwrk.h"
  32. #include "lpc17xx_pinsel.h"
  33. /* If this source file built with example, the LPC17xx FW library configuration
  34. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  35. * otherwise the default FW library configuration file must be included instead
  36. */
  37. #ifdef __BUILD_WITH_EXAMPLE__
  38. #include "lpc17xx_libcfg.h"
  39. #else
  40. #include "lpc17xx_libcfg_default.h"
  41. #endif /* __BUILD_WITH_EXAMPLE__ */
  42. #ifdef _DBGFWK
  43. /* Debug framework */
  44. static Bool debug_frmwrk_initialized = FALSE;
  45. void (*_db_msg)(LPC_UART_TypeDef *UARTx, const void *s) = UARTPuts;
  46. void (*_db_msg_)(LPC_UART_TypeDef *UARTx, const void *s) = UARTPuts_;
  47. void (*_db_char)(LPC_UART_TypeDef *UARTx, uint8_t ch) = UARTPutChar;
  48. void (*_db_dec)(LPC_UART_TypeDef *UARTx, uint8_t decn) = UARTPutHex;
  49. void (*_db_dec_16)(LPC_UART_TypeDef *UARTx, uint16_t decn) = UARTPutHex16;
  50. void (*_db_dec_32)(LPC_UART_TypeDef *UARTx, uint32_t decn) = UARTPutHex32;
  51. void (*_db_hex)(LPC_UART_TypeDef *UARTx, uint8_t hexn) = UARTPutDec;
  52. void (*_db_hex_16)(LPC_UART_TypeDef *UARTx, uint16_t hexn) = UARTPutDec16;
  53. void (*_db_hex_32)(LPC_UART_TypeDef *UARTx, uint32_t hexn) = UARTPutDec32;
  54. uint8_t (*_db_get_char)(LPC_UART_TypeDef *UARTx) = UARTGetChar;
  55. /*********************************************************************//**
  56. * @brief Puts a character to UART port
  57. * @param[in] UARTx Pointer to UART peripheral
  58. * @param[in] ch Character to put
  59. * @return None
  60. **********************************************************************/
  61. void UARTPutChar (LPC_UART_TypeDef *UARTx, uint8_t ch)
  62. {
  63. if (debug_frmwrk_initialized)
  64. UART_Send(UARTx, &ch, 1, BLOCKING);
  65. }
  66. /*********************************************************************//**
  67. * @brief Get a character to UART port
  68. * @param[in] UARTx Pointer to UART peripheral
  69. * @return character value that returned
  70. **********************************************************************/
  71. uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx)
  72. {
  73. uint8_t tmp = 0;
  74. if (debug_frmwrk_initialized)
  75. UART_Receive(UARTx, &tmp, 1, BLOCKING);
  76. return(tmp);
  77. }
  78. /*********************************************************************//**
  79. * @brief Puts a string to UART port
  80. * @param[in] UARTx Pointer to UART peripheral
  81. * @param[in] str string to put
  82. * @return None
  83. **********************************************************************/
  84. void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)
  85. {
  86. uint8_t *s = (uint8_t *) str;
  87. if (!debug_frmwrk_initialized)
  88. return;
  89. while (*s)
  90. {
  91. UARTPutChar(UARTx, *s++);
  92. }
  93. }
  94. /*********************************************************************//**
  95. * @brief Puts a string to UART port and print new line
  96. * @param[in] UARTx Pointer to UART peripheral
  97. * @param[in] str String to put
  98. * @return None
  99. **********************************************************************/
  100. void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str)
  101. {
  102. if (!debug_frmwrk_initialized)
  103. return;
  104. UARTPuts (UARTx, str);
  105. UARTPuts (UARTx, "\n\r");
  106. }
  107. /*********************************************************************//**
  108. * @brief Puts a decimal number to UART port
  109. * @param[in] UARTx Pointer to UART peripheral
  110. * @param[in] decnum Decimal number (8-bit long)
  111. * @return None
  112. **********************************************************************/
  113. void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum)
  114. {
  115. if (!debug_frmwrk_initialized)
  116. return;
  117. uint8_t c1=decnum%10;
  118. uint8_t c2=(decnum/10)%10;
  119. uint8_t c3=(decnum/100)%10;
  120. UARTPutChar(UARTx, '0'+c3);
  121. UARTPutChar(UARTx, '0'+c2);
  122. UARTPutChar(UARTx, '0'+c1);
  123. }
  124. /*********************************************************************//**
  125. * @brief Puts a decimal number to UART port
  126. * @param[in] UARTx Pointer to UART peripheral
  127. * @param[in] decnum Decimal number (8-bit long)
  128. * @return None
  129. **********************************************************************/
  130. void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum)
  131. {
  132. if (!debug_frmwrk_initialized)
  133. return;
  134. uint8_t c1=decnum%10;
  135. uint8_t c2=(decnum/10)%10;
  136. uint8_t c3=(decnum/100)%10;
  137. uint8_t c4=(decnum/1000)%10;
  138. uint8_t c5=(decnum/10000)%10;
  139. UARTPutChar(UARTx, '0'+c5);
  140. UARTPutChar(UARTx, '0'+c4);
  141. UARTPutChar(UARTx, '0'+c3);
  142. UARTPutChar(UARTx, '0'+c2);
  143. UARTPutChar(UARTx, '0'+c1);
  144. }
  145. /*********************************************************************//**
  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
  150. **********************************************************************/
  151. void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum)
  152. {
  153. if (!debug_frmwrk_initialized)
  154. return;
  155. uint8_t c1=decnum%10;
  156. uint8_t c2=(decnum/10)%10;
  157. uint8_t c3=(decnum/100)%10;
  158. uint8_t c4=(decnum/1000)%10;
  159. uint8_t c5=(decnum/10000)%10;
  160. uint8_t c6=(decnum/100000)%10;
  161. uint8_t c7=(decnum/1000000)%10;
  162. uint8_t c8=(decnum/10000000)%10;
  163. uint8_t c9=(decnum/100000000)%10;
  164. uint8_t c10=(decnum/1000000000)%10;
  165. UARTPutChar(UARTx, '0'+c10);
  166. UARTPutChar(UARTx, '0'+c9);
  167. UARTPutChar(UARTx, '0'+c8);
  168. UARTPutChar(UARTx, '0'+c7);
  169. UARTPutChar(UARTx, '0'+c6);
  170. UARTPutChar(UARTx, '0'+c5);
  171. UARTPutChar(UARTx, '0'+c4);
  172. UARTPutChar(UARTx, '0'+c3);
  173. UARTPutChar(UARTx, '0'+c2);
  174. UARTPutChar(UARTx, '0'+c1);
  175. }
  176. /*********************************************************************//**
  177. * @brief Puts a hex number to UART port
  178. * @param[in] UARTx Pointer to UART peripheral
  179. * @param[in] hexnum Hex number (8-bit long)
  180. * @return None
  181. **********************************************************************/
  182. void UARTPutHex (LPC_UART_TypeDef *UARTx, uint8_t hexnum)
  183. {
  184. uint8_t nibble, i;
  185. if (!debug_frmwrk_initialized)
  186. return;
  187. UARTPuts(UARTx, "0x");
  188. i = 1;
  189. do {
  190. nibble = (hexnum >> (4*i)) & 0x0F;
  191. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  192. } while (i--);
  193. }
  194. /*********************************************************************//**
  195. * @brief Puts a hex number to UART port
  196. * @param[in] UARTx Pointer to UART peripheral
  197. * @param[in] hexnum Hex number (16-bit long)
  198. * @return None
  199. **********************************************************************/
  200. void UARTPutHex16 (LPC_UART_TypeDef *UARTx, uint16_t hexnum)
  201. {
  202. uint8_t nibble, i;
  203. if (!debug_frmwrk_initialized)
  204. return;
  205. UARTPuts(UARTx, "0x");
  206. i = 3;
  207. do {
  208. nibble = (hexnum >> (4*i)) & 0x0F;
  209. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  210. } while (i--);
  211. }
  212. /*********************************************************************//**
  213. * @brief Puts a hex number to UART port
  214. * @param[in] UARTx Pointer to UART peripheral
  215. * @param[in] hexnum Hex number (32-bit long)
  216. * @return None
  217. **********************************************************************/
  218. void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum)
  219. {
  220. uint8_t nibble, i;
  221. if (!debug_frmwrk_initialized)
  222. return;
  223. UARTPuts(UARTx, "0x");
  224. i = 7;
  225. do {
  226. nibble = (hexnum >> (4*i)) & 0x0F;
  227. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  228. } while (i--);
  229. }
  230. ///*********************************************************************//**
  231. // * @brief print function that supports format as same as printf()
  232. // * function of <stdio.h> library
  233. // * @param[in] None
  234. // * @return None
  235. // **********************************************************************/
  236. //void _printf (const char *format, ...)
  237. //{
  238. // static char buffer[512 + 1];
  239. // va_list vArgs;
  240. // char *tmp;
  241. // va_start(vArgs, format);
  242. // vsprintf((char *)buffer, (char const *)format, vArgs);
  243. // va_end(vArgs);
  244. //
  245. // _DBG(buffer);
  246. //}
  247. /*********************************************************************//**
  248. * @brief Initialize Debug frame work through initializing UART port
  249. * @param[in] None
  250. * @return None
  251. **********************************************************************/
  252. void debug_frmwrk_init(void)
  253. {
  254. UART_CFG_Type UARTConfigStruct;
  255. PINSEL_CFG_Type PinCfg;
  256. #if (USED_UART_DEBUG_PORT==0)
  257. /*
  258. * Initialize UART0 pin connect
  259. */
  260. PinCfg.Funcnum = 1;
  261. PinCfg.OpenDrain = 0;
  262. PinCfg.Pinmode = 0;
  263. PinCfg.Pinnum = 2;
  264. PinCfg.Portnum = 0;
  265. PINSEL_ConfigPin(&PinCfg);
  266. PinCfg.Pinnum = 3;
  267. PINSEL_ConfigPin(&PinCfg);
  268. #elif (USED_UART_DEBUG_PORT==1)
  269. /*
  270. * Initialize UART1 pin connect
  271. */
  272. PinCfg.Funcnum = 1;
  273. PinCfg.OpenDrain = 0;
  274. PinCfg.Pinmode = 0;
  275. PinCfg.Pinnum = 15;
  276. PinCfg.Portnum = 0;
  277. PINSEL_ConfigPin(&PinCfg);
  278. PinCfg.Pinnum = 16;
  279. PINSEL_ConfigPin(&PinCfg);
  280. #endif
  281. /* Initialize UART Configuration parameter structure to default state:
  282. * Baudrate = 9600bps
  283. * 8 data bit
  284. * 1 Stop bit
  285. * None parity
  286. */
  287. UART_ConfigStructInit(&UARTConfigStruct);
  288. // Re-configure baudrate to 115200bps
  289. UARTConfigStruct.Baud_rate = 115200;
  290. // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
  291. UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct);
  292. // Enable UART Transmit
  293. UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE);
  294. debug_frmwrk_initialized = TRUE;
  295. }
  296. #endif /*_DBGFWK */
  297. /* --------------------------------- End Of File ------------------------------ */