/*  *********************************************************************
    *  ASTRIS - Remote JTAG probe
    *
    *  Astris Consistent Debug
    *
    *  File: astris_consistent_debug.c
    *
    *  Library to support consistent debug
    *
    *********************************************************************
    *
    *  Copyright (C) 2013  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_CONSISTENT_DEBUG_H
#define _ASTRIS_CONSISTENT_DEBUG_H

#include "consistent_debug_registry.h"
#include "consistent_debug_helper_fns.h"
#include <stdbool.h>
#include "astris_api.h"

#ifdef __cplusplus
extern "C" {
#endif // defined(__cplusplus)

/**
 * Gets the top-level-header for the Consistent Debug Registry
 * on the device.
 *
 * @return const dbg_top_level_header_t* A read-only pointer to
 *         a shadow of the top level header copied from the
 *         device, if it exists. Otherwise, NULL
 */
const dbg_top_level_header_t *consistent_debug_get_top_level_header(void);

/**
 * Reads the entry at entry_num from the consistent debug
 * registry
 *
 * @param entry_num The entry to read (between 0 and
 *                  num_records)
 * @param out_res The structure is copied from the device to the
 *                provided location. This field is only valid
 *                when the return value is true.
 *
 * @return bool True when successful, false otherwise.
 */
bool consistent_debug_read_entry(int entry_num, dbg_record_header_t *out_res);

/**
 * Prints out the entire debug registry to stdout (for debugging purposes)
 */
void consistent_debug_print_all_entries(void);

void consistent_debug_init(AXconn_t *conn_info, AXap_t *ap);

/**
 * Gets the pointer saved in debug root scratch register
 * and returns the pointer type
 *
 * @param pointer_type Pointer type copied into this variable.
 * This field is only valid when the return type is nonzero
 *
 * @return Debug root pointer
 */
AXmemaddr_t get_debug_root(dbg_root_ptr_type_t *pointer_type);

#ifdef __cplusplus
}
#endif // defined(__cplusplus)

#endif // _ASTRIS_consistent_debug_H
