Exemplo n.º 1
0
extern "C" void USART3_IRQHandler(void) {
	uint8_t b;
	// Is it a RX interrupt?
	if (USART_GetITStatus(EVAL_COM1, USART_IT_RXNE) != RESET) {
		/* Read one byte from the receive data register */
		b = USART_ReceiveData(EVAL_COM1) & 0x7F;
		if (rx_buffer.push(b) == false) {
			// This is bad.
		}
		// If this is a command end, increment the rdy command count
		if (b == '$') {
			commands_count++;
		}
	}
	// Is it a TX interrupt?
	if (USART_GetITStatus(EVAL_COM1, USART_IT_TXE) != RESET) {

		// Pop an element from the tx queue
		uint8_t elem = 0;
		if (tx_buffer.pop(elem) == false) {
			// This is also bad
			return;
		}
		/* Write one byte to the transmit data register */
		USART_SendData(EVAL_COM1, elem);

		// If the tx queue is empty, turn TX interrupt off
		if (tx_buffer.is_empty()) {
			USART_ITConfig(EVAL_COM1, USART_IT_TXE, DISABLE);
		}
	}
}
Exemplo n.º 2
0
bool uart_recieve(uint8_t &elem) {
	// Nothing to recieve?
	if (rx_buffer.is_empty()) {
		return false;
	}

	// Pop the recieved element.
	return rx_buffer.pop(elem);
}
Exemplo n.º 3
0
bool uart_send(uint8_t elem) {
	// try to push the elem to the tx queue. will not work if its full
	bool pushed = tx_buffer.push(elem);
	// Turn on interrupt...
	USART_ITConfig(EVAL_COM1, USART_IT_TXE, ENABLE);
	return pushed;
}
int main(int argc, const char * argv[])
{
    
    CyclicBuffer<int>* testBuffer = new CyclicBuffer<int>(25);
    
    testBuffer->isFull();
    
    for(int i = 0; i < 120;i++) {
        testBuffer->push(i);
        
        if(testBuffer->isFull()) {
        
            if(i == 42) {
                testBuffer->flush();
            }
        
            testBuffer->resetIterator();
            for(int j =0; j < 25; j++) {
                printf("inhalt an der stelle %d : %d \n", j, *(testBuffer->next()));
            }
            printf("\n");
        }
    }

    return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    int s;
    CyclicBuffer * buffer = new CyclicBuffer(16, s);

    if(s==CyclicBuffer::BUFFER_OK)
        qDebug() << "Buffer allocation succeeded with size 16.";

    qDebug() << "Borders of buffer are set to:" << buffer->GetBottomIndex() << "and" << buffer->GetTopIndex();

    qDebug() << "Pushing characters A, B, C, D into buffer.";
    buffer->Push('A');
    buffer->Push('B');
    buffer->Push('C');
    buffer->Push('D');

    qDebug() << "Index of writing pointer is:" << buffer->GetPushIndex() << "and index of read pointer is:" << buffer->GetPopIndex();

    qDebug() << "Reading the firstly pushed character:" << (char)buffer->Pop();
    qDebug() << "Reading index is now:" << buffer->GetPopIndex();

    qDebug() << "Starting 5 cycles of Pop() calls:\n";
    unsigned char ch;
    for(int i=0; i<5; i++)
    {
        if((ch = buffer->Pop())!=NULL)
            qDebug() << "Cycle" << i << ":" << (char)ch;
        else
            qDebug() << "Cycle" << i << ":" << "Nothing to read.";
    }

    qDebug() << "\nSetting element at index 1 to value X.";
    if(buffer->SetValueAt(1, 'X')==CyclicBuffer::BUFFER_OK)
        qDebug() << "Value at index 1 was set to:" << (char)buffer->GetValueAt(1);
    else
        qDebug() << "Value could not be read.";

    qDebug() << "Forcing index back to index 1.";
    if(buffer->SetPopIndex(1)==CyclicBuffer::BUFFER_OK)
        qDebug() << "Index was successfuly set back to" << buffer->GetPopIndex();

    qDebug() << "\nPushing \'Hi world\' string.";
    const char str[] = "Hi world";

    for(int j=0; j<(sizeof(str)/sizeof(char)); j++)
    {
        buffer->Push((unsigned char)str[j]);
    }

    qDebug() << "Now reading string from buffer.";
    while((ch = buffer->Pop())!=NULL)
    {
        qDebug() << ":" << (char)ch;
    }

    qDebug() << "Current writing index position:" << buffer->GetPushIndex();

    const char str2[] = "Hi buffer";
    qDebug() <<"\nAppending next string: \'Hi buffer\'";

    for(int j=0; j<(sizeof(str2)/sizeof(char)); j++)
    {
        buffer->Push((unsigned char)str2[j]);
    }

    qDebug() << "Now reading string from buffer.";
    while((ch = buffer->Pop())!=NULL)
    {
        qDebug() << ":" << (char)ch;
    }

    qDebug() << "Current writing index position:" << buffer->GetPushIndex();
    qDebug() << "Current reading index position:" << buffer->GetPopIndex();

    qDebug() << "Moving top border to index 10.";
    buffer->SetTopIndex(10);
    qDebug() << "Now buffer size is:" << buffer->GetBufferSize() << "while total memory size is:" << buffer->GetTotalBufferSize();
    qDebug() << "Reallocating memory size to 32.";
    if(buffer->ReallocBuffer(32)==CyclicBuffer::BUFFER_OK)
    {
        qDebug() << "Successfuly reallocated. Memory size is:" << buffer->GetTotalBufferSize() << "while buffer size is:" << buffer->GetBufferSize();
    }
    else
        qDebug() << "Rallocation failed.";

    qDebug() << "\nResetting buffer...";
    buffer->ResetBuffer();
    qDebug() << "Read pointer:" << buffer->GetPopIndex() << "Write pointer:" << buffer->GetPushIndex() << "Bottom border:" << buffer->GetBottomIndex() << "Top border:" << buffer->GetTopIndex();

    qDebug() << "/nSetting bottom border to index 5.";
    buffer->SetBottomIndex(5);
    qDebug() << "Write and read pointers are now:" << buffer->GetPushIndex() << "and" << buffer->GetPopIndex();
    qDebug() << "Buffer size is:" << buffer->GetBufferSize() << "while total memory size is:" << buffer->GetTotalBufferSize();


    delete buffer;

    return a.exec();
}
Exemplo n.º 6
0
unsigned int tx_buffer_free_count(void) {
	return tx_buffer.size() - tx_buffer.count();
}
Exemplo n.º 7
0
	void update(byte c) {
		buffer.push(c);
	}