Example #1
0
FREQ_TREND_ENUM FreqData_GetTrend(void)
{
	FREQ_TREND_ENUM trend = TREND_NONE;
	if (Ringbuf_Full(&s_averageBuffer))
	{
		uint16_t newestAverage = *(uint16_t*)(Ringbuf_Get_Newest(&s_averageBuffer));
		uint16_t oldestAverage = *(uint16_t*)(Ringbuf_Get_Oldest(&s_averageBuffer));
		
		if (newestAverage > oldestAverage)
		{
			if ((newestAverage - oldestAverage) >= TREND_BANDGAP)
			{
				trend = TREND_UP;
			}
		}
		else if (oldestAverage > newestAverage)
		{
			if ((oldestAverage - newestAverage) >= TREND_BANDGAP)
			{
				trend = TREND_DN;
			}
		}
	}
	
	return trend;
}
/****************************************************************************
* DESCRIPTION: Reserves and gets the next data portion of the buffer.
* RETURN:      pointer to the data, or NULL if the list is full
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
volatile uint8_t *Ringbuf_Alloc(
    RING_BUFFER * b)
{
    volatile uint8_t *ring_data = NULL; /* used to help point ring data */

    if (b) {
        /* limit the amount of elements that we accept */
        if (!Ringbuf_Full(b)) {
            ring_data = b->buffer;
            ring_data += ((b->head % b->element_count) * b->element_size);
            b->head++;
        }
    }

    return ring_data;
}
/****************************************************************************
* DESCRIPTION: Adds an element of data to the ring buffer
* RETURN:      true on succesful add, false if not added
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
bool Ringbuf_Put(
    RING_BUFFER * b,    /* ring buffer structure */
    uint8_t * data_element)
{       /* one element to add to the ring */
    bool status = false;        /* return value */
    volatile uint8_t *ring_data = NULL; /* used to help point ring data */
    unsigned i; /* loop counter */

    if (b && data_element) {
        /* limit the amount of elements that we accept */
        if (!Ringbuf_Full(b)) {
            ring_data = b->buffer;
            ring_data += ((b->head % b->element_count) * b->element_size);
            for (i = 0; i < b->element_size; i++) {
                ring_data[i] = data_element[i];
            }
            b->head++;
            status = true;
        }
    }

    return status;
}