Implementation of hardware independent serial driver for CSI. More...
#include "csi_bus.h"
#include <string.h>
#include "csi_hwserial.h"
#include "csi_const.h"
#include "csi_crc.h"
#include "csi_types.h"
Macros | |
#define | CSI_ACK_ERR 'F' |
negative acknowledge | |
#define | CSI_ACK_OK 'O' |
positive acknowledge | |
#define | CSI_CMD_ANSWER 0x00 |
answer from device | |
#define | CSI_CMD_DATA_READ 0x10 |
read up to 4 bytes of data | |
#define | CSI_CMD_DATA_WRITE 0x11 |
write up to 4 bytes of data | |
#define | CSI_CMD_SEG_READ 0x14 |
read segment | |
#define | CSI_CMD_SEG_READ_INIT 0x12 |
start read of segmented data | |
#define | CSI_CMD_SEG_WRITE 0x15 |
write segment | |
#define | CSI_CMD_SEG_WRITE_INIT 0x13 |
initialize segmented write | |
#define | CSI_COMM_TIMEOUT_MS 500 |
default timeout | |
#define | WORDSIZE_CRC_1 1 |
#define | WORDSIZE_DATA_BYTES_2 2 |
#define | WORDSIZE_ERR_CODE_2 2 |
#define | WORDSIZE_EXPEDITED_DATA_2 2 |
#define | WORDSIZE_HEADER_1 1 |
#define | WORDSIZE_INDEX_1 1 |
#define | WORDSIZE_INDEX_SUB_2 2 |
#define | WORDSIZE_OBJECT_LEN_2 2 |
#define | WORDSIZE_OPCODE_LEN_1 1 |
#define | WORDSIZE_SEG_CONTROL_BYTE_1 1 |
#define | WORDSIZE_SUB_AND_NODE_ID_1 1 |
Functions | |
static int | Csi_CreateByteStreamV2 (TCsiFrameBuf *Frame, TCsiFrameBuf *ByteStream) |
static void | Csi_MemcpySwap (void *pDestBuf, const void *pSrcBuf, uint32_t dwDataSize) |
static uint16_t | Csi_PrepareFrameHeader (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint8_t Command, uint8_t DataAndCrcWordSize, uint16_t *CRC) |
static void | Csi_PrepareTxFrameV2 (TCsiFrameBuf *TxFrame, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pTransfDWord, uint8_t Write) |
static void | Csi_StoreCrcIntoFrame (struct CsiBus *pBus, uint8_t DataAndCrcWordSize, uint16_t *CRC) |
static uint16_t | Csi_StoreIntoFrame (uint16_t *TxFrame, const void *pWordData, uint16_t Bytes, uint16_t *CRC) |
static uint16_t | Csi_StoreWordIntoFrame (uint16_t *TxFrame, uint16_t Data, uint16_t *CRC) |
static void | Csi_StoreWordIntoFrameV2 (uint8_t *TxFrame, uint16_t Data) |
static long | CsiBus_ExecuteSingleTransfer (struct CsiBus *pBus, uint8_t DataAndCrcWordSize, uint8_t RxWordsMinus1) |
static long | CsiBus_ReceiveResponseV2 (struct CsiBus *pBus, TCsiFrameBuf *RxFrame) |
static long | CsiBus_SendAckn (struct CsiBus *pBus) |
static long | CsiBus_TransfData (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pTransfDWord, uint8_t bWrite) |
long | CsiBus_TransfDataV2 (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pTransfDWord, uint8_t Write) |
static long | CsiBus_WaitForAckn (struct CsiBus *pBus) |
static long | CsiBus_WaitForChar (struct CsiBus *pBus, uint8_t WaitChar) |
long | CsiBusClose (struct CsiBus *pBus) |
Close connection. More... | |
long | CsiBusOpen (struct CsiBus *pBus) |
This function initializes connection to CSI bus. More... | |
long | CsiBusReadData (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pRxDWord) |
This function reads up to 4 bytes of data from device object dictionary. More... | |
long | CsiBusReadDataV2 (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t *pRxDWord) |
This function reads up to 4 bytes of data from device object dictionary using the new serial protocol version V2. More... | |
long | CsiBusReadLargeData (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint8_t *pDataBuffer, uint16_t BufferSize) |
Use this function if you need to read more than 4 bytes of data. More... | |
long | CsiBusWriteData (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t TxDWord) |
This function writes up to 4 bytes of data into device object dictionary. More... | |
long | CsiBusWriteDataV2 (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint32_t TxDWord) |
This function writes up to 4 bytes of data into device object dictionary using the new serial protocol version V2. More... | |
long | CsiBusWriteLargeData (struct CsiBus *pBus, uint8_t NodeId, uint16_t ObjDicIdx, uint8_t ObjDicSub, uint8_t *pDataBuffer, uint32_t DataSize, CsiDataTransferCallback Callback) |
Use this function if you need to write more than 4 bytes of data. More... | |
Variables | |
static const uint8_t | DLE = 0x90 |
static const uint8_t | STX = 0x02 |
Detailed Description
Implementation of hardware independent serial driver for CSI.
- Date
- 2009/09/08
Function Documentation
long CsiBusClose | ( | struct CsiBus * | pBus | ) |
Close connection.
- Parameters
-
[in] pBus Bus object to finish communication
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiClose().
long CsiBusOpen | ( | struct CsiBus * | pBus | ) |
This function initializes connection to CSI bus.
- Parameters
-
[in] pBus Bus object with properly set timeout value and configured serial channel data
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiConnectToDevice(), and CsiOpen().
long CsiBusReadData | ( | struct CsiBus * | pBus, |
uint8_t | NodeId, | ||
uint16_t | ObjDicIdx, | ||
uint8_t | ObjDicSub, | ||
uint32_t * | pRxDWord | ||
) |
This function reads up to 4 bytes of data from device object dictionary.
- Parameters
-
[in] pBus Bus object the device is attached to [in] NodeId NodeId (1 - 30) of device to read from [in] ObjDicIdx Index into device object dictionary [in] ObjDicSub Sub entry of object dictionary entry [in] pRxDWord Points to DWord buffer for storage of received data
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiDevReadObject().
long CsiBusReadDataV2 | ( | struct CsiBus * | pBus, |
uint8_t | NodeId, | ||
uint16_t | ObjDicIdx, | ||
uint8_t | ObjDicSub, | ||
uint32_t * | pRxDWord | ||
) |
This function reads up to 4 bytes of data from device object dictionary using the new serial protocol version V2.
Use this function if you work with devices like Nemesys M and S that have a controller with this new protocol
- Parameters
-
[in] pBus Bus object the device is attached to [in] NodeId NodeId (1 - 30) of device to read from [in] ObjDicIdx Index into device object dictionary [in] ObjDicSub Sub entry of object dictionary entry [in] pRxDWord Points to DWord buffer for storage of received data
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiDevReadObject().
long CsiBusReadLargeData | ( | struct CsiBus * | pBus, |
uint8_t | NodeId, | ||
uint16_t | ObjDicIdx, | ||
uint8_t | ObjDicSub, | ||
uint8_t * | pDataBuffer, | ||
uint16_t | BufferSize | ||
) |
Use this function if you need to read more than 4 bytes of data.
If data size is <=4, this function falls back to CsiBusReadData()
- Parameters
-
[in] pBus Bus object the device is attached to [in] NodeId NodeId (1 - 30) of device to read from [in] ObjDicIdx Index into device object dictionary [in] ObjDicSub Sub entry of object dictionary entry [in] pDataBuffer Points to buffer that stores data [in] BufferSize Size of the buffer given in pDataBuffer
- Return values
-
>= 0 Number of received bytes in pDataBuffer <0 Error code
Referenced by CsiDevReadLargeObject().
long CsiBusWriteData | ( | struct CsiBus * | pBus, |
uint8_t | NodeId, | ||
uint16_t | ObjDicIdx, | ||
uint8_t | ObjDicSub, | ||
uint32_t | TxDWord | ||
) |
This function writes up to 4 bytes of data into device object dictionary.
- Parameters
-
[in] pBus Bus object the device is attached to [in] NodeId NodeId (1 - 30) of CSI device to write to [in] ObjDicIdx Index into device object dictionary [in] ObjDicSub Sub entry of object dictionary entry [in] TxDWord Points to DWord that contains data to write
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiDevWriteObject().
long CsiBusWriteDataV2 | ( | struct CsiBus * | pBus, |
uint8_t | NodeId, | ||
uint16_t | ObjDicIdx, | ||
uint8_t | ObjDicSub, | ||
uint32_t | TxDWord | ||
) |
This function writes up to 4 bytes of data into device object dictionary using the new serial protocol version V2.
Use this function if you work with devices like Nemesys M and S that have a controller with this new protocol.
- Parameters
-
[in] pBus Bus object the device is attached to [in] NodeId NodeId (1 - 30) of CSI device to write to [in] ObjDicIdx Index into device object dictionary [in] ObjDicSub Sub entry of object dictionary entry [in] TxDWord Points to DWord that contains data to write
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiDevWriteObject().
long CsiBusWriteLargeData | ( | struct CsiBus * | pBus, |
uint8_t | NodeId, | ||
uint16_t | ObjDicIdx, | ||
uint8_t | ObjDicSub, | ||
uint8_t * | pDataBuffer, | ||
uint32_t | DataSize, | ||
CsiDataTransferCallback | Callback | ||
) |
Use this function if you need to write more than 4 bytes of data.
If data size is <=4, this function falls back to CsiBusWriteData()
- Parameters
-
[in] pBus Bus object the device is attached to [in] NodeId NodeId (1 - 30) of CSI device to write to [in] ObjDicIdx Index into device object dictionary [in] ObjDicSub Sub entry of object dictionary entry [in] pDataBuffer Points to buffer that stores data [in] DataSize Size of the buffer given in pDataBuffer [in] Callback Callback function that will be called after each data packet that has been sent (e.g. to show a progress bar)
- Returns
- Error code - ERR_NOERR indicates success
Referenced by CsiDevWriteLargeObject().