Subversion Repositories HomeAutomation

Rev

Rev 939 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "canprintf.h"
  3.  
  4. #if CAN_PRINTF==1
  5. /*
  6. * This is included in the default module somehow, and the user of a module
  7. * only has to enable CAN_PRINTF in config.inc
  8. *
  9. */
  10. #define SEND_BUFFER_SIZE 8
  11. static StdCan_Msg_t printfTxMsg;
  12. static uint8_t bufpoint;
  13. static FILE canstdout = FDEV_SETUP_STREAM(CanPutChar, NULL, _FDEV_SETUP_WRITE);
  14.  
  15. /*----------------------------------------------------------------------------
  16. * Initfunction for printf-CAN
  17. * Call this function from your initiation routine
  18. *
  19. *--------------------------------------------------------------------------*/
  20. void CanPrintf_Init(void)
  21. {
  22.     StdCan_Set_class(printfTxMsg.Header, CAN_MODULE_CLASS_TST);
  23.     StdCan_Set_direction(printfTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  24.     printfTxMsg.Header.ModuleType = 0;
  25.     printfTxMsg.Header.ModuleId = 0;
  26.     printfTxMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_ASCII;
  27.     bufpoint = 0;
  28.     stdout = &canstdout;    //set the output stream
  29. }
  30.  
  31. /*----------------------------------------------------------------------------
  32. * Putchar for CAN
  33. * Implements a small buffer, sends packet over CAN if buffer is full or
  34. * \n-char is sent.
  35. * No timeout to force send, so a string that should be completely printed should
  36. * be terminated by \n
  37. *--------------------------------------------------------------------------*/
  38. int CanPutChar(char c, FILE* stream)
  39. {
  40.     printfTxMsg.Data[bufpoint] = c;
  41.     bufpoint++;
  42.  
  43.     if (c == '\n' || bufpoint >= SEND_BUFFER_SIZE) {
  44.         printfTxMsg.Length = bufpoint;
  45.         StdCan_Put(&printfTxMsg);
  46.         bufpoint = 0;
  47.        
  48.         for (uint16_t i = 1; i > 0; i++) {
  49.             asm("nop");
  50.         }
  51.     }
  52.     return 0;
  53. }
  54. #endif //CAN_PRINTF
  55.