/******************************************************************
 * @file  receiver_Proc.s.c
 * @brief:    [file description] 
 * @author: HUOHUO
 * @Date 2024年4月20日
 * COPYRIGHT NOTICE: ITTC
 * Change_date         Owner         Change_content
 * 2024年4月20日        HUOHUO       create file

*****************************************************************/
#include "receiver_sync_func.h"
#define ADDR_ALIGN(addr, val)   ((((uint32_t)(addr) + (2<<(val)) - 1)>>(val))<<(val)) 

void dm_check(uint32_t mark)
{
    uint32_t idx;
    uint32_t flag = 0;
    for( idx = 0 ;idx < 8; idx++)
    {
        if(0xa5a55a5a != *last_mem_dm[idx])
        {
            flag |= (1<<idx);
            LOG_ERROR_S("lk 0x%08x\n", last_mem_dm[idx]);
        }
    }

    if(0 != flag)
    {
    LOG_ERROR_S("dm leadking detect!!%d 0x%08x\n", mark, flag);
    __ucps2_synch(0);
    __ucps2_synch(0);
    __ucps2_synch(0);
    __ucps2_synch(0);
    __ucps2_synch(0);
    __ucps2_dbgbreak();
    }
}

void Receiver_Sync_Memory_Alloc( )
{
    uint32_t receiver_sync_param_ptr;//not use
    uint32_t dm0_space;
    uint32_t dm1_space;
    uint32_t dm2_space;
    uint32_t dm3_space;

     //0 空间回收
    dmalloc_trim(0, APE_DM0);
    dmalloc_trim(0, APE_DM1);
    dmalloc_trim(0, APE_DM2);
    dmalloc_trim(0, APE_DM3);   

    //1. DM0空间申请
    dm0_space = getFreeSpace(APE_DM0);
    // LOG_ERROR_S("dm0 space:%d\n",dm0_space);
    receiver_sync_malloc_dm0_ptr = dmalloc_unit(dm0_space - 1024, APE_DM0); //尽量申请空间
    if (NULLPTR == receiver_sync_malloc_dm0_ptr)
    {
        LOG_ERROR_S("rec sync DM0 fail\n");
        return;
    }

    //2. DM0空间分配
    //DM0第一段，微码相关空间
    receiver_sync_config_dm0_ptr = (uint32_t)receiver_sync_malloc_dm0_ptr;

    // LOG_ERROR_S("sync_track dm0 0x%08x 0x%08x %d\n", g_receiver_sync_table_param.receiver_sync_config0_ddr_ptr, receiver_sync_config_dm0_ptr,
    //     g_receiver_sync_table_param.receiver_sync_config0_length);
        
    ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)g_receiver_sync_table_param.receiver_sync_config0_ddr_ptr,
                                 (uint64_t)DM_TO_CSU_ADDR(receiver_sync_config_dm0_ptr),
                                 g_receiver_sync_table_param.receiver_sync_config0_length,
                                 DMA_TAG_G2L,
                                 0);    

    //DM0第二段，堆空间
    receiver_sync_temp_dm0_ptr = (int32_t *)ADDR_ALIGN(receiver_sync_config_dm0_ptr + \
        (g_receiver_sync_table_param.receiver_sync_config0_length>>2), 2); //起始地址4byte对齐
    
    //3. DM3空间申请
    dm3_space = getFreeSpace(APE_DM3);
    receiver_sync_malloc_dm3_ptr = dmalloc_unit(dm3_space - 1024, APE_DM3);//尽量申请
    //若空间申请失败，则释放已申请的空间，再退出任务
    if (NULLPTR == receiver_sync_malloc_dm3_ptr)
    {
        LOG_ERROR_S("rec sync DM3 fail\n");
        dfree_unit(receiver_sync_malloc_dm0_ptr, APE_DM0);
        return;
    }
    //DM3第一段，堆空间
    receiver_sync_temp_dm3_ptr = (int32_t *)ADDR_ALIGN(receiver_sync_malloc_dm3_ptr, 12); //起始地址4k对齐


    //4. DM1空间申请
    dm1_space = getFreeSpace(APE_DM1);
    receiver_sync_malloc_dm1_ptr = dmalloc_unit(dm1_space - 1024, APE_DM1);//尽量申请
    //若空间申请失败，则释放已申请的空间，再退出任务
    if (NULLPTR == receiver_sync_malloc_dm1_ptr)
    {
        LOG_ERROR_S("rec sync DM1 fail\n");
        dfree_unit(receiver_sync_malloc_dm3_ptr, APE_DM3);
        dfree_unit(receiver_sync_malloc_dm0_ptr, APE_DM0);
        return;
    }
    //DM1第一段,堆空间
    receiver_sync_temp_dm1_ptr = (int32_t *)ADDR_ALIGN(receiver_sync_malloc_dm1_ptr + \
        (g_receiver_sync_table_param.receiver_sync_config1_length>>2), 12); //起始地址4k对齐

    //5. DM2空间申请
    dm2_space = getFreeSpace(APE_DM2);
    receiver_sync_malloc_dm2_ptr = dmalloc_unit(dm2_space - 1024, APE_DM2);//尽量申请
    //若空间申请失败，释放已申请的空间，再退出任务
    if (NULLPTR == receiver_sync_malloc_dm2_ptr)
    {
        LOG_ERROR_S("rec sync DM2 fail\n");
        dfree_unit(receiver_sync_malloc_dm3_ptr, APE_DM3);
        dfree_unit(receiver_sync_malloc_dm0_ptr, APE_DM0);
        dfree_unit(receiver_sync_malloc_dm1_ptr, APE_DM1);
        return;
    }
    //DM2第一段,堆空间
    receiver_sync_temp_dm2_ptr = (int32_t *)ADDR_ALIGN(receiver_sync_malloc_dm2_ptr + \
        (g_receiver_sync_table_param.receiver_sync_config2_length>>2), 2); //起始地址4byte对齐

    ape_csu_task_lookup(DMA_TAG_G2L, 1);
    

    //debug
    last_mem_dm[0] = receiver_sync_malloc_dm0_ptr + ((dm0_space - 1024)>>2) -1;
    last_mem_dm[1] = receiver_sync_malloc_dm0_ptr + ((dm0_space - 1024)>>2) -2;
    last_mem_dm[2] = receiver_sync_malloc_dm1_ptr + ((dm1_space - 1024)>>2) -1;
    last_mem_dm[3] = receiver_sync_malloc_dm1_ptr + ((dm1_space - 1024)>>2) -2;
    last_mem_dm[4] = receiver_sync_malloc_dm2_ptr + ((dm2_space - 1024)>>2) -1;
    last_mem_dm[5] = receiver_sync_malloc_dm2_ptr + ((dm2_space - 1024)>>2) -2;
    last_mem_dm[6] = receiver_sync_malloc_dm3_ptr + ((dm3_space - 1024)>>2) -1;
    last_mem_dm[7] = receiver_sync_malloc_dm3_ptr + ((dm3_space - 1024)>>2) -2;

    *last_mem_dm[0] = 0xa5a55a5a;
    *last_mem_dm[1] = 0xa5a55a5a;
    *last_mem_dm[2] = 0xa5a55a5a;
    *last_mem_dm[3] = 0xa5a55a5a;
    *last_mem_dm[4] = 0xa5a55a5a;
    *last_mem_dm[5] = 0xa5a55a5a;
    *last_mem_dm[6] = 0xa5a55a5a;
    *last_mem_dm[7] = 0xa5a55a5a;

    

}



void Receiver_Sync_Memory_Free( )
{
    //8. 内存释放
    dfree_unit(receiver_sync_malloc_dm2_ptr, APE_DM2);
    dfree_unit(receiver_sync_malloc_dm1_ptr, APE_DM1);
    dfree_unit(receiver_sync_malloc_dm3_ptr, APE_DM3);
    dfree_unit(receiver_sync_malloc_dm0_ptr, APE_DM0);
}



 /*!   
 * @brief:  Receiver_sync链路处理
 * @author:  HUOHUO
 * @Date:  2024年10月30日
 */
void Receiver_Sync_Proc(
)
{
    //局部变量定义
    int32_t  *cfg_addr;
    uint32_t time_data_ddr_ptr;
    uint32_t time_data_length;

    uint32_t cur_sfn = get_rx_nr_sfn();
    uint32_t cur_slot = get_rx_nr_slot();
    volatile sync_status = LOAD_EX_W(&(g_receiver_sync_status_SM_ptr->sync_status));

    if(SYNC_FIRST_RUNING ==  sync_status)
    {
        TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 2);
        return ;
    }
    else if(SYNC_IDLE == sync_status)
    {
        TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 3);
        STORE_EX_W(&g_receiver_sync_status_SM_ptr->sync_status ,SYNC_FIRST_RUNING);
        __ucps2_synch(0);
        receiver_sync2first_sync_t temp_msg;
        temp_msg.sfn = cur_sfn;
        temp_msg.slot = cur_slot;
        phy_et_msg_send((uint32_t)(&temp_msg),
                            sizeof(receiver_sync2first_sync_t),
                            UCP4008_KERNEL_INNER,
                            APE4_CORE_ID,
                            APE7_CORE_ID,
                            PHY_TASK_RECIEVER_SYNC,
                            PHY_TASK_RECIEVER_FIRST_SYNC);

        //第一次同步目前不存储数据做处理，注释
        // receiver_sync2first_sync_t data_send2first_sync_task;
        // phy_et_msg_send((uint32_t)(&data_send2first_sync_task),
        //                     sizeof(receiver_sync2first_sync_t),
        //                     UCP4008_KERNEL_INNER,
        //                     get_core_id(),
        //                     get_core_id(),
        //                     PHY_TASK_PRI_RECEIVER_SYNC,
        //                     PHY_TASK_PRI_RECEIVER_FIRST_SYNC);
        TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 4);
    }
    else if(SYNC_TRACKING == sync_status)
    {
        TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 5);
        Receiver_Fine_Sync_Proc(cur_sfn, cur_slot);

        //根据当前状态机状态，buffer存储的数据长度，sync同步帧头，发送核间消息触发任务
        TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 6);

    }
    else
    {
        TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 7);
        return;
    }

    TRACE(TRACE_RECEIVER_SYNC_ADDR, 3, 8);
    return;
}



//用于跟踪同步
void Receiver_Fine_Sync_Proc(uint32_t sfn, uint32_t slot)
{
    g_time_start[2] = TIME_NS();
    uint16_t dbg_time0, dbg_time1;
    RUN_CNT(TRACE_RECEIVER_SYNC_FINE_ADDR, 0);

    uint32_t ret;
    int32_t  *cfg_addr;// 配置地址指针
    uint32_t time0 = g_time_start;
    volatile uint32_t time1 = time0;
    uint32_t task_idx = 0;
    volatile uint32_t frame_head_offset;
    uint32_t src_addr0;
    uint32_t src_addr1;
    
    //用于指示循环buffer空口数据的存储头
    uint32_t buffer_sel = (slot + RECEIVER_SYNC_SYNC2SYMB_NUM_BUFFER -1) & 0x3; 
    uint32_t buffer_sel2 = (buffer_sel + 1) & 0x3; 
    
    TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 1); 
    //Proc的DM空间申请
    
    Receiver_Sync_Memory_Alloc();
    TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 2);

    dbg_time0 = Time_offset(2);
    //搬移1055sample数据供定时同步,奇数slot处理偶buffer数据，反之
#ifndef RECV_DBG_DATA_TEST
    if( 1 == (slot & 0x01) )
    {
        src_addr0 = (uint32_t)JESD_NRFDD_RX_SLOT_EVEN_DATA_ADDR;
        src_addr1 = (uint32_t)JESD_NRFDD_RX_SLOT_ODD_DATA_ADDR;
    }
    else
    {
        src_addr0 = (uint32_t)JESD_NRFDD_RX_SLOT_ODD_DATA_ADDR; 
        src_addr1 = (uint32_t)JESD_NRFDD_RX_SLOT_EVEN_DATA_ADDR;       
    }
#else
    src_addr0 = (uint32_t)JESD_NRFDD_RX_SLOT_EVEN_DATA_ADDR;
    src_addr1 = (uint32_t)JESD_NRFDD_RX_SLOT_ODD_DATA_ADDR;  
#endif

    ape_csu_task_lookup(DMA_TAG_G2L, 1);
    //取数方式，同步点为中心，前16，后15，相关长度1024
    frame_head_offset = LOAD_EX_W(&g_receiver_sync_status_SM_ptr->frame_head_offset);
    LOG_ERROR_S("frame_head_offset=%d\n", frame_head_offset );

    if(16 > frame_head_offset)
    {
        //当前buffer头
        ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(src_addr0),
                                    (uint64_t)DM_TO_CSU_ADDR(receiver_sync_temp_dm0_ptr + (16 - frame_head_offset) ),
                                    (1055 - (16 - frame_head_offset) )<<2,
                                    DMA_TAG_G2L,
                                    0);    
        //上个buffer尾
        memcpy_ext(receiver_sync_temp_dm0_ptr, src_addr1 + ((61440 - (16 - frame_head_offset) ) <<2), (16 - frame_head_offset)<<2 );

        
        // LOG_ERROR_S("csu1:%d %d\n", (16 - frame_head_offset)<<2 , (1055 - (16 - frame_head_offset) )<<2 );
    }
    else if(61440 - (15 + 1024) < frame_head_offset)
    {
        //当前buffer尾
        ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(src_addr0 +  ((frame_head_offset -16) <<2) ),
                                    (uint64_t)DM_TO_CSU_ADDR(receiver_sync_temp_dm0_ptr),
                                    ((61440 - (frame_head_offset -16)) )<<2,
                                    DMA_TAG_G2L,
                                    0);  
        //下个buffer头  等待保证数据被jesd_csu存入    
        while(time1 - time0 < 10000)
        {
            time1 = Time_offset(2);
        }
        ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)(src_addr1),
                            (uint64_t)DM_TO_CSU_ADDR(receiver_sync_temp_dm0_ptr + (61440 - (frame_head_offset -16) ) ),
                            (1055 - (61440 - (frame_head_offset -16)) )<<2,
                            DMA_TAG_G2L,
                            0); 
        
        // LOG_ERROR_S("csu2:%d %d\n", ((61440 - (frame_head_offset -16)) )<<2 , (1055 - (61440 - (frame_head_offset -16)) )<<2 );
    }
    else
    {
        //当前buffer
        ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(src_addr0 +  ((frame_head_offset -16) <<2) ),
                                    (uint64_t)DM_TO_CSU_ADDR(receiver_sync_temp_dm0_ptr),
                                    (1055)<<2,
                                    DMA_TAG_G2L,
                                    0); 
        
         // LOG_ERROR_S("csu3:0x%08x 0x%08x\n", (src_addr0 +  ((frame_head_offset -16) <<2) ) , receiver_sync_temp_dm0_ptr );
    }

    //复制数据DM0 -> DM1
    cfg_addr = (int32_t *)receiver_sync_config_dm0_ptr + g_receiver_sync_table_param.ConfigByteCopy_CFG1_Offset;
    ByteCopy((int)cfg_addr, 
            MPU_ADDR(receiver_sync_temp_dm0_ptr),
            MPU_ADDR(receiver_sync_temp_dm1_ptr),
            (1055) << 2);

    WAIT_MPU_STOP;
    ape_csu_task_lookup(DMA_TAG_G2L, 1);
    TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 3); 
    
    dbg_time1 = Time_offset(2);
    TRACE_MAX(TRACE_RECEIVER_SYNC_FINE_ADDR, 5, dbg_time1-dbg_time0 );
    dbg_time0 = dbg_time1;
    // LOG_ERROR_S("%d %d %d\n", sfn, slot , dbg_cur_time);
    // if(100 < dbg_cur_time )
    // {
    // LOG_ERROR_S("time overload !!\n");
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_dbgbreak();
    // }

    //插空拷贝数据到SM，提供给sync_symb数据输入来源
    ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(src_addr0),
                                (uint64_t)(sync2symb_data_buffer[buffer_sel]),
                                (61440)<<2,
                                DMA_TAG_G2G,
                                0);

    SVRReg[0] = MPU_ADDR(cfg_addr);
    ByteCopyAsm(SVRReg);


    cfg_addr = (int32_t *)receiver_sync_config_dm0_ptr + g_receiver_sync_table_param.ConfigSyncVer_CFG4_Offset;
    SyncVer((int)cfg_addr, 
             MPU_ADDR(receiver_sync_temp_dm0_ptr), 
             MPU_ADDR(receiver_sync_temp_dm1_ptr),
             MPU_ADDR(receiver_sync_temp_dm2_ptr), 
             MPU_ADDR(receiver_sync_temp_dm3_ptr));

    WAIT_MPU_STOP;
    TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 4);
    dbg_time1 = Time_offset(2);
    TRACE_MAX(TRACE_RECEIVER_SYNC_FINE_ADDR, 6, dbg_time1-dbg_time0 );
    dbg_time0 = dbg_time1;
    SVRReg[0] = MPU_ADDR(cfg_addr);
    SyncVerAsm(SVRReg);



    // 得到验证后的同步位置
    WAIT_MPU_STOP;
    dbg_time1 = Time_offset(2);
    TRACE_MAX(TRACE_RECEIVER_SYNC_FINE_ADDR, 7, dbg_time1-dbg_time0 );
    dbg_time0 = dbg_time1;
    TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 5);
    uint32_t maxWindowSum = receiver_sync_temp_dm3_ptr[1];
    //更新最佳位置
    int32_t bestPosition =receiver_sync_temp_dm3_ptr[0]-16 + frame_head_offset;
    LOG_ERROR_S("%d %d %d\n", receiver_sync_temp_dm3_ptr[0], receiver_sync_temp_dm3_ptr[1], bestPosition);
    //更新sync2symb的buffer状态记录
    STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_data_len,  LOAD_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_data_len) + 61440);
    STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_data_offset , 61440 * buffer_sel2);


    volatile cylic_buffer_proc_data_offset = LOAD_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_proc_data_offset);
    if(-1 == cylic_buffer_proc_data_offset )  //初始态，初始化数据处理偏移
    {
        STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_proc_data_offset , 61440 * buffer_sel);
        __ucps2_synch(0);
        cylic_buffer_proc_data_offset = 61440 * buffer_sel;
    }
    

    volatile cylic_buffer_data_offset = 61440 * buffer_sel2;
    uint32_t cylic_buffer_data_offset_temp = (cylic_buffer_data_offset >= cylic_buffer_proc_data_offset) ?
                                                cylic_buffer_data_offset   :
                                                (cylic_buffer_data_offset + 61440 * RECEIVER_SYNC_SYNC2SYMB_NUM_BUFFER); 

    uint32_t offset_temp = 0 + frame_head_offset;

    uint32_t cylic_buffer_data_len = LOAD_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_data_len);
    while(offset_temp <= cylic_buffer_data_offset_temp)
    {
        if( (cylic_buffer_proc_data_offset + 61440 <= offset_temp) )
        {
        TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 6);
        //填写给symb任务的调度信息
        data_send2symb_task[task_idx].sfn = sfn;
        data_send2symb_task[task_idx].slot = slot;
        data_send2symb_task[task_idx].num_data_section = (offset_temp > (61440 * 4) && (offset_temp < (61440 * 5)) ) ? 2 : 1;
        data_send2symb_task[task_idx].proc_id = g_proc_id;
        data_send2symb_task[task_idx].data_section0_ptr =  sync2symb_data_buffer[0] + (((offset_temp - 61440) % (61440*4))<<2);
        data_send2symb_task[task_idx].data_section0_length = (offset_temp > (61440 * 4)) ? ((61440 * 4) - (offset_temp - 61440)) : 61440;
        data_send2symb_task[task_idx].data_section1_ptr =  (2 == data_send2symb_task[task_idx].num_data_section) ? (sync2symb_data_buffer[0]) : 0;
        data_send2symb_task[task_idx].data_section1_length = (2 == data_send2symb_task[task_idx].num_data_section) ? (61440 - data_send2symb_task[task_idx].data_section0_length) : 0; 

        //维护状态信息
        cylic_buffer_data_len =  cylic_buffer_data_offset_temp - offset_temp;
        cylic_buffer_proc_data_offset = offset_temp % (61440*4);

        //为了适配SYMB接口，如果数据是两段，搬移成一块
        if(2 == data_send2symb_task[task_idx].num_data_section)
        {
                ape_csu_task_lookup(DMA_TAG_G2G,1);
                ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(data_send2symb_task[task_idx].data_section1_ptr),
                                (uint64_t)(data_send2symb_task[task_idx].data_section0_ptr + data_send2symb_task[task_idx].data_section0_length),
                                (data_send2symb_task[task_idx].data_section1_length)<<2,
                                DMA_TAG_G2G,
                                1);
        }
        //发核间消息给SYMB_TASK
        phy_et_msg_send((uint32_t)(&data_send2symb_task[task_idx]),
                            sizeof(receiver_sync2symb_t),
                            UCP4008_KERNEL_INTER,
                            get_core_id(),
                            APE5_CORE_ID,
                            PHY_TASK_PRI_RECEIVER_SYNC,
                            PHY_TASK_PRI_RECEIVER_SYMB);
        g_proc_id++;
        task_idx++;
        }

        offset_temp += 61440;
    }
    STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_data_len , cylic_buffer_data_len);
    STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_proc_data_offset, cylic_buffer_proc_data_offset);

    dbg_time1 = Time_offset(2);
    TRACE_MAX(TRACE_RECEIVER_SYNC_FINE_ADDR, 8, dbg_time1-dbg_time0 );
    dbg_time0 = dbg_time1;

    //TODO:后续需要添加门限判断条件
    uint32_t threshold = 1;
    if(threshold)
    {
        STORE_EX_W(&g_receiver_sync_status_SM_ptr->frame_head_offset , (bestPosition+61440) % 61440);
        //LOG_INFO_S("rec sync track offset: %d\n", bestPosition % 61440);
        ret = SYNC_OK;
    } 


    //执行完成，更新状态机
    if(SYNC_OK == ret)
    {
        //此分支本身就是SYNC_TRACKING
        //g_receiver_sync_status_SM_ptr.sync_status = SYNC_TRACKING;

    }
    else
    {
        STORE_EX_W(&g_receiver_sync_status_SM_ptr->sync_status , SYNC_IDLE);
        STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_proc_data_offset , -1);
        STORE_EX_W(&g_receiver_sync_status_SM_ptr->cylic_buffer_data_len, 0);
    }
    TRACE(TRACE_RECEIVER_SYNC_FINE_ADDR, 3, 7);
    ape_csu_task_lookup(DMA_TAG_G2G, 1);
    Receiver_Sync_Memory_Free();

    RUN_CNT(TRACE_RECEIVER_SYNC_FINE_ADDR, 1);
    TRACE_MAX(TRACE_RECEIVER_SYNC_FINE_ADDR, 2, Time_offset(2) );
    return;
}