Example #1
0
static int _send_int(SerialPort *port, unsigned char* buf, int bsize)
{
	int i;
	unsigned long pretime;
	
	for (i = 0; i < bsize; i++)
	{
		if (port->TxTimeOut < 0) {
			while (QueueFull(port->xmit));
		} else {
			pretime = timer_NowTime();
			while (QueueFull(port->xmit) && (timer_NowTime() - pretime) < port->TxTimeOut); 
			
			if (QueueFull(port->xmit)) {
				if (UART_TIMEOUT_DEBUG)
					err_print((char*)"%s: COM%d transmit timeout.\n", __FUNCTION__, port->com + 1);
				if (!(port->ier & THREI)) io_outpb(port->IER, port->ier |= THREI);
				return i;
			}
		}
		
		io_DisableINT();
		{
			PushQueue(port->xmit, buf[i]);
			
			if (!(port->ier & THREI) && (i == (bsize - 1) || QueueFull(port->xmit)))
			{
				switch (port->control)
				{
					case NO_CONTROL:
					{
						io_outpb(port->IER, port->ier |= THREI);
					}
					break;
					
					case RTS_CTS:
					{
						if (port->cts == CTS_ON) {
							io_outpb(port->IER, port->ier |= THREI);
						}
					}
					break;
					
					case XON_XOFF:
					{
						if (port->xonxoff_rcvd != XOFF_RCVD) {
							io_outpb(port->IER, port->ier |= THREI);
						}
					}
					break;
					
					default: break;
				};
			}
		}
		io_RestoreINT();
	}
	
	return i;
}
int EnQueue(queue* Q,int e)
{
    if(Q!=NULL)
    {
        if(QueueFull(Q))
        {
            printf("\nQueue is Full\n");
            return -1;
        }
        else
        {
            *(Q->rear) = e;
            if(Q->rear == &(Q->data[QueueSize-1]))
            {
                Q->rear = &(Q->data[0]);
                Q->flag = 1;
            }
            else
            {
                Q->rear++;
            }
            return 0;
        }
    }
    else
    {
        printf("\nQueue is NULL\n");
        return -1;
    }
}
Example #3
0
void *CarArrive(void *vptr) 
{
    int  k,i, arrival, d;
    Car437 *newptr;

    for (k=0; k<timers; k++) 
	{ 
    	// synchronize a virtual time to wall clock with 1:1000
    	while (GetTime() < k*10) 
			usleep(1000); // approx granularity 1 msec
      
	  	vClk += 10; 
     	 
	  	// display the waiting line every 10 mins
      	if (k%60==0) 
	 	{
          	PrintVClk(vClk);
        	  printf("::waiting line %d %d %d %d\n",
					  QueueSize(&Q[0]),QueueSize(&Q[1]),QueueSize(&Q[2]),QueueSize(&Q[3]));
      	}

     	 // taking care of arrival every 10 seconds
    	  arrival = RandPoisson(mean);
    	  nArrv += arrival;
  	    for (i=0; i<arrival; i++) 
		{
       		d=rand()%4;  // from East, South, West, or North
          	if (QueueFull(&Q[d])==true) {nDetour++; continue;}
        		CarArriv(d);
      	}
    	for (i=0; i<4; i++) 
			Sem437V(&Barrier[i]); // let 4-way threads to go
    }
   return(NULL);
}
DWORD QueuePut (QUEUE_OBJECT *q, PVOID msg, DWORD msize, DWORD MaxWait)
{
    DWORD TotalWaitTime = 0;
    BOOL TimedOut = FALSE;

    WaitForSingleObject (q->qGuard, INFINITE);
    if (q->msgArray == NULL) return 1;  /* Queue has been destroyed */

    while (QueueFull (q) && !TimedOut)
    {
        ReleaseMutex (q->qGuard);
        WaitForSingleObject (q->qNf, CV_TIMEOUT);
        if (MaxWait != INFINITE)
        {
            TotalWaitTime += CV_TIMEOUT;
            TimedOut = (TotalWaitTime > MaxWait);
        }
        WaitForSingleObject (q->qGuard, INFINITE);
    }
    /* Put the message in the queue */
    if (!TimedOut) QueueInsert (q, msg, msize);
    /* Signal that the queue is not empty as we've inserted a message */
    PulseEvent (q->qNe);
    ReleaseMutex (q->qGuard);

    return TimedOut ? WAIT_TIMEOUT : 0;
}
 virtual void push(const IEvent::Ptr& e) throw(QueueFull) {
     boost::unique_lock<boost::mutex> lock(_mtx);
    
     if (size() >= _maxQueueSize) {
         throw QueueFull();
     } else {
         _list.push_back(e);
         _notEmptyCond.notify_one();
     }
 }
Example #6
0
static int Enqueue(struct Queue *q, const uint8_t *data, uint16_t len)
{
	int i;
	for (i = 0; !QueueFull(q) && (i < len); i++)
	{
		q->q[q->pWR] = data[i];
		q->pWR = ((q->pWR + 1) ==  QUEUE_SIZE) ? 0 : q->pWR + 1;
	}
	return i;
}
Example #7
0
DWORD QueueInsert (QUEUE_OBJECT *q, PVOID msg, DWORD msize)
{
    char *pm;

    if (QueueFull(q)) return 1; /* Error - Q is full */
    pm = q->msgArray;
    /* Add a new youngest ("last") message */
    memcpy (pm + (q->qLast * msize), msg, msize);
    q->qLast = ((q->qLast + 1) % q->qSize);
    return 0;
}
Example #8
0
/*********************************************************************
* Enter Queue (Circle Mode)
**********************************************************************/
int QueueEnterC(SqQueue *sq, int qdata)
{
	   if(QueueFull(sq, 1))
	   {
         printf("The queue is full!\n");
         return -1;
	   }
	   
	   sq->rear = (sq->rear + 1) % QUEUE_SIZE;
     sq->queue[sq->rear] = qdata;
     sq->qcount ++;    
     
     return 0;
}
Example #9
0
DMPAPI(bool) PushBufQueue(Queue *queue, void *buf)
{
	bool ret = false;
	
	io_DisableINT();
	if (QueueFull(queue) == false) {
		memcpy((unsigned char *)queue->data + queue->tail*queue->dsize, buf, queue->dsize);
		queue->tail = (queue->tail + 1) % queue->size;
		ret = true;
	}
	io_RestoreINT();
	
	return ret;
}
Example #10
0
DWORD QueuePut (QUEUE_OBJECT *q, PVOID msg, DWORD mSize, DWORD maxWait)
{
    WaitForSingleObject (q->qGuard, INFINITE);
    if (q->msgArray == NULL) return 1;  /* Queue has been destroyed */
    while (QueueFull (q))
    {
        SignalObjectAndWait (q->qGuard, q->qNf, INFINITE, FALSE);
        WaitForSingleObject (q->qGuard, INFINITE);
    }
    /* Put the message in the queue */
    QueueInsert (q, msg, mSize);
    /* Signal that the queue is not empty as we've inserted a message */
    PulseEvent (q->qNe);
    ReleaseMutex (q->qGuard);

    return 0;
}
Example #11
0
DWORD QueuePut (QUEUE_OBJECT *q, PVOID msg, DWORD msize, DWORD MaxWait)
{
    AcquireSRWLockExclusive (&q->qGuard);
    if (q->msgArray == NULL) return 1;  /* Queue has been destroyed */

    while (QueueFull (q))
    {
        if (!SleepConditionVariableSRW(&q->qNf, &q->qGuard, INFINITE, 0))
            ReportError(_T("QueuePut failed. SleepConditionVariableCS."), 1, TRUE);
    }
    /* Put the message in the queue */
    QueueInsert (q, msg, msize);
    /* Signal that the queue is not empty as we've inserted a message */
    WakeConditionVariable (&q->qNe);
    ReleaseSRWLockExclusive (&q->qGuard);
    return 0;
}
Example #12
0
/*********************************************************************
* Delete Queue (Line Mode)
**********************************************************************/
int QueueEnterL(SqQueue *sq, int qdata)
{
	   if(QueueFull(sq, 0))
	   {
         	printf("The queue is full!\n");
         	return -1;
	   }
	   
	   if(sq->qcount >= 1)
	   {
         memmove((sq->queue + 1), sq->queue, sq->qcount*sizeof(int));
     }
     sq->queue[sq->rear] = qdata;
     if( sq->qcount < QUEUE_SIZE)         // overflow limit
     {
         sq->qcount++;     	
     }
     return 0;
}
Example #13
0
void SerialRxISR2(void)
{
  unsigned char rxval;               /* value to receive */
    
  serialErrors2 = RCSTA2;            /* read in and save error bits only */
    
  rxval = RCREG2;                    /* read in the Receive Buffer Register */
  
  if (OERR2) {                       /* if an overrun error occurred, reset */
    CREN2 = 0; CREN2 = 1;            /* receiver; framing error cleared by */
  }                                  /* reading RCREGx */
  
  if (QueueFull(&serialRxQueue2)) {   /* if RX Queue is full, */
    serialErrors2 |= SERIAL_RX_BUF_OE;/* log an Rx Buffer Overflow error */
  
  } else {                           /* if RX Queue isn't full, it is */
    Enqueue(&serialRxQueue2, rxval); /* enqueued with the received byte */
  }
}
Example #14
0
DWORD QueuePut (QUEUE_OBJECT *q, PVOID msg, DWORD mSize, DWORD maxWait)
{
	if (q->msgArray == NULL) return 1;  /* Queue has been destroyed */
	WaitForSingleObject (q->qGuard, INFINITE);

	while (!ShutDownPut && QueueFull (q)) {
		if (SignalObjectAndWait(q->qGuard, q->qNf, INFINITE, TRUE) == WAIT_IO_COMPLETION 
			&& ShutDownPut) {
			continue;
		}
		WaitForSingleObject (q->qGuard, INFINITE);
	}
	/* Put the message in the queue */
	if (!ShutDownPut) {
		QueueInsert (q, msg, mSize);	
		/* Signal that the queue is not empty as we've inserted a message */
		SetEvent (q->qNe);
		ReleaseMutex (q->qGuard);
	}
	return ShutDownPut ? WAIT_TIMEOUT : 0;
}
Example #15
0
unsigned char SerialOutRdy2(void)
{
  return (!QueueFull(&serialTxQueue2)); /* there's a byte in non-empty queue */
}