Esempio n. 1
0
node *Get(void) {
	if (!IsQueueEmpty())
		return Queue[(front++) % tree];
	else
		printf("Queue is Empty!\n");
	return NULL;
}
Esempio n. 2
0
void LevelOrderTraverse(BinaryTree * binaryTree,void(*visit)()){
	if(binaryTree){
		
		NodeQueue * queue=NULL;
		queue=InitQueue();

		visit(binaryTree->data);
		if(binaryTree->lChild){
			EnQueue(queue,binaryTree->lChild);
		}

		if(binaryTree->rChild){
			EnQueue(queue,binaryTree->rChild);
		}

		while(IsQueueEmpty(queue)==1){
			Node * e=NULL;
			e=DeQueue(queue);
			visit(e->data);
			if(e->lChild){
				EnQueue(queue,e->lChild);
			}

			if(e->rChild){
				EnQueue(queue,e->rChild);
			}
		}

		DestroyQueue(queue);		
	}
}
Esempio n. 3
0
void AddToReadyQueue(ProcessControlBlock **head, ProcessControlBlock *pcb)
{
    ProcessControlBlock *tmp;
    ProcessControlBlock *prev;

    if (IsQueueEmpty(*head))
    {
        *head = pcb;
        (*head)->nextPCB = NULL;
        return;
    }

    if ( pcb->priority < (*head)->priority  )	{		// infront of queue
        pcb->nextPCB = *head;
        *head = pcb;
        return;
    }


    tmp = *head;
    while ( (tmp != NULL) && (tmp->priority <= pcb->priority) ) {
        prev = tmp;
        tmp = tmp->nextPCB;
    }
    prev->nextPCB = pcb;								// insert in the Middle & End
    pcb->nextPCB = tmp;

}
Esempio n. 4
0
CORE_PROC(int, RelayInput)( PDATAPATH pdp
												, PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) )
{
	extern int gbTrace;
	if( pdp->pPrior )
	{
		PTEXT p;
		int moved = 0;

		if( gbTrace )
			xlprintf(LOG_NOISE+1)( WIDE("Relay input from %s to %s..........")
										, GetText( pdp->pPrior->pName )
										, GetText( pdp->pName ) );
		do
		{
			if( pdp->pPrior->Read )
			{
				pdp->pPrior->Read( pdp->pPrior );
			}
			if( IsQueueEmpty( &pdp->pPrior->Input ) )
				break;
			//Log( WIDE("Has some input to handle...") );
			while( ( p = (PTEXT)DequeLink( &pdp->pPrior->Input ) ) )
			{
				if( gbTrace )
					lprintf( WIDE("Data is: %s"), GetText( p ) );
				if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) )
				{
					//lprintf( WIDE("Data callback...") );
					for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) )
					{
						moved++;
						if( p != (POINTER)1 )
							EnqueLink( &pdp->Input, p );
						else
							lprintf( WIDE("Data was consumed by datapath.") );
					}
				}
				else
				{
					 PTEXT out = BuildLine( p );
					 Log1( WIDE("Relay In: %s"), GetText( out ) );
					 LineRelease( out );
					moved++;
					EnqueLink( &pdp->Input, p );
				}
			}
			if( gbTrace && !moved && !pdp->pPrior->flags.Closed )
			{
				lprintf( WIDE("Did not result in data, try reading source again, rerelay. %s %s"), GetText( pdp->pName ), GetText( pdp->pPrior->pName ) );
			}
		  } while( !moved &&
					 !pdp->pPrior->flags.Closed );
		// stop relaying closes at datasource points
		//if( !pdp->pPrior->flags.Data_Source )
		pdp->flags.Closed |= pdp->pPrior->flags.Closed;
		return moved;
	}
	return 0;
}
Esempio n. 5
0
void AddToTimerQueue(ProcessControlBlock **head, ProcessControlBlock *pcb)
{
    ProcessControlBlock *tmp;
    ProcessControlBlock *prev;

    if (IsQueueEmpty(*head))
    {
        *head = pcb;
        (*head)->nextPCB = NULL;
        return;
    }

    // add by increasing of time
    if ( (*head)->wakeup_time > pcb->wakeup_time) {     //in front
        pcb->nextPCB = *head;
        *head = pcb;
        return;
    }

    tmp = *head;
    while ( (tmp != NULL) && (tmp->wakeup_time <= pcb->wakeup_time)) {           // <= so prev always has value
        prev = tmp;
        tmp = tmp->nextPCB;
    }
    prev->nextPCB = pcb;								// insert in the Middle & End
    pcb->nextPCB = NULL;								// reset linker

    if (tmp != NULL) {									// insert in the Middle
        pcb->nextPCB = tmp;
        return;
    }

}
Esempio n. 6
0
File: write.c Progetto: ms-iot/bsp
/*++

Routine Description:

    This routine is used to determine if conditions are appropriate
    to satisfy a wait for transmit empty event, and if so to complete
    the request that is waiting for that event.  It also call the code
    that checks to see if we should lower the RTS line if we are
    doing transmit toggling.

    NOTE: This routine is called by WdfInterruptSynchronize.

    NOTE: This routine assumes that it is called with the cancel
          spinlock held.

Arguments:

    Context - Really a pointer to the device extension.

Return Value:

    This routine always returns FALSE.

--*/
_Use_decl_annotations_
BOOLEAN
SerialProcessEmptyTransmit(
    WDFINTERRUPT Interrupt,
    PVOID Context
    )
{
    PSERIAL_DEVICE_EXTENSION extension = Context;

    UNREFERENCED_PARAMETER(Interrupt);

    if (extension->IsrWaitMask && (extension->IsrWaitMask & SERIAL_EV_TXEMPTY) &&
        extension->EmptiedTransmit && (!extension->TransmitImmediate) &&
        (!extension->CurrentWriteRequest) && IsQueueEmpty(extension->WriteQueue)) {

        extension->HistoryMask |= SERIAL_EV_TXEMPTY;
        if (extension->IrpMaskLocation) {

            *extension->IrpMaskLocation = extension->HistoryMask;
            extension->IrpMaskLocation = NULL;
            extension->HistoryMask = 0;

            SerialGetRequestContext(extension->CurrentWaitRequest)->Information = sizeof(ULONG);

            SerialInsertQueueDpc(extension->CommWaitDpc);
        }

        extension->CountOfTryingToLowerRTS++;
        SerialPerhapsLowerRTS(extension->WdfInterrupt, extension);
    }

    return FALSE;
}
Esempio n. 7
0
void Enqueue(struct queue * queue, struct hash *thash, int pageno,
		char *contents, time_t expirystamp, char *etag,char *modifystampstr) {
	if (IsQueueFull(queue)) {

		thash->array[queue->rear->pageno] = NULL;
		Dequeue(queue);
	}

	struct queuenode *newnode = CreateNewQueueNode(pageno, contents,
			expirystamp, etag,modifystampstr);

	if (IsQueueEmpty(queue)) {
		queue->front = queue->rear = newnode;

	} else {
		newnode->next = queue->front;
		queue->front->prev = newnode;
		queue->front = newnode;
	}

	thash->array[pageno] = newnode;

	queue->count++;

}
Esempio n. 8
0
DWORD
DequeueEvent(
    ROUTING_PROTOCOL_EVENTS  *prpeEvent,
    MESSAGE                  *pmMessage)
{
    DWORD           dwErr   = NO_ERROR;
    PQUEUE_ENTRY    pqe     = NULL;
    PEVENT_ENTRY    pee     = NULL;

    ACQUIRE_QUEUE_LOCK(&(g_ce.lqEventQueue));

    do {
        if (IsQueueEmpty(&(g_ce.lqEventQueue.head))) {
            dwErr = ERROR_NO_MORE_ITEMS;
            TRACE0(CONFIGURATION, "No events in the queue.");
            break;
        }

        pqe = Dequeue(&(g_ce.lqEventQueue.head));
        pee = CONTAINING_RECORD(pqe, EVENT_ENTRY, qeEventQueueLink);
        *(prpeEvent) = pee->rpeEvent;
        *(pmMessage) = pee->mMessage;

        /* created in EE_EnqueueEvent */
        EE_Destroy(pee);
        pee = NULL;
    } while (FALSE);

    RELEASE_QUEUE_LOCK(&(g_ce.lqEventQueue));

    return dwErr;
}
Esempio n. 9
0
struct proc* DequeueProcess(struct processQueue* queue)
{
	if(!IsQueueEmpty(queue))
	{
		struct proc* p = queue->proc[queue->head];
		queue->head= (queue->head+1)%QUEUE_CAPACITY;
		queue->size=queue->size-1;
		return p;
		
	}
	return 0;
}
Esempio n. 10
0
struct PP_Var DequeueMessage()
{
    struct PP_Var message;
    pthread_mutex_lock(&g_queue_mutex);
    while ( IsQueueEmpty() != 0 )
        pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
    message = g_queue[g_queue_start];
    g_queue_start = (g_queue_start + 1) % MAX_QUEUE_SIZE;
    g_queue_size--;
    pthread_mutex_unlock(&g_queue_mutex);
    return(message);
}
void addNewNode(Queue* _queue,QNode* node){

    if ( IsQueueEmpty( _queue ) )// If queue is empty, change both head and last pointers
        _queue->last = _queue->head = node;
    else  // Else change the last
    {
        _queue->last->next = node;
        node->prev = _queue->last;
        _queue->last = node;
    }
    _queue->_size++;
}
Esempio n. 12
0
// End of Queue routines
// -------------------------------------------------------------------
void Scanner::nextTokenInternal()
{
    // check if a token has been pushed back into the token stream, if so use it first
    // I think I should get rid of this code, use queue methods instead
    if (previousToken.tokenCode != CodeTypes::tEmptyToken)
    {
        ftoken = previousToken.tokenCode;
        tokenString = previousToken.tokenString;
        tokenDouble = previousToken.tokenDouble;
        tokenInteger = previousToken.tokenInteger;
        previousToken.tokenCode = CodeTypes::tEmptyToken;
        return;
    }

    // Check if there is anything in the token queue, if so get the item
    // from the queue and exit. If not, read as normal from the stream.
    // Checking the queue before reading from the stream can be turned off and on
    // by setting the FromQueue Flag.
    if(FromQueue)
    {
        if(!IsQueueEmpty())
        {
            getTokenFromQueue();
            return;
        }
    }

    skipBlanks();
    tokenString = "";

    TCharCode::TCharCode code = FCharTable[fch];
    switch(code)
    {
        case TCharCode::cLETTER:
        case TCharCode::cUNDERSCORE:
            getWord();
            break;
        case TCharCode::cDIGIT:
            getNumber();
            break;
        case TCharCode::cDOUBLEQUOTE:
            getString();
            break;
        case TCharCode::cETX:
            ftoken = CodeTypes::tEndOfStreamToken;
            break;
        default:
            getSpecial();
            break;
    }
}
Esempio n. 13
0
void LevelOrderIterative( TreeNode *root )
{
	if( !root )
	{
		return;
	}

	Enqueue( root );
	Enqueue( NULL );

	while( !IsQueueEmpty() )
	{
		root = Dequeue();

		if( !root )
		{
			if( !IsQueueEmpty() )
			{
				Enqueue( NULL );
				continue;
			}
			else
			{
				break;
			}
		}

		root->next = Queue[ front ];

		if( root->left )
			Enqueue( root->left );

		if( root->right )
			Enqueue( root->right );
	}

}
Esempio n. 14
0
TreeNode* Dequeue()
{
	TreeNode *retVal = NULL;
	if( IsQueueEmpty() )
	{
		printf("\n Empty Queue. \n");
	}
	else
	{
		retVal = Queue[ front++ ];
		if( front > rear )
			front = rear = -1;
	}
	return retVal;
}
Esempio n. 15
0
ProcessControlBlock *DeQueue(ProcessControlBlock **head)
{
    ProcessControlBlock *tmp;

    if (IsQueueEmpty(*head))
    {
        return NULL;
    }

    tmp = *head;
    *head = (*head)->nextPCB;
    tmp->nextPCB = NULL;								// release next pointer, go to anothe queue

    return tmp;
}
Esempio n. 16
0
INT32 SizeQueue(ProcessControlBlock *head)
{
    int count = 0;
    if (IsQueueEmpty(head))
    {
        return 0;
    }
    else
    {
        while (head != NULL)
        {
            count++;
            head = head->nextPCB;
        }
    }
    return count;
}
Esempio n. 17
0
void PrintQueue(ProcessControlBlock *head)
{
    if (IsQueueEmpty(head))
    {
        return;
    }
    else
    {
        while (head != NULL)
        {
            printf("%d ",head->process_id);
            head = head->nextPCB;
        }
        printf(";\n");
    }

}
Esempio n. 18
0
/** Dequeue a message and return it.
 *
 * This function blocks until a message is available. It should not be called
 * on the main thread.
 *
 * NOTE: this function assumes g_queue_mutex is _NOT_ held.
 * @return The message at the head of the queue. */
char* DequeueMessage() {
  char* message = NULL;

  pthread_mutex_lock(&g_queue_mutex);

  while (IsQueueEmpty()) {
    pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
  }

  message = g_queue[g_queue_start];
  g_queue_start = (g_queue_start + 1) % MAX_QUEUE_SIZE;
  g_queue_size--;

  pthread_mutex_unlock(&g_queue_mutex);

  return message;
}
Esempio n. 19
0
/**
  Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
  and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.

  @param  Event        Event to be signaled when a key is pressed.
  @param  Context      Points to USB_KB_DEV instance.

**/
VOID
EFIAPI
USBKeyboardWaitForKey (
  IN  EFI_EVENT               Event,
  IN  VOID                    *Context
  )
{
  USB_KB_DEV  *UsbKeyboardDevice;
  EFI_KEY_DATA KeyData;
  EFI_TPL      OldTpl;

  UsbKeyboardDevice = (USB_KB_DEV *) Context;

  //
  // Enter critical section
  //  
  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
  
  //
  // WaitforKey doesn't suppor the partial key.
  // Considering if the partial keystroke is enabled, there maybe a partial
  // keystroke in the queue, so here skip the partial keystroke and get the
  // next key from the queue
  //
  while (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
    //
    // If there is pending key, signal the event.
    //
    CopyMem (
      &KeyData,
      UsbKeyboardDevice->EfiKeyQueue.Buffer[UsbKeyboardDevice->EfiKeyQueue.Head],
      sizeof (EFI_KEY_DATA)
      );
    if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {
      Dequeue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (EFI_KEY_DATA));
      continue;
    }
    gBS->SignalEvent (Event);
    break;
  }
  //
  // Leave critical section and return
  //
  gBS->RestoreTPL (OldTpl);
}
Esempio n. 20
0
void Level_Traverse(node *ptr) {
	InitializeQueue();	
	Put(ptr);

	while (!IsQueueEmpty()) {
		ptr = Get();
		Display(ptr);

		if (ptr->left != head)
			Put(ptr->left);

		if (ptr->mid != head)
			Put(ptr->mid);

		if (ptr->right != head)
			Put(ptr->right);
	}
}
Esempio n. 21
0
/**
  Internal function to read the next keystroke from the keyboard buffer.

  @param  UsbKeyboardDevice       USB keyboard's private structure.
  @param  KeyData                 A pointer to buffer to hold the keystroke
                                  data for the key that was pressed.

  @retval EFI_SUCCESS             The keystroke information was returned.
  @retval EFI_NOT_READY           There was no keystroke data availiable.
  @retval EFI_DEVICE_ERROR        The keystroke information was not returned due to
                                  hardware errors.
  @retval EFI_INVALID_PARAMETER   KeyData is NULL.
  @retval Others                  Fail to translate keycode into EFI_INPUT_KEY

**/
EFI_STATUS
USBKeyboardReadKeyStrokeWorker (
  IN OUT USB_KB_DEV                 *UsbKeyboardDevice,
     OUT EFI_KEY_DATA               *KeyData
  )
{
  if (KeyData == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  if (IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
    return EFI_NOT_READY;
  }

  Dequeue (&UsbKeyboardDevice->EfiKeyQueue, KeyData, sizeof (*KeyData));

  return EFI_SUCCESS;
}
Esempio n. 22
0
void Dequeue(struct queue *queue) {
	if (IsQueueEmpty(queue)) {
		return;
	}

	struct queuenode *temp = queue->rear;

	if (queue->front == queue->rear)
		queue->front = NULL;

	queue->rear = queue->rear->prev;
	if (queue->rear)
		queue->rear->next = NULL;

	free(temp);

	queue->count--;
}
plNetMessage* plNetClientStreamRecorder::IGetNextMessage()
{
    plNetMessage* msg = nil;

    if (!IsQueueEmpty() && GetNextMessageTimeDelta() <= 0 )
    {
        msg = plNetMessage::ConvertNoRef(GetResMgr()->ReadCreatableVersion(fRecordStream));
        // msg->SetPeeked(true);

        // Fix the flags on game messages, so we won't get an assert later
        plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
        if (gameMsg)
        {
            plMessage* plMsg = gameMsg->GetContainedMsg(GetResMgr());
            plNetClientApp::GetInstance()->UnInheritNetMsgFlags(plMsg);

            // write message (and label) to ram stream
            hsRAMStream stream;
            GetResMgr()->WriteCreatable(&stream, plMsg);

            // put stream in net msg wrapper
            gameMsg->StreamInfo()->CopyStream(&stream);
            // gameMsg->StreamInfo()->SetStreamType(plMsg->ClassIndex());       // type of game msg
        }

        double nextPlaybackTime = fRecordStream->ReadLEDouble();
        if (nextPlaybackTime < fNextPlaybackTime)
            fBetweenAges = true;

        fNextPlaybackTime = nextPlaybackTime;

        // If this was the last message, stop playing back
        if (fRecordStream->AtEnd())
        {
            fRecordStream->Close();
            delete fRecordStream;
            fRecordStream = nil;
        }
    }
    
    return msg;
}
Esempio n. 24
0
int main()
{
    Queue q;
    int nData = 0;
    int nLength = 0;
    BOOL bEmpty = FALSE;

    InitQueue(&q);
    EnQueue(&q, 12);
    EnQueue(&q, 3);
    EnQueue(&q, 8);
    EnQueue(&q, 34);
    EnQueue(&q, 6);
    EnQueue(&q, 9);
    EnQueue(&q, 56);
    EnQueue(&q, 78);
    EnQueue(&q, 4);
    EnQueue(&q, 90);
    printf("入队后的队列:");
    TraverseQueue(&q, OutputQueue);

    nLength = GetQueueLength(&q);
    printf("队列长度:%d\n", nLength);

    bEmpty = IsQueueEmpty(&q);
    printf("队列为%s\n", bEmpty ? "空" : "非空");

    DeQueue(&q, &nData);
    printf("出队数据:%d\n", nData);
    printf("出队后的队列:");
    TraverseQueue(&q, OutputQueue);

    DeQueue(&q, &nData);
    printf("出队数据:%d\n", nData);
    printf("出队后的队列:");
    TraverseQueue(&q, OutputQueue);

    DestroyQueue(&q);

    return 0;
}
Esempio n. 25
0
void AddToReadyQueueNotPriority(ProcessControlBlock **head, ProcessControlBlock *pcb)
{
    ProcessControlBlock *tmp;
    ProcessControlBlock *prev;

    if (IsQueueEmpty(*head))
    {
        *head = pcb;
        (*head)->nextPCB = NULL;
        return;
    }

    tmp = *head;
    while (tmp != NULL) {
        prev = tmp;
        tmp = tmp->nextPCB;
    }
    prev->nextPCB = pcb;								// insert in the Middle & End
    pcb->nextPCB = tmp;

}
Esempio n. 26
0
int main(){
  int value =0;
  QueType* queue;
  QueType* q1 = QueType* q2 = NULL;
  printf("enter value; %d\n", value);
  scanf("%d\n",&value);
  queue = CreateQueue();
  while(value <= 7){
    Enqueue(queue,value);
    value++;
    printf("\n Elements in the queue are:\n");
    printqueue(queue,value);
  }

  /* Print all the items */
  while(!IsQueueEmpty(queue)){
    Dequeue(queue,&value);
    printf("%d\n",value);
  }
  DestroyQueue(queue);
  return 0;
}
Esempio n. 27
0
ProcessControlBlock *DeQueueWithDiskId(ProcessControlBlock **head, INT32 disk_id)
{
    ProcessControlBlock *tmp = *head;
    ProcessControlBlock *prev = NULL;

    if (IsQueueEmpty(*head))
    {
        return NULL;
    }

    while (tmp != NULL) {
        if ( (tmp->disk_io.disk_id == disk_id) ) { // && (tmp->state != PROCESS_STATE_TERMINATE)
            //First one
            if (tmp == *head) {
                *head = tmp->nextPCB;
                tmp->nextPCB = NULL;
                return tmp;
            }
            // last one
            else if (tmp->nextPCB == NULL) {
                prev->nextPCB = NULL;
                return tmp;
            }
            else { // middile
                prev->nextPCB = tmp->nextPCB;
                tmp->nextPCB = NULL;
                return tmp;
            }

        }
        prev = tmp;
        tmp = tmp->nextPCB;
    }

    if ( (tmp == NULL)  &&(prev != NULL) )
        return NULL;
}
Esempio n. 28
0
int CQueue::DeQueue(void)
{
	if(!IsQueueEmpty())
	{
		switch(label)
		{
			case SEQ:
				{
					return p->arrayQueue[++p->front];
				}
			case CYCLE:
				{
					q->front=(q->front+1)%MAXLEN;
					q->queueLen--;
					return q->arrayQueue[q->front];
				}
			case CHAIN:
				{
					int x=r->front->data;
					queueNode *r_1;
					r_1=r->front;
					r->front=r->front->next;
					if(r->front==NULL)
						r->rear=NULL;
					delete r_1;
					return x;
				}
			default:
				{
					return 0;
					break;
				}
		}

	}	
	return 0;
}
Esempio n. 29
0
void main(void) 
{
  /* put your own code here */
  
  SET_TCNT_PRESCALE( TCNT_PRESCALE_8);
	TSCR1 = TSCR1_INIT;
  
	seg_init();
	CANinit(THE_FLOOR);
	SET_BITS(LED_DDR, LED1_MASK|LED2_MASK);

	node_id = PORTB & 3; //get hardware specified node id
	
	while (!(CANCTL0&0x10));

	CANRFLG = 0xC3;
	CANRIER = 0x01;

	InitializeQueue(&rec);	// Create the Recieve Queue
	
	
	
     clear_seg();

	EnableInterrupts;

  for(;;) 
  {

	if(IsQueueEmpty(rec) != 0)
	{		
		DeQueue(&rec);
		Parse_Floor();
	}
  
  // button 1 press
    if((PTJ & (SWITCH1_MASK |SWITCH2_MASK) )== SWITCH1_MASK) 
    {
        if(THE_FLOOR == F1 || THE_FLOOR == F2)
        {
            if (last != SWITCH1_MASK) 
            {   // check if button already pressed 

            	data[0] = THE_FLOOR;
            	data[1] = CALL_SWITCH1;
            	data[2] = UP;
            	
            	(void)CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
            	last =  SWITCH1_MASK;        
            }  
        }
        else if(THE_FLOOR == F3)
        {
            if (last != SWITCH1_MASK) 
            {   // check if button already pressed 

                data[0] = THE_FLOOR;
                data[1] = CALL_SWITCH1;
                data[2] = DOWN;

                (void)CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
                last =  SWITCH1_MASK;        
            }  
        }

    }                
  
  //button 2 press
    else if((PTJ & (SWITCH1_MASK |SWITCH2_MASK) )== SWITCH2_MASK)
    {
        if(THE_FLOOR == F2)
        {
            if (last != SWITCH2_MASK) 
            { // check if button already pressed    
                data[0] = THE_FLOOR;
                data[1] = CALL_SWITCH2;
                data[2] = DOWN;

                CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
                last =  SWITCH2_MASK;
            } 
        }
 
    }
  
  else
  last = 0;
  
  
  // Updates the LED
  FORCE_BITS(PTS,0b00001100 , led) ;


  

  } /* loop forever */
  /* please make sure that you never leave main */
}
Esempio n. 30
0
File: utils.c Progetto: MHesham/bsp
VOID
SerialStartOrQueue(
    IN PSERIAL_DEVICE_EXTENSION Extension,
    IN WDFREQUEST Request,
    IN WDFQUEUE QueueToExamine,
    IN WDFREQUEST *CurrentOpRequest,
    IN PSERIAL_START_ROUTINE Starter
    )

/*++

Routine Description:

    This routine is used to either start or queue any requst
    that can be queued in the driver.

Arguments:

    Extension - Points to the serial device extension.

    Request - The request to either queue or start.  In either
          case the request will be marked pending.

    QueueToExamine - The queue the request will be place on if there
                     is already an operation in progress.

    CurrentOpRequest - Pointer to a pointer to the request the is current
                   for the queue.  The pointer pointed to will be
                   set with to Request if what CurrentOpRequest points to
                   is NULL.

    Starter - The routine to call if the queue is empty.

Return Value:


--*/

{

    NTSTATUS status;
    PREQUEST_CONTEXT reqContext;
    WDF_REQUEST_PARAMETERS  params;

    reqContext = SerialGetRequestContext(Request);

    WDF_REQUEST_PARAMETERS_INIT(&params);

    WdfRequestGetParameters(
             Request,
             &params);

    //
    // If this is a write request then take the amount of characters
    // to write and add it to the count of characters to write.
    //

    if (params.Type == WdfRequestTypeWrite) {

        Extension->TotalCharsQueued += reqContext->Length;

    } else if ((params.Type == WdfRequestTypeDeviceControl) &&
               ((params.Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR) ||
                (params.Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER))) {

        reqContext->IoctlCode = params.Parameters.DeviceIoControl.IoControlCode; // We need this in the destroy callback

        Extension->TotalCharsQueued++;

    }

    if (IsQueueEmpty(QueueToExamine) &&  !(*CurrentOpRequest)) {

        //
        // There were no current operation.  Mark this one as
        // current and start it up.
        //

        *CurrentOpRequest = Request;

        Starter(Extension);

        return;

    } else {

        //
        // We don't know how long the request will be in the
        // queue.  If it gets cancelled while waiting in the queue, we will
        // be notified by EvtCanceledOnQueue callback so that we can readjust
        // the lenght or free the buffer.
        //
        reqContext->Extension = Extension; // We need this in the destroy callback

        status = WdfRequestForwardToIoQueue(Request,  QueueToExamine);
        if(!NT_SUCCESS(status)) {
            TraceEvents(TRACE_LEVEL_ERROR, DBG_READ, "WdfRequestForwardToIoQueue failed%X\n", status);
            ASSERTMSG("WdfRequestForwardToIoQueue failed ", FALSE);
            SerialCompleteRequest(Request, status, 0);
        }

        return;
    }
}