CANopen Master Documentation
Version 6.06.04
Loading...
Searching...
No Matches
com_demo.h File Reference

Detailed Description

This file implements service demo functions for a CANopen Master application.

+ Include dependency graph for com_demo.h:

Functions

ComStatus_tv ComDemoLssProcess (uint8_t ubNetV)
 
ComStatus_tv ComDemoNmtProcess (uint8_t ubNetV)
 

Function Documentation

◆ ComDemoLssProcess()

ComStatus_tv ComDemoLssProcess ( uint8_t  ubNetV)
Parameters
[in]ubNetVCANopen Network channel
Returns
Value of enumeration ComErr_e

This sample code shows the interaction between the event handler for LSS and an example LSS master process behaviour. The LSS master process should be called periodically (e.g. every 200 ms). The LSS master process performs the following steps:

  • test for unconfigured nodes
  • run LSS fast-scan if a node has been found
  • assign a node-ID to new nodes
{
//---------------------------------------------------------------------------------------------------
// start action according to internal state
//
switch (ComDemoLssState(ubNetV))
{
//-------------------------------------------------------------------------------------------
// Run LSS fast-scan process: the purpose here is only to obtain the complete LSS address of
// a device, so all parameters are set to 0. If a value (e.g. vendor id) is known it should
// be passed as parameter to increase the scan speed.
//
tvStatusT = ComLssFastscan(ubNetV, 0, 0, 0, 0);
break;
//--------------------------------------------------------
// configure new node-ID
//
tvStatusT = ComLssConfigureNodeId(ubNetV, ComDemoLssGetNodeId());
break;
//--------------------------------------------------------
// switch mode global to waiting
//
break;
//-----------------------------------------------------
// search for non-configured devices
//
default:
break;
}
return(tvStatusT);
}
@ eCOM_ERR_NONE
Definition com_defs.h:155
int32_t ComStatus_tv
Definition com_defs.h:116
ComStatus_tv ComDemoLssProcess(uint8_t ubNetV)
@ eCOM_LSS_PROT_CONF_ID
Definition com_lss.h:142
@ eCOM_LSS_PROT_SWI_GLB
Definition com_lss.h:99
@ eCOM_LSS_PROT_FASTSCAN
Definition com_lss.h:148
ComStatus_tv ComLssFastscan(uint8_t ubNetV, uint32_t ulVendorIdV, uint32_t ulProdCodeV, uint32_t ulRevisionNumV, uint32_t ulSerialNumV)
ComStatus_tv ComLssConfigureNodeId(uint8_t ubNetV, uint8_t ubNodeIdV)
@ eCOM_LSS_MODE_WAITING
Definition com_lss.h:82
ComStatus_tv ComLssSwitchModeGlobal(uint8_t ubNetV, uint8_t ubModeV)

◆ ComDemoNmtProcess()

ComStatus_tv ComDemoNmtProcess ( uint8_t  ubNetV)
Parameters
[in]ubNetVCANopen Network channel
Returns
Value of enumeration ComErr_e

This sample code shows possible reaction on a NMT state change of a CANopen device.

{
uint16_t uwFifoValueT = 0;
uint16_t *puwFifoEntryT;
if (atsNmtNodeS[ubNetV] == 0)
{
if (McFifoIsEmpty(&atsNmtFifoS[ubNetV]) == 0)
{
//-----------------------------------------------------------------------------------
// Read NMT state and node-id from FIFO
//
puwFifoEntryT = McFifoDataOutPtr(&atsNmtFifoS[ubNetV]);
uwFifoValueT = *puwFifoEntryT;
McFifoIncOut(&atsNmtFifoS[ubNetV]);
uint8_t ubNodeIdT = (uint8_t) uwFifoValueT;
uint8_t ubNmtStateT = (uint8_t) (uwFifoValueT >> 8);
switch (ubNmtStateT)
{
atsNmtNodeS[ubNetV] = ubNodeIdT;
ComDemoNodeIdentify(ubNetV, ubNodeIdT);
break;
break;
break;
default:
break;
}
}
}
return (eCOM_ERR_NONE);
}
ComStatus_tv ComDemoNmtProcess(uint8_t ubNetV)
@ eCOM_NMT_STATE_OPERATIONAL
Definition com_nmt.h:89
@ eCOM_NMT_STATE_BOOTUP
Definition com_nmt.h:98
@ eCOM_NMT_STATE_PREOPERATIONAL
Definition com_nmt.h:86
ComStatus_tv ComNmtSetNodeState(uint8_t ubNetV, uint8_t ubNodeIdV, uint8_t ubStateV)
Set NMT state of CANopen device.
void * McFifoDataOutPtr(McFifoCtrl_ts *ptsFifoV)
bool_t McFifoIsEmpty(McFifoCtrl_ts *ptsFifoV)
void McFifoIncOut(McFifoCtrl_ts *ptsFifoV)