29 static LWSEM_STRUCT ci_sema_stream;
40 static uint8 ci_protocol_stream_id = 0;
52 static uint8 ci_stream_get_num_instances(
void);
54 static ci_stream_config_t *ci_stream_create_config_buf(
boolean aCreateTrigElementBytes,
56 static isf_status_t ci_stream_internal_init(
void *apInitData);
65 uint32 num_bytes = anumElements / 8; \
66 if ( (anumElements ) > 0) \
79 uint8 temp = *p1; *p1 = *p2; *p2 = temp;
92 ci_protocol_stream_id = aprotocolID;
95 if (_lwsem_create(&ci_sema_stream, 1) != MQX_OK)
99 ci_stream_internal_init(apInitData);
112 gpStreamFirstInstance = NULL;
113 gpStreamNextInstance = NULL;
125 _lwsem_wait_ticks(&ci_sema_stream, 0);
127 gpStreamNextInstance = NULL;
128 if (gpStreamFirstInstance != NULL)
130 gpStreamNextInstance = gpStreamFirstInstance->pNextInstance;
131 pConfig = gpStreamFirstInstance->pStreamConfig;
134 _lwsem_post(&ci_sema_stream);
145 _lwsem_wait_ticks(&ci_sema_stream, 0);
147 if (gpStreamNextInstance != NULL)
149 pConfig = gpStreamNextInstance->pStreamConfig;
150 gpStreamNextInstance = gpStreamNextInstance->pNextInstance;
153 _lwsem_post(&ci_sema_stream);
165 _lwsem_wait_ticks(&ci_sema_stream, 0);
167 pStreamConfig = ci_stream_get_config(aStreamID);
169 _lwsem_post(&ci_sema_stream);
171 return pStreamConfig;
180 if (gpStreamFirstInstance == NULL)
184 _lwsem_wait_ticks(&ci_sema_stream, 0);
189 if (pInstTarget != NULL)
192 if (ci_stream_get_num_instances() > 1)
195 if (gpStreamFirstInstance == pInstTarget)
198 gpStreamFirstInstance = pInstTarget->pNextInstance;
208 if (pInstCur != pInstTarget)
212 pInstCur = pInstCur->pNextInstance;
217 pInstBef->pNextInstance = pInstTarget->pNextInstance;
227 gpStreamFirstInstance = NULL;
242 _lwsem_post(&ci_sema_stream);
256 if ( (apTriggerMask == NULL) || (apElementList == NULL) )
259 if (aNumElements == 0)
263 _lwsem_wait_ticks(&ci_sema_stream, 0);
266 if (ci_stream_get_config(aStreamID) != NULL)
269 _lwsem_post(&ci_sema_stream);
275 uint32 num_trigmask_bytes = 0;
276 uint32 num_element_bytes = 0;
306 + ci_stream_get_output_packet_size(aNumElements, apElementList)
318 if ( (pNewStreamConfig == NULL) || (pNewStreamInstance == NULL) )
322 if (pNewStreamConfig != NULL)
325 if (pNewStreamInstance != NULL)
338 pNewStreamConfig->streamID = aStreamID;
339 pNewStreamConfig->numElements = aNumElements;
342 CI_COPY_MEM(apElementList, pNewStreamConfig->pElementList, num_element_bytes);
353 while(element_index < aNumElements)
355 uint32 trigbyte_index = element_index / 8;
356 uint8 bitmask = element_index - (trigbyte_index * 8);
359 pNewStreamConfig->pTriggerMask[trigbyte_index] |= (apTriggerMask[trigbyte_index] & (
uint8)(1 << bitmask));
375 CI_COPY_MEM(pNewStreamConfig->pTriggerMask, pNewStreamInstance->pTriggerState, num_trigmask_bytes);
390 pNewStreamInstance->pStreamBuffer = (
uint8 *)((
uint32)pNewStreamInstance->pTriggerState + num_trigmask_bytes);
400 while(element_index < pNewStreamConfig->numElements)
407 (
uint32)pNewStreamInstance->pStreamBuffer +
408 ci_stream_get_streambuffer_offset(
410 pNewStreamConfig->numElements,
411 pNewStreamConfig->pElementList) );
414 *pDest = pElement[element_index].datasetID;
421 pNewStreamInstance->pStreamConfig = pNewStreamConfig;
423 pNewStreamInstance->pNextInstance = NULL;
433 uint16 len = (
uint16)ci_stream_get_config_payload_size(pNewStreamConfig->numElements, pNewStreamConfig->pElementList);
440 if (pLastInstance == NULL)
442 gpStreamFirstInstance = pNewStreamInstance;
444 pLastInstance->pNextInstance = pNewStreamInstance;
448 _lwsem_post(&ci_sema_stream);
462 uint8 num_dataset_updated_total = 0;
472 _lwsem_wait_ticks(&ci_sema_stream, 0);
476 pStreamInstance = gpStreamFirstInstance;
479 while (pStreamInstance != NULL)
484 uint32 trigbyte_index = 0;
485 uint8 num_dataset_updated = 0;
488 while(element_index < pStreamInstance->pStreamConfig->numElements)
491 trigbyte_index = element_index / 8;
494 if (pElement[element_index].datasetID == aDataSetID)
502 uint32 dataset_start = (
uint32)pElement[element_index].offset;
503 uint32 dataset_end = (
uint32)pElement[element_index].length + dataset_start;
504 uint32 src_start = aOffset;
505 uint32 src_end = src_start + aLength;
512 (dataset_start < src_end)
516 (dataset_end > src_start)
521 if (src_start <= dataset_start)
522 src_start = dataset_start;
523 if (src_end >= dataset_end)
524 src_end = dataset_end;
527 uint16 len = src_end - src_start;
537 (
uint32)pStreamInstance->pStreamBuffer +
538 ci_stream_get_streambuffer_offset(
540 pStreamInstance->pStreamConfig->numElements,
541 pStreamInstance->pStreamConfig->pElementList)
544 if (dataset_start < src_start)
547 pDest = (
uint8 *)( (
uint32)pDest + (src_start - dataset_start) );
553 uint8 bitmask = element_index - (trigbyte_index * 8);
554 pStreamInstance->pTriggerState[trigbyte_index] &= ~(
uint8)(1 << bitmask);
557 ++num_dataset_updated;
571 boolean bSendDataToHost =
TRUE;
577 if (pStreamInstance->pTriggerState[trigbyte_index] != 0)
578 bSendDataToHost =
FALSE;
579 }
while(++trigbyte_index < num_trigger_bytes);
582 if (bSendDataToHost ==
TRUE)
598 pStreamInstance->pStreamBuffer[num_bytes] = (
uint8)( (crc16 >> 8) & 0xff);
599 pStreamInstance->pStreamBuffer[num_bytes+1] = (
uint8)( (crc16 >> 0) & 0xff);
616 CI_COPY_MEM(pStreamInstance->pStreamConfig->pTriggerMask, pStreamInstance->pTriggerState, num_trigger_bytes);
623 num_dataset_updated_total += num_dataset_updated;
625 pStreamInstance = pStreamInstance->pNextInstance;
629 if ( (ret ==
ISF_SUCCESS) && (num_dataset_updated_total == 0) )
636 _lwsem_post(&ci_sema_stream);
649 uint8 num_instances = 0;
651 _lwsem_wait_ticks(&ci_sema_stream, 0);
653 num_instances = ci_stream_get_num_instances();
655 _lwsem_post(&ci_sema_stream);
657 return num_instances;
669 if (apTrigger == NULL)
673 _lwsem_wait_ticks(&ci_sema_stream, 0);
675 pStreamInstance = ci_stream_get_instance(aStreamID);
677 if (pStreamInstance != NULL)
684 apTrigger[i] = pStreamInstance->pTriggerState[i];
685 }
while(++i < num_trigger_bytes);
693 _lwsem_post(&ci_sema_stream);
705 _lwsem_wait_ticks(&ci_sema_stream, 0);
707 pStreamInstance = ci_stream_get_instance(aStreamID);
709 if (pStreamInstance != NULL)
716 pStreamInstance->pTriggerState[i] = pStreamInstance->pStreamConfig->pTriggerMask[i];
717 }
while(++i < num_trigger_bytes);
725 _lwsem_post(&ci_sema_stream);
734 _lwsem_wait_ticks(&ci_sema_stream, 0);
742 _lwsem_post(&ci_sema_stream);
764 if (gpStreamFirstInstance != NULL)
767 pStreamInstance = gpStreamFirstInstance;
771 if (pStreamInstance->pStreamConfig->streamID == aStreamID)
774 pStreamConfig = pStreamInstance->pStreamConfig;
779 pStreamInstance = pStreamInstance->pNextInstance;
782 }
while((pStreamConfig == NULL) && (pStreamInstance !=NULL ));
785 return pStreamConfig;
795 if (gpStreamFirstInstance != NULL)
798 pStreamInstance = gpStreamFirstInstance;
802 if (pStreamInstance->pStreamConfig->streamID == aStreamID)
810 pStreamInstance = pStreamInstance->pNextInstance;
813 }
while(pStreamInstance !=NULL);
816 return pStreamInstance;
828 if ( (apElementList == NULL) || (aNumElements == 0) || (aElementIndex >= aNumElements) )
831 pElementList = apElementList;
835 while(i < aElementIndex)
838 offset_bytes += pElementList[i].length;
858 uint32 output_packet_size_bytes = 0;
860 if ( (apElementList == NULL) || (aNumElements == 0) )
874 output_packet_size_bytes += ci_stream_get_config_payload_size(aNumElements, apElementList);
876 return output_packet_size_bytes;
885 uint32 payload_size_bytes = 0;
887 if ( (apElementList == NULL) || (aNumElements == 0) )
890 pElementList = apElementList;
892 uint8 i = aNumElements;
897 payload_size_bytes += pElementList[i].length;
900 return payload_size_bytes;
907 static uint8 ci_stream_get_num_instances(
void)
910 uint8 num_instances = 0;
913 if (gpStreamFirstInstance != NULL)
916 pStreamInstance = gpStreamFirstInstance;
921 pStreamInstance = pStreamInstance->pNextInstance;
923 }
while(pStreamInstance !=NULL );
927 return num_instances;
937 if (gpStreamFirstInstance != NULL)
939 pStreamInstance = gpStreamFirstInstance;
941 while(pStreamInstance->pNextInstance != NULL)
943 pStreamInstance = pStreamInstance->pNextInstance;
947 return pStreamInstance;
953 static ci_stream_config_t *ci_stream_create_config_buf(
boolean aCreateTrigElementBytes,
957 if (anumElements == 0)
964 if (aCreateTrigElementBytes ==
TRUE)
986 pConfig->numElements = anumElements;
993 pConfig->pTriggerMask = (
uint8 *)((
uint32)pConfig->pElementList
1002 if (apnumBytesAlloc != NULL)
1005 *apnumBytesAlloc = bytes_allocated;
1020 uint8 crc_bytes = 0;
1033 uint32 num_response_data_bytes = 0;
1045 uint8 *pStreamResp = &stream_resp_array[0];
1051 boolean bDynamicRespBuf =
FALSE;
1073 else if (apSrc == NULL)
1139 while(pConfig != NULL)
1146 ci_stream_internal_init(NULL);
1237 num_response_data_bytes = 1;
1273 uint32 expected_bytes = 1;
1275 if (anumBytes == expected_bytes)
1352 uint32 expected_bytes = 1;
1354 if (anumBytes == expected_bytes)
1366 num_response_data_bytes =
1370 + num_element_bytes;
1373 num_response_totalbytes
1374 + num_response_data_bytes
1379 bDynamicRespBuf =
TRUE;
1386 pStreamResp = pTemp;
1392 *pTemp++ = pInst->pStreamConfig->streamID;
1393 *pTemp++ = pInst->pStreamConfig->numElements;
1396 CI_COPY_MEM(pInst->pStreamConfig->pTriggerMask, pTemp, num_trig_bytes);
1397 pTemp += num_trig_bytes;
1403 while(i < pInst->pStreamConfig->numElements)
1405 *pTemp++ = pElementList[i].datasetID;
1406 *pTemp++ = ((pElementList[i].length >> 8) & 0xFF);
1407 *pTemp++ = (pElementList[i].length & 0xFF);
1408 *pTemp++ = ((pElementList[i].offset >> 8) & 0xFF);
1409 *pTemp++ = (pElementList[i].offset & 0xFF);
1421 num_response_data_bytes = 0;
1474 if (pConfig != NULL)
1476 num_response_data_bytes = 1;
1527 if (pConfig != NULL)
1529 num_response_data_bytes = 1;
1579 uint32 expected_bytes = 0;
1588 expected_bytes += num_trigmask_bytes;
1589 element_offset = expected_bytes;
1590 expected_bytes += num_element_bytes;
1593 if (anumBytes == expected_bytes)
1598 uint8 *pSrcElementBytes = (
uint8 *)&apSrc[element_offset];
1602 if (pDestElementList != NULL)
1604 uint8 element_index = 0;
1606 while(element_index < num_elements)
1609 pDestElementList[element_index].datasetID = *pSrcElementBytes++;
1611 pDestElementList[element_index].length = (
uint16)(pSrcElementBytes[0] << 8) | (
uint16)(pSrcElementBytes[1]);
1612 pSrcElementBytes += 2;
1614 pDestElementList[element_index].offset = (
uint16)(pSrcElementBytes[0] << 8) | (
uint16)(pSrcElementBytes[1]);
1615 pSrcElementBytes += 2;
1664 uint32 expected_bytes = 1;
1667 if (anumBytes == expected_bytes)
1708 uint32 expected_bytes = 1;
1711 if (anumBytes == expected_bytes)
1786 num_response_totalbytes += num_response_data_bytes;
1808 pStreamResp[num_response_totalbytes + 0] = (
uint8)((
uint16)(crc16 & 0xff00) >> 8);
1809 pStreamResp[num_response_totalbytes + 1] = (
uint8)(crc16 & 0xff);
1818 if (bDynamicRespBuf ==
TRUE)
isf_status_t isf_ci_stream_reset_trigger(uint8 aStreamID)
This API resets the trigger bits of the the given stream ID.
#define STREAM_PROTOCOL_RECV_MIN_BYTESIZE
Defines the minimum number of bytes of a received host packet.
ISF board support header files.
unsigned char uint8
This defines uint8 as unsigned char.
#define STREAM_PROTOCOL_CMD_BYTESIZE
Defines the number of bytes for host command.
#define cmd_createstream_get_numelements(pSrc)
#define STREAM_PROTOCOL_CMD_STATUS_BYTESIZE
Defines the number of bytes for command status.
#define STREAM_CRC_DISABLED
#define STREAM_CRC_ENABLED
Stream control: enable/disable CRC generation/checking.
#define STREAM_PROTOCOL_RESP_INDEX_NUMDATA_LSB
ISF Command Interpreter (CI) stream protocol header file.
#define cmd_createstream_get_trigmask_ptr(pSrc)
Command Interpreter (CI) stream protocol header file.
#define CI_STREAM_DATASET_ID_BYTESIZE
Defines the number of bytes to store the data set ID.
unsigned long uint32
This defines uint32 as unsigned long.
#define STREAM_PROTOCOL_OUTPUTPACKET_INDEX_LENGTH_LSB
#define cmd_createstream_get_streamID(pSrc)
isf_status_t isf_ci_stream_create(uint8 aStreamID, uint8 aNumElements, uint8 *apTriggerMask, ci_stream_element_t *apElementList)
This API creates a stream.
#define STREAM_PROTOCOL_OUTPUTPACKET_INDEX_COCO_STAT
struct ci_stream_ctrl_reg1_t::@5 Bits
isf_status_t ci_stream_init(uint8 aprotocolID, void *apInitData)
This is a CI stream protocol intialization callback function pointer.
ci_stream_config_t * isf_ci_stream_get_next(void)
This API returns the configuration of the next stream in the linked list.
#define STREAM_PROTOCOL_DATA_ENABLED
Stream protocol control: enable/disable data update.
Command interpreter task header file. This file is internal ISF code.
#define CI_STREAM_OUTPUTPACKET_STREAMID_BYTESIZE
Defines the number of bytes to store the stream ID.
#define STREAM_PROTOCOL_RESP_INDEX_CMD_ECHO
isf_status_t isf_ci_stream_update_data(uint8 aDataSetID, uint16 aLength, uint16 aOffset, uint8 *apSrc)
This API updates the data of a dataset.
#define CI_STREAM_NUMELEMENTS_BYTESIZE
Defines the number of bytes to specify the number of elements.
ci_stream_config_t * isf_ci_stream_get(uint8 aStreamID)
#define STREAM_PROTOCOL_RESP_INDEX_PROTOCOLID
Defines the indexes of the command response array to the host.
#define STREAM_PROTOCOL_RESP_RESPDATALENGTH_BYTESIZE
Defines the number of bytes to store the length of the response data. If there are no response data...
ci_stream_config_t * isf_ci_stream_get_first(void)
This API returns the configuration of the first stream in the linked list.
The isf_util.h file contains the utility method declarations and macros.
#define ci_stream_get_host_cmd(pSrc)
Macros to access buffer received from host.
#define STREAM_PROTOCOL_RESP_MIN_BYTESIZE
Defines the minimum number of response bytes to the host not including CRC. Do not add CRC bytes into...
#define STREAM_PROTOCOL_OUTPUTPACKET_INDEX_LENGTH_MSB
isf_status_t ci_send_packet(uint32 anumBytes, uint8 *apSrc)
CI send packet - main function to send data to host.
uint16 ccitt_crc16_cal(uint32 anumBytes, uint8 *apBuf)
This crc function contains the standard CCITT CRC 16-bit implementation.
void byteswap(uint8 *p1, uint8 *p2)
uint32 ci_stream_get_num_trig_bytes(uint8 anumElements)
void isf_ci_stream_set_CRC(boolean acrcEnable)
This API sets the cyclic redundancy check (CRC) code generation to the requested state.
uint32 ci_stream_get_num_element_bytes(uint8 anumElements)
#define STREAM_PROTOCOL_OUTPUTPACKET_INDEX_STREAMID
Main ISF header file. Contains code common to all ISF components.
#define CI_STREAM_OUTPUTPACKET_LENGTH_BYTESIZE
Defines the number of bytes to store the length of the output packet data.
ci_stream_ctrl_reg1_t StreamCtrlReg1
#define STREAM_PROTOCOL_RESP_DEFAULT_ARRAY_BYTESIZE
Defines the fixed array size of the response buffer array. The size specified is sufficient for most ...
API definitions, types, and macros for the Intelligent Sensing Framework (ISF) Command Interpreter (C...
General library initialization failure status.
#define STREAM_PROTOCOL_OUTPUTPACKET_INDEX_PROTOCOLID
Defines the indexes of the stream data update buffer (output packet).
#define STREAM_PROTOCOL_RESP_INDEX_NUMDATA_MSB
#define CI_STREAM_PROTOCOL_ID_BYTESIZE
Defines the number of bytes to store the protocol ID.
Stream protocol registers Structure. Contains stream protocol control registers.
unsigned short uint16
This defines uint16 as unsigned short.
#define STREAM_COCO_BIT_MASK
int32 isf_status_t
ISF return status type.
Stream instance structure is used internally to encapsulate the information of a stream and the curre...
#define STREAM_PROTOCOL_RESP_INDEX_DATASTART
isf_status_t isf_ci_stream_delete(uint8 aStreamID)
This API deletes the given stream ID.
isf_status_t isf_ci_stream_get_trigger(uint8 aStreamID, uint8 *apTrigger)
This API returns the trigger state of the given stream ID.
#define CI_ALLOC_MEM_ZERO(x)
Memory allocation abstraction.
#define CI_COPY_MEM(src, dest, size)
#define STREAM_PROTOCOL_DATA_DISABLED
isf_status_t ci_protocol_CB_stream(uint32 anumBytes, uint8 *apSrc, uint32 *apnumDestBytes, uint8 *apDest)
This is a CI stream protocol callback function pointer.
uint8 isf_ci_stream_get_num_streams(void)
This API returns the number of streams.
#define STREAM_PROTOCOL_RESP_INDEX_COCO_STAT
#define STREAM_CRC_BYTESIZE
Defines the number of bytes for 16-bit CRC value.