Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

720 wiersze
19 KiB

  1. /*******************************************************************************
  2. * *
  3. * Copyright 2010 Rheinmetall Canada Inc. *
  4. * *
  5. * No part of this document may be reproduced, stored in *
  6. * a retrieval system, or transmitted, in any form or by any means, *
  7. * electronic, mechanical, photocopying, recording, or otherwise, *
  8. * without the prior written permission of Rheinmetall Canada Inc. *
  9. * *
  10. *******************************************************************************/
  11. /*
  12. Description:
  13. This is a template file for standard C code file.
  14. */
  15. /* ************************************************************************** */
  16. /* ¤Revision:
  17. 000 20100616 JFM,
  18. Original version.
  19. ### YYYYMMDD Initial, Bug Identification
  20. Change description.
  21. */
  22. /* ************************************************************************** */
  23. /* Includes */
  24. #include "define.h"
  25. #include "Uart.h"
  26. #include "Internaluart.h"
  27. #include <stdio.h>
  28. #include <string.h>
  29. //#include "Watchdog.h"
  30. #ifndef NO_EXTERNAL_UART
  31. #include "sc16IS740Driver.h"
  32. #endif
  33. #include "digitalio.h"
  34. //#include "DriveProtocol.h"
  35. #include "terminal.h"
  36. #include "SIM7080GInterface.h"
  37. /* ************************************************************************** */
  38. /* Local variables */
  39. stUartData astUartData[MAX_UART_HANDLE];
  40. const char *gUartStrings[MAX_UART_HANDLE] = { "LORA" //UART_1
  41. ,"LTE", //UART_5
  42. // ,"CONSOLE" //UART_3
  43. };
  44. /* ************************************************************************** */
  45. /* Private function prototypes */
  46. //void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B
  47. //void _mon_write (const char * s, unsigned int count);
  48. //-----------------------------------------------------------------------------
  49. //-----------------------------------------------------------------------------
  50. void InitUart(void)
  51. {
  52. int i;
  53. InternalUartInit();
  54. //InitSC16S740();
  55. memset(&astUartData,0,sizeof(astUartData));
  56. for(i = 0; i < MAX_UART_HANDLE; i++)
  57. {
  58. astUartData[i].iDataPending = 0; //This flag is 0 when : TxPtr == RxPtr OR Uart is transmitting.
  59. astUartData[i].pcTxInPtr = &astUartData[i].acTxCircularBuffer[0];
  60. astUartData[i].pcTxOutPtr = &astUartData[i].acTxCircularBuffer[0];
  61. //memset(&astUartData[i].acTxCircularBuffer[0],0xDE,UART_MAX_TX_BUFF_SIZE);
  62. astUartData[i].pcRxInDataPtr = astUartData[i].pcRxOutDataPtr = &astUartData[i].acRxCircularBuffer[0];
  63. astUartData[i].iNbRxFIFOPendingBytes = 0;
  64. }
  65. //This is a physical mapping of the UARTS.
  66. //DO NOT CHANGE assignments unless hardware changed !
  67. //
  68. astUartData[UART_1].iIsInternal = 1;
  69. astUartData[UART_1].iPhysicalUartPort = INTERNAL_UART_PORT_2; // (232)
  70. astUartData[UART_2].iIsInternal = 1;
  71. astUartData[UART_2].iPhysicalUartPort = INTERNAL_UART_PORT_5; // (232)
  72. #ifndef NO_EXTERNAL_UART
  73. astUartData[UART_3].iIsInternal = 0;
  74. astUartData[UART_3].iPhysicalUartPort = EXT_UART_1; // (SPI - 232 daughter board)
  75. #endif
  76. setbuf(stdout,NULL); //to use printf without \r
  77. fflush(stdout);
  78. UartOpenComPort(NETWORK_UART_PORT,9600,UART_ONE_STOP_BIT,UART_NO_PARITY); //Open LoRa module port
  79. UartOpenComPort(LTE_IF_UART_PORT,115200,UART_ONE_STOP_BIT,UART_NO_PARITY); //Open LTE module port
  80. #ifdef USE_PRINTF
  81. //UartOpenComPort(CONSOLE_UART_PORT,115200,UART_ONE_STOP_BIT,UART_NO_PARITY); //Open console port
  82. #endif
  83. }
  84. //-----------------------------------------------------------------------------
  85. int UartResetPort(int p_iUartHandle)
  86. {
  87. if(p_iUartHandle > MAX_UART_HANDLE)
  88. return 0;
  89. //reset the port data structures...
  90. astUartData[p_iUartHandle].iDataPending = 0; //This flag is 0 when : TxPtr == RxPtr OR Uart is transmitting.
  91. astUartData[p_iUartHandle].pcTxInPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  92. astUartData[p_iUartHandle].pcTxOutPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  93. astUartData[p_iUartHandle].pcRxInDataPtr = astUartData[p_iUartHandle].pcRxOutDataPtr = &astUartData[p_iUartHandle].acRxCircularBuffer[0];
  94. astUartData[p_iUartHandle].iNbRxFIFOPendingBytes = 0;
  95. if(astUartData[UART_1].iIsInternal == 1)
  96. {
  97. switch(astUartData[p_iUartHandle].iPhysicalUartPort)
  98. {
  99. case INTERNAL_UART_PORT_1:
  100. {
  101. ResetUart1();
  102. break;
  103. }
  104. case INTERNAL_UART_PORT_2:
  105. {
  106. ResetUart2();
  107. break;
  108. }
  109. case INTERNAL_UART_PORT_5:
  110. {
  111. ResetUart5();
  112. break;
  113. }
  114. default:
  115. break;
  116. }
  117. }
  118. else
  119. {
  120. #ifndef NO_EXTERNAL_UART
  121. switch(astUartData[p_iUartHandle].iPhysicalUartPort)
  122. {
  123. case EXT_UART_1:
  124. {
  125. break;
  126. }
  127. default:
  128. break;
  129. }
  130. #endif
  131. }
  132. return 1;
  133. }
  134. //-----------------------------------------------------------------------------
  135. int UartOpenComPort(int p_iUartHandle, int p_iBaudRate, int p_iNbStopBits, int p_iParityEnable)
  136. {
  137. int iStopbits,iParity,iRet;
  138. if(p_iUartHandle >= MAX_UART_HANDLE || p_iUartHandle < 0)
  139. return UART_INVALID_HANDLE;
  140. if(astUartData[p_iUartHandle].iIsInternal == 1)
  141. {
  142. switch(p_iNbStopBits)
  143. {
  144. case UART_ONE_STOP_BIT:
  145. case UART_ONE_HALF_STOP_BIT: //1½ stop bits doesn't exist for internal uart
  146. {
  147. iStopbits = INT_UART_ONE_STOP_BIT;
  148. break;
  149. }
  150. case UART_TWO_STOP_BITS:
  151. {
  152. iStopbits = INT_UART_TWO_STOP_BITS;
  153. break;
  154. }
  155. }
  156. switch(p_iParityEnable)
  157. {
  158. case UART_NO_PARITY:
  159. {
  160. iParity = INT_UART_NO_PARITY;
  161. break;
  162. }
  163. case UART_EVEN_PARITY:
  164. {
  165. iParity = INT_UART_EVEN_PARITY;
  166. break;
  167. }
  168. case UART_ODD_PARTIY:
  169. {
  170. iParity = INT_UART_ODD_PARITY;
  171. break;
  172. }
  173. }
  174. iRet = OpenInternalPort(astUartData[p_iUartHandle].iPhysicalUartPort,
  175. p_iUartHandle,
  176. &astUartData[p_iUartHandle].acTxCircularBuffer[0],
  177. &astUartData[p_iUartHandle].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE-1],
  178. p_iBaudRate,
  179. iStopbits,
  180. iParity);
  181. }
  182. #ifndef NO_EXTERNAL_UART
  183. else
  184. {
  185. switch(p_iNbStopBits)
  186. {
  187. case UART_ONE_STOP_BIT:
  188. {
  189. iStopbits = ONE_STOP_BIT;
  190. break;
  191. }
  192. case UART_ONE_HALF_STOP_BIT: //1½ stop bits doesn't exist for internal uart
  193. {
  194. iStopbits = ONE_HALF_STOP_BIT;
  195. break;
  196. }
  197. case UART_TWO_STOP_BITS:
  198. {
  199. iStopbits = TWO_STOP_BITS;
  200. break;
  201. }
  202. }
  203. switch(p_iParityEnable)
  204. {
  205. case UART_NO_PARITY:
  206. {
  207. iParity = NO_PARITY;
  208. break;
  209. }
  210. case UART_EVEN_PARITY:
  211. {
  212. iParity = EVEN_PARITY;
  213. break;
  214. }
  215. case UART_ODD_PARTIY:
  216. {
  217. iParity = ODD_PARITY;
  218. break;
  219. }
  220. }
  221. iRet = OpenExternalPort(astUartData[p_iUartHandle].iPhysicalUartPort,
  222. p_iUartHandle,
  223. &astUartData[p_iUartHandle].acTxCircularBuffer[0],
  224. &astUartData[p_iUartHandle].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE-1],
  225. p_iBaudRate,
  226. iStopbits,
  227. iParity);
  228. }
  229. #endif
  230. return iRet;
  231. }
  232. //-----------------------------------------------------------------------------
  233. //-----------------------------------------------------------------------------
  234. //All the uart callback function assignment must be done here !!!
  235. //This must be changed if hardware changes or if port assignment is changed !!!
  236. //
  237. int UartReceiveData(int p_iUartHandle, char *p_pcBuffer, int p_iSize)
  238. {
  239. int i;
  240. stUartData *p_stUartDatPtr = &astUartData[p_iUartHandle];
  241. if(p_iUartHandle < 0 && p_iUartHandle >= MAX_UART_HANDLE)
  242. {
  243. //TODO: Flag a logic error !
  244. return 0;
  245. }
  246. for(i = 0; i < p_iSize; i++)
  247. {
  248. *p_stUartDatPtr->pcRxInDataPtr++ = *p_pcBuffer++;
  249. if(p_stUartDatPtr->pcRxInDataPtr > &p_stUartDatPtr->acRxCircularBuffer[UART_MAX_RX_BUFF_SIZE-1])
  250. {
  251. p_stUartDatPtr->pcRxInDataPtr = &p_stUartDatPtr->acRxCircularBuffer[0]; //wrap pointer
  252. // printf("Wrap\n");
  253. }
  254. }
  255. p_stUartDatPtr->iNbRxFIFOPendingBytes += p_iSize;
  256. if(p_stUartDatPtr->iNbRxFIFOPendingBytes >= UART_MAX_RX_BUFF_SIZE)
  257. PRINTF("RX FIFO Overflow\n");
  258. /* switch(p_iUartHandle)
  259. {
  260. case UART_0:
  261. {
  262. break;
  263. }
  264. case UART_1:
  265. {
  266. break;
  267. }
  268. case UART_2:
  269. {
  270. break;
  271. }
  272. case UART_3:
  273. {
  274. break;
  275. }
  276. case UART_4:
  277. {
  278. break;
  279. }
  280. case UART_5:
  281. {
  282. break;
  283. }
  284. } */
  285. return 1;
  286. }
  287. int UartGetPendingDataSize(int iUartHandle)
  288. {
  289. stUartData *p_stUartDatPtr = &astUartData[iUartHandle];
  290. if(p_stUartDatPtr->pcRxInDataPtr == p_stUartDatPtr->pcRxOutDataPtr)
  291. {
  292. return 0;
  293. }
  294. else if(p_stUartDatPtr->pcRxOutDataPtr < p_stUartDatPtr->pcRxInDataPtr)
  295. {
  296. return(p_stUartDatPtr->pcRxInDataPtr - p_stUartDatPtr->pcRxOutDataPtr);
  297. }
  298. else
  299. {
  300. int size = &p_stUartDatPtr->acRxCircularBuffer[UART_MAX_RX_BUFF_SIZE-1] - p_stUartDatPtr->pcRxOutDataPtr;
  301. size += p_stUartDatPtr->pcRxInDataPtr - &p_stUartDatPtr->acRxCircularBuffer[0];
  302. return size;
  303. }
  304. }
  305. //-----------------------------------------------------------------------------
  306. //-----------------------------------------------------------------------------
  307. int UartTransmitData(int p_iUartHandle, char *p_pcBuffer, int p_iSize)
  308. {
  309. int iRet = 0;
  310. // Case where OutPtr < InPtr
  311. // * = Available space
  312. //
  313. //Top ---->|---------------|
  314. // | * |
  315. //OutPtr ->| |
  316. // | |
  317. // | (p_pcBuffer) | //Available size = (OutPtr - Top) + (Bottom - InPtr)
  318. // | |
  319. //InPtr -->| |
  320. // | * |
  321. // | * |
  322. //Bottom ->|---------------|
  323. // Case where OutPtr > InPtr
  324. // * = Available space
  325. //
  326. //Top ---->|---------------|
  327. // | |
  328. //InPtr -->| |
  329. // | * |
  330. // | * | //available size = OutPtr - InPtr
  331. // | * |
  332. //OutPtr ->| |
  333. // | (p_pcBuffer) |
  334. // | |
  335. //Bottom ->|---------------|
  336. //Check if data buffer fits in remaining circular buffer space
  337. if(astUartData[p_iUartHandle].pcTxOutPtr < astUartData[p_iUartHandle].pcTxInPtr)
  338. {
  339. //Calculate remaining buffer space and check if it's enough to fit requested data buffer
  340. if(p_iSize > ((astUartData[p_iUartHandle].pcTxOutPtr - &astUartData[p_iUartHandle].acTxCircularBuffer[0]) + //Outptr - Top
  341. (&astUartData[p_iUartHandle].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE-1] - astUartData[p_iUartHandle].pcTxInPtr))) //Bottom - Inptr
  342. {
  343. //Drop remaining packets, flush buffer
  344. astUartData[p_iUartHandle].iDataPending = 0;
  345. astUartData[p_iUartHandle].pcTxInPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  346. astUartData[p_iUartHandle].pcTxOutPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  347. return UART_BUFFER_FULL;
  348. }
  349. }
  350. else if(astUartData[p_iUartHandle].pcTxInPtr < astUartData[p_iUartHandle].pcTxOutPtr)
  351. {
  352. //Calculate remaining buffer space and check if it's enough to fit requested data buffer
  353. if(p_iSize > (astUartData[p_iUartHandle].pcTxOutPtr - astUartData[p_iUartHandle].pcTxInPtr))
  354. {
  355. //Drop remaining packets, flush buffer
  356. astUartData[p_iUartHandle].iDataPending = 0; //Force data pending flag to flush buffer
  357. astUartData[p_iUartHandle].pcTxInPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  358. astUartData[p_iUartHandle].pcTxOutPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  359. return UART_BUFFER_FULL;
  360. }
  361. }
  362. else //OutPtr = InPtr
  363. {
  364. if(p_iSize > UART_MAX_TX_BUFF_SIZE - 1) //message is too big to fit in buffer !!!
  365. {
  366. //Drop remaining packets, flush buffer
  367. astUartData[p_iUartHandle].iDataPending = 0; //Force data pending flag to flush buffer
  368. astUartData[p_iUartHandle].pcTxInPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  369. astUartData[p_iUartHandle].pcTxOutPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  370. return UART_BUFFER_FULL;
  371. }
  372. }
  373. int i;
  374. for(i = 0; i < p_iSize; i++)
  375. {
  376. *astUartData[p_iUartHandle].pcTxInPtr++ = *p_pcBuffer++; //fill circular buffer
  377. if(astUartData[p_iUartHandle].pcTxInPtr > &astUartData[p_iUartHandle].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE-1]) //check for wrapping
  378. {
  379. astUartData[p_iUartHandle].pcTxInPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0];
  380. }
  381. }
  382. //Now flag pending data for transmission.
  383. astUartData[p_iUartHandle].iDataPending = 1; //The data send will start on next Main loop processing
  384. return iRet;
  385. }
  386. //-----------------------------------------------------------------------------
  387. //-----------------------------------------------------------------------------
  388. //Some data has been entirely sent
  389. //Move output pointer
  390. //
  391. int DataSentNotification(int p_iUartHandle,int DataSize)
  392. {
  393. //Check wrapping.
  394. if(astUartData[p_iUartHandle].pcTxOutPtr + DataSize < &astUartData[p_iUartHandle].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE])
  395. {
  396. astUartData[p_iUartHandle].pcTxOutPtr += DataSize;
  397. }
  398. else //Pointer must wrap
  399. {
  400. //Top ------>|---------------|
  401. // | * |
  402. //Final Pos->| | // Final Pos = Top + *
  403. // | |
  404. // | (buffer) | // DataSize = & + *
  405. // | | // & = Bottom - OutPtr
  406. //OutPtr --->| | // * = DataSize - &
  407. // | & | // FinalPos = Top + (DataSize - (Bottom - OutPtr))
  408. // | & |
  409. //Bottom --->|---------------|
  410. // if(p_iUartHandle != PRINTF_UART_PORT)
  411. // printf("Out wrap\r");
  412. DataSize -= (&astUartData[p_iUartHandle].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE] - astUartData[p_iUartHandle].pcTxOutPtr); //p_iSize - (Bottom - OutPtr)
  413. astUartData[p_iUartHandle].pcTxOutPtr = &astUartData[p_iUartHandle].acTxCircularBuffer[0] + DataSize; //Top + new p_iSize
  414. }
  415. //Check if data is pending in buffer
  416. if(astUartData[p_iUartHandle].pcTxOutPtr != astUartData[p_iUartHandle].pcTxInPtr)
  417. {
  418. astUartData[p_iUartHandle].iDataPending = 1;
  419. }
  420. else
  421. {
  422. astUartData[p_iUartHandle].iDataPending = 0;
  423. // LORA_MODULE_TX_LED_PIN = LED_OFF;
  424. }
  425. return UART_OK;
  426. }
  427. //-----------------------------------------------------------------------------
  428. //-----------------------------------------------------------------------------
  429. //Called by main loop. Check if any uart has data pending to be sent
  430. //
  431. int UartTick(void)
  432. {
  433. int i = 0;
  434. int iRet;
  435. int p_iSize;
  436. char aTempBuffer[UART_MAX_RX_BUFF_SIZE];
  437. TickInternalUart();
  438. //Send...
  439. for(i = 0; i < MAX_UART_HANDLE; i++)
  440. {
  441. if(astUartData[i].iDataPending)
  442. {
  443. char *pcTxInPtr = astUartData[i].pcTxInPtr;
  444. //Check remaining data size.
  445. if(astUartData[i].pcTxOutPtr < pcTxInPtr)
  446. {
  447. p_iSize = pcTxInPtr - astUartData[i].pcTxOutPtr;
  448. }
  449. else
  450. {
  451. p_iSize = ((&astUartData[i].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE] - astUartData[i].pcTxOutPtr) +
  452. (pcTxInPtr - &astUartData[i].acTxCircularBuffer[0]));
  453. }
  454. if(astUartData[i].iIsInternal) //Uart handle mapped to PIC internal uart
  455. {
  456. astUartData[i].iDataPending = 0;
  457. iRet = SendInternalUartData(astUartData[i].pcTxOutPtr,
  458. p_iSize,
  459. astUartData[i].iPhysicalUartPort,
  460. &astUartData[i].acTxCircularBuffer[0],
  461. &astUartData[i].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE-1]);
  462. }
  463. #ifndef NO_EXTERNAL_UART
  464. else //mapped to external uart
  465. {
  466. astUartData[i].iDataPending = 0;
  467. iRet = SendExternalUartData(astUartData[i].iPhysicalUartPort, astUartData[i].pcTxOutPtr, p_iSize,&astUartData[i].acTxCircularBuffer[0], &astUartData[i].acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE-1]);
  468. }
  469. #endif
  470. //TODO: manage return values
  471. switch(iRet)
  472. {
  473. case UART_OK:
  474. {
  475. break;
  476. }
  477. case UART_PORT_BUSY:
  478. case UART_BUFFER_FULL:
  479. {
  480. astUartData[i].iDataPending = 1;
  481. break;
  482. }
  483. case UART_PORT_NOT_OPENED:
  484. {
  485. break;
  486. }
  487. }
  488. }
  489. //Receive...
  490. // int iNbPendingData = astUartData[i].iNbRxFIFOPendingBytes; //JFM 2012-09-05
  491. int iNbPendingData = UartGetPendingDataSize(i);
  492. if(iNbPendingData > 0)
  493. {
  494. int byte;
  495. for(byte = 0; byte < iNbPendingData; byte++)
  496. {
  497. aTempBuffer[byte] = *astUartData[i].pcRxOutDataPtr++;
  498. if(astUartData[i].pcRxOutDataPtr > &astUartData[i].acRxCircularBuffer[UART_MAX_RX_BUFF_SIZE-1])
  499. astUartData[i].pcRxOutDataPtr = &astUartData[i].acRxCircularBuffer[0]; //wrap pointer
  500. }
  501. astUartData[i].iNbRxFIFOPendingBytes -= iNbPendingData;
  502. switch(i)
  503. {
  504. // case DRIVE_UART_PORT:
  505. // {
  506. // //printf("drive rx\n");
  507. // DriveProtocolRxData(aTempBuffer,iNbPendingData);
  508. // break;
  509. // }
  510. // case CU_UART_PORT:
  511. // {
  512. // CUProtocolRxData(aTempBuffer,iNbPendingData); // HCAM 20120918
  513. // break;
  514. // }
  515. case NETWORK_UART_PORT:
  516. {
  517. //HEARTBEAT_LED_1_TOGGLE_REG = HEARTBEAT_LED_1_TOGGLE_MASK;
  518. //UartTransmitData(CONSOLE_UART_PORT, aTempBuffer, iNbPendingData);//echo received character
  519. int i = 0;
  520. for(i = 0; i< iNbPendingData; i++)
  521. {
  522. ProtocolAnalyzeNewData(aTempBuffer[i]);
  523. //RxTerminalData(aTempBuffer[i]);
  524. }
  525. break;
  526. }
  527. case LTE_IF_UART_PORT:
  528. {
  529. int i = 0;
  530. for(i = 0; i< iNbPendingData; i++)
  531. {
  532. // LTE_MODULE_RX_LED_PIN = ~LTE_MODULE_RX_LED_PIN;
  533. LTEModuleNewData(aTempBuffer[i]);
  534. //ProtocolAnalyzeNewData(aTempBuffer[i]);
  535. //RxTerminalData(aTempBuffer[i]);
  536. }
  537. break;
  538. }
  539. }
  540. }
  541. }
  542. return UART_OK;
  543. }
  544. //-----------------------------------------------------------------------------
  545. //
  546. // This function is used in the case of a large amount of data to be sent or received
  547. // in a process without going back to main loop.
  548. void UartBlockAndTick(unsigned int TickCount)
  549. {
  550. int i;
  551. // KickWatchdog();
  552. for(i = 0; i < TickCount; i++)
  553. {
  554. UartTick();
  555. }
  556. // KickWatchdog();
  557. }
  558. //-----------------------------------------------------------------------------
  559. //-----------------------------------------------------------------------------
  560. //
  561. // This function is used in the case of a large amount of data to be sent or received
  562. // in a process without going back to main loop.
  563. int UartBlockUntillBufEmpty(int iUartHandle)
  564. {
  565. if(iUartHandle >= MAX_UART_HANDLE)
  566. return 0;
  567. // KickWatchdog();
  568. while(astUartData[iUartHandle].iDataPending)
  569. {
  570. UartTick();
  571. }
  572. // KickWatchdog();
  573. return 1;
  574. }
  575. //-----------------------------------------------------------------------------
  576. //-----------------------------------------------------------------------------
  577. //Overload the stdio character output routine to redirect printfs
  578. //
  579. //void _mon_putc(char c)
  580. //{
  581. // KickWatchdog();
  582. // U2TXREG = c;
  583. // while (U2STAbits.TRMT==0);
  584. //#ifdef USE_BLOCKING_PRINTF
  585. // switch(CONSOLE_UART_PORT)
  586. // {
  587. // case UART_1: //(422) Uart 1B
  588. // {
  589. // if(U1MODEbits.ON == 1)
  590. // {
  591. // U1TXREG = c;
  592. // while (U1STAbits.TRMT==0);
  593. // }
  594. // break;
  595. // }
  596. // case UART_2: //(422) Uart 2A
  597. // {
  598. // if(U2MODEbits.ON == 1)
  599. // {
  600. // U2TXREG = c;
  601. // while (U2STAbits.TRMT==0);
  602. // }
  603. // break;
  604. // }
  605. // }
  606. //#else
  607. // UartTransmitData(PRINTF_UART_PORT, &c, 1);
  608. //#endif
  609. // UartTransmitData(CONSOLE_UART_PORT, &c, 1);
  610. // Nop();
  611. // KickWatchdog();
  612. //}
  613. /*
  614. void _mon_write (const char * s, unsigned int count)
  615. {
  616. #ifdef USE_BLOCKING_PRINTF
  617. int i;
  618. for(i = 0; i < count; i++)
  619. _mon_putc(*s++);
  620. #else
  621. UartTransmitData(UART_10, s, count);
  622. #endif
  623. }*/
  624. //EOF