Пример #1
0
void NiPci6220MainThread(void *arg)
{
    int i;
    int ret;
    DaqQueueData pDAQData;

    ret = NiPci6220Config();

    if(ret > 0) {
        epicsPrintf("NiPci6220 Initialize Error\n");
        return;
    }

    epicsPrintf("NiPci6220 Initialize OK\n");

    while(1) {
        epicsMessageQueueReceive(daq6220pvt.DaqQueueId, (void *)&pDAQData, sizeof(DaqQueueData));
    epicsPrintf("NiPci6220 received message : %d\n", pDAQData.opcode);

        switch(pDAQData.opcode) {
        case OP_CODE_DAQ_RUN:
            if(daq6220pvt.status == DAQ_STATUS_STOP) {
                system("rm -f /tmp/nidaq_6220.dat");
                daq6220pvt.status = DAQ_STATUS_RUN;
                epicsPrintf("NI6220 OP_CODE_DAQ_RUN\n");

                ret = SetDaqStart(&daq6220pvt);
            }
            break;
        case OP_CODE_DAQ_STOP:  /* Stop Task */
            if(daq6220pvt.status == DAQ_STATUS_RUN) {
                daq6220pvt.status = DAQ_STATUS_STOP;
                epicsPrintf("NI6220 OP_CODE_DAQ_STOP\n");
            }
            break;
        case OP_CODE_DAQ_CONFIG:
            if(daq6220pvt.status != DAQ_STATUS_RUN) {
                SetDaqAbort(&daq6220pvt);
                NiPci6220Config();
            }
            break;
        case OP_CODE_DAQ_ABORT: /* Task clear and Initialize */
            if(daq6220pvt.status == DAQ_STATUS_RUN) {
                epicsPrintf("**** Abort ****\n");
                SetDaqAbort(&daq6220pvt);
                NiPci6220Config();
            }
            break;
        case OP_CODE_DAQ_MDSPLUS: /* MDSPlus Data Write */
            epicsPrintf("**** MDSPlus Write ****\n");
            daq6220pvt.status = DAQ_STATUS_DONE;
#if 0
            acqMdsPutData(&daq6220pvt);
#endif
            break;
        }

        epicsThreadSleep(0.1);
    }
}
Пример #2
0
static EPICSTHREADFUNC calcThread(void *param)
{
    subRecord *precord;
    myData    *pmyData;
    struct rset    *prset;

    while(epicsMessageQueueReceive(queueId, (void*) &pmyData, sizeof(myData*))) {
        precord =  pmyData->precord;
        prset   = (struct rset*) precord->rset;

        if(dbSubFinalDebug) {
            epicsMessageQueueShow(queueId, 1);
            epicsPrintf("Thread %s: Record %s requested thread processing\n",
                        epicsThreadGetNameSelf(),
                        precord->name);
        }


        pmyData->private_counter ++;


        dbScanLock((struct dbCommon*) precord);
        (*prset->process)(precord);
        dbScanUnlock((struct dbCommon*) precord);
    
    }


    return 0;
}
Пример #3
0
static void acalcPerformTask(void *parm) {
	calcMessage msg;
	acalcoutRecord *pcalc;
	struct rset *prset;

	if (aCalcoutRecordDebug >= 10)
		printf("acalcPerformTask:entry\n");

	while (1) {
		/* waiting for messages */
		if (epicsMessageQueueReceive(acalcMsgQueue, &msg, MSG_SIZE) != MSG_SIZE) {
			printf("acalcPerformTask: epicsMessageQueueReceive returned wrong size\n");
			break;
		}

		pcalc = msg.pcalc;
		prset = (struct rset *)(pcalc->rset);

		dbScanLock((struct dbCommon *)pcalc);

		if (aCalcoutRecordDebug >= 10)
			printf("acalcPerformTask:message from '%s'\n", pcalc->name);
		call_aCalcPerform(pcalc);
		if (aCalcoutRecordDebug >= 10)
			printf("acalcPerformTask:processing '%s'\n", pcalc->name);

		(*prset->process)(pcalc);
		dbScanUnlock((struct dbCommon *)pcalc);
	}
}
Пример #4
0
static void controlThreadFunc(void *param)
{

	drvM6802_taskConfig *ptaskConfig = (drvM6802_taskConfig*) param;
	drvM6802_controlThreadConfig *pcontrolThreadConfig;
	controlThreadQueueData		queueData;

	while( !ptaskConfig->pcontrolThreadConfig ) epicsThreadSleep(.1);
	pcontrolThreadConfig = (drvM6802_controlThreadConfig*) ptaskConfig->pcontrolThreadConfig;


	epicsPrintf("task launching: %s thread for %s task\n",pcontrolThreadConfig->threadName, ptaskConfig->taskName);

	while(TRUE) {
		EXECFUNCQUEUE            pFunc;
		execParam                *pexecParam;
		struct dbCommon          *precord;
		struct rset              *prset;

		drvM6802_taskConfig    *ptaskConfig;

		epicsMessageQueueReceive(pcontrolThreadConfig->threadQueueId,
				         (void*) &queueData,
					 sizeof(controlThreadQueueData));

		pFunc      = queueData.pFunc;
	        pexecParam = &queueData.param;	
		precord    = (struct dbCommon*) pexecParam->precord;
		prset      = (struct rset*) precord->rset;
		ptaskConfig = (drvM6802_taskConfig *) pexecParam->ptaskConfig;

		if(!pFunc) continue;
		else pFunc(pexecParam);

		if(!precord) continue;


		dbScanLock(precord);
		(*prset->process)(precord); 
		dbScanUnlock(precord);
	}


	return;
}
Пример #5
0
void NiPci6220MainThread(void *arg)
{
    int i;
    int ret;
    char szFile[256];
    DaqQueueData pDAQData;

    ret = NiPci6220Config();

    epicsAtExit((EPICSEXITFUNC) NiPci6220Exit, NULL);

    if(ret > 0) {
        epicsPrintf("NiPci6220 Initialize Error\n");
        return;
    }

    epicsPrintf("NiPci6220 Initialize OK\n");

    while(1) {
        epicsMessageQueueReceive(daq6220pvt.DaqQueueId, (void *)&pDAQData, sizeof(DaqQueueData));

        switch(pDAQData.opcode) {
        case OP_CODE_DAQ_RUN:
            if(daq6220pvt.status == DAQ_STATUS_STOP) {
                system("rm -f /tmp/nidaq_6220.dat");
                daq6220pvt.status = DAQ_STATUS_RUN;
                epicsPrintf("NI6220 : OP_CODE_DAQ_RUN\n");

                for(i=0; i < 16; i++) {
                    if(daq6220pvt.mdsput[i] == 1 && daq6220pvt.fp[i] == NULL) {
                        sprintf(szFile, "/tmp/%s_%d.dat", daq6220pvt.fileName, i);
                        daq6220pvt.fp[i] = fopen(szFile, "w+");
                    }
                }

                ret = SetDaqStart(&daq6220pvt);
            }
            break;
        case OP_CODE_DAQ_STOP:  /* Stop Task */
            if(daq6220pvt.status == DAQ_STATUS_RUN) {
                daq6220pvt.status = DAQ_STATUS_STOP;
                epicsPrintf("NI6220 : OP_CODE_DAQ_STOP\n");
            }
            break;
        case OP_CODE_DAQ_CONFIG:
            if(daq6220pvt.status != DAQ_STATUS_RUN) {
                SetDaqAbort(&daq6220pvt);
                NiPci6220Config();
            }
            break;
        case OP_CODE_DAQ_ABORT: /* Task clear and Initialize */
            if(daq6220pvt.status == DAQ_STATUS_RUN) {
                epicsPrintf("NI6220 : Abort\n");
                SetDaqAbort(&daq6220pvt);
                NiPci6220Config();
            }
            break;
        case OP_CODE_DAQ_MDSPLUS: /* MDSPlus Data Write */
            epicsPrintf("**** NI6220 MDSPlus Write ****\n");
            daq6220pvt.status = DAQ_STATUS_DONE;
            break;
        }

        epicsThreadSleep(0.1);
    }
}
Пример #6
0
static void RingThreadFunc(void *param)
{
	int i,j,ss;
/*	unsigned long long int start, stop,currentCal;
	uint32 shotNu;
*/
	drvM6802_taskConfig *ptaskConfig = (drvM6802_taskConfig*) param;
	drvM6802_controlThreadConfig *pringThreadConfig;

	bufferingThreadQueueData queueData;
	drvBufferConfig_Node *pbufferNode;


	while( !ptaskConfig->pringThreadConfig ) epicsThreadSleep(.1);
	pringThreadConfig = (drvM6802_controlThreadConfig*) ptaskConfig->pringThreadConfig;


	for(i = 0; i< 30; i++)
	{
		drvBufferConfig_Node *pbufferNode = NULL;
		pbufferNode = (drvBufferConfig_Node*) malloc(sizeof(drvBufferConfig_Node));
		if(!pbufferNode) {
				epicsPrintf("\n>>> malloc(sizeof(drvBufferConfig_Node))... fail\n");
				return;
		}
		ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node);
	}


	epicsPrintf("ellCount: %d <init task launching> \n", ellCount(pdrvBufferConfig->pbufferList) );
	epicsPrintf("task launching: %s thread for %s task\n",pringThreadConfig->threadName, ptaskConfig->taskName);

	i = INIT_CH_MASK;   
	ss = 0;	
	while(TRUE) 
	{
		epicsMessageQueueReceive(bufferingQueueID, (void*) &queueData, sizeof(bufferingThreadQueueData));

/*		epicsThreadSleep(.5); */

#if 0
		epicsPrintf(">>> rcv ID: %d, dma cnt: %d, stop: %d\n", bufferingQueueID, 
																queueData.cnt_DMAcallback, 
																queueData.nStop);
#endif
		pbufferNode = queueData.pNode;

		if(pbufferNode) 
		{
			if( pbufferNode->nStop ) {
/*			if( queueData.nStop) { */
/*				epicsPrintf(">>> rcv ID: %d, dma cnt: %d, stop: %d\n", bufferingQueueID, 
																queueData.cnt_DMAcallback, 
																queueData.nStop);
*/
				fwrite( &i, 4, 1, fpRaw ); /* number of used channel = whole channel */
				fwrite( &dmaSize, 4, 1, fpRaw );
				fwrite( &pbufferNode->nCnt, 4, 1, fpRaw );
				fclose(fpRaw);
				fpRaw = NULL;
/*				nDMAcnt = 0; */
/*				epicsPrintf("last ell count before : %d \n", ellCount(pdrvBufferConfig->pbufferList) ); */
				ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node);
				epicsPrintf("ellCount: %d <end> \n", ellCount(pdrvBufferConfig->pbufferList) );
			  	ss = ellCount(pdrvBufferConfig->pbufferList);
				if(ss<30){
					for(j = ss; j <= 29; j++)
					{
					ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node);
					}
					epicsPrintf("Ell Buffer lack add Complated : ellCnt %d \n", ellCount(pdrvBufferConfig->pbufferList) ); 
				}

			} else {
#if 0    /* TG.Lee Enable 20081111 */
				epicsPrintf("RingThreadFunc Time Register Address TG.Lee\n");
				epicsPrintf(">>> MM_CNTRL_REG_1 : 0x%X\n", ptaskConfig->register_m6802[MM_CNTRL_REG_1] );
				epicsPrintf(">>> MM_CNTRL_REG_2 : 0x%X\n", ptaskConfig->register_m6802[MM_CNTRL_REG_2] );
				epicsPrintf(">>> MM_PGA_ARRAY_1 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_1] );
				epicsPrintf(">>> MM_PGA_ARRAY_2 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_2] );
				epicsPrintf(">>> MM_PGA_ARRAY_3 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_3] );
				epicsPrintf(">>> MM_PGA_ARRAY_4 : 0x%X\n", ptaskConfig->register_m6802[MM_PGA_ARRAY_4] );
				epicsPrintf(">>> MM_ADC_HPFE : 0x%X\n", ptaskConfig->register_m6802[MM_ADC_HPFE] );
				epicsPrintf(">>> MM_ADC_ZCAL : 0x%X\n", ptaskConfig->register_m6802[MM_ADC_ZCAL] );
#endif

/*				epicsPrintf(">>> rcv ID: %d, dma cnt: %d, stop: %d\n", bufferingQueueID, 
																queueData.cnt_DMAcallback, 
																queueData.nStop);
*/
/*				if( nDMAcnt != pbufferNode->nCnt )
					epicsPrintf("\n>>> RingThreadFunc : Get Message order error! cnt(%d) \n", pbufferNode->nCnt);
*/
				fwrite( pbufferNode->data, dmaSize, 1, fpRaw );
/*				nDMAcnt = queueData.cnt_DMAcallback +1; */
/*				epicsPrintf("ell count before : %d \n", ellCount(pdrvBufferConfig->pbufferList) ); */
				ellAdd(pdrvBufferConfig->pbufferList, &pbufferNode->node);
				epicsPrintf("ellCount :ellCnt %d <first> \n", ellCount(pdrvBufferConfig->pbufferList) );  
			}
/*		epicsPrintf("Wait Ring ?? %d \n", ss++);   */
/*
			if (ptaskConfig->eceCalMode) {
				start = drvM6802_getCurrentUsec();
				drvM6802_set_DAQstop(ptaskConfig);
				epicsThreadSleep(0.1);
				drvM6802_set_DAQclear(ptaskConfig);
				epicsThreadSleep(0.1);
				dataChannelizationAndSendData(ptaskConfig->shotNumber, 3);							
				epicsThreadSleep(0.1);
				shotNu = ptaskConfig->shotNumber;
				ptaskConfig->shotNumber = shotNu + 1;
				epicsPrintf("Local Mode - ECE Calibration => shot Number : %d \n",ptaskConfig->shotNumber);
				pbufferNode->nStop = 1;
				epicsThreadSleep(0.1);
				drvM6802_set_DAQready(ptaskConfig);
				epicsThreadSleep(0.1);
				drvM6802_set_DAQstart(ptaskConfig);
				epicsThreadSleep(0.1);
				stop = drvM6802_getCurrentUsec();
				currentCal = drvM6802_intervalUSec(start, stop);
				epicsPrintf("\nECE Calibration Cycle time is %lf msec\n", 1.E-3 * (double)currentCal);	
			}
*/
/*			pbufferNode = (drvBufferConfig_Node*) ellNext(&pbufferNode->node); */

		} else
			epicsPrintf("\n>>> RingThreadFunc : no ellFirst node \n");
	}


	return;
}
Пример #7
0
void threadFunc_user_RingBuf(void *param)
{
	int i, ellCnt;
/*	int show_info = 0; */

	ST_STD_device *pSTDdev = (ST_STD_device*) param;
//	ST_threadCfg *pST_BufThread;

	ST_User_Buff_node queueData;
	ST_buf_node *pbufferNode;	
	ST_ACQ196 *pAcq196;

//	while( !pSTDdev->pST_BuffThread) epicsThreadSleep(.1);
	
//	pST_BufThread = (ST_threadCfg*) pSTDdev->pST_BuffThread;
	pAcq196 = (ST_ACQ196 *)pSTDdev->pUser;

#if PRINT_DAQ_DEBUG
	epicsPrintf("\n %s: pSTDdev: %p, pAcq196: %p , pST_BuffThread: %p\n",pSTDdev->taskName, pSTDdev, pAcq196, pSTDdev->ST_RingBufThread );
#endif
/*	epicsPrintf("\n >>> %s has threadQueueId: %d\n", pST_BufThread->threadName, pSTDdev->ST_RingBufThread.threadQueueId );
*/

	for(i = 0; i< MAX_RING_BUF_NUM; i++)
	{
		ST_buf_node *pbufferNode1 = NULL;
		pbufferNode1 = (ST_buf_node*) malloc(sizeof(ST_buf_node));
		if(!pbufferNode1) {
			epicsPrintf("\n>>> threadFunc_user_RingBuf: malloc(sizeof(ST_buf_node))... fail\n");
			return;
		}
		ellAdd(pSTDdev->pList_BufferNode, &pbufferNode1->node);
	}
	epicsPrintf(" %s: create %d node (size:%dKB)\n", pSTDdev->ST_RingBufThread.threadName, 
																		MAX_RING_BUF_NUM,
																		sizeof(ST_buf_node)/1024 );
/*
	epicsPrintf("task launching: %s thread for %s task\n",pringThreadConfig->threadName, pSTDdev->taskName);
*/
#if 0
	epicsPrintf(">>> %s, ellCnt:%d\n", pringThreadConfig->threadName, 
												ellCount(pAcq196->pdrvBufferConfig->pbufferList));
#endif
	
	while(TRUE) 
	{
		epicsMessageQueueReceive(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buff_node));
	
		if( queueData.opcode & QUEUE_OPCODE_CLOSE_FILE) {
#if PRINT_DMA_NUM			
			printf(">>> [3]%s: got msg \"%s\" close\n", pSTDdev->taskName, pAcq196->dataFileName);
#endif
#if USE_FILE_POINTER
			if( pAcq196->fpRaw != NULL )
				fclose(pAcq196->fpRaw);
			pAcq196->fpRaw = NULL;
#else
			close(pAcq196->R_file);
			pAcq196->R_file = -1;
#endif
			
#if PRINT_DMA_NUM			
			printf(">>> [4]%s: DAQ stopted!(0x%X) \n", pSTDdev->taskName, pSTDdev->StatusDev);
#endif
/*			trig_stop = wf_getCurrentUsec();
			trig_interval = wf_intervalUSec(trig_start, trig_stop); */
#if PRINT_DMA_NUM
/*			printf(">>> [5]%s: Trig ON time is %lf sec\n", pSTDdev->taskName, (1.E-3 * (double)trig_interval)/1000.0 ); */
#endif

			/* it will have possible problem when Mater mode with internal clock */
			if( (pAcq196->nCardMode != CARD_MODE_MASTER) && (pAcq196->clockSource == CLOCK_INTERNAL) )  /* this is single op mode */
			{
				acq196_setDIO_falling(pSTDdev);				
			}
			
			pSTDdev->StatusDev &= ~DEV_CMD_DAQ_STOPED;

		} /* when opcode is file close command */
		else {
			pbufferNode = queueData.pNode;

			if( pSTDdev->StatusDev & TASK_WAIT_FOR_TRIGGER ) 
			{	
				pSTDdev->StatusDev |= TASK_IN_PROGRESS;
				pSTDdev->StatusDev &= ~TASK_WAIT_FOR_TRIGGER;
				scanIoRequest(pSTDdev->ioScanPvt_status);
				notify_refresh_master_status();
			}

#if USE_FILE_POINTER
			fwrite( pbufferNode->data, queueData.size, 1, pAcq196->fpRaw );
#else			
			write(pAcq196->R_file, pbufferNode->data, queueData.size);
#endif

			ellAdd(pSTDdev->pList_BufferNode, &pbufferNode->node);
			ellCnt = ellCount(pSTDdev->pList_BufferNode);
#if 0
			if( pSTDdev->ST_Base.nSamplingRate >= 200000) {
				if( (queueData.u32Cnt % 8 )==0 )
					show_info = 1;
			} else if( pSTDdev->ST_Base.nSamplingRate >= 100000) {
				if( (queueData.u32Cnt % 5 )==0 )
					show_info = 1;
			} else if( pSTDdev->ST_Base.nSamplingRate >= 50000) {
				if( (queueData.u32Cnt % 3 )==0 )
					show_info = 1;
			} else {
				show_info = 1;
			}
			if( show_info){
/*				printf("*%s, %dMB, %d, rcv:%lu\n", pringThreadConfig->threadName, queueData.size/1024/1024, ellCnt, queueData.u32Cnt );  */
				pAcq196->daqing_cnt++;
				scanIoRequest(pSTDdev->ioScanPvt_userCall);
				show_info = 0;
			}
#endif
			pAcq196->daqing_cnt++;
			scanIoRequest(pSTDdev->ioScanPvt_userCall);


			if( ellCnt < MAX_CUTOFF_BUF_NODE) {
				printf("!!! %s, Danger! DMA must be Stopped !! >> Ell Counter: %d\n", 
																pSTDdev->ST_RingBufThread.threadName, 
																ellCnt);
/*				pSTDdev->StatusDev &= ~STATUS_SYS_RUN;
				drvDPIO2_set_DMAstop ( pAcq196);
*/
			}

		} /* whenever get a Data node  */

	} /* while(TRUE)  */

	return;
}
Пример #8
0
static void initConversionTask(void* parm)
{
    int qstatus;
    void *sub;
    struct reinitMsg msg;
    struct cvtRecord *pcvt;
    long status;

    while (TRUE) {
        qstatus = epicsMessageQueueReceive(
            initConversionQ, (void*)&msg, REINIT_MSG_SIZE);
        if (qstatus == -1) {
            nerrmsg("", "msgQReceive failed");
            continue;
        }
        pcvt = msg.record;
        status = initConversion(pcvt->name, msg.bdir, msg.tdir, msg.meth, msg.spec, &sub);
        dbScanLock((struct dbCommon *)pcvt);
        if (status && pcvt->ista != menuCvtInitStateAgain) {
            if (pcvt->ista != menuCvtInitStateError) {
                pcvt->ista = menuCvtInitStateError;
                pcvt->drty |= DRTY_ISTA;
            }
        }
        else {
            switch (pcvt->ista) {
            case menuCvtInitStateInProgress:
            case menuCvtInitStateError:
                pcvt->ista = menuCvtInitStateDone;
                pcvt->drty |= DRTY_ISTA;
                /* free old csub if it was a csm_function... */
                if (pcvt->meth == menuCvtMethod1DTable
                    || pcvt->meth == menuCvtMethod1DTableInverted
                    || pcvt->meth == menuCvtMethod2DTable) {
                    csm_function *csub = (csm_function *)pcvt->csub;
                    if (csub) {
                        /* check because it might have never been created */
                        csm_free(csub);
                    }
                }
                /* ...and write the new values back into the record */
                pcvt->meth = msg.meth;
                pcvt->drty |= DRTY_METH;
                strncpy(pcvt->spec, msg.spec, SPEC_SIZE);
                pcvt->drty |= DRTY_SPEC;
                strncpy(pcvt->bdir, msg.bdir, BDIR_SIZE);
                pcvt->drty |= DRTY_BDIR;
                strncpy(pcvt->tdir, msg.tdir, TDIR_SIZE);
                pcvt->drty |= DRTY_TDIR;
                pcvt->csub = sub;
                break;
            case menuCvtInitStateAgain:
                if (!status && sub && (
                    pcvt->meth == menuCvtMethod1DTable
                    || pcvt->meth == menuCvtMethod1DTableInverted
                    || pcvt->meth == menuCvtMethod2DTable)) {
                    csm_free((csm_function *)sub);
                }
                /* even if initConversion(...) above failed, we go here */
                if (reinitConversion(pcvt)) {
                    /* this is fatal */
                    pcvt->ista = menuCvtInitStateError;
                    pcvt->drty |= DRTY_ISTA;
                    pcvt->pact = TRUE;
                    break;
                }
                pcvt->ista = menuCvtInitStateInProgress;
                pcvt->drty |= DRTY_ISTA;
                break;
            case menuCvtInitStateDone:
                errmsg("internal error: unexpected "
                    "value <menuCvtInitStateDone> in field ISTA");
                pcvt->pact = TRUE;
                break;
            default:
                errmsg("internal error: ISTA is not a member of menuCvtMethod");
                pcvt->pact = TRUE;
            }
        }
        checkAlarms(pcvt);
        monitor(pcvt);
        dbScanUnlock((struct dbCommon *)pcvt);
    }
}
Пример #9
0
void threadFunc_RTcore_RingBuf(void *param)
{
	int i, ellCnt;
	epicsThreadId pthreadInfo;

	ST_STD_device *pSTDdev = (ST_STD_device*) param;

	ST_User_Buf_node queueData;
	ST_buf_node *pbufferNode;	
	ST_RTcore *pRTcore;


	pRTcore = (ST_RTcore *)pSTDdev->pUser;

#if 0
	epicsPrintf("\n %s: pSTDdev: %p, p16aiss8ao4: %p , pST_BuffThread: %p\n",pSTDdev->taskName, pSTDdev, p16aiss8ao4, pST_BufThread );
#endif

	for(i = 0; i< MAX_RING_BUF_NUM; i++)
	{
		ST_buf_node *pbufferNode1 = NULL;
		pbufferNode1 = (ST_buf_node*) malloc(sizeof(ST_buf_node));
		if(!pbufferNode1) {
			epicsPrintf("\n>>> threadFunc_user_RingBuf: malloc(sizeof(ST_buf_node))... fail\n");
			return;
		}
		ellAdd(pSTDdev->pList_BufferNode, &pbufferNode1->node);
	}
	epicsPrintf(" %s: create %d node (size:%dKB)\n", pSTDdev->ST_RingBufThread.threadName, 
																		MAX_RING_BUF_NUM,
																		sizeof(ST_buf_node)/1024 );
#if 0
	epicsPrintf(">>> %s, ellCnt:%d\n", pringThreadConfig->threadName, 
												ellCount(p16aiss8ao4->pdrvBufferConfig->pbufferList));
#endif

#if USE_CPU_AFFINITY_RT	
	pthreadInfo = epicsThreadGetIdSelf();
/*	printf("%s: EPICS ID %p, pthreadID %lu\n", pthreadInfo->name, (void *)pthreadInfo, (unsigned long)pthreadInfo->tid); */
	epicsThreadSetCPUAffinity( pthreadInfo, AFFINITY_RTCORE_RING);
	epicsThreadSetPosixPriority(pthreadInfo, PRIOTY_RTCORE_RING, "SCHED_FIFO");
#endif

	
	while(TRUE) 
	{
		epicsMessageQueueReceive(pSTDdev->ST_RingBufThread.threadQueueId, (void*) &queueData, sizeof(ST_User_Buf_node));

		pbufferNode = queueData.pNode;


/*		fwrite( pbufferNode->data,  sizeof(unsigned int), LOOP_CNT*LOOP_ELM, pRTcore->fp_raw); */
		
		
		ellAdd(pSTDdev->pList_BufferNode, &pbufferNode->node);
		ellCnt = ellCount(pSTDdev->pList_BufferNode);
/*		printf("RTcore_RingBuf, ellCnt: %d\n", ellCnt); */


	} /* while(TRUE)  */

	return;
}
void* module_data_parser_thread(void* arg){
    int is_autocal_data, reg_data,i,j,k,code_depth,err;
    unsigned short *local_buffer_ptr,*temp_us_ptr,*conv,*process_buf_ptr,*netbuffer,frame_header[HEADER_LENGHT];
    unsigned short packet_tag,slot_id=0;
    unsigned char th_dac=0,loop_mode=0;
    unsigned short this_frame_has_aligment_errors;
    SOCKET data_socket;
    struct sockaddr_in sock_addr;
    int status;

    local_buffer_ptr=databuffer_allocation(PIXIEII_MODULES*MATRIX_DIM_WORDS*15);//la dimensione in byte di un intero frame
    if(local_buffer_ptr==NULL){
        printf("PROC:error allocating buffers\n");
        exit(-1);}
    else{
        if(verbose>=2)printf("PROC:Processing Thread Started\n");
    }
    /***TCP/IP monitor***************inizio********************dacounting_daq.cpp********************/
    sock_addr.sin_family=AF_INET; // indico il protocollo utilizzato (TCP/IP)
    sock_addr.sin_port=htons(4444); //indico la porta a cui connettere il socket
    if (hostToIPAddr("127.0.0.1", &sock_addr.sin_addr) < 0)
        printf("PROC:hostToIPAddr failed\n");
    // The following is not supported on Linux.  Is it needed?
    //sock_addr.sin_addr.S_un.S_un_b.s_b1=127; // indico l'indirizzo IP
    //sock_addr.sin_addr.S_un.S_un_b.s_b2=0;
    //sock_addr.sin_addr.S_un.S_un_b.s_b3=0;
    //sock_addr.sin_addr.S_un.S_un_b.s_b4=1;
    netbuffer=databuffer_allocation((MATRIX_DIM_WORDS*PIXIEII_MODULES)+HEADER_LENGHT);

    /*****TCP/IP monitor****************fine********************dacounting_daq.cpp********************/
    printf("PROC:data Parser Thread started\n");
    conv=conversion_table_allocation();

    while(1){
        status = epicsMessageQueueReceive(ptr_list, &process_buf_ptr, sizeof(&process_buf_ptr));
printf("module_data_parser_thread: got process_buf_ptr=%p\n", process_buf_ptr);
        if (status <= 0){
            printf("PROC: error epicsMessageQueueReceive returned %d\n", status);
            continue;
        }
        if (process_buf_ptr==NULL){
            printf("PROC: error process_buf_ptr=NULL\n");
            continue;
        }
        packet_tag=*(process_buf_ptr+PACKET_TAG_OFFSET*2);
        th_dac=(packet_tag>>(PIXIE_THDAC_OFFSET+DUMMY_0_OFFSET))&PIXIE_THDAC_MASK;
        loop_mode=(packet_tag>>(LOOP_MODE_OFFSET+DUMMY_1_OFFSET))&LOOP_MODE_MASK;
        if(verbose>=2)printf("\nPROC: packet_tag=%04xh\n",packet_tag);
        if(verbose>=2)printf("\nPROC: th_dac=%d, loop_mode=%02Xh\n",th_dac,loop_mode);
        slot_id=*((char*)process_buf_ptr+SLOT_ID_OFFSET)&SLOT_ID_MASK;
        if(verbose>=2)printf("PROC: slot_id=%04xh\n",slot_id);
        if(packet_tag & AUTOCAL_DATA){
            if(verbose>=2)printf("\nPROC:Autocal");
            code_depth=5;
            is_autocal_data=1;
        } else{
            if(verbose>=2)printf("\nPROC:Counters");
            code_depth=15;
            is_autocal_data=0;
        }
        if(packet_tag & REG_PACKET){
            if(verbose>=2)printf("\nPROC:REG 1 data\n");
            reg_data=1;
        } else{
            if(verbose>=2)printf("\nPROC:REG 0 data\n");
            reg_data=0;
        }
        if(packet_tag & FRAME_HAS_ALIGN_ERRORS){
            this_frame_has_aligment_errors=1;
        } else{
            this_frame_has_aligment_errors=0;
        }

        temp_us_ptr=process_buf_ptr+(PACKET_TAG_BYTES/2);
        if(verbose>=3)printf("local_buffer filling code_depth=%d\n",code_depth);
        for(i=0;i<PIXIEII_MODULES;i++) {
            for(j=0;j<COLS_PER_DOUT*PIXIE_ROWS;j++) {
                for(k=0;k<code_depth;k++){
                    my_bytes_swap(temp_us_ptr+i+(j*PIXIEII_MODULES*code_depth)+(k*PIXIEII_MODULES));
                    local_buffer_ptr[(i*COLS_PER_DOUT*PIXIE_ROWS*code_depth)+(j*code_depth)+k]=
                        temp_us_ptr[i+(j*PIXIEII_MODULES*code_depth)+(k*PIXIEII_MODULES)];
                }
            }
        }
        //printf("local_buffer has been filled with original data and data modules are grouped\n");
        //memcpy(buff+PACKET_TAG_BYTES,process_buf_ptr+PACKET_TAG_BYTES,PIXIEII_MODULES*MATRIX_DIM_WORDS*code_depth);
        for(i=0;i<PIXIEII_MODULES;i++){
            //printf("parsing %d module data\n",i);
            for(j=0;j<COLS_PER_DOUT*PIXIE_ROWS;j++) {
                convert_bit_stream_to_counts(code_depth,
                    local_buffer_ptr+(i*COLS_PER_DOUT*PIXIE_ROWS*code_depth)+(j*code_depth),
                    process_buf_ptr+(i*MATRIX_DIM_WORDS)+(j*PIXIE_DOUTS)+(PACKET_TAG_BYTES/2),PIXIE_DOUTS);

            }
        }
        //printf("data parsed\n");
        for(i=0;i<PIXIEII_MODULES;i++){
            //printf("processing module %d data\n,i);
            if(is_autocal_data==0 && convert_data==1)
                decode_pixie_data_buffer(conv,process_buf_ptr+(PACKET_TAG_BYTES/2)+i*MATRIX_DIM_WORDS);
            databuffer_sorting(process_buf_ptr+(PACKET_TAG_BYTES/2)+i*MATRIX_DIM_WORDS);
            map_data_buffer_on_pixie(process_buf_ptr+(PACKET_TAG_BYTES/2)+i*MATRIX_DIM_WORDS);
        }

        /*********************sendig data to TCPIP monitor*********************/
        for(i=0;i<HEADER_LENGHT;i++) frame_header[i]=0x8000;
        frame_header[0]=BUFFER_HDR_TAG;
        frame_header[1]|=(unsigned short)(this_frame_has_aligment_errors);
        frame_header[2]|=(unsigned short)(is_autocal_data);
        frame_header[3]|=(sh_code & 0x1);
        frame_header[4]|=(unsigned short)ceil((double)shutter_duration_ms);
        frame_header[5]|=(unsigned short)slot_id;
        if(reg_data==0)
            frame_header[6]|=REG_0_BUFF_CODE;
        else
            frame_header[6]|=REG_1_BUFF_CODE;
        for(i=0;i<HEADER_LENGHT;i++) netbuffer[i]=frame_header[i];
        for(i=0;i<MATRIX_DIM_WORDS*PIXIEII_MODULES;i++) netbuffer[i+HEADER_LENGHT]=process_buf_ptr[i+(PACKET_TAG_BYTES/2)];
        data_socket=epicsSocketCreate(PF_INET,SOCK_STREAM,0);
        err=connect(data_socket,(struct sockaddr*)&sock_addr,sizeof(struct sockaddr));
        if(!err) {
            if (verbose>=1)printf("\r\nI got Pixie!!");
        } else
            if (verbose>=1)printf("\r\nGot error attempting to connect to pixie = %s",strerror(errno));
        if(!err) send(data_socket,(const char*)netbuffer,(MATRIX_DIM*PIXIEII_MODULES)+(HEADER_LENGHT*2),0);
        if(!err)epicsSocketDestroy(data_socket);
        /*********************sendig data to TCPIP monitor*********************/
        free(process_buf_ptr);
        if (verbose>=1)printf("PROC:pocessing buffer released\n");

    }
    free(local_buffer_ptr);//qui non ci arriverà mai!!!!
}