/*  *********************************************************************
 *  ASTRIS - Remote JTAG probe
 *
 *  Apple TAPMUX Declaration
 *
 *  File: astris_tapmux.h
 *
 *
 ***********************************************************************
 *
 *  Copyright (C) 2020-2021 Apple Inc. All rights reserved.
 *
 *  This document is the property of Apple Inc.
 *  It is considered confidential and proprietary.
 *
 *  This document may not be reproduced or transmitted in any form,
 *  in whole or in part, without the express written permission of
 *  Apple Inc.
 ********************************************************************* */

#ifndef astris_tapmux_h
#define astris_tapmux_h

#include "astris_api.h"
#include "bitfields.h"

class TapMux_t {

public:
    TapMux_t(AXchip_t *tap, uint32_t num_etaps);

    typedef enum class TapMuxCmd_e {
        TAPMUX_CLEAR_ALL,
        TAPMUX_RESET,
        TAPMUX_RESET_ALL,
        TAPMUX_RESET_ALL_SELECT,
        TAPMUX_RESET_SELECT,
    } TapMuxCmd;

    int tapmux_cmd(TapMuxCmd cmd, uint32_t tap_id);
    int pulse_all_etaps();
    int pulse_etap_and_select(uint8_t tap_id);
    int ir_scan_etap(uint8_t tap_id, int cnt, uint8_t *bits);
    int all_reset_select(uint8_t tap_id);

protected:
    const char *_log_key;
    AXchip_t *m_tap;
    AXconn_t *m_conn;
    uint8_t m_num_etaps;

    const uint8_t TAPMUX_SEL_IR = 0x11; //8'b00010001

    uint32_t S_TAPMUX_SEL_EN;
    uint32_t S_TAPMUX_SEL_RESET;

    uint32_t M_TAPMUX_SEL_EN;
    uint32_t M_TAPMUX_SEL_RESET;

};

#endif /* astris_tapmux_h */
