// Copyright 2011-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef __RINGBUF_H__
#define __RINGBUF_H__

#include <xs1.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <platform.h>

#if __XC__
extern "C" {
#endif

#define FRAME_SIZE          120   //101623 - from 256 to 120

#define RF_CHAN_NUM         2       //stereo. Multichannel uses NUM_USB_CHAN_OUT
                                    //
#define RB_SIZE             FRAME_SIZE*RF_CHAN_NUM*16   //2 channel, 32-bit, 16 frame
#define RB_MASK             (RB_SIZE - 1)


extern uint32_t r_buffer[RB_SIZE];

typedef struct {
    uint32_t * buf_addr;
    int next_empty;
    int next_data;
    int full;
    int empty;
} ring_buffer_t;

void     rb_init(void);
void     rb_put_word(uint32_t data);
uint32_t rb_get_word(void);
int      rb_is_full(void); 
int      rb_is_empty(void);

#if __XC__
} //extern c
#endif

#endif //RINGBUFFER_H

