//
//  astris_gateway_setup.h
//  Astris
//
//  Created by Anatoly Torchinsky on 6/27/19.
//

#ifndef astris_gateway_setup_h
#define astris_gateway_setup_h

#include <Astris/astris_api.h>

class GatewaySetup_t {

public:
    GatewaySetup_t(AXconn_t *conn, AXchip_t *chip, AXap_t *dbgap);
    virtual ~GatewaySetup_t();

    // This function assign values to m_gateway_select_apb and m_gateway_select_axi.
    // new_gateway_addr is system address of DBG_MUX_SELECT_REQ_GNT
    void set_gateway_select_addr(AXmemaddr_t new_gateway_addr);

    void set_stm_tck(uint32_t raw_reg);
    void set_jam_tck(uint32_t raw_reg);

    virtual int take_gateway()    = 0;
    virtual int release_gateway() = 0;

    virtual int take_kis_swd_control(bool force_setup) {return ASTRIS_ERR_NOTSUPPORTED;}
    virtual int release_kis_swd_control()              {return ASTRIS_ERR_NOTSUPPORTED;}

    virtual bool kis_own_swd() {return false;}
    virtual bool kis_own_tap() {return false;}

    void set_board_id(uint32_t bid);

protected:

    int rexplore_jtagap();

    AXconn_t *m_conn;
    AXchip_t *m_chip;
    AXap_t *m_dbgap;

    AXmemaddr_t m_gateway_select_apb;
    AXmemaddr_t m_gateway_select_axi;
    uint32_t m_stm_tck;
    uint32_t m_jam_tck;
    uint32_t m_board_id;
};

#endif /* astris_gateway_setup_h */
