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

Detailed Description

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

#include "com_mgr.h"
#include "com_nmt.h"
#include "com_lss.h"
#include "com_sync.h"
#include "com_time.h"
#include <stdio.h>
#include <string.h>
+ Include dependency graph for com_demo.h:
+ This graph shows which files directly or indirectly include this file:

Functions

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

Macro Definition Documentation

◆ TMPL_COM_HAS_CONSOLE

#define TMPL_COM_HAS_CONSOLE   0

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);
}
int32_t ComStatus_tv
Definition com_defs.h:116
@ eCOM_ERR_NONE
Definition com_defs.h:155
ComStatus_tv ComDemoLssProcess(uint8_t ubNetV)
uint8_t ComDemoLssState(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)

◆ ComDemoLssState()

uint8_t ComDemoLssState ( uint8_t ubNetV)

◆ ComDemoNmtConfigurationDone()

void ComDemoNmtConfigurationDone ( uint8_t ubNetV,
uint8_t ubNodeIdV )

◆ ComDemoNmtInit()

ComStatus_tv ComDemoNmtInit ( uint8_t ubNetV)

◆ 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 ComDemoNodeIdentify(uint8_t ubNetV, uint8_t ubNodeIdV)
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)

◆ ComDemoNmtQueueStateChange()

void ComDemoNmtQueueStateChange ( uint8_t ubNetV,
uint8_t ubNodeIdV,
uint8_t ubNmtStateV )

◆ ComDemoNmtStateString()

char * ComDemoNmtStateString ( uint8_t ubNetV,
uint8_t ubNodeIdV )

◆ ComDemoNodeIdentify()

ComStatus_tv ComDemoNodeIdentify ( uint8_t ubNetV,
uint8_t ubNodeIdV )

◆ ComDemoNodeInfoString()

char * ComDemoNodeInfoString ( uint8_t ubNetV,
uint8_t ubNodeIdV )

◆ ComDemoNodeInit()

ComStatus_tv ComDemoNodeInit ( uint8_t ubNetV)

◆ ComDemoNrlStateString()

char * ComDemoNrlStateString ( uint8_t ubNetV)

◆ ComDemoPdoRcvInit()

ComStatus_tv ComDemoPdoRcvInit ( uint8_t ubNetV)

◆ ComDemoPdoTrmInit()

ComStatus_tv ComDemoPdoTrmInit ( uint8_t ubNetV)

◆ ComDemoSdoObjectRead()

ComStatus_tv ComDemoSdoObjectRead ( uint8_t ubNetV,
uint8_t ubNodeIdV )

◆ ComDemoSyncCounter()

ComStatus_tv ComDemoSyncCounter ( uint8_t ubNetV)

◆ ComDemoSyncStart()

ComStatus_tv ComDemoSyncStart ( uint8_t ubNetV)