aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-08-30 17:20:06 +0300
committerShlomo Hecht <shlomo@twine-s.com>2018-08-30 17:20:06 +0300
commit62db371c2acc1564cc8bedbe2e355dd863d2bac4 (patch)
treeaa0f85fd52f8a29469236d77123e642d4ceca003 /Software/Embedded_SW/Embedded/Communication/CommunicationTask.c
parent89136a907fcc2ab46ec332e71c1cb4dc478830a9 (diff)
downloadTango-62db371c2acc1564cc8bedbe2e355dd863d2bac4.tar.gz
Tango-62db371c2acc1564cc8bedbe2e355dd863d2bac4.zip
support fast communication (multiple Rx messages from PC). set dispenser homing microstep to 1
Diffstat (limited to 'Software/Embedded_SW/Embedded/Communication/CommunicationTask.c')
-rw-r--r--Software/Embedded_SW/Embedded/Communication/CommunicationTask.c92
1 files changed, 58 insertions, 34 deletions
diff --git a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c
index 91f1a78aa..b0b5115a2 100644
--- a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c
+++ b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c
@@ -16,6 +16,7 @@ Mailbox_Handle CommunicationTxMsgQ = NULL;
typedef struct CommRxMessage{
uint16_t messageId;
uint16_t msgSize;
+ uint32_t BuffId;
}CommRxMessageStruc;
typedef struct CommTxMessage{
uint16_t messageId;
@@ -30,28 +31,65 @@ struct serialBuffer {
size_t used;
size_t size;
} typedef SerialBuffer;
-
+#define SHORT_BUFFER_SIZE 100
char CommRxBuffer[COMM_MAX_BUFFER_SIZE];
-SerialBuffer inBuffer;
-uint32_t initArray(size_t initialSize) {
- SerialBuffer *a = &inBuffer;
+char CommShortRxBuffer[10][SHORT_BUFFER_SIZE];
+SerialBuffer inBuffer[11];
+bool SerialBufferUsed[11] = {false,false,false,false,false,false,false,false,false,false,false,false};
+uint32_t initArray(size_t initialSize)
+{
if (initialSize >= COMM_MAX_BUFFER_SIZE) return 0;
+ if (initialSize > SHORT_BUFFER_SIZE)
+ {
+ if (SerialBufferUsed[10] == true)
+ {
+ return 0xFF;
+ }
+ else
+ {
+ SerialBufferUsed[10] = true;
+ inBuffer[10].buffer = CommRxBuffer;
+ inBuffer[10].used = 0;
+ inBuffer[10].size = initialSize;
+ return 10;
+ }
+ }
+ else
+ {
+ int i;
+ for (i = 0; i < 10; i++)
+ {
+ if (SerialBufferUsed[i] == false)
+ break;
+ }
+ if (i == 10) return 0xFF;
+ else
+ {
+ SerialBufferUsed[i] = true;
+ inBuffer[i].buffer = CommRxBuffer;
+ inBuffer[i].used = 0;
+ inBuffer[i].size = initialSize;
+ return i;
+ }
+ }
+ /*SerialBuffer *a = &inBuffer;
a->buffer = CommRxBuffer;
a->used = 0;
a->size = initialSize;
- return initialSize;
+ return initialSize;*/
}
-void insertArray(char element) {
- SerialBuffer *a = &inBuffer;
+void insertArray(uint32_t buffer,char element)
+{
+ SerialBuffer *a = &inBuffer[buffer];
// a->used is the number of used entries, because a->array[a->used++] updates a->used only *after* the array has been accessed.
// Therefore a->used can go up to a->size
a->buffer[a->used++] = element;
}
-void freeArray(void) {
- SerialBuffer *a = &inBuffer;
- a->used = a->size = 0;
+void freeArray(uint32_t buffer)
+{
+ SerialBufferUsed[buffer] = false;
}
uint32_t CommunicationTaskInit(void)
@@ -62,13 +100,14 @@ uint32_t CommunicationTaskInit(void)
}
uint32_t CommTxMsgCounter = 0;
uint32_t CommRxMsgCounter = 0;
-uint32_t CommunicationTaskMessageReceived(uint16_t msgSize)
+uint32_t CommunicationTaskMessageReceived(uint32_t buffer,uint16_t msgSize)
{
CommRxMessageStruc Message;
CommRxMsgCounter++;
Message.messageId = 1;
Message.msgSize = msgSize;
+ Message.BuffId = buffer;
if (CommunicationRxMsgQ != NULL)
/*retcode =*/ Mailbox_post(CommunicationRxMsgQ , &Message, BIOS_NO_WAIT);
@@ -86,13 +125,13 @@ void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length))
* this communication task is created statically in system initialization, in blocking mode
* over one of the chosen ommunication methods (USB or Blutooth).
******************************************************************************/
+uint32_t cLength[50] = {0};
+byte cindex = 0;
void communicationTask(UArg arg0, UArg arg1)
{
- //uint32_t ui32RxCount;
CommRxMessageStruc Message;
- initArray(1);
//ui32RxCount = 0;
CommunicationRxMsgQ = Mailbox_create(sizeof(CommRxMessageStruc), 4, NULL,NULL);
@@ -109,11 +148,13 @@ void communicationTask(UArg arg0, UArg arg1)
//ui32RxCount += Message.msgSize;
if (callback != NULL)
{
- callback(inBuffer.buffer,inBuffer.used);
+ cLength[cindex] = Message.msgSize;
+ if (cindex++>=50)
+ cindex = 0;
+ callback(inBuffer[Message.BuffId].buffer,inBuffer[Message.BuffId].used);
}
- freeArray();
- initArray( 1);
+ freeArray(Message.BuffId);
break;
default:
break;
@@ -150,27 +191,10 @@ int32_t SetCommunicationPath(bool UARTorUSB)
void communicationTxTask(UArg arg0, UArg arg1)
{
- //uint32_t ui32RxCount;
CommTxMessageStruc Message;
-/* typedef struct CommRxMessage{
- uint16_t messageId;
- uint16_t msgSize;
- char *Buff;
- }CommTxMessageStruc;
-*/
- initArray(1);
-
- /*#ifdef USE_USB
- SetCommunicationPath(isUSB);
- #else
- SetCommunicationPath(isUART);
- #endif*/
- //ui32RxCount = 0;
+ //initArray(1);
CommunicationTxMsgQ = Mailbox_create(sizeof(CommTxMessageStruc), 20, NULL,NULL);
- /* Block while the device is NOT connected to the USB */
-// Semaphore_pend(initConnectionSem, BIOS_WAIT_FOREVER);
-
while(1)
{
Mailbox_pend(CommunicationTxMsgQ , &Message, BIOS_WAIT_FOREVER);