SCOM Serial Communication Protocol  0.5.2
Macros | Functions
scom_frame.c File Reference

SCOM frame definition. More...

#include "scom_frame.h"
#include "scom_crc.h"
#include "hal.h"

Go to the source code of this file.

Macros

#define HAL_LOG_CHANNEL   SCOM
 
#define HAL_LOG_SUBCHANNEL   FRAME
 

Functions

uint16_t SCOMFrame_GetTotalFrameSize (const SCOMFrame *const frame)
 
bool SCOMFrame_SetType (SCOMFrame *const frame, const uint8_t type)
 
uint8_t SCOMFrame_GetType (const SCOMFrame *const frame)
 
bool SCOMFrame_SetPriority (SCOMFrame *const frame, const uint8_t priority)
 
uint8_t SCOMFrame_GetPriority (const SCOMFrame *const frame)
 
bool SCOMFrame_SetFrameNumber (SCOMFrame *const frame, const uint8_t number)
 
uint8_t SCOMFrame_GetFrameNumber (const SCOMFrame *const frame)
 
bool SCOMFrame_SetPayloadSize (SCOMFrame *const frame, const uint8_t size)
 
uint8_t SCOMFrame_GetPayloadSize (const SCOMFrame *const frame)
 
uint8_t * SCOMFrame_GetPayloadPtr (const SCOMFrame *const frame)
 
uint32_t SCOMFrame_GetTotalPayloadSize (const SCOMFrame *const frame)
 
uint32_t SCOMFrame_GetMultiId (const SCOMFrame *const frame)
 
uint32_t SCOMFrame_GetMultiOffset (const SCOMFrame *const frame)
 
bool SCOMFrame_SetAcknowledgement (SCOMFrame *const frame, const bool ack)
 
bool SCOMFrame_IsMultiframe (const SCOMFrame *const frame)
 
bool SCOMFrame_IsAcknowledged (const SCOMFrame *const frame)
 
uint16_t SCOMFrame_CalculateCRC (const SCOMFrame *const frame)
 

Detailed Description

SCOM frame definition.

License: $License$
Version
Revision
448
Purpose: SCOM serial communication protocol

Definition in file scom_frame.c.

Macro Definition Documentation

#define HAL_LOG_CHANNEL   SCOM

Definition at line 11 of file scom_frame.c.

#define HAL_LOG_SUBCHANNEL   FRAME

Definition at line 12 of file scom_frame.c.

Function Documentation

uint16_t SCOMFrame_CalculateCRC ( const SCOMFrame *const  frame)

Calculates CRC for the given frame.

Parameters
[in]frameSCOMFrame
Returns
calculated CRC (0xffff is returned if NULL frame was passed)

Definition at line 234 of file scom_frame.c.

References CRC16_InitCRC, CRC16_UpdateCRC_Byte, HAL_PACKED::ctrl, HAL_PACKED::payload, HAL_PACKED::singleframe, HAL_PACKED::size, and HAL_PACKED::type.

uint8_t SCOMFrame_GetFrameNumber ( const SCOMFrame *const  frame)

Gets frame number.

Parameters
[in]frameSCOMFrame
Returns

Definition at line 108 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_FRAME_NUMBER_MASK.

uint32_t SCOMFrame_GetMultiId ( const SCOMFrame *const  frame)

Gets the multiId associated with a multi-frame.

Parameters
[in]frameSCOMFrame
Return values
multiIdif the frame is a multi-frame
0if NULL frame was passed or frame is not a multi-frame

Definition at line 166 of file scom_frame.c.

References HAL_PACKED::ctrl, HAL_PACKED::multiframe, HAL_PACKED::payload, and SCOM_FRAME_CTRL_MULTI_ID_MASK.

uint32_t SCOMFrame_GetMultiOffset ( const SCOMFrame *const  frame)

Gets the payload offset of a multi-frame.

Parameters
[in]frameSCOMFrame
Return values
payloadoffset if the frame is a multi-frame
0if NULL frame was passed or frame is not a multi-frame

Definition at line 179 of file scom_frame.c.

References HAL_PACKED::ctrl, HAL_PACKED::multiframe, HAL_PACKED::payload, and SCOM_FRAME_CTRL_MULTI_ID_MASK.

uint8_t* SCOMFrame_GetPayloadPtr ( const SCOMFrame *const  frame)

Gets the pointer to the frame payload.

Parameters
[in]frameSCOMFrame
Returns
pointer to frame payload or NULL if NULL frame was passed

Definition at line 144 of file scom_frame.c.

References HAL_PACKED::ctrl, HAL_PACKED::multiframe, HAL_PACKED::payload, SCOM_FRAME_CTRL_MULTI_ID_MASK, and HAL_PACKED::singleframe.

uint8_t SCOMFrame_GetPayloadSize ( const SCOMFrame *const  frame)

Gets frame payload size.

Parameters
[in]frameSCOMFrame
Return values
0..SCOM_MAX_DATA_LENGTH - frame payload size in bytes
0if NULL frame was passed

Definition at line 133 of file scom_frame.c.

References HAL_PACKED::size.

uint8_t SCOMFrame_GetPriority ( const SCOMFrame *const  frame)

Gets frame priority.

Parameters
[in]frameSCOMFrame
Return values
0..6- frame priority
7indication that this frame was retransmitted
0xffif NULL frame was passed

Definition at line 82 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_FRAME_PRIORITY_MASK.

Referenced by SCOMFrameQueue_Insert().

uint16_t SCOMFrame_GetTotalFrameSize ( const SCOMFrame *const  frame)

Returns the total size in bytes of the SCOMFrame including all its fields.

Parameters
[in]frameSCOMFrame
Returns
total frame size or 0 if NULL frame was passed

Definition at line 20 of file scom_frame.c.

References HAL_PACKED::multiframe, HAL_PACKED::payload, SCOMFrame_IsMultiframe(), HAL_PACKED::size, HAL_PACKED::sof, and HAL_PACKED::sync.

uint32_t SCOMFrame_GetTotalPayloadSize ( const SCOMFrame *const  frame)

Gets total frame payload size. For single-frames this is equal to the SCOMFrame_GetPayloadSize. For multi-frames the total size of the payload is returned.

Parameters
[in]frameSCOMFrame
Return values
totalframe payload size in bytes
0if NULL frame was passed

Definition at line 155 of file scom_frame.c.

References HAL_PACKED::ctrl, HAL_PACKED::multiframe, HAL_PACKED::payload, SCOM_FRAME_CTRL_MULTI_ID_MASK, and HAL_PACKED::size.

uint8_t SCOMFrame_GetType ( const SCOMFrame *const  frame)

Gets frame type.

Parameters
[in]frameSCOMFrame
Return values
0..240- frame type
0xffif NULL frame was passed

Definition at line 56 of file scom_frame.c.

References HAL_PACKED::type.

bool SCOMFrame_IsAcknowledged ( const SCOMFrame *const  frame)

Checks if the frame should be acknowledged or not.

Parameters
[in]frameSCOMFrame
Return values
trueif the frame should be acknowledged, false otherwise

Definition at line 221 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_NOACK_MASK.

Referenced by SCOM_Proc().

bool SCOMFrame_IsMultiframe ( const SCOMFrame *const  frame)

Checks if the frame is a multiframe of singleframe.

Parameters
[in]frameSCOMFrame
Return values
trueif frame is

Definition at line 208 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_MULTI_ID_MASK.

Referenced by SCOMFrame_GetTotalFrameSize().

bool SCOMFrame_SetAcknowledgement ( SCOMFrame *const  frame,
const bool  ack 
)

Sets acknowledgment generation for the given frame.

Parameters
[in,out]frameSCOMFrame
[in]acktrue if acknowledgment should be generated in response to this frame, false otherwise
Return values
trueif acknowledgment was successfully set
falseif NULL frame was passed

Definition at line 192 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_NOACK_MASK.

Referenced by SCOM_SendAllocatedFrameWithoutACK(), and SCOM_SendFrameWithoutAck().

bool SCOMFrame_SetFrameNumber ( SCOMFrame *const  frame,
const uint8_t  number 
)

Sets frame number.

Parameters
[in,out]frameSCOMFrame
numberframe number (0..15)
Return values
trueif frame number was successfully set
falseif bad frame number or NULL frame was passed

Definition at line 93 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_FRAME_NUMBER_MASK.

Referenced by SCOM_Proc().

bool SCOMFrame_SetPayloadSize ( SCOMFrame *const  frame,
const uint8_t  size 
)

Sets frame payload size.

Parameters
[in,out]frameSCOMFrame
[in]typeframe payload size in bytes (0..SCOM_MAX_DATA_LENGTH)
Return values
trueif size was successfully set
falseif bad size or NULL frame was passed

Definition at line 119 of file scom_frame.c.

References SCOM_MAX_DATA_LENGTH, and HAL_PACKED::size.

bool SCOMFrame_SetPriority ( SCOMFrame *const  frame,
const uint8_t  priority 
)

Sets frame priority.

Parameters
[in,out]frameSCOMFrame
[in]priorityframe priority (0 - lowest, 6 - highest)
Return values
trueif priority was successfully set
falseif bad priority or NULL frame was passed

Definition at line 67 of file scom_frame.c.

References HAL_PACKED::ctrl, and SCOM_FRAME_CTRL_FRAME_PRIORITY_MASK.

Referenced by SCOM_SendFrame(), SCOM_SendFrameWithoutAck(), SCOM_SendMultiFrame(), SCOM_SendServiceFrame(), and SCOM_SendServiceMultiFrame().

bool SCOMFrame_SetType ( SCOMFrame *const  frame,
const uint8_t  type 
)

Sets frame type.

Parameters
[in,out]frameSCOMFrame
[in]typeframe type (0..240)
Return values
trueif type was successfully set
falseif bad type or NULL frame was passed

Definition at line 42 of file scom_frame.c.

References HAL_PACKED::type.