SCOM Serial Communication Protocol  0.5.2
Data Structures | Macros | Typedefs | Enumerations | Functions
scom_frame.h File Reference

SCOM frame definition. More...

#include "hal.h"
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  HAL_PACKED
 SCOM version record. More...
 

Macros

#define SCOM_MAX_DATA_LENGTH   UINT8_C(255)
 
#define SCOM_SOF_CHARACTER   UINT8_C(0x3a)
 
#define SCOM_FRAME_CTRL_FRAME_NUMBER_MASK   UINT8_C(0x07)
 
#define SCOM_FRAME_CTRL_NOACK_MASK   UINT8_C(0x08)
 
#define SCOM_FRAME_CTRL_FRAME_PRIORITY_MASK   UINT8_C(0x70)
 
#define SCOM_FRAME_CTRL_MULTI_ID_MASK   UINT8_C(0x80)
 

Typedefs

typedef struct HAL_PACKED SCOMFrame
 Definition of an SCOM frame. More...
 

Enumerations

enum  SCOMFrameType { SCOM_FRAMETYPE_PING = 250, SCOM_FRAMETYPE_PONG = 251, SCOM_FRAMETYPE_IDENTIFY = 252 }
 SCOM native frame types. More...
 

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
427
Purpose: SCOM serial communication protocol

Definition in file scom_frame.h.

Macro Definition Documentation

#define SCOM_FRAME_CTRL_FRAME_NUMBER_MASK   UINT8_C(0x07)
#define SCOM_FRAME_CTRL_FRAME_PRIORITY_MASK   UINT8_C(0x70)

Definition at line 41 of file scom_frame.h.

Referenced by SCOMFrame_GetPriority(), and SCOMFrame_SetPriority().

#define SCOM_FRAME_CTRL_MULTI_ID_MASK   UINT8_C(0x80)
#define SCOM_FRAME_CTRL_NOACK_MASK   UINT8_C(0x08)

Definition at line 40 of file scom_frame.h.

Referenced by SCOMFrame_IsAcknowledged(), and SCOMFrame_SetAcknowledgement().

#define SCOM_MAX_DATA_LENGTH   UINT8_C(255)

Defines the maximum length of data (in bytes) that can be sent in a single SCOM frame. The default value assumes that the frame payload can be 255 bytes, according to the SCOM specification. The user may want to change it in order to limit the RAM memory footprint required to handle SCOM packets.

As of version 0.4.0 it is discouraged for the user to define this variable.

Definition at line 28 of file scom_frame.h.

#define SCOM_SOF_CHARACTER   UINT8_C(0x3a)

Typedef Documentation

typedef struct HAL_PACKED SCOMFrame

Definition of an SCOM frame.

Enumeration Type Documentation

SCOM native frame types.

Enumerator
SCOM_FRAMETYPE_PING 

Packet type definition: PING.

SCOM_FRAMETYPE_PONG 

Packet type definition: PONG.

SCOM_FRAMETYPE_IDENTIFY 

Packet type definition: IDENTIFY.

Definition at line 46 of file scom_frame.h.

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.