/******************************************************************
 * @file  trace.h
 * @brief:    record code status
 * @author: HUOHUO
 * @Date 2022年1月10日
 * COPYRIGHT NOTICE: ITTC All rights reserved. 
 * Change_date         Owner         Change_content
 * 2024年10月23日        HUOHUO       create file

*****************************************************************/

#ifndef     TRACE_H
#define     TRACE_H

#include "common.h"
#include "drv_ape.h"
#include "mem_def.h"
#include "phy_macro.h"



#define TRACE(base, offset, val)    STORE_EX_W( (void*)((base) + 4*(offset)), (val))
#define TRACE_MAX(base, offset, val) \
{ \
    if ( (val) > LOAD_EX_W( (void*)((base) + 4*(offset)) ) ) \
        STORE_EX_W( (void*)((base) + 4*(offset)), (val) ); \
} 

#define RUN_CNT(base, offset)       STORE_EX_W( (void*)((base) + 4*(offset)), LOAD_EX_W( (void*)((base) + 4*(offset)) ) + 1 )
#define TIME_SLOT()                 (get_tx_nr_slot() )
#define TIME_US()                   (uint32_t)((GET_STC_CNT()* 2097) >> 21)
#define TIME_NS()                   (uint32_t)(GET_STC_CNT())

#define TIME_DIFF(start_slot, start_us, end_slot, end_us)   ((start_slot) <= (end_slot) )? \
     (( (end_slot) - (start_slot) ) * 500 + ( (end_us) - (start_us) )): \
     ((NR_SFN_SLOT_NUM + (end_slot) - (start_slot) )* 500 + (end_us) - (start_us) ) \

extern uint32_t g_time_start[3];
extern uint32_t Time_offset(uint32_t idx);
//#define TIME_RECORD(base, offset, time0) STORE_EX_W( (void*)((base) + 4*(offset)), GET_STC_CNT() - time0)

#endif