My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

debug_frmwrk.c 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. void (*_db_msg)(LPC_UART_TypeDef *UARTx, const void *s);
  45. void (*_db_msg_)(LPC_UART_TypeDef *UARTx, const void *s);
  46. void (*_db_char)(LPC_UART_TypeDef *UARTx, uint8_t ch);
  47. void (*_db_dec)(LPC_UART_TypeDef *UARTx, uint8_t decn);
  48. void (*_db_dec_16)(LPC_UART_TypeDef *UARTx, uint16_t decn);
  49. void (*_db_dec_32)(LPC_UART_TypeDef *UARTx, uint32_t decn);
  50. void (*_db_hex)(LPC_UART_TypeDef *UARTx, uint8_t hexn);
  51. void (*_db_hex_16)(LPC_UART_TypeDef *UARTx, uint16_t hexn);
  52. void (*_db_hex_32)(LPC_UART_TypeDef *UARTx, uint32_t hexn);
  53. uint8_t (*_db_get_char)(LPC_UART_TypeDef *UARTx);
  54. /*********************************************************************//**
  55. * @brief Puts a character to UART port
  56. * @param[in] UARTx Pointer to UART peripheral
  57. * @param[in] ch Character to put
  58. * @return None
  59. **********************************************************************/
  60. void UARTPutChar (LPC_UART_TypeDef *UARTx, uint8_t ch)
  61. {
  62. UART_Send(UARTx, &ch, 1, BLOCKING);
  63. }
  64. /*********************************************************************//**
  65. * @brief Get a character to UART port
  66. * @param[in] UARTx Pointer to UART peripheral
  67. * @return character value that returned
  68. **********************************************************************/
  69. uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx)
  70. {
  71. uint8_t tmp = 0;
  72. UART_Receive(UARTx, &tmp, 1, BLOCKING);
  73. return(tmp);
  74. }
  75. /*********************************************************************//**
  76. * @brief Puts a string to UART port
  77. * @param[in] UARTx Pointer to UART peripheral
  78. * @param[in] str string to put
  79. * @return None
  80. **********************************************************************/
  81. void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)
  82. {
  83. uint8_t *s = (uint8_t *) str;
  84. while (*s)
  85. {
  86. UARTPutChar(UARTx, *s++);
  87. }
  88. }
  89. /*********************************************************************//**
  90. * @brief Puts a string to UART port and print new line
  91. * @param[in] UARTx Pointer to UART peripheral
  92. * @param[in] str String to put
  93. * @return None
  94. **********************************************************************/
  95. void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str)
  96. {
  97. UARTPuts (UARTx, str);
  98. UARTPuts (UARTx, "\n\r");
  99. }
  100. /*********************************************************************//**
  101. * @brief Puts a decimal number to UART port
  102. * @param[in] UARTx Pointer to UART peripheral
  103. * @param[in] decnum Decimal number (8-bit long)
  104. * @return None
  105. **********************************************************************/
  106. void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum)
  107. {
  108. uint8_t c1=decnum%10;
  109. uint8_t c2=(decnum/10)%10;
  110. uint8_t c3=(decnum/100)%10;
  111. UARTPutChar(UARTx, '0'+c3);
  112. UARTPutChar(UARTx, '0'+c2);
  113. UARTPutChar(UARTx, '0'+c1);
  114. }
  115. /*********************************************************************//**
  116. * @brief Puts a decimal number to UART port
  117. * @param[in] UARTx Pointer to UART peripheral
  118. * @param[in] decnum Decimal number (8-bit long)
  119. * @return None
  120. **********************************************************************/
  121. void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum)
  122. {
  123. uint8_t c1=decnum%10;
  124. uint8_t c2=(decnum/10)%10;
  125. uint8_t c3=(decnum/100)%10;
  126. uint8_t c4=(decnum/1000)%10;
  127. uint8_t c5=(decnum/10000)%10;
  128. UARTPutChar(UARTx, '0'+c5);
  129. UARTPutChar(UARTx, '0'+c4);
  130. UARTPutChar(UARTx, '0'+c3);
  131. UARTPutChar(UARTx, '0'+c2);
  132. UARTPutChar(UARTx, '0'+c1);
  133. }
  134. /*********************************************************************//**
  135. * @brief Puts a decimal number to UART port
  136. * @param[in] UARTx Pointer to UART peripheral
  137. * @param[in] decnum Decimal number (8-bit long)
  138. * @return None
  139. **********************************************************************/
  140. void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum)
  141. {
  142. uint8_t c1=decnum%10;
  143. uint8_t c2=(decnum/10)%10;
  144. uint8_t c3=(decnum/100)%10;
  145. uint8_t c4=(decnum/1000)%10;
  146. uint8_t c5=(decnum/10000)%10;
  147. uint8_t c6=(decnum/100000)%10;
  148. uint8_t c7=(decnum/1000000)%10;
  149. uint8_t c8=(decnum/10000000)%10;
  150. uint8_t c9=(decnum/100000000)%10;
  151. uint8_t c10=(decnum/1000000000)%10;
  152. UARTPutChar(UARTx, '0'+c10);
  153. UARTPutChar(UARTx, '0'+c9);
  154. UARTPutChar(UARTx, '0'+c8);
  155. UARTPutChar(UARTx, '0'+c7);
  156. UARTPutChar(UARTx, '0'+c6);
  157. UARTPutChar(UARTx, '0'+c5);
  158. UARTPutChar(UARTx, '0'+c4);
  159. UARTPutChar(UARTx, '0'+c3);
  160. UARTPutChar(UARTx, '0'+c2);
  161. UARTPutChar(UARTx, '0'+c1);
  162. }
  163. /*********************************************************************//**
  164. * @brief Puts a hex number to UART port
  165. * @param[in] UARTx Pointer to UART peripheral
  166. * @param[in] hexnum Hex number (8-bit long)
  167. * @return None
  168. **********************************************************************/
  169. void UARTPutHex (LPC_UART_TypeDef *UARTx, uint8_t hexnum)
  170. {
  171. uint8_t nibble, i;
  172. UARTPuts(UARTx, "0x");
  173. i = 1;
  174. do {
  175. nibble = (hexnum >> (4*i)) & 0x0F;
  176. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  177. } while (i--);
  178. }
  179. /*********************************************************************//**
  180. * @brief Puts a hex number to UART port
  181. * @param[in] UARTx Pointer to UART peripheral
  182. * @param[in] hexnum Hex number (16-bit long)
  183. * @return None
  184. **********************************************************************/
  185. void UARTPutHex16 (LPC_UART_TypeDef *UARTx, uint16_t hexnum)
  186. {
  187. uint8_t nibble, i;
  188. UARTPuts(UARTx, "0x");
  189. i = 3;
  190. do {
  191. nibble = (hexnum >> (4*i)) & 0x0F;
  192. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  193. } while (i--);
  194. }
  195. /*********************************************************************//**
  196. * @brief Puts a hex number to UART port
  197. * @param[in] UARTx Pointer to UART peripheral
  198. * @param[in] hexnum Hex number (32-bit long)
  199. * @return None
  200. **********************************************************************/
  201. void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum)
  202. {
  203. uint8_t nibble, i;
  204. UARTPuts(UARTx, "0x");
  205. i = 7;
  206. do {
  207. nibble = (hexnum >> (4*i)) & 0x0F;
  208. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  209. } while (i--);
  210. }
  211. ///*********************************************************************//**
  212. // * @brief print function that supports format as same as printf()
  213. // * function of <stdio.h> library
  214. // * @param[in] None
  215. // * @return None
  216. // **********************************************************************/
  217. //void _printf (const char *format, ...)
  218. //{
  219. // static char buffer[512 + 1];
  220. // va_list vArgs;
  221. // char *tmp;
  222. // va_start(vArgs, format);
  223. // vsprintf((char *)buffer, (char const *)format, vArgs);
  224. // va_end(vArgs);
  225. //
  226. // _DBG(buffer);
  227. //}
  228. /*********************************************************************//**
  229. * @brief Initialize Debug frame work through initializing UART port
  230. * @param[in] None
  231. * @return None
  232. **********************************************************************/
  233. void debug_frmwrk_init(void)
  234. {
  235. UART_CFG_Type UARTConfigStruct;
  236. PINSEL_CFG_Type PinCfg;
  237. #if (USED_UART_DEBUG_PORT==0)
  238. /*
  239. * Initialize UART0 pin connect
  240. */
  241. PinCfg.Funcnum = 1;
  242. PinCfg.OpenDrain = 0;
  243. PinCfg.Pinmode = 0;
  244. PinCfg.Pinnum = 2;
  245. PinCfg.Portnum = 0;
  246. PINSEL_ConfigPin(&PinCfg);
  247. PinCfg.Pinnum = 3;
  248. PINSEL_ConfigPin(&PinCfg);
  249. #elif (USED_UART_DEBUG_PORT==1)
  250. /*
  251. * Initialize UART1 pin connect
  252. */
  253. PinCfg.Funcnum = 1;
  254. PinCfg.OpenDrain = 0;
  255. PinCfg.Pinmode = 0;
  256. PinCfg.Pinnum = 15;
  257. PinCfg.Portnum = 0;
  258. PINSEL_ConfigPin(&PinCfg);
  259. PinCfg.Pinnum = 16;
  260. PINSEL_ConfigPin(&PinCfg);
  261. #endif
  262. /* Initialize UART Configuration parameter structure to default state:
  263. * Baudrate = 9600bps
  264. * 8 data bit
  265. * 1 Stop bit
  266. * None parity
  267. */
  268. UART_ConfigStructInit(&UARTConfigStruct);
  269. // Re-configure baudrate to 115200bps
  270. UARTConfigStruct.Baud_rate = 115200;
  271. // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
  272. UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct);
  273. // Enable UART Transmit
  274. UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE);
  275. _db_msg = UARTPuts;
  276. _db_msg_ = UARTPuts_;
  277. _db_char = UARTPutChar;
  278. _db_hex = UARTPutHex;
  279. _db_hex_16 = UARTPutHex16;
  280. _db_hex_32 = UARTPutHex32;
  281. _db_dec = UARTPutDec;
  282. _db_dec_16 = UARTPutDec16;
  283. _db_dec_32 = UARTPutDec32;
  284. _db_get_char = UARTGetChar;
  285. }
  286. #endif /*_DBGFWK */
  287. /* --------------------------------- End Of File ------------------------------ */