// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 SmartLogic.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : ecs_rfm_spu1_oam.c.h
// Author        : huanfeng.wang
// Created On    : 2023-05-22
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#ifndef __ECS_RFM_SPU1_OAM_H__
#define __ECS_RFM_SPU1_OAM_H__

#include "typedef.h"

#define SPU_OAM_BASE_DELAY_SET_REQ            0x200  // 0x200
#define SPU_OAM_BASE_DELAY_SET_RSP            0x201
#define SPU_OAM_BASE_DELAY_QRY_REQ            0x202
#define SPU_OAM_BASE_DELAY_QRY_RSP            0x203
#define SPU_OAM_FIBER_DELAY_QRY_REQ           0x204
#define SPU_OAM_FIBER_DELAY_QRY_RSP           0x205
#define SPU_OAM_FRAME_HEAD_OFFSET_REQ         0x206
#define SPU_OAM_FRAME_HEAD_OFFSET_RSP         0x207
#define SPU_OAM_FRAME_HEAD_OFFSET_QRY_REQ     0x208
#define SPU_OAM_FRAME_HEAD_OFFSET_QRY_RSP     0x209

#define MSG_TRANSFER_OAM_MSG_TYPE         0x125
#define DM_GLADDR_TO_DMAADDR1(addr)	(addr-0x100000)// (addr-0x200000) //

typedef struct tOamMsgTransferHeader {
	uint8_t numMsg;
	uint8_t cellIndex;
	uint16_t rsv;
	uint32_t msgType;
	uint32_t msgLen;
	uint32_t msgData[0];
} OamMsgTransferHeader_t;

typedef struct tSpuOamBaseDelaySetReq {
	uint8_t  u8fiber_port;
    uint8_t  u8rsv[3];
	uint32_t u32dl_frame_offset;
	uint32_t u32ul_frame_offset;
	uint32_t u32ul_data_frame_offset;
} SpuOamBaseDelaySetReq_t;

typedef struct tSpuOamBaseDelaySetRsp {
	uint8_t  u8fiber_port;
    uint8_t  u8result;
    uint8_t  u8rsv[2];
} SpuOamBaseDelaySetRsp_t;

typedef struct tSpuOamBaseDelayQryReq {
	uint8_t  u8fiber_port;
    uint8_t  u8rsv[3];
} SpuOamBaseDelayQryReq_t;

typedef struct tSpuOamBaseDelayQryRsp {
	uint8_t  u8fiber_port;
    uint8_t  u8result;
    uint8_t  u8rsv[2];
	uint32_t u32dl_frame_offset;
	uint32_t u32ul_frame_offset;
	uint32_t u32ul_data_frame_offset;
} SpuOamBaseDelayQryRsp_t;

typedef struct tSpuOamFiberDelayQryReq {
	uint8_t  u8fiber_port;
    uint8_t  u8rsv[3];
} SpuOamFiberDelayQryReq_t;

typedef struct tSpuOamFiberDelayQryRsp {
	uint8_t  u8fiber_port;
    uint8_t  u8result;
    uint8_t  u8rsv[2];
	uint32_t u32t14_val;
} SpuOamFiberDelayQryRsp_t;

typedef struct tSpuOamFrameHeadOffsetReq {
	uint16_t u16frame_head_offset;
    uint8_t  u8rsv[2];
} SpuOamFrameHeadOffsetReq_t;

typedef struct tSpuOamFrameHeadOffsetRsp {
	uint8_t  u8result;
    uint8_t  u8rsv[3];
} SpuOamFrameHeadOffsetRsp_t;

typedef struct tSpuOamFrameHeadOffsetQryRsp {
	uint8_t  u8result;
    uint8_t  u8rsv;
	uint16_t u16frame_head_offset;
}SpuOamFrameHeadOffsetQryRsp_t;

void oam_msg_init(void);
void oam_msg_proc(uint32_t u32msg_addr, uint32_t u32msg_size);
void oam_base_delay_proc(SpuOamBaseDelaySetReq_t *spu_oam_base_delay_set_ptr, OamMsgTransferHeader_t *spu_oam_msg_ptr);
void oam_base_qry_proc(SpuOamBaseDelayQryReq_t   *spu_oam_base_delay_qry_ptr, OamMsgTransferHeader_t *spu_oam_msg_ptr);
void oam_fiber_delay_proc(SpuOamFiberDelayQryReq_t *spu_oam_fiber_delay_qry_ptr, OamMsgTransferHeader_t *spu_oam_msg_ptr);
void oam_frame_head_offset_proc(SpuOamFrameHeadOffsetReq_t *spu_oam_frame_head_offset_qry_ptr, OamMsgTransferHeader_t *spu_oam_msg_ptr);
void oam_frame_head_offset_qry_proc(OamMsgTransferHeader_t *spu_oam_msg_ptr);
void oam_msg_proc_test(uint32_t u32msg_addr, uint32_t u32msg_size);
static inline uint32_t oam_spu_fill_msg_header(uint8_t inst_id, char* buf, uint32_t size, uint32_t msgType);
static inline int32_t oam_spu_send_msg(uint8_t inst_id, uint32_t src_addr, uint32_t size, uint32_t msgType);


#endif

