//
//  astris_gatewy_setup_h13.hpp
//  Astris
//
//  Created by Anatoly Torchinsky on 7/1/19.
//

#ifndef astris_gateway_setup_h13_h
#define astris_gateway_setup_h13_h

#include <Astris/astris_gateway_setup.h>
#include <Astris/bitfields.h>

class GatewaySetupH13_t:
    public GatewaySetup_t {

public:
    GatewaySetupH13_t(AXconn_t *conn, AXchip_t *chip, AXap_t *dbgap);

    virtual int take_gateway();
    virtual int release_gateway();

    virtual int take_kis_swd_control(bool force_setup);
    int         release_kis_swd_control();

    bool kis_own_swd();
    bool kis_own_tap();

    virtual uint32_t get_stm_control0_reg();

protected:
    static const uint32_t
        S_DbgMuxSelectKisSwdReq = 0,
        S_DbgMuxSelectKisSwdGnt = 4,
        S_DbgMuxSelectDapSwdReq = 8,
        S_DbgMuxSelectDapSwdGnt = 12,
        S_DbgMuxSelectKisTapReq = 16,
        S_DbgMuxSelectKisTapGnt = 20,
        S_DbgMuxSelectDapTapReq = 24,
        S_DbgMuxSelectDapTapGnt = 28;

    static const uint32_t
        M_DbgMuxSelectKisSwdReq = _MM_MAKEMASK(1, S_DbgMuxSelectKisSwdReq),
        M_DbgMuxSelectKisSwdGnt = _MM_MAKEMASK(1, S_DbgMuxSelectKisSwdGnt),
        M_DbgMuxSelectDapSwdReq = _MM_MAKEMASK(1, S_DbgMuxSelectDapSwdReq),
        M_DbgMuxSelectDapSwdGnt = _MM_MAKEMASK(1, S_DbgMuxSelectDapSwdGnt),
        M_DbgMuxSelectKisTapReq = _MM_MAKEMASK(1, S_DbgMuxSelectKisTapReq),
        M_DbgMuxSelectKisTapGnt = _MM_MAKEMASK(1, S_DbgMuxSelectKisTapGnt),
        M_DbgMuxSelectDapTapReq = _MM_MAKEMASK(1, S_DbgMuxSelectDapTapReq),
        M_DbgMuxSelectDapTapGnt = _MM_MAKEMASK(1, S_DbgMuxSelectDapTapGnt);
};

#endif /* astris_gateway_setup_h13_h */
