Exemplo n.º 1
0
void Cqtestbench(void)	// queue Test bench
{
unsigned char data;
unsigned char status;

	QueueInit();	// initialize queue
	
status=	PushQueue(1);	// Push something into the queue
status=	PushQueue(2);
status=	PushQueue(3);
	
	if(PushQueue(4)==QFULL)
	{
		_printf( "Queue Overflowed \n");
		return;
	}


	while (QueueStatus())		// some news?
	{
	status=PullQueue(&data); 	// if yes then get data from queue
		_printf( "Data pulled: %d , Remaining: %d   \n",data,QueueStatus());
	}

}
Exemplo n.º 2
0
// 二叉树的镜像非递归 
void MirrorBinTreeNor(pBTNode pRoot)
{
	LQueue q;
	InitQueue(&q);
	PushQueue(&q, pRoot);
	while (!QueueEmpyt(&q)) {
		pBTNode pCur = QueueFront(&q);
		PopQueue(&q);
		if (pCur->_pLeft)
			PushQueue(&q, pCur->_pLeft);
		if (pCur->_pRight)
			PushQueue(&q, pCur->_pRight);
		swap(&pCur->_pLeft, &pCur->_pRight);
	}
}
Exemplo n.º 3
0
// 层序遍历 
void LevelOrder(pBTNode pRoot)
{
	LQueue q;
	InitQueue(&q);
	PushQueue(&q, pRoot);
	while (!QueueEmpyt(&q)) {
		pBTNode pCur = QueueFront(&q);
		PopQueue(&q);
		printf("%c ", pCur->_data);
		if(pCur->_pLeft)
			PushQueue(&q, pCur->_pLeft);
		if (pCur->_pRight)
			PushQueue(&q, pCur->_pRight);
	}
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
/* USART6 IRQ handler. */
void USART6_IRQHandler(void) {
	uint8_t i;
	uint8_t rxdata;
	BaseType_t xHigherPriTaskWoken;

	xHigherPriTaskWoken = pdFALSE;

	/* USART6 RX interrupt. */
	if(USART6->SR & USART_SR_RXNE) {
		/* Push data into RX Queue. */
		rxdata = USART_ReadByte(USART6);
#ifdef MIRROR_USART6
		USART_SendByte(USART2, rxdata);
#endif
		if(rxPipeState > 0) {
			if(PushQueue(rxQueue, &rxdata)) {
				GPIO_SetBits(LEDS_GPIO_PORT, RED);
				GPIO_ResetBits(LEDS_GPIO_PORT, BLUE);
			}
			else {
				GPIO_SetBits(LEDS_GPIO_PORT, BLUE);
				GPIO_ResetBits(LEDS_GPIO_PORT, RED);
			}
		}
	}

	/* USART6 TX interrupt. */
	if(USART6->SR & USART_SR_TXE) {
		if(usart_stream[usart_stream_idx].BufLen > 0) {
			USART_SendByte(USART6, *usart_stream[usart_stream_idx].pBuf);
			usart_stream[usart_stream_idx].pBuf++;
			usart_stream[usart_stream_idx].BufLen--;
		}
		else {
			/* Current USART streaming is finished. */
			/* Release and clear current USART stream. */
			ClearStream(usart_stream + usart_stream_idx);
			/* Try to stream next USART stream which should be stream. */
			usart_stream_idx++;
			for(i=0; i<MAX_USART_STREAM; i++) {
				usart_stream_idx = (usart_stream_idx + i) % MAX_USART_STREAM;
				if(usart_stream[usart_stream_idx].pBuf != NULL)
					break;
			}
			/* Disable USART6 TX interrupt after all streams are finished. */
			if(i >= MAX_USART_STREAM)
				USART_ITConfig(USART6, USART_IT_TXE, DISABLE);
		}
	}
}
Exemplo n.º 6
0
int main(void)
{
	PQ q = CreateQueue(10);

	PushQueue(q, GetRand());
	PushQueue(q, GetRand());
	PushQueue(q, GetRand());
	PushQueue(q, GetRand());

	PrintQueue(q);


	int i = 0;
	for( ; i < 10; ++i)
	{
		PushQueue(q, GetRand());
		PopQueue(q);
		PrintQueue(q);
	}

	ReleaseQueue(q);
	
	return 0;
}
Exemplo n.º 7
0
void OnOffVisualization::update() {
  double value = input_->getInput();

  double sum = 0.0;
  for (int i = 0; i < smoothing_length_; i++) {
    sum += smoothing_[i];
  }
  sum += value;
  value = sum / (double)(smoothing_length_ + 1);

  PushQueue(smoothing_, smoothing_length_, value);

  CRGB color = CRGB::Blue;
  color.fadeToBlackBy(255 - (255 * value));
  viz_[0] = color;
}
Exemplo n.º 8
0
DMP_INLINE(void) EP2_OutHandler(USB_Device *usb)
{
	int i;
	WORD size;
	
#ifdef DMP_86DUINO_MODE
	RX_LED_ON();
#endif	
	size = (WORD)(io_inpdw(usb->EP[2].OutDLR) & 0x00001FFFFL);
	#if defined DMP_DOS_DJGPP
	dosmemget(usb->EP[2].OutPhysical, EP2_MAX_PACKET_SIZE_OUT, usb->EP[2].OutBuf);
	#endif
	for (i = 0; i < size; i++) PushQueue(usb->rcvd, usb->EP[2].OutBuf[i]);
	
	if (usb->rcvd->count < (usb->rcvd->size - NEAR_FULL_SIZE))
	SetEPnDLR(usb, EP2, OUT, ENABLE | EP2_MAX_PACKET_SIZE_OUT);
}
/*==============================================================
Name:	PhaseMapScan
Desc:  执行改进的线扫描算法
Param:
Return: NULL
Note:
  --------------------------------------------------------------*/
void CVQualityMapGuidedUn::ScanPhaseMap(double * bitmap, int * labelmap, int width, int height,CPoint startpoint,
                                        CPoint CurrentPoint,Queue *queue, double * absolutephasemap,int index)
{
    CPoint NeighborPoint;
    bool b_nearNeighborUnwrap = FALSE; // 判断面向起点的邻近点相位是否展开
    bool b_Neighbor = FALSE; // 判断周围邻近点是否为作用点,如果都是非,则丢弃该点
    // 至少有一个面向起点的邻点被展开,扫描点将被展开,然后标记为展开
    for(int i = 0; i < 8; i++)
    {
        NeighborPoint.x = CurrentPoint.x + NeighborDirection[i][0];
        NeighborPoint.y = CurrentPoint.y + NeighborDirection[i][1];
        {
            if((abs(NeighborPoint.x - startpoint.x) <= abs(CurrentPoint.x - startpoint.x))&&(abs(NeighborPoint.y - startpoint.y) <= abs(CurrentPoint.y - startpoint.y))
                    &&(labelmap[NeighborPoint.x + NeighborPoint.y * width] == UNWRAP))
            {
                labelmap[CurrentPoint.x + CurrentPoint.y * width] = UNWRAP;
                absolutephasemap[CurrentPoint.x + CurrentPoint.y * width] = this->LineScan(bitmap[CurrentPoint.x + CurrentPoint.y * width],
                        bitmap[NeighborPoint.x + NeighborPoint.y * width],absolutephasemap[NeighborPoint.x + NeighborPoint.y * width], CurrentPoint, NeighborPoint) ;
                b_nearNeighborUnwrap = TRUE;
                break;
            }
            //	b_Neighbor = TRUE;
        }
    }
    bool b_farNeighbor = false;
    //该点面向起点的邻点都未展开,但至少有一个有效的邻点面向边界,该点将被放入堆栈
    if((!b_nearNeighborUnwrap))//&&(labelmap[CurrentPoint.x + CurrentPoint.y*width] == LEVEL3))
    {
        for(int i = 0; i < 8; i++)
        {
            NeighborPoint.x = CurrentPoint.x + NeighborDirection[i][0];
            NeighborPoint.y = CurrentPoint.y + NeighborDirection[i][1];

            if((abs(NeighborPoint.x - startpoint.x) > abs(CurrentPoint.x - startpoint.x))||(abs(NeighborPoint.y - startpoint.y) > abs(CurrentPoint.y - startpoint.y)))
            {
                PushQueue(queue,CurrentPoint.x + CurrentPoint.y*width);
                b_farNeighbor = true;
                break;
            }
        }
    }
    if(b_farNeighbor)
        labelmap[CurrentPoint.x + CurrentPoint.y*width] = index +1;

}
Exemplo n.º 10
0
DMPAPI(int) usb_Send(void *vusb, BYTE *buf, int bsize)
{
	int i;
	DWORD pretime;
	USB_Device *usb = (USB_Device *)vusb;
	
	if (usb == NULL) { err_print((char*)"%s: USB device is null.\n", __FUNCTION__); return 0; }
	// if (usb->state != USB_DEV_CONFIGURED)
	// {
		// err_print((char*)"%s: USB device is not ready.\n", __FUNCTION__);
		// return 0;
	// }
	
	for (i = 0; i < bsize; i++)
	{
		if (usb->TimeOut != USB_NO_TIMEOUT) {
			pretime = timer_nowtime();
			while (usb->xmit->count >= usb->xmit->size && (timer_nowtime() - pretime) < usb->TimeOut); 
			
			if (usb->xmit->count >= usb->xmit->size) {
				if (USB_TIMEOUT_DEBUG)
					err_print((char*)"%s: USB device transmit timeout.\n", __FUNCTION__);
				EP2_InHandler(usb);
				return i;
			}
		}
		else while (usb->xmit->count >= usb->xmit->size);
		
		io_DisableINT();
		{
			PushQueue(usb->xmit, buf[i]);
			
			if ((i == (bsize - 1) || usb->xmit->count >= usb->xmit->size) && usb->state == USB_DEV_CDC_CONNECT)
			{
				EP2_InHandler(usb);
			}
		}
		io_RestoreINT();
	}
	
	return i;
}
Exemplo n.º 11
0
void McuMessageHandler::SendBody(StruMcuPacket *packet, unsigned short id)
{
    if((m_handshake == false) && (id != MCU_PACKET_HANDSHAKE))
    {
        LogUtility::Log(LOG_LEVEL_WARN, "McuMessageHandler::SendBody not handshake yet");
        DestroyPacket(packet);
        return;
    }
    
    McuPacket &content = packet->packet;
    if(content.size() > MCU_MAX_CONTENT_SIZE)
    {
        LogUtility::Log(LOG_LEVEL_DEBUG, "McuMessageHandler::SendBody too large");
        DestroyPacket(packet);
        return;
    }
    PacketHead(packet, (unsigned short)id);
    PacketCheckSumFlag(packet);
    PushQueue(packet);
}
Exemplo n.º 12
0
static int CAN_ISR(int irq, void *data)
{
	unsigned long isr;
	CAN_Bus *can = (CAN_Bus *)data;
	
	if (((isr = io_In32(can->handle, can->ISR)) & 0x07FFL) != 0x00L)
	{
		if (isr & CAN_RXI)
		{
			io_DisableINT();
			{
				can->rx_temp.type  = (unsigned char)io_In32(can->handle, can->RX.TYPE);
				can->rx_temp.id    = io_In32(can->handle, can->RX.IDR);
				can->rx_temp.hdata = io_In32(can->handle, can->RX.DATAH);
				can->rx_temp.ldata = io_In32(can->handle, can->RX.DATAL);
				PushBufQueue(can->rcvd, (void*)&can->rx_temp);
			}
			io_RestoreINT();
			
			io_Out32(can->handle, can->REQ, 0x0100L); // release the received message
			io_Out32(can->handle, can->ISR, CAN_RXI);
		}
		
		if (isr & CAN_TX0I)
		{
			unsigned long stat;
			
			stat = io_In32(can->handle, can->TX[0].STAT);
			if (stat & 0x20L)
			{
				can->TX[0].Err_CNT++;
				can->error = CAN_ERROR_TX0 + (unsigned char)((stat & 0x00070000L) >> 16);
				if (can->ErrStoreEnable == true)
					PushQueue(can->err, can->error);
				if (can->error_handler != NULL) can->error_handler(can);
			}
			if ((stat & 0x07L) == 0x05L) can_RoundRobin(can);
			
			io_Out32(can->handle, can->ISR, CAN_TX0I);
		}
Exemplo n.º 13
0
static int CAN_ISR(int irq, void *data)
{
	unsigned long isr;
	CAN_Bus *can = (CAN_Bus *)data;
	
	if (((isr = io_In32(can->ioHandle, can->ISR)) & 0x07FFL) != 0x00L)
	{
		if (isr & CAN_RXI)
		{
			unsigned long temp;
			CANFrame rx_temp;
			
			io_DisableINT();
			{
				temp = io_In32(can->ioHandle, can->RX.TYPE);
				rx_temp.type          = (int)(temp & 0x03UL);
				rx_temp.length        = (int)((temp >> 4) & 0x0FUL);
				rx_temp.identifier    = io_In32(can->ioHandle, can->RX.IDR);
				rx_temp.Data.dword[0] = io_In32(can->ioHandle, can->RX.DATAL);
				rx_temp.Data.dword[1] = io_In32(can->ioHandle, can->RX.DATAH);
				PushBufQueue(can->rcvd, (void*)&rx_temp);
			}
			io_RestoreINT();
			
			io_Out32(can->ioHandle, can->REQ, 0x0100UL); // release the received message
			io_Out32(can->ioHandle, can->ISR, CAN_RXI);
		}
		
		if (isr & CAN_TX0I)
		{
			unsigned long stat;
			
			stat = io_In32(can->ioHandle, can->TX[0].STAT);
			if (stat & 0x20UL)
			{
				can->LastError = CAN_ERROR_TX0 + (unsigned char)((stat & 0x00070000UL) >> 16);
				if (can->StoreError)
					PushQueue(can->Error, can->LastError);
			}
Exemplo n.º 14
0
void vSoundStreamProperties::Synchronize(const vRenderable *object)
{
    if(!object)
        return;

    const cSoundStream *stream = dynamic_cast<const cSoundStream*>(object);
    if(!stream)
        return;

    // Update properties
    SetVolume(stream->GetVolume());
    SetEnabled(stream->GetEnabled());
    SetLooping(stream->GetLooping());
    SetWantedState(stream->GetWantedState());
    SetFrequency(stream->GetFrequency());
    SetFormat(stream->GetFormat());
    
    // Rewrite chunks queue
    ClearQueue();
    for(std::list<FixedArray<char>*>::const_iterator it = stream->GetDataQueue().begin(); it != stream->GetDataQueue().end(); ++it)
    {
        PushQueue(*it);
    }
};
Exemplo n.º 15
0
void keypress_watcher(int scancode) {
	PushQueue(kbQueue, scancode); // In Arduino, it has 10ms scan-time.
} END_OF_FUNCTION(keypress_watcher)