TIME
CANopen_301

## Files

file | CO_TIME.h
| CANopen Time-stamp protocol.

## Data Structures

struct | CO_TIME_t
| TIME producer and consumer object. More...

## Functions

CO_ReturnError_t | CO_TIME_init (CO_TIME_t *TIME, CO_EM_t *em, CO_SDO_t *SDO, CO_NMT_internalState_t *operatingState, uint32_t COB_ID_TIMEMessage, uint32_t TIMECyclePeriod, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx)
| Initialize TIME object. More...
void | CO_TIME_initCallbackPre (CO_TIME_t *TIME, void *object, void(*pFunctSignalPre)(void *object))
| Initialize TIME callback function. More...
uint8_t | CO_TIME_process (CO_TIME_t *TIME, uint32_t timeDifference_us)
| Process TIME communication. More...

## Detailed Description

CANopen Time-stamp protocol.

For CAN identifier see CO_Default_CAN_ID_t

TIME message is used for time synchronization of the nodes on network. One node should be TIME producer, others can be TIME consumers. This is configured with COB_ID_TIME object 0x1012 :

- bit 31 should be set for a consumer
- bit 30 should be set for a producer

### TIME CONSUMER

CO_TIME_init() configuration :

- COB_ID_TIME : 0x80000100L -> TIME consumer with TIME_COB_ID = 0x100
- TIMECyclePeriod :
  - 0 -> no EMCY will be transmitted in case of TIME timeout
  - X -> an EMCY will be transmitted in case of TIME timeout (X * 1.5) ms

Latest time value is stored in `CO->TIME->Time` variable.

### TIME PRODUCER

CO_TIME_init() configuration :

- COB_ID_TIME : 0x40000100L -> TIME producer with TIME_COB_ID = 0x100
- TIMECyclePeriod : Time transmit period in ms

Write time value in `CO->TIME->Time` variable, this will be sent at TIMECyclePeriod.

## Function Documentation

## CO_TIME_init()

CO_ReturnError_t CO_TIME_init | ( | CO_TIME_t * | TIME,
|  | CO_EM_t * | em,
|  | CO_SDO_t * | SDO,
|  | CO_NMT_internalState_t * | operatingState,
|  | uint32_t | COB_ID_TIMEMessage,
|  | uint32_t | TIMECyclePeriod,
|  | CO_CANmodule_t * | CANdevRx,
|  | uint16_t | CANdevRxIdx,
|  | CO_CANmodule_t * | CANdevTx,
|  | uint16_t | CANdevTxIdx
| ) |  |

Initialize TIME object.

Function must be called in the communication reset section.

Parameters

  TIME | This object will be initialized.
  em | Emergency object.
  SDO | SDO server object.
  operatingState | Pointer to variable indicating CANopen device NMT internal state.
  COB_ID_TIMEMessage | Should be intialized with CO_CAN_ID_TIME_STAMP
  TIMECyclePeriod | TIME period in ms (may also be used in consumer mode for timeout detection (1.5x period)).
  CANdevRx | CAN device for TIME reception.
  CANdevRxIdx | Index of receive buffer in the above CAN device.
  CANdevTx | CAN device for TIME transmission.
  CANdevTxIdx | Index of transmit buffer in the above CAN device.

Returns
  CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.

## CO_TIME_initCallbackPre()

void CO_TIME_initCallbackPre | ( | CO_TIME_t * | TIME,
|  | void * | object,
|  | void(*)(void *object) | pFunctSignalPre
| ) |  |

Initialize TIME callback function.

Function initializes optional callback function, which should immediately start processing of CO_TIME_process() function. Callback is called after TIME message is received from the CAN bus.

Parameters

  TIME | This object.
  object | Pointer to object, which will be passed to pFunctSignalPre(). Can be NULL
  pFunctSignalPre | Pointer to the callback function. Not called if NULL.

## CO_TIME_process()

uint8_t CO_TIME_process | ( | CO_TIME_t * | TIME,
|  | uint32_t | timeDifference_us
| ) |  |

Process TIME communication.

Function must be called cyclically.

Parameters

  TIME | This object.
  timeDifference_us | Time difference from previous function call in [microseconds].

Returns
  0: No special meaning.
  1: New TIME message recently received (consumer) / transmited (producer).