aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2013-05-23 05:54:22 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2013-05-23 05:54:22 -0700
commitfa5c422908eacd37928836bbcdd4f8cbc8c73690 (patch)
treedb99754803d55779c0a7560e7dab0901c0fe8d4c
parent34f88462b0c47f097a710a425b71489e7710b047 (diff)
parentb027c2f5adbf726ff4dac8c10e551e034927dfc1 (diff)
downloadandroid_external_ant-wireless_ant_native-fa5c422908eacd37928836bbcdd4f8cbc8c73690.tar.gz
android_external_ant-wireless_ant_native-fa5c422908eacd37928836bbcdd4f8cbc8c73690.tar.bz2
android_external_ant-wireless_ant_native-fa5c422908eacd37928836bbcdd4f8cbc8c73690.zip
Merge "Merge remote-tracking branch 'remotes/quic/caf/github/master' into upload"
-rw-r--r--src/vfs/ant_rx_chardev.c54
-rw-r--r--src/vfs/prerelease/ant_driver_defines.h53
2 files changed, 81 insertions, 26 deletions
diff --git a/src/vfs/ant_rx_chardev.c b/src/vfs/ant_rx_chardev.c
index 2af65a4..2f0cc33 100644
--- a/src/vfs/ant_rx_chardev.c
+++ b/src/vfs/ant_rx_chardev.c
@@ -45,6 +45,14 @@ extern ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U
#define ANT_POLL_TIMEOUT ((int)30000)
+static ANT_U8 aucRxBuffer[NUM_ANT_CHANNELS][ANT_HCI_MAX_MSG_SIZE];
+
+#ifdef ANT_DEVICE_NAME // Single transport path
+ static int iRxBufferLength[NUM_ANT_CHANNELS] = {0};
+#else
+ static int iRxBufferLength[NUM_ANT_CHANNELS] = {0, 0};
+#endif //
+
int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo);
/*
@@ -232,14 +240,13 @@ int setFlowControl(ant_channel_info_t *pstChnlInfo, ANT_U8 ucFlowSetting)
int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
{
int iRet = -1;
- ANT_U8 aucRxBuffer[ANT_HCI_MAX_MSG_SIZE];
int iRxLenRead;
int iCurrentHciPacketOffset;
- int iHciPacketSize;
+ int iHciDataSize;
ANT_FUNC_START();
// Keep trying to read while there is an error, and that error is EAGAIN
- while (((iRxLenRead = read(pstChnlInfo->iFd, aucRxBuffer, sizeof(aucRxBuffer))) < 0)
+ while (((iRxLenRead = read(pstChnlInfo->iFd, &aucRxBuffer[eChannel][iRxBufferLength[eChannel]], (sizeof(aucRxBuffer[eChannel]) - iRxBufferLength[eChannel]))) < 0)
&& errno == EAGAIN)
;
@@ -261,10 +268,21 @@ int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
goto out;
}
} else {
- ANT_SERIAL(aucRxBuffer, iRxLenRead, 'R');
+ ANT_SERIAL(aucRxBuffer[eChannel], iRxLenRead, 'R');
+
+ iRxLenRead += iRxBufferLength[eChannel]; // add existing data on
+
+ // if we didn't get a full packet, then just exit
+ if (iRxLenRead < (aucRxBuffer[eChannel][ANT_HCI_SIZE_OFFSET] + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE)) {
+ iRxBufferLength[eChannel] = iRxLenRead;
+ iRet = 0;
+ goto out;
+ }
+ iRxBufferLength[eChannel] = 0; // reset buffer length here since we should have a full packet
+
#if ANT_HCI_OPCODE_SIZE == 1 // Check the different message types by opcode
- ANT_U8 opcode = aucRxBuffer[ANT_HCI_OPCODE_OFFSET];
+ ANT_U8 opcode = aucRxBuffer[eChannel][ANT_HCI_OPCODE_OFFSET];
if(ANT_HCI_OPCODE_COMMAND_COMPLETE == opcode) {
// Command Complete, so signal a FLOW_GO
@@ -290,33 +308,39 @@ int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
while(iCurrentHciPacketOffset < iRxLenRead) {
- iHciPacketSize = aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
+ // TODO Allow HCI Packet Size value to be larger than 1 byte
+ // This currently works as no size value is greater than 255, and little endian
+ iHciDataSize = aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
+ if ((iHciDataSize + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iCurrentHciPacketOffset) >
+ iRxLenRead) {
+ // we don't have a whole packet
+ iRxBufferLength[eChannel] = iRxLenRead - iCurrentHciPacketOffset;
+ memcpy(aucRxBuffer[eChannel], &aucRxBuffer[eChannel][iCurrentHciPacketOffset], iRxBufferLength[eChannel]);
+ // the increment at the end should push us out of the while loop
+ } else
#ifdef ANT_MESG_FLOW_CONTROL
- if (aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
+ if (aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
ANT_MESG_FLOW_CONTROL) {
// This is a flow control packet, not a standard ANT message
if(setFlowControl(pstChnlInfo, \
- aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
+ aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
goto out;
}
} else
#endif // ANT_MESG_FLOW_CONTROL
{
if (pstChnlInfo->fnRxCallback != NULL) {
- // TODO Allow HCI Packet Size value to be larger than 1 byte
- // This currently works as no size value is greater than 255, and little endian
-
// Loop through read data until all HCI packets are written to callback
- pstChnlInfo->fnRxCallback(iHciPacketSize, \
- &aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET]);
+ pstChnlInfo->fnRxCallback(iHciDataSize, \
+ &aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET]);
} else {
ANT_WARN("%s rx callback is null", pstChnlInfo->pcDevicePath);
- }
+ }
}
- iCurrentHciPacketOffset = iCurrentHciPacketOffset + ANT_HCI_HEADER_SIZE + iHciPacketSize;
+ iCurrentHciPacketOffset = iCurrentHciPacketOffset + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iHciDataSize;
}
}
diff --git a/src/vfs/prerelease/ant_driver_defines.h b/src/vfs/prerelease/ant_driver_defines.h
index 7b6b58b..f2e843b 100644
--- a/src/vfs/prerelease/ant_driver_defines.h
+++ b/src/vfs/prerelease/ant_driver_defines.h
@@ -29,39 +29,70 @@
#ifndef __VFS_PRERELEASE_H
#define __VFS_PRERELEASE_H
-#define ANT_CHIP_NAME "TTY"
-
-#define ANT_COMMANDS_DEVICE_NAME "/dev/smd5"
-#define ANT_DATA_DEVICE_NAME "/dev/smd6"
-
-// Hard reset not supported, don't define ANT_IOCTL_RESET
-
// -----------------------------------------
// | Header | Data | Footer |
// |----------------------|-----------------|
// |Optional| Data | Opt. | ... | Optional |
// | Opcode | Size | Sync | | Checksum |
+
+// Data may include any number of ANT packets, with no sync byte or checksum.
+// A read from the driver may return any number of ANT HCI packets.
+
+
+// ---------------------- REQUIRED
+
+// Which chip is this library being built for:
+#define ANT_CHIP_NAME "TTY"
+// Set the file name the driver creates for the ANT device:
+// If chip uses separate command and data paths:
+#define ANT_COMMANDS_DEVICE_NAME "/dev/smd5"
+#define ANT_DATA_DEVICE_NAME "/dev/smd6"
+// OR
+// If chip uses one path:
+// #define ANT_DEVICE_NAME "/dev/Z"
+
+
+// Set to the number of bytes of header is for Opcode:
#define ANT_HCI_OPCODE_SIZE 0
+
+// Set to the number of bytes of header is for Data Size:
#define ANT_HCI_SIZE_SIZE 1
-
+
+// Set to the number of bytes of header is for Sync:
#define ANT_HCI_SYNC_SIZE 0
+
+// Set to the number of bytes of footer is for Checksum:
#define ANT_HCI_CHECKSUM_SIZE 0
+
+// ---------------------- OPTIONAL
-#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
+// If hard reset is supported, define ANT_IOCTL_RESET
+// #define ANT_IOCTL_RESET _IOW('U', 210, int)
+// #define ANT_IOCTL_RESET_PARAMETER (0)
+// If the chip sends flow control messages:
+// Define the Opcode for a Flow Control message:
+#define ANT_MESG_FLOW_CONTROL ((ANT_U8)0xC9)
+// AND
+// define the message content:
+// That signals Flow Go:
#define ANT_FLOW_GO ((ANT_U8)0x00)
+
+// That signals Flow Stop:
+#define ANT_FLOW_STOP ((ANT_U8)0x80)
-// ---------------------- Not chip specific
+// ---------------------- NOT CHIP SPECIFIC
+// These should not need to be modified, but should be verified they are correct
#define ANT_HCI_HEADER_SIZE ((ANT_HCI_OPCODE_SIZE) + (ANT_HCI_SIZE_SIZE) + (ANT_HCI_SYNC_SIZE))
+#define ANT_HCI_FOOTER_SIZE (ANT_HCI_CHECKSUM_SIZE)
#define ANT_HCI_OPCODE_OFFSET 0
#define ANT_HCI_SIZE_OFFSET ((ANT_HCI_OPCODE_OFFSET) + (ANT_HCI_OPCODE_SIZE))
#define ANT_HCI_SYNC_OFFSET ((ANT_HCI_SIZE_OFFSET) + (ANT_HCI_SIZE_SIZE))
#define ANT_HCI_DATA_OFFSET (ANT_HCI_HEADER_SIZE)
-#define ANT_FLOW_STOP ((ANT_U8)0x80)
#define ANT_FLOW_GO_WAIT_TIMEOUT_SEC 10
#endif /* ifndef __VFS_PRERELEASE_H */