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

Main API file. More...

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

Go to the source code of this file.

Data Structures

struct  SCOMFrameBuffer
 Definition of the frame buffer used by SCOM. More...
 
struct  HAL_PACKED
 SCOM version record. More...
 
struct  HAL_PACKED
 SCOM version record. More...
 
struct  SCOMACKState
 Descriptor of the ACK state. More...
 
struct  SCOMStatistics
 Descriptor of the SCOM statistics. More...
 
struct  SCOMDataLinkDesc
 SCOM Data Link descriptor. More...
 
struct  SCOMMultiFrameDesc
 Definition of multiframe descriptor structure. More...
 

Macros

#define SCOM_VER_HI   0
 
#define SCOM_VER_LO   5
 
#define SCOM_REVISION   0
 
#define SCOM_DECLARE_FRAME_BUFFER(name, txQueueSize, rxQueueSize)
 This macro declares a frame buffer for SCOM as a fixed pool. More...
 
#define SCOM_DECLARE_FRAME_BUFFER_USING_HEAP(name)
 This macro declares a frame buffer for SCOM that uses heap. More...
 
#define SCOM_DEVICE_INFO_LEN   (sizeof(((SCOMIdentity *)0)->version) + sizeof(((SCOMIdentity *)0)->deviceClass) + sizeof(((SCOMIdentity *)0)->deviceUID))
 
#define SCOM_ERR__COMMUNICATION_ERROR   1
 
#define SCOM_ERR__INTERNAL_ERROR   2
 
#define SCOM_ERR__DATA_TOO_LARGE   3
 
#define SCOM_ERR__TX_OVERLOAD   4
 
#define SCOM_ERR__SYNCHRONIZATION_ERROR   5
 

Typedefs

typedef OSTime(* SCOMClockSource )(void)
 
typedef struct HAL_PACKED SCOMVersion
 SCOM version record. More...
 
typedef struct HAL_PACKED SCOMIdentity
 Definition of a structure that identifies an SCOM device. More...
 
typedef struct SCOMDataLinkDesc SCOMDataLinkDesc
 SCOM Data Link descriptor. More...
 
typedef SCOMDataLinkDescSCOMDataLink
 
typedef bool(* SCOMFrameReceptionHandler )(SCOMDataLink scom, SCOMFrame *frame)
 
typedef void(* SCOMAckReceptionHandler )(SCOMDataLink scom, uint8_t frame_type)
 
typedef void(* SCOMServiceHandler )(SCOMDataLinkDesc *scom, SCOMFrame *frame)
 

Enumerations

enum  SCOMReceiverState { SCOM_RX_WAIT_FOR_SOF, SCOM_RX_ACK, SCOM_RX_FRAME, SCOM_BROKEN_LINK }
 Possible receiver states. More...
 
enum  SCOMConnectionState { SCOM_CONNECTION_UNINITIALIZED = 0, SCOM_CONNECTION_OPERATIONAL = 1, SCOM_CONNECTION_UNSYNCHRONIZED = 2, SCOM_CONNECTION_BROKEN = 3 }
 Possible SCOM connection states. More...
 
enum  SCOMResult {
  SCOM_RESULT_OK, SCOM_ERROR = 1, SCOM_RESULT_ERROR = 1, SCOM_TX_EMPTY,
  SCOM_TX_FULL, SCOM_INTERNAL_ERROR, SCOM_FRAME_RECEIVED, SCOM_RECEIVER_BLOCKED,
  SCOM_NO_FRAME, SCOM_TX_FRAME_BUFFER_OVERRUN, SCOM_RX_FRAME_DATA_TOO_LARGE, SCOM_FRAME_NOT_IN_BUFFER,
  SCOM_USART_TX_BUF_ERROR, SCOM_USART_RX_BUF_ERROR, SCOM_COMMUNICATION_ERROR, SCOM_TX_INTEGRITY_ERROR,
  SCOM_FILTER_LIST_FULL, SCOM_FILTER_TIMEOUT, SCOM_FILTER_ERROR, SCOM_SYNCHRONIZATION_ERROR,
  SCOM_NO_DEVICE, SCOM_RESULT_CRC_MISMATCH
}
 

Functions

SCOMDataLink SCOM_Create (void)
 
void SCOM_Destroy (SCOMDataLinkDesc *const scom)
 
SCOMFrameBufferSCOM_CreateFrameBuffer (size_t rxBuffSize, size_t txBuffSize)
 
void SCOM_DestroyFrameBuffer (SCOMFrameBuffer *frameBuffer)
 
SCOMResult SCOM_Init (SCOMDataLink scom, IODevice iodevice, SCOMFrameBuffer *frameBuffer, SCOMClockSource clockSource, uint32_t ackTimeout, uint32_t deviceClass, uint8_t *deviceUID, uint8_t numberOfServices, uint8_t *serviceIDs)
 
SCOMResult SCOM_Deinit (SCOMDataLink scom)
 
SCOMResult SCOM_InitAsMonitor (SCOMDataLink scom, IODevice iodevice, SCOMFrameBuffer *frameBuffer, SCOMClockSource clockSource, uint32_t ackTimeout)
 
SCOMResult SCOM_RunProcessingThread (SCOMDataLink scom)
 
void SCOM_StopProcessingThread (SCOMDataLink scom)
 
SCOMResult SCOM_EnableConnectivityCheck (SCOMDataLink scom, uint32_t checkPeriod)
 
SCOMResult SCOM_DisableConnectivityCheck (SCOMDataLink scom)
 
SCOMConnectionState SCOM_GetConnectionState (const SCOMDataLinkDesc *const scom)
 
IODevice SCOM_GetIODevice (const SCOMDataLinkDesc *const scom)
 
SCOMResult SCOM_SendFrame (SCOMDataLink scom, uint8_t framePriority, uint8_t frameType, const void *frameData, uint8_t frameDataSize)
 
SCOMResult SCOM_SendFrameWithoutAck (SCOMDataLink scom, uint8_t framePriority, uint8_t frameType, const void *frameData, uint8_t frameDataSize)
 
SCOMResult SCOM_SendMultiFrame (SCOMDataLink scom, uint8_t framePriority, uint8_t frameType, const void *frameData, uint32_t frameDataSize, SCOMMultiFrameDesc *multiFrameDesc)
 
SCOMResult SCOM_SendAllocatedMultiFrame (SCOMDataLink scom, SCOMFrame *frame, SCOMMultiFrameDesc *multiFrameDesc)
 
SCOMResult SCOM_AllocFrame (SCOMDataLink scom, SCOMFrame **framePtr)
 
SCOMResult SCOM_SendAllocatedFrame (SCOMDataLink scom, SCOMFrame *frame)
 
SCOMResult SCOM_SendAllocatedFrameWithoutACK (SCOMDataLink scom, SCOMFrame *frame)
 
SCOMResult SCOM_SetFrameReceptionHandlerFunc (SCOMDataLink scom, SCOMFrameReceptionHandler frameReceptionFunc)
 
SCOMResult SCOM_SetAckReceptionHandlerFunc (SCOMDataLink scom, SCOMAckReceptionHandler ackReceptionFunc)
 
SCOMResult SCOM_SetServiceHandler (SCOMDataLink scom, uint8_t serviceID, SCOMServiceHandler serviceHandlerFunc)
 
SCOMResult SCOM_Proc (SCOMDataLink scom)
 
SCOMFrameSCOM_GetReceivedFrame (SCOMDataLink scom)
 
void SCOM_UnlockFrame (SCOMDataLink scom, SCOMFrame *frame)
 
SCOMStatistics SCOM_GetStatistics (const SCOMDataLinkDesc *const scom)
 
void SCOM_ResetStatistics (SCOMDataLink scom)
 
bool SCOM_IsBusy (SCOMDataLink scom)
 

Detailed Description

Main API file.

SCOM Serial communication protocol.

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

Definition in file scom.h.

Macro Definition Documentation

#define SCOM_DECLARE_FRAME_BUFFER (   name,
  txQueueSize,
  rxQueueSize 
)

This macro declares a frame buffer for SCOM as a fixed pool.

This macro provides a convenient way of declaring a frame buffer to be used by SCOM.

Parameters
namename of the resulting frame buffer structure
txQueueSizenumber of frames that will be available in the transmission queue
rxQueueSizenumber of frames that will be available in the reception queue

Definition at line 37 of file scom.h.

#define SCOM_DECLARE_FRAME_BUFFER_USING_HEAP (   name)

This macro declares a frame buffer for SCOM that uses heap.

This macro provides a convenient way of declaring a frame buffer to be used by SCOM.

Parameters
namename of the resulting frame buffer structure

Definition at line 50 of file scom.h.

#define SCOM_DEVICE_INFO_LEN   (sizeof(((SCOMIdentity *)0)->version) + sizeof(((SCOMIdentity *)0)->deviceClass) + sizeof(((SCOMIdentity *)0)->deviceUID))

Definition at line 97 of file scom.h.

#define SCOM_ERR__COMMUNICATION_ERROR   1

Definition at line 240 of file scom.h.

#define SCOM_ERR__DATA_TOO_LARGE   3

Definition at line 242 of file scom.h.

#define SCOM_ERR__INTERNAL_ERROR   2

Definition at line 241 of file scom.h.

#define SCOM_ERR__SYNCHRONIZATION_ERROR   5

Definition at line 244 of file scom.h.

#define SCOM_ERR__TX_OVERLOAD   4

Definition at line 243 of file scom.h.

#define SCOM_REVISION   0

Definition at line 15 of file scom.h.

Referenced by SCOM_Init().

#define SCOM_VER_HI   0

Definition at line 12 of file scom.h.

Referenced by SCOM_Init().

#define SCOM_VER_LO   5

Definition at line 13 of file scom.h.

Referenced by SCOM_Init().

Typedef Documentation

typedef void(* SCOMAckReceptionHandler)(SCOMDataLink scom, uint8_t frame_type)

Type definition of SCOM ack reception handler function

Definition at line 205 of file scom.h.

typedef OSTime(* SCOMClockSource)(void)

Type definition of SCOM clock source function.

Definition at line 74 of file scom.h.

SCOM data link handle.

Definition at line 195 of file scom.h.

SCOM Data Link descriptor.

typedef bool(* SCOMFrameReceptionHandler)(SCOMDataLink scom, SCOMFrame *frame)

Type definition of SCOM frame reception handler function

Return values
true- function should return true when frame was processed and should be unlock.
false- function should return false when frame wasn't processed and should be added to queue.

Definition at line 202 of file scom.h.

typedef struct HAL_PACKED SCOMIdentity

Definition of a structure that identifies an SCOM device.

typedef void(* SCOMServiceHandler)(SCOMDataLinkDesc *scom, SCOMFrame *frame)

Type definition of SCOM service frame handler function

Definition at line 208 of file scom.h.

typedef struct HAL_PACKED SCOMVersion

SCOM version record.

Enumeration Type Documentation

Possible SCOM connection states.

Enumerator
SCOM_CONNECTION_UNINITIALIZED 
SCOM_CONNECTION_OPERATIONAL 
SCOM_CONNECTION_UNSYNCHRONIZED 
SCOM_CONNECTION_BROKEN 

Definition at line 108 of file scom.h.

Possible receiver states.

Enumerator
SCOM_RX_WAIT_FOR_SOF 
SCOM_RX_ACK 
SCOM_RX_FRAME 
SCOM_BROKEN_LINK 

Definition at line 100 of file scom.h.

enum SCOMResult

Possible SCOM function results

Enumerator
SCOM_RESULT_OK 
SCOM_ERROR 
SCOM_RESULT_ERROR 
SCOM_TX_EMPTY 
SCOM_TX_FULL 
SCOM_INTERNAL_ERROR 
SCOM_FRAME_RECEIVED 
SCOM_RECEIVER_BLOCKED 
SCOM_NO_FRAME 
SCOM_TX_FRAME_BUFFER_OVERRUN 
SCOM_RX_FRAME_DATA_TOO_LARGE 
SCOM_FRAME_NOT_IN_BUFFER 
SCOM_USART_TX_BUF_ERROR 
SCOM_USART_RX_BUF_ERROR 
SCOM_COMMUNICATION_ERROR 
SCOM_TX_INTEGRITY_ERROR 
SCOM_FILTER_LIST_FULL 
SCOM_FILTER_TIMEOUT 
SCOM_FILTER_ERROR 
SCOM_SYNCHRONIZATION_ERROR 
SCOM_NO_DEVICE 
SCOM_RESULT_CRC_MISMATCH 

Definition at line 211 of file scom.h.

Function Documentation

SCOMResult SCOM_AllocFrame ( SCOMDataLink  scom,
SCOMFrame **  framePtr 
)

Allocates new frame in the internal SCOM frame buffer, to allow direct access to SCOMFrame structure and avoid unnecessary copying of data. The allocated frame can later be sent using SCOM_SendAllocatedFrame or deleted using SCOM_UnlockFrame.

Parameters
scomSCOM handle
framePtrpointer to variable, where a pointer to an allocated SCOMFrame structure will be stored
Return values
SCOM_RESULT_OKon success - the framePtr holds a valid pointer to SCOMFrame
SCOM_TX_FULLif there is no more free space to allocate frame in the frame buffer
SCOM_ERRORif other error occurred

Definition at line 706 of file scom.c.

References SCOMFrameQueueItem::frame, SCOMDataLinkDesc::frameBuffer, SCOM_ERROR, SCOM_RESULT_OK, SCOM_TX_FULL, SCOMFrameQueue_Lock(), and SCOMFrameBuffer::txFrameQueue.

SCOMDataLink SCOM_Create ( void  )

Creates an instance of SCOM descriptor.

Returns
pointer to new SCOM descriptor

Definition at line 146 of file scom.c.

Referenced by SCOM_ScanAndRun().

SCOMFrameBuffer* SCOM_CreateFrameBuffer ( size_t  rxBuffSize,
size_t  txBuffSize 
)

Allocates memory (using heap), creates and initializes a frame buffer for SCOM, of a given size. This frame buffer can than be used in a call to SCOM_Init. Alternatively, if heap memory allocation is discouraged, macro SCOM_DECLARE_FRAME_BUFFER can be used to declare the frame buffer statically.

Parameters
rxBuffSizenumber of incoming frames that can fit into the frame buffer
txBuffSizenumber of outgoing frames that can fit into the frame buffer
Returns
pointer to a frame buffer of NULL if heap allocation failed

Definition of a SCOM frame queue.

Frame pool items

First item in the queue

Pool size (number of managed items)

Pool access mutex

Definition at line 174 of file scom.c.

References SCOMFrameQueue::pool, SCOMFrameBuffer::rxFrameQueue, and SCOMFrameBuffer::txFrameQueue.

Referenced by SCOM_ScanAndRun().

SCOMResult SCOM_Deinit ( SCOMDataLink  scom)

Deinitializes the SCOM protocol.

Parameters
scomSCOM descriptor
Returns
SCOM_RESULT_OK or SCOM_ERROR if SCOM descriptor not exist
void SCOM_Destroy ( SCOMDataLinkDesc *const  scom)

Destroys an instance of SCOM descriptor.

Parameters
scomSCOM descriptor

Definition at line 161 of file scom.c.

Referenced by SCOM_ScanAndRun().

void SCOM_DestroyFrameBuffer ( SCOMFrameBuffer frameBuffer)

Destroys the frame buffer, previously created with a call to SCOM_CreateFrameBuffer.

Parameters
frameBufferframe buffer to destroy

Definition at line 218 of file scom.c.

SCOMResult SCOM_DisableConnectivityCheck ( SCOMDataLink  scom)

Disable periodical connectivity check.

Parameters
scomSCOM descriptor
Returns
SCOM_RESULT_OK on success or SCOM_ERROR if initialization parameter were invalid
SCOMResult SCOM_EnableConnectivityCheck ( SCOMDataLink  scom,
uint32_t  checkPeriod 
)

Enables periodical connectivity check. This forces the SCOM to send additional PING frames if needed to ensure, that a frame is exchanged at least once in a check period.

Parameters
scomSCOM descriptor
checkPeriodcheck period
Returns
SCOM_RESULT_OK on success or SCOM_ERROR if one or more of the provided initialization parameters were invalid
SCOMConnectionState SCOM_GetConnectionState ( const SCOMDataLinkDesc *const  scom)

Checks SCOM connection state.

Parameters
scomSCOM descriptor
Return values
SCOM_CONNECTION_UNINITIALIZEDSCOM connection is not initialized
SCOM_CONNECTION_OPERATIONALconnection is operational
SCOM_CONNECTION_UNSYNCHRONIZEDconnection lost synchronization
SCOM_CONNECTION_BROKENconnection was broken

Definition at line 461 of file scom.c.

References SCOMDataLinkDesc::accessGuard, SCOMDataLinkDesc::connectionState, SCOM_ACCESS_GUARD_TIMEOUT, SCOM_CONNECTION_UNINITIALIZED, and SCOM_RESULT_ERROR.

IODevice SCOM_GetIODevice ( const SCOMDataLinkDesc *const  scom)

Gets the IODevice associated with SCOM.

Parameters
scomSCOM descriptor
Returns
IODevice object

Definition at line 482 of file scom.c.

References SCOMDataLinkDesc::iodevice.

SCOMFrame* SCOM_GetReceivedFrame ( SCOMDataLink  scom)

Gets the oldest received frame that is waiting in the reception queue. The caller is responsible for deleting the frame once it is not needed anymore, through a call to SCOM_UnlockFrame.

Parameters
scomSCOM handle
Returns
pointer to pending frame or NULL if there is no pending frame

Definition at line 1065 of file scom.c.

References SCOMFrameQueueItem::frame, SCOMDataLinkDesc::frameBuffer, SCOMFrameBuffer::rxFrameQueue, and SCOMFrameQueue_GetFirstInQueue().

Referenced by SCOM_FilterProc().

SCOMStatistics SCOM_GetStatistics ( const SCOMDataLinkDesc *const  scom)

Gets current SCOM statistics record.

Parameters
scomSCOM handle
Returns
SCOMStatistics structure

Definition at line 1109 of file scom.c.

References SCOMDataLinkDesc::accessGuard, SCOM_ACCESS_GUARD_TIMEOUT, and SCOMDataLinkDesc::stats.

SCOMResult SCOM_Init ( SCOMDataLink  scom,
IODevice  iodevice,
SCOMFrameBuffer frameBuffer,
SCOMClockSource  clockSource,
uint32_t  ackTimeout,
uint32_t  deviceClass,
uint8_t *  deviceUID,
uint8_t  numberOfServices,
uint8_t *  serviceIDs 
)

Initializes the SCOM protocol on top of the provided IODevice object.

Parameters
scomSCOM descriptor
iodeviceIODevice object used as a hardware interface for SCOM
frameBufferpointer to a frame buffer structure (see SCOM_DECLARE_FRAME_BUFFER)
clockSourcefunction returning current time
ackTimeouttime used for detecting timeout in ACK reception
deviceClassclass of the SCOM device
deviceUIDunique identifier of the SCOM device
numberOfServicesnumber of standard services that will be supported by the protocol - must be less or equal to SCOM_MAX_SERVICES
serviceIDsarray of service identifiers (size equals to numberOfServices)
Returns
SCOM_RESULT_OK on success or SCOM_ERROR if one or more of the provided initialization parameters were invalid

Definition at line 230 of file scom.c.

References SCOMDataLinkDesc::accessGuard, SCOMDataLinkDesc::clockSource, SCOMDataLinkDesc::connectionState, SCOMDataLinkDesc::connectivityCheckIncommingCounter, SCOMDataLinkDesc::connectivityCheckOutgoingCounter, SCOMDataLinkDesc::connectivityCheckPeriod, HAL_PACKED::deviceClass, HAL_PACKED::deviceUID, SCOMACKState::frame, SCOMDataLinkDesc::frameBeingTransmitted, SCOMDataLinkDesc::frameBuffer, SCOMStatistics::framesReceived, SCOMStatistics::framesSent, SCOMDataLinkDesc::id, SCOMDataLinkDesc::iodevice, SCOMDataLinkDesc::lastConnectivityCheckTime, SCOMDataLinkDesc::lastFrameNumber, SCOMDataLinkDesc::multiCounter, SCOMStatistics::retransmissionsReceived, SCOMStatistics::retransmissionsSent, HAL_PACKED::revision, SCOMDataLinkDesc::rxAck, SCOMFrameBuffer::rxFrameQueue, SCOMDataLinkDesc::rxState, SCOM_ACK_SOF_CHARACTER, SCOM_CONNECTION_OPERATIONAL, SCOM_ERROR, SCOM_MAX_FRAME_FILTERS, SCOM_MAX_SERVICES, SCOM_RESULT_OK, SCOM_REVISION, SCOM_RX_WAIT_FOR_SOF, SCOM_VER_HI, SCOM_VER_LO, SCOMFrameQueue_Init(), SCOMDataLinkDesc::serviceCount, HAL_PACKED::soack, SCOMDataLinkDesc::stats, HAL_PACKED::sync, SCOMDataLinkDesc::timeout, SCOMDataLinkDesc::txCounter, SCOMFrameBuffer::txFrameQueue, HAL_PACKED::verHi, HAL_PACKED::verLo, and HAL_PACKED::version.

Referenced by SCOM_InitAsMonitor(), and SCOM_ScanAndRun().

SCOMResult SCOM_InitAsMonitor ( SCOMDataLink  scom,
IODevice  iodevice,
SCOMFrameBuffer frameBuffer,
SCOMClockSource  clockSource,
uint32_t  ackTimeout 
)

Initializes the SCOM protocol on top of the provided IODevice object but as a protocol monitor only.

Parameters
scomSCOM descriptor
iodeviceIODevice object used as a hardware interface for SCOM
frameBufferpointer to a frame buffer structure (see SCOM_DECLARE_FRAME_BUFFER)
clockSourcefunction returning current time
ackTimeouttime used for detecting timeout in ACK reception
Returns
SCOM_RESULT_OK on success or SCOM_ERROR if one or more of the provided initialization parameters were invalid

Definition at line 363 of file scom.c.

References SCOMDataLinkDesc::monitorMode, SCOM_Init(), and SCOM_RESULT_OK.

bool SCOM_IsBusy ( SCOMDataLink  scom)

Checks if SCOM is in the middle of some sending or receiving process.

Parameters
scomSCOM handle
Returns
true if SCOM is busy, false otherwise

Definition at line 1044 of file scom.c.

References SCOMDataLinkDesc::frameBeingTransmitted, SCOMDataLinkDesc::frameBuffer, SCOM_FRAME_EMPTY, SCOM_FRAME_TX_SENT, SCOMFrameQueue_GetFirstInQueue(), SCOMFrameQueueItem::state, and SCOMFrameBuffer::txFrameQueue.

SCOMResult SCOM_Proc ( SCOMDataLink  scom)

Implements the SCOM data link layer procedures. Must be called periodically (for ex. in an OS task).

Parameters
scomSCOM handle
Return values
SCOM_RESULT_OKon success
SCOM_COMMUNICATION_ERRORif a communication error was detected
SCOM_SYNCHRONIZATION_ERRORif link was desynchronized
SCOM_ERRORif other error occurred

Definition at line 859 of file scom.c.

References SCOMDataLinkDesc::accessGuard, SCOMDataLinkDesc::clockSource, SCOMDataLinkDesc::connectionState, HAL_PACKED::crc, SCOMFrameQueueItem::frame, SCOMACKState::frame, SCOMDataLinkDesc::frameBeingReceived, SCOMDataLinkDesc::frameBeingTransmitted, SCOMDataLinkDesc::frameBuffer, SCOMStatistics::framesReceived, SCOMStatistics::framesSent, SCOMDataLinkDesc::iodevice, SCOMDataLinkDesc::lastConnectivityCheckTime, SCOMDataLinkDesc::receptionTime, SCOMStatistics::retransmissionsReceived, SCOMStatistics::retransmissionsSent, SCOMDataLinkDesc::rxAck, SCOMDataLinkDesc::rxState, SCOM_ACCESS_GUARD_TIMEOUT, SCOM_ACK_SOF_CHARACTER, SCOM_COMMUNICATION_ERROR, SCOM_CONNECTION_BROKEN, SCOM_CONNECTION_OPERATIONAL, SCOM_CONNECTION_UNSYNCHRONIZED, SCOM_ERROR, SCOM_FRAME_TX_READY_FOR_SEND, SCOM_RESULT_OK, SCOM_RX_ACK, SCOM_RX_FRAME, SCOM_RX_WAIT_FOR_SOF, SCOM_SOF_CHARACTER, SCOM_SYNCHRONIZATION_ERROR, SCOMAckFrame_CalculateCRC(), SCOMAckFrame_Initialize(), SCOMAckFrame_IsValidAck(), SCOMFrame_IsAcknowledged(), SCOMFrame_SetFrameNumber(), SCOMFrameQueue_GetFirstInQueue(), SCOMFrameQueue_Unlock(), SCOMDataLinkDesc::sendTime, SCOMFrameQueueItem::state, SCOMACKState::state, SCOMDataLinkDesc::stats, SCOMDataLinkDesc::timeout, SCOMDataLinkDesc::txAck, SCOMFrameBuffer::txFrameQueue, and HAL_PACKED::type.

void SCOM_ResetStatistics ( SCOMDataLink  scom)

Resets SCOM statistics.

Parameters
scomSCOM handle
SCOMResult SCOM_RunProcessingThread ( SCOMDataLink  scom)

Creates and starts the thread that periodically calls the SCOM_Proc function, that actually runs the protocol engine.

Parameters
scomSCOM descriptor
Returns
SCOM_RESULT_OK on success or SCOM_ERROR if thread creation failed
SCOMResult SCOM_SendAllocatedFrame ( SCOMDataLink  scom,
SCOMFrame frame 
)

Schedules transmission of a frame, that was previously allocated with SCOM_AllocFrame. The frame should have already these properties set: type, priority, dataSize. After being sent, the frame is automatically deleted (unlocked) - there is no need to explicitly call SCOM_UnlockFrame.

Parameters
scomSCOM handle
frameframe previously allocated with SCOM_AllocFrame
Return values
SCOM_RESULT_OKif the frame transmission was scheduled successfully
SCOM_FRAME_NOT_IN_BUFFERif the frame is not part of the SCOM frame buffer
SCOM_ERRORif other error occurred

Definition at line 735 of file scom.c.

References SCOMDataLinkDesc::frameBuffer, HAL_PACKED::null, SCOM_ERROR, SCOM_FRAME_NOT_IN_BUFFER, SCOM_FRAME_TX_READY_FOR_SEND, SCOM_RESULT_OK, SCOM_SOF_CHARACTER, SCOMFrameQueue_GetItemByFrame(), SCOMFrameQueue_Insert(), HAL_PACKED::sof, SCOMFrameQueueItem::state, and SCOMFrameBuffer::txFrameQueue.

SCOMResult SCOM_SendAllocatedFrameWithoutACK ( SCOMDataLink  scom,
SCOMFrame frame 
)

Schedules transmission of a frame, that was previously allocated with SCOM_AllocFrame. The frame should have already these properties set: type, priority, dataSize. After being sent, the frame is automatically deleted (unlocked) - there is no need to explicitly call SCOM_UnlockFrame.

Parameters
scomSCOM handle
frameframe previously allocated with SCOM_AllocFrame
Return values
SCOM_RESULT_OKif the frame transmission was scheduled successfully
SCOM_FRAME_NOT_IN_BUFFERif the frame is not part of the SCOM frame buffer
SCOM_ERRORif other error occurred

Definition at line 766 of file scom.c.

References SCOMDataLinkDesc::frameBuffer, HAL_PACKED::null, SCOM_ERROR, SCOM_FRAME_NOT_IN_BUFFER, SCOM_FRAME_TX_READY_FOR_SEND, SCOM_RESULT_OK, SCOM_SOF_CHARACTER, SCOMFrame_SetAcknowledgement(), SCOMFrameQueue_GetItemByFrame(), SCOMFrameQueue_Insert(), HAL_PACKED::sof, SCOMFrameQueueItem::state, and SCOMFrameBuffer::txFrameQueue.

SCOMResult SCOM_SendAllocatedMultiFrame ( SCOMDataLink  scom,
SCOMFrame frame,
SCOMMultiFrameDesc multiFrameDesc 
)

Schedules transmission of a mulitframe, that was previously allocated with SCOM_AllocFrame. The frame should have already these properties set: type, priority, dataSize. After being sent, the frame is automatically deleted (unlocked) - there is no need to explicitly call SCOM_UnlockFrame.

Parameters
scomSCOM handle
frameframe previously allocated with SCOM_AllocFrame
multiFrameDescpointer to a multiframe descriptor, that holds information about a multiframe sending process
Return values
SCOM_RESULT_OKif the frame transmission was scheduled successfully
SCOM_FRAME_NOT_IN_BUFFERif the frame is not part of the SCOM frame buffer
SCOM_ERRORif other error occurred

Definition at line 650 of file scom.c.

References HAL_PACKED::ctrl, SCOMDataLinkDesc::frameBuffer, SCOMMultiFrameDesc::multi_id, SCOMDataLinkDesc::multiCounter, HAL_PACKED::multiframe, HAL_PACKED::null, HAL_PACKED::payload, SCOMMultiFrameDesc::progress, SCOM_ERROR, SCOM_FRAME_CTRL_MULTI_ID_MASK, SCOM_FRAME_NOT_IN_BUFFER, SCOM_FRAME_TX_READY_FOR_SEND, SCOM_RESULT_OK, SCOM_SOF_CHARACTER, SCOMFrameQueue_GetItemByFrame(), SCOMFrameQueue_Insert(), HAL_PACKED::size, HAL_PACKED::sof, SCOMFrameQueueItem::state, and SCOMFrameBuffer::txFrameQueue.

SCOMResult SCOM_SendFrame ( SCOMDataLink  scom,
uint8_t  framePriority,
uint8_t  frameType,
const void *  frameData,
uint8_t  frameDataSize 
)

Schedules the frame transmission. The frame is copied (along with all the data) to the internal SCOM buffer. If there is no activity on the hardware interface then the frame will be sent at the next call to SCOM_Proc. However if there are other frames (older or with higher priority) the frame will wait for it's turn. This function may be called asynchronously with other SCOM functions and from ISRs.

Parameters
scomSCOM handle
framePrioritypriority of a frame
frameTypetype of frame
frameDatadata associated with the frame or NULL if there is no data
frameDataSizesize of data to be associated with frame
Returns
SCOM_RESULT_OK if the frame was scheduled successfully or SCOM_TX_FRAME_BUFFER_OVERRUN if there is no more free space to buffer the frame
SCOMResult SCOM_SendFrameWithoutAck ( SCOMDataLink  scom,
uint8_t  framePriority,
uint8_t  frameType,
const void *  frameData,
uint8_t  frameDataSize 
)

WARNING: THIS FUNCTION SENDS THE FRAME WITHOUT ACKNOWLEDGEMENT. NO RETRANSMISSION WILL BE HANDLED.

Schedules the frame transmission. The frame is copied (along with all the data) to the internal SCOM buffer. If there is no activity on the hardware interface then the frame will be sent at the next call to SCOM_Proc. However if there are other frames (older or with higher priority) the frame will wait for it's turn. This function may be called asynchronously with other SCOM functions and from ISRs.

Parameters
scomSCOM handle
framePrioritypriority of a frame
frameTypetype of frame
frameDatadata associated with the frame or NULL if there is no data
frameDataSizesize of data to be associated with frame
Returns
SCOM_RESULT_OK if the frame was scheduled successfully or SCOM_TX_FRAME_BUFFER_OVERRUN if there is no more free space to buffer the frame

Definition at line 530 of file scom.c.

References HAL_PACKED::ctrl, SCOMFrameQueueItem::frame, SCOMDataLinkDesc::frameBuffer, HAL_PACKED::null, HAL_PACKED::payload, SCOM_ERROR, SCOM_FRAME_TX_READY_FOR_SEND, SCOM_RESULT_OK, SCOM_SOF_CHARACTER, SCOM_TX_FRAME_BUFFER_OVERRUN, SCOMFrame_SetAcknowledgement(), SCOMFrame_SetPriority(), SCOMFrameQueue_Insert(), SCOMFrameQueue_Lock(), HAL_PACKED::singleframe, HAL_PACKED::size, HAL_PACKED::sof, SCOMFrameQueueItem::state, SCOMFrameBuffer::txFrameQueue, and HAL_PACKED::type.

Referenced by SCOM_WaitForDevice().

SCOMResult SCOM_SendMultiFrame ( SCOMDataLink  scom,
uint8_t  framePriority,
uint8_t  frameType,
const void *  frameData,
uint32_t  frameDataSize,
SCOMMultiFrameDesc multiFrameDesc 
)

Schedules sending of another part of multi-frame packet. The resulting frame is copied (along with all the data) to the internal SCOM buffer, just like in the case of a standard SCOM frame.

Parameters
scomSCOM handle
framePrioritypriority of a frame
frameTypetype of frame
frameDatadata associated with the frame or NULL if there is no data
frameDataSizetotal size of data to send in multi-frame packet
multiFrameDescpointer to a SCOMMultiFrameDesc structure where the information about multi-frame sending progress will be stored - used to enable iterative sending of multi-frames.
Returns
SCOM_RESULT_OK if the frame was scheduled successfully or SCOM_TX_FRAME_BUFFER_OVERRUN if there is no more free space to buffer the frame or SCOM_ERROR if the multiFrameDesc parameter is NULL

Definition at line 574 of file scom.c.

References HAL_PACKED::ctrl, SCOMFrameQueueItem::frame, SCOMDataLinkDesc::frameBuffer, SCOMMultiFrameDesc::multi_id, SCOMDataLinkDesc::multiCounter, HAL_PACKED::multiframe, HAL_PACKED::null, HAL_PACKED::payload, SCOMMultiFrameDesc::progress, SCOM_ERROR, SCOM_FRAME_CTRL_MULTI_ID_MASK, SCOM_FRAME_TX_READY_FOR_SEND, SCOM_RESULT_OK, SCOM_SOF_CHARACTER, SCOM_TX_FRAME_BUFFER_OVERRUN, SCOMFrame_SetPriority(), SCOMFrameQueue_Insert(), SCOMFrameQueue_Lock(), HAL_PACKED::size, HAL_PACKED::sof, SCOMFrameQueueItem::state, SCOMFrameBuffer::txFrameQueue, and HAL_PACKED::type.

SCOMResult SCOM_SetAckReceptionHandlerFunc ( SCOMDataLink  scom,
SCOMAckReceptionHandler  ackReceptionFunc 
)

Sets the ACK reception handler. This handler is a function, that will be called by the SCOM each time an ACK is received.

Parameters
scomSCOM handle
ackReceptionFuncpointer to the handler function
Returns
SCOM_RESULT_OK
SCOMResult SCOM_SetFrameReceptionHandlerFunc ( SCOMDataLink  scom,
SCOMFrameReceptionHandler  frameReceptionFunc 
)

Sets the frame reception handler. This handler is a function, that will be called by the SCOM each time a frame is received. The handler just reacts on the frame, it does not send.

Parameters
scomSCOM handle
frameReceptionFuncpointer to the handler function
Returns
SCOM_RESULT_OK
SCOMResult SCOM_SetServiceHandler ( SCOMDataLink  scom,
uint8_t  serviceID,
SCOMServiceHandler  serviceHandlerFunc 
)

Sets the service frame reception handler. This handler is a function that will be called by the SCOM each time a service frame with the matching serviceID is received. Note however, that all the serviceIDs that should be handled need to be defined during the call to SCOM_Init .

Parameters
scomSCOM handle
serviceIDserviceID
serviceHandlerFuncpointer to the handler function
Returns
SCOM_RESULT_OK on success SCOM_RESULT_ERROR on error

Definition at line 841 of file scom.c.

References SCOM_MAX_SERVICES, SCOM_RESULT_ERROR, and SCOM_RESULT_OK.

void SCOM_StopProcessingThread ( SCOMDataLink  scom)

Starts the thread, previously started with SCOM_RunProcessingThread.

Parameters
scomSCOM descriptor

Definition at line 420 of file scom.c.

References SCOMDataLinkDesc::procTask.

Referenced by SCOM_ScanAndRun().

void SCOM_UnlockFrame ( SCOMDataLink  scom,
SCOMFrame frame 
)

Deletes the frame that was either received through a call to SCOM_GetReceivedFrame or was allocated using SCOM_AllocFrame, but was not sent using SCOM_SendAllocatedFrame.

Parameters
scomSCOM handle
frameframe to delete

Definition at line 1086 of file scom.c.

References SCOMDataLinkDesc::frameBuffer, SCOMFrameBuffer::rxFrameQueue, SCOMFrameQueue_GetItemByFrame(), SCOMFrameQueue_Unlock(), and SCOMFrameBuffer::txFrameQueue.

Referenced by SCOM_FilterProc().