/* Function: rt_UploadServerWork =============================================== * Abstract: * Upload model signals to host. */ PUBLIC boolean_T rt_UploadServerWork(SimStruct *S) { int_T i; ExtBufMemList upList; boolean_T error = EXT_NO_ERROR; UNUSED_PARAM(S); #ifdef VXWORKS /* * Don't spin the CPU unless we've got data to upload. * The upload.c/UploadBufAddTimePoint function gives the sem * each time that data is added. */ semTake(uploadSem, WAIT_FOREVER); #endif if (!connected) goto EXIT_POINT; UploadBufGetData(&upList); while(upList.nActiveBufs > 0) { for (i=0; i<upList.nActiveBufs; i++) { int_T nSet; const BufMem *bufMem = &upList.bufs[i]; error = ExtSetHostData( extUD,bufMem->nBytes1,bufMem->section1,&nSet); if (error || (nSet != bufMem->nBytes1)) { fprintf(stderr,"ExtSetHostData() failed on data upload.\n"); goto EXIT_POINT; } if (bufMem->section2 != NULL) { /* circular buffer was wrapped - send 2nd piece */ error = ExtSetHostData( extUD,bufMem->nBytes2,bufMem->section2,&nSet); if (error || (nSet != bufMem->nBytes2)) { fprintf(stderr,"ExtSetHostData() failed on data upload.\n"); goto EXIT_POINT; } } /* comfirm that the data was sent */ UploadBufDataSent(upList.tids[i]); } UploadBufGetData(&upList); } EXIT_POINT: return(error); } /* end rt_UploadServerWork */
/* Function: UploadServerWork ================================================= * Abstract: * Upload model signals to host for a single upInfo. */ void UploadServerWork(int32_T upInfoIdx, int_T numSampTimes) { int_T i; ExtBufMemList upList; boolean_T error = EXT_NO_ERROR; #ifdef QNX_OS /* * Don't spin the CPU unless we've got data to upload. * The upload.c/UploadBufAddTimePoint function gives the sem * each time that data is added. */ //taskUnsafe(); //printf("Waiting on uploadSem\n"); sem_wait(uploadSem); //printf("Unblocked in uploadSem in UploadServerWork\n"); //taskSafe(); #endif if (!connected) { //printf("Exiting UploadServerwork because host not connected\n"); } else { //printf("In UploadServerWork, host connected\n"); } if (!connected) goto EXIT_POINT; UploadBufGetData(&upList, upInfoIdx, numSampTimes); while(upList.nActiveBufs > 0) { for (i=0; i<upList.nActiveBufs; i++) { const BufMem *bufMem = &upList.bufs[i]; /* * We call SendPktDataToHost() instead of SendPktToHost() because * the packet header is combined with packet payload. We do this * to avoid the overhead of making two calls for each upload * packet - one for the head and one for the payload. */ error = SendPktDataToHost( bufMem->section1, bufMem->nBytes1); if (error != EXT_NO_ERROR) { fprintf(stderr,"SendPktDataToHost() failed on data upload.\n"); goto EXIT_POINT; } if (bufMem->nBytes2 > 0) { error = SendPktDataToHost( bufMem->section2, bufMem->nBytes2); if (error != EXT_NO_ERROR) { fprintf(stderr,"SendPktDataToHost() failed on data upload.\n"); goto EXIT_POINT; } } /* comfirm that the data was sent */ UploadBufDataSent(upList.tids[i], upInfoIdx); } UploadBufGetData(&upList, upInfoIdx, numSampTimes); } EXIT_POINT: if (error != EXT_NO_ERROR) { /* An error in this function is caused by a physical failure in the * external mode connection. We assume this failure caused the host * to disconnect. The target must be disconnected and returned to a * state where it is running and can be re-connected to by the host. */ ForceDisconnectFromHost(numSampTimes); } }
/* Function: UploadServerWork ================================================= * Abstract: * Upload model signals to host for a single upInfo. */ void UploadServerWork(int32_T upInfoIdx, int_T numSampTimes) { int_T i; ExtBufMemList upList; boolean_T error = EXT_NO_ERROR; #ifdef EXT_SVR_MUTEX_ENABLE pthread_mutex_lock(&_sendPktLock); #endif if (!connected) goto EXIT_POINT; UploadBufGetData(&upList, upInfoIdx, numSampTimes); while(upList.nActiveBufs > 0) { for (i=0; i<upList.nActiveBufs; i++) { const BufMem *bufMem = &upList.bufs[i]; /* * We call SendPktDataToHost() instead of SendPktToHost() because * the packet header is combined with packet payload. We do this * to avoid the overhead of making two calls for each upload * packet - one for the head and one for the payload. */ error = SendPktDataToHost( bufMem->section1, bufMem->nBytes1); if (error != EXT_NO_ERROR) { fprintf(stderr,"SendPktDataToHost() failed on data upload.\n"); goto EXIT_POINT; } if (bufMem->nBytes2 > 0) { error = SendPktDataToHost( bufMem->section2, bufMem->nBytes2); if (error != EXT_NO_ERROR) { fprintf(stderr,"SendPktDataToHost() failed on data upload.\n"); goto EXIT_POINT; } } /* comfirm that the data was sent */ UploadBufDataSent(upList.tids[i], upInfoIdx); } UploadBufGetData(&upList, upInfoIdx, numSampTimes); } EXIT_POINT: #ifdef EXT_SVR_MUTEX_ENABLE pthread_mutex_unlock(&_sendPktLock); #endif if (error != EXT_NO_ERROR) { /* An error in this function is caused by a physical failure in the * external mode connection. We assume this failure caused the host * to disconnect. The target must be disconnected and returned to a * state where it is running and can be re-connected to by the host. */ ForceDisconnectFromHost(numSampTimes); } }