diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-30 17:20:06 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-30 17:20:06 +0300 |
| commit | 62db371c2acc1564cc8bedbe2e355dd863d2bac4 (patch) | |
| tree | aa0f85fd52f8a29469236d77123e642d4ceca003 /Software/Embedded_SW | |
| parent | 89136a907fcc2ab46ec332e71c1cb4dc478830a9 (diff) | |
| download | Tango-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')
5 files changed, 76 insertions, 43 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); diff --git a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.h b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.h index 50309c899..27907ee07 100644 --- a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.h +++ b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.h @@ -13,13 +13,13 @@ void RegisterReceiveCallback(void (*callback_ptr)(char* buffer, size_t length)); uint32_t initArray( size_t initialSize); -void insertArray( char element); +void insertArray(uint32_t buffer, char element); -void freeArray(void); +void freeArray(uint32_t buffer); extern uint32_t CommunicationTaskInit(void); -extern uint32_t CommunicationTaskMessageReceived(uint16_t msgSize); +extern uint32_t CommunicationTaskMessageReceived(uint32_t buffer,uint16_t msgSize); extern bool CommunicationTaskSendMessage(char* buffer,size_t length); diff --git a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c index 04561139e..b4da9afa9 100644 --- a/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c +++ b/Software/Embedded_SW/Embedded/Drivers/USB_Communication/USBCDCD.c @@ -530,6 +530,8 @@ uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValu return(0); } +uint32_t buffId = 0xFF; + void handleRx(void) { uint32_t ui32Read; @@ -551,7 +553,9 @@ if (expected_message_size == 0) } while(size_bar < 4); expected_message_size = *(int *)size; - initArray( expected_message_size); + buffId = initArray( expected_message_size); + if (buffId == 0xFF) + expected_message_size = 0; } do @@ -561,14 +565,14 @@ if (expected_message_size == 0) // Did we get a character? if(ui32Read) { - insertArray(ui8Char); + insertArray(buffId,ui8Char); current_message_size++; } if (current_message_size == expected_message_size) { g_RxCount += current_message_size; - CommunicationTaskMessageReceived(g_RxCount); + CommunicationTaskMessageReceived(buffId,current_message_size); expected_message_size = 0; current_message_size = 0; break; diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c index ec61f414c..b5c61eb46 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c @@ -199,6 +199,8 @@ void UART_ResetBuffers(void) // The UART interrupt handler. // //***************************************************************************** +uint32_t U0buffId = 0xFF; + void UARTIntHandler(UArg arg0) { uint32_t ui32Status; @@ -235,7 +237,8 @@ void UARTIntHandler(UArg arg0) //uDataLength[uindex] = U0_expected_message_size; //if (uindex++>=50) // uindex = 0; - if (initArray( U0_expected_message_size) == 0) + U0buffId = initArray( U0_expected_message_size); + if (U0buffId == 0xFF) U0_expected_message_size = 0; U0_size_bar = 0; memcpy (oldsize,size,4); @@ -246,7 +249,7 @@ void UARTIntHandler(UArg arg0) ui8Char = (char)ROM_UARTCharGetNonBlocking(UART_BASE); Uart_rx_TotalCounter++; - insertArray(ui8Char); + insertArray(U0buffId,ui8Char); U0_current_message_size++; if (U0_current_message_size == U0_expected_message_size) @@ -254,7 +257,7 @@ void UARTIntHandler(UArg arg0) Clock_setTimeout(UartClock, UartClockTimeout); Clock_start(UartClock); Uart_rx_Counter+=(4+U0_current_message_size); - CommunicationTaskMessageReceived(U0_current_message_size); + CommunicationTaskMessageReceived(U0buffId, U0_current_message_size); U0_expected_message_size = 0; U0_current_message_size = 0; break; diff --git a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c index af8932872..70ede0916 100644 --- a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c +++ b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c @@ -183,6 +183,7 @@ uint32_t DispenserHomingRequestCallback(uint32_t deviceID, uint32_t ReadValue) //close dry air valve in the dispenser Valve_Set((Valves_t) (DispenserId+VALVE_2W_MID_AIR_LF), Atm_MidTank_OFF); + MotorSetMicroStep(deviceID, MotorsCfg[deviceID].microstep); responseContainer = createContainer(MESSAGE_TYPE__DispenserHomingResponse, HomingToken[deviceID], true, &response, &motor_homing_response__pack, &motor_homing_response__get_packed_size); responseContainer.continuous = true; @@ -230,6 +231,7 @@ uint32_t DispenserHomingRequestFunc(MessageContainer* requestContainer) //open dry air valve in the dispenser Valve_Set((Valves_t) (request->index+VALVE_2W_MID_AIR_LF), Atm_MidTank_ON); + MotorSetMicroStep(MotorId, 1); MotorMovetoLimitSwitch (MotorId,1-MotorsCfg[MotorId].directionthreadwize, speed, Motor_Id_to_LS_Id[MotorId], DispenserHomingRequestCallback); return OK; |
