// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 SmartLogic.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : ape_top.c
// Author        : xianfeng.du
// Created On    : 2022-06-25
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#include "typedef.h"
#include "smartos.h"
#include "ape_drv.h"
#include "ucp_handshake.h"
#include "ucp_utility.h"
#include "ucp_printf.h"
#include "msg_transfer_mem.h"
#include "msg_transfer_queue.h"
#include "pet_sm_mgt.h"
#include "osp_init.h"
#include "phy_para.h"

static int32_t gCoreId = 0;
ALWAYS_INLINE int32_t get_core_id(void)
{
    return gCoreId;
}

void set_core_id(void)
{
    __ucps2_iCacheConfig(f_DoubleEnable, f_BypassEnable);

    gCoreId = smart_get_cpuid();
    if (0 > gCoreId)
    {
        debug_write(DBG_DDR_ERR_IDX(0, 13), gCoreId);
    }
    UCP_PRINT_EMPTY("Hello world from APE,coreId[0x%x]", gCoreId);

    __ucps2_synch(0);

    return;
}

int32_t soc_drv_init()
{
    int apeId = get_core_id();
    if (0 == apeId)
    {
        drv_sm_init();
        osp_var_init();
        pet_sm_init();
    }

    return 0;
}

void spu_drv_init(void)
{
    pet_sm_alloc();

    ape_drv_init();

    return;
}

void spu_msg_transfer_init(void)//ape level
{
    msg_transfer_mem_alloc();

    handshake_slave_with_master();

    msg_transfer_queue_init();

    return;
}

