#include "queue.h" //========================================================================================================== // QUEUE THAT SENDS PULSES FROM INT TO MAIN-LOOP //========================================================================================================== static int read_d; /*!< Read index points to the place in the queue that has already been read */ static int write_d; /*!< The write index points to the place where the next write in the queue will take place. */ static unsigned int nexaQueueBuffer[NEXA_QUEUE_SIZE]; void rcvInitQueue( ) { read_d = 0; write_d = 1; } unsigned int getQueueUsed() { return (write_d-read_d); } unsigned char rcvEnQueue( unsigned int value ) { // Is the queue full ? if( write_d == read_d ) { return 0u; } // Make the data copy nexaQueueBuffer[write_d] = value; // Increment the write position write_d++; if( write_d == NEXA_QUEUE_SIZE ) write_d=0; return 1u; } unsigned char rcvDeQueue( unsigned int *value ) { int writePos = write_d; // Pseudo writepos if( writePos < read_d || writePos == read_d ) writePos += NEXA_QUEUE_SIZE; // The queue is empty ? if( writePos == ( read_d + 1 ) ) { return 0u; } // Increment the read position read_d++; if( read_d == NEXA_QUEUE_SIZE ) read_d=0; // Make the data copy *value = nexaQueueBuffer[read_d]; return 1u; } //========================================================================================================== // QUEUE THAT SENDS CODES FROM MAIN-LOOP TO WIFI //========================================================================================================== static int wifi_read_d; /*!< Read index points to the place in the queue that has already been read */ static int wifi_write_d; /*!< The write index points to the place where the next write in the queue will take place. */ static unsigned long long wifiQueueBufferValue[WIFI_QUEUE_SIZE]; static unsigned int wifiQueueBufferType[WIFI_QUEUE_SIZE]; void wifi_rcvInitQueue( ) { wifi_read_d = 0; wifi_write_d = 1; } unsigned char wifi_rcvEnQueue( unsigned int type, unsigned long long value ) { // Is the queue full ? if( wifi_write_d == wifi_read_d ) { return 0u; } // Make the data copy wifiQueueBufferType[wifi_write_d] = type; wifiQueueBufferValue[wifi_write_d] = value; // Increment the write position wifi_write_d++; if( wifi_write_d == WIFI_QUEUE_SIZE ) wifi_write_d=0; return 1u; } unsigned char wifi_rcvDeQueue( unsigned int *type, unsigned int *value ) { int wifi_writePos = wifi_write_d; // Pseudo writepos if( wifi_writePos < wifi_read_d || wifi_writePos == wifi_read_d ) wifi_writePos += WIFI_QUEUE_SIZE; // The queue is empty ? if( wifi_writePos == ( wifi_read_d + 1 ) ) { return 0u; } // Increment the read position wifi_read_d++; if( wifi_read_d == WIFI_QUEUE_SIZE ) wifi_read_d=0; // Make the data copy *type = wifiQueueBufferType[wifi_read_d]; *value = wifiQueueBufferValue[wifi_read_d]; return 1u; }