#ifndef GRIFO_NODE0_IF_H
#define GRIFO_NODE0_IF_H

#include <stdint.h>

namespace grifo_fw
{


class Node0
{
public:

    struct cr_t
    {
        unsigned int synch: 1;
        unsigned int spare_low: 7;

        unsigned int asynch_win_size:   16;

        unsigned int spare_high: 8;
    };

    struct dispatcher_destination_t
    {
        uint32_t dst_id; //SRIO ID
        uint32_t dst_address; //memory address to write to
    };

    struct dispatcher_configuration_t
    {
        enum {
            num_of_channels=9, //radar channel

            first_det_capture_ch=9,
            first_hr_ch=18,
            num_of_hr_channels=3,

            max_dispatcher_channles=21/*low res + high res + det capture*/
        };

        cr_t cr;

        uint32_t ch_enable;
        uint32_t doorbell;

        uint32_t hdr_doorbell[2];

        uint32_t gap_ctrl_[5-2];

        dispatcher_destination_t header;

        uint32_t gap_header[14];

        dispatcher_destination_t ch[max_dispatcher_channles];

        uint32_t spare[52];
    };


    void initializeChannels(unsigned int dstId, const void* address, unsigned int doorbell);

    void configureSynchAcquisition(bool synch=true);

    void configureAsynchAcquisition(unsigned int samples_56Mhz);


    void configureHeaderDestination(unsigned int pingpong, unsigned int dstId, const void* address, unsigned int doorbell);
    void configureChannelDestination(unsigned int pingpong, unsigned int ch, unsigned int dstId, const void* address);

    void configureChannels(unsigned int pingpong, unsigned int dstId, const void* address, unsigned int ch_gap);

    void configureCaptureChannel(unsigned int pingpong, unsigned int ch, unsigned int dstId, const void* address);

    static void enableChannels(unsigned int ch_mask);
    void enableChannel(unsigned int ch_num, bool enable);

    void dispatcherUpdate(unsigned int pingpong);

    void headerReset();
    void generateHeaderTestPattern();
    void headerClear();
    int headerSet(const void* data, unsigned int size);
    int headerAdd(const char* extra_cookie, const void* data, unsigned int size);
    int headerAdd(unsigned int extra_cookie, const void* data, unsigned int size);
    int headerSetExtra(const void* data, unsigned int size, unsigned int extra_cookie, const void* extra, unsigned int extra_size);	//add a trailing extra info, not used in processing

    unsigned int boorbellCode(unsigned int pingpong) const;

    const dispatcher_configuration_t* node0RegisterImage();

    uint32_t getEnabledChannelMask();

    enum hw_ch_cfg_t  { hw_ch_null, hw_ch_cfg_1dc, hw_ch_cfg_2dc, hw_ch_cfg_operative};

    void setChannelMapConfiguration(hw_ch_cfg_t cfg);

    static void setRecMask(unsigned int m);
    static void setRecHeader(bool enable);

private:
};

}   //namespace grifo_fw

#endif // GRIFO_NODE0_IF_H
