debug_pin.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. This software is subject to the license described in the license.txt file included with this software distribution.You may not use this file except in compliance with this license.
  3. Copyright © Dynastream Innovations Inc. 2014
  4. All rights reserved.
  5. */
  6. #include "nrf.h"
  7. //#include "nrf51_bitfields.h"
  8. #include "debug_pin.h"
  9. #if defined (DEBUGGING_PINS_ENABLE)
  10. ///////////////////////////////////////////////////////////////////////
  11. // This function outputs a Manchester waveform for a
  12. // given priority context and event number. The particular waveforms were pre-calculated
  13. // so that the transmission speed is as fast as possible.
  14. // With Manchester encoding, the clock is XOR'd with an oversampled data stream.
  15. // This way, one is guaranteed to have a transitition every bit period and
  16. // the clock can be extracted from the data stream.
  17. // After oversampling the data (e.g. bABC... -> bAABBCC) and XORing with 0x55 or
  18. // b01010101.
  19. //
  20. // The following waveform lookup table was pre-determined:
  21. // Data Output Waveform
  22. // ---------------------
  23. // 0 0x55
  24. // 1 0x56
  25. // 2 0x59
  26. // 3 0x5A
  27. // 4 0x65
  28. // 5 0x66
  29. // 6 0x69
  30. // 7 0x6A
  31. // 8 0x95
  32. // 9 0x96
  33. // 10 0x99
  34. // 11 0x9A
  35. // 12 0xA5
  36. // 13 0xA6
  37. // 14 0xA9
  38. // 15 0xAA
  39. ///////////////////////////////////////////////////////////////////////
  40. #define STACK_DEBUG_MANCHESTER_BYTE55(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  41. __nop(); __nop();\
  42. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  43. __nop(); __nop();\
  44. NRF_GPIO->OUTSET = 1UL << ucPin;\
  45. __nop(); __nop();\
  46. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  47. __nop(); __nop();\
  48. NRF_GPIO->OUTSET = 1UL << ucPin;\
  49. __nop(); __nop();\
  50. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  51. __nop(); __nop();\
  52. NRF_GPIO->OUTSET = 1UL << ucPin;\
  53. __nop(); __nop();\
  54. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  55. __nop(); __nop();}
  56. #define STACK_DEBUG_MANCHESTER_BYTE56(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  57. __nop(); __nop();\
  58. NRF_GPIO->OUTSET = 1UL << ucPin;\
  59. __nop(); __nop();\
  60. NRF_GPIO->OUTSET = 1UL << ucPin;\
  61. __nop(); __nop();\
  62. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  63. __nop(); __nop();\
  64. NRF_GPIO->OUTSET = 1UL << ucPin;\
  65. __nop(); __nop();\
  66. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  67. __nop(); __nop();\
  68. NRF_GPIO->OUTSET = 1UL << ucPin;\
  69. __nop(); __nop();\
  70. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  71. __nop(); __nop();}
  72. #define STACK_DEBUG_MANCHESTER_BYTE59(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  73. __nop(); __nop();\
  74. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  75. __nop(); __nop();\
  76. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  77. __nop(); __nop();\
  78. NRF_GPIO->OUTSET = 1UL << ucPin;\
  79. __nop(); __nop();\
  80. NRF_GPIO->OUTSET = 1UL << ucPin;\
  81. __nop(); __nop();\
  82. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  83. __nop(); __nop();\
  84. NRF_GPIO->OUTSET = 1UL << ucPin;\
  85. __nop(); __nop();\
  86. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  87. __nop(); __nop();}
  88. #define STACK_DEBUG_MANCHESTER_BYTE5A(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  89. __nop(); __nop();\
  90. NRF_GPIO->OUTSET = 1UL << ucPin;\
  91. __nop(); __nop();\
  92. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  93. __nop(); __nop();\
  94. NRF_GPIO->OUTSET = 1UL << ucPin;\
  95. __nop(); __nop();\
  96. NRF_GPIO->OUTSET = 1UL << ucPin;\
  97. __nop(); __nop();\
  98. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  99. __nop(); __nop();\
  100. NRF_GPIO->OUTSET = 1UL << ucPin;\
  101. __nop(); __nop();\
  102. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  103. __nop(); __nop();}
  104. #define STACK_DEBUG_MANCHESTER_BYTE65(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  105. __nop(); __nop();\
  106. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  107. __nop(); __nop();\
  108. NRF_GPIO->OUTSET = 1UL << ucPin;\
  109. __nop(); __nop();\
  110. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  111. __nop(); __nop();\
  112. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  113. __nop(); __nop();\
  114. NRF_GPIO->OUTSET = 1UL << ucPin;\
  115. __nop(); __nop();\
  116. NRF_GPIO->OUTSET = 1UL << ucPin;\
  117. __nop(); __nop();\
  118. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  119. __nop(); __nop();}
  120. #define STACK_DEBUG_MANCHESTER_BYTE66(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  121. __nop(); __nop();\
  122. NRF_GPIO->OUTSET = 1UL << ucPin;\
  123. __nop(); __nop();\
  124. NRF_GPIO->OUTSET = 1UL << ucPin;\
  125. __nop(); __nop();\
  126. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  127. __nop(); __nop();\
  128. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  129. __nop(); __nop();\
  130. NRF_GPIO->OUTSET = 1UL << ucPin;\
  131. __nop(); __nop();\
  132. NRF_GPIO->OUTSET = 1UL << ucPin;\
  133. __nop(); __nop();\
  134. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  135. __nop(); __nop();}
  136. #define STACK_DEBUG_MANCHESTER_BYTE69(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  137. __nop(); __nop();\
  138. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  139. __nop(); __nop();\
  140. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  141. __nop(); __nop();\
  142. NRF_GPIO->OUTSET = 1UL << ucPin;\
  143. __nop(); __nop();\
  144. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  145. __nop(); __nop();\
  146. NRF_GPIO->OUTSET = 1UL << ucPin;\
  147. __nop(); __nop();\
  148. NRF_GPIO->OUTSET = 1UL << ucPin;\
  149. __nop(); __nop();\
  150. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  151. __nop(); __nop();}
  152. #define STACK_DEBUG_MANCHESTER_BYTE6A(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  153. __nop(); __nop();\
  154. NRF_GPIO->OUTSET = 1UL << ucPin;\
  155. __nop(); __nop();\
  156. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  157. __nop(); __nop();\
  158. NRF_GPIO->OUTSET = 1UL << ucPin;\
  159. __nop(); __nop();\
  160. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  161. __nop(); __nop();\
  162. NRF_GPIO->OUTSET = 1UL << ucPin;\
  163. __nop(); __nop();\
  164. NRF_GPIO->OUTSET = 1UL << ucPin;\
  165. __nop(); __nop();\
  166. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  167. __nop(); __nop();}
  168. #define STACK_DEBUG_MANCHESTER_BYTE95(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  169. __nop(); __nop();\
  170. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  171. __nop(); __nop();\
  172. NRF_GPIO->OUTSET = 1UL << ucPin;\
  173. __nop(); __nop();\
  174. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  175. __nop(); __nop();\
  176. NRF_GPIO->OUTSET = 1UL << ucPin;\
  177. __nop(); __nop();\
  178. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  179. __nop(); __nop();\
  180. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  181. __nop(); __nop();\
  182. NRF_GPIO->OUTSET = 1UL << ucPin;\
  183. __nop(); __nop();}
  184. #define STACK_DEBUG_MANCHESTER_BYTE96(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  185. __nop(); __nop();\
  186. NRF_GPIO->OUTSET = 1UL << ucPin;\
  187. __nop(); __nop();\
  188. NRF_GPIO->OUTSET = 1UL << ucPin;\
  189. __nop(); __nop();\
  190. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  191. __nop(); __nop();\
  192. NRF_GPIO->OUTSET = 1UL << ucPin;\
  193. __nop(); __nop();\
  194. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  195. __nop(); __nop();\
  196. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  197. __nop(); __nop();\
  198. NRF_GPIO->OUTSET = 1UL << ucPin;\
  199. __nop(); __nop();}
  200. #define STACK_DEBUG_MANCHESTER_BYTE99(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  201. __nop(); __nop();\
  202. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  203. __nop(); __nop();\
  204. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  205. __nop(); __nop();\
  206. NRF_GPIO->OUTSET = 1UL << ucPin;\
  207. __nop(); __nop();\
  208. NRF_GPIO->OUTSET = 1UL << ucPin;\
  209. __nop(); __nop();\
  210. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  211. __nop(); __nop();\
  212. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  213. __nop(); __nop();\
  214. NRF_GPIO->OUTSET = 1UL << ucPin;\
  215. __nop(); __nop();}
  216. #define STACK_DEBUG_MANCHESTER_BYTE9A(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  217. __nop(); __nop();\
  218. NRF_GPIO->OUTSET = 1UL << ucPin;\
  219. __nop(); __nop();\
  220. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  221. __nop(); __nop();\
  222. NRF_GPIO->OUTSET = 1UL << ucPin;\
  223. __nop(); __nop();\
  224. NRF_GPIO->OUTSET = 1UL << ucPin;\
  225. __nop(); __nop();\
  226. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  227. __nop(); __nop();\
  228. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  229. __nop(); __nop();\
  230. NRF_GPIO->OUTSET = 1UL << ucPin;\
  231. __nop(); __nop();}
  232. #define STACK_DEBUG_MANCHESTER_BYTEA5(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  233. __nop(); __nop();\
  234. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  235. __nop(); __nop();\
  236. NRF_GPIO->OUTSET = 1UL << ucPin;\
  237. __nop(); __nop();\
  238. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  239. __nop(); __nop();\
  240. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  241. __nop(); __nop();\
  242. NRF_GPIO->OUTSET = 1UL << ucPin;\
  243. __nop(); __nop();\
  244. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  245. __nop(); __nop();\
  246. NRF_GPIO->OUTSET = 1UL << ucPin;\
  247. __nop(); __nop();}
  248. #define STACK_DEBUG_MANCHESTER_BYTEA6(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  249. __nop(); __nop();\
  250. NRF_GPIO->OUTSET = 1UL << ucPin;\
  251. __nop(); __nop();\
  252. NRF_GPIO->OUTSET = 1UL << ucPin;\
  253. __nop(); __nop();\
  254. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  255. __nop(); __nop();\
  256. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  257. __nop(); __nop();\
  258. NRF_GPIO->OUTSET = 1UL << ucPin;\
  259. __nop(); __nop();\
  260. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  261. __nop(); __nop();\
  262. NRF_GPIO->OUTSET = 1UL << ucPin;\
  263. __nop(); __nop();}
  264. #define STACK_DEBUG_MANCHESTER_BYTEA9(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  265. __nop(); __nop();\
  266. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  267. __nop(); __nop();\
  268. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  269. __nop(); __nop();\
  270. NRF_GPIO->OUTSET = 1UL << ucPin;\
  271. __nop(); __nop();\
  272. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  273. __nop(); __nop();\
  274. NRF_GPIO->OUTSET = 1UL << ucPin;\
  275. __nop(); __nop();\
  276. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  277. __nop(); __nop();\
  278. NRF_GPIO->OUTSET = 1UL << ucPin;\
  279. __nop(); __nop();}
  280. #define STACK_DEBUG_MANCHESTER_BYTEAA(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  281. __nop(); __nop();\
  282. NRF_GPIO->OUTSET = 1UL << ucPin;\
  283. __nop(); __nop();\
  284. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  285. __nop(); __nop();\
  286. NRF_GPIO->OUTSET = 1UL << ucPin;\
  287. __nop(); __nop();\
  288. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  289. __nop(); __nop();\
  290. NRF_GPIO->OUTSET = 1UL << ucPin;\
  291. __nop(); __nop();\
  292. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  293. __nop(); __nop();\
  294. NRF_GPIO->OUTSET = 1UL << ucPin;\
  295. __nop(); __nop();}
  296. #define STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin) {NRF_GPIO->OUTCLR = 1UL << ucPin;\
  297. __nop(); __nop();\
  298. NRF_GPIO->OUTSET = 1UL << ucPin;\
  299. __nop(); __nop();}
  300. #define STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin) {NRF_GPIO->OUTSET = 1UL << ucPin;\
  301. __nop(); __nop();\
  302. NRF_GPIO->OUTCLR = 1UL << ucPin;\
  303. __nop(); __nop();}
  304. void stack_debug_Manchester_Start(uint8_t ucPin, uint8_t ucCode)
  305. {
  306. __disable_irq();
  307. NRF_GPIO->OUTCLR = 1UL << ucPin;
  308. __nop(); __nop();
  309. switch (ucCode)
  310. {
  311. case 0:
  312. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  313. STACK_DEBUG_MANCHESTER_BYTE55(ucPin);
  314. break;
  315. case 1:
  316. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  317. STACK_DEBUG_MANCHESTER_BYTE56(ucPin);
  318. break;
  319. case 2:
  320. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  321. STACK_DEBUG_MANCHESTER_BYTE59(ucPin);
  322. break;
  323. case 3:
  324. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  325. STACK_DEBUG_MANCHESTER_BYTE5A(ucPin);
  326. break;
  327. case 4:
  328. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  329. STACK_DEBUG_MANCHESTER_BYTE65(ucPin);
  330. break;
  331. case 5:
  332. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  333. STACK_DEBUG_MANCHESTER_BYTE66(ucPin);
  334. break;
  335. case 6:
  336. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  337. STACK_DEBUG_MANCHESTER_BYTE69(ucPin);
  338. break;
  339. case 7:
  340. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  341. STACK_DEBUG_MANCHESTER_BYTE6A(ucPin);
  342. break;
  343. case 8:
  344. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  345. STACK_DEBUG_MANCHESTER_BYTE95(ucPin);
  346. break;
  347. case 9:
  348. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  349. STACK_DEBUG_MANCHESTER_BYTE96(ucPin);
  350. break;
  351. case 10:
  352. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  353. STACK_DEBUG_MANCHESTER_BYTE99(ucPin);
  354. break;
  355. case 11:
  356. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  357. STACK_DEBUG_MANCHESTER_BYTE9A(ucPin);
  358. break;
  359. case 12:
  360. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  361. STACK_DEBUG_MANCHESTER_BYTEA5(ucPin);
  362. break;
  363. case 13:
  364. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  365. STACK_DEBUG_MANCHESTER_BYTEA6(ucPin);
  366. break;
  367. case 14:
  368. STACK_DEBUG_MANCHESTER_PREAMBLE_ODD(ucPin);
  369. STACK_DEBUG_MANCHESTER_BYTEA9(ucPin);
  370. break;
  371. case 15:
  372. STACK_DEBUG_MANCHESTER_PREAMBLE_EVEN(ucPin);
  373. STACK_DEBUG_MANCHESTER_BYTEAA(ucPin);
  374. break;
  375. default:
  376. break;
  377. }
  378. // clear last manchester code state
  379. NRF_GPIO->OUTCLR = 1UL << ucPin;
  380. __nop(); __nop();
  381. // start window
  382. NRF_GPIO->OUTSET = 1UL << ucPin;
  383. __nop(); __nop();
  384. __enable_irq();
  385. }
  386. void stack_debug_Manchester_Stop(uint8_t ucPin)
  387. {
  388. __disable_irq();
  389. // end window
  390. NRF_GPIO->OUTCLR = 1UL << ucPin;
  391. __nop(); __nop();
  392. __enable_irq();
  393. }
  394. #endif // DEBUGGING_PINS_ENABLE