18 #include "fsl_os_abstraction.h"
28 static semaphore_t ci_sema_stream;
38 static uint8 ci_protocol_stream_id = 0;
50 static uint8 ci_stream_get_num_instances(
void);
52 static ci_stream_config_t *ci_stream_create_config_buf(
boolean aCreateTrigElementBytes,
54 static isf_status_t ci_stream_internal_init(
void *apInitData);
63 uint32 num_bytes = anumElements / 8; \
64 if ( (anumElements ) > 0) \
78 uint8 temp = *p1; *p1 = *p2; *p2 = temp;
91 ci_protocol_stream_id = aprotocolID;
92 if (OSA_SemaCreate(&ci_sema_stream, 1) !=
ISF_SUCCESS)
96 ci_stream_internal_init(apInitData);
109 gpStreamFirstInstance = NULL;
110 gpStreamNextInstance = NULL;
121 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
122 gpStreamNextInstance = NULL;
123 if (gpStreamFirstInstance != NULL)
125 gpStreamNextInstance = gpStreamFirstInstance->pNextInstance;
126 pConfig = gpStreamFirstInstance->pStreamConfig;
128 OSA_SemaPost(&ci_sema_stream);
138 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
140 if (gpStreamNextInstance != NULL)
142 pConfig = gpStreamNextInstance->pStreamConfig;
143 gpStreamNextInstance = gpStreamNextInstance->pNextInstance;
146 OSA_SemaPost(&ci_sema_stream);
158 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
160 pStreamConfig = ci_stream_get_config(aStreamID);
162 OSA_SemaPost(&ci_sema_stream);
164 return pStreamConfig;
173 if (gpStreamFirstInstance == NULL)
177 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
182 if (pInstTarget != NULL)
185 if (ci_stream_get_num_instances() > 1)
188 if (gpStreamFirstInstance == pInstTarget)
191 gpStreamFirstInstance = pInstTarget->pNextInstance;
201 if (pInstCur != pInstTarget)
205 pInstCur = pInstCur->pNextInstance;
210 pInstBef->pNextInstance = pInstTarget->pNextInstance;
220 gpStreamFirstInstance = NULL;
235 OSA_SemaPost(&ci_sema_stream);
249 if ( (apTriggerMask == NULL) || (apElementList == NULL) )
252 if (aNumElements == 0)
256 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
260 if (ci_stream_get_config(aStreamID) != NULL)
263 OSA_SemaPost(&ci_sema_stream);
269 uint32 num_trigmask_bytes = 0;
270 uint32 num_element_bytes = 0;
300 + ci_stream_get_output_packet_size(aNumElements, apElementList)
312 if ( (pNewStreamConfig == NULL) || (pNewStreamInstance == NULL) )
316 if (pNewStreamConfig != NULL)
319 if (pNewStreamInstance != NULL)
332 pNewStreamConfig->streamID = aStreamID;
333 pNewStreamConfig->numElements = aNumElements;
336 CI_COPY_MEM(apElementList, pNewStreamConfig->pElementList, num_element_bytes);
347 while(element_index < aNumElements)
349 uint32 trigbyte_index = element_index / 8;
350 uint8 bitmask = element_index - (trigbyte_index * 8);
353 pNewStreamConfig->pTriggerMask[trigbyte_index] |= (apTriggerMask[trigbyte_index] & (
uint8)(1 << bitmask));
369 CI_COPY_MEM(pNewStreamConfig->pTriggerMask, pNewStreamInstance->pTriggerState, num_trigmask_bytes);
384 pNewStreamInstance->pStreamBuffer = (
uint8 *)((
uint32)pNewStreamInstance->pTriggerState + num_trigmask_bytes);
394 while(element_index < pNewStreamConfig->numElements)
401 (
uint32)pNewStreamInstance->pStreamBuffer +
402 ci_stream_get_streambuffer_offset(
404 pNewStreamConfig->numElements,
405 pNewStreamConfig->pElementList) );
408 *pDest = pElement[element_index].datasetID;
415 pNewStreamInstance->pStreamConfig = pNewStreamConfig;
417 pNewStreamInstance->pNextInstance = NULL;
427 uint16 len = (
uint16)ci_stream_get_config_payload_size(pNewStreamConfig->numElements, pNewStreamConfig->pElementList);
434 if (pLastInstance == NULL)
436 gpStreamFirstInstance = pNewStreamInstance;
438 pLastInstance->pNextInstance = pNewStreamInstance;
441 OSA_SemaPost(&ci_sema_stream);
455 uint8 num_dataset_updated_total = 0;
465 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
469 pStreamInstance = gpStreamFirstInstance;
472 while (pStreamInstance != NULL)
477 uint32 trigbyte_index = 0;
478 uint8 num_dataset_updated = 0;
481 while(element_index < pStreamInstance->pStreamConfig->numElements)
484 trigbyte_index = element_index / 8;
487 if (pElement[element_index].datasetID == aDataSetID)
495 uint32 dataset_start = (
uint32)pElement[element_index].offset;
496 uint32 dataset_end = (
uint32)pElement[element_index].length + dataset_start;
497 uint32 src_start = aOffset;
498 uint32 src_end = src_start + aLength;
505 (dataset_start < src_end)
509 (dataset_end > src_start)
514 if (src_start <= dataset_start)
515 src_start = dataset_start;
516 if (src_end >= dataset_end)
517 src_end = dataset_end;
520 uint16 len = src_end - src_start;
530 (
uint32)pStreamInstance->pStreamBuffer +
531 ci_stream_get_streambuffer_offset(
533 pStreamInstance->pStreamConfig->numElements,
534 pStreamInstance->pStreamConfig->pElementList)
537 if (dataset_start < src_start)
540 pDest = (
uint8 *)( (
uint32)pDest + (src_start - dataset_start) );
546 uint8 bitmask = element_index - (trigbyte_index * 8);
547 pStreamInstance->pTriggerState[trigbyte_index] &= ~(
uint8)(1 << bitmask);
550 ++num_dataset_updated;
564 boolean bSendDataToHost =
TRUE;
570 if (pStreamInstance->pTriggerState[trigbyte_index] != 0)
571 bSendDataToHost =
FALSE;
572 }
while(++trigbyte_index < num_trigger_bytes);
575 if (bSendDataToHost ==
TRUE)
591 pStreamInstance->pStreamBuffer[num_bytes] = (
uint8)( (crc16 >> 8) & 0xff);
592 pStreamInstance->pStreamBuffer[num_bytes+1] = (
uint8)( (crc16 >> 0) & 0xff);
609 CI_COPY_MEM(pStreamInstance->pStreamConfig->pTriggerMask, pStreamInstance->pTriggerState, num_trigger_bytes);
616 num_dataset_updated_total += num_dataset_updated;
618 pStreamInstance = pStreamInstance->pNextInstance;
622 if ( (ret ==
ISF_SUCCESS) && (num_dataset_updated_total == 0) )
629 OSA_SemaPost(&ci_sema_stream);
642 uint8 num_instances = 0;
644 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
647 num_instances = ci_stream_get_num_instances();
649 OSA_SemaPost(&ci_sema_stream);
651 return num_instances;
663 if (apTrigger == NULL)
667 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
669 pStreamInstance = ci_stream_get_instance(aStreamID);
671 if (pStreamInstance != NULL)
678 apTrigger[i] = pStreamInstance->pTriggerState[i];
679 }
while(++i < num_trigger_bytes);
687 OSA_SemaPost(&ci_sema_stream);
699 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
701 pStreamInstance = ci_stream_get_instance(aStreamID);
703 if (pStreamInstance != NULL)
710 pStreamInstance->pTriggerState[i] = pStreamInstance->pStreamConfig->pTriggerMask[i];
711 }
while(++i < num_trigger_bytes);
719 OSA_SemaPost(&ci_sema_stream);
728 OSA_SemaWait(&ci_sema_stream, OSA_WAIT_FOREVER);
736 OSA_SemaPost(&ci_sema_stream);
758 if (gpStreamFirstInstance != NULL)
761 pStreamInstance = gpStreamFirstInstance;
765 if (pStreamInstance->pStreamConfig->streamID == aStreamID)
768 pStreamConfig = pStreamInstance->pStreamConfig;
773 pStreamInstance = pStreamInstance->pNextInstance;
776 }
while((pStreamConfig == NULL) && (pStreamInstance !=NULL ));
779 return pStreamConfig;
789 if (gpStreamFirstInstance != NULL)
792 pStreamInstance = gpStreamFirstInstance;
796 if (pStreamInstance->pStreamConfig->streamID == aStreamID)
804 pStreamInstance = pStreamInstance->pNextInstance;
807 }
while(pStreamInstance !=NULL);
810 return pStreamInstance;
822 if ( (apElementList == NULL) || (aNumElements == 0) || (aElementIndex >= aNumElements) )
825 pElementList = apElementList;
829 while(i < aElementIndex)
832 offset_bytes += pElementList[i].length;
852 uint32 output_packet_size_bytes = 0;
854 if ( (apElementList == NULL) || (aNumElements == 0) )
868 output_packet_size_bytes += ci_stream_get_config_payload_size(aNumElements, apElementList);
870 return output_packet_size_bytes;
879 uint32 payload_size_bytes = 0;
881 if ( (apElementList == NULL) || (aNumElements == 0) )
884 pElementList = apElementList;
886 uint8 i = aNumElements;
891 payload_size_bytes += pElementList[i].length;
894 return payload_size_bytes;
901 static uint8 ci_stream_get_num_instances(
void)
904 uint8 num_instances = 0;
907 if (gpStreamFirstInstance != NULL)
910 pStreamInstance = gpStreamFirstInstance;
915 pStreamInstance = pStreamInstance->pNextInstance;
917 }
while(pStreamInstance !=NULL );
921 return num_instances;
931 if (gpStreamFirstInstance != NULL)
933 pStreamInstance = gpStreamFirstInstance;
935 while(pStreamInstance->pNextInstance != NULL)
937 pStreamInstance = pStreamInstance->pNextInstance;
941 return pStreamInstance;
947 static ci_stream_config_t *ci_stream_create_config_buf(
boolean aCreateTrigElementBytes,
951 if (anumElements == 0)
958 if (aCreateTrigElementBytes ==
TRUE)
980 pConfig->numElements = anumElements;
987 pConfig->pTriggerMask = (
uint8 *)((
uint32)pConfig->pElementList
996 if (apnumBytesAlloc != NULL)
999 *apnumBytesAlloc = bytes_allocated;
1014 uint8 crc_bytes = 0;
1027 uint32 num_response_data_bytes = 0;
1039 uint8 *pStreamResp = &stream_resp_array[0];
1045 boolean bDynamicRespBuf =
FALSE;
1067 else if (apSrc == NULL)
1133 while(pConfig != NULL)
1140 ci_stream_internal_init(NULL);
1231 num_response_data_bytes = 1;
1267 uint32 expected_bytes = 1;
1269 if (anumBytes == expected_bytes)
1346 uint32 expected_bytes = 1;
1348 if (anumBytes == expected_bytes)
1360 num_response_data_bytes =
1364 + num_element_bytes;
1367 num_response_totalbytes
1368 + num_response_data_bytes
1373 bDynamicRespBuf =
TRUE;
1380 pStreamResp = pTemp;
1386 *pTemp++ = pInst->pStreamConfig->streamID;
1387 *pTemp++ = pInst->pStreamConfig->numElements;
1390 CI_COPY_MEM(pInst->pStreamConfig->pTriggerMask, pTemp, num_trig_bytes);
1391 pTemp += num_trig_bytes;
1397 while(i < pInst->pStreamConfig->numElements)
1399 *pTemp++ = pElementList[i].datasetID;
1400 *pTemp++ = ((pElementList[i].length >> 8) & 0xFF);
1401 *pTemp++ = (pElementList[i].length & 0xFF);
1402 *pTemp++ = ((pElementList[i].offset >> 8) & 0xFF);
1403 *pTemp++ = (pElementList[i].offset & 0xFF);
1415 num_response_data_bytes = 0;
1468 if (pConfig != NULL)
1470 num_response_data_bytes = 1;
1521 if (pConfig != NULL)
1523 num_response_data_bytes = 1;
1573 uint32 expected_bytes = 0;
1582 expected_bytes += num_trigmask_bytes;
1583 element_offset = expected_bytes;
1584 expected_bytes += num_element_bytes;
1587 if (anumBytes == expected_bytes)
1592 uint8 *pSrcElementBytes = (
uint8 *)&apSrc[element_offset];
1596 if (pDestElementList != NULL)
1598 uint8 element_index = 0;
1600 while(element_index < num_elements)
1603 pDestElementList[element_index].datasetID = *pSrcElementBytes++;
1605 pDestElementList[element_index].length = (
uint16)(pSrcElementBytes[0] << 8) | (
uint16)(pSrcElementBytes[1]);
1606 pSrcElementBytes += 2;
1608 pDestElementList[element_index].offset = (
uint16)(pSrcElementBytes[0] << 8) | (
uint16)(pSrcElementBytes[1]);
1609 pSrcElementBytes += 2;
1658 uint32 expected_bytes = 1;
1661 if (anumBytes == expected_bytes)
1702 uint32 expected_bytes = 1;
1705 if (anumBytes == expected_bytes)
1780 num_response_totalbytes += num_response_data_bytes;
1802 pStreamResp[num_response_totalbytes + 0] = (
uint8)((
uint16)(crc16 & 0xff00) >> 8);
1803 pStreamResp[num_response_totalbytes + 1] = (
uint8)(crc16 & 0xff);
1812 if (bDynamicRespBuf ==
TRUE)
#define cmd_createstream_get_streamID(pSrc)
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.
#define STREAM_PROTOCOL_CMD_BYTESIZE
Defines the number of bytes for host command.
#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.
Command Interpreter (CI) stream protocol header file.
#define CI_STREAM_DATASET_ID_BYTESIZE
Defines the number of bytes to store the data set ID.
#define STREAM_PROTOCOL_OUTPUTPACKET_INDEX_LENGTH_LSB
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::@4 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.
#define cmd_createstream_get_numelements(pSrc)
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 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.
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.
unsigned short int uint16
#define CI_STREAM_OUTPUTPACKET_LENGTH_BYTESIZE
Defines the number of bytes to store the length of the output packet data.
void isf_ci_stream_set_stream_enable()
This API enables data stream.
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.
#define cmd_createstream_get_trigmask_ptr(pSrc)
#define STREAM_COCO_BIT_MASK
void byteswap(uint8 *p1, uint8 *p2)
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
void isf_ci_stream_set_stream_disable()
This API disables data stream.
#define CI_ALLOC_MEM_ZERO(x)
Memory allocation abstraction.
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_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 ci_stream_get_host_cmd(pSrc)
Macros to access buffer received from host.
#define STREAM_PROTOCOL_RESP_INDEX_COCO_STAT
#define STREAM_CRC_BYTESIZE
Defines the number of bytes for 16-bit CRC value.