/*
 * grifo_detector_if.h
 *
 */

#ifndef GRIFO_DETECTOR_IF_H_
#define GRIFO_DETECTOR_IF_H_

#include <stdint.h>

namespace grifo_fw
{

struct detector_raw_if_t
{
    template<unsigned int S_, unsigned int E_> struct spare_t {uint32_t xxx[(E_-S_)/4];};

    enum
    {
        FS_1 = 112, //Mhz
        FS_2 = 16   //Mhz
    };

    enum mof_t {
        mof_pass=0, //MOF 0 = PASS (modalità HR)
        mof_non_coherent=1, //MOF 1 = NON COHERENT
        mof_ramp=2, //MOF 2 = RAMP
        mof_pulse=3 //MOF 3 = PULSE
    };

    struct basic_settings_t
    {
        uint32_t mof; //mof_t
        uint32_t pre_filter_id; //LPF7  <=max_fir_set
        uint32_t post_filter_id; //LPF8 <=max_fir_set

        int32_t f_base;  //FS_2 = detector_doppler_frequency_convert_hz(dobbler_hz)
        int32_t f_delta; //FS_2

        uint32_t lsn_start_56mhz;
        uint32_t lsn_len_56mhz;
        uint32_t prt_num;
    };

    enum {
        num_ph_vectors=64,
        num_ph_channes=16
    };

    struct settings_t
    {
        basic_settings_t sett;

        spare_t<0x3F, 0x100> spare__;

        struct ph_vector_t
        {
            int32_t ph[num_ph_channes];
        };
        ph_vector_t ph_vectors[num_ph_vectors];
        //int32_t ph_vectors[num_ph_vectors][num_ph_channes];
    };

    settings_t settings;

    //Parameters
    enum {
        max_fir_len=69,
        max_fir_set=4
    };

    struct filter_t
    {
        int32_t coeff[max_fir_len]; //Signed 12 bits. higher bits ignore so we can use int16 = int32
        uint32_t spare__[27];
    };

    uint32_t spare1__[0x100/4];

    filter_t pre_filter[max_fir_set];
    filter_t post_filter[max_fir_set];
};


class detector_blob_t;

extern detector_raw_if_t* detector_blob_payload(const detector_blob_t* b=0);

extern void detector_initialize_raw_default_blob(void* raw_memory);

extern detector_blob_t* detector_get_default_blob();
extern detector_raw_if_t* detector_get_default_if(void);

extern unsigned int detector_output_frquency_mhz();
extern unsigned int detector_output_frquency_mhz(detector_raw_if_t::mof_t);

extern unsigned int detector_doppler_frequency_convert_hz(unsigned long hz);

extern void detector_enable_full_programming(bool enable);

} /*namespace*/


#endif /* GRIFO_DETECTOR_IF_H_ */
