CANopen FD Master Library
Making your systems precise, reliable and high-quality - 5.10.01
com_demo_sync.c

//============================================================================//
// File: com_demo_sync.c //
// Description: Examples for SYNC service in CANopen Master stack //
// //
// Copyright (C) MicroControl GmbH & Co. KG //
// 53844 Troisdorf - Germany //
// www.microcontrol.net //
// //
//----------------------------------------------------------------------------//
// The copyright to the computer program(s) herein is the property of //
// MicroControl GmbH & Co. KG, Germany. The program(s) may be used //
// and/or copied only with the written permission of MicroControl GmbH & //
// Co. KG or in accordance with the terms and conditions stipulated in //
// the agreement/contract under which the program(s) have been supplied. //
// //
//============================================================================//
#include "com_sync.h"
#if COM_SYNC_SUPPORT > 0
//----------------------------------------------------------------------------//
// ComDemoSyncCounter() //
// Start SYNC with identifier 201h and SYNC counter, cycle time 20 ms //
//----------------------------------------------------------------------------//
ComStatus_tv ComDemoSyncCounter(uint8_t ubNetV)
{
ComStatus_tv tvStatusT;
//----------------------------------------------------------------
// disable the SYNC service, otherwise we can't change the
// identifier value
//
tvStatusT = ComSyncEnable(ubNetV, 0);
if(tvStatusT != eCOM_ERR_OK)
{
return(tvStatusT);
}
//----------------------------------------------------------------
// now set the identifier to 201h
//
tvStatusT = ComSyncSetId(ubNetV, 0x0201);
if(tvStatusT != eCOM_ERR_OK)
{
return (tvStatusT);
}
//----------------------------------------------------------------
// the SYNC counter shall run from 1 .. 32
//
tvStatusT = ComSyncSetCounter(ubNetV, 32);
if(tvStatusT != eCOM_ERR_OK)
{
return (tvStatusT);
}
//----------------------------------------------------------------
// set the cycle time to 20 ms
// we don't check the return value here because nothing
// bad can happen at this stage
//
ComSyncSetCycleTime(ubNetV, 20000);
//----------------------------------------------------------------
// enable the SYNC service again
//
ComSyncEnable(ubNetV, 1);
return(tvStatusT);
} // ComDemoSyncCounter
//----------------------------------------------------------------------------//
// ComDemoSyncStart() //
// Start SYNC with default identifier and 500 milliseconds cycle time //
//----------------------------------------------------------------------------//
ComStatus_tv ComDemoSyncStart(uint8_t ubNetV)
{
ComStatus_tv tvStatusT;
//----------------------------------------------------------------
// set the cycle time to 500 ms
//
tvStatusT = ComSyncSetCycleTime(ubNetV, 500000);
if(tvStatusT != eCOM_ERR_OK)
{
return(tvStatusT);
}
//----------------------------------------------------------------
// enable the SYNC service
//
tvStatusT = ComSyncEnable(ubNetV, 1);
return(tvStatusT);
} // ComDemoSyncStart
#endif