Rev 965 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 905 | arune | 1 | |
| 2 | #include "canprintf.h" |
||
| 3 | |||
| 4 | #if CAN_PRINTF==1 |
||
| 5 | /* |
||
| 939 | arune | 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 |
||
| 905 | arune | 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 | { |
||
| 959 | runge | 22 | StdCan_Set_class(printfTxMsg.Header, CAN_MODULE_CLASS_TST); |
| 23 | StdCan_Set_direction(printfTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 965 | runge | 24 | printfTxMsg.Header.ModuleType = CAN_MODULE_TYPE_TST_DEBUG; |
| 905 | arune | 25 | printfTxMsg.Header.ModuleId = 0; |
| 968 | runge | 26 | printfTxMsg.Header.Command = CAN_MODULE_CMD_DEBUG_PRINTF; |
| 905 | arune | 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 |