示例#1
0
/****************************************************************************
* DESCRIPTION: Adds an array of elements of data to the FIFO
* RETURN:      true on succesful add, false if not added
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
u8 FIFO_PutAr(fifo_buffer * b,u8 * data, u16 len)
{
    u8 status = false;        /* return value */
	u16 cpsr;
	u16 delta = 0;
    if (b) {
        /* limit the ring to prevent overwriting */
        if (!FIFO_Full(b)) 
		  {
		    //cpsr = __disable_irq();	   //deb
			if( len > (b->buffer_len - b->head) )
			  {
			    delta = (b->buffer_len - b->head);
				memcpy((char *)&(b->buffer[b->head]), (char *)data,delta);
			   	len -= delta;
			    cpsr = __disable_irq();
				b->head = 0;
			    if(!cpsr)
	     		    __enable_irq();
			  }
			memcpy((char *)&(b->buffer[b->head % b->buffer_len]),&data[delta],len);
		    cpsr = __disable_irq();
			b->head += len;
		    if(b->head == b->buffer_len)
		        b->head = 0;
		    if(!cpsr)
     		    __enable_irq();
            status = true;
			//if(!cpsr)			 //deb
     		//    __enable_irq();
          }
    }

    return status;
}
示例#2
0
//=============================================================================
// UART Transmit Function
//=============================================================================
void UARTA0_Send(char data)
{
	// Put straight to UART if not yet transmitting
	if (!UARTA0_transmitting)
	{
		UCA0TXBUF = data;
		UARTA0_transmitting = 1;
		IE2 |= UCA0TXIE;
	  // Load data into TX buffer
	} else {
		// Make sure the buffer isn't full. Loop continuously if it is.
    while(FIFO_Full(&UARTA0_tx_buffer));
    FIFO_Put(&UARTA0_tx_buffer, data);
	}
}
示例#3
0
/****************************************************************************
* DESCRIPTION: Adds an element of data to the FIFO
* RETURN:      true on succesful add, false if not added
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
u8 FIFO_Put(fifo_buffer * b,u8 data_byte)
{
    u8 status = false;        /* return value */
	u16 cpsr;
    if (b) {
        /* limit the ring to prevent overwriting */
        if (!FIFO_Full(b)) {
            b->buffer[b->head % b->buffer_len] = data_byte;
		    cpsr = __disable_irq();
            b->head++;
		    if(b->head == b->buffer_len)
		        b->head = 0;
		    if(!cpsr)
     		    __enable_irq();
            status = true;
        }
    }

    return status;
}					 
示例#4
0
/****************************************************************************
* DESCRIPTION: move head of buffer without copying real info(for DMA)
* RETURN:      true on succesful add, false if not added
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
u8 FIFO_MovePtr(fifo_buffer * b, u16 len)
{
    u8 status = false;        /* return value */
	u16 delta = 0;
    if (b)
	 {
        /* limit the ring to prevent overwriting */
        if (!FIFO_Full(b)) 
		  {
			if( len > (b->buffer_len - b->head) )
			  {
			    delta = (b->buffer_len - b->head);
			   	len -= delta;
				b->head = 0;
			  }
			b->head += len;
		    if(b->head == b->buffer_len)
		        b->head = 0;
            status = true;
          }
      }
    return status;
}