ParaCAN 0.0.40-master SHA: 4c1cf74739
CAN_Para.c File Reference

Hardware-independent parameterinterface implementation via Controller Area Network (CAN) More...

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "CAN_Para.h"
#include "../lib/Para/PARA_Lib.h"
#include "../lib/Para/PARA_ID_System.h"
#include "../lib/Para/PARA_MemoryInfo.h"

Macros

#define CAN_BUFFER_LENGTH   50
 Length of Buffer which is used for write operations to parameter values. More...
 

Functions

static void process_para_data (uint8_t rxdata[8], uint8_t DLC)
 Process received data. More...
 
static void CAN_Para_Ping_Request (void)
 Response to ping from PC. More...
 
static void CAN_Para_Read_one (uint8_t rxdata[8])
 Read request from PC to µC. More...
 
static void CAN_Para_Read_All (uint8_t rxdata[8])
 Read all SubIDs of a parameter. More...
 
static void CAN_Para_Read_Memory (uint8_t rxdata[8])
 Read Memory Area. More...
 
static void CAN_Para_Write (uint8_t rxdata[8])
 Write request. More...
 
void CAN_Para_Init (void)
 Initialization of CAN Parameterinterface. More...
 
uint8_t CAN_Para_ReceiveIRQ (uint8_t data[8], uint32_t id, uint8_t DLC)
 Reads Message from CAN-Interface and handles Parameter Request. More...
 
void CAN_Para_Cyclic (void)
 Cyclic procedure to process messages that needs more than one answer message. More...
 
void CAN_Para_SendPing (void)
 Send ping to connected PCs. More...
 

Variables

const uint16_t cui16_CANBaseAddress
 Base address of the CAN Parameter-interface. Must be defined in main program. More...
 
const uint16_t cui16_CANBroadcastAddress
 Broadcast Address of the CAN Parameter-interface. Must be defined in main program. With this Identifier the Broadcast Pings are send. More...
 
static Parameter_InfoHeader g_CAN_Parameter_info
 Parameter-information of the actual processed Message. More...
 
static uint8_t g_ui8CAN_Para_Packet_id
 Identifier of the actulal processed Message. Is used for follow-up telegrams. More...
 
static volatile uint8_t g_ui8CanAccessInProgress =0
 Mutex to prevent access from other PC while follow-up telegrams are processed. More...
 
static uint32_t g_ui32CAN_RemainingDataToSend
 Length of the remaining data in follow-up telegrams. More...
 
static uint32_t g_ui32CAN_ActualMemoryAddress
 Address of the processed memory-area which is transferred in follow-up telegrams. More...
 
static uint8_t g_ui8CAN_PacketRunningCounter
 Running counter of the actual follow-up telegram. More...
 
static uint32_t g_ui32CANActualOffset
 Actual offset of the processed follow-up telegram. More...
 
static uint8_t g_ui8CANReceiveLength
 Length of the received Telegram. More...
 
static uint8_t g_pui8CANBuffer [50]
 Buffer to process write requests. More...
 

Detailed Description

Hardware-independent parameterinterface implementation via Controller Area Network (CAN)

Author
R. Wegener
Date
17.03.2022


© Copyright 2017-2022 Copyright: Torquetronik GmbH Stütingstraße 30 58285 Gevelsberg

Macro Definition Documentation

◆ CAN_BUFFER_LENGTH

#define CAN_BUFFER_LENGTH   50

Length of Buffer which is used for write operations to parameter values.

If the length of the Buffer is not sufficient during a write operation, Error-code 2 is returned.

Function Documentation

◆ CAN_Para_Cyclic()

void CAN_Para_Cyclic ( void  )

Cyclic procedure to process messages that needs more than one answer message.

This function must be called regularly, or from CAN transmit interrupt. If the global variable g_ui32CAN_RemainingDataToSend > 0 the remaining data is sent. If further characters in the string or other subIDs are to be transmitted, these are sent.

Author
R. Wegener

◆ CAN_Para_Init()

void CAN_Para_Init ( void  )

Initialization of CAN Parameterinterface.

Must be called before using all other functions. Local variables are initialized here.

Author
R. Wegener

◆ CAN_Para_Ping_Request()

static void CAN_Para_Ping_Request ( void  )
static

Response to ping from PC.

Process the Connect from PC (command 1) telegram.

Author
R. Wegener

◆ CAN_Para_Read_All()

static void CAN_Para_Read_All ( uint8_t  rxdata[8])
static

Read all SubIDs of a parameter.

Process the Read all SubIDs (command 4) telegram. Data direction is from µC to PC. Does not work with string data type! Each sub-ID must be transmitted individually.

Parameters
rxdataTransmitted Data bytes
Author
R. Wegener

◆ CAN_Para_Read_Memory()

static void CAN_Para_Read_Memory ( uint8_t  rxdata[8])
static

Read Memory Area.

Process the Read Memory Area (command 5) telegram. Data direction is from µC to PC.

Parameters
rxdataTransmitted Data bytes
Author
R. Wegener

◆ CAN_Para_Read_one()

static void CAN_Para_Read_one ( uint8_t  rxdata[8])
static

Read request from PC to µC.

Process the Read one SubID (command 2) telegram.

Parameters
rxdataData-Bytes from PC
Author
R. Wegener

◆ CAN_Para_ReceiveIRQ()

uint8_t CAN_Para_ReceiveIRQ ( uint8_t  data[8],
uint32_t  id,
uint8_t  DLC 
)

Reads Message from CAN-Interface and handles Parameter Request.

Is normally called from receive-interrupt. After processing the CAN-Message the answer is sent depending on the message type.

Return values
1Data is processed
0Data is not processed.
Parameters
dataData of the received CAN-Telegram.
idIdentifier of the received CAN-Telegram.
DLCNumber of bytes received in this CAN-Telegram.
Author
R. Wegener

◆ CAN_Para_SendPing()

void CAN_Para_SendPing ( void  )

Send ping to connected PCs.

Send one Ping from Device for Autoconnect to PC, to announce presence of Device. The Device starts connecting afterwards. Should mot be send faster than in a 500ms cycle.

Author
R. Wegener

◆ CAN_Para_Write()

static void CAN_Para_Write ( uint8_t  rxdata[8])
static

Write request.

Process the Write of one Sub-ID (command 3) telegram. Data direction is from PC to µC. Only the write request is processed here. The data are processed with subsequent telegrams.

Parameters
rxdataTransmitted Data bytes
Author
R. Wegener

◆ process_para_data()

static void process_para_data ( uint8_t  rxdata[8],
uint8_t  DLC 
)
static

Process received data.

In the case of write access, the data are transmitted in the 2nd and following CAN telegrams. These telegrams are sent with a different ID and are processed here.

Parameters
rxdataReceived Data bytes
DLCnumber of data bytes
Author
R. Wegener

Variable Documentation

◆ cui16_CANBaseAddress

const uint16_t cui16_CANBaseAddress
extern

Base address of the CAN Parameter-interface. Must be defined in main program.

◆ cui16_CANBroadcastAddress

const uint16_t cui16_CANBroadcastAddress
extern

Broadcast Address of the CAN Parameter-interface. Must be defined in main program. With this Identifier the Broadcast Pings are send.

◆ g_CAN_Parameter_info

Parameter_InfoHeader g_CAN_Parameter_info
static

Parameter-information of the actual processed Message.

◆ g_pui8CANBuffer

uint8_t g_pui8CANBuffer[50]
static

Buffer to process write requests.

◆ g_ui32CAN_ActualMemoryAddress

uint32_t g_ui32CAN_ActualMemoryAddress
static

Address of the processed memory-area which is transferred in follow-up telegrams.

◆ g_ui32CAN_RemainingDataToSend

uint32_t g_ui32CAN_RemainingDataToSend
static

Length of the remaining data in follow-up telegrams.

◆ g_ui32CANActualOffset

uint32_t g_ui32CANActualOffset
static

Actual offset of the processed follow-up telegram.

◆ g_ui8CAN_PacketRunningCounter

uint8_t g_ui8CAN_PacketRunningCounter
static

Running counter of the actual follow-up telegram.

◆ g_ui8CAN_Para_Packet_id

uint8_t g_ui8CAN_Para_Packet_id
static

Identifier of the actulal processed Message. Is used for follow-up telegrams.

◆ g_ui8CanAccessInProgress

volatile uint8_t g_ui8CanAccessInProgress =0
static

Mutex to prevent access from other PC while follow-up telegrams are processed.

◆ g_ui8CANReceiveLength

uint8_t g_ui8CANReceiveLength
static

Length of the received Telegram.