diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dba3a55 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "driver/rfic"] + path = driver/rfic + url = http://gitlab.smartlogictech.com/ucp/driver/ucp4008_rfic.git +[submodule "driver/tfu"] + path = driver/tfu + url = http://gitlab.smartlogictech.com/ucp/driver/ucp4008_tfu.git diff --git a/app/inc/mem_sections.h b/app/inc/mem_sections.h new file mode 100644 index 0000000..e738daf --- /dev/null +++ b/app/inc/mem_sections.h @@ -0,0 +1,52 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : mem_section.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + + +#ifndef __MEM_SECTIONS_H__ +#define __MEM_SECTIONS_H__ + +#include "typedef.h" + +#define MEM_ALIGNED_4BYTES 4 +#define MEM_ALIGNED_64BYTES 64 +#define RFM_IM_SECTION __attribute__((aligned(MEM_ALIGNED_4BYTES))) + +#define PET_SRAM_BASE_ADDR 0x08700000 +#define PET_SRAM_SIZE 0x20000//128KBytes + +#define ECS_SRAM_BASE_ADDR 0x07200000 +#define ECS_SRAM_SIZE (0x20000 - 0x2000)//128KBytes,reserved 8KBytes for CPRI CSU + +#define UCP_MSG_MEM_BASE_ADDR (0xA0000000) +#define UCP_MSG_MEM_SIZE (128*1024*1024)//128MBytes + +typedef struct +{ + uint64_t baseAddr; + uint64_t currAddr; + uint32_t maxSize; + + char* memSectionName; +} MEM_SECTION_INFO; + +void memSectionInit(MEM_SECTION_INFO* memSecInfo, uint64_t baseAddr, uint32_t maxSize, char* memSectionName); +void memSectionReset(MEM_SECTION_INFO* memSecInfo); +void* memSectionAlloc(MEM_SECTION_INFO* memSecInfo, uint32_t allocSize, uint32_t allocAlign, char* varString); +//void memSectionAllocPrint(MEM_SECTION_INFO* memSecInfo, uint32_t allocSize, char* varString); + +//MEM_SECTION_INFO* GetEcsSramSection(); +MEM_SECTION_INFO* GetPetSramSection(); +MEM_SECTION_INFO* GetMsgDdrSection(); + +#endif diff --git a/app/inc/msg_transfer_layer.h b/app/inc/msg_transfer_layer.h new file mode 100644 index 0000000..72cbac7 --- /dev/null +++ b/app/inc/msg_transfer_layer.h @@ -0,0 +1,81 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_transfer_layer.h +// Author : xianfeng.du +// Created On : 2022-06-29 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __MSG_TRANSFER_LAYER_H__ +#define __MSG_TRANSFER_LAYER_H__ + +#include "typedef.h" + +#define MAX_INSTANCE_NUM (2) +#define MAX_PORT_NUM (4) + +#define SUCCESS (0) +#define FAILURE (-1) +#define UNINITIALIZED_QUEUE (1) +#define FULLEDED_QUEUE (2) +#define EMPTY_QUEUE (2) +#define OUT_OF_BLOCK_MEMORY (2) + +typedef enum e_transfer_type { + NON_CU_SPLIT, + CU_SPLIT, + OAM, + TRANSFER_TYPE_NUM +} transfer_type_e; + +typedef enum e_cu_flag { + C_PLANE, + U_PLANE +} cu_flag_e; + +typedef union tHandleId { + uint32_t value; + struct { + uint8_t rsv; + uint8_t type_id; + uint8_t inst_id; + uint8_t port_id; + }; +} HandleId_t; + +typedef uint32_t (*msg_transfer_callback)(const char* buf,uint32_t payloadSize); + +typedef struct t_queue_info { + uint32_t tx_desc_num; + uint32_t rx_desc_num; + uint32_t tx_block_size; + uint32_t rx_block_size; + uint16_t tx_block_num; + uint16_t rx_block_num; + uint16_t directions; + uint16_t rsv; + msg_transfer_callback tx_callback; + msg_transfer_callback rx_callback; +} queue_info_s; + +typedef struct t_transfer_type_info { + queue_info_s queue_cplane_info; + queue_info_s queue_uplane_info; +} transfer_type_info_s; + +int32_t msg_transfer_init(uint16_t port_index, uint16_t transfer_type, uint16_t inst_id, const transfer_type_info_s* transfer_type_info); +int32_t msg_transfer_send_start(int32_t handle_id, uint16_t cu_flag); +int32_t msg_transfer_alloc_msg(int32_t handle_id, uint16_t cu_flag, uint32_t bufSize, char** buf, uint32_t* availableSize, uint32_t* offset); +int32_t msg_transfer_send_msg(int32_t handle_id, uint16_t cu_flag, uint8_t* msg_ptr, uint32_t offset, uint32_t msg_len); +int32_t msg_transfer_send_end(int32_t handle_id, uint16_t cu_flag); +int32_t msg_transfer_receive(int32_t handle_id, uint16_t cu_flag, uint32_t offset, uint32_t len, uint8_t** msg_ptr); +int32_t msg_transfer_close(int32_t handle_id); + +#endif + diff --git a/app/inc/msg_transfer_mbuffer.h b/app/inc/msg_transfer_mbuffer.h new file mode 100644 index 0000000..499813e --- /dev/null +++ b/app/inc/msg_transfer_mbuffer.h @@ -0,0 +1,37 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_transfer_mbuffer.h +// Author : xianfeng.du +// Created On : 2022-12-21 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __MSG_TRANSFER_MEM_BUFFER_H__ +#define __MSG_TRANSFER_MEM_BUFFER_H__ + +#include "typedef.h" + +typedef union tMsgMemBufAttribute{ + uint32_t ele[4]; //aligned + struct { + uint32_t msgSize; // in bytes + uint8_t qNo; + uint8_t state; + uint16_t idx; + //uint8_t msgType; // 0=data, 1=control + //uint8_t eop; + //uint8_t nSegs; + }; +} MsgMemBufAttr_t; + +#define MSG_MBUF_HEAD_SIZE (sizeof(MsgMemBufAttr_t)) +#define MSG_MBUF_ATTR(pBuf) ((MsgMemBufAttr_t *)((uint8_t *)pBuf - MSG_MBUF_HEAD_SIZE)) + +#endif + diff --git a/app/inc/msg_transfer_mem.h b/app/inc/msg_transfer_mem.h new file mode 100644 index 0000000..e8a255d --- /dev/null +++ b/app/inc/msg_transfer_mem.h @@ -0,0 +1,26 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_transfer_mem.h +// Author : xianfeng.du +// Created On : 2022-12-21 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __MSG_TRANSFER_MEM_H__ +#define __MSG_TRANSFER_MEM_H__ + +#include "msg_transfer_queue.h" + +MsgQueueLocalMgt_t* get_msg_queue_local_mgt(void); + +void msg_transfer_mem_init(void); + +#endif + + diff --git a/app/inc/msg_transfer_queue.h b/app/inc/msg_transfer_queue.h new file mode 100644 index 0000000..4774369 --- /dev/null +++ b/app/inc/msg_transfer_queue.h @@ -0,0 +1,88 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_transfer_queue.h +// Author : xianfeng.du +// Created On : 2022-12-21 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __MSG_TRANSFER_QUEUE_H__ +#define __MSG_TRANSFER_QUEUE_H__ + +#include "typedef.h" +#include "msg_transfer_layer.h" + +#define MAX_M_BUFFER_NUM 128 + +typedef enum eMsgQueueType { + UCP4008_TRAFFIC_NR_eMBB_DATA, + UCP4008_TRAFFIC_NR_eMBB_CTRL, + UCP4008_TRAFFIC_OAM, + UCP4008_TRAFFIC_MAX_NUM +} MsgQueueType_e; + +typedef struct tQueueCfg { + uint32_t block_size; + uint16_t block_num; + uint16_t rsv; + //msg_transfer_callback* tx_callback; + msg_transfer_callback rx_callback; +} QueueCfg_t; + +typedef struct tMsgQueueCfg { + HandleId_t handler; + QueueCfg_t tx_queue; + QueueCfg_t rx_queue; +} MsgQueueCfg_t; + +typedef struct tMsgQueueCommonInfo{ + uint32_t alloc; + uint32_t in; + uint32_t out; + uint32_t free; + + uint16_t ringSize; + uint16_t ringMask; + uint32_t bufBase; + uint32_t bufSize; + uint32_t bufIdxBase; +} MsgQueueCommonInfo_t; + +typedef struct tMsgQueueLocalInfo{ + uint8_t* bufBase; + uint8_t* bufIdxBase; + uint64_t bufAddr; + uint32_t availableSize; + uint32_t offset; + uint16_t idx; + uint16_t msgCnt; + uint8_t rsv[4]; +} MsgQueueLocalInfo_t; + +typedef struct tSyncInfo { + uint8_t queueCfgFlag; + uint8_t rsv[15]; +} SyncInfo_t; + +typedef struct tMsgQueueLocalMgt { + SyncInfo_t localSyncInfo; + MsgQueueCfg_t localQueueCfg[MAX_INSTANCE_NUM][UCP4008_TRAFFIC_MAX_NUM];//local + MsgQueueLocalInfo_t localDlQueue[MAX_INSTANCE_NUM][UCP4008_TRAFFIC_MAX_NUM]; //local + MsgQueueLocalInfo_t localUlQueue[MAX_INSTANCE_NUM][UCP4008_TRAFFIC_MAX_NUM]; //local +} MsgQueueLocalMgt_t; + +int32_t msg_queue_dl_block_init(uint8_t inst_id, uint8_t que_id); +int32_t msg_queue_dl_alloc_buf(uint8_t inst_id, uint8_t que_id); +int32_t msg_queue_dl_put_buf(uint8_t inst_id, uint8_t que_id); +uint8_t* msg_queue_ul_get_buf(uint8_t inst_id, uint8_t que_id); +void msg_transfer_queue_setup(uint8_t inst_id, uint8_t que_id); +void msg_transfer_queue_free(uint8_t inst_id, uint8_t que_id); + +#endif + diff --git a/app/inc/pet_sm_mgt.h b/app/inc/pet_sm_mgt.h new file mode 100644 index 0000000..27ad2e6 --- /dev/null +++ b/app/inc/pet_sm_mgt.h @@ -0,0 +1,34 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : pet_sm_mgt.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __PET_SHARE_MEM_MGT_H__ +#define __PET_SHARE_MEM_MGT_H__ + +#include "ucp_handshake.h" +#include "msg_transfer_queue.h" + +typedef struct tPetSmLocalMgt { + UcpHandshake_t* pHandshake;//common + SyncInfo_t* pSyncInfo;//common + uint16_t* pBufIdxBase;//common + MsgQueueCfg_t* pQueueCfg[MAX_INSTANCE_NUM][UCP4008_TRAFFIC_MAX_NUM];//common + MsgQueueCommonInfo_t* pDlQueue[MAX_INSTANCE_NUM][UCP4008_TRAFFIC_MAX_NUM];//common + MsgQueueCommonInfo_t* pUlQueue[MAX_INSTANCE_NUM][UCP4008_TRAFFIC_MAX_NUM];//common +} PetSmLocalMgt_t; + +void pet_sm_alloc(void); +PetSmLocalMgt_t* get_pet_sm_local_mgt(void); + +#endif + diff --git a/app/inc/typedef.h b/app/inc/typedef.h new file mode 100644 index 0000000..74b4889 --- /dev/null +++ b/app/inc/typedef.h @@ -0,0 +1,31 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : typedef.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __TYPEDEF_H__ +#define __TYPEDEF_H__ + +//Types definitions +//typedef unsigned char bool; +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef short int int16_t; +typedef unsigned short int uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef long int int64_t; +typedef unsigned long int uint64_t; +//typedef long long int int64_t; +//typedef unsigned long long int uint64_t; + +#endif diff --git a/app/inc/ucp_handshake.h b/app/inc/ucp_handshake.h new file mode 100644 index 0000000..8eb9eb0 --- /dev/null +++ b/app/inc/ucp_handshake.h @@ -0,0 +1,38 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ucp_handshake.h +// Author : xianfeng.du +// Created On : 2022-07-22 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __UCP_HANDSHAKE_H__ +#define __UCP_HANDSHAKE_H__ + +#include "typedef.h" + +#define MAX_NUM_SPU 12 +#define MAX_NUM_CORE (MAX_NUM_SPU+1) +#define NPU_CORE_ID MAX_NUM_SPU + +#define HANDSHKAE_REQ_VALUE 0x5A5A5A5A +#define HANDSHKAE_RESP_VALUE 0xA5A5A5A5 + +typedef struct tUcpHandshake{ + volatile uint32_t request[MAX_NUM_CORE]; + volatile uint32_t response[MAX_NUM_CORE]; + volatile uint32_t heartbeat[MAX_NUM_CORE]; +} UcpHandshake_t; + +void ucp_handshake(void); + +#endif + + + diff --git a/app/inc/ucp_printf.h b/app/inc/ucp_printf.h new file mode 100644 index 0000000..2d2fc20 --- /dev/null +++ b/app/inc/ucp_printf.h @@ -0,0 +1,74 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ucp_printf.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + + +#ifndef __UCP_RINTF_H__ +#define __UCP_RINTF_H__ + +#include +//#include + + +#define PRINT_OFF 0x00000000 // close all PRINT +#define PRINT_ERROR 0x00000001 +#define PRINT_WARN 0x00000002 +#define PRINT_DEBUG 0x00000004 +#define PRINT_LOG 0x00000008 +#define PRINT_TICK 0x00000010 + +//#define UCP_PRINT_LEVEL (PRINT_OFF) +#define UCP_PRINT_LEVEL (PRINT_ERROR | PRINT_WARN |PRINT_DEBUG|PRINT_LOG | PRINT_TICK) +//#define UCP_PRINT_LEVEL (PRINT_ERROR |PRINT_DEBUG| PRINT_SHELL) + +#if (UCP_PRINT_LEVEL & PRINT_ERROR) +//#define UCP_PRINT_ERROR(fmt, args...) printf(__FILE__ ": [ERROR]: %d: %s():" fmt "\n", __LINE__, __func__, ##args) +#define UCP_PRINT_ERROR(fmt, args...) osp_log_output(PRINT_ERROR, "[ERROR]:" fmt "\n", ##args) +#else +#define UCP_PRINT_ERROR(fmt, args...) +#endif + +#if (UCP_PRINT_LEVEL & PRINT_WARN) +//#define UCP_PRINT_WARN(fmt, args...) printf(__FILE__ ": [WARN]: %d: %s():" fmt "\n", __LINE__, __func__, ##args) +#define UCP_PRINT_WARN(fmt, args...) osp_log_output(PRINT_WARN, "[WARN]:" fmt "\n", ##args) +#else +#define UCP_PRINT_WARN(fmt, args...) +#endif + +#if (UCP_PRINT_LEVEL & PRINT_LOG) +//#define UCP_PRINT_LOG(fmt, args...) printf(__FILE__ ": [LOG]: %d: %s():" fmt "\n", __LINE__, __func__, ##args) +#define UCP_PRINT_LOG(fmt, args...) osp_log_output(PRINT_LOG, "[LOG]:" fmt "\n", ##args) +#else +#define UCP_PRINT_LOG(fmt, args...) +#endif + +#if (UCP_PRINT_LEVEL & PRINT_DEBUG) +//#define UCP_PRINT_LOG(fmt, args...) printf(__FILE__ ": [LOG]: %d: %s():" fmt "\n", __LINE__, __func__, ##args) +#define UCP_PRINT_DEBUG(fmt, args...) osp_log_output(PRINT_DEBUG, "[DEBUG]:" fmt "\n", ##args) +#else +#define UCP_PRINT_DEBUG(fmt, args...) +#endif + +#if (UCP_PRINT_LEVEL & PRINT_TICK) +//#define UCP_PRINT_TICK(fmt, args...) printf(__FILE__ ": [TICK]: %d: %s():" fmt "\n", __LINE__, __func__, ##args) +#define UCP_PRINT_TICK(fmt, args...) osp_log_output(PRINT_TICK, "[TICK]:" fmt "\n", ##args) +#else +#define UCP_PRINT_TICK(fmt, args...) +#endif + +#define UCP_PRINT_SHELL(fmt, args...) printf("[SHELL:]" fmt, ##args) + +extern void osp_log_output(unsigned char level, const char *fmt, ...); + + +#endif diff --git a/app/inc/ucp_utility.h b/app/inc/ucp_utility.h new file mode 100644 index 0000000..50dc98f --- /dev/null +++ b/app/inc/ucp_utility.h @@ -0,0 +1,41 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ucp_utility.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + + +#ifndef __UCP_UTILITY_H__ +#define __UCP_UTILITY_H__ + +#include "typedef.h" +#include "ospHeap.h" + +#ifdef UCP_SPIN_LOCK +#include +#define ucp_spin_lock(x) pthread_spin_lock((pthread_spinlock_t *)x) +#define ucp_spin_unlock(x) pthread_spin_unlock((pthread_spinlock_t *)x) +extern pthread_spinlock_t lock_dl_tx_alloc; +extern pthread_spinlock_t lock_dl_tx_put; +#else +#define ucp_spin_lock(x) +#define ucp_spin_unlock(x) +#endif +void ucp_spinlock_init(); + +int32_t isPowerOf2(uint32_t n); + +//cache +void ucp_cache_writeback(uint8_t* buf, uint32_t length); +void ucp_cache_invalid(uint8_t* buf, uint32_t length); +void ucp_cache_flush(uint8_t* buf, uint32_t length); + +#endif diff --git a/app/src/main.c b/app/src/main.c new file mode 100644 index 0000000..071d4ae --- /dev/null +++ b/app/src/main.c @@ -0,0 +1,83 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : main.c +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "ospLog.h" +#include "ospShell.h" +#include "ucp_printf.h" +#include "drv_init.h" + +#ifdef ENABLE_JESD_TEST +extern int32_t UCP_API_JESD_PlatformSetup (void); +extern int32_t UCP_API_TRANSCEIVER_Init(uint64_t txLo, uint64_t rxLo, uint64_t bw, uint16_t initAtt); +#endif + +int32_t test_case(uint32_t argc, int32_t* argvp); + +extern OSP_STATUS osp_init(); +extern uint8_t osp_sw_queue_init(); + + +#define MAX_PARA_NUM 4 +int32_t main(int32_t argc, char* argvp[]) +{ + //uint32_t stc_cnt = 0, stc_cnt1 = 0; + + UCP_PRINT_DEBUG("Hello world from A72."); + + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(4,&mask); + sched_setaffinity(0,sizeof(cpu_set_t),&mask); + +#ifdef ENABLE_JESD_TEST + UCP_API_JESD_PlatformSetup(); + UCP_API_TRANSCEIVER_Init(2575770000u, 2575770000u, 100000000u, 0); + usleep(100000); +#endif + + osp_init(); + drv_init(); + +#ifdef PALLADIUM_TEST + UCP_PRINT_DEBUG("entered testmode."); + + int32_t args[MAX_PARA_NUM]; + uint32_t count = argc - 1; + if(count > MAX_PARA_NUM) { + UCP_PRINT_ERROR("parameter number[%d] error",count); + return -1; + } + + for (uint32_t i=0; ibaseAddr = baseAddr; + memSecInfo->maxSize = maxSize; + memSecInfo->memSectionName = memSectionName; + + memSecInfo->currAddr = baseAddr; +} + +void memSectionReset(MEM_SECTION_INFO* memSecInfo) +{ + memSecInfo->currAddr = memSecInfo->baseAddr; +} + +void memSectionAllocPrint(MEM_SECTION_INFO* memSecInfo, uint32_t allocSize, char* varString) +{ +#if (UCP_PRINT_LEVEL & PRINT_DEBUG) + char* pMemSectionName = (char*)&memSecInfo->memSectionName[0]; +#endif + + UCP_PRINT_DEBUG("Memory Section - [%s]: Base Address: [0x%lx]; Maximum Size: [%8u]\n", + pMemSectionName, + memSecInfo->baseAddr, + memSecInfo->maxSize); + UCP_PRINT_DEBUG("Memory Section - [%s]: Variable Name: [%s]; Allocated Address: [0x%lx]; Allocated Size: [%6u]\n", + pMemSectionName, + varString, + memSecInfo->currAddr, + allocSize); +} + +void* memSectionAlloc(MEM_SECTION_INFO* memSecInfo, uint32_t allocSize, uint32_t allocAlign, char* varString) +{ + void* ret; + + uint64_t baseAddr = memSecInfo->baseAddr; + uint64_t currAddr = ((memSecInfo->currAddr + (allocAlign - 1)) / allocAlign) * allocAlign; + uint32_t maxSize = memSecInfo->maxSize; + + uint8_t* p = (uint8_t *)baseAddr; + uint32_t offset = currAddr - baseAddr; + + if ((offset + allocSize) <= maxSize) { + ret = (void*)&p[offset]; + + memSecInfo->currAddr = currAddr; + + /* disable as default since it cost much time. Could be enabled when needed. */ + memSectionAllocPrint(memSecInfo, allocSize, varString); + + memSecInfo->currAddr = currAddr + allocSize; + } else { + UCP_PRINT_ERROR("Memory Section - [%s]: Base Address: [0x%lx]; Maximum Size: [%8u]", + memSecInfo->memSectionName, + baseAddr, + maxSize); + + UCP_PRINT_ERROR("Memory Section - [%s]: Variable Name: [%s]; Allocated Address: [0x%lx]; Allocated Size: [%6u]", + memSecInfo->memSectionName, + varString, + currAddr, + allocSize); + + UCP_PRINT_ERROR("Can't allocate %u bytes in Memory Section - [%s] for Variable - [%s]!", allocSize, memSecInfo->memSectionName, varString); + ret = NULL; + } + + return ret; +} + +/*MEM_SECTION_INFO* GetEcsSramSection() +{ + return (MEM_SECTION_INFO*)&EcsSram; +}*/ + +MEM_SECTION_INFO* GetPetSramSection() +{ + return (MEM_SECTION_INFO*)&PetSram; +} + +MEM_SECTION_INFO* GetMsgDdrSection() +{ + return (MEM_SECTION_INFO*)&MsgDdrMem; +} + + diff --git a/app/src/msg_transfer_layer.c b/app/src/msg_transfer_layer.c new file mode 100644 index 0000000..8a65d84 --- /dev/null +++ b/app/src/msg_transfer_layer.c @@ -0,0 +1,277 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_transfer_layer.c +// Author : xianfeng.du +// Created On : 2022-06-29 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include "mem_sections.h" +#include "ucp_printf.h" +#include "pet_sm_mgt.h" +#include "msg_transfer_mem.h" +#include "msg_transfer_mbuffer.h" + +static inline int8_t get_queue_id(uint16_t type_id, uint16_t cu_flag) +{ + int8_t que_id = -1; + + switch (type_id) + { + case CU_SPLIT: + if (cu_flag == U_PLANE) { + que_id = UCP4008_TRAFFIC_NR_eMBB_DATA; + } else { + que_id = UCP4008_TRAFFIC_NR_eMBB_CTRL; + } + break; + case OAM: + que_id = UCP4008_TRAFFIC_OAM; + break; + default: + UCP_PRINT_ERROR("get_queue_id doesn't support transfer_type[%d] .",type_id); + break; + } + + return que_id; +} + +static inline void get_queue_info(uint16_t inst_id, uint16_t que_id, uint32_t handle_id, queue_info_s* queue_info) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueCfg_t* pLocalQueueCfg = (MsgQueueCfg_t *)&pMsgQueueLocalMgt->localQueueCfg[inst_id][que_id]; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCfg_t* pCommonQueueCfg = pPetSmLocalMgt->pQueueCfg[inst_id][que_id]; + + pLocalQueueCfg->handler.value = handle_id; + pLocalQueueCfg->tx_queue.block_num = queue_info->tx_block_num; + pLocalQueueCfg->tx_queue.block_size = queue_info->tx_block_size; + pLocalQueueCfg->rx_queue.block_num = queue_info->rx_block_num; + pLocalQueueCfg->rx_queue.block_size = queue_info->rx_block_size; + pLocalQueueCfg->rx_queue.rx_callback = queue_info->rx_callback; + memcpy((void *)&pCommonQueueCfg->handler, (void *)&pLocalQueueCfg->handler, sizeof(HandleId_t)); + memcpy((void *)&pCommonQueueCfg->tx_queue, (void *)&pLocalQueueCfg->rx_queue, sizeof(QueueCfg_t)); + memcpy((void *)&pCommonQueueCfg->rx_queue, (void *)&pLocalQueueCfg->tx_queue, sizeof(QueueCfg_t)); + + msg_transfer_queue_setup(inst_id, que_id); + + return; +} + +int32_t msg_transfer_init(uint16_t port_index, uint16_t transfer_type, uint16_t inst_id, const transfer_type_info_s* transfer_type_info) +{ + if (port_index >= MAX_PORT_NUM) + { + UCP_PRINT_ERROR("msg_transfer_init port_index[%d] error.",port_index); + return FAILURE; + } + + if (transfer_type > OAM) + { + UCP_PRINT_ERROR("msg_transfer_init transfer_type[%d] error.",transfer_type); + return FAILURE; + } + + if (inst_id >= MAX_INSTANCE_NUM) + { + UCP_PRINT_ERROR("msg_transfer_init inst_id[%d] error.",inst_id); + return FAILURE; + } + + uint16_t que_id; + HandleId_t handler; + + handler.port_id = (uint8_t)port_index; + handler.inst_id = (uint8_t)inst_id; + handler.type_id = (uint8_t)transfer_type; + + switch (transfer_type) + { + case CU_SPLIT: + que_id = UCP4008_TRAFFIC_NR_eMBB_DATA; + get_queue_info(inst_id, que_id, handler.value, (queue_info_s *)&transfer_type_info->queue_uplane_info); + + que_id = UCP4008_TRAFFIC_NR_eMBB_CTRL; + get_queue_info(inst_id, que_id, handler.value, (queue_info_s *)&transfer_type_info->queue_cplane_info); + break; + case OAM: + que_id = UCP4008_TRAFFIC_OAM; + get_queue_info(inst_id, que_id, handler.value, (queue_info_s *)&transfer_type_info->queue_cplane_info); + break; + default: + UCP_PRINT_ERROR("msg_transfer_init doesn't support transfer_type[%d] .",transfer_type); + //break; + return FAILURE; + } + + return (int32_t)handler.value; +} + +int32_t msg_transfer_send_start(int32_t handle_id, uint16_t cu_flag) +{ + HandleId_t handler; + handler.value= (uint32_t)handle_id; + //uint8_t port_id = handler.port_id; + uint8_t inst_id = handler.inst_id; + uint8_t type_id = handler.type_id; + + int8_t que_id = get_queue_id(type_id, cu_flag); + if (que_id < 0) + { + UCP_PRINT_ERROR("msg_transfer_send_start,UNINITIALIZED_QUEUE"); + return UNINITIALIZED_QUEUE; + } + msg_queue_dl_block_init(inst_id,que_id); + + return SUCCESS; +} + + +int32_t msg_transfer_alloc_msg(int32_t handle_id, uint16_t cu_flag, uint32_t bufSize, char** buf, uint32_t* availableSize, uint32_t* offset) +{ + HandleId_t handler; + handler.value= (uint32_t)handle_id; + //uint8_t port_id = handler.port_id; + uint8_t inst_id = handler.inst_id; + uint8_t type_id = handler.type_id; + int8_t que_id = get_queue_id(type_id, cu_flag); + + if (que_id < 0) + { + *(uint64_t *)buf = 0; + *availableSize = 0; + *offset = 0; + UCP_PRINT_ERROR("msg_transfer_alloc_msg,UNINITIALIZED_QUEUE"); + return UNINITIALIZED_QUEUE; + } + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t*)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id]; + + if (0 == ch->msgCnt) + { + msg_queue_dl_alloc_buf(inst_id,que_id); + } + *(uint64_t *)buf = ch->bufAddr + ch->offset; + *availableSize = ch->availableSize; + *offset = ch->offset; + ch->msgCnt++; + + UCP_PRINT_LOG("msg_transfer_alloc_msg,buf:0x%lx,availableSize:0x%08x,offset:0x%08x", *(uint64_t *)buf, ch->availableSize, ch->offset); + + return SUCCESS; +} + +int32_t msg_transfer_send_msg(int32_t handle_id, uint16_t cu_flag, uint8_t* msg_ptr, uint32_t offset, uint32_t msg_len) +{ + HandleId_t handler; + handler.value= (uint32_t)handle_id; + //uint8_t port_id = handler.port_id; + uint8_t inst_id = handler.inst_id; + uint8_t type_id = handler.type_id; + int8_t que_id = get_queue_id(type_id, cu_flag); + if (que_id < 0) { + UCP_PRINT_ERROR("msg_transfer_alloc_msg,UNINITIALIZED_QUEUE"); + return UNINITIALIZED_QUEUE; + } + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t*)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id]; + ch->availableSize -= msg_len; + ch->offset += msg_len; + + UCP_PRINT_LOG("msg_transfer_send_msg,buf:0x%lx,availableSize:0x%08x,offset:0x%08x", (ch->bufAddr+ch->offset), ch->availableSize, ch->offset); + + return SUCCESS; +} + +int32_t msg_transfer_send_end(int32_t handle_id, uint16_t cu_flag) +{ + HandleId_t handler; + handler.value= (uint32_t)handle_id; + //uint8_t port_id = handler.port_id; + uint8_t inst_id = handler.inst_id; + uint8_t type_id = handler.type_id; + + int8_t que_id = get_queue_id(type_id, cu_flag); + if (que_id < 0) + { + UCP_PRINT_ERROR("msg_transfer_send_end,UNINITIALIZED_QUEUE"); + return UNINITIALIZED_QUEUE; + } + msg_queue_dl_put_buf(inst_id,que_id); + + return SUCCESS; +} + +int32_t msg_transfer_receive(int32_t handle_id, uint16_t cu_flag, uint32_t offset, uint32_t len, uint8_t** msg_ptr) +{ + uint32_t handledLength = 0; + int32_t remainedLength = 0; + uint8_t *buf, *temp; + MsgMemBufAttr_t* mbuf; + + HandleId_t handler; + handler.value= (uint32_t)handle_id; + //uint8_t port_id = handler.port_id; + uint8_t inst_id = handler.inst_id; + uint8_t type_id = handler.type_id; + int8_t que_id = get_queue_id(type_id, cu_flag); + if (que_id < 0) + { + return UNINITIALIZED_QUEUE; + } + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueCfg_t* pQueueCfg = (MsgQueueCfg_t *)&pMsgQueueLocalMgt->localQueueCfg[inst_id][que_id]; + + buf = msg_queue_ul_get_buf(inst_id,que_id); + if (buf == NULL) + { + return EMPTY_QUEUE; + } + + //*msg_ptr = buf; + mbuf = MSG_MBUF_ATTR(buf); + remainedLength = mbuf->msgSize; + temp = buf; + do + { + handledLength = pQueueCfg->rx_queue.rx_callback((char *)temp, remainedLength); + remainedLength -= handledLength; + temp += handledLength; + } while(remainedLength > 0); + + return SUCCESS; +} + +int32_t msg_transfer_close(int32_t handle_id) +{ + HandleId_t handler; + handler.value= (uint32_t)handle_id; + //uint8_t port_id = handler.port_id; + uint8_t inst_id = handler.inst_id; + uint8_t type_id = handler.type_id; + + if (type_id == CU_SPLIT) + { + msg_transfer_queue_free(inst_id, UCP4008_TRAFFIC_NR_eMBB_DATA); + msg_transfer_queue_free(inst_id, UCP4008_TRAFFIC_NR_eMBB_CTRL); + } + else + { + msg_transfer_queue_free(inst_id, UCP4008_TRAFFIC_OAM); + } + + return SUCCESS; +} + diff --git a/app/src/msg_transfer_mem.c b/app/src/msg_transfer_mem.c new file mode 100644 index 0000000..bac8353 --- /dev/null +++ b/app/src/msg_transfer_mem.c @@ -0,0 +1,50 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : .c +// Author : xianfeng.du +// Created On : 2022-07-22 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include "mem_sections.h" +#include "msg_transfer_queue.h" +#include "ucp_printf.h" +#include "ucp_utility.h" +#include "ucp_handshake.h" +#include "ospHeap.h" +#include "pet_sm_mgt.h" + +MsgQueueLocalMgt_t gMsgQueueLocalMgt; +MsgQueueLocalMgt_t* get_msg_queue_local_mgt(void) +{ + return (MsgQueueLocalMgt_t *)&gMsgQueueLocalMgt; +} + +void msg_transfer_mem_init(void) +{ + UCP_PRINT_LOG("start initializing memory,limit[%lu]",sizeof(MsgQueueLocalMgt_t)); + + uint64_t length; + uint8_t* ptr = (uint8_t *)get_static_mem(ARM_APE_MSG,(uint64_t *)&length); + MEM_SECTION_INFO* pMemSection = GetMsgDdrSection(); + memSectionInit(pMemSection, (uint64_t)ptr, (uint32_t)length, pMemSection->memSectionName); + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + memset((void *)pMsgQueueLocalMgt,0,sizeof(MsgQueueLocalMgt_t)); + + pet_sm_alloc(); + + return; +} + + + + + diff --git a/app/src/msg_transfer_queue.c b/app/src/msg_transfer_queue.c new file mode 100644 index 0000000..a8ca707 --- /dev/null +++ b/app/src/msg_transfer_queue.c @@ -0,0 +1,277 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_queue_common.c +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include +#include "ospHeap.h" +#include "mem_sections.h" +#include "ucp_printf.h" +#include "ucp_utility.h" +#include "pet_sm_mgt.h" +#include "msg_transfer_mem.h" +#include "msg_transfer_mbuffer.h" + +static inline void* get_mbuf_ptr(uint8_t* base, uint32_t size, uint16_t idx) +{ + void *mbuf = (void *)(base + (size * idx)); + return mbuf; +} + +static inline void msg_queue_dl_setup(uint32_t instId, uint32_t qNo, uint8_t* bufBase, uint32_t bufSize, uint32_t numOfBufs) +{ + assert(isPowerOf2(numOfBufs)); + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t *)&pMsgQueueLocalMgt->localDlQueue[instId][qNo]; + ch->bufBase = bufBase; + uint64_t phy_addr; + osp_virt_to_phy(ARM_APE_MSG, (uint64_t)bufBase, (uint64_t *)&phy_addr); + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pDlQueue[instId][qNo]; + memset((void *)chCommon, 0, sizeof(MsgQueueCommonInfo_t)); + chCommon->ringSize = (uint16_t)numOfBufs; + chCommon->ringMask = (uint16_t)(numOfBufs - 1); + chCommon->bufBase = (uint32_t)phy_addr; + chCommon->bufSize = bufSize; + + uint8_t *m = bufBase; + MsgMemBufAttr_t *mbuf; + for (uint32_t k = 0; k < numOfBufs; k++) + { + mbuf = (MsgMemBufAttr_t *)m; + mbuf->qNo = (uint8_t)qNo; + mbuf->state = 1; + mbuf->idx = k; + m += bufSize; + } + + UCP_PRINT_LOG("Setup DL Queue[0x%08x] ch = 0x%lx", qNo, (uint64_t)chCommon); + UCP_PRINT_LOG("qNo = 0x%08x bufBase = 0x%lx bufSize = 0x%08x numOfBufs = 0x%08x",qNo, (uint64_t)bufBase, bufSize, numOfBufs); + + return; +} + +int32_t msg_queue_dl_block_init(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t*)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id]; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pDlQueue[inst_id][que_id]; + + ch->availableSize = chCommon->bufSize - MSG_MBUF_HEAD_SIZE; + ch->offset = 0; + ch->msgCnt = 0; + + return SUCCESS; +} + +int32_t msg_queue_dl_alloc_buf(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t*)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id]; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pDlQueue[inst_id][que_id]; + +#if 0 + ucp_spin_lock(&lock_dl_tx_alloc); + ch->idx = chCommon->alloc & chCommon->ringMask; + chCommon->alloc++; + ucp_spin_unlock(&lock_dl_tx_alloc); +#else + ch->idx = atomic_fetch_add(&chCommon->alloc,1) & chCommon->ringMask; +#endif + + MsgMemBufAttr_t *mbuf = (MsgMemBufAttr_t *)get_mbuf_ptr(ch->bufBase, chCommon->bufSize, ch->idx); + ch->bufAddr = (uint64_t)&mbuf[1]; + + UCP_PRINT_LOG("msg_queue_dl_alloc_buf,buf:0x%lx,availableSize:0x%08x,offset:0x%08x", ch->bufAddr, ch->availableSize, ch->offset); + + return SUCCESS; +} + +int32_t msg_queue_dl_put_buf(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t*)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id]; + if (ch->msgCnt == 0) + { + //ch->offset + return SUCCESS; + } + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pDlQueue[inst_id][que_id]; + + MsgMemBufAttr_t *mbuf = (MsgMemBufAttr_t *)get_mbuf_ptr(ch->bufBase, chCommon->bufSize, ch->idx); + mbuf->msgSize = ch->offset; + +#if 0 + ucp_spin_lock(&lock_dl_tx_put); + chCommon->in++; + ucp_spin_unlock(&lock_dl_tx_put); +#else + atomic_fetch_add(&chCommon->in,1); +#endif + + UCP_PRINT_LOG("msg_queue_dl_put_buf[%d] chCommon info alloc[%d],in[%d],out[%d]",que_id,chCommon->alloc,chCommon->in,chCommon->out); + + return SUCCESS; +} + +static inline void msg_queue_dl_free(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t *)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id]; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pDlQueue[inst_id][que_id]; + + memset((void *)ch, 0, sizeof(MsgQueueLocalInfo_t)); + memset((void *)chCommon, 0, sizeof(MsgQueueCommonInfo_t)); + + return; +} + +static inline void msg_queue_ul_setup(uint32_t instId, uint32_t qNo, uint8_t* bufBase, uint32_t bufSize, uint32_t numOfBufs) +{ + assert(isPowerOf2(numOfBufs)); + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t *)&pMsgQueueLocalMgt->localUlQueue[instId][qNo]; + ch->bufBase = bufBase; + uint64_t phy_addr; + osp_virt_to_phy(ARM_APE_MSG, (uint64_t)bufBase, (uint64_t *)&phy_addr); + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pUlQueue[instId][qNo]; + memset((void *)chCommon, 0, sizeof(MsgQueueCommonInfo_t)); + chCommon->ringSize = (uint16_t)numOfBufs; + chCommon->ringMask = (uint16_t)(numOfBufs - 1); + chCommon->bufBase = (uint32_t)phy_addr; + chCommon->bufSize = bufSize; + + osp_virt_to_phy(ECS_SM, (uint64_t)ch->bufIdxBase, (uint64_t *)&phy_addr); + chCommon->bufIdxBase = (uint32_t)phy_addr; + + uint8_t *m = bufBase; + MsgMemBufAttr_t *mbuf; + for (uint32_t k = 0; k < numOfBufs; k++) + { + mbuf = (MsgMemBufAttr_t *)m; + mbuf->qNo = (uint8_t)qNo; + mbuf->state = 1; + mbuf->idx = k; + m += bufSize; + } + + UCP_PRINT_LOG("Setup UL Queue[0x%08x] ch = 0x%lx", qNo, (uint64_t)chCommon); + UCP_PRINT_LOG("qNo = 0x%08x bufBase = 0x%lx bufSize = 0x%08x numOfBufs = 0x%08x",qNo, (uint64_t)bufBase, bufSize, numOfBufs); + + return; +} + + +uint8_t* msg_queue_ul_get_buf(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t*)&pMsgQueueLocalMgt->localUlQueue[inst_id][que_id]; + uint16_t* pIdxBase = (uint16_t *)ch->bufIdxBase; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pUlQueue[inst_id][que_id]; + + uint32_t avail = chCommon->in - chCommon->out; + if (0 == avail) + { + return NULL; + } + + uint16_t idx = chCommon->out & chCommon->ringMask; + uint16_t bufIdx = pIdxBase[idx]; + + MsgMemBufAttr_t *mbuf = (MsgMemBufAttr_t *)get_mbuf_ptr(ch->bufBase, chCommon->bufSize, bufIdx); + uint8_t *buf = (uint8_t *)&mbuf[1]; + chCommon->out++; + + return buf; +} + +static inline void msg_queue_ul_free(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueLocalInfo_t* ch = (MsgQueueLocalInfo_t *)&pMsgQueueLocalMgt->localUlQueue[inst_id][que_id]; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pPetSmLocalMgt->pUlQueue[inst_id][que_id]; + + memset((void *)ch, 0, sizeof(MsgQueueLocalInfo_t)); + memset((void *)chCommon, 0, sizeof(MsgQueueCommonInfo_t)); + + return; +} + +void msg_transfer_queue_setup(uint8_t inst_id, uint8_t que_id) +{ + MEM_SECTION_INFO* pMemSection = GetMsgDdrSection(); + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueCfg_t* pQueueCfg = (MsgQueueCfg_t *)&pMsgQueueLocalMgt->localQueueCfg[inst_id][que_id]; + memset((void *)&pMsgQueueLocalMgt->localDlQueue[inst_id][que_id],0,sizeof(MsgQueueLocalInfo_t)); + memset((void *)&pMsgQueueLocalMgt->localUlQueue[inst_id][que_id],0,sizeof(MsgQueueLocalInfo_t)); + + uint16_t block_num; + uint32_t block_size; + uint8_t* ptr; + + block_num = pQueueCfg->tx_queue.block_num; + block_size = pQueueCfg->tx_queue.block_size; + ptr = (uint8_t *)memSectionAlloc(pMemSection, block_num*block_size, MEM_ALIGNED_4BYTES, "dlAddr"); + msg_queue_dl_setup(inst_id, que_id, ptr, block_size, block_num); + + block_num = pQueueCfg->rx_queue.block_num; + block_size = pQueueCfg->rx_queue.block_size; + memset((void *)pPetSmLocalMgt->pBufIdxBase, 0, (block_num*sizeof(uint16_t))); + pMsgQueueLocalMgt->localUlQueue[inst_id][que_id].bufIdxBase = (uint8_t *)pPetSmLocalMgt->pBufIdxBase; + pPetSmLocalMgt->pBufIdxBase += block_num; + ptr = (uint8_t *)memSectionAlloc(pMemSection, block_num*block_size, MEM_ALIGNED_4BYTES, "ulAddr"); + msg_queue_ul_setup(inst_id, que_id, (uint8_t *)ptr, block_size, block_num); + + return; +} + + +void msg_transfer_queue_free(uint8_t inst_id, uint8_t que_id) +{ + MsgQueueLocalMgt_t* pMsgQueueLocalMgt = get_msg_queue_local_mgt(); + MsgQueueCfg_t* pLocalQueueCfg = (MsgQueueCfg_t *)&pMsgQueueLocalMgt->localQueueCfg[inst_id][que_id]; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + MsgQueueCfg_t* pCommonQueueCfg = pPetSmLocalMgt->pQueueCfg[inst_id][que_id]; + + memset((void *)pLocalQueueCfg, 0, sizeof(MsgQueueCfg_t)); + memset((void *)pCommonQueueCfg, 0, sizeof(MsgQueueCfg_t)); + + msg_queue_dl_free(inst_id,que_id); + msg_queue_ul_free(inst_id,que_id); + + return; +} + + diff --git a/app/src/pet_sm_mgt.s.c b/app/src/pet_sm_mgt.s.c new file mode 100644 index 0000000..dd8234e --- /dev/null +++ b/app/src/pet_sm_mgt.s.c @@ -0,0 +1,60 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2020 PicocomTech. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ecs_sm_mgt.c +// Author : xianfeng.du +// Created On : 2022-06-27 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include "ucp_printf.h" +#include "mem_sections.h" +#include "ucp_utility.h" +#include "pet_sm_mgt.h" +#include "ospHeap.h" + +PetSmLocalMgt_t gPetSmLocalMgt; +PetSmLocalMgt_t* get_pet_sm_local_mgt(void) +{ + return (PetSmLocalMgt_t *)&gPetSmLocalMgt; +} + +void pet_sm_alloc(void) +{ + UCP_PRINT_LOG("start allocating pet share memory"); + uint32_t i,j; + uint64_t length; + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + + uint8_t* ptr = (uint8_t *)get_static_mem(PET_SM,(uint64_t *)&length); + MEM_SECTION_INFO* pMemSection = GetPetSramSection(); + length = PET_SRAM_SIZE; + memSectionInit(pMemSection, (uint64_t)ptr, (uint32_t)length, pMemSection->memSectionName); + + pPetSmLocalMgt->pHandshake = (UcpHandshake_t *)memSectionAlloc(pMemSection, sizeof(UcpHandshake_t), MEM_ALIGNED_4BYTES, "pHandshake"); + pPetSmLocalMgt->pSyncInfo = (SyncInfo_t *)memSectionAlloc(pMemSection, sizeof(SyncInfo_t), MEM_ALIGNED_4BYTES, "pSyncInfo"); + pPetSmLocalMgt->pBufIdxBase = (uint16_t *)memSectionAlloc(pMemSection, MAX_INSTANCE_NUM*UCP4008_TRAFFIC_MAX_NUM*MAX_M_BUFFER_NUM*sizeof(uint16_t), MEM_ALIGNED_4BYTES, "pBufIdxBase"); + + for (i = 0; i < MAX_INSTANCE_NUM; i++) { + for (j = 0; j < UCP4008_TRAFFIC_MAX_NUM; j++) { + pPetSmLocalMgt->pQueueCfg[i][j] = (MsgQueueCfg_t *)memSectionAlloc(pMemSection, sizeof(MsgQueueCfg_t), MEM_ALIGNED_4BYTES, "pQueueCfg"); + } + } + + for (i = 0; i < MAX_INSTANCE_NUM; i++) { + for (j = 0; j < UCP4008_TRAFFIC_MAX_NUM; j++) { + pPetSmLocalMgt->pDlQueue[i][j] = (MsgQueueCommonInfo_t *)memSectionAlloc(pMemSection, sizeof(MsgQueueCommonInfo_t), MEM_ALIGNED_64BYTES, "pDlQueue"); + pPetSmLocalMgt->pUlQueue[i][j] = (MsgQueueCommonInfo_t *)memSectionAlloc(pMemSection, sizeof(MsgQueueCommonInfo_t), MEM_ALIGNED_64BYTES, "pUlQueue"); + } + } + + return; +} + + + diff --git a/app/src/ucp_handshake.c b/app/src/ucp_handshake.c new file mode 100644 index 0000000..3161086 --- /dev/null +++ b/app/src/ucp_handshake.c @@ -0,0 +1,44 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ucp_handshake.c +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include "ucp_printf.h" +#include "ucp_utility.h" +#include "ucp_handshake.h" +#include "msg_transfer_mem.h" +#include "pet_sm_mgt.h" + +//master is the core which controlled the handshake flow +void ucp_handshake(void) +{ + uint32_t core_id = NPU_CORE_ID; + uint32_t request= (core_id + HANDSHKAE_REQ_VALUE); + volatile uint32_t response; + + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + UcpHandshake_t* pHandshake = pPetSmLocalMgt->pHandshake; + + pHandshake->request[core_id] = request; + UCP_PRINT_DEBUG("core[0x%08x] sent handshake request message,value[0x%08x].",core_id,request); + + while(1) { + response = pHandshake->response[core_id]; + if (response == (core_id + HANDSHKAE_RESP_VALUE)) { + UCP_PRINT_DEBUG("core[0x%08x] recieved handshake response message,value[0x%08x].",core_id,response); + break; + } + } + + return; +} + diff --git a/app/src/ucp_utility.c b/app/src/ucp_utility.c new file mode 100644 index 0000000..c5e7e31 --- /dev/null +++ b/app/src/ucp_utility.c @@ -0,0 +1,65 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ucp_utility.c +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include "typedef.h" +#include "mem_sections.h" +#include "ucp_utility.h" +#include "ospHeap.h" + +#ifdef UCP_SPIN_LOCK +pthread_spinlock_t lock_dl_tx_alloc; +pthread_spinlock_t lock_dl_tx_put; +void ucp_spinlock_init() +{ + pthread_spin_init((pthread_spinlock_t *)&lock_dl_tx_alloc,PTHREAD_PROCESS_PRIVATE);//PTHREAD_PROCESS_SHARED + pthread_spin_init((pthread_spinlock_t *)&lock_dl_tx_put,PTHREAD_PROCESS_PRIVATE);// + return; +} +#else +void ucp_spinlock_init() +{ + return; +} +#endif + +int32_t isPowerOf2(uint32_t n) +{ + return n && !(n & (n - 1)); +} + +void ucp_cache_writeback(uint8_t* buf, uint32_t length) +{ +#ifdef CACHE_ENABLE + osp_clean_dcache_area((void*)buf, length); +#endif + return; +} + +void ucp_cache_invalid(uint8_t* buf, uint32_t length) +{ +#ifdef CACHE_ENABLE + osp_invalid_dcache_area(ARM_APE_MSG,(uint64_t)buf,length); +#endif + return; +} + +void ucp_cache_flush(uint8_t* buf, uint32_t length) +{ +#ifdef CACHE_ENABLE + osp_flush_dcache_area((void*)buf, length); +#endif + return; +} + + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..82808db --- /dev/null +++ b/build.sh @@ -0,0 +1,54 @@ +set -e + +usage() { + echo "usage: $0 [variants] [--cache] [--jesd] [--test caseid] " 1>&2 + msg=${1:-} + if [ ! -z "${msg}" ]; then + echo "error:$1" + fi + exit 1 +} + +variants= +fronthaul_option="cpri" +cache_option="no" +test_option="no" +case_id=0 + +while [[ "$#" > 0 ]]; do + case $1 in + --cache) cache_option="yes"; shift;; + + --cpri) fronthaul_option="cpri"; shift;; + --jesd) fronthaul_option="jesd"; shift;; + + --test) test_option="yes"; + if [[ ! -z "$2" ]] && [[ -n "$(echo $2 | sed -n " /^[0-9]\+$/p")" ]]; then + case_id=$2; shift; + fi + shift;; + + --*| -*) usage "unknown option $1"; exit 1;; + *) variants+=" $1"; shift;; + esac; +done + +export DIR_ROOT=$(cd `dirname "$0"`;pwd) +#echo "# script_dir:${DIR_ROOT}" +export RFIC_DIR=${DIR_ROOT}/driver/rfic +export BUILD_DIR=${DIR_ROOT}/build + +if [ -d ${BUILD_DIR} ]; then + rm -rf ${BUILD_DIR} +fi + +if [[ "${fronthaul_option}" == "jesd" ]]; then + cd ${RFIC_DIR}/ + make clean + make lib CROSS_CC=aarch64-linux-gnu- + cp ${RFIC_DIR}/librfic.a ${DIR_ROOT}/lib +fi + +cd ${DIR_ROOT}/ +make cache_option=${cache_option} fronthaul_option=${fronthaul_option} test_option=${test_option} test_id=${case_id} + diff --git a/driver/arm_csu/inc/arm_csu.h b/driver/arm_csu/inc/arm_csu.h new file mode 100644 index 0000000..01b4c4f --- /dev/null +++ b/driver/arm_csu/inc/arm_csu.h @@ -0,0 +1,73 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : arm_csu.h +// Author : xinxin.li +// Created On : 2022-11-23 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#ifndef _ARM_CSU_H_ +#define _ARM_CSU_H_ + +#include "typedef.h" + +#define CSU_DEV_MAP_LEN 0xA00 + +#define VIR_ADDR_VAL(base, offset) (*((volatile uint32_t*)(base+offset))) + +typedef struct _tagCsuDmaReg +{ + uint32_t dmaAddrL; + uint32_t dmaAddrH; + uint32_t dmaYStepL; + uint32_t dmaYStepH; + uint32_t dmaZStepL; + uint32_t dmaZStepH; + uint32_t dmaXNum; + uint32_t dmaYNum; + uint32_t dmaAllNum : 24; + uint32_t dmaGran : 4; + uint32_t dmaSize : 4; +}stCsuDmaReg; + +typedef struct _tagCsuDmaCmdL +{ + uint32_t rCmd : 2; + uint32_t wCmd : 2; + uint32_t dmaType : 1; + uint32_t cacheMode : 1; + uint32_t continueNext : 1; + uint32_t continueLast : 1; + uint32_t idSrc : 5; + uint32_t idDst : 5; + uint32_t dmaTag : 5; + uint32_t flush : 1; + uint32_t ecpriEnd : 3; + uint32_t zNumValid : 1; + uint32_t allOrYNum : 2; + uint32_t allNumSel : 1; + uint32_t stall : 1; +}stCsuDmaCmdL; + +int arm_csu_init(); + +// 0: not finished, 1: finished +int get_arm_csu_status(uint8_t tag); + +int arm_csu_wait_done(uint8_t tag); + +int arm_csu_wait_all_done(void); + +int get_free_reg_group(uint8_t tag); + +int get_free_channel(); + +int arm_csu_dma_1D_transfer(uint64_t addrSrc, uint64_t addrDst, uint32_t dataLen); + +#endif + diff --git a/driver/arm_csu/inc/memcpy_csu.h b/driver/arm_csu/inc/memcpy_csu.h new file mode 100644 index 0000000..9fc7822 --- /dev/null +++ b/driver/arm_csu/inc/memcpy_csu.h @@ -0,0 +1,29 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : memcpy_csu.h +// Author : xianfeng.du +// Created On : 2022-12-1 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#ifndef _MEMCPY_CSU_H_ +#define _MEMCPY_CSU_H_ + +#include "typedef.h" + +typedef enum eUcpMemCpyCsuType { + STACK2MSG, + MSG2STACK, + STACK2STACK +} UcpMemcpyCsuType_e; + +void memcpy_csu_stack2stack(uint64_t dst_phy_addr, uint64_t src_phy_addr, uint32_t size,uint8_t check_flag); +void memcpy_csu_stack_and_msg(uint64_t stack_phy_addr, uint64_t msg_virt_addr, uint32_t size,UcpMemcpyCsuType_e type, uint8_t check_flag); + +#endif + diff --git a/driver/arm_csu/inc/ucp_csu.h b/driver/arm_csu/inc/ucp_csu.h new file mode 100644 index 0000000..1cedc2b --- /dev/null +++ b/driver/arm_csu/inc/ucp_csu.h @@ -0,0 +1,203 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ucp_csu.h +// Author : xinxin.li +// Created On : 2022-11-23 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef _UCP_CSU_H_ +#define _UCP_CSU_H_ + +#define AP_CSU_BASE 0x04258000 + +#define AP_CSU_ALLPENDEVENTMASK (0x0*4) +#define AP_CSU_EVENTMASK (0x2*4) +#define AP_CSU_INTMASK (0x4*4) +#define AP_CSU_ELEVELMASK (0x5*4) +#define AP_CSU_TAGMASK0 (0x6*4) +#define AP_CSU_TAGMASK1 (0x7*4) +#define AP_CSU_TAGMASK2 (0x8*4) +#define AP_CSU_TAGMASK3 (0x9*4) +#define AP_CSU_ARMCMDRECV (0xA*4) +#define AP_CSU_FETCHMODE_CACHEMODE (0xB*4) +#define AP_CSU_ALLPENDEVENT0 (0xC*4) +#define AP_CSU_ALLPENDEVENT1 (0xD*4) +#define AP_CSU_EM_BS_SMSEL_PREDATANUM (0x10*4) +#define AP_CSU_FINDDMATAG (0x14*4) +#define AP_CSU_CMDFIFO0_CMD (0x18*4) +#define AP_CSU_CMDFIFO1_CMD (0x19*4) +#define AP_CSU_CMDFIFO2_CMD (0x1A*4) +#define AP_CSU_CMDFIFO3_CMD (0x1B*4) +#define AP_CSU_CMDFIFO0_NUM (0x1C*4) +#define AP_CSU_CMDFIFO1_NUM (0x1D*4) +#define AP_CSU_CMDFIFO2_NUM (0x1E*4) +#define AP_CSU_CMDFIFO3_NUM (0x1F*4) +#define AP_CSU_PRICMDVALID0 (0x20*4) +#define AP_CSU_PRICMDVALID1 (0x21*4) +#define AP_CSU_CMDECODATAL32BIT0 (0x24*4) +#define AP_CSU_CMDECODATAL32BIT1 (0x25*4) +#define AP_CSU_CMDHIGHDATA (0x28*4) +#define AP_CSU_CMDFIFO0 (0x2C*4) +#define AP_CSU_CMDFIFO1 (0x2D*4) +#define AP_CSU_CMDFIFO2 (0x2E*4) +#define AP_CSU_CMDFIFO3 (0x2F*4) +#define AP_CSU_CMDFIFO0_TAGNUM (0x34*4) +#define AP_CSU_CMDFIFO1_TAGNUM (0x35*4) +#define AP_CSU_CMDFIFO2_TAGNUM (0x36*4) +#define AP_CSU_CMDFIFO3_TAGNUM (0x37*4) +#define AP_CSU_DMASTATUS (0x38*4) + +#define AP_CSU_DMAADDRL0 (0x200*4) +#define AP_CSU_DMAADDRH0 (0x201*4) +#define AP_CSU_DMAYSTEPL0 (0x202*4) +#define AP_CSU_DMAYSTEPH0 (0x203*4) +#define AP_CSU_DMAZSTEPL0 (0x204*4) +#define AP_CSU_DMAZSTEPH0 (0x205*4) +#define AP_CSU_DMAYNUMXNUM0 (0x206*4) +#define AP_CSU_DMASIZEGRANALLNUM0 (0x207*4) + +#define AP_CSU_DMAADDRL1 (0x208*4) +#define AP_CSU_DMAADDRH1 (0x209*4) +#define AP_CSU_DMAYSTEPL1 (0x20A*4) +#define AP_CSU_DMAYSTEPH1 (0x20B*4) +#define AP_CSU_DMAZSTEPL1 (0x20C*4) +#define AP_CSU_DMAZSTEPH1 (0x20D*4) +#define AP_CSU_DMAYNUMXNUM1 (0x20E*4) +#define AP_CSU_DMASIZEGRANALLNUM1 (0x20F*4) + +#define AP_CSU_DMAADDRL2 (0x210*4) +#define AP_CSU_DMAADDRH2 (0x211*4) +#define AP_CSU_DMAYSTEPL2 (0x212*4) +#define AP_CSU_DMAYSTEPH2 (0x213*4) +#define AP_CSU_DMAZSTEPL2 (0x214*4) +#define AP_CSU_DMAZSTEPH2 (0x215*4) +#define AP_CSU_DMAYNUMXNUM2 (0x216*4) +#define AP_CSU_DMASIZEGRANALLNUM2 (0x217*4) + +#define AP_CSU_DMAADDRL3 (0x218*4) +#define AP_CSU_DMAADDRH3 (0x219*4) +#define AP_CSU_DMAYSTEPL3 (0x21A*4) +#define AP_CSU_DMAYSTEPH3 (0x21B*4) +#define AP_CSU_DMAZSTEPL3 (0x21C*4) +#define AP_CSU_DMAZSTEPH3 (0x21D*4) +#define AP_CSU_DMAYNUMXNUM3 (0x21E*4) +#define AP_CSU_DMASIZEGRANALLNUM3 (0x21F*4) + +#define AP_CSU_DMAADDRL4 (0x220*4) +#define AP_CSU_DMAADDRH4 (0x221*4) +#define AP_CSU_DMAYSTEPL4 (0x222*4) +#define AP_CSU_DMAYSTEPH4 (0x223*4) +#define AP_CSU_DMAZSTEPL4 (0x224*4) +#define AP_CSU_DMAZSTEPH4 (0x225*4) +#define AP_CSU_DMAYNUMXNUM4 (0x226*4) +#define AP_CSU_DMASIZEGRANALLNUM4 (0x227*4) + +#define AP_CSU_DMAADDRL5 (0x228*4) +#define AP_CSU_DMAADDRH5 (0x229*4) +#define AP_CSU_DMAYSTEPL5 (0x22A*4) +#define AP_CSU_DMAYSTEPH5 (0x22B*4) +#define AP_CSU_DMAZSTEPL5 (0x22C*4) +#define AP_CSU_DMAZSTEPH5 (0x22D*4) +#define AP_CSU_DMAYNUMXNUM5 (0x22E*4) +#define AP_CSU_DMASIZEGRANALLNUM5 (0x22F*4) + +#define AP_CSU_DMAADDRL6 (0x230*4) +#define AP_CSU_DMAADDRH6 (0x231*4) +#define AP_CSU_DMAYSTEPL6 (0x232*4) +#define AP_CSU_DMAYSTEPH6 (0x233*4) +#define AP_CSU_DMAZSTEPL6 (0x234*4) +#define AP_CSU_DMAZSTEPH6 (0x235*4) +#define AP_CSU_DMAYNUMXNUM6 (0x236*4) +#define AP_CSU_DMASIZEGRANALLNUM6 (0x237*4) + +#define AP_CSU_DMAADDRL7 (0x238*4) +#define AP_CSU_DMAADDRH7 (0x239*4) +#define AP_CSU_DMAYSTEPL7 (0x23A*4) +#define AP_CSU_DMAYSTEPH7 (0x23B*4) +#define AP_CSU_DMAZSTEPL7 (0x23C*4) +#define AP_CSU_DMAZSTEPH7 (0x23D*4) +#define AP_CSU_DMAYNUMXNUM7 (0x23E*4) +#define AP_CSU_DMASIZEGRANALLNUM7 (0x23F*4) + +#define AP_CSU_DMAADDRL8 (0x240*4) +#define AP_CSU_DMAADDRH8 (0x241*4) +#define AP_CSU_DMAYSTEPL8 (0x242*4) +#define AP_CSU_DMAYSTEPH8 (0x243*4) +#define AP_CSU_DMAZSTEPL8 (0x244*4) +#define AP_CSU_DMAZSTEPH8 (0x245*4) +#define AP_CSU_DMAYNUMXNUM8 (0x246*4) +#define AP_CSU_DMASIZEGRANALLNUM8 (0x247*4) + +#define AP_CSU_DMAADDRL9 (0x248*4) +#define AP_CSU_DMAADDRH9 (0x249*4) +#define AP_CSU_DMAYSTEPL9 (0x24A*4) +#define AP_CSU_DMAYSTEPH9 (0x24B*4) +#define AP_CSU_DMAZSTEPL9 (0x24C*4) +#define AP_CSU_DMAZSTEPH9 (0x24D*4) +#define AP_CSU_DMAYNUMXNUM9 (0x24E*4) +#define AP_CSU_DMASIZEGRANALLNUM9 (0x24F*4) + +#define AP_CSU_DMAADDRL10 (0x250*4) +#define AP_CSU_DMAADDRH10 (0x251*4) +#define AP_CSU_DMAYSTEPL10 (0x252*4) +#define AP_CSU_DMAYSTEPH10 (0x253*4) +#define AP_CSU_DMAZSTEPL10 (0x254*4) +#define AP_CSU_DMAZSTEPH10 (0x255*4) +#define AP_CSU_DMAYNUMXNUM10 (0x256*4) +#define AP_CSU_DMASIZEGRANALLNUM10 (0x257*4) + +#define AP_CSU_DMAADDRL11 (0x258*4) +#define AP_CSU_DMAADDRH11 (0x259*4) +#define AP_CSU_DMAYSTEPL11 (0x25A*4) +#define AP_CSU_DMAYSTEPH11 (0x25B*4) +#define AP_CSU_DMAZSTEPL11 (0x25C*4) +#define AP_CSU_DMAZSTEPH11 (0x25D*4) +#define AP_CSU_DMAYNUMXNUM11 (0x25E*4) +#define AP_CSU_DMASIZEGRANALLNUM11 (0x25F*4) + +#define AP_CSU_DMAADDRL12 (0x260*4) +#define AP_CSU_DMAADDRH12 (0x261*4) +#define AP_CSU_DMAYSTEPL12 (0x262*4) +#define AP_CSU_DMAYSTEPH12 (0x263*4) +#define AP_CSU_DMAZSTEPL12 (0x264*4) +#define AP_CSU_DMAZSTEPH12 (0x265*4) +#define AP_CSU_DMAYNUMXNUM12 (0x266*4) +#define AP_CSU_DMASIZEGRANALLNUM12 (0x267*4) + +#define AP_CSU_DMAADDRL13 (0x268*4) +#define AP_CSU_DMAADDRH13 (0x269*4) +#define AP_CSU_DMAYSTEPL13 (0x26A*4) +#define AP_CSU_DMAYSTEPH13 (0x26B*4) +#define AP_CSU_DMAZSTEPL13 (0x26C*4) +#define AP_CSU_DMAZSTEPH13 (0x26D*4) +#define AP_CSU_DMAYNUMXNUM13 (0x26E*4) +#define AP_CSU_DMASIZEGRANALLNUM13 (0x26F*4) + +#define AP_CSU_DMAADDRL14 (0x270*4) +#define AP_CSU_DMAADDRH14 (0x271*4) +#define AP_CSU_DMAYSTEPL14 (0x272*4) +#define AP_CSU_DMAYSTEPH14 (0x273*4) +#define AP_CSU_DMAZSTEPL14 (0x274*4) +#define AP_CSU_DMAZSTEPH14 (0x275*4) +#define AP_CSU_DMAYNUMXNUM14 (0x276*4) +#define AP_CSU_DMASIZEGRANALLNUM14 (0x277*4) + +#define AP_CSU_DMAADDRL15 (0x278*4) +#define AP_CSU_DMAADDRH15 (0x279*4) +#define AP_CSU_DMAYSTEPL15 (0x27A*4) +#define AP_CSU_DMAYSTEPH15 (0x27B*4) +#define AP_CSU_DMAZSTEPL15 (0x27C*4) +#define AP_CSU_DMAZSTEPH15 (0x27D*4) +#define AP_CSU_DMAYNUMXNUM15 (0x27E*4) +#define AP_CSU_DMASIZEGRANALLNUM15 (0x27F*4) + + + +#endif diff --git a/driver/arm_csu/src/arm_csu.c b/driver/arm_csu/src/arm_csu.c new file mode 100644 index 0000000..2c70797 --- /dev/null +++ b/driver/arm_csu/src/arm_csu.c @@ -0,0 +1,230 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : arm_csu.c +// Author : xinxin.li +// Created On : 2022-11-23 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#include "ucp_csu.h" +#include "arm_csu.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ucp_utility.h" +#include "ucp_printf.h" +#include "drv_init.h" + + +uint8_t* virMemAddr = NULL; +int arm_csu_init() +{ + if (-1 == g_drv_mem_fd) + { +// printf("open dev mem. \r\n"); + g_drv_mem_fd = open("/dev/mem", O_RDWR|O_SYNC); + if (0 > g_drv_mem_fd) + { + UCP_PRINT_ERROR("open /dev/mem error\n"); + return -1; + } + } + +// printf("start mmap. \r\n"); + virMemAddr = (uint8_t*)mmap(NULL, CSU_DEV_MAP_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, g_drv_mem_fd, AP_CSU_BASE); + if ((uint8_t*)(-1) == virMemAddr) + { + UCP_PRINT_ERROR("mmap error!!"); + return -1; + } + +// printf("csu init. \r\n"); + int i; + for (i = 0; i < 16; i++) + { + *((volatile uint32_t*)(virMemAddr+AP_CSU_DMAYNUMXNUM0) + (i<<3)) = ((4<<16)|1024); + *((volatile uint32_t*)(virMemAddr+AP_CSU_DMAYSTEPL0) + (i<<3)) = 1024; + *((volatile uint32_t*)(virMemAddr+AP_CSU_DMAYSTEPH0) + (i<<3)) = 0; + *((volatile uint32_t*)(virMemAddr+AP_CSU_DMAZSTEPL0) + (i<<3)) = 4096; + *((volatile uint32_t*)(virMemAddr+AP_CSU_DMAZSTEPH0) + (i<<3)) = 0; + } + + *((volatile uint32_t*)(virMemAddr+AP_CSU_EM_BS_SMSEL_PREDATANUM)) = (0x2A<<16) | (0x0<<14) | (0x5<<5) | 0x9; // (0x3F<<16); + *((volatile uint32_t*)(virMemAddr+AP_CSU_EM_BS_SMSEL_PREDATANUM)) = (0x2A<<16) | (0x1<<14) | (0x5<<5) | 0x9; + *((volatile uint32_t*)(virMemAddr+AP_CSU_EM_BS_SMSEL_PREDATANUM)) = (0x2A<<16) | (0x2<<14) | (0x5<<5) | 0x9; + *((volatile uint32_t*)(virMemAddr+AP_CSU_EM_BS_SMSEL_PREDATANUM)) = (0x2A<<16) | (0x3<<14) | (0x5<<5) | 0x9; + + *((volatile uint32_t*)(virMemAddr+AP_CSU_FINDDMATAG)) = 0x60; + *((volatile uint32_t*)(virMemAddr+AP_CSU_TAGMASK0)) = 0xFFFFFFFF; + *((volatile uint32_t*)(virMemAddr+AP_CSU_TAGMASK1)) = 0xFFFFFFFF; + *((volatile uint32_t*)(virMemAddr+AP_CSU_TAGMASK2)) = 0xFFFFFFFF; + *((volatile uint32_t*)(virMemAddr+AP_CSU_TAGMASK3)) = 0xFFFFFFFF; + + return 0; +} + +int get_arm_csu_status(uint8_t tag) +{ + if (31 < tag) + { + UCP_PRINT_ERROR("input para error! tag = %d. \r\n", tag); + return -1; + } + + uint32_t status = VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS); + return (status&(1<1) +//tag 4 5 6 7 1(2->3) +//tag 8 9 10 11 2(4->5) +//tag 12 13 14 15 3(6->7) +//tag 16 17 18 19 4(8->9) +//tag 20 21 22 23 5(10->11) +//tag 24 25 26 27 6(12->13) +//tag 28 29 30 31 7(14->15) + +// get unused register group according to tag number +int get_free_reg_group(uint8_t tag) +{ + if (31 < tag) + { + return -1; + } + + uint32_t dmaStatus = VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS); + uint8_t fifoNum = tag % 4; + uint8_t regGroup = tag / 4; + if (0 == (dmaStatus & (0xF<>16) & 0xFF; + int ret = regGroup | (fifoNum<<8) | (tag<<16); + return ret; + } + } + } + } +} + +int arm_csu_dma_1D_transfer(uint64_t addrSrc, uint64_t addrDst, uint32_t dataLen) +{ + uint8_t regGroup = 0; + uint8_t fifoNum = 0; + uint8_t tag = 0; + uint32_t temp = get_free_channel(); +// printf("get free channle: 0x%x. \r\n", temp); + + regGroup = temp & 0xFF; + fifoNum = (temp>>8) & 0xFF; + tag = (temp>>16)&0xFF; + + uint8_t offset = regGroup << 6; + // src reg + VIR_ADDR_VAL(virMemAddr, AP_CSU_DMAADDRL0 + offset) = addrSrc & 0xFFFFFFFF; + VIR_ADDR_VAL(virMemAddr, AP_CSU_DMAADDRH0 + offset) = addrSrc >> 32; + VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASIZEGRANALLNUM0 + offset) = (0xF<<28) | dataLen; + // dst reg + VIR_ADDR_VAL(virMemAddr, AP_CSU_DMAADDRL1 + offset) = addrDst & 0xFFFFFFFF; + VIR_ADDR_VAL(virMemAddr, AP_CSU_DMAADDRH1 + offset) = addrDst >> 32; + VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASIZEGRANALLNUM1 + offset) = (0xE<<24) | dataLen; // write global, size=0 + + VIR_ADDR_VAL(virMemAddr, AP_CSU_CMDHIGHDATA) = 0; + stCsuDmaCmdL dmaCmdL; + dmaCmdL.dmaType = 1; + dmaCmdL.idSrc = 0 + (regGroup<<1); + dmaCmdL.idDst = 1 + (regGroup<<1); + dmaCmdL.dmaTag = tag; + //(uint32_t)(VIR_ADDR_VAL(virMemAddr, AP_CSU_CMDFIFO0+(fifoNum<<2))) = (uint32_t)(*((uint32_t*)(&dmaCmdL))); + memcpy((uint32_t*)(virMemAddr+AP_CSU_CMDFIFO0+(fifoNum<<2)), (uint32_t*)(&dmaCmdL), 4); + + return tag; +} + + + diff --git a/driver/arm_csu/src/memcpy_csu.c b/driver/arm_csu/src/memcpy_csu.c new file mode 100644 index 0000000..b9866ab --- /dev/null +++ b/driver/arm_csu/src/memcpy_csu.c @@ -0,0 +1,68 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : arm_csu.c +// Author : xiafeng.du +// Created On : 2022-11-23 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#include "typedef.h" +#include "arm_csu.h" +#include "ospHeap.h" +#include "ucp_printf.h" +#include "memcpy_csu.h" + +//STACK mem type:cacheable, MSG mem type:non-cacheable, +//the function only works for the transfer between cacheable STACK mem and MSG non-cacheable mem +void memcpy_csu_stack2stack(uint64_t dst_phy_addr, uint64_t src_phy_addr, uint32_t size,uint8_t check_flag) +{ + uint8_t tag = arm_csu_dma_1D_transfer(src_phy_addr, dst_phy_addr, size); + + if (check_flag) + { + arm_csu_wait_done(tag); + } + return; +} + + +void memcpy_csu_stack_and_msg(uint64_t stack_phy_addr, uint64_t msg_virt_addr, uint32_t size,UcpMemcpyCsuType_e type, uint8_t check_flag) +{ + uint64_t msg_phy_addr = 0; + uint64_t src_phy_addr = 0; + uint64_t dst_phy_addr = 0; + uint8_t tag = 0; + + osp_virt_to_phy(ARM_APE_MSG, msg_virt_addr, &msg_phy_addr); + + switch(type) + { + case STACK2MSG: + src_phy_addr = stack_phy_addr; + dst_phy_addr = msg_phy_addr; + break; + case MSG2STACK: + src_phy_addr = msg_phy_addr; + dst_phy_addr = stack_phy_addr; + break; + default: + UCP_PRINT_ERROR("memcpy_csu type[%d] error.",type); + return; + //break; + } + tag = arm_csu_dma_1D_transfer(src_phy_addr, dst_phy_addr, size); + + if (check_flag) { + arm_csu_wait_done(tag); + } + return; +} + + + + diff --git a/driver/cache/Makefile b/driver/cache/Makefile new file mode 100644 index 0000000..01ade28 --- /dev/null +++ b/driver/cache/Makefile @@ -0,0 +1,25 @@ +export ARCH=arm64 +export CROSS_COMPILE=aarch64-linux-gnu- +#KERNELDIR = /public/liweihua/workspace/linux-5.15.40 +KERNELDIR = /public/liweihua/workspace/linux-5.10.165 +OBJ = SM_DDR + +PWD = $(shell pwd) +# Kernel modules +ifeq ($(OBJ),SM_DDR) + obj-m=ucp4008cache.o + #ucp4008cache-objs=osp_sm_ddr.o + #ucp4008cache-objs = cache.o osp_sm_ddr.o + ucp4008cache-y:=osp_sm_ddr.o cache.o +endif + +# Specify flags for the module compilation. +ccflags-y = -g -O0 +#INCLUDE += -l./../../common/ +build: kernel_modules +kernel_modules: + make -C $(KERNELDIR) M=$(PWD) modules +clean: + make -C $(KERNELDIR) M=$(PWD) clean + + diff --git a/driver/cache/cache.S b/driver/cache/cache.S new file mode 100644 index 0000000..833a460 --- /dev/null +++ b/driver/cache/cache.S @@ -0,0 +1,78 @@ +/* + * Cache maintenance + * + * Copyright (C) 2001 Deep Blue Solutions Ltd. + * Copyright (C) 2012 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +//#include +#include +#include + +/* + * dcache_line_size - get the safe D-cache line size across all CPUs + */ + .macro mydcache_line_size, reg, tmp + //read_ctr \tmp + mrs \tmp, ctr_el0 + ubfm \tmp, \tmp, #16, #19 // cache line size encoding + mov \reg, #4 // bytes per word + lsl \reg, \reg, \tmp // actual cache line size + .endm + +/* + * __inval_dcache_area(kaddr, size) + * + * Ensure that any D-cache lines for the interval [kaddr, kaddr+size) + * are invalidated. Any partial lines at the ends of the interval are + * also cleaned to PoC to prevent data loss. + * + * - kaddr - kernel address + * - size - size in question + */ +SYM_FUNC_START(__myinval_dcache_area) + /* FALLTHROUGH */ +/* + * __dma_inv_area(start, size) + * - start - virtual start address of region + * - size - size in question + */ +__mydma_inv_area: + add x1, x1, x0 + mydcache_line_size x2, x3 + sub x3, x2, #1 + tst x1, x3 // end cache line aligned? + bic x1, x1, x3 + b.eq 1f + dc civac, x1 // clean & invalidate D / U line +1: tst x0, x3 // start cache line aligned? + bic x0, x0, x3 + b.eq 2f + dc civac, x0 // clean & invalidate D / U line + b 3f +2: dc ivac, x0 // invalidate D / U line +3: add x0, x0, x2 + cmp x0, x1 + b.lo 2b + dsb sy + ret +//ENDPIPROC(__myinval_dcache_area) +//SYM_FUNC_END(__mydma_inv_area) +SYM_FUNC_END(__myinval_dcache_area) + + diff --git a/driver/cache/osp_sm_ddr.c b/driver/cache/osp_sm_ddr.c new file mode 100644 index 0000000..e193a17 --- /dev/null +++ b/driver/cache/osp_sm_ddr.c @@ -0,0 +1,532 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/*函数原型*/ +static int __init ucp_sm_ddr_module_init(void); +int ucp_sm_ddr_cache_open(struct inode *inode, struct file *filp); +int ucp_sm_ddr_noncache_open(struct inode *inode, struct file *filp); + +int ucp_sm_ddr_cache_release(struct inode *inode, struct file *filp); +int ucp_sm_ddr_noncache_release(struct inode *inode, struct file *filp); + +ssize_t ucp_sm_ddr_cache_read(struct file *filp, char __user *buf, size_t size_in, loff_t *ppos); +ssize_t ucp_sm_ddr_noncache_read(struct file *filp, char __user *buf, size_t size_in, loff_t *ppos); + +ssize_t ucp_sm_ddr_cache_write(struct file *filp, char __user *buf, size_t size, loff_t *ppos); +ssize_t ucp_sm_ddr_noncache_write(struct file *filp, char __user *buf, size_t size, loff_t *ppos); + +static long ucp_sm_ddr_cache_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); +static long ucp_sm_ddr_noncache_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); + +static int ucp_sm_ddr_cache_mmap(struct file *filp, struct vm_area_struct *vma); +static int ucp_sm_ddr_noncache_mmap(struct file *filp, struct vm_area_struct *vma); + +static ssize_t ucp_mem_show(struct device *dev,struct device_attribute *attr, char *buf); +static void __exit ucp_sm_ddr_module_exit(void); + +extern void __myinval_dcache_area(unsigned long vir_cache_add, unsigned long len); + + + +static const struct vm_operations_struct osp_mmap_mem_ops = { +#ifdef CONFIG_HAVE_IOREMAP_PROT + .access = generic_access_phys +#endif +}; + + + +/*申请设备名称*/ +#define DEVICE_NAME_SM_DDR_CACHE "ucp_sm_ddr_cache" +#define DEVICE_NAME_SM_DDR_NONCACHE "ucp_sm_ddr_noncache" + + +/*设备物理地址*/ +#if 1 //4008 add +#define ECS_SM_BASE 0x07200000ul +#define PET_SM_BASE 0x08700000ul +#define SHARE_SM_BASE 0x09d00000ul +#define DDR_BASE 0x10000000ul +#define ARM_APE_MSG_BASE_PHY_ADDR 0x0A0000000UL +#define ARM_STACK_BASE_PHY_ADDR 0x100000000UL //0x0B8000000UL + + + + + +/*size num*/ +#define S128KB 0x00020000ul // 128K +#define S8MB 0x00800000ul // 8M +#define S16GB 0x1F0000000ul //0x400000000ul // 16G +#define LEN_OF_ARM_STACK 0x100000000UL +#define LEN_OF_ARM_APE_MSG 0x008000000UL + + +/*设备空间大小*/ +#define ECS_SM_SIZE 0x000060000UL +#define ECS_SM_MAX 0x00725fffful + +#define PET_SM_SIZE 0x000060000UL +#define PET_SM_MAX 0x00875fffful + +#define SHARE_SM_SIZE S8MB +#define SHARE_SM_MAX 0x0a4ffffful + + +#define DDR_SIZE S16GB +#define DDR_MAX 0x1fffffffful + + +#endif + + +#if 0 //1002 add +#define ECS_SM_BASE 0x02360000ul +#define PET_SM_BASE 0x03860000ul + +#define SHARE_SM_BASE 0x04e60000ul +#define DDR_BASE 0x10000000ul + +#define S128KB 0x00020000ul // 128K +#define S8MB 0x00800000ul // 8M +#define S16GB 0x400000000ul // 16G + +#define ECS_SM_SIZE S128KB +#define ECS_SM_MAX 0x0237fffful + +#define PET_SM_SIZE S128KB +#define PET_SM_MAX 0x0387fffful + +#define SHARE_SM_SIZE S8MB +#define SHARE_SM_MAX 0x0565fffful + +#define DDR_SIZE S16GB + +#define DDR_MAX 0x40ffffffful + +#endif + + + +/*error num*/ +#define EINVAL 22 /* Invalid argument */ + + +/*全局变量声明初始化*/ + +/*file operation structure*/ +static const struct file_operations ucp_sm_ddr_cache_fops = +{ + .owner = THIS_MODULE, + .open = ucp_sm_ddr_cache_open, + .unlocked_ioctl = ucp_sm_ddr_cache_ioctl, + .mmap = ucp_sm_ddr_cache_mmap, + .release = ucp_sm_ddr_cache_release, +}; + +static const struct file_operations ucp_sm_ddr_noncache_fops = +{ + .owner = THIS_MODULE, + .open = ucp_sm_ddr_noncache_open, + .unlocked_ioctl = ucp_sm_ddr_noncache_ioctl, + .mmap = ucp_sm_ddr_noncache_mmap, + .release = ucp_sm_ddr_noncache_release, +}; + + + +static struct miscdevice ucp_sm_ddr_cache_miscdev = { + .minor = MISC_DYNAMIC_MINOR, + .name = DEVICE_NAME_SM_DDR_CACHE, + .fops = &ucp_sm_ddr_cache_fops, +}; + +static struct miscdevice ucp_sm_ddr_noncache_miscdev = { + .minor = MISC_DYNAMIC_MINOR, + .name = DEVICE_NAME_SM_DDR_NONCACHE, + .fops = &ucp_sm_ddr_noncache_fops, +}; + + +void __iomem * g_vir_ecs_sm_cache_add = NULL; +void __iomem * g_vir_pet_sm_cache_add = NULL; +void __iomem * g_vir_share_sm_cache_add = NULL; +void __iomem * g_vir_ddr_cache_add = NULL; +void __iomem * g_vir_msg_cache_add = NULL; +void __iomem * g_vir_stack_cache_add = NULL; + + + +static DEVICE_ATTR(ucp_sm_ddr_cache, S_IRUGO, ucp_mem_show, NULL); +static DEVICE_ATTR(ucp_sm_ddr_noncache, S_IRUGO, ucp_mem_show, NULL); + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver init function********************/ +/********************************************************************/ +static int __init ucp_sm_ddr_module_init(void) +{ + int iRet=0; + + /*注册 设备驱动*/ + iRet = misc_register(&ucp_sm_ddr_cache_miscdev); + if(iRet) + { + goto sm_ddr_misc_err; + } + iRet = misc_register(&ucp_sm_ddr_noncache_miscdev); + if(iRet) + { + goto sm_ddr_misc_err; + } + + /*在/sys/class 目录下创建对应的属性文件*/ + iRet = device_create_file(ucp_sm_ddr_cache_miscdev.this_device, &dev_attr_ucp_sm_ddr_cache); + if (iRet) + { + goto sm_ddr_cache_attr_err; + printk(KERN_EMERG "ucp_sm_ddr_cache_module_init failed \r\n"); + + } + + printk(KERN_EMERG "ucp_sm_ddr_cache_module_init ok cat /sys/devices/virtual/misc/ucp_sm_ddr_cache\r\n"); + + iRet = device_create_file(ucp_sm_ddr_noncache_miscdev.this_device, &dev_attr_ucp_sm_ddr_noncache); + if (iRet) + { + goto sm_ddr_noncache_attr_err; + printk(KERN_EMERG "ucp_sm_ddr_noncache_module_init failed \r\n"); + + } + + printk(KERN_EMERG "ucp_sm_ddr_noncache_module_init ok cat /sys/devices/virtual/misc/ucp_sm_ddr_noncache\r\n"); + + g_vir_ecs_sm_cache_add = ioremap(ECS_SM_BASE, ECS_SM_SIZE); + + g_vir_pet_sm_cache_add = ioremap(PET_SM_BASE, PET_SM_SIZE); + + g_vir_share_sm_cache_add = ioremap(SHARE_SM_BASE, SHARE_SM_SIZE); + + g_vir_msg_cache_add = ioremap(ARM_APE_MSG_BASE_PHY_ADDR, LEN_OF_ARM_APE_MSG); + g_vir_stack_cache_add = ioremap(ARM_STACK_BASE_PHY_ADDR, LEN_OF_ARM_STACK); + + + printk(KERN_EMERG "globle g_vir_ecs_sm_cache_add = 0x%lx \n ",(uint64_t)g_vir_ecs_sm_cache_add); + + printk(KERN_EMERG "globle g_vir_pet_sm_cache_add = 0x%lx \n ",(uint64_t)g_vir_pet_sm_cache_add); + + printk(KERN_EMERG "globle g_vir_share_sm_cache_add = 0x%lx \n ",(uint64_t)g_vir_share_sm_cache_add); + + //printk(KERN_EMERG "globle g_vir_ddr_cache_add = 0x%lx \n ",g_vir_ddr_cache_add); + + printk(KERN_EMERG "globle g_vir_msg_cache_add = 0x%lx \n ",(uint64_t)g_vir_msg_cache_add); + + printk(KERN_EMERG "globle g_vir_stack_cache_add = 0x%lx \n ",(uint64_t)g_vir_stack_cache_add); + + return 0; + +sm_ddr_cache_attr_err: + misc_deregister(&ucp_sm_ddr_cache_miscdev); +sm_ddr_noncache_attr_err: + misc_deregister(&ucp_sm_ddr_noncache_miscdev); +sm_ddr_misc_err: + return -EINVAL; +} +/********************************************************************/ +/********************************************************************/ + + + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver open function********************/ +/********************************************************************/ +int ucp_sm_ddr_cache_open(struct inode *inode, struct file *filp) +{ + /* device structure pointer assgined to file private data pointer */ + printk("enter %s\n",__func__); + return 0; +} +int ucp_sm_ddr_noncache_open(struct inode *inode, struct file *filp) +{ + /* device structure pointer assgined to file private data pointer */ + printk("enter %s\n",__func__); + return 0; +} + +/********************************************************************/ +/********************************************************************/ + + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver release function*******************/ +/********************************************************************/ +int ucp_sm_ddr_cache_release(struct inode *inode, struct file *filp) +{ + return 0; +} +int ucp_sm_ddr_noncache_release(struct inode *inode, struct file *filp) +{ + return 0; +} + +/********************************************************************/ +/********************************************************************/ + + + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver read function*******************/ +/********************************************************************/ +ssize_t ucp_sm_ddr_cache_read(struct file *filp, char __user *buf, size_t size_in, loff_t *ppos) +{ + return 0; +} +ssize_t ucp_sm_ddr_noncache_read(struct file *filp, char __user *buf, size_t size_in, loff_t *ppos) +{ + return 0; +} + +/********************************************************************/ +/********************************************************************/ + + + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver write function*******************/ +/********************************************************************/ +ssize_t ucp_sm_ddr_cache_write(struct file *filp, char __user *buf, size_t size, loff_t *ppos) +{ + return 0; +} +ssize_t ucp_sm_ddr_noncache_write(struct file *filp, char __user *buf, size_t size, loff_t *ppos) +{ + return 0; +} + +/********************************************************************/ +/********************************************************************/ + + + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver ioctl function*******************/ +/********************************************************************/ +static long ucp_sm_ddr_cache_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + + void __iomem *vir_cache_add = NULL; + + unsigned long uiOffset= 0, addr = arg, len = cmd; + + + //printk("enter %s\n\n",__func__); + + //printk("addr = %#lx len = %#lx\n\n",cmd,arg); + + if(addr >= ECS_SM_BASE && addr <= ECS_SM_MAX) + { + + uiOffset = addr - ECS_SM_BASE; + + vir_cache_add = g_vir_ecs_sm_cache_add + uiOffset ; + + } + else if(addr >= PET_SM_BASE && addr <= PET_SM_MAX) + { + + uiOffset = addr - PET_SM_BASE; + + vir_cache_add = g_vir_pet_sm_cache_add + uiOffset ; + + } + else if(addr >= SHARE_SM_BASE && addr <= SHARE_SM_MAX) + { + + uiOffset = addr - SHARE_SM_BASE; + + vir_cache_add = g_vir_share_sm_cache_add + uiOffset ; + + } + else if(addr >= ARM_APE_MSG_BASE_PHY_ADDR && addr < ARM_APE_MSG_BASE_PHY_ADDR + LEN_OF_ARM_APE_MSG) + { + + uiOffset = addr - ARM_APE_MSG_BASE_PHY_ADDR; + + vir_cache_add = g_vir_msg_cache_add + uiOffset ; + } + else if(addr >= ARM_STACK_BASE_PHY_ADDR && addr < ARM_STACK_BASE_PHY_ADDR + LEN_OF_ARM_STACK) + { + + uiOffset = addr - ARM_STACK_BASE_PHY_ADDR; + + vir_cache_add = g_vir_stack_cache_add + uiOffset ; + } + else + { + + printk("ucp_sm_ddr_cache_ioctl phy add out of range \n "); + + return -1; + } + + //__mydma_inv_area(vir_cache_add, arg); + __myinval_dcache_area((unsigned long)vir_cache_add, len); + + + return 0; +} + +static long ucp_sm_ddr_noncache_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + return 0; +} + +/********************************************************************/ +/********************************************************************/ + + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver mmap function*******************/ +/********************************************************************/ +static int ucp_sm_ddr_cache_mmap(struct file *filp, struct vm_area_struct *vma) +{ + + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; + unsigned long vmsize = vma->vm_end - vma->vm_start; + unsigned long psize = PAGE_SIZE - offset; + pgprot_t prot = vma->vm_page_prot; + + /* 设置IO标志 */ + + /*if(vmsize > psize) { + + return -ENXIO; + }*/ + printk("enter %s,phyaddr = %#lx,vm_start = %#lx\n",__func__,offset,vma->vm_start); + //printk(KERN_EMERG "titan : cached mode is cache \n"); + //printk(KERN_EMERG "titan : vma->vm_pgoff = 0x%x \n",offset); + + vma->vm_ops = &osp_mmap_mem_ops; + + if(remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, vmsize, prot) != 0) { + + return -EAGAIN; + } + + //printk(KERN_EMERG "titan : vma->vm_start = 0x%x \n",vma->vm_start); + + return 0; + + +} + +static int ucp_sm_ddr_noncache_mmap(struct file *filp, struct vm_area_struct *vma) +{ + + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; + unsigned long vmsize = vma->vm_end - vma->vm_start; + unsigned long psize = PAGE_SIZE - offset; + pgprot_t prot = vma->vm_page_prot; + + /* 设置IO标志 */ + +// vir_sm_noncache_add = ioremap_nocache(SM_BASE, SM_SIZE); + +// vir_ddr_noncache_add = ioremap_nocache(DDR_BASE, DDR_SIZE); + + + /*if(vmsize > psize) { + + return -ENXIO; + } */ + printk("enter %s,phyaddr = %#lx,vm_start = %#lx\n",__func__,offset,vma->vm_start); + + //printk(KERN_EMERG "titan : vma->vm_pgoff = 0x%x \n",offset); + + prot = pgprot_writecombine(prot); + + vma->vm_ops = &osp_mmap_mem_ops; + + //printk(KERN_EMERG "titan : cached mode is non cache \n"); + + if(remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, vmsize, prot) != 0) { + + return -EAGAIN; + } + + return 0; +} + + +/********************************************************************/ +/********************************************************************/ +static ssize_t ucp_mem_show(struct device *dev,struct device_attribute *attr, char *buf) +{ + return 0; +} + +/********************************************************************/ +/*********************sm0~sm5 & ddr driver exit function*******************/ +/********************************************************************/ +/* module unload function*/ +static void __exit ucp_sm_ddr_module_exit(void) +{ + + iounmap(g_vir_ecs_sm_cache_add); + iounmap(g_vir_pet_sm_cache_add); + iounmap(g_vir_share_sm_cache_add); + iounmap(g_vir_ddr_cache_add); + + + device_remove_file(ucp_sm_ddr_cache_miscdev.this_device, &dev_attr_ucp_sm_ddr_cache); + device_remove_file(ucp_sm_ddr_noncache_miscdev.this_device, &dev_attr_ucp_sm_ddr_noncache); + + + misc_deregister(&ucp_sm_ddr_cache_miscdev); + misc_deregister(&ucp_sm_ddr_noncache_miscdev); + + + +} +/********************************************************************/ +/********************************************************************/ + + +/* + * a simple char device driver: ExtInt without mutex + * + * Copyright (C) 2014 Barry Song (baohua@kernel.org) + * + * Licensed under GPLv2 or later. + */ + + +MODULE_AUTHOR ("lte team"); +MODULE_DESCRIPTION ("ucp_sm_ddr driver module" ); +MODULE_LICENSE ("GPL"); +module_init(ucp_sm_ddr_module_init); +module_exit(ucp_sm_ddr_module_exit); +MODULE_INFO(intree, "Y"); + + + + + + + + diff --git a/driver/init/inc/drv_init.h b/driver/init/inc/drv_init.h new file mode 100644 index 0000000..380e58a --- /dev/null +++ b/driver/init/inc/drv_init.h @@ -0,0 +1,17 @@ +#ifndef _DRV_INIT_H_ +#define _DRV_INIT_H_ + +#include "typedef.h" + +extern int32_t g_drv_mem_fd; + +#define STC_REG_BASE_ADDR (0x08568000) +#define STC_REG_LEN (0x08000) +#define STC_LTBG_REG_OFFSET 0x1005 + +int32_t drv_init(void); +uint64_t get_arm_cycle(); +uint32_t read_stc_local_timer(); + +#endif + diff --git a/driver/init/src/drv_init.s.c b/driver/init/src/drv_init.s.c new file mode 100644 index 0000000..73a0574 --- /dev/null +++ b/driver/init/src/drv_init.s.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +//#include +#include +#include +#include "drv_init.h" +#include "arm_csu.h" +#include "ucp_printf.h" + +#ifdef ENABLE_JESD_TEST + +#endif + +int32_t g_drv_mem_fd = -1; +uint32_t *g_stc_regs_ptr = NULL; //0x08568000 + +uint64_t get_arm_cycle() +{ + uint64_t cycle; + + asm volatile("mrs %0, pmccntr_el0" : "=r" (cycle)); + + return cycle; +} + +uint32_t read_stc_local_timer() +{ + return *(g_stc_regs_ptr + STC_LTBG_REG_OFFSET); +} + +int32_t init_stc() +{ + if(g_drv_mem_fd < 0) + { + g_drv_mem_fd = open("/dev/mem", O_RDWR|O_SYNC); + if(g_drv_mem_fd < 0) + { + UCP_PRINT_ERROR("open /dev/mem error"); + return -1; + } + } + + if(g_stc_regs_ptr == NULL) + { + g_stc_regs_ptr = mmap(NULL, STC_REG_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, + g_drv_mem_fd, STC_REG_BASE_ADDR); + if(-1 == (int64_t)g_stc_regs_ptr) + { + UCP_PRINT_ERROR("mmap stc regs error!! return = %ld\n",(uint64_t)g_stc_regs_ptr); + return -2; + } + } + + return 0; +} + +int32_t drv_init(void) +{ + if(0 != arm_csu_init()) + { + UCP_PRINT_ERROR("Init arm csu error!!"); + return -1; + } + + if(0 != init_stc()) + { + UCP_PRINT_ERROR("Init stc error!!"); + return -3; + } + + return 0; +} + diff --git a/driver/ioreg/Makefile b/driver/ioreg/Makefile new file mode 100644 index 0000000..67219d6 --- /dev/null +++ b/driver/ioreg/Makefile @@ -0,0 +1,20 @@ +export ARCH = arm64 +export CROSS_COMPILE = aarch64-linux-gnu- + +ARCH=arm64 +CROSS_COMPILE = aarch64-linux-gnu- + +KERNELDIR ?= /public/linboheng/workspace/ucp4008_nr_integrated_small_cell_new_kernel/kernel/linux-5.10.165 +PWD = $(shell pwd) +obj-m := ioreg.o + +# Specify flags for the module compilation. +ccflags-y = -g -O0 + +build: kernel_modules +kernel_modules: + make -C $(KERNELDIR) M=$(PWD) modules +clean: + make -C $(KERNELDIR) M=$(PWD) clean + + diff --git a/driver/ioreg/ioreg.c b/driver/ioreg/ioreg.c new file mode 100644 index 0000000..4064b76 --- /dev/null +++ b/driver/ioreg/ioreg.c @@ -0,0 +1,182 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#define IOCTL_MMAPREG _IO('k',0x20) + + +#define DEVICE_NAME "ioreg" + +void __iomem * addr; + +/*file open function*/ +int ioreg_open(struct inode *inode, struct file *filp) +{ + /* device structure pointer assgined to file private data pointer */ + return 0; +} + +/*file release function*/ +int ioreg_release(struct inode *inode, struct file *filp) +{ + return 0; +} + +/* ioctl device control function */ +static long ioreg_ioctl(struct file *filp, u32 cmd, unsigned long arg) +{ + + u32 val; + + + switch ((int)cmd) + { + + case IOCTL_MMAPREG: + get_user(val, (unsigned long *)arg); + addr = ioremap(val, 4096); + + break; + + + + default: + return - EINVAL; + } + + return 0; +} + +ssize_t ioreg_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos) +{ + + if (copy_to_user(buf, (void *)(addr), size)) + { + + return -EFAULT; + } + iounmap(addr); + return 0; +} + +ssize_t ioreg_write(struct file *filp,const char __user *buf, size_t size, loff_t *ppos) +{ + if(copy_from_user((void *)(addr), buf, size)) + { + + return -EFAULT; + } + + + iounmap(addr); + return 0; +} + +/*file operation structure*/ +static const struct file_operations ioreg_fops = +{ + .owner = THIS_MODULE, + .open = ioreg_open, + .read = ioreg_read, + .write = ioreg_write, + .unlocked_ioctl = ioreg_ioctl, + .release = ioreg_release, +}; + + + + +static struct miscdevice ioreg_miscdev = { + .minor = MISC_DYNAMIC_MINOR, + .name = DEVICE_NAME, + .fops = &ioreg_fops, +}; + + + + + + +static int __init ioreg_module_init(void) +{ + + struct device_node *np; + int ret; + + + ret = misc_register(&ioreg_miscdev); + if(ret) + { + return -1; + + } + + + printk(KERN_EMERG "ioreg_module_init ok "); + + return 0; + +} + +/* module unload function*/ +static void __exit ioreg_module_exit(void) +{ + + misc_deregister(&ioreg_miscdev); + +} + + + + + + +/* + * a simple char device driver: ExtInt without mutex + * + * Copyright (C) 2014 Barry Song (baohua@kernel.org) + * + * Licensed under GPLv2 or later. + */ + + +MODULE_AUTHOR ("lte team"); +MODULE_DESCRIPTION ("FRAME_SYNC driver module" ); +MODULE_LICENSE ("GPL"); +module_init(ioreg_module_init); +module_exit(ioreg_module_exit); + + + + + + + + + diff --git a/driver/mem_dump/mem_dump.c b/driver/mem_dump/mem_dump.c new file mode 100644 index 0000000..565f601 --- /dev/null +++ b/driver/mem_dump/mem_dump.c @@ -0,0 +1,288 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include //remap_pfn_range + +/* 主设备号 */ +#define BSP_DEV_MAJOR 0 +/* 主设备名 */ +#define BSP_DEV_NAME "mem_dump" + +/* 模块加载函数 */ +static int osp_mem_init(void); +/* 模块卸载函数 */ +static void osp_mem_exit(void); +/* 打开设备函数 */ +int mem_bsp_open(struct inode *inode, struct file *filp); +/* 释放设备函数 */ +int mem_bsp_release(struct inode *inode, struct file *filp); +/* 读函数 */ +static ssize_t mem_bsp_read (struct file *filp, __user char *buf, size_t count, loff_t *f_pos); +/* ioctl函数 */ +long mem_bsp_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); +/* mmap函数 */ +int mem_bsp_mmap(struct file *filp, struct vm_area_struct *vma); +/* 写函数 */ +ssize_t mem_bsp_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos); + + + +/******************************* 局部宏定义 ***********************************/ +/* bsp 主设备号 */ + + +typedef struct mem_struct{ + int g_s32BspDevMajor ; + unsigned int g_u32CacheCoherent; + struct cdev g_struBspDev; + struct class *cls; + dev_t g_devno; + struct device *parent; + struct device *this_device; + +}mem_st; + + +/******************************* 函数实现 *************************************/ +/******************************************************************************* +* 函数名: mem_init +* 描述: 模块加载时的入口函数 +* 相关文档: +* 函数存储类型:int +* 参数: 无 +* 返回值: +* 0 成功 +* <0 失败 +* 说明:具体失败参考Linux错误信息头文件 +*******************************************************************************/ + +static mem_st mem_dev ={ + .g_s32BspDevMajor = 0, + .g_u32CacheCoherent = 0, + .g_devno = 0, + + +}; + +static struct file_operations g_struBspOp = { + .owner = THIS_MODULE, + .read = mem_bsp_read, + .write = mem_bsp_write, + .open = mem_bsp_open, + .release = mem_bsp_release, + .mmap = mem_bsp_mmap, + .unlocked_ioctl = mem_bsp_ioctl, +}; + +static int osp_mem_init(void) +{ + /*函数调用结果*/ + int result; + /*设备编号*/ + dev_t devno; + + printk("bsp_init.\n"); + + /* 获取设备号 */ + if (0 == mem_dev.g_s32BspDevMajor) + { + /* 分配设备区域 */ + result = alloc_chrdev_region(&devno, 0, 1, BSP_DEV_NAME); + + /* 判断返回值 */ + if (result < 0) + { + printk(KERN_WARNING "bsp: alloc_chrdev_region error! errno = %d\n", result); + return result; + } + mem_dev.g_devno = devno; + /* 保存主设备号信息 */ + mem_dev.g_s32BspDevMajor = MAJOR(devno); + + /* 初始化dev变量 */ + cdev_init(&(mem_dev.g_struBspDev), &g_struBspOp); + /* 设备dev相应变量值 */ + mem_dev.g_struBspDev.owner = THIS_MODULE; + mem_dev.g_struBspDev.ops = &g_struBspOp; + /* 向系统增加dev设备 */ + result = cdev_add(&mem_dev.g_struBspDev, devno, 1); + if (result < 0) + { + printk ("cdev_add error!errno = %d", result); + } + + // ret = device_create_file(ucp_smem_miscdev.this_device, &dev_attr_ucp_smem); + mem_dev.cls = class_create(THIS_MODULE, "mem_dump"); + device_create(mem_dev.cls, NULL, devno, NULL, "mem_dump"); + + printk("bsp module init success!\n"); + /* 返回成功 */ + return 0; + } + else + { + printk("bsp module already init!\n"); + /* 返回 */ + return -EBUSY; + } +} + +/******************************************************************************* +* 函数名: ad9371_exit +* 描述: 模块卸载函数 +* 相关文档: +* 函数存储类型:void +* 参数: 无 +* 返回值: 无 +* 说明: +*******************************************************************************/ +static void osp_mem_exit(void) +{ + /* 判断是否执行过模块加载 */ + if(mem_dev.g_s32BspDevMajor > 0) + { + /* 删除该字符设备 */ + device_destroy(mem_dev.cls, mem_dev.g_devno); + class_destroy(mem_dev.cls); + cdev_del(&(mem_dev.g_struBspDev)); + /* 释放已分配的空间 */ + unregister_chrdev_region(MKDEV(mem_dev.g_s32BspDevMajor, 0), 1); + /* 清空主设备号 */ + mem_dev.g_s32BspDevMajor = 0; + /* 调试信息输出 */ + printk("bsp module cleanup success!\n"); + + } + return; +} + +/******************************************************************************* +* 函数名: ad9731_bsp_open +* 描述: 打开文件 +* 相关文档: +* 函数存储类型:int +* 参数: +* +* 参数名 类型 输入/输出 描述 +* -------- ---- --- ----------- +* inode struct inode* input 文件节点结构 +* filp struct file* input 文件结构 +* 返回值: +* 0 成功 +* 说明: +*******************************************************************************/ +int mem_bsp_open(struct inode *inode, struct file *filp) +{ + return 0; +} + +/******************************************************************************* +* 函数名: ad9731_bsp_release +* 描述: 关闭文件 +* 相关文档: +* 函数存储类型:int +* 参数: +* +* 参数名 类型 输入/输出 描述 +* -------- ---- --- ----------- +* inode struct inode* input 文件节点结构 +* filp struct file* input 文件结构 +* 返回值: +* 0 成功 +* 说明: +*******************************************************************************/ +int mem_bsp_release(struct inode *inode, struct file *filp) +{ + /* 操作成功 */ + return 0; +} + +/******************************************************************************* +* 函数名: ad9731_bsp_read () +* +* 描述: 读操作。 +* 相关文档: <描述此函数的相关协议名称、版本及在协议中的位置> +* 函数存储类型: + +*******************************************************************************/ +static ssize_t mem_bsp_read (struct file *filp, char *buf, size_t count, loff_t *f_pos) +{ + return 0; +} + +/******************************************************************************* +* 函数名: ad9731_bsp_write () +* +* 描述: 写操作。 +* 相关文档: <描述此函数的相关协议名称、版本及在协议中的位置> +* 函数存储类型: + +*******************************************************************************/ +ssize_t mem_bsp_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) +{ + return 0; +} + +/******************************************************************************* +* 函数名: ad9731_bsp_ioctl +* 描述: IO控制 +* 相关文档: +* 函数存储类型:int +* 参数: + +*******************************************************************************/ +long mem_bsp_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + return 0; +} + +/******************************************************************************* +* 函数名: mem_bsp_mmap +* 描述: IO内存映射 +* 相关文档: +* 函数存储类型:int +* 参数: +* +*******************************************************************************/ + +int mem_bsp_mmap(struct file *filp, struct vm_area_struct *vma) +{ + /* 设置IO标志 */ + + vma->vm_flags |= VM_IO; + + + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + printk("mmap start\n\r"); + + /* 建立映射 */ + if (remap_pfn_range(vma, + vma->vm_start, + vma->vm_pgoff, + vma->vm_end-vma->vm_start, + vma->vm_page_prot) < 0) + { + return -EAGAIN; + } + + return 0; +} + + +MODULE_AUTHOR ("mr yang"); +MODULE_DESCRIPTION ("mem_dump" ); +MODULE_LICENSE ("GPL"); +module_init(osp_mem_init); +module_exit(osp_mem_exit); + +/******************************* 源文件结束 ***********************************/ + diff --git a/driver/rfic b/driver/rfic new file mode 160000 index 0000000..1f8aef0 --- /dev/null +++ b/driver/rfic @@ -0,0 +1 @@ +Subproject commit 1f8aef08469197a952e766f439fc0bfbc9a28ea5 diff --git a/driver/stc-dev/Makefile b/driver/stc-dev/Makefile new file mode 100644 index 0000000..6cb9c08 --- /dev/null +++ b/driver/stc-dev/Makefile @@ -0,0 +1,25 @@ +export ARCH=arm64 +export CROSS_COMPILE=aarch64-linux-gnu- +#KERNELDIR = /public/liweihua/workspace/linux-5.0.21 +KERNELDIR = /public/liweihua/workspace/linux-5.10.165 + +OBJ = ARM_STC + +PWD = $(shell pwd) +# Kernel modules +ifeq ($(OBJ),ARM_STC) + obj-m = stc.o + #mycache-objs = osp_sm_ddr.o cache.o + stc-y := stc-dev.o +endif + +# Specify flags for the module compilation. +ccflags-y = -g -O2 +#INCLUDE += -l./../../common/ +build: kernel_modules +kernel_modules: + make -C $(KERNELDIR) M=$(PWD) modules +clean: + make -C $(KERNELDIR) M=$(PWD) clean + + diff --git a/driver/stc-dev/stc-dev.c b/driver/stc-dev/stc-dev.c new file mode 100644 index 0000000..acbf6c4 --- /dev/null +++ b/driver/stc-dev/stc-dev.c @@ -0,0 +1,357 @@ +/* + * Driver for stc module. + * + * Copyright (C) 2022, liweihua@smartlogictech.com + * Copyright 2022 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "stc_def.h" + +#define UCP4008_STC_MODULE_VERSION ("V1.0") +#define UCP4008_STC_DEVICE_NAME "stc_irq" + +struct stc_driver g_stc_drv; + +static irqreturn_t stc_tod_1pps_handler(int irqid, void *param) +{ + struct stc_driver *pirqstc = param; + + __raw_writel(0x1,pirqstc->io_base_addr + 4); //clear int + pirqstc->irq_1pps_tod_cnt++; + pirqstc->cond_1pps_tod = STC_TOD_1PPS; + //printk("enter:%s,complete_cond = %d,\n",__func__,pirqstc->complete_cond); + wake_up_interruptible(&pirqstc->pp1s_tod_queue); + + return IRQ_HANDLED; +} + +static irqreturn_t stc_1pps_in_handler(int irqid, void *param) +{ + struct stc_driver *pirqstc = param; + + __raw_writel(0x2,pirqstc->io_base_addr + 4); //clear int + pirqstc->irq_1pps_in_cnt++; + pirqstc->cond_1pps_in = STC_EX_1PPS_IN; + //printk("enter:%s,complete_cond = %d,\n",__func__,pirqstc->complete_cond); + wake_up_interruptible(&pirqstc->pp1s_in_queue); + + return IRQ_HANDLED; +} + +static irqreturn_t stc_hscc_dump_handler(int irqid, void *param) +{ + struct stc_driver *pirqstc = param; + + __raw_writel(0x4,pirqstc->io_base_addr + 4); //clear int + pirqstc->irq_hscc_dump_cnt++; + pirqstc->cond_hscc_dump = STC_HSCC_DUMP; + //printk("enter:%s,complete_cond = %d,\n",__func__,pirqstc->complete_cond); + wake_up_interruptible(&pirqstc->hscc_dump_queue); + + return IRQ_HANDLED; +} + +static int stc_open(struct inode* inode, struct file* file) +{ + printk(KERN_INFO "[%s]\n", __func__); + return 0; +} + +static ssize_t stc_read(struct file* file, char __user* buf, size_t size, loff_t* pos) +{ + sint32 ret; + uint32 cond_value; + + if(STC_TOD_1PPS == size) + { + ret = wait_event_interruptible(g_stc_drv.pp1s_tod_queue, g_stc_drv.cond_1pps_tod); + cond_value = g_stc_drv.irq_1pps_tod_cnt; + g_stc_drv.cond_1pps_tod = STC_INT_RESERVED; + } + else if(STC_EX_1PPS_IN == size) + { + ret = wait_event_interruptible(g_stc_drv.pp1s_in_queue, g_stc_drv.cond_1pps_in); + cond_value = g_stc_drv.irq_1pps_in_cnt; + g_stc_drv.cond_1pps_in = STC_INT_RESERVED; + } + else if(STC_HSCC_DUMP == size) + { + ret = wait_event_interruptible(g_stc_drv.hscc_dump_queue, g_stc_drv.cond_hscc_dump); + cond_value = g_stc_drv.irq_hscc_dump_cnt; + g_stc_drv.cond_hscc_dump = STC_INT_RESERVED; + } + else + { + return FAILURE; + } + + if(ret != 0) + { + printk("exe:%s error!\n",__func__); + return FAILURE; + } + ret = copy_to_user(buf, &cond_value, sizeof(uint32)); + + return ret; +} + +static ssize_t stc_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offt) +{ + return 0; +} + +static sint64 stc_ioctl(struct file* file, unsigned int cmd, unsigned long arg) +{ + sint32 s32Ret = SUCCESS; + stc_int_type_e int_type; + struct stc_driver *stc_drv = &g_stc_drv; + uint32 irq_enable = __raw_readl(g_stc_drv.io_base_addr + 8); + + printk("enter:%s\n",__func__); + + switch(cmd) + { + case STC_INT_CFG: + { + s32Ret = copy_from_user(&int_type, (void __user*)arg, sizeof(stc_int_type_e)); + if(s32Ret != 0) + { + printk(KERN_INFO "[%s]Copy user data failed!\n", __func__); + return FAILURE; + } + + switch(int_type) + { + case STC_TOD_1PPS: + { + s32Ret = request_irq(stc_drv->irq_1pps_tod, stc_tod_1pps_handler, IRQF_SHARED, "tod_1pps", (void *)stc_drv); + if(s32Ret != SUCCESS) + { + free_irq(stc_drv->irq_1pps_tod, stc_drv); + printk(KERN_INFO "[%s]irq_ipps_tod request error!\n", __func__); + return FAILURE; + } + + irq_enable |= 1; + __raw_writel(irq_enable,g_stc_drv.io_base_addr + 8); // + break; + } + case STC_EX_1PPS_IN: + { + s32Ret = request_irq(stc_drv->irq_1pps_in, stc_1pps_in_handler, IRQF_SHARED, "1pps_in", (void *)stc_drv); + if(s32Ret != SUCCESS) + { + free_irq(stc_drv->irq_1pps_in, stc_drv); + printk(KERN_INFO "[%s]irq_ipps_in request error!\n", __func__); + return FAILURE; + } + printk(KERN_INFO "[%s]enable irq_ipps_in int!\n", __func__); + irq_enable |= 2; + __raw_writel(irq_enable,g_stc_drv.io_base_addr + 8); // + break; + } + case STC_HSCC_DUMP: + { + s32Ret = request_irq(stc_drv->irq_hscc_dump, stc_hscc_dump_handler, IRQF_SHARED,"hscc_dump" ,(void *)stc_drv); + if(s32Ret != SUCCESS) + { + free_irq(stc_drv->irq_hscc_dump, stc_drv); + printk(KERN_INFO "[%s]irq_hscc_dump request error!\n", __func__); + return FAILURE; + } + irq_enable |= 4; + __raw_writel(irq_enable,g_stc_drv.io_base_addr + 8); // + break; + } + default:break; + } + break; + } + default: + { + s32Ret = FAILURE; + break; + } + } + + return s32Ret; +} + +static int stc_release(struct inode* inode, struct file* file) +{ + printk(KERN_INFO "[%s]realease \n", __func__); + return 0; +} + +static struct file_operations stc_fops = { + .owner = THIS_MODULE, + .open = stc_open, + .read = stc_read, + .write = stc_write, + .release = stc_release, + .unlocked_ioctl = stc_ioctl, +}; + +static struct miscdevice g_stc_dev = { + .minor = MISC_DYNAMIC_MINOR, + .name = "stc_dev", + .fops = &stc_fops, +}; + +#if 0 +static int stc_module_init(void) +{ + sint32 iRet; + uint32 u32idx; + + iRet = misc_register(&g_stc_dev); + if(iRet != SUCCESS) + { + printk("misc_register error! iRet = %d\n", iRet); + return -1; + } + + memset(&g_stc_drv, 0, sizeof(struct stc_driver)); + + g_stc_drv.irq_ipps_in = UCP4008_IRQ_1PPS_IN; + g_stc_drv.irq_hscc_dump = UCP4008_IRQ_HSCC_DUMP; + g_stc_drv.irq_ipps_tod = UCP4008_IRQ_1PPS_TOD; + g_stc_drv.irq_ipps_in_cnt = 0; + g_stc_drv.irq_hscc_dump_cnt = 0; + g_stc_drv.irq_ipps_tod_cnt = 0; + + init_waitqueue_head(&g_stc_drv.complete_queue); + g_stc_drv.complete_cond = STC_INT_RESERVED; + + g_stc_drv.io_base_addr = ioremap(STC_REG_BASE_ADDR,STC_REG_LEN); + + //init timer + #if 0 + init_timer(&g_stc_drv.avcn_timer_list); + + setup_timer(&g_stc_drv.avcn_timer_list, avcn_debounce_timer, GPIO_INT_FUNC_RESET); + #else + //timer_setup(&g_stc_drv.avcn_timer_list, avcn_debounce_timer, 0); + #endif + printk(KERN_INFO "[%s] module version %s init...\n", __func__, UCP4008_STC_MODULE_VERSION); + return 0; +} + +static void stc_module_exit(void) +{ + misc_deregister(&g_stc_dev); + + free_irq(g_stc_drv.irq_ipps_in , &g_stc_drv); + free_irq(g_stc_drv.irq_ipps_tod , &g_stc_drv); + free_irq(g_stc_drv.irq_hscc_dump , &g_stc_drv); + + printk(KERN_INFO "[%s] module version %s exit...\n", __func__, UCP4008_STC_MODULE_VERSION); +} +#endif + +static int smartlogic_stc_probe(struct platform_device *pdev) +{ + struct resource *res_common; + struct device *dev = &pdev->dev; + int i, irq, iRet; + int irq_no[3]; + + printk("enter:%s\n",__func__); + + iRet = misc_register(&g_stc_dev); + if(iRet != SUCCESS) + { + printk("misc_register error! iRet = %d\n", iRet); + return -1; + } + + for (i = 0; i < 3; ++i) + { + irq = platform_get_irq(pdev, i); + if (irq < 0) { + dev_err(dev, "failed to get irq index %d\n", i); + return -ENODEV; + } + irq_no[i] = irq; + } + + g_stc_drv.irq_1pps_tod = irq_no[0]; + g_stc_drv.irq_1pps_in = irq_no[1]; + g_stc_drv.irq_hscc_dump = irq_no[2]; + + res_common = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res_common) + { + dev_err(&pdev->dev, "memory resource not found"); + return -EINVAL; + } + + g_stc_drv.io_base_addr = devm_ioremap_resource(dev, res_common); + if (IS_ERR(g_stc_drv.io_base_addr)) + { + return PTR_ERR(g_stc_drv.io_base_addr); + } + + init_waitqueue_head(&g_stc_drv.pp1s_tod_queue); + init_waitqueue_head(&g_stc_drv.pp1s_in_queue); + init_waitqueue_head(&g_stc_drv.hscc_dump_queue); + g_stc_drv.cond_1pps_tod = STC_INT_RESERVED; + g_stc_drv.cond_1pps_in = STC_INT_RESERVED; + g_stc_drv.cond_hscc_dump = STC_INT_RESERVED; + g_stc_drv.irq_1pps_tod_cnt = 0; + g_stc_drv.irq_1pps_in_cnt = 0; + g_stc_drv.irq_hscc_dump_cnt = 0; + + return 0; +} + +static int smartlogic_stc_remove(struct platform_device *pdev) +{ + misc_deregister(&g_stc_dev); + + free_irq(g_stc_drv.irq_1pps_in , &g_stc_drv); + free_irq(g_stc_drv.irq_1pps_tod , &g_stc_drv); + free_irq(g_stc_drv.irq_hscc_dump , &g_stc_drv); + + printk(KERN_INFO "[%s] module version %s exit...\n", __func__, UCP4008_STC_MODULE_VERSION); + + return 0; +} + +static const struct of_device_id smartlogic_stc_match[] = { + { .compatible = "smartlogic,stc" }, + {}, +}; +MODULE_DEVICE_TABLE(of, smartlogic_stc_match); + +static struct platform_driver smartlogic_stc_driver = { + .driver = { + .name = "smartlogic_stc", + .of_match_table = smartlogic_stc_match, + }, + .probe = smartlogic_stc_probe, + .remove = smartlogic_stc_remove, +}; +module_platform_driver(smartlogic_stc_driver); + +MODULE_AUTHOR("liweihua@smartlogictech.com"); +MODULE_DESCRIPTION ("Smartlogictech STC module driver!"); +MODULE_LICENSE ("GPL"); + diff --git a/driver/stc-dev/stc_def.h b/driver/stc-dev/stc_def.h new file mode 100644 index 0000000..35ffa9b --- /dev/null +++ b/driver/stc-dev/stc_def.h @@ -0,0 +1,69 @@ +#ifndef _STC_DEF_H_ +#define _STC_DEF_H_ + +#include +#include /*声明printk()这个内核态的函数*/ +#include /*文件系统有关的,结构体file_operations也在fs头文件定义*/ +#include /*init和exit相关宏*/ +#include +#include +#include /*linux中断定义*/ +#include +#include /*包含与中断相关的大部分宏及结构体的定义,request_irq()等*/ +#include /*linux中的用户态内存交互函数,copy_from_user(),copy_to_user()等*/ +#include +#include +#include /*misc混合设备注册与注销*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef char sint8; +typedef unsigned char uint8; +typedef int sint32; +typedef unsigned int uint32; +typedef long sint64; +typedef unsigned long uint64; + + +#define SUCCESS (0) +#define FAILURE (-1) +#define IRQ_EXCEPTION (0xFFFFFF) + +#define STC_MODULE_MAGIC 'g' +#define STC_INT_CFG _IOWR(STC_MODULE_MAGIC, 0x01, uint32) + +#define STC_REG_BASE_ADDR (0x08568000ull) //STC鍩哄湴鍧 +#define STC_REG_LEN (0x08000) + +typedef enum +{ + STC_INT_RESERVED = 0, /* Reserved*/ /* Reserved*/ + STC_TOD_1PPS, /* stc 1pps*/ + STC_EX_1PPS_IN, /* external 1pps */ + STC_HSCC_DUMP = 4 /* HSCC_DUMP */ +} stc_int_type_e; + +struct stc_driver{ + sint32 irq_1pps_tod; + sint32 irq_1pps_in; + sint32 irq_hscc_dump; + uint32 irq_1pps_tod_cnt; + uint32 irq_1pps_in_cnt; + uint32 irq_hscc_dump_cnt; + stc_int_type_e cond_1pps_tod; + stc_int_type_e cond_1pps_in; + stc_int_type_e cond_hscc_dump; + wait_queue_head_t pp1s_tod_queue; + wait_queue_head_t pp1s_in_queue; + wait_queue_head_t hscc_dump_queue; + void __iomem *io_base_addr; +}; + +#endif diff --git a/driver/tfu b/driver/tfu new file mode 160000 index 0000000..7908793 --- /dev/null +++ b/driver/tfu @@ -0,0 +1 @@ +Subproject commit 7908793098da2a3fcc5da3f3f2831c84fe4947f7 diff --git a/driver/tsc/Makefile b/driver/tsc/Makefile new file mode 100644 index 0000000..c67d1ba --- /dev/null +++ b/driver/tsc/Makefile @@ -0,0 +1,18 @@ +PWD := $(shell pwd) + +#KERNELDIR := /public/liweihua/workspace/linux-5.0.21 +KERNELDIR := /public/liweihua/workspace/linux-5.10.165 + +obj-m := tsc.o + +modules: + $(MAKE) -C $(KERNELDIR) M=$(PWD) modules + +modules_install: + $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install + +clean: + rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.symvers *.order irq-test + +.PHONY: modules modules_install clean + diff --git a/driver/tsc/tsc.c b/driver/tsc/tsc.c new file mode 100644 index 0000000..3926405 --- /dev/null +++ b/driver/tsc/tsc.c @@ -0,0 +1,67 @@ +#include +#include +#include + +#define ARMV8_PMCR_MASK 0x3f +#define ARMV8_PMCR_E (1 << 0) +#define ARMV8_PMCR_LC (1 << 6) + +static inline u32 armv8pmu_pmcr_read(void) +{ + u64 val = 0; + asm volatile("mrs %0, pmcr_el0" : "=r" (val)); + return (u32)val; +} +static inline void armv8pmu_pmcr_write(u32 val) +{ + val &= ARMV8_PMCR_MASK; + isb(); + asm volatile("msr pmcr_el0, %0" : : "r" ((u64)val)); +} + +static inline long long armv8_read_CNTPCT_EL0(void) +{ + long long val; + asm volatile("mrs %0, CNTVCT_EL0" : "=r" (val)); + return val; +} + +static void +enable_cpu_counters(void* data) +{ + asm volatile("msr pmuserenr_el0, %0" : : "r"(0xf)); + armv8pmu_pmcr_write(ARMV8_PMCR_LC|ARMV8_PMCR_E); + asm volatile("msr PMCNTENSET_EL0, %0" :: "r" ((u32)(1<<31))); + armv8pmu_pmcr_write(armv8pmu_pmcr_read() | ARMV8_PMCR_E|ARMV8_PMCR_LC); + printk("\nCPU:%d ", smp_processor_id()); +} + +static void +disable_cpu_counters(void* data) +{ + printk(KERN_INFO "\ndisabling user-mode PMU access on CPU #%d", + smp_processor_id()); + + armv8pmu_pmcr_write(armv8pmu_pmcr_read() |~ARMV8_PMCR_E); + asm volatile("msr pmuserenr_el0, %0" : : "r"((u64)0)); +} + +static int __init init(void) +{ + on_each_cpu(enable_cpu_counters, NULL, 1); + printk(KERN_INFO "Enable Access PMU Initialized"); + return 0; +} + +static void __exit fini(void) +{ + on_each_cpu(disable_cpu_counters, NULL, 1); + printk(KERN_INFO "Access PMU Disabled"); +} + +module_init(init); +module_exit(fini); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("titan"); + + diff --git a/driver/ucp_2_revmem/Makefile b/driver/ucp_2_revmem/Makefile new file mode 100644 index 0000000..f37efb0 --- /dev/null +++ b/driver/ucp_2_revmem/Makefile @@ -0,0 +1,12 @@ + +KERN_DIR = /public/liweihua/workspace/linux-5.0.21 + +all: + make -C ${KERN_DIR} M=`pwd` modules + +clean: + make -C ${KERN_DIR} M=`pwd` modules clean + rm -rf modules.order + +obj-m += ucp_2_revmem.o + diff --git a/driver/ucp_2_revmem/build_env.sh b/driver/ucp_2_revmem/build_env.sh new file mode 100644 index 0000000..f27456d --- /dev/null +++ b/driver/ucp_2_revmem/build_env.sh @@ -0,0 +1,3 @@ +export ARCH=arm64 +export CROSS_COMPILE=/public/liweihua/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- +make diff --git a/driver/ucp_2_revmem/ucp_2_revmem.c b/driver/ucp_2_revmem/ucp_2_revmem.c new file mode 100644 index 0000000..42778a0 --- /dev/null +++ b/driver/ucp_2_revmem/ucp_2_revmem.c @@ -0,0 +1,325 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "ucp_2_revmem.h" + +/*鏆傛椂灏唘cp_mem鐨勪富璁惧鍙峰畾涔変负10 */ + +typedef struct tag_OSP_CACHE_REV +{ + unsigned int phy_addr; + unsigned int len; +}OSP_CACHE_REV; + +struct ucp_2_rev_device{ + struct device *dev; + struct miscdevice *miscdev; + void __iomem *vir_head; + unsigned int phy_head; +}; + +struct ucp_2_rev_device *ucp_2_rev_dev; + +#define DEVICE_NAME "ucp_2_revmem" +//#define DEVICE_NAME "ucp_2_mmap" + + +#define IOCTL_CACHE_INVALID _IO('k',0x10) +#define IOCTL_CACHE_FLUSH _IO('k',0x20) +#define IOCTL_SET_CACHE _IO('k',0x30) +#define IOCTL_SET_NOCACHE _IO('k',0x40) + +#define UP_ALIGNED(num, n) (((num) + (n) - 1) & (~((n) - 1))) + +#define REV_WITH_CACHE 2 +#define REV_WITH_NOCACHE 3 + +int is_cached=0; + +extern void arch_sync_dma_for_device_p(struct device *dev, void *addr, + size_t size, enum dma_data_direction dir); +extern void arch_sync_dma_for_cpu_p(struct device *dev, void *addr, + size_t size, enum dma_data_direction dir); + +/*file open function*/ +int ucp_2_revmem_open(struct inode *inode, struct file *filp) +{ + /* device structure pointer assgined to file private data pointer */ + printk("enter %s !!!\n",__func__); + return 0; +} + +ssize_t ucp_2_revmem_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos) +{ + + return 0; +} + + +/*file release function*/ +int ucp_2_revmem_release(struct inode *inode, struct file *filp) +{ + return 0; +} + +/* ioctl device control function */ +static long ucp_2_revmem_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + OSP_CACHE_REV operation; + void __iomem *vir; + struct ucp_2_rev_device *rev_dev = ucp_2_rev_dev; + struct miscdevice *miscdev = rev_dev->miscdev; + +// printk("%s\n",miscdev->name); + + switch(cmd) + { + case IOCTL_SET_CACHE: + is_cached = REV_WITH_CACHE; +// dev_info(rev_dev->dev,"ioctl set with cache"); + break; + case IOCTL_SET_NOCACHE: + is_cached = REV_WITH_NOCACHE; +// dev_info(rev_dev->dev,"ioctl set no cache"); + break; + case IOCTL_CACHE_FLUSH: + if(copy_from_user((void *)(&operation), (char *)arg, sizeof(OSP_CACHE_REV))) + { + dev_info(rev_dev->dev,"ioctl copy_from_user error"); + return - EINVAL; + } + + if(operation.phy_addr<=0 || operation.len <=0) + { + dev_info(rev_dev->dev,"ioctl user arg error"); + return - EINVAL; + } + + operation.len = UP_ALIGNED(operation.len,4); + +// vir = ioremap_cache(operation.phy_addr,operation.len); + vir = rev_dev->vir_head + (operation.phy_addr - rev_dev->phy_head); + if(vir == NULL) + { + dev_info(rev_dev->dev,"ioctl vir error"); + return - EINVAL; + } + arch_sync_dma_for_device_p(rev_dev->dev, vir, operation.len, DMA_TO_DEVICE); + break; + + case IOCTL_CACHE_INVALID: + if(copy_from_user((void *)(&operation), (char *)arg, sizeof(OSP_CACHE_REV))) + { + dev_info(rev_dev->dev,"ioctl copy_from_user error"); + return - EINVAL; + } + + if(operation.phy_addr<=0 || operation.len <=0) + { + dev_info(rev_dev->dev,"ioctl user arg error"); + return - EINVAL; + } + + operation.len = UP_ALIGNED(operation.len,4); + +// vir = ioremap_cache(operation.phy_addr,operation.len); + vir = rev_dev->vir_head + (operation.phy_addr - rev_dev->phy_head); + if(vir == NULL) + { + dev_info(rev_dev->dev,"ioctl vir error"); + return - EINVAL; + } + arch_sync_dma_for_cpu_p(rev_dev->dev, vir, operation.len, DMA_FROM_DEVICE); + break; + + + default: + return - EINVAL; + } +// iounmap(vir); + return 0; +} + + +static int ucp_2_revmem_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct ucp_2_rev_device *rev_dev = ucp_2_rev_dev; + struct miscdevice *miscdev = rev_dev->miscdev; + uint64_t offset = vma->vm_pgoff << PAGE_SHIFT; + + printk("enter %s !!!\n",__func__); + + printk("ucp_revmem_mmap offset = %#llx,start = %#llx\n",offset,vma->vm_start); + + + vma->vm_flags |= VM_IO | VM_LOCKED; + + if(offset < ARM_STACK_BASE_PHY_ADDR) + { + vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); + } +#if 0 + if(is_cached == REV_WITH_NOCACHE) + { + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + } + else if(is_cached == REV_WITH_CACHE) + { + + } + else + { + dev_info(rev_dev->dev,"flag is_cached is error %d\n",is_cached); + return -EAGAIN; + } + + + vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); +#endif + if (remap_pfn_range(vma, + vma->vm_start, + vma->vm_pgoff, + vma->vm_end-vma->vm_start, + vma->vm_page_prot) < 0) + { + return -EAGAIN; + } +// dev_info(rev_dev->dev,"ucp_revmem_mmap:%d ok\n",is_cached); + printk("leave %s !!!\n",__func__); + + is_cached = 0; + return 0; +} + + +/*file operation structure*/ +static const struct file_operations ucp_2_revmem_fops = +{ + .owner = THIS_MODULE, + .open = ucp_2_revmem_open, + .unlocked_ioctl = ucp_2_revmem_ioctl, + .mmap = ucp_2_revmem_mmap, + .release = ucp_2_revmem_release, +}; + +static ssize_t ucp_2_revmem_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int len=0; + + len += sprintf(buf+len, "%s\r\n", "ucp_2_mem attribute OK!"); + + return len; +} + +static DEVICE_ATTR(ucp_2_revmem, S_IRUGO, ucp_2_revmem_show, NULL); + +static struct miscdevice ucp_2_revmem_miscdev = { + .minor = MISC_DYNAMIC_MINOR, + .name = DEVICE_NAME, + .fops = &ucp_2_revmem_fops, +}; + +static int __init ucp_2_revmem_module_init(void) +{ + int ret; + struct miscdevice *misc_device; + void __iomem * vir_addr; + dma_addr_t phy_addr; + int i; + + ucp_2_rev_dev = (struct ucp_2_rev_device *)kzalloc(sizeof(*ucp_2_rev_dev), GFP_KERNEL); + if (!ucp_2_rev_dev) + return -ENOMEM; + + misc_device = &ucp_2_revmem_miscdev; + ret = misc_register(&ucp_2_revmem_miscdev); + if(ret) + { + goto misc_err; + } + + ret = device_create_file(ucp_2_revmem_miscdev.this_device, &dev_attr_ucp_2_revmem); + if (ret) + { + goto attr_err; + } + ucp_2_rev_dev->dev = ucp_2_revmem_miscdev.this_device; + ucp_2_rev_dev->miscdev = &ucp_2_revmem_miscdev; + dev_set_drvdata(ucp_2_revmem_miscdev.this_device, ucp_2_rev_dev); + + ucp_2_rev_dev->phy_head = UCP_2_APE_REV_MEM_START; + ucp_2_rev_dev->vir_head = ioremap_cache(UCP_2_APE_REV_MEM_START,UCP_2_APE_REM_MEM_LEN); + + dma_coerce_mask_and_coherent(ucp_2_rev_dev->dev, DMA_BIT_MASK(32)); + +/* + for(i = 0; i< 100; i++) + { //GFP_ATOMIC,GFP_KERNEL + vir_addr = dma_alloc_coherent(ucp_2_rev_dev->dev, 0x64000, (dma_addr_t *)&phy_addr, GFP_ATOMIC); + if(vir_addr == NULL) + { + printk("revmem dma_alloc_coherent error:%d\n",i); + } + } +*/ + + dev_info(ucp_2_rev_dev->dev,"ucp_2_revem_module_init ok\n"); + return 0; +misc_err: + device_remove_file(ucp_2_revmem_miscdev.this_device, &dev_attr_ucp_2_revmem); +attr_err: + misc_deregister(&ucp_2_revmem_miscdev); + return -1; + +} + +/* module unload function*/ +static void __exit ucp_2_revmem_module_exit(void) +{ + device_remove_file(ucp_2_revmem_miscdev.this_device, &dev_attr_ucp_2_revmem); + misc_deregister(&ucp_2_revmem_miscdev); +} + + + + + + +/* + * a simple char device driver: ExtInt without mutex + * + * Copyright (C) 2014 Barry Song (baohua@kernel.org) + * + * Licensed under GPLv2 or later. + */ + + +MODULE_AUTHOR ("lte team"); +MODULE_DESCRIPTION ("ucp_mem driver module" ); +MODULE_LICENSE ("GPL"); +module_init(ucp_2_revmem_module_init); +module_exit(ucp_2_revmem_module_exit); + + + + + + + + + diff --git a/driver/ucp_2_revmem/ucp_2_revmem.h b/driver/ucp_2_revmem/ucp_2_revmem.h new file mode 100644 index 0000000..be36ef3 --- /dev/null +++ b/driver/ucp_2_revmem/ucp_2_revmem.h @@ -0,0 +1,24 @@ +#ifndef __HPP_REVMEM_H__ +#define __HPP_REVMEM_H__ + + + + +#define UCP_2_APE_REV_MEM_START 0x90000000 +#define UCP_2_APE_REV_MEM_BLOCK_SIZE 0x100000 +#define UCP_2_APE_REV_MEM_BLOCK_NUM 18 +/*#define HPP_APE_REM_MEM_LEN (HPP_APE_REV_MEM_BLOCK_NUM * HPP_APE_REV_MEM_BLOCK_SIZE)*/ +#define UCP_2_APE_REM_MEM_LEN 0x20000000 + +#define SHARE_MEM_BASE_PHY_ADDR 0x009D00000UL +#define LEN_OF_SHARE_MEM 0x000800000UL +#define SHARE_MEM_END_PHY_ADDR (SHARE_MEM_BASE_PHY_ADDR + LEN_OF_SHARE_MEM) + +#define ARM_STACK_BASE_PHY_ADDR 0x0B8000000UL +// + + + + + +#endif \ No newline at end of file diff --git a/interface/arm_interface.h b/interface/arm_interface.h new file mode 100644 index 0000000..066c642 --- /dev/null +++ b/interface/arm_interface.h @@ -0,0 +1,108 @@ +#ifndef __ARM_INTERFACE_H__ +#define __ARM_INTERFACE_H__ + +typedef int OSP_STATUS; + +/********************** header files **********************/ +#include "msg_transfer_layer.h" +#include "ospHeap.h" + +typedef enum +{ + ZERO_FLAG = 0, /*0鏍囧織*/ + TRUE_FLAG /*1 鏍囧織*/ +}clk_flag_e; + +typedef enum +{ + CLK_DISABLE = 0, /* clock unuseable status */ + CLK_WARM_UP = 1, /* warm up status */ + CLK_TRACKING, /* tracking status */ + CLK_HOLD_OVER /* hold over status */ +}clk_sync_state_e; + +typedef struct +{ + uint32_t common_alarm; + uint32_t hold_over_time; + clk_sync_state_e status; +}clock_module_status_s; + +/****************** Msg_transfer function *****************/ +/* +name: msg_transfer_mem_init +para: null +brief: msg_transfer memory init(before call msg_transfer_init) +*/ +void msg_transfer_mem_init(void); + +/* +name: ucp_handshake +para: null +brief: handshake with host(after call msg_transfer_init) +*/ +void ucp_handshake(void); + +/* +name: rx_callback_oam +para: Input: buf: the address of the data +para: Input: payloadSize: the length of the data +brief: ape/rfm log receive callback +*/ +uint32_t rx_callback_oam(const char* buf,uint32_t payloadSize); + +/********************** Init function *********************/ +/* +name: osp_init +para: null +brief: osp function init +*/ +OSP_STATUS osp_init(); + +uint32_t read_stc_local_timer(void); + +/* +name: drv_init +para: null +brief: drv function init +*/ +int32_t drv_init(void); + +/**********************************************************************************************/ +/* testmac interface */ + +/********************** Init function *********************/ +/* +name: osp_arm_log_proc +para: Input: pbuf: the log's address +para: Input: len: the log's length +para: Input: logid: the log's id +para: Input: msg_type: the log's type +brief: arm log output +*/ +OSP_STATUS osp_arm_log_proc(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type); + +/********************** Osp function *********************/ +/* +name: osp_read_spe_cfg_file +para: Input: path: the config file's path +brief: load the spe config file by the path +*/ +int32_t osp_read_spe_cfg_file(char* path); + +/* +name: osp_get_cfg_file +para: Input: name: the config file's name +para: Output: paddr: the config file's address +para: Output: psize: the config file's size +brief: get a config file's address and size +*/ +int32_t osp_get_cfg_file(char* name, uint64_t *paddr, uint32_t *psize); + +int32_t get_clock_module_status(volatile clock_module_status_s* clk_module_status_ptr); +int32_t set_clk_mode(clk_flag_e pseudo_flag); + + + +#endif /* __ARM_INTERFACE_H__ */ + diff --git a/interface/memcpy_csu.h b/interface/memcpy_csu.h new file mode 100644 index 0000000..2dc6166 --- /dev/null +++ b/interface/memcpy_csu.h @@ -0,0 +1,59 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : memcpy_csu.h +// Author : xianfeng.du +// Created On : 2022-12-1 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#ifndef _MEMCPY_CSU_H_ +#define _MEMCPY_CSU_H_ + +#include "typedef.h" + +typedef enum eUcpMemCpyCsuType { + STACK2MSG, + MSG2STACK, + STACK2STACK +} UcpMemcpyCsuType_e; + +/****************************************************************** +* description锛氬崗璁爤鍐呭瓨涔嬮棿鏁版嵁鎼Щ +* Input(s): +* dst_phy_addr:鐩殑鍦板潃(鐗╃悊鍦板潃) +* src_phy_addr:婧愬湴鍧(鐗╃悊鍦板潃) +* size锛氭惉绉婚暱搴︼紝鍗曚綅:瀛楄妭 +* check_flag:鏄惁绛夊緟鎼Щ缁撴潫 1锛氱瓑寰咃紝0锛氫笉绛夊緟 +* +* Output(s): +* 鏃 +* +* Returns: +* 鏃 +********************************************************************/ +void memcpy_csu_stack2stack(uint64_t dst_phy_addr, uint64_t src_phy_addr, uint32_t size,uint8_t check_flag); + + +/****************************************************************** +* description锛氬崗璁爤鍐呭瓨涓巉api娑堟伅鍐呭瓨涔嬮棿鏁版嵁鎼Щ +* Input(s): +* stack_phy_addr:鍗忚鏍堝唴瀛樺湴鍧(鐗╃悊鍦板潃) +* msg_virt_addr:fapi娑堟伅鍐呭瓨鍦板潃(铏氭嫙鍦板潃) +* size锛氭惉绉婚暱搴︼紝鍗曚綅:瀛楄妭 +* type锛氭惉绉荤被鍨嬶細STACK2MSG/MSG2STACK +* check_flag:鏄惁绛夊緟鎼Щ缁撴潫 1锛氱瓑寰咃紝0锛氫笉绛夊緟 +* Output(s): +* 鏃 +* Returns: +* 鏃 +********************************************************************/ + +void memcpy_csu_stack_and_msg(uint64_t stack_phy_addr, uint64_t msg_virt_addr, uint32_t size,UcpMemcpyCsuType_e type, uint8_t check_flag); + +#endif + diff --git a/interface/msg_transfer_layer.h b/interface/msg_transfer_layer.h new file mode 100644 index 0000000..72cbac7 --- /dev/null +++ b/interface/msg_transfer_layer.h @@ -0,0 +1,81 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : msg_transfer_layer.h +// Author : xianfeng.du +// Created On : 2022-06-29 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __MSG_TRANSFER_LAYER_H__ +#define __MSG_TRANSFER_LAYER_H__ + +#include "typedef.h" + +#define MAX_INSTANCE_NUM (2) +#define MAX_PORT_NUM (4) + +#define SUCCESS (0) +#define FAILURE (-1) +#define UNINITIALIZED_QUEUE (1) +#define FULLEDED_QUEUE (2) +#define EMPTY_QUEUE (2) +#define OUT_OF_BLOCK_MEMORY (2) + +typedef enum e_transfer_type { + NON_CU_SPLIT, + CU_SPLIT, + OAM, + TRANSFER_TYPE_NUM +} transfer_type_e; + +typedef enum e_cu_flag { + C_PLANE, + U_PLANE +} cu_flag_e; + +typedef union tHandleId { + uint32_t value; + struct { + uint8_t rsv; + uint8_t type_id; + uint8_t inst_id; + uint8_t port_id; + }; +} HandleId_t; + +typedef uint32_t (*msg_transfer_callback)(const char* buf,uint32_t payloadSize); + +typedef struct t_queue_info { + uint32_t tx_desc_num; + uint32_t rx_desc_num; + uint32_t tx_block_size; + uint32_t rx_block_size; + uint16_t tx_block_num; + uint16_t rx_block_num; + uint16_t directions; + uint16_t rsv; + msg_transfer_callback tx_callback; + msg_transfer_callback rx_callback; +} queue_info_s; + +typedef struct t_transfer_type_info { + queue_info_s queue_cplane_info; + queue_info_s queue_uplane_info; +} transfer_type_info_s; + +int32_t msg_transfer_init(uint16_t port_index, uint16_t transfer_type, uint16_t inst_id, const transfer_type_info_s* transfer_type_info); +int32_t msg_transfer_send_start(int32_t handle_id, uint16_t cu_flag); +int32_t msg_transfer_alloc_msg(int32_t handle_id, uint16_t cu_flag, uint32_t bufSize, char** buf, uint32_t* availableSize, uint32_t* offset); +int32_t msg_transfer_send_msg(int32_t handle_id, uint16_t cu_flag, uint8_t* msg_ptr, uint32_t offset, uint32_t msg_len); +int32_t msg_transfer_send_end(int32_t handle_id, uint16_t cu_flag); +int32_t msg_transfer_receive(int32_t handle_id, uint16_t cu_flag, uint32_t offset, uint32_t len, uint8_t** msg_ptr); +int32_t msg_transfer_close(int32_t handle_id); + +#endif + diff --git a/interface/ospHeap.h b/interface/ospHeap.h new file mode 100644 index 0000000..fd355a6 --- /dev/null +++ b/interface/ospHeap.h @@ -0,0 +1,109 @@ +#ifndef __OSPHEAP__ +#define __OSPHEAP__ + +#define ECS_SM_DM_BASE_PHY_ADDR 0x007200000UL +#define PET_SM_DM_BASE_PHY_ADDR 0x008700000UL +#define APE_DM_BASE_PHY_ADDR 0x009400000UL //APCx(x:0-3):0x009400000+x*0x200000,2M per APC +#define SHARE_MEM_BASE_PHY_ADDR 0x009D00000UL +#define APE_PHY_BASE_PHY_ADDR 0x010000000UL +#define APE_TEXT_BASE_PHY_ADDR 0x090000000UL +#define ARM_APE_MSG_BASE_PHY_ADDR 0x0A0000000UL +#define APE_LOG_BASE_PHY_ADDR 0x0A8000000UL +#define RESERVED_BASE_PHY_ADDR 0x100000000UL +#define ARM_STACK_BASE_PHY_ADDR 0x100000000UL + +#define LEN_OF_ECS_SM_DM 0x000060000UL //sm(0x20000) + dm(0x40000) +#define LEN_OF_PET_SM_DM 0x000060000UL //sm(0x20000) + dm(0x40000) +#define LEN_OF_APE_DM 0x000800000UL +#define LEN_OF_SHARE_MEM 0x000800000UL +#define LEN_OF_APE_PHY 0x080000000UL +#define LEN_OF_APE_TEXT 0x010000000UL +#define LEN_OF_ARM_APE_MSG 0x008000000UL +#define LEN_OF_APE_LOG 0x010000000UL +#define LEN_OF_ARM_STACK 0x100000000UL + +#define OSP_DISPLAY_MAX_LEN 0x400 +#define OSP_DISPLAY_PAGE_LEN 0x1000 + +typedef enum +{ + ECS_SM = 0, //actual ECS_SM_DM 384 total SM:128KB:0x007200000UL,DM:256KB:0x007220000UL + PET_SM, //actual PET_SM_DM 384 total SM:128KB:0x008700000UL,DM:256KB:0x008720000UL + APE_DM, + SHARE_MEM, + APE_PHY, + APE_TEXT, + ARM_APE_MSG, + APE_LOG, + ARM_STACK, + MEM_RESERVE +}module_type_e; + +/****************************************************************** +* Input(s): +* module锛歮odule_type_e绫诲瀷鏋氫妇鍊硷紝FAPI娑堟伅绫诲瀷涓篈RM_APE_MSG锛 +* virt_addr锛氬緟杞崲鐨勮櫄鎷熷湴鍧銆 +* +* Output(s): +* phy_addr锛氱墿鐞嗗湴鍧 +* +* Returns: +* 0锛氭垚鍔 +* 闈0锛氬け璐 +********************************************************************/ +int32_t osp_virt_to_phy(module_type_e module, uint64_t virt_addr, uint64_t *phy_addr); + +/****************************************************************** +* Input(s): +* module锛歮odule_type_e绫诲瀷鏋氫妇鍊硷紝FAPI娑堟伅绫诲瀷涓篈RM_APE_MSG锛 +* phy_addr锛氬緟杞崲鐨勭墿鐞嗗湴鍧銆 +* +* Output(s): +* virt_addr锛氳櫄鎷熷湴鍧 +* +* Returns: +* 0锛氭垚鍔 +* 闈0锛氬け璐 +********************************************************************/ +int32_t osp_phy_to_virt(module_type_e module, uint64_t phy_addr, uint64_t *virt_addr); + +/****************************************************************** +* Input(s): +* addr锛氳櫄鎷熷湴鍧锛 +* len锛氶暱搴︺ +* +* Output(s): +* +* +* Returns: +* +********************************************************************/ +void osp_flush_dcache_area(void * volatile addr, uint64_t volatile len); +void osp_clean_dcache_area(void * volatile addr, uint64_t volatile len); + +/****************************************************************** +* Input(s): +* module锛歮odule_type_e绫诲瀷鏋氫妇鍊硷紝FAPI娑堟伅绫诲瀷涓篈RM_APE_MSG锛 +* addr锛氳櫄鎷熷湴鍧锛 +* len锛氶暱搴︺ +* +* Output(s): +* +* +* Returns: +* 0锛氭垚鍔 +* 闈0锛氬け璐 +********************************************************************/ +int32_t osp_invalid_dcache_area(module_type_e module, uint64_t virt_addr, uint64_t len); + +/**********************************************************************************************/ +/* testmac interface */ +void *get_static_mem(module_type_e module, uint64_t *len); +void *osp_heap_mem_init(char *pbuf, uint64_t size,void *head_of_static_mem,module_type_e module); +int8_t *osp_alloc_heap_mem(void *heap, uint32_t size); +int32_t osp_free_heap_mem(void *heap, char *pbuf); +int32_t osp_show_heap_mem(void *heap); +int32_t osp_display_phy_mem(uint64_t phy_addr, uint32_t len); + +#endif + diff --git a/interface/typedef.h b/interface/typedef.h new file mode 100644 index 0000000..74b4889 --- /dev/null +++ b/interface/typedef.h @@ -0,0 +1,31 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : typedef.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __TYPEDEF_H__ +#define __TYPEDEF_H__ + +//Types definitions +//typedef unsigned char bool; +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef short int int16_t; +typedef unsigned short int uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef long int int64_t; +typedef unsigned long int uint64_t; +//typedef long long int int64_t; +//typedef unsigned long long int uint64_t; + +#endif diff --git a/kernel/dts/ucp4008-evb.dts b/kernel/dts/ucp4008-evb.dts new file mode 100644 index 0000000..5062c98 --- /dev/null +++ b/kernel/dts/ucp4008-evb.dts @@ -0,0 +1,1589 @@ +/dts-v1/; + +#include +#include +#include +#include +#include +#include +#include +#include + +/ { + compatible = "smartlogic,ucp2"; + interrupt-parent = <&gic>; + #address-cells = <2>; + #size-cells = <2>; + + aliases { + serial0 = &serial_0; + serial1 = &serial_1; + serial2 = &serial_2; + serial3 = &serial_3; + }; + chosen { + stdout-path = &serial_0; + }; + + soc: soc { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges; + //dma-ranges = <0xe0000000 0 0 0x10000000>; + //ranges = <0 0xe0000000 0 0x10000000>; + apb-pclk{ + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24000000>; + clock-output-names = "apb-pclk"; + }; + + gic: interrupt-controller@02181000 { + compatible = "arm,gic-v3"; + #interrupt-cells = <3>; + interrupt-controller; + reg = <0x01800000 0x10000>, /* GICD */ + <0x01900000 0x00F60000>, /* GICR */ + <0x04200000 0x00010000>, /* GICC */ + <0x01820000 0x00010000>, /* GICH */ + <0x01830000 0x00010000>; /* GICV */ + interrupt-parent = <&gic>; + }; + + serial_0: serial@04440000 { + compatible = "snps,dw-apb-uart"; + reg = <0x04440000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "baudclk"; + clocks = <&clock_reset UART0_SCLK>; + reg-io-width = <4>; + reg-shift = <2>; + status = "okay"; + }; + serial_1: serial@04448000 { + compatible = "snps,dw-apb-uart"; + reg = <0x04448000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "baudclk"; + clocks = <&clock_reset UART1_SCLK>; + reg-io-width = <4>; + reg-shift = <2>; + status = "disabled"; + }; + serial_2: serial@04d00000 { + compatible = "snps,dw-apb-uart"; + reg = <0x04d00000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "baudclk"; + clocks = <&clock_reset UART2_SCLK>; + reg-io-width = <4>; + reg-shift = <2>; + status = "okay"; + }; + serial_3: serial@04d08000 { + compatible = "snps,dw-apb-uart"; + reg = <0x04d08000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "baudclk"; + clocks = <&clock_reset UART3_SCLK>; + reg-io-width = <4>; + reg-shift = <2>; + status = "disabled"; + }; + stc: stc-controller@08568000 { + compatible = "smartlogic,stc"; + reg = <0x08568000 0x8000>; + interrupt-parent = <&gic>; + interrupts = , + , + ; + status = "okay"; + }; + timer { + compatible = "arm,armv8-timer"; + interrupts =, + , + , + ; +// clock-frequency = <50000000>; /* 50M */ + }; + +// pet:pet@{ +// compatible = "smartlogic,pet"; +// reg = <0x091d0000 0x10000>, +// <0x091f0000 0x10000>; +// +// }; + + smmu: mmu@042b8000 { + compatible = "arm,mmu-500"; + reg = <0x042b8000 0x20000>; + #global-interrupts = <1>; + #iommu-cells = <1>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + }; + + clock_reset: clock-controller@04550000 { + compatible = "smartlogic,ucp2-clock"; + reg = <0x04550000 0x10000>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + pcie: pcie@091e0000 { + compatible = "smartlogic,pcie-ucp4008evb"; + interrupts = , + ; + interrupt-names = "sys", "perst"; + reg = <0x091e0000 0x10000>, /* pcie-app */ + <0x0c000000 0x500000>, /* pcie-dbi */ + <0x04550000 0x1000>, /* pcie-crg */ + <0x04560000 0x1000>, /* pcie-syscfg */ + <0x091d0000 0x1000>, /* pet-ctrl */ + <0x091f0000 0x1000>, /* pet-crg */ + <0x09204000 0x100000>; /* pet-pma3 */ + reg-names = "pcie-app", "pcie-dbi", "pcie-crg", "pcie-syscfg", "pet-ctrl", "pet-crg", "pet-pma3"; + ep-id = <0>; + status = "disabled"; + }; + + pvt: pvt@4708000 { + compatible = "ucp4008pvt"; + reg = <0x4708000 0x1000>; + interrupts = ; + status = "okay"; + + tsa_hytrs = <0>; + tsa_alarm = <100000>; + + tsb_hytrs = <0>; + tsb_alarm = <95000>; + + vma_hytrs = <700>; + vma_alarm = <850>; + + vmb_hytrs = <690>; + vmb_alarm = <870>; + }; + + i2c_0: i2c@04420000{ /* AT24CM01 */ + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x04420000 0x8000>; + interrupts = ; + clock-frequency = <400000>; + clocks = <&clock_reset I2C0_CLK>; + status = "okay"; + eeprom@50 { + compatible = "atmel,24c1024"; + reg = <0x50>; + }; + }; + + i2c_1: i2c@04428000{ /* i2c switch */ + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x04428000 0x8000>; + interrupts = ; + clock-frequency = <100000>; //400000 + clocks = <&clock_reset I2C1_CLK>; + status = "okay"; + + i2c-switch@70 { + compatible = "nxp,pca9548"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x70>; + + sfp0_i2c: i2c@3 { /* TMAC SFP */ + #address-cells = <1>; + #size-cells = <0>; + reg = <0x3>; + }; + + i2c@4 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4>; + + sensor@49 { + compatible = "ti,tmp468"; + reg = <0x49>; + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0x0>; + label = "local"; + }; + channel@1 { + reg = <0x1>; + label = "external-ch1"; + }; + channel@2 { + reg = <0x2>; + label = "external-ch2"; + }; + channel@3 { + reg = <0x3>; + label = "external-ch3"; + }; + channel@4 { + reg = <0x4>; + label = "external-ch4"; + }; + channel@5 { + reg = <0x5>; + label = "external-ch5"; + }; + channel@6 { + reg = <0x6>; + label = "external-ch6"; + }; + channel@7 { + reg = <0x7>; + label = "external-ch7"; + }; + channel@8 { + reg = <0x8>; + label = "external-ch8"; + }; + }; + }; + + i2c@5 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0x5>; + ltm4677@40{ + compatible = "lltc,ltm4677"; + reg = <0x40>; + }; + ltm4677@42{ + compatible = "lltc,ltm4677"; + reg = <0x42>; + }; + }; + + i2c@6 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0x6>; + ltm4675@42{ + compatible = "lltc,ltm4675"; + reg = <0x42>; + }; + }; + + }; + + }; + + sfp0: sfp-0 { + compatible = "sff,sfp"; + i2c-bus = <&sfp0_i2c>; + maximum-power-milliwatt = <2000>; + }; + + pinctrl: pinctrl@04458000 { + compatible = "ucp2,pinctrl"; + + leds_gpio: leds_gpio { + ucp2,pins = ; /* GPIO0B18 */ + ucp2,pull = ; + ucp2,function = ; + }; + phy0_reset_gpio:phy0_reset_gpio{ + ucp2,pins = ; /* GPIO1B5 */ + ucp2,pull = ; + ucp2,function = ; + }; + phy1_reset_gpio:phy1_reset_gpio{ + ucp2,pins = ; /* GPIO1B4 */ + ucp2,pull = ; + ucp2,function = ; + }; + usb_reset_gpio:usb_reset_gpio{ + ucp2,pins = ; /* GPIO1B7 */ + ucp2,pull = ; + ucp2,function = ; + }; + i2c_mux_reset_gpio:i2c_mux_reset_gpio{ + ucp2,pins = ; /* GPIO1B6 */ + ucp2,pull = ; + ucp2,function = ; + }; + reset_8A34002_gpio:reset_8A34002_gpio{ + ucp2,pins = ; /* GPIO1B8 */ + ucp2,pull = ; + ucp2,function = ; + }; + pcie_reset_gpio:pcie_reset_gpio{ + ucp2,pins = ; /* input ??? GPIO0B13 */ + ucp2,pull = ; + ucp2,function = ; + }; + gps_reset_gpio:gps_reset_gpio{ + ucp2,pins = ; /* GPIO1-B29 */ + ucp2,pull = ; + ucp2,function = ; + }; + + qspi0_cs_gpio:qspi0_cs_gpio{ + ucp2,pins = ; /* GPIO0-B23 */ + ucp2,pull = ; + ucp2,function = ; + }; + qspi0_gpios:qspi0_gpios{ + ucp2,pins = ; + ucp2,pull = ; + ucp2,function = ; + }; + + spi1_gpios:spi1_gpios{ + ucp2,pins = ; + ucp2,pull = ; + ucp2,function = ; + }; + spi2_gpios:spi2_gpios{ + ucp2,pins = ; + ucp2,pull = ; + ucp2,function = ; + }; + spi2_cs_8A34002:spi2_cs_8A34002{ + ucp2,pins = ; /* GPIO0A11 */ + ucp2,pull = ; + ucp2,function = ; + }; + + // by daya 1 + AD9026_reset_gpio:AD9026_reset_gpio{ + ucp2,pins = ; /* GPIO1B9 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_tx1_gpio:AD9026_tx1_gpio{ + ucp2,pins = ; /* GPIO1B13 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_tx2_gpio:AD9026_tx2_gpio{ + ucp2,pins = ; /* GPIO1B12 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_tx3_gpio:AD9026_tx3_gpio{ + ucp2,pins = ; /* GPIO1B15 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_tx4_gpio:AD9026_tx4_gpio{ + ucp2,pins = ; /* GPIO1B14 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_rx1_gpio:AD9026_rx1_gpio{ + ucp2,pins = ; /* GPIO1B17 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_rx2_gpio:AD9026_rx2_gpio{ + ucp2,pins = ; /* GPIO1B16 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_rx3_gpio:AD9026_rx3_gpio{ + ucp2,pins = ; /* GPIO1B19 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9026_rx4_gpio:AD9026_rx4_gpio{ + ucp2,pins = ; /* GPIO1B18 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9528_reset_gpio:AD9528_reset_gpio{ + ucp2,pins = ; /* GPIO1B11 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9528_sysrefRequest_gpio:AD9528_sysrefRequest_gpio{ + ucp2,pins = ; /* GPIO1B10 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9528_status0_gpio:AD9528_status0_gpio{ + ucp2,pins = ; /* GPIO1B27 */ + ucp2,pull = ; + ucp2,function = ; + }; + AD9528_status1_gpio:AD9528_status1_gpio{ + ucp2,pins = ; /* GPIO1B26 */ + ucp2,pull = ; + ucp2,function = ; + }; + spi1_cs_AD9026:spi1_cs_AD9026{ + ucp2,pins = ; /* GPIO0A6 */ + ucp2,pull = ; + ucp2,function = ; + }; + spi1_cs_AD9528:spi1_cs_AD9528{ + ucp2,pins = ; /* GPIO0B19 */ + ucp2,pull = ; + ucp2,function = ; + }; + // end 1 + + }; + + gpio0: gpio@04450000 { + compatible = "snps,dw-apb-gpio"; + reg = <0x04450000 0x8000>; + #address-cells = <1>; + #size-cells = <0>; + port0a: gpio@0 { + compatible = "snps,dw-apb-gpio-port"; + gpio-controller; + #gpio-cells = <2>; + snps,nr-gpios = <32>; + reg = <0>; +// interrupt-controller; +// interrupt-parent = <&gic>; +// interrupts = ; + }; + port0b: gpio@1 { + compatible = "snps,dw-apb-gpio-port"; + gpio-controller; + #gpio-cells = <2>; + snps,nr-gpios = <32>; + reg = <1>; + }; + }; + + gpio1: gpio@04D10000 { + compatible = "snps,dw-apb-gpio"; + reg = <0x04D10000 0x8000>; + #address-cells = <1>; + #size-cells = <0>; + port1a: gpio@0 { + compatible = "snps,dw-apb-gpio-port"; + gpio-controller; + #gpio-cells = <2>; + snps,nr-gpios = <15>; /* GPIO1A0-GPIO1A14 */ + reg = <0>; +// interrupt-controller; +// interrupt-parent = <&gic>; +// interrupts = ; + }; + port1b: gpio@1 { + compatible = "snps,dw-apb-gpio-port"; + gpio-controller; + #gpio-cells = <2>; + snps,nr-gpios = <32>; /* GPIO1B0-GPIO1B31 */ + reg = <1>; + }; + + /* GPIO1A17-GPIO1A31 only used in LVDS mode disable */ + }; + + leds { + compatible = "gpio-leds"; + pinctrl-names = "default"; + pinctrl-0 = <&leds_gpio>; + status = "okay"; + heartbeat { + label = "Heartbeat"; + gpios = <&port0b 18 GPIO_ACTIVE_LOW>; /* GPIO0B18 */ + linux,default-trigger = "heartbeat"; + }; + }; + + usbphy_reset { + compatible = "smartlogic,usbphy_reset"; + pinctrl-names = "default"; + pinctrl-0 = <&usb_reset_gpio>; + status = "okay"; + pin = <&port1b 7 GPIO_ACTIVE_LOW>; /* GPIO1B7 */ + }; + i2c_reset { + compatible = "smartlogic,i2c_reset"; + pinctrl-names = "default"; + pinctrl-0 = <&i2c_mux_reset_gpio>; + status = "okay"; + pin = <&port1b 6 GPIO_ACTIVE_LOW>; /* GPIO1B6 */ + }; + ad9026_reset { + compatible = "smartlogic,ad9026_reset"; + pinctrl-names = "default"; + pinctrl-0 = <&AD9026_reset_gpio>; + status = "okay"; + pin = <&port1b 9 GPIO_ACTIVE_LOW>; /* GPIO1B9 */ + }; + reset_8A34002 { + compatible = "smartlogic,reset_8A34002"; + pinctrl-names = "default"; + pinctrl-0 = <&reset_8A34002_gpio>; + status = "okay"; + pin = <&port1b 8 GPIO_ACTIVE_LOW>; /* GPIO1B8 */ + }; + ad9528_reset { + compatible = "smartlogic,AD9528_reset"; + pinctrl-names = "default"; + pinctrl-0 = <&AD9528_reset_gpio>; + status = "okay"; + pin = <&port1b 11 GPIO_ACTIVE_LOW>; /* GPIO1B11 */ + }; + + ethernet0: ethernet0@01a40000 { + compatible = "smartlogic,dwmac-5.10a"; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "tx", "ptp_ref"; + clocks = <&clock_reset GMAC0_TX_CLK>, + <&clock_reset GMAC0_PTP_REF_CLK>; + reg = <0x01a40000 0x4000>; + phy-handle = <ðphy0>; + phy-mode = "rgmii"; + ethernet= <0>; + snps,en-tx-lpi-clockgating; + snps,en-lpi; + snps,write-requests = <4>; + snps,read-requests = <4>; + snps,burst-map = <0x4>; + snps,txpbl = <16>; + snps,rxpbl = <16>; + snps,aal; + snps,tso; + sph_disable; + smartlogic,mac-delay = <0x0303>; + status = "okay"; + + mdio0: mdio0 { + #address-cells = <0x1>; + #size-cells = <0x0>; + compatible = "snps,dwmac-mdio"; + }; + }; + + ethernet1: ethernet1@01a50000 { + compatible = "smartlogic,dwmac-5.10a"; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "tx", "ptp_ref"; + clocks = <&clock_reset GMAC1_TX_CLK>, + <&clock_reset GMAC1_PTP_REF_CLK>; + reg = <0x01a50000 0x4000>; + phy-handle = <ðphy1>; + phy-mode = "rgmii"; + ethernet= <1>; + snps,en-tx-lpi-clockgating; + snps,en-lpi; + snps,write-requests = <4>; + snps,read-requests = <4>; + snps,burst-map = <0x4>; + snps,txpbl = <16>; + snps,rxpbl = <16>; + snps,aal; + snps,tso; + sph_disable; + smartlogic,mac-delay = <0x0303>; + status = "okay"; + + /*fixed-link { + speed = <1000>; + full-duplex; + };*/ + + mdio1: mdio1 { + #address-cells = <0x1>; + #size-cells = <0x0>; + compatible = "snps,dwmac-mdio"; + }; + }; + + ethernet2: ethernet2@08524000 { + compatible = "smartlogic,dwmac-5.10a"; + interrupt-parent = <&gic>; + interrupts = ; +// clock-names = "tx"; +// clocks = <&clock_reset GMAC2_TX_CLK>; + reg = <0x08524000 0x1FFFF>; +// phy-handle = <ðphy0>; + phy-mode = "gmii"; + ethernet= <2>; + snps,en-tx-lpi-clockgating; + snps,en-lpi; + snps,write-requests = <4>; + snps,read-requests = <4>; + snps,burst-map = <0x4>; + snps,txpbl = <16>; + snps,rxpbl = <16>; + snps,aal; + snps,tso; + sph_disable; + smartlogic,mac-delay = <0x0101>; + status = "okay"; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + + ethernet3: ethernet3@09090000 { + compatible = "smartlogic,dwxgmac"; + interrupt-parent = <&gic>; + interrupts = ; + clock-names = "tx", "ptp_ref"; + clocks = <&clock_reset TMAC_PTP_REF_CLK>, + <&clock_reset TMAC_PTP_REF_CLK>; + reg = <0x09090000 0x100000>; +// phy-handle = <ðphy0>; + phy-mode = "xlgmii"; + sfp = <&sfp0>; + ethernet= <3>; + snps,en-tx-lpi-clockgating; + snps,en-lpi; + snps,write-requests = <4>; + snps,read-requests = <4>; + snps,burst-map = <0x4>; + snps,txpbl = <16>; + snps,rxpbl = <16>; + max-frame-size = <16368>; + snps,multicast-filter-bins = <256>; + snps,perfect-filter-entries = <128>; + snps,axi-config = <&stmmac_axi_setup>; + snps,mtl-rx-config = <&mtl_rx_setup>; + snps,mtl-tx-config = <&mtl_tx_setup>; + rx-fifo-depth = <16384>; + tx-fifo-depth = <16384>; + snps,aal; + snps,tso; + sph_disable; +// smartlogic,mac-delay = <0x0101>; + //max-speed = <10000>; + sfp-max-speed = <10000>; + managed = "in-band-status"; + status = "okay"; + /*fixed-link { + speed = <10000>; + full-duplex; + };*/ + + }; + + stmmac_axi_setup: stmmac-axi-config { + snps,wr_osr_lmt = <0xf>; + snps,rd_osr_lmt = <0xf>; + snps,blen = <256 128 64 32 0 0 0>; + }; + + mtl_rx_setup: rx-queues-config { + snps,rx-queues-to-use = <1>; + snps,rx-sched-sp; + queue0 { + snps,dcb-algorithm; + snps,map-to-dma-channel = <0x0>; + snps,priority = <0x0>; + }; + }; + + mtl_tx_setup: tx-queues-config { + snps,tx-queues-to-use = <1>; + snps,tx-sched-wrr; + queue0 { + snps,weight = <0x10>; + snps,dcb-algorithm; + snps,priority = <0x0>; + }; + /*queue1 { + snps,avb-algorithm; + snps,send_slope = <0x1000>; + snps,idle_slope = <0x1000>; + snps,high_credit = <0x3E800>; + snps,low_credit = <0xFFC18000>; + snps,priority = <0x1>; + };*/ + }; + +// sysctrl: sysctrl@04560000 { +// compatible = "smartlogic,ucp4008-sysctrl"; +// reg = <0x04560000 0x10000>; +// #reset-cells = <1>; +// }; + + usb: usb@045c0000 { + compatible = "smartlogic,ucp4008-usb", "snps,dwc2"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x045c0000 0x40000>; + interrupts = ; + + pinctrl-names = "default"; + pinctrl-0 = <&usb_reset_gpio>; + reset-gpios = <&port1b 7 GPIO_ACTIVE_HIGH>; + + dr_mode = "host"; + //dr_mode = "peripheral"; + //dr_mode = "otg"; + + status = "disable"; + }; + + mmcsd: mmcsd@01a60000 { + compatible = "snps,dw-mshc"; + reg = <0x01a60000 0x1000>; + interrupts = ; + clocks = <&clock_reset CIU_CCLK>,<&clock_reset CIU_CCLK_DIV>,<&clock_reset SDIO_TUNING_CLK_DIV>; + clock-names = "biu","ciu","ciu_div1"; + fifo-depth = <512>; + card-detect-delay = <200>; + bus-width = <8>; + max-frequency = <40000000>; /* 40M */ + clock-frequency = <62500000>; /* 62.5M */ + smartlogic,clock-frequency-div1 = <250000000>; /* 250M */ + status = "okay"; + cap-mmc-highspeed; + cap-sd-highspeed; + non-removable; + }; + + eip0: eip@01060000 { + #adress-cells = <1>; + #size-cells = <1>; + compatible = "smartlogic, eip-197"; + interrupt-parent = <&gic>; + interrupts = , + , + , + , + ; + reg = <0x01060000 0x200000>; + }; + + eip1: eip@01260000 { + #adress-cells = <1>; + #size-cells = <1>; + compatible = "smartlogic, eip-197-pdcp"; + interrupt-parent = <&gic>; + interrupts = , + , + , + , + ; + reg = <0x01260000 0x200000>; + }; + + com_module{ + compatible = "smartlogic,com"; + status = "okay"; + //reg = <0x30000000 0x1fb0>; + //mem_block_size = <4096>; + com_header_addr = <0x931fc00>; + }; + + qspi_0: spi@04430000 { /* spi0 MT25QU02G */ + compatible = "snps,dw-apb-ssi"; + reg = <0x04430000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; + clocks = <&clock_reset SSI0_CLK>; + pinctrl-names = "default"; + pinctrl-0 = <&qspi0_cs_gpio &qspi0_gpios>; +// resets = <&clock_reset SSI1_DEV_SWRSTREQ>; + reset-names = "spi0"; + bus-num = <0x0>; + reg-io-width = <4>; + num-cs = <1>; + cs-gpios = <&port0b 23 GPIO_ACTIVE_HIGH>; + reg-shift = <2>; + status = "okay"; + }; + + // by daya 2 + spi_1: spi@04438000 { /* spi1 ADRV9026 AD9528 */ + compatible = "snps,dw-apb-ssi"; + reg = <0x04438000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; + clocks = <&clock_reset SSI1_CLK>; + pinctrl-names = "default"; + pinctrl-0 = <&spi1_cs_AD9026>,<&AD9026_reset_gpio>,<&spi1_cs_AD9528>,<&AD9528_reset_gpio>,<&AD9528_sysrefRequest_gpio>, + <&AD9026_tx1_gpio>,<&AD9026_tx2_gpio>,<&AD9026_tx3_gpio>,<&AD9026_tx4_gpio>, + <&AD9026_rx1_gpio>,<&AD9026_rx2_gpio>,<&AD9026_rx3_gpio>,<&AD9026_rx4_gpio>, + <&leds_gpio>,<&AD9528_status0_gpio>,<&AD9528_status1_gpio>; +// resets = <&clock_reset SSI1_DEV_SWRSTREQ>; + reset-names = "spi1"; + bus-num = <1>; + reg-io-width = <4>; + // daya num-cs = <2>; + // daya cs-gpios = <&port0a 6 GPIO_ACTIVE_HIGH>, <&port0b 19 GPIO_ACTIVE_HIGH>; + reg-shift = <2>; + status = "okay"; + }; + + spi2: spi@04d18000 { /* spi2 8A34002 */ +// compatible = "snps,dwc-ssi-1.01a"; + compatible = "snps,dw-apb-ssi"; + reg = <0x04d18000 0x8000>; + interrupt-parent = <&gic>; + interrupts = ; +// clocks = <&clock_reset SSI2_CLK>, +// <&clock_reset SSI2_CLK_DIV>; + clocks = <&clock_reset SSI2_CLK>; + clock-names = "ssi_clk","pclk"; + pinctrl-names = "default"; + pinctrl-0 = <&spi2_cs_8A34002>,<&spi2_gpios>; + //resets = <&clock_reset SSI2_DEV_SWRSTREQ>; + reset-names = "spi"; + bus-num = <0x2>; + /* Could possibly go up to 200 MHz */ + spi-max-frequency = <100000000>; /* 100M */ + num-cs = <1>; + cs-gpios = <&port0a 11 GPIO_ACTIVE_HIGH>; + reg-io-width = <4>; + status = "okay"; + }; + +// dma_test { +// compatible = "smartlogic,dma_test"; +// status = "okay"; +// iommus = <&smmu>; +// dma-ranges; +// memory-region = <&cdsp_fw_mem1>; +// }; + +// smmu_test { +// compatible = "smartlogic,smmu_test"; +// status = "okay"; +// iommus = <&smmu UCP4008_SID_SMMU_TEST>; +// }; + timer00: timer@04418000 { + compatible = "snps,dw-apb-timer"; + reg = <0x004418000 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + clocks = <&clock_reset TIMER00_CLK>; + clock-names = "timer"; + +// resets = <&clock_reset TIMER00_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer01: timer@04418014 { + compatible = "snps,dw-apb-timer"; + reg = <0x004418014 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + + clocks = <&clock_reset TIMER01_CLK>; + clock-names = "timer"; + +// resets = <&clock_reset TIMER01_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer02: timer@04418028 { + compatible = "snps,dw-apb-timer"; + reg = <0x04418028 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + + clocks = <&clock_reset TIMER02_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER02_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer03: timer@0441803c { + compatible = "snps,dw-apb-timer"; + reg = <0x0441803c 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER03_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER03_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer04: timer@04418050 { + compatible = "snps,dw-apb-timer"; + reg = <0x0441805 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER04_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER04_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer05: timer@04418064 { + compatible = "snps,dw-apb-timer"; + reg = <0x04418064 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER05_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER05_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer06: timer@04418078 { + compatible = "snps,dw-apb-timer"; + reg = <0x04418078 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER06_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER06_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer07: timer@0441808c { + compatible = "snps,dw-apb-timer"; + reg = <0x0441808c 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER07_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER07_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer10: timer@04D28000 { + compatible = "snps,dw-apb-timer"; + reg = <0x004D28000 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + clocks = <&clock_reset TIMER10_CLK>; + clock-names = "timer"; + +// resets = <&clock_reset TIMER10_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer11: timer@04D28014 { + compatible = "snps,dw-apb-timer"; + reg = <0x004D28014 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + + clocks = <&clock_reset TIMER11_CLK>; + clock-names = "timer"; + +// resets = <&clock_reset TIMER11_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer12: timer@04D28028 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D28028 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + + clocks = <&clock_reset TIMER12_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER12_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer13: timer@04D2803c { + compatible = "snps,dw-apb-timer"; + reg = <0x04D2803c 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER13_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER13_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer14: timer@04D28050 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D2805 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER14_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER14_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer15: timer@04D28064 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D28064 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER15_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER15_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer16: timer@04D28078 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D28078 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER16_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER16_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer17: timer@04D2808c { + compatible = "snps,dw-apb-timer"; + reg = <0x04D2808c 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER17_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER17_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer20: timer@04D38000 { + compatible = "snps,dw-apb-timer"; + reg = <0x004D38000 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + clocks = <&clock_reset TIMER20_CLK>; + clock-names = "timer"; + +// resets = <&clock_reset TIMER20_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer21: timer@04D38014 { + compatible = "snps,dw-apb-timer"; + reg = <0x004D38014 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + + clocks = <&clock_reset TIMER21_CLK>; + clock-names = "timer"; + +// resets = <&clock_reset TIMER21_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer22: timer@04D38028 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D38028 0x14>; + interrupt-parent = <&gic>; + interrupts = ; + + clocks = <&clock_reset TIMER22_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER22_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer23: timer@04D3803c { + compatible = "snps,dw-apb-timer"; + reg = <0x04D3803c 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER23_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER23_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer24: timer@04D38050 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D3805 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER24_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER24_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + timer25: timer@04D38064 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D38064 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER25_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER25_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer26: timer@04D38078 { + compatible = "snps,dw-apb-timer"; + reg = <0x04D38078 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER26_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER26_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + timer27: timer@04D3808c { + compatible = "snps,dw-apb-timer"; + reg = <0x04D3808c 0x14>; + interrupts = ; + + clocks = <&clock_reset TIMER27_CLK>; + clock-names = "timer"; +// resets = <&clock_reset TIMER27_DEV_SWRSTREQ>; +// reset-names = "timer"; + status = "okay"; + }; + + test_dma: test { + compatible = "smartlogic,dma_test"; + status = "okay"; + }; + + dmac: dma-controller@04540000 { + #dma-cells = <1>; + compatible = "snps,axi-dma-1.01a"; + reg = <0x04540000 0x400>; + clocks = <&clock_reset DMAS0_CORE_CLK_DIV>, <&clock_reset DMAS0_CORE_CLK>; + clock-names = "core-clk", "cfgr-clk"; + interrupt-parent = <&gic>; + interrupts = ; + dma-channels = <8>; + snps,dma-masters = <1>; + snps,data-width = <4>; + snps,block-size = <512 512 512 512 512 512 512 512>; + snps,priority = <0 1 2 3 4 5 6 7>; + snps,axi-max-burst-len = <8>; + }; + dmas1: dma-controller@04d38000 { + #dma-cells = <1>; + compatible = "snps,axi-dma-1.01a"; + reg = <0x04d38000 0x400>; + /*clocks = <&core_clk>, <&cfgr_clk>; + clock-names = "core-clk", "cfgr-clk"; */ + interrupt-parent = <&gic>; + interrupts = ; + dma-channels = <8>; + snps,dma-masters = <1>; + snps,data-width = <4>; + snps,block-size = <512 512 512 512 512 512 512 512>; + snps,priority = <0 1 2 3 4 5 6 7>; + snps,axi-max-burst-len = <8>; +// resets = <&clock_reset DMAS1_DEV_SWRSTREQ>; +// reset-names = "DMAS1"; + }; + + wdt: watchdog@04400000 { + compatible = "snps,dw-wdt"; + reg = <0x04400000 0x100>; + clock-names = "tclk"; + clocks = <&clock_reset MAIN_PCLK_DIV>; + interrupts = ; + status = "okay"; + }; + + wdt1: watchdog@04408000 { + compatible = "snps,dw-wdt"; + reg = <0x04408000 0x100>; + clock-names = "tclk"; + clocks = <&clock_reset MAIN_PCLK_DIV>; + interrupts = ; + status = "okay"; + }; + + rtc: rtc@04410000 { + compatible = "apm,xgene-rtc"; + reg = <0x04410000 0x8000>; + interrupts = ; + #clock-cells = <1>; + clocks = <&clock_reset RTC_CLK>; + }; + }; +}; + +&qspi_0 { + #address-cells = <1>; + #size-cells = <0>; + + flash0: n25q00@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "micron,mt25qu02g", "jedec,spi-nor"; + reg = <0>; /* chip select */ + spi-tx-bus-width= <0x1>; + spi-rx-bus-width= <0x1>; + // spi-max-frequency = <100000000>; + spi-max-frequency = <40000000>; + m25p,fast-read; + cdns,page-size = <256>; + cdns,block-size = <16>; + cdns,read-delay = <4>; + cdns,tshsl-ns = <50>; + cdns,tsd2d-ns = <50>; + cdns,tchsh-ns = <4>; + cdns,tslch-ns = <4>; + status = "okay"; + + partition@qspi-boot { + /* 8MB for raw data. */ + label = "Flash 0 Raw Data"; + reg = <0x0 0x800000>; + }; + + partition@qspi-rootfs { + /* 120MB for jffs2 data. */ + label = "Flash 0 jffs2 Filesystem"; + reg = <0x800000 0x7800000>; + }; + }; +}; + +// by daya 3 +&spi_1 { + #address-cells = <1>; + #size-cells = <0>; + + spidev0: spidev@0 { + compatible = "rohm,dh2228fv"; + spi-max-frequency = <8000000>; + reg = <0>; + bus-width = <4>; + device-width = <1>; + }; +}; + +&spi2 { + #address-cells = <1>; + #size-cells = <0>; + + phc@0 { /* Clock Matrix */ + compatible = "idt,8a34000"; + spi-max-frequency = <1000000>; + reg = <0>; + }; +}; + +&mdio0 { + ethphy0: ethernet-phy@0 { +// compatible = "ethernet-phy-ieee802.3-c22"; + compatible = "marvell,88E1510"; + reg = <1>; + device_type = "ethernet-phy"; +// marvell,reg-init = <0x12 0x14 0 0x4>; + pinctrl-names = "default"; + pinctrl-0 = <&phy0_reset_gpio>; + reset-assert-us = <10000>; + reset-deassert-us = <50000>; + reset-gpios = <&port1b 5 GPIO_ACTIVE_LOW>; /* GPIO1B5 */ + }; +}; + +&mdio1 { + status = "okay"; + ethphy1: ethernet-phy@1 { +// compatible = "ethernet-phy-ieee802.3-c22"; + compatible = "marvell,88E1510"; + reg = <1>; + device_type = "ethernet-phy"; +// marvell,reg-init = <0x12 0x14 0 0x4>; + pinctrl-names = "default"; + pinctrl-0 = <&phy1_reset_gpio>; + reset-assert-us = <10000>; + reset-deassert-us = <50000>; + reset-gpios = <&port1b 4 GPIO_ACTIVE_LOW>; /* GPIO1B4 */ + }; +}; + +/{ + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu-map { + cluster0 { + core0 { + cpu = <&cpu0>; + }; + + core1 { + cpu = <&cpu1>; + }; + core2 { + cpu = <&cpu2>; + }; + core3 { + cpu = <&cpu3>; + }; + + }; + + cluster1 { + core0 { + cpu = <&cpu4>; + }; + core1 { + cpu = <&cpu5>; + }; + core2 { + cpu = <&cpu6>; + }; + core3 { + cpu = <&cpu7>; + }; + }; + + }; + + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x0>; + enable-method = "spin-table"; + cpu-release-addr = <0x00 0x00>; + next-level-cache = <&cluster0_l2>; + numa-node-id = <0>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x1>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster0_l2>; + numa-node-id = <0>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x2>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster0_l2>; + numa-node-id = <0>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu3: cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x3>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster0_l2>; + numa-node-id = <0>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu4: cpu@100 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x100>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster1_l2>; + numa-node-id = <1>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu5: cpu@101 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x101>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster1_l2>; + numa-node-id = <1>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu6: cpu@102 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x102>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster1_l2>; + numa-node-id = <1>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cpu7: cpu@103 { + device_type = "cpu"; + compatible = "arm,cortex-a72", "arm,armv8"; + reg = <0x103>; + enable-method = "spin-table"; +// cpu-release-addr = <0x00 0x0a200000>; + cpu-release-addr = <0x00 0x045602c0>; + next-level-cache = <&cluster1_l2>; + numa-node-id = <1>; + operating-points-v2 = <&cpu0_opp_table>; + clocks = <&clock_reset A72CORE_SRCCLK_0>; + + }; + + cluster0_l2: l2-cache0 { + compatible = "cache"; + }; + + cluster1_l2: l2-cache1 { + compatible = "cache"; + }; + }; +}; + +/ { +cpu0_opp_table: opp_table0 { + compatible = "operating-points-v2"; + opp-shared; + + + opp-1500000000 { + opp-hz = /bits/ 64 <1500000000>; + clock-latency-ns = <40000>; + opp-suspend; + }; + + opp-1600000000 { + opp-hz = /bits/ 64 <1600000000>; + clock-latency-ns = <40000>; + opp-suspend; + }; + + opp-1800000000 { + opp-hz = /bits/ 64 <1800000000>; + clock-latency-ns = <40000>; + opp-suspend; + }; + }; +}; + + +/ { + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + reserved: test@10000000 { + no-map; + reg = <0 0x10000000 0x0 0xA8000000>; + }; + + /*reserved2: test2@10000000 { + no-map; + reg = <0x1 0x00000000 0x1 0x00000000>; + };*/ + + cdsp_fw_mem: memory@0xb0000000 { + compatible = "shared-dma-pool"; + reg = <0x0 0xF0000000 0 0x0C000000>; /*CMA (128+64)M*/ + reusable; + linux,cma-default; + }; + + + }; +}; + + +/ { + + fixed-rate-clocks { + xtal0 { + compatible = "smartlogic,clock-xtal0"; + clock-frequency = <20000000>; /* 20M */ +// clock-frequency = <1000000000>; /* 1000M */ + + }; + xtal1 { + compatible = "smartlogic,clock-xtal1"; + clock-frequency = <20000000>; + }; + + sfp_eth_clk { + compatible = "smartlogic,sfp_eth_clk"; + clock-frequency = <125000000>; + }; + pet_eth_ref_clk { + compatible = "smartlogic,pet_eth_ref_clk"; + clock-frequency = <20000000>; + }; + es_eth_ref_clk { + compatible = "smartlogic,es_eth_ref_clk"; + clock-frequency = <20000000>; + }; + + js_jesd_dev_clk { + compatible = "smartlogic,js_jesd_dev_clk"; + clock-frequency = <20000000>; + }; + + gmac1_ptp_pps { + compatible = "smartlogic,gmac1_ptp_pps"; + clock-frequency = <20000000>; + }; + gmac0_ptp_pps { + compatible = "smartlogic,gmac0_ptp_pps"; + clock-frequency = <20000000>; + }; + tmac_ptp_pps { + compatible = "smartlogic,tmac_ptp_pps"; + clock-frequency = <20000000>; + }; + }; +}; diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/makefile b/makefile new file mode 100644 index 0000000..293d6a9 --- /dev/null +++ b/makefile @@ -0,0 +1,167 @@ +#======================================================================================================== +# platform makefile +#FileName: makefile +#Author: xianfeng.du +#Data锛 2022-08-10 +#Description: top makefile +#======================================================================================================== +VERSION = 1.00 + +OPTION ?= +ifeq ($(OPTION),GCC) + CROSS_CC ?= +else +# TOOLS ?= /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin +# CROSS_CC ?= $(TOOLS)/aarch64-linux-gnu- + CROSS_CC ?= aarch64-linux-gnu- +endif + +AR = ar +CC = $(CROSS_CC)gcc +#$(info "CC=" $(CC)) + +DEFINES ?= +#DEFINES ?= UBLOX_ENABLE + +ifeq ($(fronthaul_option),jesd) +DEFINES += ENABLE_JESD_TEST +endif + +#optimization level -O2 +C_OPT_FLAGS ?= -O2 + +CC_FLAGS ?= $(C_OPT_FLAGS) -Wall -g +CC_FLAGS += -Werror -Wno-unused-function +CC_FLAGS += $(foreach d,$(DEFINES),-D$(d)) +CC_FLAGS += -fPIC + +LIB_DIRS ?= ./lib + +SRC_DIRS ?= ./app/src +SRC_DIRS += ./osp/src +SRC_DIRS += ./driver/arm_csu/src +SRC_DIRS += ./driver/init/src + +INCLUDE_DIRS ?= ./app/inc +INCLUDE_DIRS += ./osp/inc +INCLUDE_DIRS += ./driver/arm_csu/inc +INCLUDE_DIRS += ./driver/init/inc +test ?= $(test_option) +case ?= $(test_id) +ifeq ($(test),yes) + DEFINES += PALLADIUM_TEST +#testbench + CASE_ID := $(case) + TEST_DIR := ./test/case$(CASE_ID) + SRC_DIRS += $(TEST_DIR)/src + INCLUDE_DIRS += $(TEST_DIR)/inc +endif + +cache ?= $(cache_option) +ifeq ($(cache),yes) + DEFINES += CACHE_ENABLE +endif + +LD_FLAGS ?= -lgcc -lc +LD_FLAGS += -lm -ldl -Wl,-rpath=./ +LD_FLAGS += -lpthread +LD_FLAGS += -rdynamic -funwind-tables -ffunction-sections +ifeq ($(fronthaul_option),jesd) +LD_FLAGS += -lrfic +endif +$(info "DEFINES=" $(DEFINES)) + +#Flatten files and remove the duplicate by sort +ABS_SRC_DIRS := $(foreach d,$(SRC_DIRS),$(abspath $(d))) + +SRC_FILES := $(foreach d,$(ABS_SRC_DIRS),$(wildcard $(d)/*.c)) + +#main.c +MAIN_DIR := ./app/src +MAIN_FILE := ./app/src/main.c + +# Allow certain files to be excluded from the build +EXCL_SRCS ?= $(MAIN_FILE) +#EXCL_SRCS += ./app/src/main.c + +# Filter source files (allow files to be excluded) +FINAL_SRCS_FILES += $(foreach f,$(SRC_FILES),$(if $(findstring $(abspath $(f)),$(abspath $(EXCL_SRCS))),,$(f))) +#$(info "FINAL_SRCS_FILES=" $(FINAL_SRCS_FILES)) + +# ============================================================================== +# Variables: Output Files +# ============================================================================== +BUILD_DIR := ./build +OBJ_MAIN_DIR := $(BUILD_DIR)/main +OBJ_DIR := $(BUILD_DIR)/obj +#BIN_DIR := $(BUILD_DIR)/bin +#LIB_DIR := $(BUILD_DIR)/lib +#ELF_FILE := $(BIN_DIR)/test.elf +BIN_FILE := $(BUILD_DIR)/msgtransfer.out +LIB_FILE := $(BUILD_DIR)/libmsgtransfer.a + +OBJ_FILES += $(foreach f,$(FINAL_SRCS_FILES),$(OBJ_DIR)/$(patsubst %.c,%.o,$(notdir $(f)))) +OBJ_MAIN_FILES += $(foreach f,$(MAIN_FILE),$(OBJ_MAIN_DIR)/$(patsubst %.c,%.o,$(notdir $(f)))) + +ifeq ($(fronthaul_option),jesd) +#OBJ_FILES += $(wildcard $(RFIC_DIR)/*.o) +RFIC_OBJ_DIR := $(BUILD_DIR)/rfic_obj +RFIC_OBJ_FILES := $(wildcard $(RFIC_OBJ_DIR)/*.o) +else +RFIC_OBJ_FILES := +endif + +# ============================================================================== +# Rules: Compilation +# ============================================================================== +define DO_BUILD_OBJ +$(2)/%.o: $(1)/%.c | $(2) + @echo "# Compiling $$< -> $$@" + $(CC) $(CC_FLAGS) -o $$@ -c $$< $(patsubst %,-I %,$(INCLUDE_DIRS)) +#OBJ_TGTS += $(foreach f,$(wildcard $(1)/*.c),$(OBJ_DIR)/$(notdir $(basename $(1)))/$(patsubst %.c,%.o,$(notdir $(f)))) +endef + +define DO_BUILD_DIR +$(1): + @echo "# Creating directory $$@" + mkdir -p $$@ +endef + +define DO_BUILD + $(eval $(call DO_BUILD_DIR,$(1))) + $(foreach d,$(sort $(2)),$(eval $(call DO_BUILD_OBJ,$(d),$(1)))) +endef + +$(eval $(call DO_BUILD,$(OBJ_DIR),$(ABS_SRC_DIRS))) +$(eval $(call DO_BUILD,$(OBJ_MAIN_DIR), $(abspath $(MAIN_DIR)))) + +$(BIN_FILE):$(OBJ_FILES) $(OBJ_MAIN_FILES) +# @echo "# Creating bin directory $(BIN_DIR)" +# mkdir -p $(BIN_DIR) + + @echo "# Linking objects to form $@" + $(CC) -o $@ $^ $(LD_FLAGS) $(patsubst %,-L %,$(LIB_DIRS)) +# $(CC) -o $@ $^ $(LD_FLAGS) -T$(LINK_FILE) + +$(LIB_FILE):$(OBJ_FILES) $(RFIC_OBJ_FILES) +# @echo "# Creating lib directory $(LIB_DIR)" +# mkdir -p $(LIB_DIR) + + @echo "# Linking objects to form $@" + $(AR) -rcs $@ $^ +# $(CC) -shared -o $@ $^ $(LD_FLAGS) + +# ============================================================================== +# Rules: Targets +# ============================================================================== +.DEFAULT_GOAL := all +.PHONY: build lib clean +all: build lib + +build: $(BIN_FILE) + +lib: $(LIB_FILE) + +clean: + @echo "deleted all files" + rm -rf $(BUILD_DIR) diff --git a/osp/inc/OspMutProcess.h b/osp/inc/OspMutProcess.h new file mode 100644 index 0000000..903d919 --- /dev/null +++ b/osp/inc/OspMutProcess.h @@ -0,0 +1,23 @@ +#ifndef __OSPMUTPROCESSH__ + +#define __OSPMUTPROCESSH__ + + + +#ifdef __cplusplus + +extern "C" { + +#endif + +int32_t osp_mut_process_init(void); +int32_t osp_get_mut_process_id(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPRESHELLH__ */ + + diff --git a/osp/inc/crc32.h b/osp/inc/crc32.h new file mode 100644 index 0000000..1d1cb3d --- /dev/null +++ b/osp/inc/crc32.h @@ -0,0 +1,6 @@ +#ifndef __CRC32H__ +#define __CRC32H__ + +uint32_t osp_crc32(uint32_t crc, const unsigned char *p, uint32_t len); + +#endif \ No newline at end of file diff --git a/osp/inc/osp.h b/osp/inc/osp.h new file mode 100644 index 0000000..7aa53b2 --- /dev/null +++ b/osp/inc/osp.h @@ -0,0 +1,66 @@ +#ifndef __OSPH__ +#define __OSPH__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ospTypes.h" +//#include "ospDllLib.h" +//#include "ospSllLib.h" + + +#include "ospDelay.h" + +//#include "ospQFifoLib.h" +//#include "ospQJob.h" +//#include "ospQLib.h" +//#include "ospQPriLib.h" + +#include "ospSem.h" +#include "ospUtil.h" +#include "ospTimer.h" + +#include "ospAtomicOp.h" +#include "ospSoftQue.h" +#include "ospBuf.h" +#include "ospMsg.h" +#include "ospDbg.h" + +#include "ospTask.h" +#include "ospRtc.h" +#include "ospUdp.h" +#include "ospLog.h" +#include "ospDiag.h" +#include "ospMem.h" +#include "ospTest.h" +#include "ospShell.h" + +#include "ospTcp.h" +#include "ospHeap.h" +#include "ospSoftQue.h" +#include "OspMutProcess.h" +#include "ospOtherMsg.h" +#include "ospNetShell.h" +#include "ospFile.h" + +#undef LITTLE_ENDIAN + +#define OSP_VERSION "OSP-1.0.0" +extern int32_t g_ProcessId; + +//INT32 ospgdb; + +/* function prototype */ + +extern void osp_version(void); + +int32_t osp_init_done(); +int32_t osp_is_init_done(); + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPH__ */ + diff --git a/osp/inc/ospAtomicOp.h b/osp/inc/ospAtomicOp.h new file mode 100644 index 0000000..ebc279a --- /dev/null +++ b/osp/inc/ospAtomicOp.h @@ -0,0 +1,31 @@ +#ifndef __OSPATOMOPTH__ +#define __OSPATOMOPTH__ + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct { + int32_t counter; +} OSP_atomic_t; +#define atomic_read(v) (*(volatile int32_t *)&(v)->counter) +#define atomic_set(v, i) (((v)->counter) = (i)) + +/* function prototype */ +extern void osp_atomic_inc(int32_t *pVar); +extern void osp_atomic_dec(int32_t *pVar); +extern int32_t osp_atomic_get(int32_t *pVar); +extern void osp_atomic_set(int32_t *pVar, int32_t val); +extern void osp_atomic64_inc(int64_t *pVar); +extern void osp_atomic64_dec(int64_t *pVar); +extern int64_t osp_atomic64_get(int64_t *pVar); +extern void osp_atomic64_set(int64_t *pVar, int64_t val); + + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPATOMOPTH__ */ + + diff --git a/osp/inc/ospBuf.h b/osp/inc/ospBuf.h new file mode 100644 index 0000000..0ccca2b --- /dev/null +++ b/osp/inc/ospBuf.h @@ -0,0 +1,100 @@ +#ifndef __OSPBUFH__ +#define __OSPBUFH__ + +#ifdef __cplusplus +extern "C" { +#endif + + + +#define OSPBUF_SIZE (6*1024*1024UL) //(577*1024*1024UL) /* 512M->1G */ + +#define MAX_BLOCK_NUM 512 /*256*/ /* 1024->512 */ +#define MIN_SIZE_ORDER 6 +#define MAX_SIZE_ORDER 12/* 21 */ /* 16->19 64K->512K */ +#define MAX_OSPBUF_LEN (1 << MAX_SIZE_ORDER) + + +/*when mem is empty , we should make sure cmd is OK*/ +#define SIZE_ORDER_SHELL 10 // origin: 16 +#define SHELL_BUF_SIZE 1024 // origin: 1665535 + +#define SIZE_ORDER_PRINT_LOG SIZE_ORDER_SHELL +/*change with SIZE_ORDER_PRINT_LOG*/ +#define PRINT_LOG_BUF_SIZE SHELL_BUF_SIZE + + + +#define BUF_FOR_MEMORY 0 +#define BUF_FOR_MSG 1 + +typedef struct tag_Osp_BufQ_Tcb +{ + Osp_SoftQue soft_que; + uint64_t data[MAX_BLOCK_NUM]; + int32_t order; +}Osp_BufQ_Tcb; + + +#define OSP_BUFQ_TCBSIZE (sizeof(Osp_BufQ_Tcb)) + +#define OSP_BUFQ_ENCNT(que) que->soft_que.EnCnt +#define OSP_BUFQ_DECNT(que) que->soft_que.DeCnt +#define OSP_BUFQ_CUR(que) que->soft_que.CurNum +#define OSP_BUFQ_DEP(que) que->soft_que.Dep +#define OSP_BUFQ_ORDER(que) que->order +#define OSP_BUFQ_QUE(que) que->soft_que + +typedef struct tag_Osp_Block_Head +{ + uint32_t UserId; /*0x55aa???? */ + uint16_t RelaOrder; /*for TCB*/ + uint16_t UseType; /*memory or msg */ + uint16_t rev[2]; + uint32_t MagicOffset; /*for dect write over*/ + uint32_t idx; /*idx of this pool*/ + uint32_t NormalFlag; /*1: norbuffer 0: Pribuffer*/ + uint32_t Rev[2]; +}Osp_Block_Head; +extern char *OspBufferBase; + +#define BUFFER_BASE OspBufferBase + +#define BUFFERQUE_BASE_PRINT_LOG OspBufferqueBasePrintLog +#define BUFFERDATA_BASE_PRINT_LOG OspBufferDataBasePrintLog +#define BUFFERQUE_BASE_SHELL OspBufferqueBaseShell +#define BUFFERDATA_BASE_SHELL OspBufferDataBaseShell +#define BUFFERQUE_BASE_NOR OspBufferQueBaseNor +#define BUFFERDATA_BASE_NOR OspBufferDataBaseNor + +#define BUFFER_NORMAL_LEVEL 0 +#define BUFFER_SHELL_LEVEL 1 +#define BUFFER_PRINTLOG_LEVEL 2 + + + + + +#define VALIDIDMASK 0x55aa0000 +#define FREEUSERID 0x0000FFFF +#define BUF_MAGIC_NUM (0x12348765) + +#define OSP_BLOCK_HEAD_SIZE ((uint32_t)(sizeof(Osp_Block_Head))) +#define OSP_BUF_MAGICDATA_SIZE ((uint32_t)(sizeof(uint32_t))) + + +extern void *osp_get_buffer(uint32_t size, uint16_t UseType, uint16_t PriLevel); +extern OSP_STATUS osp_free_buffer(void *pBuffer); +extern void osp_show_buf_count(void); + + +extern OSP_STATUS osp_buf_init(void); + + + +#ifdef __cplusplus +} +#endif + +#endif /*__OSPBUFH__ */ + diff --git a/osp/inc/ospCfgToBin.h b/osp/inc/ospCfgToBin.h new file mode 100644 index 0000000..d6e9ad9 --- /dev/null +++ b/osp/inc/ospCfgToBin.h @@ -0,0 +1,34 @@ +#ifndef __OSP_CFG_TO_BIN_H__ +#define __OSP_CFG_TO_BIN_H__ + +#define APE_CFG_FILE_NAME_LEN (64) +#define APE_CFG_FILE_NUM (64) + +typedef struct OSP_CFG_FILE_REG +{ + char name[APE_CFG_FILE_NAME_LEN]; + uint32_t phy_addr; + uint32_t len; +}osp_cfg_file_reg; + + +typedef struct OSP_SPE_CFG_FILE_REG +{ + char name[APE_CFG_FILE_NAME_LEN]; + uint64_t vir_addr; + uint32_t len; +}osp_spe_cfg_file_reg; + +extern int32_t osp_read_cfg_file(void); + + +/* TestMac interface */ +extern int32_t osp_read_spe_cfg_file(char* path); +extern int32_t osp_get_cfg_file(char* name, uint64_t *paddr, uint32_t *psize); + +#ifdef HEARTBEAT_ENABLE +extern int8_t osp_get_im2ddr_to_file(uint8_t u8CoreId); +#endif + +#endif /* __OSP_CFG_TO_BIN_H__ */ + diff --git a/osp/inc/ospDbg.h b/osp/inc/ospDbg.h new file mode 100644 index 0000000..db26d3e --- /dev/null +++ b/osp/inc/ospDbg.h @@ -0,0 +1,79 @@ +#ifndef __OSPDBGH__ + +#define __OSPDBGH__ + + + +#ifdef __cplusplus + +extern "C" { + +#endif +#include + +#define MAX_DBGINFO_LEN (SHELL_BUF_SIZE-64) + + +#define CMD_DEBUG_LEVEL 0 +#define ERR_DEBUG_LEVEL 1 +#define WARNING_DEBUG_LEVEL 2 +#define RUN_DEBUG_LEVEL 3 +#define DBG_DEBUG_LEVEL 4 + +#define DeadFuncNum 64 + +OSP_STATUS osp_debug_out(int32_t level, char *fmt,...); +OSP_STATUS osp_debug_out_with_time(int32_t level, char *fmt,...); +void osp_local_shell_out_main(Osp_Msg_Head *pMsg); +OSP_STATUS osp_print(char *pbuf, uint32_t len); +int32_t osp_local_shell_in_main(); +void osp_debug_init(void); +void osp_show_msg_que_info(); +int32_t osp_trace_task(uint32_t Id); +int32_t osp_suspend_task(uint32_t Id); +int32_t osp_resume_task(uint32_t Id); +int32_t sinal_init(void); +void SetTimerParAll(char*pa, uint32_t val); +Osp_Msg_Head *osp_alloc_msg_print_log(void); + + + +#define OSP_TASK_SIGNAL_SUSPEND (SIGRTMIN + 1) +#define OSP_TASK_SIGNAL_RESUME (SIGRTMIN + 2) +#define OSP_TASK_SIGNAL_TRACE (SIGRTMIN + 3) +#define OSP_TASK_SIGNAL_RMSHELL (SIGINT) +#define OSP_TASK_SIGNAL_SEGV (SIGSEGV) +#define OSP_TASK_SIGNAL_BUSSERR (SIGBUS) + +void osp_debug_out_set_level(int32_t level); +int32_t osp_shell_dis_mem(int32_t num, uint64_t addr); +int32_t osp_shell_set_mem(int32_t val, uint64_t addr); +void osp_set_dbg_cmdlev(void); +void osp_set_dbg_errlev(void); +void osp_set_dbg_crunlev(void); +void osp_set_dbg_cwarlev(void); + +int32_t osp_task_dbg_out_enable_all(void); +int32_t osp_task_dbg_out_enable(uint32_t taskid); +int32_t osp_task_dbg_out_disable_all(void); +int32_t osp_task_dbg_out_disable(uint32_t taskid); +int32_t osp_task_dbg_out2log_disable_all(void); +int32_t osp_task_dbg_out2log_disable(uint32_t taskid); +int32_t osp_task_dbg_out2log_enable_all(void); +int32_t osp_task_dbg_out2log_enable(uint32_t taskid); + +void osp_assert(int32_t val); +int32_t osp_reg_dead_func(OSP_FUNCPTR pfunc); + + +#ifdef __cplusplus + +} + +#endif + + + +#endif /*__OSPDBGH__ */ + + diff --git a/osp/inc/ospDelay.h b/osp/inc/ospDelay.h new file mode 100644 index 0000000..6341b52 --- /dev/null +++ b/osp/inc/ospDelay.h @@ -0,0 +1,23 @@ +#ifndef __OSPDELAYH__ +#define __OSPDELAYH__ + + +#ifdef __cplusplus +extern "C" { +#endif + + + + + +/* function prototype */ + +extern OSP_STATUS osp_delay(uint32_t delay); +void osp_delay_while(uint64_t ns); + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPDELAYH__ */ + diff --git a/osp/inc/ospDiag.h b/osp/inc/ospDiag.h new file mode 100644 index 0000000..2bae196 --- /dev/null +++ b/osp/inc/ospDiag.h @@ -0,0 +1,98 @@ +#ifndef __OSPDIAGCH__ +#define __OSPDIAGCH__ + +#include "ospTypes.h" + +#ifdef __cplusplus +extern "C" { +#endif +#define DIAG_CNTID0 0 +#define DIAG_CNTID1 1 +#define DIAG_CNTID2 2 +#define DIAG_CNTID3 3 +#define DIAG_CNTID4 4 +#define DIAG_CNTID5 5 +#define DIAG_CNTID6 6 +#define DIAG_CNTID7 7 +#define DIAG_CNTID8 8 +#define DIAG_CNTID9 9 +#define DIAG_CNTID10 10 +#define DIAG_CNTID11 11 +#define DIAG_CNTID12 12 +#define DIAG_CNTID13 13 +#define DIAG_CNTID14 14 +#define DIAG_CNTID15 15 +#define DIAG_CNTID16 16 +#define DIAG_CNTID17 17 +#define DIAG_CNTID18 18 +#define DIAG_CNTID19 19 +#define DIAG_CNTID20 20 +#define DIAG_CNTID21 21 +#define DIAG_CNTID22 22 +#define DIAG_CNTID23 23 +#define DIAG_CNTID24 24 +#define DIAG_CNTID25 25 +#define DIAG_CNTID26 26 +#define DIAG_CNTID27 27 +#define DIAG_CNTID28 28 +#define DIAG_CNTID29 29 +#define DIAG_CNTID30 30 +#define DIAG_CNTID31 31 +#define DIAG_CNTID32 32 +#define DIAG_CNTID33 33 +#define DIAG_CNTID34 34 +#define DIAG_CNTID35 35 +#define DIAG_CNTID36 36 +#define DIAG_CNTID37 37 +#define DIAG_CNTID38 38 +#define DIAG_CNTID39 39 +#define DIAG_CNTID40 40 +#define DIAG_CNTID41 41 +#define DIAG_CNTID42 42 +#define DIAG_CNTID43 43 +#define DIAG_CNTID44 44 +#define DIAG_CNTID45 45 +#define DIAG_CNTID46 46 +#define DIAG_CNTID47 47 +#define DIAG_CNTID48 48 +#define DIAG_CNTID49 49 +#define DIAG_CNTID50 50 +#define DIAG_CNTID51 51 +#define DIAG_CNTID52 52 +#define DIAG_CNTID53 53 +#define DIAG_CNTID54 54 +#define DIAG_CNTID55 55 +#define DIAG_CNTID56 56 +#define DIAG_CNTID57 57 +#define DIAG_CNTID58 58 +#define DIAG_CNTID59 59 +#define DIAG_CNTID60 60 +#define DIAG_CNTID61 61 +#define DIAG_CNTID62 62 +#define DIAG_CNTID63 63 + + + +#define CNT_NUM_PER_TASK 64 +extern uint64_t *g_DiagCntBase; +#define TASK_CNT_ADD(TaskId, CntId) osp_atomic64_inc((int64_t *)(g_DiagCntBase + TaskId *CNT_NUM_PER_TASK + CntId)) +#define TASK_CNT_SET(TaskId, CntId, Val) osp_atomic64_set((int64_t *)(g_DiagCntBase + TaskId *CNT_NUM_PER_TASK + CntId), Val) +#define TASK_CNT_GET(TaskId, CntId) osp_atomic64_get((int64_t *)(g_DiagCntBase + TaskId *CNT_NUM_PER_TASK + CntId)) + +int32_t osp_diag_init(void); +OSP_STATUS OspCntAdd(uint32_t TaskId, uint32_t CntId); +OSP_STATUS OspCntSet(uint32_t TaskId, uint32_t CntId, uint64_t Val); +uint32_t osp_diag_cnt_str(uint32_t TaskId, char *pstr, uint32_t inlen); +int32_t osp_diag_cnt_init(void); +OSP_STATUS osp_show_tsk_diag_cnt(uint32_t TaskId); +OSP_STATUS osp_diag_cnt_add(uint32_t TaskId, uint32_t CntId); + + + + +#ifdef __cplusplus +} +#endif + +#endif /*__OSPRTCH__ */ + diff --git a/osp/inc/ospDump.h b/osp/inc/ospDump.h new file mode 100644 index 0000000..20402d6 --- /dev/null +++ b/osp/inc/ospDump.h @@ -0,0 +1,47 @@ +#ifndef __OSPDUMPH__ + +#define __OSPDUMPH__ + + + +#ifdef __cplusplus + +extern "C" { + +#endif + +#include "ospShell.h" +#include "ospHeap.h" + +#define APC_DM_LEN 0x200000 +#define MAX_DUMP_DIS_SIZE (6*1024*1024) +#define MAX_DUMP_LEN (1*1024*1024) + +void osp_dump_init(void); +void osp_dump_dis_mem(char* addr, uint32_t ulLen); +void osp_mem_print(char *addr , uint32_t ulLen); +void osp_dump_dm_test(uint8_t ucApcId, uint64_t ullAddr, uint32_t ullen); +OSP_STATUS osp_dump_proc(char *pName, module_type_e module, uint64_t phy_addr, uint64_t ulLen); +void osp_dump_dm(char *pName, uint32_t ulLen); +void osp_dump_sm(char *pName, uint32_t ulLen); +OSP_STATUS osp_dump_len_is_ok(module_type_e module, uint64_t ulLen); +int8_t osp_show_dm_by_apcid(uint8_t ucApcId, uint64_t phy_addr, uint32_t ulLen); +int8_t osp_dump_dm_by_apcid(char *pName, uint8_t ucApcId, uint64_t phy_addr, uint32_t ulLen); +int32_t osp_dump_phy_mem(uint64_t phy_addr, uint32_t len, uint64_t tmp_addr); + +#ifdef HEARTBEAT_ENABLE +int8_t osp_dump_dm_by_coreid(uint8_t coreid); +#endif + + +#ifdef __cplusplus + +} + +#endif + + + +#endif + + diff --git a/osp/inc/ospFile.h b/osp/inc/ospFile.h new file mode 100644 index 0000000..b3b7efc --- /dev/null +++ b/osp/inc/ospFile.h @@ -0,0 +1,36 @@ +#ifndef _FILE_H_ +#define _FILE_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct +{ + char filepath[128]; + int32_t flag; + mode_t mode; + int32_t fd; + pthread_mutex_t mutex; +} file_t; + +int32_t osp_file_init(file_t *file); + +int32_t osp_file_read(char *buffer, int32_t size, file_t *file); + +int32_t osp_file_write(file_t *file, char *buffer, int32_t size); +int32_t osp_mkdirs(char *path, mode_t mode); +int32_t osp_get_file_path(char *name, char *path); +int32_t osp_file_is_exist(char *file); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/osp/inc/ospHeap.h b/osp/inc/ospHeap.h new file mode 100644 index 0000000..acac3c2 --- /dev/null +++ b/osp/inc/ospHeap.h @@ -0,0 +1,57 @@ +#ifndef __OSPHEAP__ +#define __OSPHEAP__ + +#include "typedef.h" + +#define ECS_SM_DM_BASE_PHY_ADDR 0x007200000UL +#define PET_SM_DM_BASE_PHY_ADDR 0x008700000UL +#define APE_DM_BASE_PHY_ADDR 0x009400000UL //APCx(x:0-3):0x009400000+x*0x200000,2M per APC +#define SHARE_MEM_BASE_PHY_ADDR 0x009D00000UL +#define APE_PHY_BASE_PHY_ADDR 0x010000000UL +#define APE_TEXT_BASE_PHY_ADDR 0x090000000UL +#define ARM_APE_MSG_BASE_PHY_ADDR 0x0A0000000UL +#define APE_LOG_BASE_PHY_ADDR 0x0A8000000UL +#define RESERVED_BASE_PHY_ADDR 0x100000000UL +#define ARM_STACK_BASE_PHY_ADDR 0x100000000UL + + +#define LEN_OF_ECS_SM_DM 0x000060000UL //sm(0x20000) + dm(0x40000) +#define LEN_OF_PET_SM_DM 0x000060000UL //sm(0x20000) + dm(0x40000) +#define LEN_OF_APE_DM 0x000800000UL +#define LEN_OF_SHARE_MEM 0x000800000UL +#define LEN_OF_APE_PHY 0x080000000UL +#define LEN_OF_APE_TEXT 0x010000000UL +#define LEN_OF_ARM_APE_MSG 0x008000000UL +#define LEN_OF_APE_LOG 0x010000000UL +#define LEN_OF_ARM_STACK 0x100000000UL + +#define OSP_DISPLAY_MAX_LEN 0x400 +#define OSP_DISPLAY_PAGE_LEN 0x1000 + +typedef enum +{ + ECS_SM = 0, //actual ECS_SM_DM 384 total SM:128KB:0x007200000UL,DM:256KB:0x007220000UL + PET_SM, //actual PET_SM_DM 384 total SM:128KB:0x008700000UL,DM:256KB:0x008720000UL + APE_DM, + SHARE_MEM, + APE_PHY, + APE_TEXT, + ARM_APE_MSG, + APE_LOG, + ARM_STACK, + MEM_RESERVE +}module_type_e; + +void *get_static_mem(module_type_e module, uint64_t *len); +void *osp_heap_mem_init(char *pbuf, uint64_t size,void *head_of_static_mem,module_type_e module); +int8_t *osp_alloc_heap_mem(void *heap, uint32_t size); +int32_t osp_free_heap_mem(void *heap, char *pbuf); +int32_t osp_show_heap_mem(void *heap); +int32_t osp_virt_to_phy(module_type_e module, uint64_t virt_addr, uint64_t *phy_addr); +int32_t osp_phy_to_virt(module_type_e module, uint64_t phy_addr, uint64_t *virt_addr); +void osp_flush_dcache_area(void * volatile addr, uint64_t volatile len); +void osp_clean_dcache_area(void * volatile addr, uint64_t volatile len); +int32_t osp_invalid_dcache_area(module_type_e module, uint64_t virt_addr, uint64_t len); +int32_t osp_display_phy_mem(uint64_t phy_addr, uint32_t len); +#endif + diff --git a/osp/inc/ospHeartbeat.h b/osp/inc/ospHeartbeat.h new file mode 100644 index 0000000..7251e2a --- /dev/null +++ b/osp/inc/ospHeartbeat.h @@ -0,0 +1,14 @@ +#ifndef __OSP_HEARTBEAT__ +#define __OSP_HEARTBEAT__ + +typedef struct __OspHeartBeatInfo_t +{ + uint32_t u32CheckFlag; /* 0: check; 1: no check */ + uint32_t u32LastCounter; /* 涓婃蹇冭烦璁℃暟 */ + uint32_t u32LossCounter; /* 澶变俊璁℃暟 */ +}OspHeartbeatInfo_t; + +int8_t OspHeartbeatPro(void); + +#endif /* __OSP_HEARTBEAT__ */ + diff --git a/osp/inc/ospList.h b/osp/inc/ospList.h new file mode 100644 index 0000000..846a072 --- /dev/null +++ b/osp/inc/ospList.h @@ -0,0 +1,810 @@ +#ifndef __HPP_LIST_H__ +#define __HPP_LIST_H__ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#undef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL (void *)0 +#endif + +#define LIST_POISON1 NULL +#define LIST_POISON2 NULL + +#define offset(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +/** + * container_of - cast a member of a structure out to the containing structure + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. + * + */ +#define container_of(ptr, type, member) ({ \ + const typeof(((type *)0)->member)*__mptr = (ptr); \ + (type *)((char *)__mptr - offset(type, member)); }) + +#define WRITE_ONCE(var, val) \ + (*((volatile typeof(val) *)(&(var))) = (val)) + +#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) + +struct list_head { + struct list_head *next, *prev; +}__attribute__((packed)); + +/* + * Simple doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ + +#define LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = LIST_HEAD_INIT(name) + +static inline void INIT_LIST_HEAD(struct list_head *list) +{ + WRITE_ONCE(list->next, list); + list->prev = list; +} + +/* + * Insert a new entry between two known consecutive entries. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +#ifndef CONFIG_DEBUG_LIST +static inline void __list_add(struct list_head *new_node, + struct list_head *prev, + struct list_head *next) +{ + next->prev = new_node; + new_node->next = next; + new_node->prev = prev; + WRITE_ONCE(prev->next, new_node); +} +#else +extern void __list_add(struct list_head *new_node, + struct list_head *prev, + struct list_head *next); +#endif + +/** + * list_add - add a new entry + * @new_node: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void list_add(struct list_head *new_node, struct list_head *head) +{ + __list_add(new_node, head, head->next); +} + + +/** + * list_add_tail - add a new entry + * @new_node: new entry to be added + * @head: list head to add it before + * + * Insert a new entry before the specified head. + * This is useful for implementing queues. + */ +static inline void list_add_tail(struct list_head *new_node, struct list_head *head) +{ + __list_add(new_node, head->prev, head); +} + +/* + * Delete a list entry by making the prev/next entries + * point to each other. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static inline void __list_del(struct list_head * prev, struct list_head * next) +{ + next->prev = prev; + WRITE_ONCE(prev->next, next); +} + +/** + * list_del - deletes entry from list. + * @entry: the element to delete from the list. + * Note: list_empty() on entry does not return true after this, the entry is + * in an undefined state. + */ +#ifndef CONFIG_DEBUG_LIST +static inline void __list_del_entry(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); +} + +static inline void list_del(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; +} +#else +extern void __list_del_entry(struct list_head *entry); +extern void list_del(struct list_head *entry); +#endif + +/** + * list_replace - replace old entry by new one + * @old : the element to be replaced + * @new_node : the new element to insert + * + * If @old was empty, it will be overwritten. + */ +static inline void list_replace(struct list_head *old, + struct list_head *new_node) +{ + new_node->next = old->next; + new_node->next->prev = new_node; + new_node->prev = old->prev; + new_node->prev->next = new_node; +} + +static inline void list_replace_init(struct list_head *old, + struct list_head *new_node) +{ + list_replace(old, new_node); + INIT_LIST_HEAD(old); +} + +/** + * list_del_init - deletes entry from list and reinitialize it. + * @entry: the element to delete from the list. + */ +static inline void list_del_init(struct list_head *entry) +{ + __list_del_entry(entry); + INIT_LIST_HEAD(entry); +} + +/** + * list_move - delete from one list and add as another's head + * @list: the entry to move + * @head: the head that will precede our entry + */ +static inline void list_move(struct list_head *list, struct list_head *head) +{ + __list_del_entry(list); + list_add(list, head); +} + +/** + * list_move_tail - delete from one list and add as another's tail + * @list: the entry to move + * @head: the head that will follow our entry + */ +static inline void list_move_tail(struct list_head *list, + struct list_head *head) +{ + __list_del_entry(list); + list_add_tail(list, head); +} + +/** + * list_is_last - tests whether @list is the last entry in list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int32_t list_is_last(const struct list_head *list, + const struct list_head *head) +{ + return list->next == head; +} + +/** + * list_empty - tests whether a list is empty + * @head: the list to test. + */ +static inline int32_t list_empty(const struct list_head *head) +{ + return READ_ONCE(head->next) == head || READ_ONCE(head->next) == NULL; +} + +/** + * list_empty_careful - tests whether a list is empty and not being modified + * @head: the list to test + * + * Description: + * tests whether a list is empty _and_ checks that no other CPU might be + * in the process of modifying either member (next or prev) + * + * NOTE: using list_empty_careful() without synchronization + * can only be safe if the only activity that can happen + * to the list entry is list_del_init(). Eg. it cannot be used + * if another CPU could re-list_add() it. + */ +static inline int32_t list_empty_careful(const struct list_head *head) +{ + struct list_head *next = head->next; + return (next == head) && (next == head->prev); +} + +/** + * list_rotate_left - rotate the list to the left + * @head: the head of the list + */ +static inline void list_rotate_left(struct list_head *head) +{ + struct list_head *first; + + if (!list_empty(head)) { + first = head->next; + list_move_tail(first, head); + } +} + +/** + * list_is_singular - tests whether a list has just one entry. + * @head: the list to test. + */ +static inline int32_t list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} + +static inline void __list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + struct list_head *new_first = entry->next; + list->next = head->next; + list->next->prev = list; + list->prev = entry; + entry->next = list; + head->next = new_first; + new_first->prev = head; +} + +/** + * list_cut_position - cut a list into two + * @list: a new list to add all removed entries + * @head: a list with entries + * @entry: an entry within head, could be the head itself + * and if so we won't cut the list + * + * This helper moves the initial part of @head, up to and + * including @entry, from @head to @list. You should + * pass on @entry an element you know is on @head. @list + * should be an empty list or a list you do not care about + * losing its data. + * + */ +static inline void list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + if (list_empty(head)) + return; + if (list_is_singular(head) && + (head->next != entry && head != entry)) + return; + if (entry == head) + INIT_LIST_HEAD(list); + else + __list_cut_position(list, head, entry); +} + +static inline void __list_splice(const struct list_head *list, + struct list_head *prev, + struct list_head *next) +{ + struct list_head *first = list->next; + struct list_head *last = list->prev; + + first->prev = prev; + prev->next = first; + + last->next = next; + next->prev = last; +} + +/** + * list_splice - join two lists, this is designed for stacks + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice(const struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __list_splice(list, head, head->next); +} + +/** + * list_splice_tail - join two lists, each list being a queue + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice_tail(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __list_splice(list, head->prev, head); +} + +/** + * list_splice_init - join two lists and reinitialise the emptied list. + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * The list at @list is reinitialised + */ +static inline void list_splice_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __list_splice(list, head, head->next); + INIT_LIST_HEAD(list); + } +} + +/** + * list_splice_tail_init - join two lists and reinitialise the emptied list + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * Each of the lists is a queue. + * The list at @list is reinitialised + */ +static inline void list_splice_tail_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __list_splice(list, head->prev, head); + INIT_LIST_HEAD(list); + } +} + +/** + * list_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + */ +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +/** + * list_last_entry - get the last element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_last_entry(ptr, type, member) \ + list_entry((ptr)->prev, type, member) + +/** + * list_first_entry_or_null - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define list_first_entry_or_null(ptr, type, member) ({ \ + struct list_head *head__ = (ptr); \ + struct list_head *pos__ = READ_ONCE(head__->next); \ + pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ +}) + +/** + * list_next_entry - get the next element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +/** + * list_prev_entry - get the prev element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_prev_entry(pos, member) \ + list_entry((pos)->member.prev, typeof(*(pos)), member) + +/** + * list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + */ +#define list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +/** + * list_for_each_prev - iterate over a list backwards + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + */ +#define list_for_each_prev(pos, head) \ + for (pos = (head)->prev; pos != (head); pos = pos->prev) + +/** + * list_for_each_safe - iterate over a list safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_safe(pos, n, head) \ + for (pos = (head)->next, n = pos->next; pos != (head); \ + pos = n, n = pos->next) + +/** + * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_prev_safe(pos, n, head) \ + for (pos = (head)->prev, n = pos->prev; \ + pos != (head); \ + pos = n, n = pos->prev) + +/** + * list_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_last_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_prev_entry(pos, member)) + +/** + * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() + * @pos: the type * to use as a start point + * @head: the head of the list + * @member: the name of the list_head within the struct. + * + * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). + */ +#define list_prepare_entry(pos, head, member) \ + ((pos) ? : list_entry(head, typeof(*pos), member)) + +/** + * list_for_each_entry_continue - continue iteration over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_continue_reverse - iterate backwards from the given point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for (pos = list_prev_entry(pos, member); \ + &pos->member != (head); \ + pos = list_prev_entry(pos, member)) + +/** + * list_for_each_entry_from - iterate over list of given type from the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_for_each_entry_from(pos, head, member) \ + for (; &pos->member != (head); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member), \ + n = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_next_entry(n, member)) + +/** + * list_for_each_entry_safe_continue - continue list iteration safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_next_entry(pos, member), \ + n = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_next_entry(n, member)) + +/** + * list_for_each_entry_safe_from - iterate over list from current point safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_for_each_entry_safe_from(pos, n, head, member) \ + for (n = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_next_entry(n, member)) + +/** + * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_last_entry(head, typeof(*pos), member), \ + n = list_prev_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_prev_entry(n, member)) + +/** + * list_safe_reset_next - reset a stale list_for_each_entry_safe loop + * @pos: the loop cursor used in the list_for_each_entry_safe loop + * @n: temporary storage used in list_for_each_entry_safe + * @member: the name of the list_head within the struct. + * + * list_safe_reset_next is not safe to use in general if the list may be + * modified concurrently (eg. the lock is dropped in the loop body). An + * exception to this is if the cursor element (pos) is pinned in the list, + * and list_safe_reset_next is called after re-taking the lock and before + * completing the current iteration of the loop body. + */ +#define list_safe_reset_next(pos, n, member) \ + n = list_next_entry(pos, member) + +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +#define HLIST_HEAD_INIT { .first = NULL } +#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) +static inline void INIT_HLIST_NODE(struct hlist_node *h) +{ + h->next = NULL; + h->pprev = NULL; +} + +static inline int32_t hlist_unhashed(const struct hlist_node *h) +{ + return !h->pprev; +} + +static inline int32_t hlist_empty(const struct hlist_head *h) +{ + return !READ_ONCE(h->first); +} + +static inline void __hlist_del(struct hlist_node *n) +{ + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + + WRITE_ONCE(*pprev, next); + if (next) + next->pprev = pprev; +} + +static inline void hlist_del(struct hlist_node *n) +{ + __hlist_del(n); + n->next = LIST_POISON1; + n->pprev = LIST_POISON2; +} + +static inline void hlist_del_init(struct hlist_node *n) +{ + if (!hlist_unhashed(n)) { + __hlist_del(n); + INIT_HLIST_NODE(n); + } +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + WRITE_ONCE(h->first, n); + n->pprev = &h->first; +} + +/* next must be != NULL */ +static inline void hlist_add_before(struct hlist_node *n, + struct hlist_node *next) +{ + n->pprev = next->pprev; + n->next = next; + next->pprev = &n->next; + WRITE_ONCE(*(n->pprev), n); +} + +static inline void hlist_add_behind(struct hlist_node *n, + struct hlist_node *prev) +{ + n->next = prev->next; + WRITE_ONCE(prev->next, n); + n->pprev = &prev->next; + + if (n->next) + n->next->pprev = &n->next; +} + +/* after that we'll appear to be on some hlist and hlist_del will work */ +static inline void hlist_add_fake(struct hlist_node *n) +{ + n->pprev = &n->next; +} + +static inline bool hlist_fake(struct hlist_node *h) +{ + return h->pprev == &h->next; +} + +/* + * Check whether the node is the only node of the head without + * accessing head: + */ +static inline bool +hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h) +{ + return !n->next && n->pprev == &h->first; +} + +/* + * Move a list from one list head to another. Fixup the pprev + * reference of the first entry if it exists. + */ +static inline void hlist_move_list(struct hlist_head *old, + struct hlist_head *new_node) +{ + new_node->first = old->first; + if (new_node->first) + new_node->first->pprev = &new_node->first; + old->first = NULL; +} + +#define hlist_entry(ptr, type, member) container_of(ptr,type,member) + +#define hlist_for_each(pos, head) \ + for (pos = (head)->first; pos ; pos = pos->next) + +#define hlist_for_each_safe(pos, n, head) \ + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ + pos = n) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +/** + * hlist_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +/** + * hlist_for_each_entry_continue - iterate over a hlist continuing after current point + * @pos: the type * to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_continue(pos, member) \ + for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +/** + * hlist_for_each_entry_from - iterate over a hlist continuing from current point + * @pos: the type * to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_from(pos, member) \ + for (; pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +/** + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another &struct hlist_node to use as temporary storage + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_safe(pos, n, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ + pos && ({ n = pos->member.next; 1; }); \ + pos = hlist_entry_safe(n, typeof(*pos), member)) + +#ifdef __cplusplus +} +#endif + +#endif + + + diff --git a/osp/inc/ospLog.h b/osp/inc/ospLog.h new file mode 100644 index 0000000..d736c63 --- /dev/null +++ b/osp/inc/ospLog.h @@ -0,0 +1,112 @@ +#ifndef __OSPLOGH__ +#define __OSPLOGH__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ospShell.h" + +#define LOG_MODE_PATH "./server/logmode" +#define MAX_FILE_SIZE (32*1024*1024) +#define MAX_FILE_NUM (8) +#define MAX_LOG_CFG_NUM (64) +#define FREE_RAM_SIZE (150*1024*1024) + +typedef struct tag_osp_log_file_cfg_obj{ + uint32_t valied; + char logname[64]; + uint32_t max_file_size_M; + uint32_t max_file_num; + uint32_t with_time; + uint32_t cur_sum_len; + FILE* file; + uint32_t cur_file_idx; + uint32_t key; + uint32_t msg_type; +}osp_log_file_cfg; + +#if 1 +typedef struct OSP_LOG_MSG_INFO +{ + int64_t i64msg_type; + uint8_t *pu8msg_addr; + uint32_t u32msg_size; +}osp_log_msg_info_t; +#endif + +typedef struct tMsgTransferHeader { + uint8_t numMsg; + uint8_t cellIndex; + uint16_t rsv; + uint32_t msgType; + uint32_t msgLen; + //uint16_t log_size; + //uint16_t rsv; + uint32_t log_size; + uint32_t log_data[0]; +} MsgTransferHeader_t; + +#define MSG_TRANSFER_LOG_MSG_TYPE (0x124) +#define MSG_TRANSFER_SHELL_MSG_TYPE (0x125) +#define SPU_LOG_CLIENT_BUF_SIZE (512) /* one log: 512Bytes */ + +#define SYS_LOG_MAX_LEN_OF_MESSAGE (1024) +#define SYS_LOG_UDP_PORT (514) + +#if 0 +/*SYSLOG_SERV */ +#define SYSLOG_SERV_FACILITY (23) +#define SYSLOG_SERV_LEVEL (7) +#endif +#define APE_MSG_LOG_HEAD_SIZE sizeof(osp_sw_msg_info_t) +#define APE_MSG_LOG_LEN(x) (x->u16DataLen - APE_MSG_LOG_HEAD_SIZE) +#define APE_MSG_LOG_HEAD_TO_COMM(x) (char *)((uint64_t)x + APE_MSG_LOG_HEAD_SIZE) + + +OSP_STATUS osp_dbg_log(char *pbuf, uint32_t buflen); +OSP_STATUS osp_dbg_log_ext(char *pbuf, uint32_t buflen, int32_t LogId); + +void osp_dbg_log_main(osp_sw_msg_info_t *pMsg); +OSP_STATUS osp_close_log_file(FILE *fd); +OSP_STATUS osp_write_diaglog(char *pbuf, uint32_t len, uint32_t logid, uint32_t msg_type); +void osp_log_init(void); +int32_t osp_fflush_all_logfile(void); +void osp_get_current_time(void); +void osp_get_msgtype_name(uint32_t msg_type, char *msg_name); + +/* change the log out mode: don't use pthread and msgQ */ +#if 1 +uint8_t osp_log_msg_create(void); +int32_t osp_log_msg_get_id(void); +int32_t osp_log_msg_send(int32_t i32que_id, uint8_t *pu8msg_add, uint32_t u32msg_size); +int32_t osp_log_msg_recv(int32_t i32que_id, uint8_t *pu8msg_add, uint32_t u32max_size); +int32_t osp_log_msg_proc(uint8_t *pu8msg_add, uint32_t u32msg_size); +uint64_t osp_oam_msg_proc_task(void); +#endif +int32_t osp_create_oam_msg_task(uint8_t cpu, uint8_t pri); + +uint32_t rx_callback_oam(const char* buf,uint32_t payloadSize); +uint32_t osp_get_ape_port(osp_sw_msg_info_t *pMsg); +int8_t osp_log_mode_init();/*init log out mode*/ +bool osp_ip_is_null(char *ip); +bool osp_path_is_null(char *path); +void osp_cfg_default_log_mode(void); +void osp_log_mode_get(); +void osp_log_cfg_reload(void); +OSP_STATUS osp_ape_log_proc(osp_sw_msg_info_t *pMsg); +OSP_STATUS osp_arm_log_proc(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type); +void osp_platform_log_proc(osp_sw_msg_info_t *pMsg); +void osp_net_log_proc(char *pMsg, uint32_t len, uint32_t port); +uint32_t osp_filter_char(char *str, char c); +int8_t osp_log_mode_cfg(void); +uint32_t osp_get_freeram(void); +void osp_log_output(unsigned char level, const char *fmt, ...); +void osp_log_print(osp_sw_msg_info_t *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/osp/inc/ospMem.h b/osp/inc/ospMem.h new file mode 100644 index 0000000..b7026c8 --- /dev/null +++ b/osp/inc/ospMem.h @@ -0,0 +1,22 @@ +#ifndef __OSPMEMH__ +#define __OSPMEMH__ + + + +#ifdef __cplusplus +extern "C" { +#endif +#define OSP_MEM_SIZE (OSPBUF_SIZE + 1024*1024*6) + +extern OSP_STATUS osp_mem_init(void); +extern char *osp_alloc_mem(uint32_t Len); +extern void osp_free_mem(char *pbuf); +extern void osp_print_tatal_mem(void); +extern char *osp_get_init_mem(int32_t len); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/osp/inc/ospMsg.h b/osp/inc/ospMsg.h new file mode 100644 index 0000000..c567074 --- /dev/null +++ b/osp/inc/ospMsg.h @@ -0,0 +1,130 @@ +#ifndef __OSPMSGH__ +#define __OSPMSGH__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#define OSP_MEGQ_DEP 8192 + +#define OSP_MESSAGE_LEN sizeof(uint64_t) +extern char *gOspMsgQue; +#define IS_TIMER_MSG(pMsg)((pMsg->MsgType) == OSP_TIMER_TYPE) +#define OSP_MSG_QUE_SIZE (sizeof(Osp_MsgQ_Tcb)) + +typedef enum en_osp_msg_type +{ + OSP_TIMER_TYPE = 0x5555, + OSP_SHELL_TYPE, + + /*OSP_STR_LOG = 0x12350002, + OSP_BIN_LOG = 0x1234000a,*/ + OSP_STR_LOG = 0x60, + OSP_BIN_LOG = 0x61, + OSP_PLATFORM_LOG = 0x62, + OSP_MAX_TYPE, + +}EN_OSP_MSG_TYPE; + +typedef struct tag_Osp_Msg_Head +{ + uint32_t MsgType; + uint32_t MsgSize; /*is just msgdata len, not include Osp_Msg_Head*/ + uint32_t SrcId; + uint32_t DstId; + +}Osp_Msg_Head; + + +typedef enum OSP_MSG_TYPE +{ + UCP4008_KERNEL_INTER = 0, /* 鏍搁棿閫氫俊 */ + UCP4008_OSP_HANDSHAKE = 7, /* 鎻℃墜娑堟伅 */ + UCP4008_OSP_CFG_FILE, /* 寰爜閰嶇疆鏂囦欢娑堟伅 */ + UCP4008_OSP_DDR_INIT, /* DDR鍒濆鍖栭厤缃秷鎭 */ + UCP4008_OSP_DUMP, /* DUMP娑堟伅 */ + UCP4008_OSP_LOG, /* LOG娑堟伅 */ + UCP4008_OSP_SHELL, /* SHELL娑堟伅 */ + UCP4008_OSP_SHELL_ECHO, /* SHELL鍥炴樉娑堟伅 */ + UCP4008_KERNEL_INNER = 0XFF, /* 鏍稿唴閫氫俊娑堟伅 */ +}osp_msg_type; + +#if 0 +typedef struct tag_Osp_Ape_Msg_Head +{ + U32 MsgType; + U8 MsgSize; + U8 Msg_Padding[3]; /*reserved*/ + + U8 Src_Core_Id; + U8 Dst_Core_Id; + U8 Src_Task_Id; + U8 Dst_Task_Id; + + U8 data[0]; +}Osp_Ape_Msg_Head; +#endif +typedef struct tag_Osp_Timer_Msg_Block +{ + Osp_Msg_Head osp_msg_head; + uint64_t data; +}Osp_Timer_Msg_Block; + + +#define APE_MSG_DADA_LEN(x) (x->msg_size - APE_MSG_HEAD_SIZE) +#define APE_MSG_HEAD_SIZE sizeof(Osp_Ape_Msg_Head) +#define APE_MSG_HEAD_TO_COMM(x) (char *)((uint64_t)x + APE_MSG_HEAD_SIZE) +#define MSG_HEAD_SIZE sizeof(Osp_Msg_Head) +#define MSG_HEAD_TO_COMM(x) (char *)((uint64_t)x + MSG_HEAD_SIZE) +#define MSG_DADA_LEN(x) (x->MsgSize) +#define MSG_TO_OFFSET(x) ((uint64_t)x - (uint64_t)gOspMsgQue) +#define OFFSET_TO_MSG(x) (Osp_Msg_Head *)((uint64_t)x + (uint64_t)gOspMsgQue) + + +typedef struct tag_Osp_MsgQ_Tcb +{ + Osp_SoftQue soft_que; + uint64_t data[OSP_MEGQ_DEP]; +}Osp_MsgQ_Tcb; + + +#define OSP_MSGQ_ENCNT(que) que->soft_que.EnCnt +#define OSP_MSGQ_DECNT(que) que->soft_que.DeCnt +#define OSP_MSGQ_CUR(que) que->soft_que.CurNum +#define OSP_MSGQ_DEP(que) que->soft_que.Dep +#define OSP_MSGQ_QUE(que) que->soft_que + + + +extern int osp_create_msgq(Osp_MsgQ_Tcb *, char *name); +extern Osp_Msg_Head *osp_alloc_msg(uint32_t Len); +Osp_Msg_Head *osp_alloc_msgTimer(void); +Osp_Msg_Head *osp_alloc_msgCmd(uint32_t Len); +extern OSP_STATUS osp_send_msg(Osp_Msg_Head *p_MsgHead); +extern Osp_Msg_Head *osp_rev_msg(void); +extern Osp_Msg_Head *osp_rev_msgtry(void); +Osp_Msg_Head *osp_rev_msg_timeout(uint32_t timeout); + +extern void osp_free_msg(Osp_Msg_Head *pHead); +extern OSP_STATUS osp_msg_que_init(void); + +extern int dequetry(uint64_t *pvalue, Osp_MsgQ_Tcb *que); +extern int dequetimeout(uint64_t *pvalue, Osp_MsgQ_Tcb *que, uint32_t timeout); +extern Osp_Msg_Head *osp_rev_msgid(int id); +extern Osp_Msg_Head *osp_alloc_msgId(uint32_t Len, int id); +extern OSP_STATUS osp_send_msgId(Osp_Msg_Head *p_MsgHead,int id); +extern int osp_free_msgid(Osp_Msg_Head *pHead,int id); +extern OSP_STATUS osp_send_por_msg(Osp_Msg_Head *p_MsgHead, Osp_MsgQ_Tcb *que); +extern Osp_Msg_Head *osp_rev_promsg(Osp_MsgQ_Tcb *que); + + + + + +#ifdef __cplusplus +} +#endif + +#endif /*__OSPMSGH__ */ + diff --git a/osp/inc/ospNetShell.h b/osp/inc/ospNetShell.h new file mode 100644 index 0000000..e7e0d64 --- /dev/null +++ b/osp/inc/ospNetShell.h @@ -0,0 +1,26 @@ +#ifndef __OSPRESHELLLOCALH__ + +#define __OSPRESHELLLOCALH__ + + + +#ifdef __cplusplus + +extern "C" { + +#endif + +int32_t serve_main(void); + +int32_t osp_net_shell_init(void); +int32_t osp_net_shell_main(Osp_Msg_Head *pMsg); +int32_t osp_net_shell_out(Osp_Msg_Head *pMsg); +int32_t osp_del_udp(int32_t udpid); +int32_t osp_net_msg_main(Osp_Msg_Head *pMsg); +#ifdef __cplusplus +} +#endif + +#endif /* __OSPRESHELLLOCALH__ */ + + diff --git a/osp/inc/ospOtherMsg.h b/osp/inc/ospOtherMsg.h new file mode 100644 index 0000000..b8b2d81 --- /dev/null +++ b/osp/inc/ospOtherMsg.h @@ -0,0 +1,20 @@ +#ifndef __OSPOTHERMSGH__ +#define __OSPOTHERMSGH__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define OSP_MAX_OTHER_MSG_LEN (64*1024) + +int32_t osp_send_othermsg(Osp_Msg_Head *pMsg, uint64_t data); +Osp_Msg_Head *osp_rev_other_msg(uint64_t data); + + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPOTHERMSGH__ */ + diff --git a/osp/inc/ospRtc.h b/osp/inc/ospRtc.h new file mode 100644 index 0000000..8e6bd0a --- /dev/null +++ b/osp/inc/ospRtc.h @@ -0,0 +1,31 @@ +#ifndef __OSPRTCH__ +#define __OSPRTCH__ + +#include "ospTypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct tagRTC_DATE_TIME{ + uint32_t year; + uint32_t month; + uint32_t day; + uint32_t hour; + uint32_t minute; + uint32_t second; + uint32_t usecond; +} OSP_RTCTIME; + +/* function prototype */ + +extern OSP_STATUS osp_get_rtc_time(OSP_RTCTIME *pRtc); +extern void osp_show_rtc_time(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPRTCH__ */ + diff --git a/osp/inc/ospSem.h b/osp/inc/ospSem.h new file mode 100644 index 0000000..21712f9 --- /dev/null +++ b/osp/inc/ospSem.h @@ -0,0 +1,59 @@ +#ifndef __OSPSEMH__ +#define __OSPSEMH__ + +#ifdef __cplusplus +extern "C" { +#endif +#include "ospTypes.h" + +#include +#include +#include + + + +typedef enum /*SEM_B_STATE */ +{ + SEM_EMPTY, /* 0: semaphore not available */ + SEM_FULL /* 1: semaphore available */ +} SEM_B_STATE; + + + + +#define SEM_TYPE_MUTEX 0x1 +#define SEM_TYPE_COUNT 0x2 +#define SEM_TYPE_BINARY 0x3 + +typedef struct tag_lx_sem_t +{ + union + { + pthread_mutex_t sem_mutex; + sem_t sem_count; + } u; + + int32_t sem_type; +} lx_sem_t; + + +extern OSP_STATUS osp_sem_taketry(void *semId); +extern void *osp_semm_create(void); +extern void *osp_semsm_create(void *semId); +extern void *osp_semb_create(SEM_B_STATE initalState); +extern void *osp_semc_create(int32_t initCount); +extern OSP_STATUS osp_sem_take(void *semId, int32_t timeout); +extern OSP_STATUS osp_sem_give(void *semId); +extern OSP_STATUS osp_sem_delete(void *semId); + +extern OSP_STATUS osp_semr_take(void *semId, int32_t timeout); +extern OSP_STATUS osp_sem_wtake(void *semId, int32_t timeout); +extern OSP_STATUS osp_semrw_give(void *semId); +extern void *osp_semss_create(void *sem); + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPSEMH__ */ + diff --git a/osp/inc/ospShell.h b/osp/inc/ospShell.h new file mode 100644 index 0000000..d5643b6 --- /dev/null +++ b/osp/inc/ospShell.h @@ -0,0 +1,119 @@ +#ifndef _ospshelllxh +#define _ospshelllxh + + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include "ospTypes.h" +#include "ospSwQueue.h" + + +#define UCP4008_OSP_SHELL_REG 0x16 + +#define SPU_SHELL_MSG_DADA_LEN(x) (x->u16DataLen - OSP_SW_MSG_INFO_SIZE) +#define SPU_SHELL_MSG_HEAD_TO_COMM(x) (char *)((uint64_t)x + OSP_SW_MSG_INFO_SIZE) +#define SPU_SHELL_DADA_LEN(x) (x->u16DataLen) + +typedef struct tag_Osp_Ape_Msg_Head +{ + uint32_t msg_size; /* 娑堟伅闀垮害锛堝崟浣嶏細瀛楄妭锛 */ + uint8_t msg_type; /* 娑堟伅绫诲瀷 */ + uint8_t msg_padding[3];/* 淇濈暀瀛楁 */ + + uint8_t src_core_id; /* 婧愭牳ID */ + uint8_t dst_core_id; /* 鐩殑鏍窱D */ + uint8_t src_task_id; /* 婧愪换鍔D */ + uint8_t dst_task_id; /* 鐩殑浠诲姟ID */ + + uint8_t data[0]; +}Osp_Ape_Msg_Head; + +typedef struct tag_Osp_Server_Head +{ + uint8_t ip[16]; + uint8_t path[128]; + uint32_t ulport; +}Osp_Server_Head; + +typedef struct tag_Osp_Ape_Send_Count +{ + uint32_t ulsendcount; + uint32_t irq_no; + uint32_t irq_num; + uint32_t irq_handle_count; +}Osp_Ape_Send_Count; + +typedef struct tagOspCmdRtn +{ + char cmd[64]; + OSP_FUNCPTR wrapper; + OSP_FUNCPTR routine; + char descption[128]; + uint32_t argnum; +}OSP_CMD_RTN; + +typedef struct tagOspCmdExt +{ + char cmd[32]; + // char desc[32]; + uint32_t argnum; + uint32_t num; +}OSP_CMD_EXT; + +extern int32_t osp_shell_main(); +extern int32_t osp_execcmd(void); +extern int32_t osp_getcmdarg(char *cmd); +extern void osp_set_prompt(); +extern int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc); +extern int32_t osp_insert_cmd_ext(char *name, OSP_FUNCPTR pfunc, char *desc, int32_t argnum); +int32_t osp_shell_init(void); +bool osp_is_ape_cmd(char *pCmd); +void osp_get_ape_id(uint8_t ucApeid); +void osp_ape_msg_send(char *pCmd); +void osp_show_ape_taskinfo(void); +uint32_t rev_shell_log_data(uint32_t port_id,uint32_t queue_num,uint32_t el_ind,const char* buf,uint32_t remainedLength,uint32_t* handledLength); +uint32_t osp_ape_shell_wrapper(char **arg, uint32_t len, OSP_FUNCPTR func); +void osp_ape_set_log_level(uint8_t ucLevel); +void osp_show_print_level(void); +void osp_set_print_level(uint8_t ucLevel); +void osp_cmd_register(OSP_CMD_EXT *pCmdExt); +void osp_cmd_insert_proc(osp_sw_msg_info_t *pMsg); +void osp_reget_ape_cmd(void); +int32_t osp_shell_str_wrapper(char **arg, int32_t len, OSP_FUNCPTR func); +int32_t osp_shell_wrapper(char **arg, int32_t len, OSP_FUNCPTR func); +int32_t osp_shell_mem_wrapper(char **arg, int32_t len, OSP_FUNCPTR func); +void osp_ape_shell_out(Osp_Ape_Msg_Head *pMsg); +extern int32_t osp_display_phy_mem(uint64_t phy_addr, uint32_t len); +void osp_show_queue_ul_info(void); +void osp_show_queue_dl_info(void); +uint64_t osp_shell_task(void); +int8_t osp_server_cfg(uint8_t *ip, uint32_t ulport); +void osp_server_cfg_show(); +void osp_log_path_cfg(char *path); +void osp_server_get(); +void osp_set_platform_log_echo(uint8_t ucIsEcho); +void osp_set_ape_log_mode(uint8_t ucIsEcho); +void osp_set_platform_log_mode(uint8_t ucIsEcho); +void osp_set_arm_log_mode(uint8_t ucIsNet); +void osp_ape_csu_stop_cfg(uint8_t ucstop, uint8_t ucadvance); +void osp_ape_csu_int_cnt(); +/*void osp_get_tfu_location_info(void); +void osp_get_clock_tracking_state(void); +void osp_reset_clock_module(void); +void osp_set_clk_mode(clk_flag_e pseudo_flag);*/ +void osp_show_swqueue_info(); +void osp_show_info_by_coreid(osp_sw_msg_info_t *pMsg); +void osp_set_oam(uint8_t ucOam); + + +#ifdef __cplusplus +} +#endif + +#endif /*_ospshellh */ + diff --git a/osp/inc/ospSoftQue.h b/osp/inc/ospSoftQue.h new file mode 100644 index 0000000..d7ffb85 --- /dev/null +++ b/osp/inc/ospSoftQue.h @@ -0,0 +1,63 @@ +#ifndef __OSPSOFTH__ +#define __OSPSOFTH__ + +#ifdef __cplusplus +extern "C" { +#endif + + + +typedef struct tag_Osp_SoftQue +{ + lx_sem_t mutex; + lx_sem_t sem; + int32_t Id; //QUEUE ID + char Name[32]; + int32_t EnIdx; //入队索引 + int32_t DeIdx; //出队索引 + int32_t Dep; //队列深度 + int32_t CurNum; + uint64_t EnCnt; //入队统计计数 + uint64_t DeCnt; //出队统计计数 + uint64_t FullCnt; //队列满统计计数 + uint64_t EmptyCnt; //队列空统计计数 + uint32_t Mask; + uint64_t Buf[]; +}Osp_SoftQue; + + +#define QUE_NEED_WAKE 1 +#define QUE_NO_NEED_WAKE 0 + +#define QUE_ISBLOCK 1 +#define QUE_NOBLOCK 0 + + +int32_t osp_create_softque(Osp_SoftQue *que, int32_t Dep, char *name); +int32_t osp_soft_que_enque(uint64_t value, Osp_SoftQue *que, int32_t IsNeedWake); +int32_t osp_softque_deque(uint64_t *pvalue, Osp_SoftQue *que, int32_t IsBlock); +int32_t osp_softque_dequetry(uint64_t *pvalue, Osp_SoftQue *que); +int32_t osp_softque_dequeTimeOut(uint64_t *pvalue, Osp_SoftQue *que, uint32_t timeout); +int32_t osp_get_soft_que_info(Osp_SoftQue *que, char *pbuf); +int32_t osp_get_soft_que_desc(char *pbuf); + + + +#define OSP_SOFTQ_ENCNT(que) que->EnCnt +#define OSP_SOFTQ_DECNT(que) que->DeCnt +#define OSP_SOFTQ_CUR(que) que->CurNum +#define OSP_SOFTQ_DEP(que) que->Dep + + +#define OSP_SOFTQ_SIZE(dep) (sizeof(Osp_SoftQue) + sizeof(uint64_t) * dep) + + + + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPSOFTH__ */ + diff --git a/osp/inc/ospSwQueue.h b/osp/inc/ospSwQueue.h new file mode 100644 index 0000000..bc92d49 --- /dev/null +++ b/osp/inc/ospSwQueue.h @@ -0,0 +1,133 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ospSwQueue.h +// Author : +// Created On : 2023-01-19 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __OSP_SW_QUEUE_H__ +#define __OSP_SW_QUEUE_H__ + +#define SPU_APE_RFM_QUE_SIG_SIZE (512) /* 杞欢闃熷垪涓涓崟浣嶇殑闀垮害涓512瀛楄妭 */ +#define OSP_APE_RFM_SHELL_QUE_DEP (8) /* Shell杞欢闃熷垪鐨勬繁搴︿负8 */ +#define OSP_APE_RFM_QUE_DEP (256) +#define OSP_APE_RFM_MSG_QUE_DEP (128) + +#define OSP_APE_RFM_LOG_NUM (12) +#define OSP_APE_RFM_SHELL_NUM (24) + +typedef enum OSP_SW_QUEUE_INDEX +{ + SW_LOG_APE0 = 0, + SW_LOG_APE1, + SW_LOG_APE2, + SW_LOG_APE3, + SW_LOG_APE4, + SW_LOG_APE5, + SW_LOG_APE6, + SW_LOG_APE7, + SW_LOG_PET_RFM0, + SW_LOG_PET_RFM1, + SW_LOG_ECS_RFM0, + SW_LOG_ECS_RFM1, + + SW_SHELL_APE0, //12 + SW_SHELL_APE1, + SW_SHELL_APE2, + SW_SHELL_APE3, + SW_SHELL_APE4, + SW_SHELL_APE5, + SW_SHELL_APE6, + SW_SHELL_APE7, + SW_SHELL_PET_RFM0, + SW_SHELL_PET_RFM1, + SW_SHELL_ECS_RFM0, + SW_SHELL_ECS_RFM1, + + SW_SHELL_ECHO_APE0, //24 + SW_SHELL_ECHO_APE1, + SW_SHELL_ECHO_APE2, + SW_SHELL_ECHO_APE3, + SW_SHELL_ECHO_APE4, + SW_SHELL_ECHO_APE5, + SW_SHELL_ECHO_APE6, + SW_SHELL_ECHO_APE7, + SW_SHELL_ECHO_PET_RFM0, + SW_SHELL_ECHO_PET_RFM1, + SW_SHELL_ECHO_ECS_RFM0, + SW_SHELL_ECHO_ECS_RFM1, + + SW_QUEUE_MAX_INDEX, +}osp_sw_queue_index_e; + +typedef enum OSP_SW_QUEUE_TYPE +{ + OSP_SW_QUEUE_LOG, /* Log杞欢闃熷垪 */ + OSP_SW_QUEUE_SHELL, /* Shell杞欢闃熷垪 */ + OSP_SW_QUEUE_MAX, /* 杞欢闃熷垪鏈澶х被鍨 */ +}osp_sw_queue_type_e; + +typedef struct SPU_SW_QUEUE_MEM +{ + void* pvaddr; + uint16_t u16queue_id; + uint16_t u16queue_type; + uint8_t u8queue_offset; + uint8_t u8queue_padding; + uint16_t u16queue_mem_idx; + uint16_t u16queue_dep; + uint16_t u16queue_mask; + uint16_t u16queue_padding; + uint32_t u32queue_full_count; + uint32_t u32queue_empty_count; +}spu_sw_queue_mem_t; + +typedef struct SPU_SW_QUEUE_SHARE_INFO +{ + volatile uint16_t u16queue_deque_idx; + volatile uint16_t u16queue_enque_idx; + volatile uint16_t u16queue_alloc_idx; + volatile uint16_t u16queue_free_idx; + //volatile uint16_t u16queue_deque_count; + //volatile uint16_t u16queue_enque_count; + volatile uint16_t u16queue_msg[OSP_APE_RFM_QUE_DEP]; +}spu_sw_queue_share_info_t; + +#define SPU_SW_QUEUE_SHARE_INFO_SIZE (sizeof(spu_sw_queue_share_info_t)) + +typedef enum OSP_SW_MSG_PKT_TYPE +{ + PKT_TYPE_LOG = 0x60, + PKT_TYPE_STR_LOG = 0x61, +}osp_sw_msg_pkt_type_e; + +typedef struct OSP_SW_MSG_INFO +{ + uint8_t u8Head[2]; + uint16_t u16DataLen; + uint8_t u8PktType; + uint8_t u8CoreId; + uint16_t u16Tail; + int8_t i8Data[0]; +}osp_sw_msg_info_t; + +#define OSP_SW_MSG_INFO_HEAD1 (0xAB) +#define OSP_SW_MSG_INFO_HEAD2 (0xEF) +#define OSP_SW_MSG_INFO_SIZE sizeof(osp_sw_msg_info_t) + +uint8_t osp_sw_queue_init(void); + +uint8_t osp_sw_enque(osp_sw_queue_index_e emqueue_idx, int8_t *pi8addr); +uint8_t osp_sw_deque(osp_sw_queue_index_e emqueue_idx, osp_sw_msg_info_t **pstmsg_info); +int8_t *osp_sw_mem_malloc(osp_sw_queue_index_e emqueue_idx); + + +#endif /* __OSP_SW_QUEUE_H__ */ + diff --git a/osp/inc/ospSwTimer.h b/osp/inc/ospSwTimer.h new file mode 100644 index 0000000..47e4540 --- /dev/null +++ b/osp/inc/ospSwTimer.h @@ -0,0 +1,66 @@ +#ifndef __OSP_SW_TIMER__ +#define __OSP_SW_TIMER__ + +#define OSP_SW_TIMER_NAME_LEN (24) +#define OSP_SW_TIMER_NUM (4) + +#define OSP_GET_MIN(a, b) (((a) < (b)) ? (a) : (b)) + +/* 瀹氭椂鍣ㄥ洖璋冨嚱鏁 */ +typedef void (*OSP_CALLBACK)(void* pArg); + +/* 瀹氭椂鍣ㄧ被鍨 */ +typedef enum _OspTmrType +{ + OSP_TMR_ONESHOT = 0, /* 涓娆℃у畾鏃跺櫒 */ + OSP_TMR_PERIODIC /* 鍛ㄦ湡鎬у畾鏃跺櫒 */ +}OspTmrType; + +/* 瀹氭椂鍣ㄧ姸鎬 */ +typedef enum _OspTmrStatus +{ + OSP_TMR_STOPED = 0, /* 鍋滄 */ + OSP_TMR_RUNING /* 杩愯 */ +}OspTmrStatus; + +typedef enum _OspTmrUsing +{ + OSP_TMR_FREE = 0, /* 瀹氭椂鐐圭粨鐐圭┖闂 */ + OSP_TMR_BUSY /* 瀹氭椂鐐圭粨鐐瑰繖 */ +}OspTmrUsing; + +/* 瀹氭椂鍣ㄧ粨鏋勪綋 */ +typedef struct _OspSwTimer +{ + uint8_t u8Using; /* 瀹氭椂鍣ㄦ槸鍚﹀崰鐢細0-鏈崰鐢紱1-宸插崰鐢 */ + uint8_t u8Padding[3]; + uint8_t u8TmrName[OSP_SW_TIMER_NAME_LEN]; /* 瀹氭椂鍣ㄥ悕绉 */ + uint32_t u32TimeOut; /* 瀹氭椂鍣ㄨ秴鏃舵椂闂 */ + uint32_t u32RealTime; /* 褰撳墠鍓╀綑鏃堕棿 */ + OspTmrType emTmrType; /* 瀹氭椂鍣ㄧ被鍨 */ + OSP_CALLBACK pfnTmrCallBack; /* 瀹氭椂鍣ㄥ洖璋冨嚱鏁 */ + void* pArg; /* 瀹氭椂鍣ㄥ洖璋冨嚱鏁板弬鏁 */ + OspTmrStatus emTmrStatus; /* 瀹氭椂鍣ㄧ姸鎬 */ +}OspSwTimer_t; + +/* 瀹氭椂鍣ㄥ垵濮嬪寲鍑芥暟 */ +int8_t OspTmrInit(); + +/* 鍒涘缓瀹氭椂鍣 */ +int8_t OspTmrCreate(const char* pu8Name, + uint32_t u32TimeOut, + OspTmrType emTmrType, + OSP_CALLBACK pfnTmrCallBack, + void* pArg); + +/* 鍒犻櫎瀹氭椂鍣 */ +int8_t OspTmrDelete(uint8_t u8TmrIndex); + +/* 鍚姩瀹氭椂鍣 */ +int8_t OspTmrStart(uint8_t u8TmrIndex); + +/* 鍋滄瀹氭椂鍣 */ +int8_t OspTmrStop(uint8_t u8TmrIndex); + +#endif /* __OSP_SW_TIMER__ */ + diff --git a/osp/inc/ospTask.h b/osp/inc/ospTask.h new file mode 100644 index 0000000..ba51002 --- /dev/null +++ b/osp/inc/ospTask.h @@ -0,0 +1,187 @@ +#ifndef __OSPTASKMSG__ +#define __OSPTASKMSG__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "ospTypes.h" + +#define OSPTASK_MINID 1 +#define OSPTASK_MAXID 31 +#define OSP_MAX_TASK 64 //origin: 1024 + +#define OSP_TASK_STACK 16384 +#define OSP_CPU_NUM 8 + +#define OSP_NO_AFFIINITY (-1) + +#define OSP_PROCESS_MSG 0 +#define OSP_UDP_MSG 1 +#define OSP_OTHER_MSG 2 + +//#define OSP_UDP_MSG(x, ipaddr) (0x1234000000000000 |(x<<32) | inet_addr(ipaddr)) + + +typedef struct tag_OSP_UDP_TASK_DATA +{ + uint32_t port; + uint32_t IsRx; + char ip[32]; +}OSP_UDP_TASK_DATA; + + + + +typedef struct tag_OSP_TASKMSG_REG +{ + uint32_t TaskId; + uint8_t TaskName[32]; + uint32_t TaskPri; + OSP_FUNCPTR Init; + OSP_FUNCPTR MainLoop; + uint32_t Cpu; + uint32_t MsgType; + uint64_t MsgTypeData; +}OSP_TASKMSG_REG; + +typedef enum { + TASK_RUNNING = 1, + TASK_SUSPEND, + +}TaskState; + +typedef struct tag_OSP_TASKMSG +{ + OSP_TASKMSG_REG Osp_TaskMsg_Reg; + void *sem; + int32_t TId; + pthread_t PhreadId; + uint32_t Active; + uint32_t State; + uint64_t TaskRunCnt; + + uint32_t MsgQOffset; + uint32_t MsgQId; + uint32_t MsgRxCnt; + uint32_t MsgTxCnt; + uint32_t MsgAllocCnt; + uint32_t LogAllocCnt; + uint32_t MsgFreeCnt; + uint32_t MemAllocCnt; + uint32_t MemFreeCnt; + + uint32_t MsgFullCnt; + int32_t OsTaskPri; + uint32_t IsRt; + OSP_FUNCPTR send_msg_func; + OSP_FUNCPTR rev_msg_func; + uint64_t Msg_Que; + + uint32_t dbg_out_is_enable; + uint32_t dbg_out2log_is_enable; + uint32_t is_shell; + +}OSP_TASKCB; + +extern OSP_TASKCB *gOspTask; + +#define TASK_MSGQ(x) (Osp_MsgQ_Tcb *)(gOspTask[x].MsgQOffset + gOspMsgQue) +#define TASK_MSG_RXCNT(x) (gOspTask[x].MsgRxCnt) +#define TASK_MSG_TXCNT(x) (gOspTask[x].MsgTxCnt) +#define TASK_MSG_FULLCNT(x) (gOspTask[x].MsgFullCnt) +#define TASK_RUNCNT(x) (gOspTask[x].TaskRunCnt) +#define TASK_MSG_ALLOCCNT(x) (gOspTask[x].MsgAllocCnt) +#define TASK_LOGMSG_ALLOCCNT(x) (gOspTask[x].LogAllocCnt) +#define TASK_MSG_FREECNT(x) (gOspTask[x].MsgFreeCnt) + +#define TASK_MEM_ALLOCCNT(x) (gOspTask[x].MemAllocCnt) +#define TASK_MEM_FREECNT(x) (gOspTask[x].MemFreeCnt) +#define TASK_ACTIVE(x) (gOspTask[x].Active) +#define TASK_SYSID(x) (gOspTask[x].TId) +#define TASK_THREADID(x) (gOspTask[x].PhreadId) +#define TASK_STATE(x) (gOspTask[x].State) +#define TASK_TXMSG_HANDLE(x) (gOspTask[x].send_msg_func) +#define TASK_MSG_QUE(x) (gOspTask[x].Msg_Que) + +#define TASK_RXMSG_HANDLE(x) (gOspTask[x].rev_msg_func) + +#define OSP_INVALID_TASKID (-1) + + + +/*0 ~15 task ID belong to OSP*/ +typedef enum { + /*ID0 shoud rev means, ID1 is main_init*/ + OspTestTask = 1, + OspTestTask1, + OspTestTask2, + OspTestTask3, + OspTestTask4, + OspTestTask5, + OspTestTask6, + SysLogTask, + DbgLogTask, + DbgPriTask, + ShellTask, + RemShellTask, + OspTickLess, + localshellin, + localshellout, + remoteshellin, + remoteshellout, + remotelocalshellin, + ospnetshellrx, +#ifdef HEARTBEAT_ENABLE + OspTmrTask, +#endif + OspDbgLog, + CpriGmacTx, + CpriGmacRx, +}TaskId; +#define NOMSGTASK 0xaa000000 +#define MSGTASK 0x55000000 +#define MSGMASK 0xff000000 + +#define RTTASK 0x00aa0000 +#define NORMALTASK 0x00550000 +#define POLICYMASK 0x00ff0000 + +#define XXTASK 0x0000aa00 +#define XXMASK 0x0000ff00 + +#define PRIMASK 0x000000ff + + +#define RT_MSG_PRI(x) (x | MSGTASK | RTTASK) +#define RT_NOMSG_PRI(x) (x | NOMSGTASK | RTTASK) +#define XRT_MSG_PRI(x) (x | MSGTASK | RTTASK | XXTASK) + +#define IS_RT_PRI(x) ((x & POLICYMASK) == RTTASK) +#define NOMARL_MSG_PRI(x) (x | MSGTASK | NORMALTASK) +#define NOMARL_NOMSG_PRI(x) (x | NOMSGTASK | NORMALTASK) + + + +extern __thread __typeof__(uint32_t) thread_local_TaskId; +#define CURRENT_TASKID thread_local_TaskId + +extern OSP_STATUS osp_regtaskAll(void); +void *osp_find_sym(char *pName); +extern int32_t osp_get_task_num(void); +extern OSP_TASKCB *osp_get_taskcb_base(void); +extern OSP_STATUS osp_task_init(void); +extern void osp_show_task_info(void); +extern int32_t osp_task_is_shell(uint32_t taskid); +extern void osp_start_task_all(void); +extern int32_t osp_set_net_task_msg_que(int32_t taskid, int32_t txudpid, int32_t rxudpid); +extern int32_t osp_local_shell_task_is_reged(void); +extern OSP_STATUS osp_regtask(OSP_TASKMSG_REG *TaskRegTbl); + +#ifdef __cplusplus +} +#endif + +#endif /*__OSPSEMH__ */ + diff --git a/osp/inc/ospTcp.h b/osp/inc/ospTcp.h new file mode 100644 index 0000000..f907274 --- /dev/null +++ b/osp/inc/ospTcp.h @@ -0,0 +1,18 @@ +#ifndef __OSPTCPH__ +#define __OSPTCPH__ + +#ifdef __cplusplus +extern "C" { +#endif +int32_t osp_tcp_rev(int32_t socket_fd, char *pMsg, int32_t msgLen); +int32_t osp_tcp_send(int32_t socket_fd, char *pMsg, int32_t msgLen); +int32_t tcpSerCreat(int32_t port); +int32_t tcpCliCreat(int32_t port); +int32_t tcpAccept(int32_t socket_fd); +int32_t tcpConnet(int32_t socket_fd, char *targetIp, int32_t port); + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPTCH__ */ diff --git a/osp/inc/ospTest.h b/osp/inc/ospTest.h new file mode 100644 index 0000000..b2ffb3c --- /dev/null +++ b/osp/inc/ospTest.h @@ -0,0 +1,19 @@ +#ifndef __OSPTESTH__ +#define __OSPTESTH__ + +#ifdef __cplusplus +extern "C" { +#endif + +extern OSP_TASKMSG_REG g_TestRegTbl[]; + +//const U32 g_RegTestNum; + + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPH__ */ + diff --git a/osp/inc/ospTimer.h b/osp/inc/ospTimer.h new file mode 100644 index 0000000..fde58f5 --- /dev/null +++ b/osp/inc/ospTimer.h @@ -0,0 +1,80 @@ +#ifndef __OSPTIMERH__ +#define __OSPTIMERH__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* timer pool number define */ +#define OSP_TIMER_NUM (8) + + +typedef enum { + TIMER_RUNNING = 1, + TIMER_SUSPEND, + TIMER_READY, + +}TimerState; + + + + +typedef struct NODE{ + uint32_t TimerOff; + uint32_t NextNodeOff; +}Node; + +typedef struct tag_Osp_Timer_Tcb +{ + uint32_t Repeat; + uint32_t DstTaskId; + uint32_t Period; + int32_t TimeOut; + uint32_t Delay; + uint64_t RunCnt; + uint32_t State; + int32_t Fd; + + uint32_t MaxTimeOut; + uint32_t TimeOutCnt; + uint32_t Valid; + +}OSP_timer_Tcb; + +#define MSG_TO_PTIMER(msg) ((uint64_t)(msg) + MSG_HEAD_SIZE) + + + +extern OSP_STATUS osp_timer_pool_init(void); +extern void *osp_timer_create_sim(uint32_t DstTaskId, bool isRepeat, uint32_t timeout, uint32_t Delay); +extern void *OSP_timerCreate(uint32_t DstTaskId, uint64_t param1, uint64_t param2, bool isRepeat, uint32_t timeout, OSP_FUNCPTR timerCallback, uint32_t Delay); +extern OSP_STATUS osp_timer_start(void *pTimer); +extern OSP_STATUS OSP_timerDelete(void *pTimer); +extern void osp_timer_del_sim(void *timer); + +extern OSP_STATUS osp_timer_callback(uint64_t ospTaskId, uint64_t timer); +extern void osp_show_timer_count(void); +extern int32_t osp_clk_rate_get(void); +extern uint64_t osp_get_osp_ticks(void); +extern void osp_set_ticks(uint64_t ticks); +extern void showRunTimerInfo(void); +extern void showStopTimerInfo(void); +extern uint64_t OSP_getTimerRemainTime(void *pTimer); +extern uint32_t osp_get_systick(); +extern void osp_pridel_time(void); + +void osp_show_timer_info(void); +int32_t CreatFreSynFd(uint32_t pri, uint32_t offset); +void osp_timer_suspend_sim(void *timer); + + +void osp_tick_less(void); +uint64_t osp_get_cycel(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPTIMERH__ */ + diff --git a/osp/inc/ospTypes.h b/osp/inc/ospTypes.h new file mode 100644 index 0000000..9ca4ffb --- /dev/null +++ b/osp/inc/ospTypes.h @@ -0,0 +1,23 @@ +#ifndef __OSPTYPESH__ +#define __OSPTYPESH__ + +#include +#include "typedef.h" + +#define OSP_OK (0) /* 姝e父杩斿洖 */ +#define OSP_ERROR (-1) /* 閿欒杩斿洖 */ +#define OSP_PAR_ILL (-2) /* 鍏ュ弬閿欒 */ +#define OSP_FILE_ERROR (-3) /* 鏂囦欢閿欒 */ +#define OSP_PAR_REP (-4) /* 鍏ュ弬閲嶅 */ +#define OSP_QUE_FULL (-5) /* 杞槦鍒楁弧 */ +#define OSP_QUE_EMPT (-6) /* 杞槦鍒楃┖ */ +#define OSP_MEM_FULL (-7) /* 鍐呭瓨鐢宠澶辫触 */ + +typedef int32_t OSP_STATUS; +//typedef int32_t STATUS; + +typedef uint64_t (*OSP_FUNCPTR)(); + +#endif /* __OSPTYPESH__ */ + + diff --git a/osp/inc/ospUdp.h b/osp/inc/ospUdp.h new file mode 100644 index 0000000..0d378ea --- /dev/null +++ b/osp/inc/ospUdp.h @@ -0,0 +1,46 @@ +#ifndef __OSPUDPH__ +#define __OSPUDPH__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define OSP_UDP_RX 0 +#define OSP_UDP_TX 1 + + +extern int32_t osp_create_rxucp(int32_t port); +extern int32_t osp_create_txucp(int32_t port, char *targetIp); +extern int32_t osp_udp_send(char *pMsg, int32_t msgLen, int32_t udp_id); +extern int32_t osp_udp_receive(char *pbuf, int32_t size ,int32_t udp_id); +extern int32_t osp_send_udpmsg(Osp_Msg_Head *pMsg, uint64_t udp_id); +extern Osp_Msg_Head *osp_rev_udpmsg(uint64_t udp_id); +extern void OSP_Udp_Test_Main(Osp_Msg_Head *pMsg); +extern int32_t osp_udp_init(void); +extern void osp_show_udp(void); +extern int32_t osp_set_udp_noblock(int32_t udpid); +extern uint32_t osp_get_udp_rx_addr(int32_t udpid); +extern int32_t osp_get_txudp(char *ip, int32_t port); +extern int32_t osp_get_rxudp(char *ip, int32_t port); + +extern int32_t osp_get_ip_port(int32_t udpid, char *ip, int32_t *port); +extern int32_t osp_check_udpid(int32_t udpid); + +/*udp port distribution*/ + + +#define OSP_NETSHELL_RX_PORT 10003 + + + +#define OSP_UDPID_TO_QUE(t, r) ((t) << 16 | (r)) +#define OSP_UDPID_TO_TX(x) ((x) >> 16) +#define OSP_UDPID_TO_RX(x) ((x) & 0xffff) + + +#ifdef __cplusplus +} +#endif + +#endif /*__OSPBUFH__ */ + diff --git a/osp/inc/ospUtil.h b/osp/inc/ospUtil.h new file mode 100644 index 0000000..2cfd71e --- /dev/null +++ b/osp/inc/ospUtil.h @@ -0,0 +1,123 @@ +/* ospUtil.h: OSP utility header file */ + +#ifndef __OSPUTILH__ + +#define __OSPUTILH__ + + + +#ifdef __cplusplus + +extern "C" { + +#endif + + +struct list_head { + struct list_head *next, *prev; +}; + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + + + +#define OSP_NTOHL(x) (x) +#define OSP_NTOHS(x) (x) +#define OSP_HTONL(x) (x) +#define OSP_HTONS(x) (x) +#define OSP_NTOH64(x) (x) +#define OSP_HTON64(x) (x) + + + +#define OSP_OFFSET(structure, member) \ + ((uint64_t)&(((structure *)0)->member)) + + +#define __OSP_MEMBEROF(s, f, p) \ +((s *)((char *)(p) - OSP_OFFSET(s, f))) + +#define OSP_MEMBEROF(s, f, p) \ + (((p) ? __OSP_MEMBEROF(s, f, p) : ((s *)0))) + +#define OSP_MEMBER_SIZE(structure, member) \ + (sizeof (((structure *)0)->member)) + + +#define OSP_NELEMENTS(array) \ +((sizeof(array) / sizeof((array)[0]))) + + +#define OSP_ROUND_UP(x, align) \ +(((uint64_t) (x) + ((align) - 1)) & ~((align) - 1)) + + +#define OSP_ROUND_DOWN(x, align) \ +((uint64_t)(x) & ~((align) - 1)) + + + +/*32bit byte reversion */ + +#define OSP_LONGSWAP(x) \ +((((x) & 0xFF000000) >> 24) | \ + (((x) & 0x00FF0000) >> 8) | \ + (((x) & 0x0000FF00) << 8) | \ + (((x) & 0x000000FF) << 24) \ +) + +#define OSP_IS_POWEOF2(x) ((x & (x-1)) == 0) + + +/*reversing bit order*/ + + + + + + +#define OSP_SETBIT(x, pos) ((x) | (1<<(pos))) +#define OSP_CLEARBIT(x, pos) ((x) & (~(1 << (pos)))) +#define OSP_GET_BITS(x, start, len) (((x) >> (start)) & ((1 << (len)) - 1)) +#define OSP_SET_BITS(x, start, len, y) \ + (x) = (((x) & (~(((1 << (len)) - 1) << (start)))) | ((y) << (start))) + + + +/* reverse one specified bit: + + * a: U32/U16/U8 + + * pos: 0(lsb)~31(msb) + + */ + +#define OSP_REVERSE_BIT(a,pos) \ +(((((~(a)) >> (pos)) & 0x01) << (pos)) | ((a) & (~(1 << (pos))))) + + + +#ifndef min +#define min(a, b) (((a) < (b)) ? (a) : (b)) +#endif + + + +#ifndef max +#define max(a, b) (((a) > (b)) ? (a) : (b)) +#endif +#define ISPOW2(x) ((x & x - 1) == 0) + +#ifdef __cplusplus +} +#endif + +#endif /* __OSPUTILH__ */ + + diff --git a/osp/src/OspMutProcess.c b/osp/src/OspMutProcess.c new file mode 100644 index 0000000..0566c68 --- /dev/null +++ b/osp/src/OspMutProcess.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "osp.h" + + +int32_t MutProcessId = 0; + + + + + +int32_t osp_mut_process_init(void) +{ + int32_t fd; + + fd = open("/dev/read_add", O_RDWR | O_SYNC); + + if (-1 == fd) + { + MutProcessId =0; + return 0; + } + + read(fd, &MutProcessId, 4); + + return 0; + + +} + +int32_t osp_get_mut_process_id(void) +{ + return MutProcessId; +} + diff --git a/osp/src/crc32.c b/osp/src/crc32.c new file mode 100644 index 0000000..df0eaaa --- /dev/null +++ b/osp/src/crc32.c @@ -0,0 +1,237 @@ +/* + *This file is derived from osp_crc32.c from the zlib-1.1.3 distribution + *by Jean-loup Gailly and Mark Adler. + */ + +/*osp_crc32.c -- compute the CRC-32 of a data stream + *Copyright (C) 1995-1998 Mark Adler + *For conditions of distribution and use, see copyright notice in zlib.h + */ +#include +#include +#include +#include "ospTypes.h" +//#define LITTLE_ENDIAN + + + + + +#define uswap_16(x) \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)) +#define uswap_32(x) \ + ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24)) +#define _uswap_64(x, sfx) \ + ((((x) & 0xff00000000000000##sfx) >> 56) | \ + (((x) & 0x00ff000000000000##sfx) >> 40) | \ + (((x) & 0x0000ff0000000000##sfx) >> 24) | \ + (((x) & 0x000000ff00000000##sfx) >> 8) | \ + (((x) & 0x00000000ff000000##sfx) << 8) | \ + (((x) & 0x0000000000ff0000##sfx) << 24) | \ + (((x) & 0x000000000000ff00##sfx) << 40) | \ + (((x) & 0x00000000000000ff##sfx) << 56)) + +#ifdef LITTLE_ENDIAN +# define cpu_to_le16(x) (x) +# define cpu_to_le32(x) (x) +# define cpu_to_le64(x) (x) +# define le16_to_cpu(x) (x) +# define le32_to_cpu(x) (x) +# define le64_to_cpu(x) (x) +# define cpu_to_be16(x) uswap_16(x) +# define cpu_to_be32(x) uswap_32(x) +# define cpu_to_be64(x) uswap_64(x) +# define be16_to_cpu(x) uswap_16(x) +# define be32_to_cpu(x) uswap_32(x) +# define be64_to_cpu(x) uswap_64(x) +#else +# define cpu_to_le16(x) uswap_16(x) +# define cpu_to_le32(x) uswap_32(x) +# define cpu_to_le64(x) uswap_64(x) +# define le16_to_cpu(x) uswap_16(x) +# define le32_to_cpu(x) uswap_32(x) +# define le64_to_cpu(x) uswap_64(x) +# define cpu_to_be16(x) (x) +# define cpu_to_be32(x) (x) +# define cpu_to_be64(x) (x) +# define be16_to_cpu(x) (x) +# define be32_to_cpu(x) (x) +# define be64_to_cpu(x) (x) +#endif + +# define __cpu_to_be32(x) cpu_to_be32(x) +# define __cpu_to_be16(x) cpu_to_be16(x) +# define __be32_to_cpu(x) be32_to_cpu(x) +# define __be16_to_cpu(x) be16_to_cpu(x) + +#define ___htonl(x) __cpu_to_be32(x) +#define ___htons(x) __cpu_to_be16(x) +#define ___ntohl(x) __be32_to_cpu(x) +#define ___ntohs(x) __be16_to_cpu(x) + +#define htonl(x) ___htonl(x) +#define ntohl(x) ___ntohl(x) +#define htons(x) ___htons(x) +#define ntohs(x) ___ntohs(x) + + +#define tole(x) cpu_to_le32(x) + + +/*======================================================================== + *Table of CRC-32's of all single-byte values (made by make_crc_table) + */ + +static const uint32_t crc_table[256] = { +tole(0x00000000L), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL), +tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L), +tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L), +tole(0x09b64c2bL), tole(0x7eb17cbdL), tole(0xe7b82d07L), tole(0x90bf1d91L), +tole(0x1db71064L), tole(0x6ab020f2L), tole(0xf3b97148L), tole(0x84be41deL), +tole(0x1adad47dL), tole(0x6ddde4ebL), tole(0xf4d4b551L), tole(0x83d385c7L), +tole(0x136c9856L), tole(0x646ba8c0L), tole(0xfd62f97aL), tole(0x8a65c9ecL), +tole(0x14015c4fL), tole(0x63066cd9L), tole(0xfa0f3d63L), tole(0x8d080df5L), +tole(0x3b6e20c8L), tole(0x4c69105eL), tole(0xd56041e4L), tole(0xa2677172L), +tole(0x3c03e4d1L), tole(0x4b04d447L), tole(0xd20d85fdL), tole(0xa50ab56bL), +tole(0x35b5a8faL), tole(0x42b2986cL), tole(0xdbbbc9d6L), tole(0xacbcf940L), +tole(0x32d86ce3L), tole(0x45df5c75L), tole(0xdcd60dcfL), tole(0xabd13d59L), +tole(0x26d930acL), tole(0x51de003aL), tole(0xc8d75180L), tole(0xbfd06116L), +tole(0x21b4f4b5L), tole(0x56b3c423L), tole(0xcfba9599L), tole(0xb8bda50fL), +tole(0x2802b89eL), tole(0x5f058808L), tole(0xc60cd9b2L), tole(0xb10be924L), +tole(0x2f6f7c87L), tole(0x58684c11L), tole(0xc1611dabL), tole(0xb6662d3dL), +tole(0x76dc4190L), tole(0x01db7106L), tole(0x98d220bcL), tole(0xefd5102aL), +tole(0x71b18589L), tole(0x06b6b51fL), tole(0x9fbfe4a5L), tole(0xe8b8d433L), +tole(0x7807c9a2L), tole(0x0f00f934L), tole(0x9609a88eL), tole(0xe10e9818L), +tole(0x7f6a0dbbL), tole(0x086d3d2dL), tole(0x91646c97L), tole(0xe6635c01L), +tole(0x6b6b51f4L), tole(0x1c6c6162L), tole(0x856530d8L), tole(0xf262004eL), +tole(0x6c0695edL), tole(0x1b01a57bL), tole(0x8208f4c1L), tole(0xf50fc457L), +tole(0x65b0d9c6L), tole(0x12b7e950L), tole(0x8bbeb8eaL), tole(0xfcb9887cL), +tole(0x62dd1ddfL), tole(0x15da2d49L), tole(0x8cd37cf3L), tole(0xfbd44c65L), +tole(0x4db26158L), tole(0x3ab551ceL), tole(0xa3bc0074L), tole(0xd4bb30e2L), +tole(0x4adfa541L), tole(0x3dd895d7L), tole(0xa4d1c46dL), tole(0xd3d6f4fbL), +tole(0x4369e96aL), tole(0x346ed9fcL), tole(0xad678846L), tole(0xda60b8d0L), +tole(0x44042d73L), tole(0x33031de5L), tole(0xaa0a4c5fL), tole(0xdd0d7cc9L), +tole(0x5005713cL), tole(0x270241aaL), tole(0xbe0b1010L), tole(0xc90c2086L), +tole(0x5768b525L), tole(0x206f85b3L), tole(0xb966d409L), tole(0xce61e49fL), +tole(0x5edef90eL), tole(0x29d9c998L), tole(0xb0d09822L), tole(0xc7d7a8b4L), +tole(0x59b33d17L), tole(0x2eb40d81L), tole(0xb7bd5c3bL), tole(0xc0ba6cadL), +tole(0xedb88320L), tole(0x9abfb3b6L), tole(0x03b6e20cL), tole(0x74b1d29aL), +tole(0xead54739L), tole(0x9dd277afL), tole(0x04db2615L), tole(0x73dc1683L), +tole(0xe3630b12L), tole(0x94643b84L), tole(0x0d6d6a3eL), tole(0x7a6a5aa8L), +tole(0xe40ecf0bL), tole(0x9309ff9dL), tole(0x0a00ae27L), tole(0x7d079eb1L), +tole(0xf00f9344L), tole(0x8708a3d2L), tole(0x1e01f268L), tole(0x6906c2feL), +tole(0xf762575dL), tole(0x806567cbL), tole(0x196c3671L), tole(0x6e6b06e7L), +tole(0xfed41b76L), tole(0x89d32be0L), tole(0x10da7a5aL), tole(0x67dd4accL), +tole(0xf9b9df6fL), tole(0x8ebeeff9L), tole(0x17b7be43L), tole(0x60b08ed5L), +tole(0xd6d6a3e8L), tole(0xa1d1937eL), tole(0x38d8c2c4L), tole(0x4fdff252L), +tole(0xd1bb67f1L), tole(0xa6bc5767L), tole(0x3fb506ddL), tole(0x48b2364bL), +tole(0xd80d2bdaL), tole(0xaf0a1b4cL), tole(0x36034af6L), tole(0x41047a60L), +tole(0xdf60efc3L), tole(0xa867df55L), tole(0x316e8eefL), tole(0x4669be79L), +tole(0xcb61b38cL), tole(0xbc66831aL), tole(0x256fd2a0L), tole(0x5268e236L), +tole(0xcc0c7795L), tole(0xbb0b4703L), tole(0x220216b9L), tole(0x5505262fL), +tole(0xc5ba3bbeL), tole(0xb2bd0b28L), tole(0x2bb45a92L), tole(0x5cb36a04L), +tole(0xc2d7ffa7L), tole(0xb5d0cf31L), tole(0x2cd99e8bL), tole(0x5bdeae1dL), +tole(0x9b64c2b0L), tole(0xec63f226L), tole(0x756aa39cL), tole(0x026d930aL), +tole(0x9c0906a9L), tole(0xeb0e363fL), tole(0x72076785L), tole(0x05005713L), +tole(0x95bf4a82L), tole(0xe2b87a14L), tole(0x7bb12baeL), tole(0x0cb61b38L), +tole(0x92d28e9bL), tole(0xe5d5be0dL), tole(0x7cdcefb7L), tole(0x0bdbdf21L), +tole(0x86d3d2d4L), tole(0xf1d4e242L), tole(0x68ddb3f8L), tole(0x1fda836eL), +tole(0x81be16cdL), tole(0xf6b9265bL), tole(0x6fb077e1L), tole(0x18b74777L), +tole(0x88085ae6L), tole(0xff0f6a70L), tole(0x66063bcaL), tole(0x11010b5cL), +tole(0x8f659effL), tole(0xf862ae69L), tole(0x616bffd3L), tole(0x166ccf45L), +tole(0xa00ae278L), tole(0xd70dd2eeL), tole(0x4e048354L), tole(0x3903b3c2L), +tole(0xa7672661L), tole(0xd06016f7L), tole(0x4969474dL), tole(0x3e6e77dbL), +tole(0xaed16a4aL), tole(0xd9d65adcL), tole(0x40df0b66L), tole(0x37d83bf0L), +tole(0xa9bcae53L), tole(0xdebb9ec5L), tole(0x47b2cf7fL), tole(0x30b5ffe9L), +tole(0xbdbdf21cL), tole(0xcabac28aL), tole(0x53b39330L), tole(0x24b4a3a6L), +tole(0xbad03605L), tole(0xcdd70693L), tole(0x54de5729L), tole(0x23d967bfL), +tole(0xb3667a2eL), tole(0xc4614ab8L), tole(0x5d681b02L), tole(0x2a6f2b94L), +tole(0xb40bbe37L), tole(0xc30c8ea1L), tole(0x5a05df1bL), tole(0x2d02ef8dL) +}; + + + + +/*========================================================================= */ +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define DO_CRC(x) crc = tab[(crc ^ (x)) & 255] ^ (crc >> 8) +# else +# define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) +# endif + +/*========================================================================= */ + +/*No ones complement version. JFFS2 (and other things ?) + *don't use ones compliment in their CRC calculations. + */ +uint32_t osp_osp_crc32_no_comp(uint32_t crc, const unsigned char *buf, uint32_t len) +{ + const uint32_t *tab = crc_table; + const uint32_t *b = (const uint32_t *)buf; + size_t rem_len; + + crc = cpu_to_le32(crc); + /*Align it */ + if (((long)b) & 3 && len) { + unsigned char *p = (unsigned char *)b; + do { + DO_CRC(*p++); + } while ((--len) && ((long)p)&3); + b = (uint32_t *)p; + } + + rem_len = len & 3; + len = len >> 2; + for (--b; len; --len) { + /*load data 32 bits wide, xor data 32 bits wide. */ + crc ^= *++b; /*use pre increment for speed */ + DO_CRC(0); + DO_CRC(0); + DO_CRC(0); + DO_CRC(0); + } + len = rem_len; + /*And the last few bytes */ + if (len) { + unsigned char *p = (unsigned char *)(b + 1) - 1; + do { + DO_CRC(*++p); /*use pre increment for speed */ + } while (--len); + } + + return le32_to_cpu(crc); +} +#undef DO_CRC + +uint32_t osp_crc32(uint32_t crc, const unsigned char *p, uint32_t len) +{ + return osp_osp_crc32_no_comp(crc ^ 0xffffffffL, p, len) ^ 0xffffffffL; +} + +/* + *Calculate the osp_crc32 checksum triggering the watchdog every 'chunk_sz' bytes + *of input. + */ +uint32_t osp_osp_crc32_wd(uint32_t crc, const unsigned char *buf, uint32_t len, + uint32_t chunk_sz) +{ + + crc = osp_crc32 (crc, buf, len); + + return crc; +} + +void osp_osp_osp_crc32_wd_buf(const unsigned char *input, uint32_t ilen, + unsigned char *output, uint32_t chunk_sz) +{ + uint32_t crc; + + crc = osp_osp_crc32_wd(0, input, ilen, chunk_sz); + crc = htonl(crc); + memcpy(output, &crc, sizeof(crc)); +} + diff --git a/osp/src/osp.c b/osp/src/osp.c new file mode 100644 index 0000000..531dadf --- /dev/null +++ b/osp/src/osp.c @@ -0,0 +1,200 @@ +/* + * ospInit - Initailize OSP + * input: + * none + * return + * OSP_OK + */ +#define _GNU_SOURCE 1 +#define __USE_GNU 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "osp.h" +#include "ospCfgToBin.h" +#include "ucp_printf.h" +#include "ospSwTimer.h" +#include "ospDump.h" +#include "ospHeartbeat.h" +#include "ospLog.h" + +int32_t ospgdb = 1; +int32_t g_ProcessId = 0; + +#define MAX_ARGC_NUM 32 +#define MAX_ARGV_LEN 64 +int32_t parm_num; +char parm[MAX_ARGC_NUM][MAX_ARGV_LEN] = {0}; + +static int32_t g_osp_init_done = 0; + +int32_t osp_init_done() +{ + + g_osp_init_done = 1; + return 0; +} + +int32_t osp_is_init_done() +{ + return g_osp_init_done; +} + +/* + *osp_version - show OSP version + *input: + * none + *return + * none + */ + +void osp_version(void) +{ + osp_debug_out(CMD_DEBUG_LEVEL, "%s\n", OSP_VERSION" (" __DATE__ " - " __TIME__ ")"); +} + +void osp_exit(void) +{ + osp_debug_out(CMD_DEBUG_LEVEL, "osp exit ok!"); +} + +void osp_atexit(void) +{ + if (atexit(osp_exit) != 0) + osp_debug_out(CMD_DEBUG_LEVEL, "can't register ospExit"); +} + +int32_t osp_record_init_parm(int32_t argc, char *argv[]) +{ + int32_t i; + + if ((argc >= MAX_ARGC_NUM) || (NULL == argv)) + { + return -1; + } + parm_num = argc; + for (i = 0; i < argc; i++) + { + strcpy(parm[i], argv[i]); + } + + return 0; +} + +int32_t osp_get_init_parm(int32_t *argc, char *argv, int32_t size) +{ + int32_t i; + + if ((NULL == argc) || (NULL == argv)) + { + return -1; + } + + *argc = parm_num; + + for (i = 0; i < parm_num; i++) + { + strcpy(&argv[i*size], parm[i]); + } + return 0; +} +#if 0 +OSP_STATUS main(INT32 argc,char *argv[]) +{ + + osp_record_init_parm(argc, argv); + { + CURRENT_TASKID = 0; + + osp_debug_out_with_time(RUN_DEBUG_LEVEL, "starting OSP initializing...\n"); + + /*import all symbols for all so*/ + //osp_find_sym(""); + osp_mem_init(); + osp_mut_process_init(); + osp_sw_queue_init(); + osp_shell_init(); + osp_debug_init(); + osp_log_init(); + osp_msg_que_init(); + osp_buf_init(); + osp_udp_init(); + osp_timer_pool_init(); + osp_diag_init(); + test_main(); + osp_task_init(); + osp_delay(1000000);/*make sure all task start*/ + + osp_start_task_all(); + osp_init_done(); + osp_version(); + osp_atexit(); + osp_debug_out_with_time(RUN_DEBUG_LEVEL, "OSP initializing finished.\n"); + + while (1) + { + osp_delay(1000000); + } + } +} +#else +OSP_STATUS osp_init() +{ + printf("lib build: %s %s\n", __DATE__, __TIME__); + printf("---V1.3.SLEVMY.CK.202306122125_application_platform_2023_week28---\n"); + + UCP_PRINT_DEBUG("starting OSP initializing..."); + + osp_record_init_parm(0, NULL); + { + CURRENT_TASKID = 0; + + UCP_PRINT_DEBUG("starting OSP initializing...\n"); + + /*import all symbols for all so*/ + //osp_find_sym(""); + osp_mem_init(); + osp_mut_process_init(); + osp_sw_queue_init(); + osp_shell_init(); + osp_debug_init(); + osp_log_init(); + osp_dump_init(); + osp_msg_que_init(); + osp_buf_init(); + osp_udp_init(); + osp_timer_pool_init(); + osp_diag_init(); + osp_read_cfg_file(); + #ifdef HEARTBEAT_ENABLE + OspTmrInit(); + #endif + osp_task_init(); + osp_delay(1000);/*make sure all task start*/ + #ifdef HEARTBEAT_ENABLE + OspHeartbeatPro(); + #endif + UCP_PRINT_DEBUG("OSP initializing finished.\n"); + + osp_start_task_all(); + osp_init_done(); + osp_version(); + osp_atexit(); + UCP_PRINT_DEBUG("OSP initializing finished.\n"); + + /*while (1) + { + osp_delay(1000000); + }*/ + return OSP_OK; + } +} + +#endif diff --git a/osp/src/ospAtomicOp.c b/osp/src/ospAtomicOp.c new file mode 100644 index 0000000..4223578 --- /dev/null +++ b/osp/src/ospAtomicOp.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include "osp.h" + + +/* function prototype */ +void osp_atomic_inc(int32_t *pVar) +{ + if (pVar == NULL) + { + return; + } + + if (((uint64_t)pVar & 3) != 0) + { + (*pVar)++; + } + else + { + __sync_add_and_fetch(pVar, 1); + } +} + +void osp_atomic_dec(int32_t*pVar) +{ + if (pVar == NULL) + { + return; + } + + if (((uint64_t)pVar & 3) != 0) + { + (*pVar)--; + } + else + { + + __sync_sub_and_fetch(pVar, 1); + } +} + +int32_t osp_atomic_get(int32_t*pVar) +{ + if (pVar == NULL) + { + return 0; + } + + if (((uint64_t)pVar & 3) != 0) + { + return *pVar; + } + else + { + + return __sync_sub_and_fetch(pVar, 0); + } +} + +void osp_atomic_set(int32_t *pVar, int32_t val) +{ + + + atomic_set((OSP_atomic_t *)pVar,val); +} + + void osp_atomic64_inc(int64_t *pVar) +{ + if (pVar == NULL) + { + return; + } + + if (((uint64_t)pVar & 7) != 0) + { + (*pVar)++; + } + else + { + + __sync_add_and_fetch(pVar, 1); + } +} + +void osp_atomic64_dec(int64_t*pVar) +{ + if (pVar == NULL) + { + return; + } + + if (((uint64_t)pVar & 7) != 0) + { + (*pVar)--; + } + else + { + __sync_sub_and_fetch(pVar, 1); + } +} + +int64_t osp_atomic64_get(int64_t*pVar) +{ + if (((uint64_t)pVar & 7) != 0) + { + return *pVar; + } + else + { + + return __sync_or_and_fetch(pVar, 0); + } +} + +void osp_atomic64_set(int64_t*pVar, int64_t val) +{ + if (((uint64_t)pVar & 7) != 0) + { + *pVar = val; + } + else + { + + __sync_lock_test_and_set(pVar, val); + } +} \ No newline at end of file diff --git a/osp/src/ospBuf.c b/osp/src/ospBuf.c new file mode 100644 index 0000000..2f8437b --- /dev/null +++ b/osp/src/ospBuf.c @@ -0,0 +1,373 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "osp.h" + +/*lint -e826*/ + +/* buffer configuration information, + * element size must be (N+1)*basesize, + * where N is element index, basesize is the size of first element + */ + +/*buffer address range */ +char *OspBufferBase = NULL; +char *OspBufferqueBasePrintLog = NULL; +char *OspBufferDataBasePrintLog = NULL; +char *OspBufferqueBaseShell = NULL; +char *OspBufferDataBaseShell = NULL; +char *OspBufferQueBaseNor = NULL; +char *OspBufferDataBaseNor = NULL; + +int32_t osp_create_bufq(Osp_BufQ_Tcb *que, char *name, int32_t order) +{ + OSP_BUFQ_ORDER(que) = order; + return osp_create_softque(&OSP_BUFQ_QUE(que), MAX_BLOCK_NUM, name); +} + + + +int32_t osp_buf_enque(uint64_t value, Osp_BufQ_Tcb *que) +{ + return osp_soft_que_enque(value, &OSP_BUFQ_QUE(que), QUE_NO_NEED_WAKE); + +} + +int32_t osp_buf_deque(uint64_t *pvalue, Osp_BufQ_Tcb *que) +{ + return osp_softque_deque(pvalue, &OSP_BUFQ_QUE(que), QUE_NOBLOCK); +} + +//INT32 bufgdb = 1; +int32_t osp_buf_cb_init(uint32_t *puiLen) +{ + Osp_BufQ_Tcb *que; + Osp_BufQ_Tcb *quebase; + Osp_Block_Head *phead; + uint32_t Offset; + uint32_t idx; + uint32_t buf_size = 0; + uint8_t order; + + /*timer buffer init*/ + quebase = (Osp_BufQ_Tcb *) BUFFERQUE_BASE_PRINT_LOG; + order = SIZE_ORDER_PRINT_LOG; + que = quebase; + + osp_create_bufq(que, "timer_buffer", order); + + Offset = 0; + for (idx = 0; idx < MAX_BLOCK_NUM; idx++) + { + phead = (Osp_Block_Head *)(Offset + (uint64_t)BUFFERDATA_BASE_PRINT_LOG); + phead->MagicOffset = (1 << order) - OSP_BUF_MAGICDATA_SIZE; + phead->RelaOrder = 0; + phead->idx = idx; + phead->UserId = VALIDIDMASK; + phead->NormalFlag = BUFFER_PRINTLOG_LEVEL; + *(uint32_t *)((uint64_t)phead + phead->MagicOffset) = BUF_MAGIC_NUM; + osp_buf_enque(Offset + (uint64_t)BUFFERDATA_BASE_PRINT_LOG - (uint64_t)BUFFER_BASE, que); + Offset += (1 << order); + } + + /*cmd buffer init*/ + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_SHELL; + order = SIZE_ORDER_SHELL; + que = quebase; + + osp_create_bufq(que, "cmd_buffer", order); + + Offset = 0; + for (idx = 0; idx < MAX_BLOCK_NUM; idx++) + { + phead = (Osp_Block_Head *)(Offset + (uint64_t)BUFFERDATA_BASE_SHELL); + phead->MagicOffset = (1 << order) - OSP_BUF_MAGICDATA_SIZE; + phead->RelaOrder = 0; + phead->idx = idx; + phead->UserId = VALIDIDMASK; + phead->NormalFlag = BUFFER_SHELL_LEVEL; + *(uint32_t *)((uint64_t)phead + phead->MagicOffset) = BUF_MAGIC_NUM; + osp_buf_enque(Offset + (uint64_t)BUFFERDATA_BASE_SHELL - (uint64_t)BUFFER_BASE, que); + Offset += (1 << order); + } + + /*normal buffer init*/ + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_NOR; + #if 0 + for (order = MIN_SIZE_ORDER; order <= MAX_SIZE_ORDER; order++) + { + que = &quebase[order - MIN_SIZE_ORDER]; + + osp_create_bufq(que, "normal_buffer", order); + } + + Offset = 0; + for (order = MIN_SIZE_ORDER; order <= MAX_SIZE_ORDER; order++) + { +// que = (Osp_BufQ_Tcb *)((UINTPTR)quebase + OSP_BUFQ_TCBSIZE * (order - MIN_SIZE_ORDER)); + que = &quebase[order - MIN_SIZE_ORDER]; + for (idx = 0; idx < MAX_BLOCK_NUM; idx++) + { + phead = (Osp_Block_Head *)(Offset + (UINTPTR)BUFFERDATA_BASE_NOR); + phead->MagicOffset = (1 << order) - OSP_BUF_MAGICDATA_SIZE; + phead->RelaOrder = order - MIN_SIZE_ORDER; + phead->idx = idx; + phead->UserId = VALIDIDMASK; + phead->NormalFlag = BUFFER_NORMAL_LEVEL; + *(U32 *)((UINTPTR)phead + phead->MagicOffset) = BUF_MAGIC_NUM; + osp_buf_enque(Offset + (UINTPTR)BUFFERDATA_BASE_NOR - (UINTPTR)BUFFER_BASE, que); + Offset += (1 << order); + } + } + #else + + Offset = 0; + for (order = MIN_SIZE_ORDER; order <= MAX_SIZE_ORDER; order++) + { + que = &quebase[order - MIN_SIZE_ORDER]; + osp_create_bufq(que, "normal_buffer", order); + + buf_size = 1 << order; + for (idx = 0; idx < MAX_BLOCK_NUM; idx++) + { + phead = (Osp_Block_Head *)(Offset + (uint64_t)BUFFERDATA_BASE_NOR); + phead->MagicOffset = buf_size - OSP_BUF_MAGICDATA_SIZE; + phead->RelaOrder = order - MIN_SIZE_ORDER; + phead->idx = idx; + phead->UserId = VALIDIDMASK; + phead->NormalFlag = BUFFER_NORMAL_LEVEL; + *(uint32_t *)((uint64_t)phead + phead->MagicOffset) = BUF_MAGIC_NUM; + osp_buf_enque(Offset + (uint64_t)BUFFERDATA_BASE_NOR - (uint64_t)BUFFER_BASE, que); + Offset += buf_size; + } + } + #endif + *puiLen = Offset + (uint64_t)BUFFERDATA_BASE_NOR - (uint64_t)BUFFER_BASE; + return OSP_OK; +} + + + +void *osp_get_buffer(uint32_t size, uint16_t UseType, uint16_t PriLevel) +{ + Osp_BufQ_Tcb *quebase; + uint64_t offset; + int32_t ret; + int32_t RelaOrder; + Osp_Block_Head *phead; + uint32_t bufSize; + int32_t order = 0; + + bufSize = size + OSP_BLOCK_HEAD_SIZE + OSP_BUF_MAGICDATA_SIZE; + if ((NULL == BUFFER_BASE) || (bufSize > MAX_OSPBUF_LEN)) + { + return NULL; + } + + /*shell will use itself buffer*/ + if (osp_task_is_shell(CURRENT_TASKID)) + { + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_SHELL; + osp_assert(bufSize <= (1 << (OSP_BUFQ_ORDER(quebase)))); + ret = osp_buf_deque(&offset, quebase); + if (-1 != ret) + { + phead = (Osp_Block_Head *)(offset + (uint64_t)BUFFER_BASE); + phead->UserId = (VALIDIDMASK | CURRENT_TASKID); + phead->UseType = UseType; + return (void *)((uint64_t)phead + OSP_BLOCK_HEAD_SIZE); + } + return NULL; + } + + switch (PriLevel) + { + case BUFFER_NORMAL_LEVEL: + + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_NOR; + + /*查找满足bufSize的最小order*/ + for(order = MIN_SIZE_ORDER; order <= MAX_SIZE_ORDER; order++) + { + if(bufSize < (1 << order)) + { + RelaOrder = order - MIN_SIZE_ORDER; + ret = osp_buf_deque(&offset, &quebase[RelaOrder]); + if (-1 != ret) //若最小order没有buf了,继续向后面的order搜索 + { + phead = (Osp_Block_Head *)(offset + (uint64_t)BUFFER_BASE); + phead->UserId = (VALIDIDMASK | CURRENT_TASKID); + phead->UseType = UseType; + return (void *)((uint64_t)phead + OSP_BLOCK_HEAD_SIZE); + } + } + } + + //没有满足条件的buf,返回空 + if(MAX_SIZE_ORDER == order) + { + return NULL; + } + case BUFFER_PRINTLOG_LEVEL: + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_PRINT_LOG; + osp_assert(bufSize <= (1 << (OSP_BUFQ_ORDER(quebase)))); + ret = osp_buf_deque(&offset, quebase); + if (-1 != ret) + { + phead = (Osp_Block_Head *)(offset + (uint64_t)BUFFER_BASE); + phead->UserId = (VALIDIDMASK | CURRENT_TASKID); + phead->UseType = UseType; + return (void *)((uint64_t)phead + OSP_BLOCK_HEAD_SIZE); + } + return NULL; + default : + return NULL; + } +} + +OSP_STATUS osp_free_buffer(void *pBuffer) +{ + uint32_t offset; + Osp_Block_Head *phead; + Osp_BufQ_Tcb *quebase; + + + osp_assert(pBuffer != NULL); + + phead = (Osp_Block_Head *)((uint64_t)pBuffer - OSP_BLOCK_HEAD_SIZE); + + osp_assert((phead->UserId & 0xffff0000) == VALIDIDMASK); + osp_assert((phead->UserId & 0x0000ffff) != FREEUSERID); + osp_assert(*(uint32_t *)((uint64_t)phead + phead->MagicOffset) == BUF_MAGIC_NUM); + + offset = (uint64_t)phead - (uint64_t)BUFFER_BASE; + + phead->UserId = VALIDIDMASK | FREEUSERID; + + switch (phead->NormalFlag) + { + case BUFFER_NORMAL_LEVEL: + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_NOR; + osp_buf_enque(offset, &quebase[phead->RelaOrder]); + break; + case BUFFER_SHELL_LEVEL: + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_SHELL; + osp_buf_enque(offset, quebase); + break; + case BUFFER_PRINTLOG_LEVEL: + quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_PRINT_LOG; + osp_buf_enque(offset, quebase); + break; + } + return (OSP_OK); +} + + +void osp_show_buf_count(void) +{ + int32_t order; + char *pbuf; + char *p; + uint32_t len = 0; + Osp_BufQ_Tcb *quebase; + Osp_BufQ_Tcb *que; + + pbuf = malloc(10 * 1024); + osp_assert(pbuf != NULL); + + + len += sprintf(pbuf, "%-16s%-16s%-16s%-16s%-16s%-16s%-16s\n", "BlockSize", "MallocCnt", "FreeCnt", "UsedNum", + "TotalCnt", "UsedRate", "type"); + + + + que = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_SHELL; + + len += sprintf(pbuf+len, "%-16d%-16ld%-16ld%-16d%-16d%d%%\t\t%s\n", (1< +#include +#include +#include "ospTypes.h" +#include "ospCfgToBin.h" +#include "ospHeap.h" +#include "ospSem.h" +#include "ospSoftQue.h" +#include "ospMsg.h" +#include "ucp_printf.h" + +/***************************************************************************/ +/* ARM <---> APE */ +#define ARM_READ_CFG_FILE_OK (0xA0A0A0A0) /* ARM渚т笌APE渚х害瀹 */ +#define ARM_CFG_FILE_OFFSET (0x00400000) /* 閰嶇疆鏂囦欢璧峰鍦板潃鐩稿浜嶱HY绌洪棿锛屽亸绉4MB */ + +#define ARM_CFG_PHY_ADDR (0x10400000) /* 閰嶇疆鏂囦欢棣栧湴鍧 */ +#define ARM_CFG_PHY_SIZE (0x4000000) /* 閰嶇疆鏂囦欢鍖哄煙闀垮害锛64M */ +#define APE_CFG_INFO_ONE sizeof(osp_cfg_file_reg) + +#define ARM_CFG_INDXN (8) /* 4瀛楄妭锛欶lAG锛4瀛楄妭锛歂UM */ +#define ARM_CFG_FLAG (4) +#define ARM_CFG_NUM (4) + +#define ARM_CFG_INFO_ADDR (ARM_CFG_PHY_ADDR + ARM_CFG_INDXN) /* 閰嶇疆鏂囦欢澶翠俊鎭湴鍧 */ +#define ARM_CFG_INFO_SIZE (APE_CFG_INFO_ONE * APE_CFG_FILE_NUM) + +#define ARM_CFG_FILE_ADDR (ARM_CFG_INFO_ADDR + ARM_CFG_INFO_SIZE) /* 閰嶇疆鏂囦欢鏂囦欢淇℃伅鍦板潃 */ +#define ARM_CFG_FILE_SIZE (ARM_CFG_PHY_SIZE - ARM_CFG_INFO_SIZE -ARM_CFG_INDXN) /* 閰嶇疆鏂囦欢鏂囦欢鎬婚暱搴 */ + +/***************************************************************************/ +/* ARM <---> ARM */ +#define ARM_SPE_CFG_PHY_SIZE (0x1400000) /* 绾﹀畾鍦20M浠ュ唴 */ +#define ARM_SPE_CFG_INFO_ONE sizeof(osp_spe_cfg_file_reg) +#define ARM_SPE_CFG_INFO_SIZE (ARM_SPE_CFG_INFO_ONE * APE_CFG_FILE_NUM) + +#if 0 +#define ARM_SPE_CFG_PHY_ADDR (0xB8000000) /* 鎸囧畾閰嶇疆鏂囦欢棣栧湴鍧 */ +#define ARM_SPE_CFG_PHY_SIZE (0x10000) /* 鎸囧畾閰嶇疆鏂囦欢鍖哄煙闀垮害锛64K */ + +#define ARM_SPE_CFG_INFO_ADDR (ARM_SPE_CFG_PHY_ADDR + ARM_CFG_INDXN) /* 鎸囧畾閰嶇疆鏂囦欢澶翠俊鎭湴鍧 */ + +#define ARM_SPE_CFG_FILE_ADDR (ARM_SPE_CFG_INFO_ADDR + ARM_SPE_CFG_INFO_SIZE) /* 鎸囧畾閰嶇疆鏂囦欢鏂囦欢淇℃伅鍦板潃*/ +#endif +/***************************************************************************/ +/* ARM <---> APE */ +osp_cfg_file_reg g_osp_cfg_file_reg[APE_CFG_FILE_NUM]; +uint32_t g_osp_cfg_file_idx = 0; +void *g_ptr_static_mem = NULL; +uint64_t g_static_mem_size = 0; + +/***************************************************************************/ +/* ARM <---> ARM */ +osp_spe_cfg_file_reg g_spe_osp_cfg_file_reg[APE_CFG_FILE_NUM]; +uint32_t g_spe_osp_cfg_file_idx = 0; +void *g_spe_ptr_static_mem = NULL; +uint64_t g_spe_static_mem_size = 0; + +/***************************************************************************/ +/* ARM <---> APE */ +/* ARM渚э紝閰嶇疆鏂囦欢妯″潡鍒濆鍖 */ +int32_t osp_cfg_file_init() +{ + memset(&g_osp_cfg_file_reg, 0, sizeof(g_osp_cfg_file_reg)); + g_osp_cfg_file_idx = 0; + g_static_mem_size = 0; + + g_ptr_static_mem = get_static_mem(APE_PHY, &g_static_mem_size); + if (0 == g_static_mem_size) + { + UCP_PRINT_ERROR("get_static_mem(APE_PHY) error......\r\n"); + return OSP_ERROR; + } + g_ptr_static_mem += ARM_CFG_FILE_OFFSET; /* 鍦ㄥ唴瀛樿鍒掍腑锛岄厤缃枃浠剁殑璧峰鍦板潃闇瑕佸亸绉 */ + + /* 鍏堟妸NUM浣嶅啓鎴0 */ + *(uint32_t*)(g_ptr_static_mem+ARM_CFG_NUM) = 0; + + return OSP_OK; +} + +/***********************************************************/ +/* 绾﹀畾濡備笅锛 + 1. 鎵鏈夊師濮嬫枃浠朵负鏂囨湰鏂囦欢 + 2. 鎵鏈夊師濮嬫枃浠跺瓨鏀惧湪鐩綍锛 /ramfs/cfgDat/ + 3. 鎵鏈夊師濮嬫枃浠堕兘浠.dat涓哄悗缂 + 4. 闇瑕佸皢鏂囨湰鏂囦欢杞寲鎴愪簩杩涘埗鏂囦欢 + 5. 鎵鏈変簩杩涘埗鏂囦欢瀛樻斁鍦ㄧ洰褰曪細 /ramfs/config/ +*/ + +/* 灏嗘墍鏈夋枃鏈枃浠惰浆鍖栨垚浜岃繘鍒舵枃浠 */ +int32_t osp_cfg_file_to_bin() +{ + FILE *file = NULL; /* 閬嶅巻涓存椂鏂囦欢锛岃幏鍙栨墍鏈夋枃浠跺悕 */ + FILE *read_file = NULL; /* 鍘熷鏂囦欢 */ + FILE *write_file = NULL; /* 鐩殑鏂囦欢 */ + uint8_t len = 0; + uint8_t osp_cfg_file_idx = 0; /* 鏂囦欢涓暟 */ + uint32_t value = 0; + char *p_line_file_name = NULL; + char line_file_name_full[APE_CFG_FILE_NAME_LEN*2] = {0}; + char write_file_name[APE_CFG_FILE_NAME_LEN] = {0}; + char line_buf[100] = {0}; + + /* 閬嶅巻鍘熷鐩綍锛岃幏鍙栨墍鏈夋枃浠剁殑鏂囦欢鍚嶅強璺緞杈撳嚭鍒:tmpfile */ + system("find /ramfs/cfgDat/* -name '*.dat' > tmpfile"); + + /* 閬嶅巻鍘熷鐩綍锛岃幏鍙栨墍鏈夋枃浠剁殑鏂囦欢鍚嶈緭鍑哄埌:tmpfilename */ + //system("find /ramfs/cfgDat/* -name '*.dat' | sed 's#.*/##' > tmpfilename"); + + /* 鎵撳紑tmpfile鍐呮墍鏈夐渶瑕佸鐞嗙殑鏂囦欢 */ + file = fopen("./tmpfile", "rb"); + if (NULL == file) + { + UCP_PRINT_ERROR("Open file(tmpfile) error.\r\n"); + return OSP_FILE_ERROR; + } + /* 閫愪竴杞寲锛堟枃鏈枃浠 --> 浜岃繘鍒舵枃浠 */ + while(osp_cfg_file_idx < APE_CFG_FILE_NUM) + { + /* 姣忚鏄師濮嬫枃浠剁殑鍏ㄨ矾寰 */ + if (NULL == fgets(line_file_name_full, sizeof(line_file_name_full), file)) + { + /* 閬嶅巻鑷虫渶鍚庣粨鏉 */ + break; + } + p_line_file_name = strrchr(line_file_name_full, '/'); + p_line_file_name++; + + len = strlen(line_file_name_full); + line_file_name_full[len - 1] = '\0'; + + read_file = fopen(line_file_name_full, "rb"); + if (NULL == read_file) + { + UCP_PRINT_ERROR("Can not open src file: %s \r\n", line_file_name_full); + fclose(file); + return OSP_FILE_ERROR; + } + + sprintf(write_file_name, "/ramfs/config/%s", p_line_file_name); + UCP_PRINT_DEBUG("dst file: %s \r\n", write_file_name); + + write_file = fopen(write_file_name, "wb+"); + if (NULL == write_file) + { + UCP_PRINT_ERROR("Can not open dst file: %s \r\n", write_file_name); + fclose(file); + fclose(read_file); + return OSP_FILE_ERROR; + } + + /* 寮濮嬭浆鍖 */ + while(fgets(line_buf, 100, read_file)) + { + sscanf(line_buf, "0x%x", &value); + fwrite(&value, sizeof(value), 1, write_file); + } + + osp_cfg_file_idx++; + + fflush(read_file); + fclose(read_file); + fflush(write_file); + fclose(write_file); + } + + fclose(file); + system("rm tmpfile"); + + return OSP_OK; +} + +/* 灏嗕簩杩涘埗鏂囦欢瀹氬叆DDR */ +int32_t osp_bin_cfg_file_to_ddr() +{ + char *p_line_file_name = NULL; + char *p_line_file_name_begin = NULL; + char line_file_full_name[2*APE_CFG_FILE_NAME_LEN] = {0}; + char file_name[APE_CFG_FILE_NAME_LEN] = {0}; + + uint32_t len = 0; + uint32_t tmp_len = 0; + uint8_t osp_cfg_file_idx = 0; /* 鏂囦欢涓暟 */ + uint32_t ret = 0; /* 杩斿洖鍊煎垽鏂 */ + uint32_t file_len = 0; /* 鏂囦欢闀垮害 */ + uint32_t ddr_offset = 0; + + FILE *file = NULL; + FILE *read_file = NULL; + + /* 鍏ㄨ矾寰勬枃浠跺悕鍐欏叆锛 tmpfile鏂囦欢 */ + system("find /ramfs/config/* -name '*' > tmpfile"); + + /* 閬嶅巻 */ + file = fopen("./tmpfile", "rb"); + if (NULL == file) + { + UCP_PRINT_ERROR("[to_ddr]: Open file(tmpfile) error.\r\n"); + return OSP_FILE_ERROR; + } + + while(osp_cfg_file_idx < APE_CFG_FILE_NUM) + { + /* 姣忚鏄師濮嬫枃浠剁殑鍏ㄨ矾寰 */ + if (NULL == fgets(line_file_full_name, sizeof(line_file_full_name), file)) + { + /* 閬嶅巻鑷虫渶鍚庣粨鏉 */ + break; + } + p_line_file_name = strrchr(line_file_full_name, '/'); + p_line_file_name++; + + len = strlen(line_file_full_name); + line_file_full_name[len - 1] = '\0'; + + p_line_file_name_begin = line_file_full_name; + memcpy(file_name, p_line_file_name, len-(p_line_file_name - p_line_file_name_begin)); + //UCP_PRINT_DEBUG("[to_ddr]: file name : %s \r\n", file_name); + + read_file = fopen(line_file_full_name, "rb"); + if (NULL == read_file) + { + UCP_PRINT_ERROR("[to_ddr]: Can not open src file: %s \r\n", line_file_full_name); + fclose(file); + return OSP_FILE_ERROR; + } + + /* 鎵惧埌鏂囦欢缁撴潫绗 */ + ret = fseek(read_file, 0, SEEK_END); + if (ret) + { + UCP_PRINT_ERROR("[to_ddr]: Can not fseek: %s \r\n", line_file_full_name); + fclose(file); + fclose(read_file); + return OSP_FILE_ERROR; + } + + /* 璁$畻鏂囦欢闀垮害 */ + file_len = (uint32_t)ftell(read_file); + UCP_PRINT_DEBUG("[to_ddr]: file: %s ,Size: %d\r\n", line_file_full_name, file_len); + + /* 淇濇姢锛氭枃浠跺お澶氾紝绌洪棿涓嶅 */ + if ((file_len + ddr_offset) > ARM_CFG_FILE_SIZE) + { + UCP_PRINT_ERROR("[to_ddr]: too much file, no space... \r\n"); + fclose(read_file); + fclose(file); + system("rm tmpfile"); + return OSP_ERROR; + } + + /* 鍥炲埌鏂囦欢澶撮儴 */ + ret = fseek(read_file, 0, SEEK_SET); + + /* 鏇存柊鍏ㄥ眬鍙橀噺 */ + len = 0; + while(len < file_len) + { + tmp_len = fread((char*)(g_ptr_static_mem+ARM_CFG_INDXN+ARM_CFG_INFO_SIZE+ddr_offset+len), 1, file_len, read_file); + len += tmp_len; + } + + /* 鏇存柊鍏ㄥ眬鍙橀噺 */ + g_osp_cfg_file_reg[g_osp_cfg_file_idx].len = file_len; + memcpy(g_osp_cfg_file_reg[g_osp_cfg_file_idx].name, file_name, strlen(file_name)); + g_osp_cfg_file_reg[g_osp_cfg_file_idx].phy_addr = ARM_CFG_FILE_ADDR+ddr_offset; + g_osp_cfg_file_idx++; + ddr_offset += file_len; + + osp_cfg_file_idx++; + fclose(read_file); + } + + /* 鏇存柊閰嶇疆鏂囦欢澶翠俊鎭 */ + *(uint32_t *)(g_ptr_static_mem + ARM_CFG_NUM) = g_osp_cfg_file_idx; + memcpy((g_ptr_static_mem+ARM_CFG_INDXN), g_osp_cfg_file_reg, APE_CFG_INFO_ONE*g_osp_cfg_file_idx); + *(uint32_t *)g_ptr_static_mem = ARM_READ_CFG_FILE_OK; + + fclose(file); + system("rm tmpfile"); + + return OSP_OK; +} + +int32_t osp_read_cfg_file(void) +{ + int32_t ret = -1; + + /* 閰嶇疆鏂囦欢鍒濆鍖 */ + ret = osp_cfg_file_init(); + if (OSP_OK != ret) + { + UCP_PRINT_ERROR("[osp_read_cfg_file]: osp_cfg_file_init return error: %d\r\n", ret); + return ret; + } + + /* 璇婚厤缃枃浠 */ + ret = osp_cfg_file_to_bin(); + if (OSP_OK != ret) + { + UCP_PRINT_ERROR("[osp_read_cfg_file]: osp_cfg_file_to_bin return error: %d\r\n", ret); + return ret; + } + + /* 杞寲骞跺啓鍏 */ + ret = osp_bin_cfg_file_to_ddr(); + if (OSP_OK != ret) + { + UCP_PRINT_ERROR("[osp_read_cfg_file]: osp_bin_cfg_file_to_ddr return error: %d\r\n", ret); + return ret; + } + return OSP_OK; +} + +/***************************************************************************/ +/* ARM <---> ARM */ +int32_t osp_spe_cfg_file_init() +{ + memset(&g_spe_osp_cfg_file_reg, 0, sizeof(g_spe_osp_cfg_file_reg)); + g_spe_osp_cfg_file_idx = 0; + g_spe_static_mem_size = 0; + + g_spe_ptr_static_mem = malloc(ARM_SPE_CFG_PHY_SIZE); + if (NULL == g_spe_ptr_static_mem) + { + UCP_PRINT_ERROR("get_static_mem(ARM_STACK) error......\r\n"); + return OSP_ERROR; + } + return OSP_OK; + +#if 0 + g_spe_ptr_static_mem = get_static_mem(ARM_STACK, &g_spe_static_mem_size); + if (0 == g_spe_static_mem_size) + { + UCP_PRINT_ERROR("get_static_mem(ARM_STACK) error......\r\n"); + return OSP_ERROR; + } + + return OSP_OK; +#endif +} + +int32_t osp_read_spe_cfg_to_bin(char* in_path) +{ + FILE *file = NULL; /* 閬嶅巻涓存椂鏂囦欢锛岃幏鍙栨墍鏈夋枃浠跺悕 */ + FILE *read_file = NULL; /* 鍘熷鏂囦欢 */ + FILE *write_file = NULL; /* 鐩殑鏂囦欢 */ + uint8_t len = 0; + uint8_t osp_cfg_file_idx = 0; /* 鏂囦欢涓暟 */ + uint32_t value = 0; + char *p_line_file_name = NULL; + char line_file_name_full[APE_CFG_FILE_NAME_LEN*2] = {0}; + char write_file_name[APE_CFG_FILE_NAME_LEN] = {0}; + char line_buf[100] = {0}; + char cmd_string[APE_CFG_FILE_NAME_LEN*2] = {0}; + + if (NULL == in_path) + { + UCP_PRINT_ERROR("osp_read_spe_cfg_to_bin() in_path error......\r\n"); + return OSP_PAR_ILL; + } + + system("rm -rf /ramfs/config_bak/*.*"); + + /* 閬嶅巻鍘熷鐩綍锛岃幏鍙栨墍鏈夋枃浠剁殑鏂囦欢鍚嶅強璺緞杈撳嚭鍒:tmpfile */ + sprintf(cmd_string, "find /%s/* -name '*.dat' > tmpfile", in_path); + system(cmd_string); + + /* 閬嶅巻鍘熷鐩綍锛岃幏鍙栨墍鏈夋枃浠剁殑鏂囦欢鍚嶈緭鍑哄埌:tmpfilename */ + //system("find /ramfs/cfgDat/* -name '*.dat' | sed 's#.*/##' > tmpfilename"); + + /* 鎵撳紑tmpfile鍐呮墍鏈夐渶瑕佸鐞嗙殑鏂囦欢 */ + file = fopen("./tmpfile", "rb"); + if (NULL == file) + { + UCP_PRINT_ERROR("Open file(tmpfile) error.\r\n"); + return OSP_FILE_ERROR; + } + /* 閫愪竴杞寲锛堟枃鏈枃浠 --> 浜岃繘鍒舵枃浠 */ + while(osp_cfg_file_idx < APE_CFG_FILE_NUM) + { + /* 姣忚鏄師濮嬫枃浠剁殑鍏ㄨ矾寰 */ + if (NULL == fgets(line_file_name_full, sizeof(line_file_name_full), file)) + { + /* 閬嶅巻鑷虫渶鍚庣粨鏉 */ + break; + } + p_line_file_name = strrchr(line_file_name_full, '/'); + p_line_file_name++; + + len = strlen(line_file_name_full); + line_file_name_full[len - 1] = '\0'; + + read_file = fopen(line_file_name_full, "rb"); + if (NULL == read_file) + { + UCP_PRINT_ERROR("Can not open src file: %s \r\n", line_file_name_full); + fclose(file); + return OSP_FILE_ERROR; + } + + sprintf(write_file_name, "/ramfs/config_bak/%s", p_line_file_name); + //UCP_PRINT_DEBUG("dst file: %s \r\n", write_file_name); + + write_file = fopen(write_file_name, "wb+"); + if (NULL == write_file) + { + UCP_PRINT_ERROR("Can not open dst file: %s \r\n", write_file_name); + fclose(file); + fclose(read_file); + return OSP_FILE_ERROR; + } + + /* 寮濮嬭浆鍖 */ + while(fgets(line_buf, 100, read_file)) + { + sscanf(line_buf, "0x%x", &value); + fwrite(&value, sizeof(value), 1, write_file); + } + + osp_cfg_file_idx++; + + fflush(read_file); + fclose(read_file); + fflush(write_file); + fclose(write_file); + } + + fclose(file); + system("rm tmpfile"); + + return OSP_OK; +} + +int32_t osp_spe_bin_cfg_file_to_ddr() +{ + char *p_line_file_name = NULL; + char *p_line_file_name_begin = NULL; + char line_file_full_name[2*APE_CFG_FILE_NAME_LEN]={0}; + char file_name[APE_CFG_FILE_NAME_LEN] = {0}; + + uint32_t len = 0; + uint32_t tmp_len = 0; + uint8_t osp_cfg_file_idx = 0; /* 鏂囦欢涓暟 */ + uint32_t ret = 0; /* 杩斿洖鍊煎垽鏂 */ + uint32_t file_len = 0; /* 鏂囦欢闀垮害 */ + uint32_t ddr_offset = 0; + + FILE *file = NULL; + FILE *read_file = NULL; + + /* 鍏ㄨ矾寰勬枃浠跺悕鍐欏叆锛 tmpfile鏂囦欢 */ + system("find /ramfs/config_bak/* -name '*' > tmpfile"); + + /* 閬嶅巻 */ + file = fopen("./tmpfile", "rb"); + if (NULL == file) + { + UCP_PRINT_ERROR("[to_ddr]: Open file(tmpfile) error.\r\n"); + return OSP_FILE_ERROR; + } + + while(osp_cfg_file_idx < APE_CFG_FILE_NUM) + { + /* 姣忚鏄師濮嬫枃浠剁殑鍏ㄨ矾寰 */ + if (NULL == fgets(line_file_full_name, sizeof(line_file_full_name), file)) + { + /* 閬嶅巻鑷虫渶鍚庣粨鏉 */ + break; + } + p_line_file_name = strrchr(line_file_full_name, '/'); + p_line_file_name++; + + len = strlen(line_file_full_name); + line_file_full_name[len - 1] = '\0'; + + p_line_file_name_begin = line_file_full_name; + memcpy(file_name, p_line_file_name, len-(p_line_file_name - p_line_file_name_begin)); + //UCP_PRINT_DEBUG("[to_ddr]: file name : %s \r\n", file_name); + + read_file = fopen(line_file_full_name, "rb"); + if (NULL == read_file) + { + UCP_PRINT_ERROR("[to_ddr]: Can not open src file: %s \r\n", line_file_full_name); + fclose(file); + return OSP_FILE_ERROR; + } + + /* 鎵惧埌鏂囦欢缁撴潫绗 */ + ret = fseek(read_file, 0, SEEK_END); + if (ret) + { + UCP_PRINT_ERROR("[to_ddr]: Can not fseek: %s \r\n", line_file_full_name); + fclose(file); + fclose(read_file); + return OSP_FILE_ERROR; + } + + /* 璁$畻鏂囦欢闀垮害 */ + file_len = (uint32_t)ftell(read_file); + UCP_PRINT_DEBUG("[to_ddr]: file: %s ,Size: %d\r\n", line_file_full_name, file_len); + + /* 鍥炲埌鏂囦欢澶撮儴 */ + ret = fseek(read_file, 0, SEEK_SET); + + /* 鏇存柊鍏ㄥ眬鍙橀噺 */ + len = 0; + while(len < file_len) + { + tmp_len = fread((char*)(g_spe_ptr_static_mem+ARM_CFG_INDXN+ARM_SPE_CFG_INFO_SIZE+ddr_offset+len), 1, file_len, read_file); + len += tmp_len; + } + + /* 鏇存柊鍏ㄥ眬鍙橀噺 */ + g_spe_osp_cfg_file_reg[g_spe_osp_cfg_file_idx].len = file_len; + memcpy(g_spe_osp_cfg_file_reg[g_spe_osp_cfg_file_idx].name, file_name, strlen(file_name)); + g_spe_osp_cfg_file_reg[g_spe_osp_cfg_file_idx].vir_addr = (uint64_t)(g_spe_ptr_static_mem + + ARM_CFG_INDXN + + ARM_SPE_CFG_INFO_SIZE + + ddr_offset); + g_spe_osp_cfg_file_idx++; + ddr_offset += file_len; + + osp_cfg_file_idx++; + fclose(read_file); + } + + /* 鏇存柊閰嶇疆鏂囦欢澶翠俊鎭 */ + *(uint32_t *)(g_spe_ptr_static_mem+ARM_CFG_NUM) = g_spe_osp_cfg_file_idx; + memcpy((g_spe_ptr_static_mem + ARM_CFG_INDXN), g_spe_osp_cfg_file_reg, ARM_SPE_CFG_INFO_ONE * g_spe_osp_cfg_file_idx); + *(uint32_t *)g_spe_ptr_static_mem = ARM_READ_CFG_FILE_OK; + + fclose(file); + system("rm tmpfile"); + + return OSP_OK; + +} + + +/********************************************************************/ +/* TestMac Interface */ +/********************************************************************/ +int32_t osp_read_spe_cfg_file(char* path) +{ + uint32_t ret = 0; + + /* 姣忔璋冪敤鍓嶏紝娓呯┖鍏ㄥ眬鍙橀噺 */ + ret = osp_spe_cfg_file_init(); + if (OSP_OK != ret) + { + UCP_PRINT_ERROR("[osp_read_spe_cfg_file]: osp_cfg_file_init return error: %d\r\n", ret); + return ret; + } + + /* 璇绘枃鏈厤缃枃浠 */ + ret = osp_read_spe_cfg_to_bin(path); + if (OSP_OK != ret) + { + UCP_PRINT_ERROR("[osp_read_spe_cfg_file]: osp_read_spe_cfg_to_bin return error: %d\r\n", ret); + return ret; + } + + /* 杞寲 */ + ret = osp_spe_bin_cfg_file_to_ddr(); + if (OSP_OK != ret) + { + UCP_PRINT_ERROR("[osp_read_spe_cfg_file]: osp_spe_bin_cfg_file_to_ddr return error: %d\r\n", ret); + return ret; + } + return OSP_OK; +} + +int32_t osp_get_cfg_file(char* name, uint64_t *paddr, uint32_t *psize) +{ + uint16_t loop = 0; + osp_spe_cfg_file_reg *head = NULL; + if (strlen(name) > APE_CFG_FILE_NAME_LEN) + { + UCP_PRINT_ERROR("[osp_get_cfg_file]: name too long\r\n"); + return OSP_ERROR; + } + for (loop = 0; loop < APE_CFG_FILE_NUM; loop++) + { + head = g_spe_osp_cfg_file_reg + loop; + if (0 == memcmp(head->name, name, strlen(name))) + { + *paddr = head->vir_addr; + *psize = head->len; + return OSP_OK; + } + } + UCP_PRINT_DEBUG("[osp_get_cfg_file]: no this file(%s)\r\n", name); + return OSP_ERROR; +} + +#ifdef HEARTBEAT_ENABLE +#define OSP_IM2DDR_FLAG_OK (0x5a5a5a5a) +#define OSP_IM2DDR_SIZE (0x40000) /* 256k */ +#define DUMP_IM_CORE_FILE_NAME "./dump_im_core%02d_%04d%02d%02d_%02d%02d%02d" /* dump dm file */ +#define DUMP_IM_CORE_FILE_LEN (36) + +int8_t osp_get_im2ddr_to_file(uint8_t u8CoreId) +{ + int32_t ret = OSP_OK; + uint32_t u32_im2ddr_flag = 0; + char file_name[DUMP_IM_CORE_FILE_LEN]= {0}; + char *pbuf = g_ptr_static_mem; + FILE *fp = NULL; + struct tm *t; + time_t tt; + + time(&tt); + t = localtime(&tt); + + UCP_PRINT_DEBUG("[osp_get_im2ddr_to_file]: Start ... \r\n"); + + while(1) + { + u32_im2ddr_flag = *(uint32_t*)(g_ptr_static_mem); + if (OSP_IM2DDR_FLAG_OK == u32_im2ddr_flag) + { + UCP_PRINT_DEBUG("[osp_get_im2ddr_to_file]: ape write im2ddr ok\r\n"); + break; + } + } + + sprintf(file_name, DUMP_IM_CORE_FILE_NAME, u8CoreId, t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + UCP_PRINT_DEBUG("[osp_get_im2ddr_to_file]: file_name = %s\r\n", file_name); + + fp = fopen(file_name, "wb+"); + if (fp < 0) + { + UCP_PRINT_ERROR("[osp_get_im2ddr_to_file]: file open failure \n"); + return OSP_ERROR; + } + + ret = fwrite((pbuf+4), sizeof(char), OSP_IM2DDR_SIZE, fp); + if(ret < 0) + { + UCP_PRINT_ERROR("[osp_get_im2ddr_to_file]: fwrite error ret:%d\n", ret); + fclose(fp); + return OSP_ERROR; + } + + fflush(fp); + fclose(fp); + + UCP_PRINT_DEBUG("[osp_get_im2ddr_to_file]: End ... \r\n"); + return OSP_OK; +} +#endif + + diff --git a/osp/src/ospDbg.c b/osp/src/ospDbg.c new file mode 100644 index 0000000..51c08ca --- /dev/null +++ b/osp/src/ospDbg.c @@ -0,0 +1,627 @@ +#include +#include +#include +#include + + + +#include +#include + +#define _GNU_SOURCE +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include "osp.h" + + + +#define IOSIZE (32*1024*1024) +void *g_SemDeadFunc; + +int32_t osp_signal_init(void); + +uint32_t *gOspPrintLevel = NULL; + + +/*keep DbgOut with order !*/ +void *g_DbgOutSem = 0; + +char DbgBuf[MAX_DBGINFO_LEN] = {0}; +static OSP_FUNCPTR gpfunc[DeadFuncNum] = {0}; + + + +int32_t osp_task_dbg_out_enable(uint32_t taskid) +{ + gOspTask[taskid].dbg_out_is_enable = 1; + + return 0; + +} + +int32_t osp_task_dbg_out_disable(uint32_t taskid) +{ + gOspTask[taskid].dbg_out_is_enable = 0; + return 0; +} + +int32_t osp_task_dbg_out_enable_all(void) +{ + int32_t i; + + for (i = 0; i < OSP_MAX_TASK; i++) + { + if (gOspTask[i].Active) + { + osp_task_dbg_out_enable(i); + } + } + return OSP_OK; +} + +int32_t osp_task_dbg_out_disable_all(void) +{ + int32_t i; + + for (i = 0; i < OSP_MAX_TASK; i++) + { + if (gOspTask[i].Active) + { + osp_task_dbg_out_disable(i); + } + } + return OSP_OK; +} + + + +int32_t osp_task_dbg_is_log(uint32_t taskid) +{ + return gOspTask[taskid].dbg_out2log_is_enable; +} +int32_t osp_task_dbg_out2log_disable_all(void) +{ + int32_t i; + + for (i = 0; i < OSP_MAX_TASK; i++) + { + if (gOspTask[i].Active) + { + osp_task_dbg_out2log_disable(i); + } + } + return OSP_OK; + +} +int32_t osp_task_dbg_out2log_disable(uint32_t taskid) +{ + gOspTask[taskid].dbg_out2log_is_enable = 0; + + return 0; + +} +int32_t osp_task_dbg_out2log_enable_all(void) +{ + int32_t i; + for (i = 0; i < OSP_MAX_TASK; i++) + { + if (!osp_task_is_shell(i)) + osp_task_dbg_out2log_enable(i); + } + return OSP_OK; + +} + +int32_t osp_task_dbg_out2log_enable(uint32_t taskid) +{ + gOspTask[taskid].dbg_out2log_is_enable = 1; + + return 0; +} + +int32_t osp_task_dbg_out_is_enable(uint32_t taskid) +{ + return gOspTask[taskid].dbg_out_is_enable; +} + + +void osp_local_shell_out_main(Osp_Msg_Head *pMsg) +{ + + + if (osp_local_shell_task_is_reged()) + { + osp_print(MSG_HEAD_TO_COMM(pMsg), MSG_DADA_LEN(pMsg)); + } + + osp_net_shell_out(pMsg); + + osp_free_msg(pMsg); +} + + +void osp_debug_out_set_level(int32_t level) +{ + *gOspPrintLevel = level; +} + + +OSP_STATUS osp_debug_out(int32_t level, char *fmt,...) +{ + va_list vl; + Osp_Msg_Head *pMsg; + int32_t buflen = 0; + + if (!osp_is_init_done()) + { + /*to makesure osp_debug_out can be useful anytime*/ + char *pbuf = malloc(MAX_DBGINFO_LEN); + if (NULL != pbuf) + { + + va_start(vl, fmt); + buflen = vsnprintf(pbuf + buflen, MAX_DBGINFO_LEN - buflen, fmt, vl); + va_end(vl); + printf("%s\n", pbuf); + free(pbuf); + } + return OSP_OK; + + } + + + if ((NULL == gOspPrintLevel) && (*gOspPrintLevel < level)) + return (OSP_ERROR); + if (!osp_task_dbg_out_is_enable(CURRENT_TASKID)) + return (OSP_ERROR); + + if (NULL == g_DbgOutSem) + { + return OSP_ERROR; + } + + osp_sem_take(g_DbgOutSem, -1); + if ((osp_task_dbg_is_log(CURRENT_TASKID)) && (CMD_DEBUG_LEVEL != level)) + { + char *pbuf = DbgBuf; + va_start(vl, fmt); + buflen = vsnprintf(pbuf, MAX_DBGINFO_LEN, fmt, vl); + va_end(vl); + pbuf[buflen] = '\0'; + osp_dbg_log(pbuf, buflen); + osp_sem_give(g_DbgOutSem); + return OSP_OK; + } + + pMsg = osp_alloc_msg_print_log(); + if (NULL == pMsg) + { + /*to makesure osp_debug_out can be useful anytime*/ + char *pbuf = DbgBuf; + + va_start(vl, fmt); + buflen = vsnprintf(pbuf, MAX_DBGINFO_LEN, fmt, vl); + va_end(vl); + printf("%s", pbuf); + + osp_sem_give(g_DbgOutSem); + return OSP_ERROR; + } + + va_start(vl, fmt); + buflen = vsnprintf(MSG_HEAD_TO_COMM(pMsg), MAX_DBGINFO_LEN, fmt, vl); + va_end(vl); + + + + + pMsg->DstId = localshellout; + pMsg->SrcId = CURRENT_TASKID; + + pMsg->MsgSize = buflen + MSG_HEAD_SIZE; + osp_send_msg(pMsg); + osp_sem_give(g_DbgOutSem); + + return (OSP_OK); +} +OSP_STATUS osp_debug_out_with_time(int32_t level, char *fmt,...) +{ + va_list vl; + Osp_Msg_Head *pMsg; + int32_t buflen = 0; + OSP_RTCTIME osptime; + + + + if (!osp_is_init_done()) + { + /*to makesure osp_debug_out can be useful anytime*/ + char *pbuf = malloc(MAX_DBGINFO_LEN); + if (NULL != pbuf) + { + osp_get_rtc_time(&osptime); + + buflen = snprintf((char *)pbuf, (size_t)(MAX_DBGINFO_LEN), \ + "[%04d/%02d/%02d-%02d:%02d:%02d:%02d]", \ + osptime.year, osptime.month, osptime.day, \ + osptime.hour, osptime.minute, osptime.second, osptime.usecond); + + va_start(vl, fmt); + buflen = vsnprintf(pbuf+buflen, MAX_DBGINFO_LEN-buflen, fmt, vl); + va_end(vl); + printf("%s", pbuf); + free(pbuf); + } + return OSP_OK; + + } + + + + if ((gOspPrintLevel) && (*gOspPrintLevel < level)) + { + return (OSP_ERROR); + } + if (!osp_task_dbg_out_is_enable(CURRENT_TASKID)) + { + return (OSP_ERROR); + } + if (NULL == g_DbgOutSem) + { + return OSP_ERROR; + } + + osp_sem_take(g_DbgOutSem, -1); + if (osp_task_dbg_is_log(CURRENT_TASKID)) + { + char *pbuf = DbgBuf; + + /*to makesure osp_debug_out_with_time can be useful anytime*/ + + + osp_get_rtc_time(&osptime); + + buflen = snprintf((char *)pbuf, (size_t)(MAX_DBGINFO_LEN), \ + "[%04d/%02d/%02d-%02d:%02d:%02d:%02d]", \ + osptime.year, osptime.month, osptime.day, \ + osptime.hour, osptime.minute, osptime.second, osptime.usecond); + va_start(vl, fmt); + buflen += vsnprintf(pbuf+buflen, MAX_DBGINFO_LEN, fmt, vl); + va_end(vl); + pbuf[buflen] = '\0'; + osp_dbg_log(pbuf, buflen); + + + osp_sem_give(g_DbgOutSem); + return OSP_OK; + + } + + pMsg = osp_alloc_msg_print_log(); + if (NULL == pMsg) + { + + /*to makesure osp_debug_out_with_time can be useful anytime*/ + char *pbuf = DbgBuf; + + osp_get_rtc_time(&osptime); + + buflen = snprintf((char *)pbuf, (size_t)(MAX_DBGINFO_LEN), \ + "[%04d/%02d/%02d-%02d:%02d:%02d:%02d]", \ + osptime.year, osptime.month, osptime.day, \ + osptime.hour, osptime.minute, osptime.second, osptime.usecond); + + va_start(vl, fmt); + buflen = vsnprintf(pbuf + buflen, MAX_DBGINFO_LEN, fmt, vl); + va_end(vl); + printf("%s",pbuf); + + + osp_sem_give(g_DbgOutSem); + return OSP_OK; + } + + + osp_get_rtc_time(&osptime); + buflen = snprintf((char *)MSG_HEAD_TO_COMM(pMsg), (size_t)(MAX_DBGINFO_LEN), \ + "[%04d/%02d/%02d-%02d:%02d:%02d:%02d]", \ + osptime.year, osptime.month, osptime.day, \ + osptime.hour, osptime.minute, osptime.second, osptime.usecond); + + + va_start(vl, fmt); + buflen += vsnprintf(MSG_HEAD_TO_COMM(pMsg) + buflen, MAX_DBGINFO_LEN - buflen, fmt, vl); + va_end(vl); + + + pMsg->DstId = localshellout; + pMsg->SrcId = CURRENT_TASKID; + + pMsg->MsgSize = buflen + MSG_HEAD_SIZE; + osp_send_msg(pMsg); + + osp_sem_give(g_DbgOutSem); + return (OSP_OK); +} + +OSP_STATUS osp_print(char *pbuf, uint32_t len) +{ + if ((NULL == pbuf) || (0 == len)) + { + return OSP_ERROR; + } + printf("%s", pbuf); + fflush(stdout); + + return OSP_OK; +} + +int32_t osp_shell_dis_mem(int32_t num, uint64_t addr) +{ + uint32_t *p = (uint32_t *)addr; + int32_t i; + char *pbuf; + int32_t len = 0; + + if (NULL == p) + { + return -1; + } + if ((num * 4) > MAX_DBGINFO_LEN) + { + osp_debug_out(CMD_DEBUG_LEVEL, "mux display memsize : %d\r\n", (MAX_DBGINFO_LEN / 4)); + return -1; + } + + pbuf = malloc(MAX_DBGINFO_LEN); + if (NULL == pbuf) + { + return -1; + } + + for (i = 0; i < num; i++) + { + if ((i & 0x3) == 0) + len += sprintf(pbuf + len, "%p : \t", p+i); + len += sprintf(pbuf + len, "0x%08x\t", p[i]); + + if ((i & 0x3) == 0x3) + len += sprintf(pbuf + len, "%c", '\n'); + } + pbuf[len] = '\0'; + osp_debug_out(CMD_DEBUG_LEVEL, "%s", pbuf); + free(pbuf); + + return OSP_OK; +} + + +int32_t osp_shell_set_mem(int32_t val, uint64_t addr) +{ + uint32_t *p = (uint32_t *)addr; + if (NULL == p) + return -1; + *p = val; + + return OSP_OK; +} + + + + +int32_t osp_local_shell_in_main() +{ + return OSP_OK; +} + + + + + +void osp_debug_init(void) +{ + + g_DbgOutSem = osp_get_init_mem(sizeof(lx_sem_t)); + gOspPrintLevel = (uint32_t *)osp_get_init_mem(sizeof(uint32_t)); + + + if (0 == g_ProcessId) + { + *gOspPrintLevel = DBG_DEBUG_LEVEL; + osp_semsm_create(g_DbgOutSem); + } + osp_signal_init(); + +} + +void osp_signal_action_trace(int32_t nr, siginfo_t *info, void *void_context) +{ + void *trace[100] = {0}; + int32_t trace_size = 0; + char **messages = NULL; + int32_t i; + + trace_size = backtrace(trace, 100); + messages = (char **)backtrace_symbols(trace, trace_size); + + for (i = 0; i < trace_size; ++i) + { + osp_debug_out(CMD_DEBUG_LEVEL, "[bt] %s\n", messages[i]); + } + return; +} +void osp_signal_action_suspend(int32_t nr, siginfo_t *info, void *void_context) +{ + sigset_t SigSet; + int32_t Sig; + + (void)sigemptyset(&SigSet); + (void)sigaddset(&SigSet,OSP_TASK_SIGNAL_RESUME); +// osp_debug_out(CMD_DEBUG_LEVEL, "task:%d suspend\n", CURRENT_TASKID); + TASK_STATE(CURRENT_TASKID)= TASK_SUSPEND; + (void)sigwait(&SigSet, &Sig); + TASK_STATE(CURRENT_TASKID)= TASK_RUNNING; +// osp_debug_out(CMD_DEBUG_LEVEL, "task:%d resume\n", CURRENT_TASKID); + +} +void osp_signal_action_resume(int32_t nr, siginfo_t *info, void *void_context) +{ +} +void osp_signal_action_except(int32_t nr, siginfo_t *info, void *void_context) +{ + osp_assert(0); +} + + +int32_t osp_signal_init(void) +{ + + struct sigaction act; + + act.sa_sigaction = &osp_signal_action_trace; + act.sa_flags = SA_SIGINFO; + + if (sigaction(OSP_TASK_SIGNAL_TRACE, &act, NULL) < 0) { + osp_assert(0); + } + + act.sa_sigaction = &osp_signal_action_suspend; + act.sa_flags = SA_SIGINFO; + + if (sigaction(OSP_TASK_SIGNAL_SUSPEND, &act, NULL) < 0) { + osp_assert(0); + } + act.sa_sigaction = &osp_signal_action_resume; + act.sa_flags = SA_SIGINFO; + + if (sigaction(OSP_TASK_SIGNAL_RESUME, &act, NULL) < 0) { + osp_assert(0); + } + + act.sa_sigaction = &osp_signal_action_except ; + act.sa_flags = SA_SIGINFO; + + if (sigaction(OSP_TASK_SIGNAL_SEGV, &act, NULL) < 0) { + osp_assert(0); + } + + act.sa_sigaction = &osp_signal_action_except ; + act.sa_flags = SA_SIGINFO; + + if (sigaction(OSP_TASK_SIGNAL_BUSSERR, &act, NULL) < 0) { + osp_assert(0); + } + + signal(SIGTTOU, SIG_IGN); + g_SemDeadFunc = osp_semm_create(); + + return OSP_OK; + +} +int32_t osp_trace_task(uint32_t Id) +{ + if (gOspTask[Id].PhreadId) + { + (void)pthread_kill(TASK_THREADID(Id),OSP_TASK_SIGNAL_TRACE); + } + return OSP_OK; +} +int32_t osp_suspend_task(uint32_t Id) +{ + if (gOspTask[Id].PhreadId) + { + (void)pthread_kill(TASK_THREADID(Id),OSP_TASK_SIGNAL_SUSPEND); + } + return OSP_ERROR; +} + +int32_t osp_resume_task(uint32_t Id) +{ + if (gOspTask[Id].PhreadId) + { + (void)pthread_kill(TASK_THREADID(Id),OSP_TASK_SIGNAL_RESUME); + } + return OSP_ERROR; +} + +void osp_set_dbg_cmdlev(void) +{ + osp_debug_out_set_level(CMD_DEBUG_LEVEL); +} + +void osp_set_dbg_errlev(void) +{ + osp_debug_out_set_level(ERR_DEBUG_LEVEL); +} + +void osp_set_dbg_crunlev(void) +{ + osp_debug_out_set_level(RUN_DEBUG_LEVEL); +} + +void osp_set_dbg_cwarlev(void) +{ + osp_debug_out_set_level(WARNING_DEBUG_LEVEL); +} + +int32_t osp_reg_dead_func(OSP_FUNCPTR pfunc) +{ + + osp_sem_take(g_SemDeadFunc, -1); + { + static int32_t num = 0; + + if ((NULL == pfunc)||(num == (DeadFuncNum-1))) + { + osp_sem_give(g_SemDeadFunc); + return OSP_ERROR; + } + + gpfunc[num++] = pfunc; + osp_sem_give(g_SemDeadFunc); + return 0 ; + } + +} +void osp_run_dead_func(void) +{ + int32_t i=0; + for (i = 0; i < DeadFuncNum; i++) + { + if (gpfunc[i]) + gpfunc[i](); + else + break; + } + osp_debug_out_with_time(CMD_DEBUG_LEVEL,"%d DeadFunc called!\r\n", i); +} +void osp_assert(int32_t val) +{ + + if (val == 0) + { + osp_run_dead_func(); + /*to make sure deadmsg has been recorded! anyway this shuld to change in reliable way,todoa*/ + usleep(100); + + + osp_trace_task(CURRENT_TASKID); + osp_fflush_all_logfile(); + osp_suspend_task(CURRENT_TASKID); + while (1); + } + +} + + diff --git a/osp/src/ospDelay.c b/osp/src/ospDelay.c new file mode 100644 index 0000000..d62c4c9 --- /dev/null +++ b/osp/src/ospDelay.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include "osp.h" +//////// +/* + *osp_delay - delay function + *input: + * delay (ms) + *return + * OSP_OK + */ +#if 0 +OSP_STATUS osp_delay(U32 delay) +{ + + struct timespec reqt; + struct timespec remt; + + reqt.tv_sec=delay/1000; + reqt.tv_nsec =(delay%1000) *1000000;/*1ms*/ + nanosleep(&reqt,&remt); + + return (OSP_OK); +} +#endif + +OSP_STATUS osp_delay(uint32_t delay) +{ + + struct timespec reqt; + struct timespec remt; + + reqt.tv_sec = delay / 1000000; + reqt.tv_nsec = (delay % 1000000) * 1000; /*1us*/ + nanosleep(&reqt, &remt); + + return (OSP_OK); +} + +void osp_delay_while(uint64_t ns) +{ + uint64_t org; + uint64_t ticks; + + org = osp_get_cycel(); + /* 50MHz for Cycel */ + ticks = (ns / 20); + + while (osp_get_cycel() <= (org + ticks)); + +} + + + diff --git a/osp/src/ospDiag.c b/osp/src/ospDiag.c new file mode 100644 index 0000000..ef6e0ee --- /dev/null +++ b/osp/src/ospDiag.c @@ -0,0 +1,163 @@ + +#include +#include +#include +#include +#include +#include "osp.h" + + + +uint64_t *g_DiagCntBase = 0; +#define OSP_DIAGCNT_LEN (10*1024) + +static OSP_TASKCB *TaskCBBase; + + +/************************************************************************** + + +**************************************************************************/ + +int32_t osp_diag_cnt_init(void) +{ + g_DiagCntBase = (uint64_t *)osp_get_init_mem(OSP_MAX_TASK * sizeof(uint64_t) * CNT_NUM_PER_TASK); + memset(g_DiagCntBase, 0, OSP_MAX_TASK * sizeof(uint64_t) * CNT_NUM_PER_TASK); + TaskCBBase = osp_get_taskcb_base(); + return OSP_OK; +} + +OSP_STATUS osp_diag_cnt_add(uint32_t TaskId, uint32_t CntId) +{ + TASK_CNT_ADD(TaskId, CntId); + return OSP_OK; +} + +OSP_STATUS osp_diag_cnt_set(uint32_t TaskId, uint32_t CntId, uint64_t Val) +{ + TASK_CNT_SET(TaskId, CntId,Val); + return OSP_OK; + +} +uint64_t osp_diag_cnt_get(uint32_t TaskId, uint32_t CntId) +{ + return TASK_CNT_GET(TaskId, CntId); +} + +OSP_STATUS osp_show_tsk_diag_cnt(uint32_t TaskId) +{ + char *pstr = NULL; + uint32_t len = OSP_DIAGCNT_LEN; + uint32_t tmplen = 0; +// OSP_STATUS ret; + + if (!TaskCBBase[TaskId].Active) + { + osp_debug_out(CMD_DEBUG_LEVEL, "Task:%d is not active\n", TaskId); + return OSP_ERROR; + } + + pstr = malloc(len); + osp_assert(NULL != pstr); + + tmplen = (uint32_t)sprintf(pstr, "%-16s%-16s%-16s\r\n", "OspTaskId", "OspCntIdx", "OspCntValue"); + tmplen += osp_diag_cnt_str(TaskId, pstr + tmplen, len - tmplen); + + + pstr[tmplen] = '\0'; + osp_debug_out(CMD_DEBUG_LEVEL, "%s", pstr); + free(pstr); + + return OSP_OK; +} +OSP_STATUS osp_show_all_diag_cnt(void) +{ + char *pstr = NULL; + uint32_t len = OSP_DIAGCNT_LEN; + uint32_t tmplen = 0; +// U32 outlen = 0; +// OSP_STATUS ret; + uint32_t TaskId; + + + + pstr = malloc(len); + osp_assert(NULL != pstr); + + tmplen = (uint32_t)sprintf(pstr, "%-16s%-16s%-16s\r\n", "OspTaskId", "OspCntIdx", "OspCntValue"); + for (TaskId = 0; TaskId < OSP_MAX_TASK; TaskId++) + { + if (!TaskCBBase[TaskId].Active) + { + continue; + } + tmplen += osp_diag_cnt_str(TaskId, pstr + tmplen, len - tmplen); + } + + + pstr[tmplen] = '\0'; + osp_debug_out(CMD_DEBUG_LEVEL, "%s", pstr); + free(pstr); + return OSP_OK; +} + + +uint32_t osp_diag_cnt_str(uint32_t TaskId, char *pstr, uint32_t inlen) +{ + uint32_t CntId = 0; + uint32_t len = 0; + uint64_t CntVal; + + if ((!TaskCBBase[TaskId].Active) || (NULL == pstr) || (0 == inlen)) + { + osp_assert(0); + } + + for (CntId = 0; CntId < CNT_NUM_PER_TASK; CntId++) + { + CntVal = TASK_CNT_GET(TaskId,CntId); + if (0 == CntVal) + { + continue; + } + if (inlen-len < 64) + { + osp_assert(0); + } + len += sprintf(pstr + len,"%-16d%-16d%-16lu\r\n", TaskId, CntId, CntVal); + + } + return len; +} + + +/************************************************************************** + + +**************************************************************************/ + +int32_t osp_diag_init(void) +{ + int32_t ret ; + ret = osp_diag_cnt_init(); + if (OSP_OK != ret) + { + return ret; + } + + return OSP_OK; +} +/************************************************************************** + +**************************************************************************/ + +int32_t osp_show_que_status(void) +{ + return OSP_OK; +} + + + + + + diff --git a/osp/src/ospDump.c b/osp/src/ospDump.c new file mode 100644 index 0000000..c36c64a --- /dev/null +++ b/osp/src/ospDump.c @@ -0,0 +1,713 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "osp.h" +#include "ospSoftQue.h" +#include "ospLog.h" +#include "ucp_printf.h" +#include "ospDump.h" +#include "ucp_handshake.h" + +#define SPU_DM_SIZE (0x200000) /* 2M */ +#define APE_CORE_ID_0 (0) +#define APE_CORE_ID_1 (1) +#define APE_CORE_ID_2 (2) +#define APE_CORE_ID_3 (3) +#define APE_CORE_ID_4 (4) +#define APE_CORE_ID_5 (5) +#define APE_CORE_ID_6 (6) +#define APE_CORE_ID_7 (7) +#define APC_CORE_ID_0 (0) +#define APC_CORE_ID_1 (1) +#define APC_CORE_ID_2 (2) +#define APC_CORE_ID_3 (3) + + +#define DUMP_DM_CORE_FILE_NAME "./dump_dm_core%02d_%04d%02d%02d_%02d%02d%02d" /* dump dm file */ +#define DUMP_DM_CORE_FILE_LEN (36) + + +void *gp_static_sm_mem = NULL; +void *gp_static_dm_mem = NULL; +void *gp_static_ecs_sm_mem = NULL; +void *gp_static_pet_sm_mem = NULL; +void *gp_static_ape_phy_mem = NULL; +void *gp_static_ape_text = NULL; +void *gp_static_arm_ape_msg = NULL; +void *gp_static_ape_log = NULL; +void *gp_static_arm_stack = NULL; + +uint64_t gp_static_sm_mem_size = 0; +uint64_t gp_static_dm_mem_size = 0; +uint64_t gp_static_ecs_sm_mem_size = 0; +uint64_t gp_static_pet_sm_mem_size = 0; +uint64_t gp_static_ape_phy_mem_size = 0; +uint64_t gp_static_ape_text_mem_size = 0; +uint64_t gp_static_arm_ape_msg_size = 0; +uint64_t gp_static_ape_log_size = 0; +uint64_t gp_static_arm_stack_size = 0; + +char *gp_dump_buf; + +extern uint8_t g_ucIsEcho; + +void osp_dump_init(void) +{ + + gp_static_sm_mem = get_static_mem(SHARE_MEM, &gp_static_sm_mem_size); + if (0 == gp_static_sm_mem_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(SHARE_MEM) error......\r\n"); + return ; + } + + gp_static_dm_mem = get_static_mem(APE_DM, &gp_static_dm_mem_size); + if (0 == gp_static_dm_mem_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(APE_DM) error......\r\n"); + return ; + } + + gp_static_ecs_sm_mem = get_static_mem(ECS_SM, &gp_static_ecs_sm_mem_size); + if (0 == gp_static_ecs_sm_mem_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(ECS_SM) error......\r\n"); + return ; + } + + gp_static_pet_sm_mem = get_static_mem(PET_SM, &gp_static_pet_sm_mem_size); + if (0 == gp_static_pet_sm_mem_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(PET_SM) error......\r\n"); + return ; + } + + gp_static_ape_phy_mem = get_static_mem(APE_PHY, &gp_static_ape_phy_mem_size); + if (0 == gp_static_ape_phy_mem_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(APE_PHY) error......\r\n"); + return ; + } + + gp_static_ape_text = get_static_mem(APE_TEXT, &gp_static_ape_text_mem_size); + if (0 == gp_static_ape_text_mem_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(APE_TEXT) error......\r\n"); + return ; + } + + gp_static_arm_ape_msg = get_static_mem(ARM_APE_MSG, &gp_static_arm_ape_msg_size); + if (0 == gp_static_arm_ape_msg_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(ARM_APE_MSG) error......\r\n"); + return ; + } + + gp_static_ape_log = get_static_mem(APE_LOG, &gp_static_ape_log_size); + if (0 == gp_static_ape_log_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(APE_LOG) error......\r\n"); + return ; + } + + gp_static_arm_stack = get_static_mem(ARM_STACK, &gp_static_arm_stack_size); + if (0 == gp_static_arm_stack_size) + { + UCP_PRINT_ERROR("osp_dump_init get_static_mem(ARM_STACK) error......\r\n"); + return ; + } + + return; +} +#if 0 +void osp_dump_sm(char *pName, uint32_t ulLen) +{ + OSP_STATUS ret = OSP_OK; + + if(ulLen > gp_static_sm_mem_size) + { + UCP_PRINT_ERROR("osp_dump_sm ulLen:%u > gp_static_sm_mem_size:%ld", ulLen, gp_static_sm_mem_size); + return ; + } + + if(NULL == pName) + { + UCP_PRINT_ERROR("osp_dump_sm pName is null\r\n"); + return ; + } + + ret = osp_dump_proc(pName, SHARE_MEM , ulLen); + if(OSP_OK != ret) + { + UCP_PRINT_ERROR("osp_dump_sm proc error\r\n"); + return; + } + + return; +} + +void osp_dump_dm(char *pName, uint32_t ulLen) +{ + OSP_STATUS ret = OSP_OK; + + if(ulLen > gp_static_dm_mem_size) + { + UCP_PRINT_ERROR("osp_dump_dm ulLen:%u > gp_static_dm_mem_size:%ld\r\n", ulLen, gp_static_sm_mem_size); + return ; + } + + if(NULL == pName) + { + UCP_PRINT_ERROR("osp_dump_dm pName is null\r\n"); + return ; + } + + ret = osp_dump_proc(pName, APE_DM , ulLen); + if(OSP_OK != ret) + { + UCP_PRINT_ERROR("osp_dump_dm proc error\r\n"); + return; + } + + return; +} +#endif + +#ifdef HEARTBEAT_ENABLE +int8_t osp_dump_dm_ape_by_coreid(uint8_t coreid) +{ + int32_t ret = OSP_OK; + char *pbuf = gp_static_dm_mem; + char file_name[DUMP_DM_CORE_FILE_LEN]= {0}; + static FILE *fp = NULL; + struct tm *t; + time_t tt; + uint64_t u64_start_offset = 0; + + time(&tt); + t = localtime(&tt); + + switch (coreid) + { + case APE_CORE_ID_0: + case APE_CORE_ID_1: + { + u64_start_offset = 0; + ret = OSP_OK; + break; + } + case APE_CORE_ID_2: + case APE_CORE_ID_3: + { + u64_start_offset = SPU_DM_SIZE; + ret = OSP_OK; + break; + } + case APE_CORE_ID_4: + case APE_CORE_ID_5: + { + u64_start_offset = SPU_DM_SIZE*2; + ret = OSP_OK; + break; + } + case APE_CORE_ID_6: + case APE_CORE_ID_7: + { + u64_start_offset = SPU_DM_SIZE*3; + ret = OSP_OK; + break; + } + default: + { + ret = OSP_ERROR; + UCP_PRINT_ERROR("osp_dump_dm_ape_by_coreid: input coreid(%d) error\r\n", coreid); + break; + } + } + + if (OSP_ERROR == ret) + { + return ret; + } + + sprintf(file_name, DUMP_DM_CORE_FILE_NAME, coreid, t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + UCP_PRINT_ERROR("osp_dump_dm_ape_by_coreid: file_name = %s\r\n", file_name); + + fp = fopen(file_name, "wb+"); + if (fp < 0) + { + UCP_PRINT_ERROR("osp_dump_dm_ape_by_coreid: file open failure \n"); + return OSP_ERROR; + } + + ret = fwrite((pbuf+u64_start_offset), sizeof(char), SPU_DM_SIZE, fp); + if(ret < 0) + { + UCP_PRINT_ERROR("osp_dump_dm_ape_by_coreid: fwrite error ret:%d\n", ret); + fclose(fp); + return OSP_ERROR; + } + + fflush(fp); + fclose(fp); + + return OSP_OK; +} + + +int8_t osp_dump_dm_rfm_by_coreid(uint8_t coreid) +{ + return OSP_OK; +} + +int8_t osp_dump_dm_by_coreid(uint8_t coreid) +{ + /* ???? */ + if (coreid > MAX_NUM_SPU) + { + UCP_PRINT_ERROR("osp_dump_dm_by_coreid: input parameter error\r\n"); + return OSP_ERROR; + } + + if (coreid <= APE_CORE_ID_7) + { + return osp_dump_dm_ape_by_coreid(coreid); + } + else if (coreid <= MAX_NUM_SPU) + { + return osp_dump_dm_rfm_by_coreid(coreid); + } + return OSP_ERROR; +} +#endif + + +OSP_STATUS osp_dump_len_is_ok(module_type_e module, uint64_t ulLen) +{ + uint64_t ulModuleLen = 0; + + switch(module) + { + case SHARE_MEM: + ulModuleLen = gp_static_sm_mem_size; + break; + case APE_DM: + ulModuleLen = gp_static_dm_mem_size; + break; + case ECS_SM: + ulModuleLen = gp_static_ecs_sm_mem_size; + break; + case PET_SM: + ulModuleLen = gp_static_pet_sm_mem_size; + break; + case APE_PHY: + ulModuleLen = gp_static_ape_phy_mem_size; + break; + case APE_TEXT: + ulModuleLen = gp_static_ape_text_mem_size; + break; + case ARM_APE_MSG: + ulModuleLen = gp_static_arm_ape_msg_size; + break; + case APE_LOG: + ulModuleLen = gp_static_ape_log_size; + break; + case ARM_STACK: + ulModuleLen = gp_static_arm_stack_size; + break; + default: + break; + + } + + if(ulLen > ulModuleLen) + { + UCP_PRINT_ERROR("osp_dump_len is error ulLen:%ld\n", ulLen); + return OSP_ERROR; + } + + return OSP_OK; +} + +OSP_STATUS osp_dump_apc_len_is_ok(uint8_t ucApcId, uint64_t phy_addr,uint64_t ulLen) +{ + uint64_t u64_start_offset = 0; + uint64_t virt_addr = 0; + int32_t ret = OSP_OK; + uint32_t ulTmp = 0; + + switch (ucApcId) + { + case APC_CORE_ID_0: + { + u64_start_offset = 0; + ret = OSP_OK; + break; + } + case APC_CORE_ID_1: + { + u64_start_offset = SPU_DM_SIZE; + ret = OSP_OK; + break; + } + case APC_CORE_ID_2: + { + u64_start_offset = SPU_DM_SIZE*2; + ret = OSP_OK; + break; + } + case APC_CORE_ID_3: + { + u64_start_offset = SPU_DM_SIZE*3; + ret = OSP_OK; + break; + } + default: + { + ret = OSP_ERROR; + UCP_PRINT_ERROR("osp_dump_apc_len_is_ok: ucApcId:%u error\r\n", ucApcId); + break; + } + } + + if (OSP_ERROR == ret) + { + return ret; + } + + ret = osp_phy_to_virt( APE_DM, phy_addr, &virt_addr); + if(ret != OSP_OK) + { + UCP_PRINT_ERROR("osp_dump_apc_len APE_DM phy_addr:0x%lx virt_addr:0x%lx\n", phy_addr, virt_addr); + return OSP_ERROR; + } + + ulTmp = virt_addr - (uint64_t)(gp_static_dm_mem + u64_start_offset); + if(ulTmp < ulLen) + { + UCP_PRINT_ERROR("osp_dump_apc_len APE_DM ulTmp:%u\n", ulTmp); + return OSP_ERROR; + } + + return OSP_OK; +} + + +/*0x9400000 + apcid*0x200000 +(phy_addr - 0x200000)*/ +int8_t osp_dump_dm_by_apcid(char *pName, uint8_t ucApcId, uint64_t phy_addr, uint32_t ulLen) +{ + int32_t ret = OSP_OK; + static FILE *fp = NULL; + uint64_t virt_addr = 0; + uint64_t tmp_phy_addr = 0; + + if(NULL == pName) + { + UCP_PRINT_ERROR("osp_dump_dm_by_apcid: pName is NULL\r\n"); + return OSP_ERROR; + } + + if(ulLen > SPU_DM_SIZE) + { + UCP_PRINT_ERROR("osp_dump_dm_by_apcid: ulLen:%u error\r\n", ulLen); + return OSP_ERROR; + } + + tmp_phy_addr = APE_DM_BASE_PHY_ADDR + ucApcId*APC_DM_LEN +(phy_addr - APC_DM_LEN); + + ret = osp_phy_to_virt( APE_DM, tmp_phy_addr, &virt_addr); + if(ret != OSP_OK) + { + UCP_PRINT_ERROR("osp_dump_proc APE_DM phy_addr:0x%lx virt_addr:0x%lx\n", phy_addr, virt_addr); + return OSP_ERROR; + } + + fp = fopen(pName, "wb+"); + if (fp < 0) + { + UCP_PRINT_ERROR("osp_dump_dm_by_apcid: file open failure \n"); + return OSP_ERROR; + } + + ret = fwrite((char *)virt_addr, sizeof(char), ulLen, fp); + if(ret < 0) + { + UCP_PRINT_ERROR("osp_dump_dm_by_apcid: fwrite error ret:%d\n", ret); + fclose(fp); + return OSP_ERROR; + } + + fflush(fp); + fclose(fp); + + return OSP_OK; +} + +int8_t osp_show_dm_by_apcid(uint8_t ucApcId, uint64_t phy_addr, uint32_t ulLen) +{ + int32_t ret = OSP_OK; + uint64_t virt_addr = 0; + uint64_t tmp_phy_addr = 0; + + if(ulLen > SPU_DM_SIZE) + { + UCP_PRINT_ERROR("osp_show_dm_by_apcid: ulLen:%u error\r\n", ulLen); + return OSP_ERROR; + } + + tmp_phy_addr = APE_DM_BASE_PHY_ADDR + ucApcId*APC_DM_LEN +(phy_addr - APC_DM_LEN); + + ret = osp_phy_to_virt( APE_DM, tmp_phy_addr, &virt_addr); + if(ret != OSP_OK) + { + UCP_PRINT_ERROR("osp_dump_proc phy_addr:0x%lx virt_addr:0x%lx\n", phy_addr, virt_addr); + return OSP_ERROR; + } + + osp_dump_phy_mem(tmp_phy_addr, ulLen, phy_addr); + //osp_mem_print((char *)&temp_vir_addr, ulLen); + + return OSP_OK; +} + + +OSP_STATUS osp_dump_proc(char *pName, module_type_e module, uint64_t phy_addr, uint64_t ulLen) +{ + int32_t ret = 0; + uint64_t virt_addr = 0; + static FILE *fp = NULL; + + if ((NULL == pName) || (0 == ulLen) || (0 == phy_addr)) + { + UCP_PRINT_ERROR("osp_dump_proc pName:%s ulLen:%ld phy_addr:%ld\n", pName, ulLen, phy_addr); + return OSP_ERROR; + } + + ret = osp_dump_len_is_ok(module, ulLen); + if(ret != OSP_OK) + { + UCP_PRINT_ERROR("osp_dump_proc ulLen:%ld\n", ulLen); + return OSP_ERROR; + } + + ret = osp_phy_to_virt( module, phy_addr, &virt_addr); + if(ret != OSP_OK) + { + UCP_PRINT_ERROR("osp_dump_proc module:%d phy_addr:0x%lx virt_addr:0x%lx\n",module, phy_addr, virt_addr); + return OSP_ERROR; + } + + fp = fopen(pName, "wb+"); + if (fp < 0) + { + UCP_PRINT_ERROR(" file open failure \n"); + return OSP_ERROR; + } + + ret = fwrite((char *)virt_addr, sizeof(char), ulLen, fp); + if(ret < 0) + { + UCP_PRINT_ERROR("fwrite error ret:%d\n", ret); + fclose(fp); + return OSP_ERROR; + } + + fflush(fp); + fclose(fp); + + return OSP_OK; +} + +int32_t osp_dump_phy_mem(uint64_t phy_addr, uint32_t len, uint64_t tmp_addr) +{ + uint64_t addr_temp = OSP_ROUND_DOWN(phy_addr,OSP_DISPLAY_PAGE_LEN); + uint64_t addr_offset = phy_addr - addr_temp; + uint32_t *mem_vir_addr,*temp_vir_addr; + uint32_t i,j; + int32_t display_fd = 1; + + if(OSP_DISPLAY_MAX_LEN < len) + { + return OSP_ERROR; + } + + //printf("phy_addr=%#llx, mmap_addr=%#llx,virt_addr=%#llx,len = %d:\n",phy_addr,addr_temp,len); + //printf("phy_addr=%#lx, mmap_addr=%#lx,len = %d\n",phy_addr,addr_temp,len); + + + display_fd = open("/dev/mem", O_RDWR|O_SYNC); + if(display_fd < 0) + { + printf("open /dev/mem error\n"); + return OSP_ERROR; + } + + + mem_vir_addr = (uint32_t*)mmap(NULL, (OSP_DISPLAY_PAGE_LEN << 1), PROT_READ|PROT_WRITE, MAP_SHARED, display_fd, addr_temp); + if((uint32_t*)OSP_ERROR == mem_vir_addr) + { + printf("mmap error!! return value is %ld\n",(uint64_t)mem_vir_addr); + return OSP_ERROR; + } + + temp_vir_addr = mem_vir_addr + (addr_offset >> 2); + + for(i = 0; i < len; i += 16) + {//不足16字节也显示4个字 + printf("0x%016lx: ",tmp_addr + i); + + for(j = 0; j < 4; j++) + { + printf("0x%08x ",*temp_vir_addr++); + } + + printf("\n"); + } + + munmap((void*)mem_vir_addr,(OSP_DISPLAY_PAGE_LEN << 1)); + close(display_fd); + + return OSP_OK; + +} + + +void osp_dump_dm_test(uint8_t ucApcId, uint64_t ullAddr, uint32_t ullen) +{ + char abuf[4096] = {0}; + uint32_t i = 0; + uint64_t u64_start_offset = 0; + char filename[36] = {0}; + + for(i =0; i 0x200000) + { + return; + } + + for (i = 0; i < ulLen; i++) + { + if ((i & 0x7) == 0) + { + printf("%p: ", addr+i); + } + + printf("%02x ", addr[i]); + + if ((i & 0x7) == 0x7) + { + printf("\n"); + } + } + + printf("\n"); + + return; +} + + +void osp_dump_dis_mem(char* addr, uint32_t ulLen) +{ + char *p = NULL; + uint32_t i = 0; + uint32_t len = 0; + + if (NULL == addr) + { + return; + } + + if (ulLen > 0x100000) + { + return; + } + + p = addr; + + for (i = 0; i < ulLen; i++) + { + if ((i & 0x7) == 0) + { + len += sprintf(gp_dump_buf + len, "%p : ", p+i); + } + len += sprintf(gp_dump_buf + len, "%02x ", p[i]); + + if ((i & 0x7) == 0x7) + len += sprintf(gp_dump_buf + len, "%c", '\n'); + } + + gp_dump_buf[len] = '\0'; + + return; +} + + + + + diff --git a/osp/src/ospFile.c b/osp/src/ospFile.c new file mode 100644 index 0000000..bb434e6 --- /dev/null +++ b/osp/src/ospFile.c @@ -0,0 +1,146 @@ +#include +#include +#include + +#include "ospTypes.h" +#include "ospFile.h" + + +int32_t osp_file_init(file_t *file) +{ + pthread_mutex_init(&file->mutex, NULL); + return 1; +} + +int32_t osp_file_read_tmp(char *buffer, int32_t size, file_t *file) +{ + int32_t fd = open(file->filepath, O_RDONLY); + if (fd < 0) + { + printf(" file open failure \n"); + return -1; + } + + int32_t result = read(fd, buffer, size); + if ((result > size) || (result < -1)) + { + printf(" file read failure \n"); + close(fd); + return -1; + } + + close(fd); + return result; +} + +int32_t osp_file_read(char *buffer, int32_t size, file_t *file) +{ + //pthread_mutex_lock(&file->mutex); + int32_t result = osp_file_read_tmp(buffer, size, file); + //pthread_mutex_unlock(&file->mutex); + return result; +} + +int32_t osp_file_write_tmp(file_t *file, char *buffer, int32_t size) +{ + int32_t fd = open(file->filepath, file->flag, file->mode); + if (fd < 0) + { + printf(" file open failure \n"); + return -1; + } + + int32_t result = write(fd, buffer, size); + if (result < -1) + { + printf(" file write failure \n"); + close(fd); + return -1; + } + + fsync(fd); + close(fd); + return result; +} + +int32_t osp_file_write(file_t *file, char *buffer, int32_t size) +{ + pthread_mutex_lock(&file->mutex); + int32_t result = osp_file_write_tmp(file, buffer, size); + pthread_mutex_unlock(&file->mutex); + return result; +} + +int32_t osp_mkdirs(char *path, mode_t mode) +{ + char str[512]; + strncpy(str, path, 512); + int32_t len = strlen(str); + int32_t i; + struct stat s; + + + for (i = 0; i < len; i++) + { + if (str[i] == '/') + { + str[i] = '\0'; + if (access(str, 0) != 0) + { + mkdir(str, mode); + } + str[i] = '/'; + } + } + if (len > 0 && access(str,0) != 0) + { + mkdir(str, mode); + } + stat(path, &s); + if (S_ISDIR(s.st_mode)) + return 0; + return 0; +} + +int32_t osp_file_is_exist(char *file) +{ + int32_t ret; + + ret = access(file, F_OK); + if (0 == ret) + { + ret = 1; + } + else + { + ret = 0; + } + + return ret; +} +int32_t osp_get_file_path(char *name, char *path) +{ + int32_t i; + int32_t len; + + if ((NULL == name) || (NULL == path)) + { + return -1; + } + + len = strlen(name); + + for (i = len-1; i >= 0; i--) + { + if (name[i] == '/') + { + break; + } + } + + memcpy(path, name, i); + + return 0; + +} + diff --git a/osp/src/ospHeap.c b/osp/src/ospHeap.c new file mode 100644 index 0000000..2451c22 --- /dev/null +++ b/osp/src/ospHeap.c @@ -0,0 +1,655 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "osp.h" + +#include "ucp_printf.h" + + +typedef struct DoubleLinkNode +{ + uint64_t len; + int32_t IsBusy; + int32_t rsv; + struct DoubleLinkNode *prev; + struct DoubleLinkNode *next; +}MemNode; +#define OSP_NODE_SIZE sizeof(MemNode) +#define OSP_HEAP_BUF_TO_HEAD(pbuf) (MemNode *)((uint64_t)pbuf - OSP_NODE_SIZE) + +typedef struct heap_mem +{ + MemNode *root; + MemNode *cur_avaliable; + lx_sem_t *heap_mutex; + uint64_t virt_base; + uint64_t phy_base; + char name[24]; +}Heap_Mem_CB; + +typedef struct static_mem +{ + uint64_t virt_base; + uint64_t phy_base; + uint64_t len; + uint32_t is_mapped; //是否已经映射 0:未映射;1:已映射 + uint32_t rsv; +}Static_Mem_CB; + + +int32_t g_dev_mem_fd = -1; +int32_t g_dev_mem_noncache_fd = -1; + +Static_Mem_CB g_static_mem_cb[MEM_RESERVE] = +{ + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, + { + .is_mapped = 0, + }, +}; + +MemNode *osp_search_node(MemNode *head, uint32_t size) +{ + MemNode *node; + node = head; + + while (node) + { + if ((node->len > (size + OSP_NODE_SIZE)) && (!node->IsBusy)) + return node; + node = node->next; + } + return OSP_OK; +} + +MemNode *osp_split_node(MemNode *node, uint32_t size) +{ + MemNode *new; + MemNode *next; + uint32_t len; + + if (node->len-size < OSP_NODE_SIZE) + return node; + + len = node->len; + + node->len = size; + new = (MemNode *)((uint64_t)node + node->len + OSP_NODE_SIZE); + + new->len = len - size - OSP_NODE_SIZE; + new->IsBusy = 0; + + new->next = node->next; + next = new->next; + if (next) + next->prev = new; + new->prev = node; + node->next = new; + return new; +} +int32_t osp_set_node_busy(MemNode *node) +{ + node->IsBusy = 1; + return OSP_OK; +} +int32_t osp_clear_node_busy(MemNode *node) +{ + node->IsBusy = 0; + return OSP_OK; +} + +MemNode *osp_get_next_node(MemNode *node) +{ + return node->next; +} + +MemNode *osp_get_pre_node(MemNode *node) +{ + return node->prev; +} + + +int32_t osp_node_need_merge(MemNode *node, MemNode *nextnode) +{ + if ((0 == node->IsBusy)&&(0 == nextnode->IsBusy)) + return 1; + return 0; +} + +int32_t osp_node_merge(Heap_Mem_CB *heap_mem, MemNode *node, MemNode *nextnode) +{ + MemNode *nextnext; + + nextnext = nextnode->next; + + node->next = nextnext; + if (nextnext) + nextnext->prev = node; + + node->len += nextnode->len + OSP_NODE_SIZE; + + if(nextnode == heap_mem->cur_avaliable) + { + heap_mem->cur_avaliable = node; + } + + return OSP_OK; + +} + +static int32_t get_base_and_len(module_type_e module, uint64_t *base_addr,uint64_t *len) +{ + int32_t ret = OSP_OK; + + switch(module) + { + case ARM_STACK: + { + *base_addr = ARM_STACK_BASE_PHY_ADDR; + *len = LEN_OF_ARM_STACK; + break; + } + case APE_DM: + { + *base_addr = APE_DM_BASE_PHY_ADDR; + *len = LEN_OF_APE_DM; + break; + } + case APE_PHY: + { + *base_addr = APE_PHY_BASE_PHY_ADDR; + *len = LEN_OF_APE_PHY; + break; + } + case APE_TEXT: + { + *base_addr = APE_TEXT_BASE_PHY_ADDR; + *len = LEN_OF_APE_TEXT; + break; + } + case ARM_APE_MSG: + { + *base_addr = ARM_APE_MSG_BASE_PHY_ADDR; + *len = LEN_OF_ARM_APE_MSG; + break; + } + /*case ARM_LOG: + { + *base_addr = ARM_LOG_BASE_PHY_ADDR; + *len = LEN_OF_ARM_LOG; + break; + }*/ + case APE_LOG: + { + *base_addr = APE_LOG_BASE_PHY_ADDR; + *len = LEN_OF_APE_LOG; + break; + } + case SHARE_MEM: + { + *base_addr = SHARE_MEM_BASE_PHY_ADDR; + *len = LEN_OF_SHARE_MEM; + break; + } + case ECS_SM: + { + *base_addr = ECS_SM_DM_BASE_PHY_ADDR; + *len = LEN_OF_ECS_SM_DM; + break; + } + case PET_SM: + { + *base_addr = PET_SM_DM_BASE_PHY_ADDR; + *len = LEN_OF_PET_SM_DM; + break; + } + default: + { + *base_addr = 0; + *len = 0; + ret = OSP_ERROR; + break; + } + } + + return ret; +} + +void *get_static_mem(module_type_e module, uint64_t *len) +{ + void *mem_vir_addr; + uint64_t addr_offset = 0,mem_len = 0; + int32_t mem_temp_fd = -1; + + if(1 == g_static_mem_cb[module].is_mapped) //已映射 + { + *len = g_static_mem_cb[module].len; + return (void *)g_static_mem_cb[module].virt_base; + } + + +//#ifdef CACHE_ENABLE + switch(module) + { + case ARM_STACK: +#ifdef CACHE_ENABLE + case ARM_APE_MSG: +#endif + { + if(OSP_ERROR == g_dev_mem_fd) //鎵撳紑mem璁惧 + { + g_dev_mem_fd = open("/dev/ucp_sm_ddr_cache", O_RDWR|O_SYNC); + } + + if(g_dev_mem_fd < 0) + { + UCP_PRINT_ERROR("open file failed,ucp_sm_ddr_cache < 0."); + return (void *)OSP_ERROR; + } + mem_temp_fd = g_dev_mem_fd; + break; + } +#ifndef CACHE_ENABLE + case ARM_APE_MSG: +#endif + case ECS_SM: + case PET_SM: + case APE_DM: + case SHARE_MEM: + case APE_PHY: + case APE_TEXT: + case APE_LOG: + { + //g_dev_mem_fd = open("/dev/ucp_2_revmem", O_RDWR|O_SYNC); + if(OSP_ERROR == g_dev_mem_noncache_fd) //鎵撳紑mem璁惧 + { + g_dev_mem_noncache_fd = open("/dev/ucp_sm_ddr_noncache", O_RDWR|O_SYNC); + } + + if(g_dev_mem_noncache_fd < 0) + { + UCP_PRINT_ERROR("open file failed,ucp_sm_ddr_noncache < 0."); + return (void *)OSP_ERROR; + } + mem_temp_fd = g_dev_mem_noncache_fd; + break; + } + default: + UCP_PRINT_ERROR("memory type error. < 0."); + return (void *)OSP_ERROR; + } +/*#else + if(OSP_ERROR == g_dev_mem_fd) //打开mem设备 + { + //g_dev_mem_fd = open("/dev/mem", O_RDWR|O_SYNC); + g_dev_mem_fd = open("/dev/ucp_2_revmem", O_RDWR|O_SYNC); + if(g_dev_mem_fd < 0) + { + return (void *)OSP_ERROR; + } + } + mem_temp_fd = g_dev_mem_fd; +#endif*/ + /*通过模块类型获取对应的地址偏移和长度,并进行地址映射*/ + if(OSP_OK == get_base_and_len(module, &addr_offset, &mem_len)) + { + mem_vir_addr = mmap(NULL, mem_len, PROT_READ|PROT_WRITE, MAP_SHARED, mem_temp_fd, addr_offset); + if((void *)OSP_ERROR == mem_vir_addr) + { + UCP_PRINT_ERROR("get_base_and_len failed,%lx,%lx.",addr_offset,mem_len); + return (void *)OSP_ERROR; + } + else + { + *len = mem_len; + g_static_mem_cb[module].virt_base = (uint64_t)mem_vir_addr; + g_static_mem_cb[module].phy_base = addr_offset; + g_static_mem_cb[module].len = mem_len; + g_static_mem_cb[module].is_mapped = 1; + return mem_vir_addr; + } + } + else + { + UCP_PRINT_ERROR("get_base_and_len error,%lx,%lx.",addr_offset,mem_len); + return (void *)OSP_ERROR; + } +} + +void *osp_heap_mem_init(char *pbuf, uint64_t size,void *head_of_static_mem,module_type_e module) +{ + Heap_Mem_CB *heap_mem = NULL; + uint64_t addr_offset = 0,mem_len = 0; + + heap_mem = malloc(sizeof(Heap_Mem_CB)); + if(NULL == heap_mem) + { + return NULL; + } + + heap_mem->root = (MemNode *)pbuf; + if(size < OSP_NODE_SIZE) //长度小于结构头长度 + { + heap_mem->root->len = 0; + } + else + { + heap_mem->root->len = size - OSP_NODE_SIZE; + } + + heap_mem->root->IsBusy = 0; + heap_mem->root->next = NULL; + heap_mem->root->prev = NULL; + heap_mem->virt_base = (uint64_t)head_of_static_mem; + heap_mem->cur_avaliable = heap_mem->root; + + if(OSP_OK == get_base_and_len(module, &addr_offset, &mem_len)) + { + heap_mem->phy_base = addr_offset; + heap_mem->heap_mutex = osp_semm_create(); + return (void *)heap_mem; + } + else + { + return NULL; + } +} + +int8_t * osp_alloc_heap_mem(void *heap, uint32_t size) +{ + MemNode *node; + //MemNode *nextnode; + //MemNode *new; + Heap_Mem_CB *heap_mem = (Heap_Mem_CB *)heap; + + osp_sem_take(heap_mem->heap_mutex, -1); + + node = osp_search_node(heap_mem->cur_avaliable, size); + if (!node) + { + node = osp_search_node(heap_mem->root, size); + if (!node) + { + osp_sem_give(heap_mem->heap_mutex); + return NULL; + } + } + + //osp_set_node_busy(node); + node->IsBusy = 1; + + //new = osp_split_node(node, size); + heap_mem->cur_avaliable = osp_split_node(node, size); + + + //nextnode = osp_get_next_node(new); + /*nextnode = new->next; + if (NULL != nextnode) + if (osp_node_need_merge(new, nextnode)) + osp_node_merge(new, nextnode);*/ + + osp_sem_give(heap_mem->heap_mutex); + return (int8_t *)((uint64_t)node + OSP_NODE_SIZE); + +} + +int32_t osp_free_heap_mem(void *heap, char*pbuf) +{ + MemNode *node = OSP_HEAP_BUF_TO_HEAD(pbuf); + MemNode *nextnode; + MemNode *prenode; + Heap_Mem_CB *heap_mem = (Heap_Mem_CB *)heap; + + osp_sem_take(heap_mem->heap_mutex, -1); + //osp_clear_node_busy(node); + node->IsBusy = 0; + + //osp_debug_out(CMD_DEBUG_LEVEL, "node is %p, node->IsBusy is %d, node->len is %d\r\n", node, node->IsBusy, node->len); + //nextnode = osp_get_next_node(node); + nextnode = node->next; + + //prenode = osp_get_pre_node(node); + prenode = node->prev; + + if (nextnode) + { + if (osp_node_need_merge(node, nextnode)) + { + osp_node_merge(heap_mem, node, nextnode); + } + } + + if (prenode) + { + if (osp_node_need_merge(prenode, node)) + { + osp_node_merge(heap_mem, prenode, node); + } + } + osp_sem_give(heap_mem->heap_mutex); + + return 0; +} + +int32_t osp_show_heap_mem(void *heap) +{ + int32_t busynum = 0; + int32_t freenum = 0; + int32_t busymem = 0; + int32_t freemem = 0; + char buf[256] = {0}; + int32_t len = 0; + Heap_Mem_CB *heap_mem = (Heap_Mem_CB *)heap; + + MemNode *node = heap_mem->root; + osp_sem_take(heap_mem->heap_mutex, -1); + while (node) + { + osp_debug_out(CMD_DEBUG_LEVEL, "node is %p, node->IsBusy is %d, node->len is %d\r\n", node, node->IsBusy, node->len); + if (node->IsBusy) + { + busynum++; + busymem += node->len; + } + else + { + freenum++; + freemem += node->len; + } + node = node->next; + } + + osp_sem_give(heap_mem->heap_mutex); + len += sprintf(buf + len, "busynum\tbusymem\tfreenum\tfreemem\t\r\n"); + len += sprintf(buf + len, "%d\t%d\t%d\t%d\t\r\n", busynum, busymem, freenum, freemem); + osp_debug_out(CMD_DEBUG_LEVEL, "%s", buf); + + return OSP_OK; +} + +#if 0 +U64 osp_phy_to_virt(void *heap, U64 phy_addr) +{ + Heap_Mem_CB *heap_mem = (Heap_Mem_CB *)heap; + + return (heap_mem->virt_base + (phy_addr - heap_mem->phy_base)); +} + +U64 osp_virt_to_phy(void *heap, U64 virt_addr) +{ + Heap_Mem_CB *heap_mem = (Heap_Mem_CB *)heap; + + return (heap_mem->phy_base + (virt_addr - heap_mem->virt_base)); +} +#else +int32_t osp_phy_to_virt(module_type_e module, uint64_t phy_addr, uint64_t *virt_addr) +{ + if(1 == g_static_mem_cb[module].is_mapped) + { + *virt_addr = g_static_mem_cb[module].virt_base + (phy_addr - g_static_mem_cb[module].phy_base); + return OSP_OK; + } + else + { + UCP_PRINT_ERROR("osp_phy_to_virt %d error!!",module); + return OSP_ERROR; + } +} + +int32_t osp_virt_to_phy(module_type_e module, uint64_t virt_addr, uint64_t *phy_addr) +{ + if(1 == g_static_mem_cb[module].is_mapped) + { + *phy_addr = g_static_mem_cb[module].phy_base + (virt_addr - g_static_mem_cb[module].virt_base); + return OSP_OK; + } + else + { + UCP_PRINT_ERROR("osp_virt_to_phy %d error!!",module); + return OSP_ERROR; + } +} +#endif + +#if 1 +void osp_flush_dcache_area(void * volatile addr, uint64_t volatile len) +{ + +__asm volatile(" mrs x3, ctr_el0 \n" // read CTR + " ubfm x3, x3, #16, #19 \n" // cache line size encoding + " mov x2, #4 \n" // bytes per word + " lsl x2, x2, x3 \n" // actual cache line size + " add x1, x0, x1 \n" + " sub x3, x2, #1 \n" + " bic x0, x0, x3 \n" + " 9998: \n" + " dc civac, x0 \n" + " add x0, x0, x2 \n" + " cmp x0, x1 \n" + " b.lo 9998b \n" + " dsb sy \n"); + +} + +void osp_clean_dcache_area(void * volatile addr, uint64_t volatile len) +{ + +__asm volatile(" mrs x3, ctr_el0 \n" // read CTR + " ubfm x3, x3, #16, #19 \n" // cache line size encoding + " mov x2, #4 \n" // bytes per word + " lsl x2, x2, x3 \n" // actual cache line size + " add x1, x0, x1 \n" + " sub x3, x2, #1 \n" + " bic x0, x0, x3 \n" + " 9998: \n" + " dc cvac, x0 \n" + " add x0, x0, x2 \n" + " cmp x0, x1 \n" + " b.lo 9998b \n" + " dsb sy \n"); + +} +#endif + +int32_t osp_invalid_dcache_area(module_type_e module, uint64_t virt_addr, uint64_t len) +{ + int32_t iRet = 0; + uint64_t phy_addr = 0; + + if(g_dev_mem_fd < 0) + { + return OSP_ERROR; + } + + if(OSP_OK != osp_virt_to_phy(module, virt_addr, &phy_addr)) + { + return OSP_ERROR; + } + + iRet = ioctl(g_dev_mem_fd,len,phy_addr); + if(-1 == iRet) + { + printf("user_invalid_dcache_area phy add out of range \n "); + return OSP_ERROR; + } + + return OSP_OK; +} + +int32_t osp_display_phy_mem(uint64_t phy_addr, uint32_t len) +{ + uint64_t addr_temp = OSP_ROUND_DOWN(phy_addr,OSP_DISPLAY_PAGE_LEN); + uint64_t addr_offset = phy_addr - addr_temp; + uint32_t *mem_vir_addr,*temp_vir_addr; + uint32_t i,j; + int32_t display_fd = 1; + + if(OSP_DISPLAY_MAX_LEN < len) + { + return OSP_ERROR; + } + + //printf("phy_addr=%#llx, mmap_addr=%#llx,virt_addr=%#llx,len = %d:\n",phy_addr,addr_temp,len); + printf("phy_addr=%#lx, mmap_addr=%#lx,len = %d\n",phy_addr,addr_temp,len); + + + display_fd = open("/dev/mem", O_RDWR|O_SYNC); + if(display_fd < 0) + { + printf("open /dev/mem error\n"); + return OSP_ERROR; + } + + + mem_vir_addr = (uint32_t*)mmap(NULL, (OSP_DISPLAY_PAGE_LEN << 1), PROT_READ|PROT_WRITE, MAP_SHARED, display_fd, addr_temp); + if((uint32_t*)OSP_ERROR == mem_vir_addr) + { + printf("mmap error!! return value is %ld\n",(uint64_t)mem_vir_addr); + return OSP_ERROR; + } + + temp_vir_addr = mem_vir_addr + (addr_offset >> 2); + + for(i = 0; i < len; i += 16) + {//不足16字节也显示4个字 + printf("0x%016lx: ",phy_addr + i); + + for(j = 0; j < 4; j++) + { + printf("0x%08x ",*temp_vir_addr++); + } + + printf("\n"); + } + + munmap((void*)mem_vir_addr,(OSP_DISPLAY_PAGE_LEN << 1)); + close(display_fd); + return OSP_OK; +} + diff --git a/osp/src/ospHeartbeat.c b/osp/src/ospHeartbeat.c new file mode 100644 index 0000000..4e37dd6 --- /dev/null +++ b/osp/src/ospHeartbeat.c @@ -0,0 +1,350 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "pet_sm_mgt.h" +#include "msg_transfer_mem.h" +#include "ospHeartbeat.h" +#include "ospSem.h" +//#include "ospSoftQue.h" +//#include "ospMsg.h" +//#include "ospDbg.h" +#include "ucp_printf.h" +#include "ospDelay.h" +#include "ospDump.h" +#include "ospCfgToBin.h" +#include "ospSwTimer.h" + +#define RESTART_REGISTER_LEN (0x1000) +#define RESTART_REGISTER_SUBCTRL0_BASE (0x04A88000) +#define RESTART_REGISTER_SUBCTRL1_BASE (0x04AD8000) +#define RESTART_REGISTER_SUBCTRL2_BASE (0x04B28000) +#define RESTART_REGISTER_SUBCTRL3_BASE (0x04B78000) +#define RESTART_REGISTER_RST_CFG_BASE (0x04550000) + + +#define OSP_HEARTBEAT_NAME "OspHeartbeatTimer" +#define OSP_HEARTBEAT_TMR_OUT (1000) /* 1000ms->1s */ +#define OSP_HB_MAX_CORE_NUM 2//(12) /* 鐩戞祴鐨勬渶澶氭牳鏁 */ +#define OSP_HB_MAX_COUNTER (3) /* 澶变俊璁℃暟鏈澶у */ + +#define OSP_HEARTBEAT_OFF (1) /* 涓嶆娴嬪績璺 */ +#define OSP_HEARTBEAT_ON (0) /* 妫娴嬪績璺 */ + +#define HB_NO_CHECK (1) /* 涓嶅啀琚娴 */ +#define HB_CHECK (0) /* 琚娴 */ + +static uint8_t gsu8OspHeartbeatSwitch = 0; /* 榛樿妫娴嬪績璺 */ +static OspHeartbeatInfo_t gsstOspHeartbeatCounter[OSP_HB_MAX_CORE_NUM]; + +uint8_t* gu8virRegAddr = NULL; +uint8_t* gu8VirSubctrlAddr = NULL; +uint8_t* gu8VirRstCfgAddr = NULL; + +/* 鑾峰彇瀵瑰簲鏍哥殑蹇冭烦璁℃暟 */ +uint32_t OspGetHeartbeat(uint8_t u8CoreId) +{ + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + UcpHandshake_t* pHandshake = pPetSmLocalMgt->pHandshake; + return pHandshake->heartbeat[u8CoreId]; +} + + +/* 閲嶅惎瀵勫瓨鍣 */ +int8_t OspRestartRegister(uint8_t u8CoreId) +{ + uint64_t u64SubctrlAddr = 0; + int iOspRestartFd = -1; + int8_t i8ApcId = -1; + + switch(u8CoreId) + { + case 0: + case 1: + { + i8ApcId = 0; + u64SubctrlAddr = RESTART_REGISTER_SUBCTRL0_BASE; + break; + } + case 2: + case 3: + { + i8ApcId = 1; + u64SubctrlAddr = RESTART_REGISTER_SUBCTRL1_BASE; + break; + } + case 4: + case 5: + { + i8ApcId = 2; + u64SubctrlAddr = RESTART_REGISTER_SUBCTRL2_BASE; + break; + } + case 6: + case 7: + { + i8ApcId = 3; + u64SubctrlAddr = RESTART_REGISTER_SUBCTRL3_BASE; + break; + } + default: + { + i8ApcId = -1; + break; + } + } + + if (-1 == i8ApcId) + { + UCP_PRINT_ERROR("OspRestartRegister: coreid(%d) error.\r\n", u8CoreId); + return OSP_ERROR; + } + UCP_PRINT_DEBUG("OspRestartRegister: Start to restart register(coreid = %d).\r\n", u8CoreId); + + iOspRestartFd = open("/dev/mem", O_RDWR|O_SYNC); + if (0 > iOspRestartFd) + { + UCP_PRINT_ERROR("OspRestartRegister: open /dev/mem error.\r\n"); + return OSP_ERROR; + } + UCP_PRINT_DEBUG("OspRestartRegister: start mmap(subctrl).\r\n"); + + gu8VirSubctrlAddr = (uint8_t*)mmap(NULL, RESTART_REGISTER_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, iOspRestartFd, u64SubctrlAddr); + if ((uint8_t*)(-1) == gu8VirSubctrlAddr) + { + UCP_PRINT_ERROR("OspRestartRegister: mmap error.\r\n"); + return OSP_ERROR; + } + UCP_PRINT_DEBUG("OspRestartRegister: start mmap(rst_cfg).\r\n"); + + gu8VirRstCfgAddr = (uint8_t*)mmap(NULL, RESTART_REGISTER_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, iOspRestartFd, RESTART_REGISTER_RST_CFG_BASE); + if ((uint8_t*)(-1) == gu8VirRstCfgAddr) + { + UCP_PRINT_ERROR("OspRestartRegister: mmap error.\r\n"); + return OSP_ERROR; + } + UCP_PRINT_DEBUG("OspRestartRegister: Set register for restart.\r\n"); + + /* 鏍规嵁coreid璁剧疆瀵瑰簲瀵勫瓨鍣 */ + + + *((volatile uint32_t*)(gu8VirSubctrlAddr)) |= 0xC; //enable ISO, set bit2,3 to 1 + *((volatile uint32_t*)(gu8VirSubctrlAddr)) &= 0xFFFFFFFD; //apc_arstn is valid, reset bus of apc0 + *((volatile uint32_t*)(gu8VirRstCfgAddr+0x274+i8ApcId*4)) = (0xFFFFFF & (*((volatile uint32_t*)(gu8VirRstCfgAddr+i8ApcId*4)))) | (4 << 24); //reset apc0 core, set bit24 to 0 + osp_delay(1000); + *((volatile uint32_t*)(gu8VirSubctrlAddr)) |= 0x2; //apc_arstn is invalid, dereset bus of apc0 + *((volatile uint32_t*)(gu8VirRstCfgAddr+0x274+i8ApcId*4)) = (0xFFFFFF & (*((volatile uint32_t*)(gu8VirRstCfgAddr+i8ApcId*4)))) | (5 << 24); //dereset apc0 core, set bit24 to 1 + *((volatile uint32_t*)(gu8VirSubctrlAddr)) &= 0xFFFFFFF3; //disable ISO, set bit2,3 to 0 + + return OSP_OK; +} + +/* DUMP DM鍐呭瓨 */ +int8_t OspDumpDm2Ddr(uint8_t u8CoreId) +{ +#ifdef HEARTBEAT_ENABLE + return osp_dump_dm_by_coreid(u8CoreId); +#else + return OSP_OK; +#endif +} + +#define OSP_LOAD_APE0_OUT "./loadelf_8g -ape dump_im.ape0.out %d 1" +#define OSP_LOAD_APE1_OUT "./loadelf_8g -ape dump_im.ape1.out %d 1" + +/* 浜屾鍔犺浇 */ +int8_t Osp2Loader(uint8_t u8CoreId) +{ + char cmd[128] = {0}; + if (u8CoreId <= 7) + { + if (0 == u8CoreId%2) + { + sprintf(cmd, OSP_LOAD_APE0_OUT, u8CoreId); + } + else + { + sprintf(cmd, OSP_LOAD_APE1_OUT, u8CoreId); + } + UCP_PRINT_DEBUG("Osp2Loader: cmd = %s \r\n", cmd); + system(cmd); + return OSP_OK; + } + return OSP_ERROR; +} + +/* DUMP IM鍐呭瓨 */ +int8_t OspDumpIm2Ddr(uint8_t u8CoreId) +{ +#ifdef HEARTBEAT_ENABLE + return osp_get_im2ddr_to_file(u8CoreId); +#else + return OSP_OK; +#endif +} + +#define OSP_GET_DUMP_DM2TMP "./exp_file dump_dm_core* /tmp/dumpfile" +#define OSP_GET_DMMP_IM2TMP "./exp_file dump_im_core* /tmp/dumpfile" + +void OspGetFileOut(uint8_t u8CoreId) +{ + //UCP_PRINT_DEBUG("OspGetFileOut: cmd = %s \r\n", OSP_GET_DUMP_DM2TMP); + system(OSP_GET_DUMP_DM2TMP); + + //UCP_PRINT_DEBUG("OspGetFileOut: cmd = %s \r\n", OSP_GET_DMMP_IM2TMP); + system(OSP_GET_DMMP_IM2TMP); + + //UCP_PRINT_DEBUG("OspGetFileOut: OK \r\n"); + return ; +} + +/* 閲嶅惎 */ +void OspRestartPro(uint8_t u8CoreId) +{ + int8_t ret = 0; + + UCP_PRINT_DEBUG("OspRestartPro : u8CoreId = %d \r\n", u8CoreId); + + if (7 < u8CoreId) + { + UCP_PRINT_ERROR("OspRestartPro: core_id = %d(big).\r\n", u8CoreId); + return ; + } + + ret = OspRestartRegister(u8CoreId); + if (OSP_ERROR == ret) + { + UCP_PRINT_ERROR("OspRestartPro: Call OspRestartRegister return error.\r\n"); + return ; + } + + //UCP_PRINT_DEBUG("OspRestartPro : OspRestartRegister return ok \r\n"); + + ret = OspDumpDm2Ddr(u8CoreId); + if (OSP_ERROR == ret) + { + UCP_PRINT_ERROR("OspRestartPro: Call OspDumpDm2Ddr return error.\r\n"); + return ; + } + //UCP_PRINT_DEBUG("OspRestartPro : OspDumpDm2Ddr return ok \r\n"); + + ret = Osp2Loader(u8CoreId); + if (OSP_ERROR == ret) + { + UCP_PRINT_ERROR("OspRestartPro: Call Osp2Loader return error.\r\n"); + return ; + } + //UCP_PRINT_DEBUG("OspRestartPro : Osp2Loader return ok \r\n"); + + ret = OspDumpIm2Ddr(u8CoreId); + if (OSP_ERROR == ret) + { + UCP_PRINT_ERROR("OspRestartPro: Call OspDumpIm2Ddr return error.\r\n"); + return ; + } + //UCP_PRINT_DEBUG("OspRestartPro : OspDumpIm2Ddr return ok \r\n"); + + OspGetFileOut(u8CoreId); + + UCP_PRINT_DEBUG("****************************************************** \r\n"); + return ; +} + + +/* 蹇冭烦瀹氭椂鍣ㄨ秴鏃跺鐞嗗嚱鏁 +1. 鑻ヤ笉闇瑕佺洃娴嬬洿鎺ヨ繑鍥 +2. 鐩戞祴姣忎釜鏍哥殑蹇冭烦璁℃暟 + 2.1 涓庝笂娆$殑瀵规瘮锛屼竴鑷村垯鐪嬫槸鍚﹁揪鍒版渶澶уけ淇¤鏁--閲嶅惎 + 2.2 涓嶄竴鑷达紝鏇存柊涓婃璁℃暟 +*/ +void OspHeartbeatTimeoutPro(void) +{ + static uint32_t su32Cnt = 0; + uint8_t u8CoreId = 0; + uint32_t u32HeartbeatCunt = 0; + su32Cnt++; + //UCP_PRINT_DEBUG("OspHeartbeatTimeoutPro: Enter >>> (%d)", su32Cnt); + + /* 鑻ュ績璺崇洃娴嬪叧闂紝鍒欎笉鐩戞祴鍚勬牳蹇冭烦 */ + if (OSP_HEARTBEAT_OFF == gsu8OspHeartbeatSwitch) + { + UCP_PRINT_ERROR("OspHeartbeatTimeoutPro: .gsu8OspHeartbeatSwitch is OSP_HEARTBEAT_OFF.\r\n"); + return ; + } + + /* 鐩戞祴鍚勬牳蹇冭烦 */ + for( u8CoreId = 0; u8CoreId < OSP_HB_MAX_CORE_NUM; u8CoreId++) + { + if (HB_NO_CHECK == gsstOspHeartbeatCounter[u8CoreId].u32CheckFlag) + { + continue; + } + u32HeartbeatCunt = OspGetHeartbeat(u8CoreId); + UCP_PRINT_DEBUG("OspHeartbeatTimeoutPro: coreId(%d) LastBeat(%d) NowBeat(%d)\r\n", u8CoreId, gsstOspHeartbeatCounter[u8CoreId].u32LastCounter, u32HeartbeatCunt); + if (gsstOspHeartbeatCounter[u8CoreId].u32LastCounter == u32HeartbeatCunt) + { + gsstOspHeartbeatCounter[u8CoreId].u32LossCounter++; + + if (gsstOspHeartbeatCounter[u8CoreId].u32LossCounter > OSP_HB_MAX_COUNTER) + { + UCP_PRINT_ERROR("OspHeartbeatTimeoutPro: CoreID(%d) should be restart...\r\n", u8CoreId); + OspRestartPro(u8CoreId); + if (0 == u8CoreId%2) + { + gsstOspHeartbeatCounter[u8CoreId].u32CheckFlag = HB_NO_CHECK; + gsstOspHeartbeatCounter[u8CoreId+1].u32CheckFlag = HB_NO_CHECK; + } + else + { + gsstOspHeartbeatCounter[u8CoreId].u32CheckFlag = HB_NO_CHECK; + gsstOspHeartbeatCounter[u8CoreId-1].u32CheckFlag = HB_NO_CHECK; + } + return ; + } + } + else + { + gsstOspHeartbeatCounter[u8CoreId].u32LastCounter = u32HeartbeatCunt; + gsstOspHeartbeatCounter[u8CoreId].u32LossCounter = 0; + } + } + return ; +} + +/* 蹇冭烦澶勭悊鍑芥暟锛 +1. 鍒涘缓瀹氭椂鍣 +2. 鍚姩瀹氭椂鍣 +*/ +int8_t OspHeartbeatPro(void) +{ + int8_t ret = 0; + uint8_t u8TimerIndex = 0; + + memset(gsstOspHeartbeatCounter, 0, sizeof(gsstOspHeartbeatCounter)); + gsu8OspHeartbeatSwitch = OSP_HEARTBEAT_ON; + //return OSP_OK; + + /* 鍒涘缓瀹氭椂鍣 */ + ret = OspTmrCreate((const char*)OSP_HEARTBEAT_NAME, OSP_HEARTBEAT_TMR_OUT, OSP_TMR_PERIODIC, (OSP_CALLBACK)OspHeartbeatTimeoutPro, NULL); + if (OSP_ERROR == ret) + { + UCP_PRINT_ERROR("OspHeartbeatPro: OspTmrCreate return error.\r\n"); + return OSP_ERROR; + } + u8TimerIndex = ret; + + /* 鍚姩瀹氭椂鍣 */ + ret = OspTmrStart(u8TimerIndex); + if (OSP_ERROR == ret) + { + UCP_PRINT_ERROR("OspHeartbeatPro: OspTmrStart return error.\r\n"); + return OSP_ERROR; + } + return OSP_OK; +} + + diff --git a/osp/src/ospList.c b/osp/src/ospList.c new file mode 100644 index 0000000..6a3cba4 --- /dev/null +++ b/osp/src/ospList.c @@ -0,0 +1,57 @@ +#include +#include +#include + +#include "osp.h" + + + +static void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +} + +static void __list_add(struct list_head *new, + struct list_head *prev, + struct list_head *next) +{ + + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + + +static void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + + +static inline void __list_del(struct list_head *prev, struct list_head *next) +{ + next->prev = prev; + prev->next = next; +} + +static inline void __list_del_entry(struct list_head *entry) +{ + + + __list_del(entry->prev, entry->next); +} + +static inline void list_del(struct list_head *entry) +{ + __list_del_entry(entry); + entry->next = NULL; + entry->prev = NULL; +} + + +#define list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + + diff --git a/osp/src/ospLog.c b/osp/src/ospLog.c new file mode 100644 index 0000000..b76a319 --- /dev/null +++ b/osp/src/ospLog.c @@ -0,0 +1,1305 @@ +#define _GNU_SOURCE /*浣跨敤get_current_dir_name 缂栬瘧鍛婅锛岃瀹忕殑瀹氫箟搴旇鍦╱nistd.h涔嬪墠*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "osp.h" +#include "ospSoftQue.h" +#include "ospShell.h" +#include "ucp_printf.h" +#include "ospUdp.h" + + + +void *g_OspLogSem = NULL; + + +int32_t osp_base_logid; +uint32_t log_rand; +uint32_t g_ulApeLogMode = 0; /*0: ape log鏃ュ織鍐欏叆鏂囦欢 1: 缃戝彛杈撳嚭ape log 2:ape log鏃ュ織shell鎵撳嵃杈撳嚭*/ +uint32_t g_ulArmLogMode = 0; /*0: arm log鏃ュ織鍐欏叆鏂囦欢 1: 缃戝彛杈撳嚭arm log 2:arm log鏃ュ織shell鎵撳嵃杈撳嚭*/ +uint8_t g_ucPlatformMode = 0; /*0: platform log鏃ュ織鍐欏叆鏂囦欢 1: 缃戝彛杈撳嚭platform log 2:platform log鏃ュ織shell鎵撳嵃杈撳嚭*/ +uint8_t g_time_now[128]; +uint8_t g_ucFflushEnable = 0; +int32_t net_log_txudp_id = -1; /*鍚愮綉鍙og id*/ + +Osp_Server_Head gst_server_log; +extern uint8_t guc_print_level; +extern char *gp_dump_buf; +osp_log_file_cfg log_file_cfg_table[MAX_LOG_CFG_NUM][4]; + +void osp_get_current_time(void) +{ + OSP_RTCTIME osptime; + + osp_get_rtc_time(&osptime); + sprintf((char *)g_time_now, \ + "[%04d-%02d-%02d-%02d:%02d:%02d:%02d]", \ + osptime.year, osptime.month, osptime.day, \ + osptime.hour, osptime.minute, osptime.second, osptime.usecond); +} + +uint32_t osp_get_msgtype_id(uint32_t msg_type) +{ + uint32_t type = 0; + + switch(msg_type) + { + case 0x60: + type = 0; + break; + case 0x61: + type = 1; + break; + case 0x62: + type = 2; + break; + case 0x63: + type = 3; + break; + default: + type = 0; + break; + } + + return type; +} + +void osp_get_msgtype_name(uint32_t msg_type, char *msg_name) +{ + if(NULL == msg_name) + { + return; + } + + switch(msg_type) + { + case 0x60: + strcpy(msg_name,"str"); + break; + case 0x61: + strcpy(msg_name,"bin"); + break; + case 0x62: + strcpy(msg_name,"platform"); + break; + case 0x63: + strcpy(msg_name,"dm"); + break; + default: + strcpy(msg_name,"default"); + break; + } + + return; +} + + +int32_t osp_modify_log(uint32_t logid, uint32_t msg_type, uint32_t max_file_size, uint32_t max_file_num) +{ + uint32_t type = 0; + osp_log_file_cfg (*p_log_file_cfg)[4]; + + if (max_file_size > 100 || max_file_num > 100) + { + UCP_PRINT_ERROR("error:osp_modify_log max_file_szie:%d max_file_num:%d\n", max_file_size, max_file_num); + return OSP_ERROR; + } + + if (logid > 15) + { + UCP_PRINT_ERROR("error:osp_modify_log logid:%d\n", logid); + return OSP_ERROR; + } + + type = osp_get_msgtype_id(msg_type); + + p_log_file_cfg = log_file_cfg_table; + //p_log_file_cfg = (osp_log_file_cfg *)&log_file_cfg_table[0][0]; + if (p_log_file_cfg[logid][type].valied == 1) + { + p_log_file_cfg[logid][type].max_file_size_M = max_file_size; + p_log_file_cfg[logid][type].max_file_num = max_file_num; + } + else + { + UCP_PRINT_ERROR("error:osp_modify_log valied:%d\n", p_log_file_cfg[logid][type].valied); + return OSP_ERROR; + } + return OSP_OK; +} + +int32_t osp_create_log(char *name, uint32_t max_file_szie, uint32_t max_file_num, uint32_t with_time) +{ + uint32_t i; + uint32_t j; + osp_log_file_cfg (*p_log_file_cfg)[4]; + + if (NULL == g_OspLogSem) + { + return OSP_ERROR; + } + + if (name == NULL || max_file_szie < 0 || max_file_num < 0) + { + return OSP_ERROR; + } + + osp_sem_take(g_OspLogSem, -1); + + p_log_file_cfg = log_file_cfg_table; + // p_log_file_cfg = &log_file_cfg_table[0][0]; + + for (i = 0; i < MAX_LOG_CFG_NUM; i++) + { + for(j = 0; j< 4; j++) + { + if (p_log_file_cfg[i][j].valied == 0) + { + p_log_file_cfg[i][j].valied = 1; + p_log_file_cfg[i][j].max_file_size_M = max_file_szie; + p_log_file_cfg[i][j].max_file_num = max_file_num; + p_log_file_cfg[i][j].with_time = with_time; + p_log_file_cfg[i][j].key = log_rand; + + memcpy(p_log_file_cfg[i][j].logname, name, strlen(name)); + } + } + + } + + osp_sem_give(g_OspLogSem); + return OSP_OK; +} + + +FILE *osp_get_log_file(int32_t logid, uint32_t msg_type) +{ + uint32_t type =0; + + type = osp_get_msgtype_id(msg_type); + + return log_file_cfg_table[logid][type].file; +} + +OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type) +{ + osp_log_file_cfg (*p_log_file_cfg)[4]; + char name[150] = {0}; + char path[150] = {0}; + char msg_name[10] = {0}; + int32_t file_idx = 0; + uint32_t type = 0; + uint32_t ulfreeram = 0; + + if (logid >= MAX_LOG_CFG_NUM || logid < 0) + { + return OSP_ERROR; + } + + osp_get_msgtype_name(msg_type, msg_name); + type = osp_get_msgtype_id(msg_type); + if (log_file_cfg_table[logid][type].valied == 0) + { + return OSP_ERROR; + } + + p_log_file_cfg = log_file_cfg_table; + //p_log_file_cfg = &log_file_cfg_table[0][0]; + p_log_file_cfg[logid][type].cur_sum_len += len; + + osp_get_current_time(); + UCP_PRINT_LOG("osp_update_log logid:%d type:0x%x cur_sum_len:%u max_file_size_M:%u !\n", logid,type, p_log_file_cfg[logid][type].cur_sum_len, p_log_file_cfg[logid][type].max_file_size_M); + + /*鍒ゆ柇褰撳墠绯荤粺鏄惁杩樻湁瓒冲绌洪棿*/ + ulfreeram = osp_get_freeram(); + if((ulfreeram <= FREE_RAM_SIZE) || (1 == g_ucFflushEnable)) + { + sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, (p_log_file_cfg[logid][type].cur_file_idx & 0x7)+1, logid, msg_name); + system(name); + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x ulfreeram:%u g_ucFflushEnable:%u name:%s\n", __LINE__, logid, type, ulfreeram, g_ucFflushEnable, name); + osp_log_cfg_reload(); + } + + if (p_log_file_cfg[logid][type].cur_sum_len >= p_log_file_cfg[logid][type].max_file_size_M) + { + p_log_file_cfg[logid][type].cur_sum_len = 0; + p_log_file_cfg[logid][type].cur_file_idx++; + + file_idx = p_log_file_cfg[logid][type].cur_file_idx & 0x7; + if(p_log_file_cfg[logid][type].cur_file_idx >= p_log_file_cfg[logid][type].max_file_num) + { + sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, file_idx, logid, msg_name); + //sprintf(name, "%s-%d-%s-%u-%u-%s.log", p_log_file_cfg[logid][type].logname, getpid(), g_time_now, p_log_file_cfg[logid][type].cur_file_idx, logid, msg_name); + system(name); + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x remove name:%s\n", __LINE__, logid, type, name); + } + + /*鍒ゆ柇褰撳墠鏂囦欢鏄惁鍚堟硶鏂囦欢*/ + if(NULL == p_log_file_cfg[logid][type].file) + { + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:%d file:%p\n", __LINE__, logid, type, p_log_file_cfg[logid][type].file); + return OSP_ERROR; + } + + fclose(p_log_file_cfg[logid][type].file); + + osp_get_file_path(p_log_file_cfg[logid][type].logname, path); + + if (access(path, F_OK) != 0) + { + osp_mkdirs(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + sprintf(name, "%s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, file_idx, logid, msg_name); + //sprintf(name, "%s-%d-%s-%u-%u-%s.log", p_log_file_cfg[logid][type].logname, getpid(), g_time_now, p_log_file_cfg[logid][type].cur_file_idx, logid, msg_name); + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x name:%s\n", __LINE__, logid, type, name); + + /*浜岃繘鍒舵牸寮*/ + if(0x61 == msg_type) + { + p_log_file_cfg[logid][type].file = fopen(name, "wb+"); + /*鍒ゆ柇鏂囦欢鏄惁鍒涘缓鎴愬姛*/ + if(p_log_file_cfg[logid][type].file <= 0) + { + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x name:%s file create fail!\n", __LINE__, logid, type, name); + return OSP_ERROR; + } + } + else + { + p_log_file_cfg[logid][type].file = fopen(name, "w+"); + /*鍒ゆ柇鏂囦欢鏄惁鍒涘缓鎴愬姛*/ + if(p_log_file_cfg[logid][type].file <= 0) + { + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x name:%s file create fail!\n", __LINE__, logid, type, name); + return OSP_ERROR; + } + } + + } + else + { + if (NULL == p_log_file_cfg[logid][type].file) + { + osp_get_file_path(p_log_file_cfg[logid][type].logname, path); + + if (access(path, F_OK) != 0) + { + osp_mkdirs(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + sprintf(name, "%s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, p_log_file_cfg[logid][type].cur_file_idx, logid, msg_name); + //sprintf(name, "%s-%d-%s-%u-%u-%s.log", p_log_file_cfg[logid][type].logname, getpid(), g_time_now, p_log_file_cfg[logid][type].cur_file_idx, logid, msg_name); + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x name:%s\n", __LINE__, logid, type, name); + + /*浜岃繘鍒舵牸寮*/ + if(0x61 == msg_type) + { + p_log_file_cfg[logid][type].file = fopen(name, "wb+"); + /*鍒ゆ柇鏂囦欢鏄惁鍒涘缓鎴愬姛*/ + if(p_log_file_cfg[logid][type].file <= 0) + { + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x name:%s file create fail!\n", __LINE__, logid, type, name); + return OSP_ERROR; + } + } + else + { + p_log_file_cfg[logid][type].file = fopen(name, "w+"); + /*鍒ゆ柇鏂囦欢鏄惁鍒涘缓鎴愬姛*/ + if(p_log_file_cfg[logid][type].file <= 0) + { + UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x name:%s file create fail!\n", __LINE__, logid, type, name); + return OSP_ERROR; + } + } + } + } + + return OSP_OK; +} + + +void osp_log_output(unsigned char level, const char *fmt, ...) +{ + char acstr[256] = {0}; + va_list st_va_list; + + if (level > guc_print_level) + { + return; + } + + va_start(st_va_list, fmt); + vsprintf((char *)acstr, fmt, st_va_list); + va_end(st_va_list); + + printf("%s", acstr); + + return; +} + + + +OSP_STATUS osp_dbg_log_ext(char *pbuf, uint32_t buflen, int32_t LogId) +{ +#if 0 + Osp_Msg_Head *pNMsg = NULL; + + OSP_RTCTIME osptime; + char datebuf[100] = {0}; + + if ((pbuf == NULL) || (buflen == 0) || (LogId < 0) || (LogId >= MAX_LOG_CFG_NUM) || + (log_file_cfg_table[LogId].valied == 0)) + { + osp_debug_out_with_time(RUN_DEBUG_LEVEL, "osp_dbg_log_ext arg err!\r\n"); + return -1; + } + + if (log_file_cfg_table[LogId].with_time) + { + osp_get_rtc_time(&osptime); + sprintf((char *)datebuf, \ + "[%04d/%02d/%02d-%02d:%02d:%02d:%02d]", \ + osptime.year, osptime.month, osptime.day, \ + osptime.hour, osptime.minute, osptime.second, osptime.usecond); + + pNMsg = osp_alloc_msg(strlen(datebuf) + buflen); + if (pNMsg == NULL) + { + return -1; + } + + pNMsg->MsgType = OSP_STR_LOG; + pNMsg->MsgSize = strlen(datebuf) + buflen; + pNMsg->SrcId = LogId; + pNMsg->DstId = DbgLogTask; + + memcpy(MSG_HEAD_TO_COMM(pNMsg), datebuf, strlen(datebuf)); + memcpy(MSG_HEAD_TO_COMM(pNMsg) + strlen(datebuf), pbuf, buflen); + + } + else + { + pNMsg = osp_alloc_msg(buflen); + if (pNMsg == NULL) + { + return -1; + } + + pNMsg->MsgType = OSP_STR_LOG; + pNMsg->MsgSize = buflen; + pNMsg->SrcId = LogId; + pNMsg->DstId = DbgLogTask; + + memcpy(MSG_HEAD_TO_COMM(pNMsg), pbuf, buflen); + + } + + osp_send_msg(pNMsg); +#endif + return 0; +} + +OSP_STATUS osp_dbg_log(char *pbuf, uint32_t buflen) +{ + return osp_dbg_log_ext(pbuf, buflen, osp_base_logid); +} + +OSP_STATUS osp_close_log_file(FILE *file) +{ + if (fclose(file)) + { + return OSP_ERROR; + } + + return OSP_OK; +} + +uint32_t osp_get_freeram(void) +{ + uint32_t ulfreeram = 0; + struct sysinfo st_info; + + if(0 == sysinfo(&st_info)) + { + ulfreeram = st_info.freeram; + } + + return ulfreeram; +} + + +/*榛樿璧峰绔彛鍙穚ortIDStart=32768锛屼簩杩涘埗log鐨刾ortID = portIDStart + core_id * 2锛涘瓧绗︿覆log鐨刾ortID = portIDStart + core_id * 2 + 1锛 + 骞冲彴缃戝彛log榛樿绔彛鍙蜂负32800锛寀l_port = ul_platform_port + 2*uc_src_core_id;*/ +uint32_t osp_get_ape_port(osp_sw_msg_info_t *pMsg) +{ + uint32_t ul_port = 0; + uint32_t ul_start_port = 32768; + uint32_t ul_platform_port = 32800; + uint8_t uc_msg_type = 0; /* 娑堟伅绫诲瀷 */ + uint8_t uc_src_core_id = 0; /* 婧愭牳ID */ + + uc_src_core_id = pMsg->u8CoreId; + uc_msg_type = pMsg->u8PktType; + + switch (uc_msg_type) + { + case OSP_BIN_LOG: + ul_port = ul_start_port + 2*uc_src_core_id; + break; + case OSP_STR_LOG: + ul_port = ul_start_port + 2*uc_src_core_id + 1; + break; + case OSP_PLATFORM_LOG: + ul_port = ul_platform_port + 2*uc_src_core_id; + break; + default: + break; + } + + UCP_PRINT_LOG("osp_get_ape_port ul_port:%u uc_src_core_id:%u uc_msg_type:0x%x\n", ul_port, uc_src_core_id, uc_msg_type); + + return ul_port; +} + +void osp_net_log_proc(char *pMsg, uint32_t len, uint32_t port) +{ + int32_t udpid = 0; + + udpid = osp_get_txudp((char *)&gst_server_log.ip, port); + + if (osp_check_udpid(udpid)) + { + net_log_txudp_id = udpid; + //UCP_PRINT_LOG("osp_net_log_proc line:%d udpid:[%u] port:[%u]\n", __LINE__, udpid, port); + } + else + { + net_log_txudp_id = osp_create_txucp(port, (char *)&gst_server_log.ip); + //UCP_PRINT_LOG("osp_net_log_proc line:%d udpid:[%u] port:[%u]\n", __LINE__, net_log_txudp_id, port); + } + + //UCP_PRINT_LOG("osp_net_log_proc line:%d len[%u] udp_id[%u] ip[%s] port[%u]\n", __LINE__, len, net_log_txudp_id, gst_server_log.ip, port); + + osp_udp_send(pMsg, len, net_log_txudp_id); + + return; +} + +OSP_STATUS osp_write_diaglog(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type) +{ + + int32_t ret = 0; + static FILE *file = NULL; + uint32_t fd; + + if (NULL == g_OspLogSem) + { + return OSP_ERROR; + } + + if ((NULL == pbuf) || (0 == len)) + { + return OSP_ERROR; + } + + osp_sem_take(g_OspLogSem,-1); + + UCP_PRINT_LOG("osp_write_diaglog len[%u] logid[%u] msg_type[0x%x]\n", len, logid, msg_type); + + ret = osp_update_log(len, logid, msg_type); + if (ret < 0) + { + osp_sem_give(g_OspLogSem); + return OSP_ERROR; + } + + file = osp_get_log_file(logid, msg_type); + if (NULL == file) + { + osp_sem_give(g_OspLogSem); + return OSP_ERROR; + } + + ret = fwrite(pbuf, sizeof(char), len, file); + if(ret <= 0) + { + UCP_PRINT_LOG("fwrite error ret:%d\n", ret); + fclose(file); + osp_sem_give(g_OspLogSem); + return OSP_ERROR; + } + + ret = fflush(file); + if(OSP_OK != ret) + { + UCP_PRINT_LOG("fflush error ret:%d\n", ret); + g_ucFflushEnable = 1; + } + else + { + UCP_PRINT_LOG("fflush ok ret:%d\n", ret); + g_ucFflushEnable = 0; + } + + fd = fileno(file); + ret = fsync(fd); + if(OSP_OK != ret) + { + UCP_PRINT_LOG("fsync error ret:%d\n", ret); + fclose(file); + osp_sem_give(g_OspLogSem); + return OSP_ERROR; + } + + osp_sem_give(g_OspLogSem); + + return OSP_OK; +} + +OSP_STATUS osp_arm_net_log_proc(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type) +{ + Osp_Ape_Msg_Head *pmsg_head = NULL; + + if ((NULL == pbuf) || (0 == len)) + { + return OSP_ERROR; + } + + pmsg_head = (Osp_Ape_Msg_Head *)malloc(1024); + if(NULL == pmsg_head) + { + UCP_PRINT_ERROR("osp_arm_log_proc ptmp is null\n"); + return OSP_ERROR; + } + + pmsg_head->src_core_id = logid; + pmsg_head->msg_size = APE_MSG_HEAD_SIZE + len; + pmsg_head->msg_type = msg_type; + + memcpy((pmsg_head+APE_MSG_HEAD_SIZE), pbuf, len); + + //osp_net_log_proc(pmsg_head); + + free(pmsg_head); + + return OSP_OK; +} + +OSP_STATUS osp_arm_log_proc(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type) +{ + uint32_t ul_port = 0; + + if ((NULL == pbuf) || (0 == len)) + { + return OSP_ERROR; + } + + switch (msg_type) + { + case OSP_BIN_LOG: + ul_port = 32768 + 2*logid; + break; + case OSP_STR_LOG: + ul_port = 32768 + 2*logid + 1; + break; + default: + break; + } + + /*get default cfg from file*/ + //osp_log_mode_get(); + + switch(g_ulArmLogMode) + { + case 0: + osp_write_diaglog(pbuf, len, logid, msg_type); + break; + case 1: + //g_ulArmNetLogRxNum++; + osp_net_log_proc(pbuf, len, ul_port); + //g_ulArmNetLogTxNum++; + break; + case 2: + osp_log_print((osp_sw_msg_info_t *)pbuf);/*ape缁撴灉杈撳嚭鍒板睆骞*/ + break; + default: + break; + } + + return OSP_OK; +} + +OSP_STATUS osp_ape_log_proc(osp_sw_msg_info_t *pMsg) +{ + uint32_t port = 0; + + if (NULL == pMsg) + { + return OSP_ERROR; + } + + port = osp_get_ape_port(pMsg); + + switch(g_ulApeLogMode) + { + case 0: + osp_write_diaglog((char*)pMsg->i8Data, pMsg->u16DataLen, pMsg->u8CoreId, pMsg->u8PktType); + break; + case 1: + osp_net_log_proc((char*)pMsg->i8Data, pMsg->u16DataLen, port); + break; + case 2: + osp_log_print(pMsg);/*ape缁撴灉杈撳嚭鍒板睆骞*/ + break; + default: + break; + } + + return OSP_OK; +} + +void osp_platform_log_proc(osp_sw_msg_info_t *pMsg) +{ + uint32_t port = 0; + + if (NULL == pMsg) + { + return; + } + + port = osp_get_ape_port(pMsg); + + switch(g_ucPlatformMode) + { + case 0: + osp_write_diaglog((char*)pMsg->i8Data, pMsg->u16DataLen, pMsg->u8CoreId, pMsg->u8PktType); + break; + case 1: + osp_net_log_proc((char*)pMsg->i8Data, pMsg->u16DataLen, port); + break; + case 2: + osp_log_print(pMsg);/*ape缁撴灉杈撳嚭鍒板睆骞*/ + break; + default: + break; + + } + + return; +} + +void osp_log_print(osp_sw_msg_info_t *pMsg) +{ + uint32_t i = 0; + + if (NULL == pMsg) + { + return; + } + + if(OSP_BIN_LOG == pMsg->u8PktType) + { + for (i = 0; i < pMsg->u16DataLen ;i++) + { + printf("%02x ", (uint8_t)pMsg->i8Data[i]); + + if ((i & 0x7) == 0x7) + { + printf("\n"); + } + } + } + else + { + write(STDOUT_FILENO, (char*)pMsg->i8Data, pMsg->u16DataLen);/*ape缁撴灉杈撳嚭鍒板睆骞*/ + } + + return; +} + + +bool osp_ip_is_null(char *ip) +{ + if(NULL == ip) + { + strcpy((char *)&gst_server_log.ip, "192.168.20.18"); + return true; + } + + return false; +} + +bool osp_path_is_null(char *path) +{ + if(NULL == path) + { + strcpy((char *)&gst_server_log.path, "./log/"); + return true; + } + + return false; +} + + +int8_t osp_log_mode_init() +{ + int8_t ret = 0; + FILE *fp = NULL; + + if (access(LOG_MODE_PATH, F_OK) != 0) + { + osp_mkdirs("./server/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + osp_mkdirs("./log/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + + fp = fopen(LOG_MODE_PATH, "w+"); + if (fp < 0) + { + UCP_PRINT_ERROR("osp_log_mode_init file open failure \n"); + return ret; + } + + memcpy(gst_server_log.ip, "192.168.20.18", 15); + strcpy((char *)gst_server_log.path, "./log/"); + gst_server_log.ulport = 32768; + + ret = fprintf(fp,"ip:%s\r\nport:%u\napelog:%u\narmlog:%u\nlogpath:%s", \ + gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, gst_server_log.path); + if(ret < 0) + { + UCP_PRINT_ERROR("fwrite error ret:%d\n", ret); + fclose(fp); + return ret; + } + + fflush(fp); + fclose(fp); + } + + return ret; +} + +int8_t osp_log_mode_cfg() +{ + int8_t ret = 0; + FILE *fp = NULL; + + if (access("./server", F_OK) != 0) + { + osp_mkdirs("./server", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + fp = fopen(LOG_MODE_PATH, "w+"); + if (fp < 0) + { + UCP_PRINT_ERROR("osp_log_mode_cfg file open failure \n"); + return ret; + } + + ret = fprintf(fp,"ip:%s\r\nport:%u\napelog:%u\narmlog:%u\nlogpath:%s", \ + gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, \ + gst_server_log.path); + if(ret < 0) + { + UCP_PRINT_ERROR("osp_log_mode_cfg fprintf error ret:%d\n", ret); + fclose(fp); + return ret; + } + + fflush(fp); + fclose(fp); + + return ret; +} + + +void osp_cfg_default_log_mode() +{ + + memset(gst_server_log.ip, 0, 16); + memset(gst_server_log.path, 0, 128); + + strcpy((char *)gst_server_log.ip, "192.168.20.18"); + strcpy((char *)gst_server_log.path, "./log/"); + + gst_server_log.ulport = 32768; + g_ulApeLogMode = 0; + g_ulArmLogMode = 0; + + return; +} + + +void osp_log_mode_get() +{ + FILE *fp = NULL; + char *ip = NULL; + char *path = NULL; + char buf[128] = {0}; + + /*閰嶇疆gst_server_log榛樿鍊*/ + osp_cfg_default_log_mode(); + + fp = fopen(LOG_MODE_PATH, "r"); + if (NULL == fp) + { + UCP_PRINT_ERROR("osp_log_mode_get file open failure \n"); + return; + } + + while(fgets(buf, 128, fp)) + { + if(strstr(buf, "ip:")) + { + memset(gst_server_log.ip, 0, 16); + ip = strtok((char *)(buf+3), "\r\n"); + if(false == osp_ip_is_null(ip)) + { + strcpy((char *)gst_server_log.ip, ip); + } + continue; + } + if(strstr(buf, "port:")) + { + gst_server_log.ulport = (uint32_t)atoi(buf+5); + //strncpy((char *)&gst_server_log.ulport, buf+5, 2); + continue; + } + if(strstr(buf, "apelog:")) + { + g_ulApeLogMode = (uint32_t)(buf[7] - '0'); + continue; + } + if(strstr(buf, "armlog:")) + { + g_ulArmLogMode = (uint32_t)(buf[7] - '0'); + continue; + } + if(strstr(buf, "logpath:")) + { + memset(gst_server_log.path, 0, 128); + path = strtok((char *)(buf+8), "\r\n"); + if(false == osp_path_is_null(path)) + { + strcpy((char *)gst_server_log.path, path); + } + continue; + } + } + + /*UCP_PRINT_ERROR("ip:%s port:%u g_ulApeLogMode:%u g_ulArmLogMode:%u\n",\ + gst_server_log.ip,gst_server_log.ulport,\ + g_ulApeLogMode, g_ulArmLogMode);*/ + + fclose(fp); + + return; +} + +uint32_t osp_filter_char(char *str, char c) +{ + uint8_t i = 0; + uint32_t ulret = 0; + + while(str[i] != '\0') + { + if(str[i] == c) + { + ulret = (uint32_t)(str[++i] - '0'); + printf("%d\n", ulret); + break; + } + i++; + } + + return ulret; +} + +void osp_dbg_log_main(osp_sw_msg_info_t *pMsg) +{ + if (NULL == pMsg) + { + return; + } + + switch (pMsg->u8PktType) + { + case OSP_STR_LOG: + case OSP_BIN_LOG: + osp_ape_log_proc(pMsg); + break; + case OSP_PLATFORM_LOG: + osp_platform_log_proc(pMsg); + break; + default: + break; + } + + return; +} + + +void osp_log_init(void) +{ + uint32_t i = 0; + uint32_t j = 0; + + /*create arm銆乤pe log cfg file*/ + osp_log_mode_init(); + + /*get default cfg from cfg file*/ + osp_log_mode_get(); + + osp_log_msg_create(); + + g_OspLogSem = osp_get_init_mem(sizeof(lx_sem_t)); + osp_semsm_create(g_OspLogSem); + + srand(time(NULL)); + log_rand = rand(); + + for (i = 0; i < MAX_LOG_CFG_NUM; i++) + { + for(j = 0; j< 4; j++) + { + log_file_cfg_table[i][j].valied = 0; + log_file_cfg_table[i][j].max_file_size_M = 0; + log_file_cfg_table[i][j].max_file_num = 0; + log_file_cfg_table[i][j].with_time = 0; + log_file_cfg_table[i][j].key = 0; + } + + } + + osp_base_logid = osp_create_log((char *)gst_server_log.path, MAX_FILE_SIZE, MAX_FILE_NUM, 1); + + return; +} + +void osp_log_cfg_reload() +{ + uint32_t i = 0; + uint32_t j = 0; + + for (i = 0; i < MAX_LOG_CFG_NUM; i++) + { + for(j = 0; j< 4; j++) + { + log_file_cfg_table[i][j].valied = 1; + log_file_cfg_table[i][j].key = 0; + log_file_cfg_table[i][j].cur_sum_len = 0; + log_file_cfg_table[i][j].cur_file_idx = 0; + log_file_cfg_table[i][j].file = NULL; + } + + } + + return; +} + +int32_t osp_fflush_all_logfile(void) +{ + uint32_t i = 0; + uint32_t j = 0; + FILE *file; + uint32_t fd; + + for (i = 0; i < MAX_LOG_CFG_NUM; i++) + { + for(j=0; j<4; j++) + { + file = osp_get_log_file(i, j); + if (file) + { + fflush(file); + fd = fileno(file); + fsync(fd); + } + } + } + return 0; + +} + +/* 鏍规嵁鏈鏂伴渶姹傦紝Log鐨勫鐞嗘満鍒舵敼鍥1.0鐨勭姸鎬侊紝鍦ㄦ帴鍙楀洖璋冨嚱鏁颁腑鐩存帴澶勭悊 */ +#if 1 +#define OSP_LOG_MSG_Q_KEY (0x1011) +#define OSP_LOG_SEND_TYPE (0xFA) /* 鍙戦佹秷鎭椂鐨勬秷鎭被鍨 */ +int32_t gint_log_msg_id = -1; + +uint8_t osp_log_msg_create(void) +{ + gint_log_msg_id = msgget(OSP_LOG_MSG_Q_KEY, IPC_CREAT); + if (-1 == gint_log_msg_id) + { + UCP_PRINT_ERROR("[osp_log_msg_create]: msgget return error\r\n"); + return 1; + } + UCP_PRINT_LOG("[osp_log_msg_create]: gint_log_msg_id = %d\r\n", gint_log_msg_id); + return 0; +} + +int32_t osp_log_msg_get_id(void) +{ + return gint_log_msg_id; +} + +int32_t osp_log_msg_send(int32_t i32que_id, uint8_t *pu8msg_add, uint32_t u32msg_size) +{ + int32_t i32_ret = 0; + osp_log_msg_info_t* plog_msg = NULL; + + if (NULL == pu8msg_add) + { + UCP_PRINT_ERROR("[osp_log_msg_send]: buffer addr is NULL!!!\r\n"); + return -1; + } + //printf("send: que_id = %d, addr = %p, size = %d\r\n", i32que_id, pu8msg_add, u32msg_size); + + plog_msg = (osp_log_msg_info_t *)pu8msg_add; + plog_msg->i64msg_type = OSP_LOG_SEND_TYPE; + i32_ret = msgsnd(i32que_id, pu8msg_add, (u32msg_size - sizeof(int64_t)), IPC_NOWAIT); + if (0 != i32_ret) + { + UCP_PRINT_LOG("[osp_log_msg_send]: msgsnd return err(%d)\r\n", i32_ret); + } + return u32msg_size; +} + +int32_t osp_log_msg_recv(int32_t i32que_id, uint8_t *pu8msg_add, uint32_t u32max_size) +{ + int32_t i32_ret = 0; + osp_log_msg_info_t* plog_msg = NULL; + + if (NULL == pu8msg_add) + { + UCP_PRINT_ERROR("[osp_log_msg_recv]: buffer addr is NULL!!!\r\n"); + return -1; + } + + UCP_PRINT_LOG("[osp_log_msg_recv]: i32que_id(%d), size = %d\r\n", i32que_id, u32max_size); + + plog_msg = (osp_log_msg_info_t*)pu8msg_add; + i32_ret = msgrcv(i32que_id, pu8msg_add, (u32max_size-sizeof(uint64_t)), 0, 0); + if (-1 == i32_ret) + { + UCP_PRINT_LOG("[osp_log_msg_recv]: msgrcv return err(%d) %s\r\n", i32_ret, strerror(errno)); + return -2; + } + if (OSP_LOG_SEND_TYPE != plog_msg->i64msg_type) + { + UCP_PRINT_ERROR("[osp_log_msg_recv]: msg_type err(%ld)\r\n", plog_msg->i64msg_type); + return -3; + } + return (i32_ret + sizeof(int64_t)); +} + +int32_t osp_log_msg_proc(uint8_t *pu8msg_add, uint32_t u32msg_size) +{ + MsgTransferHeader_t *pmsg_transfer_header = NULL; + osp_sw_msg_info_t *pstsw_msg_info = NULL; + + uint8_t u8msg_num = 0; + uint32_t u32msg_type = 0; + uint32_t u32log_size = 0; + uint32_t u32log_num = 0; + uint32_t u32msg_cur_size = 0; + + if (NULL == pu8msg_add) + { + UCP_PRINT_ERROR("[osp_log_msg_proc]: msg_addr is NULL!!!\r\n"); + return -1; + } + + pmsg_transfer_header = (MsgTransferHeader_t*)pu8msg_add; + + u8msg_num = pmsg_transfer_header->numMsg; + u32msg_cur_size += 4; /* msgType */ + //printf("[osp_log_msg_proc]: u8msg_num = %d\r\n", u8msg_num); + + for (uint8_t u8msg_loop = 0; u8msg_loop < u8msg_num; u8msg_loop++) + { + u32msg_type = *(uint32_t*)(pu8msg_add+u32msg_cur_size); + //printf("[osp_log_msg_proc]: u32msg_type = 0x%x\r\n", u32msg_type); + + if (MSG_TRANSFER_LOG_MSG_TYPE == u32msg_type) + { + /* Log */ + u32msg_cur_size += 8; /* log_size */ + u32log_size = *(uint32_t*)(pu8msg_add+u32msg_cur_size); + u32log_num = u32log_size/SPU_LOG_CLIENT_BUF_SIZE; + u32msg_cur_size += 4; + + for (uint16_t u16loop = 0; u16loop < u32log_num; u16loop++) + { + pstsw_msg_info = (osp_sw_msg_info_t *)(pu8msg_add + u32msg_cur_size + u16loop*SPU_LOG_CLIENT_BUF_SIZE); + + //printf("i8Data = %p, len = %d, coreid = %d, type = %d\r\n", pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType); + //osp_write_diaglog((char*)pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType); + osp_dbg_log_main(pstsw_msg_info); + } + u32msg_cur_size += u32log_size; + } + else if (MSG_TRANSFER_SHELL_MSG_TYPE == u32msg_type) + { + UCP_PRINT_LOG("SHELL \r\n"); + /* Shell */ + u32msg_cur_size += 8; /* log_size */ + u32log_size = *(uint32_t*)(pu8msg_add+u32msg_cur_size); + u32msg_cur_size += 4; + u32msg_cur_size += u32log_size; + } + else + { + UCP_PRINT_LOG("OAM \r\n"); + /* OAM */ + u32msg_cur_size += 8; /* log_size */ + u32log_size = *(uint32_t*)(pu8msg_add+u32msg_cur_size); + u32msg_cur_size += 4; + u32msg_cur_size += u32log_size; + } + } + return 0; +} + +uint32_t rx_callback_oam(const char* buf,uint32_t payloadSize) +{ + osp_log_msg_info_t stosp_log_msg; + int32_t i32log_que_id = osp_log_msg_get_id(); + + memset(&stosp_log_msg, 0, sizeof(stosp_log_msg)); + stosp_log_msg.pu8msg_addr = (uint8_t *)buf; + stosp_log_msg.u32msg_size = payloadSize; + + //UCP_PRINT_LOG("oam recv: buf = %p, size = %d\r\n", buf, payloadSize); + + osp_log_msg_send(i32log_que_id, (uint8_t*)&stosp_log_msg, sizeof(stosp_log_msg)); + + return payloadSize; +} + + +uint64_t osp_oam_msg_proc_task(void) +{ + osp_log_msg_info_t stosp_log_msg; + int32_t i32_msg_id = osp_log_msg_get_id(); + static uint32_t su32LogCnt = 0; + + ++su32LogCnt; + //printf("LogTask Enter >>> %d\r\n", su32LogCnt); + //while(1) + //{ + memset(&stosp_log_msg, 0, sizeof(stosp_log_msg)); + if (0 > osp_log_msg_recv(i32_msg_id, (uint8_t*)&stosp_log_msg, sizeof(stosp_log_msg))) + { + UCP_PRINT_ERROR("[osp_oam_msg_proc_task]: osp_log_msg_recv return err\r\n"); + //continue; + return OSP_ERROR; + } + UCP_PRINT_LOG("task: addr = %p ,size = %d\r\n", stosp_log_msg.pu8msg_addr, stosp_log_msg.u32msg_size); + osp_log_msg_proc(stosp_log_msg.pu8msg_addr, stosp_log_msg.u32msg_size); + //} + return OSP_OK; +} +#endif + +int32_t osp_create_oam_msg_task(uint8_t cpu, uint8_t pri) +{ + OSP_TASKMSG_REG task_reg_tabl; + + memset(&task_reg_tabl, 0, sizeof(task_reg_tabl)); + task_reg_tabl.TaskId = OspDbgLog; + task_reg_tabl.TaskPri = RT_NOMSG_PRI(pri); + task_reg_tabl.Init = NULL; + task_reg_tabl.MainLoop = (OSP_FUNCPTR)osp_oam_msg_proc_task; + task_reg_tabl.Cpu = cpu; + + return osp_regtask(&task_reg_tabl); +} + + +#if 0 +uint32_t rx_callback_oam(const char* buf,uint32_t payloadSize) +{ + MsgTransferHeader_t *pmsg_transfer_header = NULL; + osp_sw_msg_info_t *pstsw_msg_info = NULL; + + uint8_t u8msg_num = 0; + uint32_t u32msg_type = 0; + uint32_t u32log_size = 0; + uint32_t u32log_num = 0; + uint32_t u32msg_cur_size = 0; + + if (NULL == buf) + { + UCP_PRINT_ERROR("[osp_log_msg_proc]: msg_addr is NULL!!!\r\n"); + return -1; + } + + pmsg_transfer_header = (MsgTransferHeader_t*)buf; + + u8msg_num = pmsg_transfer_header->numMsg; + u32msg_cur_size += 4; /* msgType */ + //printf("[osp_log_msg_proc]: u8msg_num = %d\r\n", u8msg_num); + + for (uint8_t u8msg_loop = 0; u8msg_loop < u8msg_num; u8msg_loop++) + { + u32msg_type = *(uint32_t*)(buf+u32msg_cur_size); + //printf("[osp_log_msg_proc]: u32msg_type = 0x%x\r\n", u32msg_type); + + if (MSG_TRANSFER_LOG_MSG_TYPE == u32msg_type) + { + /* Log */ + u32msg_cur_size += 8; /* log_size */ + u32log_size = *(uint32_t*)(buf+u32msg_cur_size); + u32log_num = u32log_size/SPU_LOG_CLIENT_BUF_SIZE; + u32msg_cur_size += 4; + + for (uint16_t u16loop = 0; u16loop < u32log_num; u16loop++) + { + pstsw_msg_info = (osp_sw_msg_info_t *)(buf + u32msg_cur_size + u16loop*SPU_LOG_CLIENT_BUF_SIZE); + + //printf("i8Data = %p, len = %d, coreid = %d, type = %d\r\n", pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType); + //osp_write_diaglog((char*)pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType); + osp_dbg_log_main(pstsw_msg_info); + } + u32msg_cur_size += u32log_size; + } + else if (MSG_TRANSFER_SHELL_MSG_TYPE == u32msg_type) + { + UCP_PRINT_LOG("SHELL \r\n"); + /* Shell */ + u32msg_cur_size += 8; /* log_size */ + u32log_size = *(uint32_t*)(buf+u32msg_cur_size); + u32msg_cur_size += 4; + u32msg_cur_size += u32log_size; + } + else + { + UCP_PRINT_LOG("OAM \r\n"); + /* OAM */ + u32msg_cur_size += 8; /* log_size */ + u32log_size = *(uint32_t*)(buf+u32msg_cur_size); + u32msg_cur_size += 4; + u32msg_cur_size += u32log_size; + } + } + return u32msg_cur_size; +} +#endif + diff --git a/osp/src/ospMem.c b/osp/src/ospMem.c new file mode 100644 index 0000000..799ef08 --- /dev/null +++ b/osp/src/ospMem.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "osp.h" + +char *OspMemBaseOrg; +char *OspMemBase; +OSP_STATUS osp_mem_init(void) +{ +// int fd; +// fd=open("./ospmem",O_CREAT|O_RDWR, 0777); +// ftruncate(fd,OSP_MEM_SIZE); +// OspMemBase=mmap(0,OSP_MEM_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); + + OspMemBase = malloc(OSP_MEM_SIZE); + if (NULL == OspMemBase) + { + return OSP_ERROR; + } + + OspMemBaseOrg = OspMemBase; + OspMemBase = (char *)(OSP_ROUND_UP(OspMemBase, 32)); + + return OSP_OK; +} + +void osp_print_tatal_mem(void) +{ + osp_debug_out_with_time(RUN_DEBUG_LEVEL, "OspMemBase = %#lx,Osp Use Total Mem is %dKB\n", (uint64_t)OspMemBase,(OspMemBase - OspMemBaseOrg) >> 10); +} + +char *osp_alloc_mem(uint32_t Len) +{ + char *p = osp_get_buffer(Len, BUF_FOR_MEMORY, BUFFER_NORMAL_LEVEL); + if (NULL == p) + { + return NULL; + } + osp_atomic_inc((int32_t *)&TASK_MEM_ALLOCCNT(CURRENT_TASKID)); + return p; + +} + +void osp_free_mem(char *pbuf) +{ + osp_atomic_inc((int32_t *)&TASK_MEM_FREECNT(CURRENT_TASKID)); + osp_free_buffer(pbuf); +} + +char *osp_get_init_mem(int32_t len) +{ + char *p; + + p = OspMemBase; + OspMemBase += len; + OspMemBase = (char *)OSP_ROUND_UP(OspMemBase, 32); + + osp_assert((OspMemBase - OspMemBaseOrg) < OSP_MEM_SIZE); + + return p; +} + + + diff --git a/osp/src/ospMsg.c b/osp/src/ospMsg.c new file mode 100644 index 0000000..9e0a8b2 --- /dev/null +++ b/osp/src/ospMsg.c @@ -0,0 +1,360 @@ +#include +#include +#include + +#include + +#include "osp.h" +#include "ospMsg.h" + +#define TIME_MSG_NUM 512 //origin: 8192 +#define TIME_MSG_MSK 511 //origin: 8191 + + +#define TIMER_MSG_SIZE sizeof(Osp_Timer_Msg_Block) + +/*timer msg has msg_head only*/ +Osp_Timer_Msg_Block *TimerMsg[TIME_MSG_NUM] = {0}; + +char *gOspMsgQue = 0; + +OSP_STATUS osp_msg_que_init(void) +{ +// int ret; + int32_t tasknum = osp_get_task_num(); + int32_t i; +// int TaskId; + + gOspTask = (OSP_TASKCB *)osp_get_init_mem(OSP_ROUND_UP(sizeof(OSP_TASKCB), 32) * tasknum); + gOspMsgQue = osp_get_init_mem((OSP_ROUND_UP(OSP_MSG_QUE_SIZE, 32)) * tasknum); + TimerMsg[0] = (Osp_Timer_Msg_Block *)osp_get_init_mem(TIME_MSG_NUM * OSP_ROUND_UP(sizeof(TIMER_MSG_SIZE), 32)); + + + + for (i = 0; i < TIME_MSG_NUM; i++) + { + TimerMsg[i] = (Osp_Timer_Msg_Block *)((uint64_t)TimerMsg[0] + i * OSP_ROUND_UP(sizeof(TIMER_MSG_SIZE), 32)); + } + + + if (0 == g_ProcessId) + { + memset(gOspTask, 0, (OSP_ROUND_UP(sizeof(OSP_TASKCB), 32) * tasknum)); + for (i = 0; i < tasknum; i++) + { + gOspTask[i].MsgQOffset = OSP_ROUND_UP(OSP_MSG_QUE_SIZE, 32) * i; + } + } + return OSP_OK; +} + +int32_t osp_create_msgq(Osp_MsgQ_Tcb *que, char *name) +{ + return osp_create_softque(&OSP_MSGQ_QUE(que), OSP_MEGQ_DEP, name); +} + +int32_t osp_msg_enque(uint64_t value, Osp_MsgQ_Tcb *que) +{ + return osp_soft_que_enque(value, &OSP_MSGQ_QUE(que), QUE_NEED_WAKE); + +} + +int32_t osp_msg_deque(uint64_t *pvalue, Osp_MsgQ_Tcb *que) +{ + return osp_softque_deque(pvalue, &OSP_MSGQ_QUE(que), QUE_ISBLOCK); + +} + +int32_t osp_msg_dequetry(uint64_t *pvalue, Osp_MsgQ_Tcb *que) +{ + return osp_softque_dequetry(pvalue, &OSP_MSGQ_QUE(que)); +} + + +int32_t osp_msg_deque_timeout(uint64_t *pvalue, Osp_MsgQ_Tcb *que, uint32_t timeout) +{ + return osp_softque_dequeTimeOut(pvalue, &OSP_MSGQ_QUE(que), timeout); +} + + + + + +Osp_Msg_Head *osp_alloc_msg(uint32_t Len) +{ + Osp_Msg_Head *pMsg; + osp_assert(Len > 0); + pMsg = osp_get_buffer(Len + MSG_HEAD_SIZE, BUF_FOR_MSG, BUFFER_NORMAL_LEVEL); + if (pMsg) + { + TASK_MSG_ALLOCCNT(CURRENT_TASKID)++; + } + return pMsg; +} + +Osp_Msg_Head *osp_alloc_msgId(uint32_t Len, int32_t id) +{ + Osp_Msg_Head *pMsg; + osp_assert(Len > 0); + pMsg = osp_get_buffer(Len + MSG_HEAD_SIZE, BUF_FOR_MSG, BUFFER_NORMAL_LEVEL); + if (pMsg) + { + osp_atomic_inc((int32_t *) & TASK_MSG_ALLOCCNT(id)); + } + return pMsg; +} + + +Osp_Msg_Head *osp_alloc_msgTimer(void) +{ + static int32_t cnt = 0; + Osp_Msg_Head *pMsg = (Osp_Msg_Head *)TimerMsg[(cnt++) & TIME_MSG_MSK]; + return pMsg; + + +} +Osp_Msg_Head*osp_alloc_msg_print_log(void) +{ + + Osp_Msg_Head *pMsg = osp_get_buffer(0 + MSG_HEAD_SIZE, BUF_FOR_MSG, BUFFER_PRINTLOG_LEVEL); + if (pMsg) + { + osp_atomic_inc((int32_t *)&TASK_LOGMSG_ALLOCCNT(CURRENT_TASKID)); + } + return pMsg; +} + + + + + +void osp_free_msg(Osp_Msg_Head *pHead) +{ + osp_atomic_inc((int32_t *)&TASK_MSG_FREECNT(CURRENT_TASKID)); + if (IS_TIMER_MSG(pHead)) + return; + osp_free_buffer(pHead); +} +int32_t osp_free_msgid(Osp_Msg_Head *pHead, int32_t id) +{ + osp_atomic_inc((int32_t *)&TASK_MSG_FREECNT(id)); + if (IS_TIMER_MSG(pHead)) + return 0; + return osp_free_buffer(pHead); +} + +OSP_STATUS osp_send_msg(Osp_Msg_Head *p_MsgHead) +{ + OSP_STATUS ret; + // U8 *pComm; + uint32_t TaskId; +// Osp_Msg_Head *p_NMsgHead; + OSP_FUNCPTR func_handle; + uint64_t que; + + osp_assert(NULL != p_MsgHead); + + TaskId = p_MsgHead->DstId; + + func_handle = TASK_TXMSG_HANDLE(TaskId); + if (NULL == func_handle) + { + osp_debug_out_with_time(ERR_DEBUG_LEVEL, "task%d can not send msg to task%d\n", CURRENT_TASKID, TaskId); + osp_free_msg(p_MsgHead); + + return OSP_ERROR; + } + + + que = TASK_MSG_QUE(TaskId); + + + osp_atomic_inc((int32_t *)&TASK_MSG_TXCNT(CURRENT_TASKID)); + + ret = func_handle(p_MsgHead, que); +// ret = osp_msg_enque(MSG_TO_OFFSET(p_MsgHead), (Osp_MsgQ_Tcb *)TASK_MSGQ(TaskId)); + if (OSP_OK != ret) + { +// osp_free_msg(p_MsgHead); + osp_debug_out_with_time(ERR_DEBUG_LEVEL, "task%d send msg to task%d msgtype 0x%x failed!\n", CURRENT_TASKID, TaskId, p_MsgHead->MsgType); + osp_atomic_inc((int32_t *)&TASK_MSG_FULLCNT(TaskId)); + return ret; + } + return OSP_OK; + +} +OSP_STATUS osp_send_msgId(Osp_Msg_Head *p_MsgHead, int32_t id) +{ + OSP_STATUS ret; +// U8 *pComm; + uint32_t TaskId; +// Osp_Msg_Head *p_NMsgHead; +// OSP_FUNCPTR func_handle; + + osp_assert(NULL != p_MsgHead); + + + TaskId = p_MsgHead->DstId; + + osp_atomic_inc((int32_t *)&TASK_MSG_TXCNT(id)); + ret = osp_msg_enque(MSG_TO_OFFSET(p_MsgHead), (Osp_MsgQ_Tcb *)TASK_MSGQ(TaskId)); + if (OSP_OK != ret) + { +// osp_free_msgid(p_MsgHead,id); + osp_atomic_inc((int32_t *)&TASK_MSG_FULLCNT(TaskId)); + return ret; + } + return OSP_OK; +} + +Osp_Msg_Head *osp_rev_msg(void) +{ + uint32_t TaskId; + OSP_FUNCPTR func_handle; + uint64_t que; + + TaskId = CURRENT_TASKID; + + que = TASK_MSG_QUE(TaskId); + func_handle = TASK_RXMSG_HANDLE(TaskId); + + return (Osp_Msg_Head *)func_handle(que); + +} + +Osp_Msg_Head *osp_rev_msgid(int32_t id) +{ + + uint64_t RcvMsg; + (void)osp_msg_deque((uint64_t *)&RcvMsg, (Osp_MsgQ_Tcb *)(TASK_MSGQ(id))); + osp_atomic_inc((int32_t*)&TASK_MSG_RXCNT(id)); + + return OFFSET_TO_MSG(RcvMsg); +} + + +Osp_Msg_Head *osp_rev_msgtry(void) +{ + + uint64_t RcvMsg; + int32_t ret; + ret = osp_msg_dequetry((uint64_t *)&RcvMsg, (Osp_MsgQ_Tcb *)(TASK_MSGQ(CURRENT_TASKID))); + if (0 != ret) + { + return NULL; + } + osp_atomic_inc((int32_t *)&TASK_MSG_RXCNT(CURRENT_TASKID)); + return OFFSET_TO_MSG(RcvMsg); +} + +Osp_Msg_Head *osp_rev_msg_timeout(uint32_t timeout) +{ + + uint64_t RcvMsg; + int32_t ret; + ret = osp_msg_deque_timeout((uint64_t *)&RcvMsg, (Osp_MsgQ_Tcb *)(TASK_MSGQ(CURRENT_TASKID)), timeout); + + if (0 != ret) + { + return NULL; + } + osp_atomic_inc((int32_t *)&TASK_MSG_RXCNT(CURRENT_TASKID)); + return OFFSET_TO_MSG(RcvMsg); +} + +Osp_Msg_Head *osp_rev_idmsg(uint32_t Id) +{ + + uint64_t RcvMsg; + (void)osp_msg_deque((uint64_t *)&RcvMsg, (Osp_MsgQ_Tcb *)(TASK_MSGQ(Id))); + osp_atomic_inc((int32_t *)&TASK_MSG_RXCNT(Id)); + + return OFFSET_TO_MSG(RcvMsg); +} + +Osp_Msg_Head *osp_rev_idmsgtry(uint32_t Id) +{ + + uint64_t RcvMsg; + int32_t ret; + ret = osp_msg_dequetry((uint64_t *)&RcvMsg, (Osp_MsgQ_Tcb *)(TASK_MSGQ(Id))); + + if (0 != ret) + { + return NULL; + } + osp_atomic_inc((int32_t *)&TASK_MSG_RXCNT(Id)); + return OFFSET_TO_MSG(RcvMsg); +} + +Osp_Msg_Head *osp_rev_id_msg_timeout(uint32_t timeout, uint32_t Id) +{ + + uint64_t RcvMsg; + int32_t ret; + ret = osp_msg_deque_timeout((uint64_t *)&RcvMsg, (Osp_MsgQ_Tcb *)(TASK_MSGQ(Id)), timeout); + + if (0 != ret) + { + return NULL; + } + osp_atomic_inc((int32_t *)&TASK_MSG_RXCNT(Id)); + return OFFSET_TO_MSG(RcvMsg); +} + + + + +void osp_show_msg_que_info(void) +{ + int32_t i; + Osp_MsgQ_Tcb *MsgQ; + char *pbuf; + int32_t len = 0; + char *p; + + pbuf = malloc(10*1024); + osp_assert(pbuf != NULL); + + len += osp_get_soft_que_desc(pbuf + len); + + for (i = 0; i < OSP_MAX_TASK; i++) + { + if (gOspTask[i].Active) + { + + MsgQ = TASK_MSGQ(i); + len += osp_get_soft_que_info(&OSP_MSGQ_QUE(MsgQ), pbuf + len); + + } + } + + + for (p = pbuf; p < pbuf+len; p += (MAX_DBGINFO_LEN-1)) + { + osp_debug_out(CMD_DEBUG_LEVEL, "%s", p); + } + free(pbuf); +} + + +OSP_STATUS osp_send_por_msg(Osp_Msg_Head *p_MsgHead, Osp_MsgQ_Tcb *que) +{ + int32_t ret; + ret = osp_msg_enque(MSG_TO_OFFSET(p_MsgHead), que); + + return ret; + +} + +Osp_Msg_Head *osp_rev_promsg(Osp_MsgQ_Tcb *que) +{ + + uint64_t RcvMsg; + + (void)osp_msg_deque((uint64_t *)&RcvMsg, que); + + return OFFSET_TO_MSG(RcvMsg); +} + + diff --git a/osp/src/ospNetShell.c b/osp/src/ospNetShell.c new file mode 100644 index 0000000..8cefeaf --- /dev/null +++ b/osp/src/ospNetShell.c @@ -0,0 +1,277 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "osp.h" + + +#define MAX_CMD_LEN (150) /*the max length of a shell command */ + +typedef struct tag_Osp_Net_Shell_Head +{ + uint32_t ip; + uint32_t port; /*is just msgdata len, not include Osp_Msg_Head*/ + uint32_t res; + uint32_t res1; +}Osp_Net_Shell_Head; + +#define NET_SHELL_HEAD_SIZE sizeof(Osp_Net_Shell_Head) + + +extern struct termios saveterm; +extern char **arg; + +extern int32_t nCmdField; +extern int32_t maxCmdField; + +int32_t sockser; +struct sockaddr_in addrser, addrcli; +socklen_t addrlen; + +#define OSP_MAX_SHELL_NUM 32 + +int32_t net_shell_txudp_id = -1; +uint32_t net_shell_res = 0; + +OSP_UDP_TASK_DATA udp_shell_rx_task = {OSP_NETSHELL_RX_PORT, 1, }; + + + + +int32_t osp_local_shell_main(char *szCmdNow) +{ + struct termios nt; + int32_t ret; + char shellbuf[MAX_CMD_LEN] = {0}; + char buf[4096] = {0}; + + tcgetattr(STDIN_FILENO, &saveterm); + nt = saveterm; + nt.c_lflag &= (~ICANON); + nt.c_lflag &= (~ECHO); + nt.c_cc[VMIN] = 1; + nt.c_cc[VTIME] = 0; + tcsetattr(STDIN_FILENO, TCSANOW, &nt); + + arg = (char **)malloc(maxCmdField *sizeof(arg[0])); + + osp_set_prompt(); + { + + memcpy(shellbuf, szCmdNow, strlen(szCmdNow)); + shellbuf[strlen(szCmdNow)] = '\0'; + + osp_getcmdarg(szCmdNow); + ret = osp_execcmd(); + + if (OSP_ERROR == ret) + { + sprintf(shellbuf + strlen(shellbuf), "%s", " > remeotelocalfile"); + system(shellbuf); + { + /*just simple cmd is supported*/ + FILE *file; + file = fopen("./remeotelocalfile", "rb"); + fread(buf, 4096, 1, file); + //printf("osp_local_shell_main:buf = %s;\n" , buf); + osp_debug_out(CMD_DEBUG_LEVEL, "%s", buf); + fclose(file); + } + + } + } + free(arg); + return ret; +} + + + +int32_t osp_enable_net_shell(void) +{ + + osp_resume_task(ospnetshellrx); + return 0; +} + + + +int32_t osp_disable_net_shell(void) +{ + int32_t udpid; + + udpid= osp_get_rxudp("127.0.0.1", OSP_NETSHELL_RX_PORT); + osp_del_udp(udpid); + + udpid= osp_get_txudp("127.0.0.1", OSP_NETSHELL_RX_PORT); + osp_del_udp(udpid); + + return 0; +} + +int32_t osp_enable_net_shell_with_port(int32_t port) +{ + int32_t txudpid; + int32_t rxudpid; + + if (port < 0) + { + return -1; + } + + osp_disable_net_shell(); + + txudpid = osp_create_txucp(port, "127.0.0.1"); + rxudpid = osp_create_rxucp(port); + + osp_set_net_task_msg_que(ospnetshellrx, txudpid, rxudpid); + osp_resume_task(ospnetshellrx); + return 0; +} + + +int32_t osp_net_shell_init(void) +{ + osp_suspend_task(CURRENT_TASKID); + return 0; +} + +int32_t osp_net_msg_main(Osp_Msg_Head *pMsg) +{ + struct in_addr addr1; + uint32_t ip; + int32_t port; + Osp_Net_Shell_Head *pShell; + int32_t udpid; + + pShell = (Osp_Net_Shell_Head *)(pMsg + 1); + ip = pShell->ip; + port = pShell->port; + memcpy(&addr1, &ip, 4); + + if (!osp_check_udpid(net_shell_txudp_id)) + { + udpid = osp_get_txudp(inet_ntoa(addr1), port); + if (osp_check_udpid(udpid)) + { + net_shell_txudp_id = udpid; + } + else + { + net_shell_txudp_id = osp_create_txucp(port, inet_ntoa(addr1)); + } + } + else if (net_shell_txudp_id != osp_get_txudp(inet_ntoa(addr1), port)) + { + osp_del_udp(net_shell_txudp_id); + net_shell_txudp_id = osp_create_txucp(port, inet_ntoa(addr1)); + } + + int32_t len = pMsg->MsgSize + MSG_HEAD_SIZE + NET_SHELL_HEAD_SIZE; + + printf("ip:port:res:res1 %d:%d:%d:%d", pShell->ip, + pShell->port, pShell->res, pShell->res1); + + osp_udp_send((char *)(pMsg), len, net_shell_txudp_id); + osp_free_msg(pMsg); + return 0; + +} +int32_t osp_net_shell_main(Osp_Msg_Head *pMsg) +{ + struct in_addr addr1; + uint32_t ip; + int32_t port; + Osp_Net_Shell_Head *pShell; + int32_t udpid; + + pShell = (Osp_Net_Shell_Head *)(pMsg + 1); + ip = pShell->ip; + port = pShell->port; + memcpy(&addr1, &ip, 4); + + if (!osp_check_udpid(net_shell_txudp_id)) + { + udpid = osp_get_txudp(inet_ntoa(addr1), port); + if (osp_check_udpid(udpid)) + { + net_shell_txudp_id = udpid; + } + else + { + net_shell_txudp_id = osp_create_txucp(port, inet_ntoa(addr1)); + } + } + else if (net_shell_txudp_id != osp_get_txudp(inet_ntoa(addr1), port)) + { + osp_del_udp(net_shell_txudp_id); + + net_shell_txudp_id = osp_create_txucp(port, inet_ntoa(addr1)); + + } + +// memcpy(&addr1, &(pMsg->SrcId), 4); + + osp_local_shell_main((char *)(pMsg) + MSG_HEAD_SIZE + NET_SHELL_HEAD_SIZE); + osp_free_msg(pMsg); + return 0; + +} + +void osp_set_net_shell_rev(uint32_t data) +{ + net_shell_res = data; + +} + +uint32_t osp_get_net_shell_rev(void) +{ + return net_shell_res; + +} + + +int32_t osp_net_shell_out(Osp_Msg_Head *pMsg) +{ + Osp_Msg_Head *pMsgN; + int32_t len; + Osp_Net_Shell_Head *pShell; + + if ((NULL == pMsg) || (-1 == net_shell_txudp_id)) + { + return -1; + } + + len = pMsg->MsgSize + MSG_HEAD_SIZE + NET_SHELL_HEAD_SIZE; + + pMsgN = osp_alloc_msg(len); + if (NULL != pMsgN) + { + memcpy((char *)pMsgN, (char *)pMsg, MSG_HEAD_SIZE); + pMsgN->MsgType = OSP_SHELL_TYPE; + + pShell = (Osp_Net_Shell_Head *)(pMsgN+1); + pShell->ip = 0; + pShell->port =0; + pShell->res = osp_get_net_shell_rev(); + + memcpy((char *)pMsgN + MSG_HEAD_SIZE + NET_SHELL_HEAD_SIZE, (char *)pMsg + MSG_HEAD_SIZE, len); + + osp_udp_send((char *)(pMsgN), len, net_shell_txudp_id); + osp_free_msg(pMsgN); + + return 0; + } + return -1; +} + + + + + diff --git a/osp/src/ospOtherMsg.c b/osp/src/ospOtherMsg.c new file mode 100644 index 0000000..843478e --- /dev/null +++ b/osp/src/ospOtherMsg.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include + +#include "osp.h" + + + + +int32_t osp_send_othermsg(Osp_Msg_Head *pMsg, uint64_t data) +{ + int32_t ret = OSP_OK; + OSP_FUNCPTR func; + + func = (OSP_FUNCPTR)data; + + ret = func((char *)pMsg, pMsg->MsgSize + MSG_HEAD_SIZE); + + osp_free_msg(pMsg); + return ret; +} + +Osp_Msg_Head *osp_rev_other_msg(uint64_t data) +{ + Osp_Msg_Head *pMsg; + int32_t ret; + int32_t len; + OSP_FUNCPTR func; + + + pMsg = osp_alloc_msg(OSP_MAX_OTHER_MSG_LEN); + if (NULL == pMsg) + { + return NULL; + } + + func = (OSP_FUNCPTR)data; + + ret = func((char *)pMsg, &len); + if (ret < 0) + { + osp_free_msg(pMsg); + return NULL; + } + + + return (Osp_Msg_Head *)pMsg; + +} + + + + diff --git a/osp/src/ospRtc.c b/osp/src/ospRtc.c new file mode 100644 index 0000000..fef8721 --- /dev/null +++ b/osp/src/ospRtc.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +#include "osp.h" + + + + /* + *osp_get_rtc_time - query RTC time + *input: + * pRtc pointer to RTC + *return + * OSP_OK + * OSP_ERROR(fail) + */ + +OSP_STATUS osp_get_rtc_time(OSP_RTCTIME *pRtc) +{ +#if 0 + + time_t sysTime; + struct tm *timeInfo = NULL; + + if (pRtc == NULL) + return (OSP_ERROR); + gettimeofday + time(&sysTime); + timeInfo = localtime(&sysTime); + pRtc->year = timeInfo->tm_year+1900; + pRtc->month = timeInfo->tm_mon+1; + pRtc->day = timeInfo->tm_mday; + pRtc->hour = timeInfo->tm_hour; + pRtc->minute = timeInfo->tm_min; + pRtc->second = timeInfo->tm_sec; +#endif + struct timeval tv; + struct timezone tz; + + struct tm *timeInfo = NULL; + + if (pRtc == NULL) + return (OSP_ERROR); + + gettimeofday(&tv, &tz); + timeInfo = localtime(&tv.tv_sec); + pRtc->year = timeInfo->tm_year + 1900; + pRtc->month = timeInfo->tm_mon + 1; + pRtc->day = timeInfo->tm_mday; + pRtc->hour = timeInfo->tm_hour; + pRtc->minute = timeInfo->tm_min; + pRtc->second = timeInfo->tm_sec; + pRtc->usecond = tv.tv_usec; + + return (OSP_OK); +} + + + + + + +void osp_show_rtc_time(void) +{ + OSP_RTCTIME Rtc; + osp_get_rtc_time(&Rtc); + + osp_debug_out(CMD_DEBUG_LEVEL, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n", + Rtc.year, Rtc.month, Rtc.day, + Rtc.hour, Rtc.minute, Rtc.second); + +} \ No newline at end of file diff --git a/osp/src/ospSem.c b/osp/src/ospSem.c new file mode 100644 index 0000000..3621776 --- /dev/null +++ b/osp/src/ospSem.c @@ -0,0 +1,351 @@ +#include +#include +#include +#include + +#include "osp.h" + +void *osp_semm_create(void) +{ + + lx_sem_t *sem = (lx_sem_t *)malloc(sizeof(lx_sem_t)); + if (sem != NULL) + { + if (pthread_mutex_init(&sem->u.sem_mutex, NULL) == 0) + { + sem->sem_type = SEM_TYPE_MUTEX; + } + else + { + free(sem); + sem = NULL; + } + } + + return (void *)sem; +} + +void*osp_semsm_create(void *semId) +{ + pthread_mutexattr_t mutexAttr; + int32_t Ret; + lx_sem_t *sem; + + sem = (lx_sem_t *)semId; + Ret = pthread_mutexattr_init(&mutexAttr); + if (0 != Ret) + { + return NULL; + } + + Ret = pthread_mutexattr_setpshared(&mutexAttr, PTHREAD_PROCESS_SHARED); + if (0 != Ret) + { + return NULL; + } + + Ret = pthread_mutexattr_setrobust(&mutexAttr, PTHREAD_MUTEX_ROBUST); + if (0 != Ret) + { + return NULL; + } + + Ret = pthread_mutex_init(&(sem->u.sem_mutex), &mutexAttr); + if (0 != Ret) + { + osp_debug_out(ERR_DEBUG_LEVEL, "pthread_mutex_init err\n"); + return NULL; + + } + sem->sem_type = SEM_TYPE_MUTEX; + + return (void *)sem; + +} + +void *osp_semss_create(void *semId) +{ + lx_sem_t *sem = (lx_sem_t *)semId; + + if (sem_init(&sem->u.sem_count, 1, 0) == 0) + { + sem->sem_type = SEM_TYPE_COUNT; + } + + return (void *)sem; +} + +void *osp_semb_create(SEM_B_STATE initalState) +{ + + int32_t initCount = (initalState == SEM_FULL) ? 1 : 0; + lx_sem_t*sem = (lx_sem_t *)malloc(sizeof(lx_sem_t)); + + if (sem != NULL) + { + if (sem_init(&sem->u.sem_count, 0, initCount) == 0) + { + sem->sem_type = SEM_TYPE_BINARY; + } + else + { + free(sem); + sem = NULL; + } + } + + return (void *)sem; +} + + + +void *osp_semc_create(int32_t initCount) +{ + + lx_sem_t *sem = (lx_sem_t *)malloc(sizeof(lx_sem_t)); + if (sem != NULL) + { + if (sem_init(&sem->u.sem_count, 1, initCount) == 0) + { + sem->sem_type = SEM_TYPE_COUNT; + } + else + { + free(sem); + sem = NULL; + } + } + + return (void *)sem; +} +int32_t osp_sem_timed_wait_millsecs(lx_sem_t *sem, long msecs) +{ + struct timespec ts; + int32_t ret = OSP_OK; + + clock_gettime(CLOCK_REALTIME, &ts); + long secs = msecs/1000; + msecs = msecs%1000; + + long add = 0; + msecs = msecs*1000*1000 + ts.tv_nsec; + add = msecs / (1000*1000*1000); + ts.tv_sec += (add + secs); + ts.tv_nsec = msecs%(1000*1000*1000); + + if (sem->sem_type == SEM_TYPE_MUTEX) + { + ret = pthread_mutex_timedlock(&sem->u.sem_mutex, &ts); + } + else + { + ret = sem_timedwait(&sem->u.sem_count, &ts); + } + return ret; +} + +int32_t osp_sem_timedwait_microsecond(lx_sem_t *sem, long msecs) +{ + struct timespec ts; + int32_t ret = OSP_OK; + + clock_gettime(CLOCK_REALTIME, &ts); + long secs = msecs / 1000000; + msecs = msecs % 1000000; + + long add = 0; + msecs = msecs * 1000 + ts.tv_nsec; + add = msecs / (1000 * 1000 * 1000); + ts.tv_sec += (add + secs); + ts.tv_nsec = msecs % (1000 * 1000 * 1000); + + if (sem->sem_type == SEM_TYPE_MUTEX) + { + ret = pthread_mutex_timedlock(&sem->u.sem_mutex, &ts); + } + else + { + ret = sem_timedwait(&sem->u.sem_count, &ts); + } + return ret; +} + +OSP_STATUS osp_sem_take(void *semId, int32_t timeout) +{ + int32_t ret = -1; + lx_sem_t *sem = (lx_sem_t *)semId; + int32_t err = EINTR; + /*errno ==EINTR means this is broken by singnal */ + while ((-1 == ret) && (err == EINTR)) + { + if (timeout > 0) + { +// ret = osp_sem_timed_wait_millsecs(sem, timeout); + ret = osp_sem_timedwait_microsecond(sem, timeout); + } + else + { + if (sem->sem_type == SEM_TYPE_MUTEX) + ret = pthread_mutex_lock(&sem->u.sem_mutex); + else + ret = sem_wait(&sem->u.sem_count); + } + if (0 != ret) + err = errno; + } + + return (OSP_OK); +} + +OSP_STATUS osp_sem_taketry(void *semId) +{ + + int32_t ret; + lx_sem_t *sem = (lx_sem_t *)semId; + + if (sem->sem_type == SEM_TYPE_MUTEX) + ret = pthread_mutex_trylock(&sem->u.sem_mutex); + else + ret = sem_trywait(&sem->u.sem_count); + if (ret != 0) + return (OSP_ERROR); + + return (OSP_OK); +} + + + +OSP_STATUS osp_sem_give(void *semId) +{ + + + int32_t ret; + lx_sem_t *sem = (lx_sem_t *)semId; + + if (sem->sem_type == SEM_TYPE_MUTEX) + ret = pthread_mutex_unlock(&sem->u.sem_mutex); + else if (sem->sem_type == SEM_TYPE_COUNT) + ret = sem_post(&sem->u.sem_count); + else + { + sem_getvalue(&sem->u.sem_count, &ret); + if (ret == 0) + ret = sem_post(&sem->u.sem_count); + } + + if (ret != 0) + return (OSP_ERROR); + + return (OSP_OK); +} + + +OSP_STATUS osp_sem_delete(void *semId) +{ + int32_t ret; + lx_sem_t *sem = (lx_sem_t *)semId; + + if (sem->sem_type == SEM_TYPE_MUTEX) + { + ret = pthread_mutex_destroy(&sem->u.sem_mutex); + } + else + { + ret = sem_destroy(&sem->u.sem_count); + } + free(sem); + + return ret; +} + + + +void *osp_semrwc_reate(int32_t readerNum) +{ + pthread_rwlock_t *sem = (pthread_rwlock_t *)malloc(sizeof(pthread_rwlock_t)); + if (sem != NULL) + { + if (0 != pthread_rwlock_init(sem, NULL)) + { + free(sem); + sem = NULL; + } + } + + return (void *)sem; +} + + + +OSP_STATUS osp_semr_take(void *semId, int32_t timeout) +{ + + int32_t ret; + struct timespec timeout1; + pthread_rwlock_t *sem = (pthread_rwlock_t *)semId; + + if (timeout > 0) + { + //timeout1.tv_sec = timeout/1000; + //timeout1.tv_nsec = (timeout%1000)*1000000; + clock_gettime(CLOCK_REALTIME, &timeout1); + timeout1.tv_sec += timeout/1000; + timeout1.tv_nsec += (timeout%1000)*1000000; + + ret = pthread_rwlock_timedrdlock(sem, &timeout1); + } + else + ret = pthread_rwlock_rdlock(sem); + + if (ret != 0) + { + return (OSP_ERROR); + } + + return (OSP_OK); +} + + + +OSP_STATUS osp_sem_wtake(void *semId, int32_t timeout) +{ + + int32_t ret; + struct timespec timeout1; + pthread_rwlock_t *sem = (pthread_rwlock_t *)semId; + + if (timeout > 0) + { + //timeout1.tv_sec = timeout/1000; + //timeout1.tv_nsec = (timeout%1000)*1000000; + clock_gettime(CLOCK_REALTIME, &timeout1); + timeout1.tv_sec += timeout/1000; + timeout1.tv_nsec += (timeout%1000)*1000000; + + ret = pthread_rwlock_timedwrlock(sem, &timeout1); + } + else + ret = pthread_rwlock_wrlock(sem); + + if (ret != 0) + { + return (OSP_ERROR); + } + + return (OSP_OK); +} + +OSP_STATUS osp_semrw_give(void *semId) +{ + + int32_t ret; + pthread_rwlock_t *sem = (pthread_rwlock_t *)semId; + + ret = pthread_rwlock_unlock(sem); + if (ret != 0) + { + return (OSP_ERROR); + } + + return (OSP_OK); +} diff --git a/osp/src/ospShell.c b/osp/src/ospShell.c new file mode 100644 index 0000000..b666804 --- /dev/null +++ b/osp/src/ospShell.c @@ -0,0 +1,1821 @@ + +#include +#include +#include +#include +#include +#include +#include + +#include "osp.h" +#include "ospShell.h" +#include "ospDbg.h" +#include "ospSoftQue.h" +#include "ospBuf.h" +#include "ospTimer.h" +#include "ospHeap.h" +#include "ospTypes.h" +#include "ucp_printf.h" +#include "ospHeap.h" +#include "ospDump.h" +#include "ospSwQueue.h" +#include "pet_sm_mgt.h" +#include "msg_transfer_layer.h" + + +#define MAX_CMD_LEN (150) /*the max length of a shell command */ +#define MAX_CMD_NUM 128 + +extern uint32_t g_ulApeLogMode; /*0: ape log鏃ュ織鍐欏叆鏂囦欢 1: 缃戝彛杈撳嚭ape log 2:ape log鏃ュ織shell鎵撳嵃杈撳嚭*/ +extern uint32_t g_ulArmLogMode; /*0: arm log鏃ュ織鍐欏叆鏂囦欢 1: 缃戝彛杈撳嚭arm log 2:arm log鏃ュ織shell鎵撳嵃杈撳嚭*/ +extern uint8_t g_ucPlatformMode; /*0: platform log鏃ュ織鍐欏叆鏂囦欢 1: 缃戝彛杈撳嚭platform log 2:platform log鏃ュ織shell鎵撳嵃杈撳嚭*/ + +extern OSP_CMD_RTN ospCmdRtnTbl[]; +extern int32_t SHELL_CMD_NUM; + +extern char *pShellBuf; + +/*function prototype */ +extern void osp_set_prompt(); + +uint8_t guc_oam = 0; +uint8_t guc_ape_id = 0; +uint8_t gac_cmd[32] = {0}; +uint8_t guc_print_level = 0x4; +uint32_t gul_arg[128] = {0}; + +Osp_Ape_Send_Count ga_ape_send_count[10]; +extern uint8_t g_ucIsEcho; +extern int32_t g_ProcessId; +extern uint8_t g_time_now[128]; +extern Osp_Server_Head gst_server_log; +extern int32_t osp_base_logid; +extern void *gpsw_que_share_mem; + +struct termios saveterm; + +OSP_CMD_RTN *ospCmdRtnTblExt = NULL; +lx_sem_t *ospCmdInsertSem = NULL; +void osp_mem_show(char *addr , uint32_t ulLen); + +void help(void); +OSP_CMD_RTN ospCmdRtnTbl[MAX_CMD_NUM] = +{ + {"help", (OSP_FUNCPTR)help, NULL, }, + {"?", (OSP_FUNCPTR)help, NULL, }, + {"i", (OSP_FUNCPTR)osp_show_task_info, NULL,"show alltask info", 0}, + {"oam", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_set_oam, "set arm oam level", 1}, + //{"x", (OSP_FUNCPTR)osp_shell_mem_wrapper, (OSP_FUNCPTR)osp_shell_dis_mem, "x num addr: show addr memory(length is num)", 2}, + //{"s", (OSP_FUNCPTR)osp_shell_mem_wrapper, (OSP_FUNCPTR)osp_shell_set_mem, "s addr val: set addr memory(length is 4)", 2}, + {"phym", (OSP_FUNCPTR)osp_shell_mem_wrapper, (OSP_FUNCPTR)osp_display_phy_mem, "show phy mempry info", 2}, + //{"c", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_tsk_diag_cnt, "show Task Diag Cnt", 1}, + {"net", (OSP_FUNCPTR)osp_show_udp, NULL, "show net info", 0}, + {"sw", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_swqueue_info, "show arm print level", 0}, + {"level", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_set_print_level, "set arm print level", 1}, + {"slevel", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_print_level, "show arm print level", 0}, + {"dump", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_dump_proc, "dump ddr mem", 4}, + {"dumpdm", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_dump_dm_by_apcid, "dump dm info to bin by apcid", 4}, + {"apcdm", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_dm_by_apcid, "show dm info by apcid", 3}, + {"dl", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_queue_dl_info, "show dl queue info", 0}, + {"ul", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_queue_ul_info, "show ul queue info", 0}, + {"apeid", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_get_ape_id, "get ape id", 1}, + {"apelog", (OSP_FUNCPTR)osp_shell_wrapper,(OSP_FUNCPTR)osp_set_ape_log_mode, "0: ape log write file 1: ape log out to net 2:ape log to shell", 1}, + {"armlog", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_set_arm_log_mode, "0: arm log write file 1: arm log out to net 2:arm log to shell", 1}, + {"plog", (OSP_FUNCPTR)osp_shell_wrapper,(OSP_FUNCPTR)osp_set_platform_log_mode, "0: platform log write file 1: platform log out to net 2:platform log to shell", 1}, + {"server", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_server_cfg, "server ip port", 2}, + {"ss", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_server_cfg_show, "show server cfg", 0}, + {"logpath", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_log_path_cfg, "cfg log path", 1}, + {"relog", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_log_mode_get,"reload log cfg", 0}, + //{"tfu", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_get_tfu_location_info, "get tfu location", 0}, + //{"clock_info", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_get_clock_tracking_state, "get clock tracking state", 0}, + //{"ret_clock", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_reset_clock_module, "reset clock module", 0}, + //{"set_clock", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_set_clk_mode, "set clock module", 1}, + {"recmd_ape", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_reget_ape_cmd, "get ape cmd again", 0}, + {"intr_ape", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_ape_csu_int_cnt, "show intr info", 0}, +// {"level_ape", (OSP_FUNCPTR)osp_shell_wrapper,(OSP_FUNCPTR)osp_ape_set_log_level, "set ape log level", 1}, +// {"csu_stop_ape", (OSP_FUNCPTR)osp_shell_wrapper,(OSP_FUNCPTR)osp_ape_csu_stop_cfg, "set csu start or stop", 2}, +// {"i_ape", (OSP_FUNCPTR)osp_shell_wrapper, (OSP_FUNCPTR)osp_show_ape_taskinfo, "show ape task info", 0}, +}; + +int32_t SHELL_CMD_NUM = OSP_NELEMENTS(ospCmdRtnTbl); +int32_t SHELL_CMD_NUM_EXT = 0; + + +#define KEY_BACKSPACE '\b' // back space +#define KEY_BACKSPACE1 127 // back space +#define KEY_ENTER '\x0A' // enter + +#define MAX_CMD_HISTORY 32 + +#define MAX_EXT_CMD_NUM MAX_CMD_NUM + +typedef enum +{ + WKS_WAIT, + WKS_RECV1B, + WKS_UDLR, + WKS_DEL, +}T_WaitKeyState; + +static char szPrompt[] = {"-> "}; + +static T_WaitKeyState waitKeyState = WKS_WAIT; +static char szCmdHistory[MAX_CMD_HISTORY][MAX_CMD_LEN]; +static char szCmdNow[MAX_CMD_LEN] = {0}; + +static uint32_t nCmdIndex = 0; +static uint32_t nCmdCursor = 0; +static uint32_t nCmdInputCount = 0; +static uint32_t nCmdInputCursor = 0; + +int32_t cmdMatched = 0; +char cmdMatchBuf[OSP_NELEMENTS(ospCmdRtnTbl)][MAX_CMD_LEN + 10] = {0}; +char cmdShowBuf[MAX_CMD_LEN*OSP_NELEMENTS(ospCmdRtnTbl)] = {0}; + +bool gEscOn = false; + + + +int32_t nCmdField; +int32_t maxCmdField = 10; +char **arg = NULL; + +void osp_mem_show(char *addr , uint32_t ulLen) +{ +#if 0 + int32_t i; + + if (NULL == addr) + { + return; + } + + if (ulLen > 65535) + { + return; + } + + for (i = 0; i < ulLen; i++) + { + if ((i & 0x3) == 0) + { + UCP_PRINT_SHELL("0x%08x: \t", addr+i); + } + + UCP_PRINT_SHELL("%08x\t", addr[i]); + + if ((i & 0x3) == 0x3) + { + UCP_PRINT_SHELL("\n"); + } + } +#endif + return; +} + +void help(void) +{ + int32_t i; + char buf[4096] = {0}; + int32_t len = 0; + + len += sprintf(buf+len, "%-16s%s\n", "cmd", "descption"); + for (i = 0; i < MAX_CMD_NUM; i++) + { + if (ospCmdRtnTbl[i].cmd[0] != 0) + { + len += sprintf(buf + len, "%-16s%s\n", ospCmdRtnTbl[i].cmd, ospCmdRtnTbl[i].descption); + + } + } + for (i = 0; i < MAX_CMD_NUM; i++) + { + if (ospCmdRtnTblExt[i].cmd[0] != 0) + { + len += sprintf(buf + len, "%-16s%s\n", ospCmdRtnTblExt[i].cmd, ospCmdRtnTblExt[i].descption); + + } + } + UCP_PRINT_SHELL("%s\n", buf); +} + + +/* + * osp_set_outstr - print string to console + * input: + * out : output string + * return + * none + */ + +void osp_set_outstr(char *out) +{ + UCP_PRINT_SHELL("%s", out); +} + +/* + * osp_set_prompt - set prompt string to console + * input: + * none + * return + * none + */ + +void osp_set_prompt() +{ + UCP_PRINT_SHELL("%s", szPrompt); +} +static int64_t argval[10] = {0}; +static char argchar[10][32] = {0}; +static char shellOut[64] = {0}; + +int32_t osp_str_is_digit(char *buf) +{ + int32_t i; + int32_t size = strlen(buf); + for (i = 0; i < size; i++) + { + if (0 == isdigit(buf[i])) + return 0; + } + + return 1; +} +int32_t osp_shell_symo(char **arg, int32_t len) +{ + int32_t i; + OSP_FUNCPTR func; + //INT32 size; + + uint64_t func_ret; + + for (i = 0; i < len; i++) + { + + if (((arg[i][0] == '0') && ((arg[i][1] == 'x') || (arg[i][1] == 'X'))) && osp_str_is_digit(arg[i])) + { + + argval[i] = strtoul(arg[i], (char **)NULL, 16); + } + else if (isdigit(arg[i][0]) && osp_str_is_digit(arg[i])) + { + argval[i] = strtoul(arg[i], (char **)NULL, 10); + } + else + { + strcpy(argchar[i], arg[i]); + argval[i] = (int64_t)argchar[i]; + } + } + + func = osp_find_sym(argchar[0]); + + if (func) + { + func_ret = func(argval[1], argval[2], argval[3], argval[4], + argval[5], argval[6], argval[7], argval[8], argval[9]); + sprintf(shellOut, "value = %p\r\n", (void *)func_ret); + osp_set_outstr(shellOut); + return 0; + } + + return -1; + +} + +int32_t osp_shell_mem_wrapper(char **arg, int32_t len, OSP_FUNCPTR func) +{ + int32_t i; + int32_t ret; + + for (i = 0; i < len; i++) + { + if ((arg[i][0] == '0') && ((arg[i][1] == 'x') || (arg[i][1] == 'X'))) + { + argval[i] = strtoul(arg[i], (char **)NULL, 16); + } + else if (isdigit(arg[i][0])) + { + argval[i] = strtoul(arg[i], (char **)NULL, 10); + } + + else + { + strcpy(argchar[i], arg[i]); + argval[i] = (uint64_t)osp_find_sym(&argchar[i][0]); + } + } + + + + ret = func(argval[0], argval[1], argval[2], argval[3], + argval[4], argval[5], argval[6], argval[7], argval[8]);; + return ret; + +} + +int32_t osp_shell_wrapper(char **arg, int32_t len, OSP_FUNCPTR func) +{ + int32_t i; + int32_t ret; + + memset(argchar, 0, sizeof(argchar)); + for (i = 0; i < len; i++) + { + if ((arg[i][0] == '"')) + { + strncpy(argchar[i], &arg[i][1],strlen(arg[i])-2); + argval[i] = (int64_t)argchar[i]; + } + else if ((arg[i][0] == '0') && ((arg[i][1] == 'x') || (arg[i][1] == 'X'))) + { + argval[i] = strtoul(arg[i], (char **)NULL, 16); + } + else if (isdigit(arg[i][0])) + { + argval[i] = strtoul(arg[i], (char **)NULL, 10); + } + else + { + strcpy(argchar[i], arg[i]); + argval[i] = (int64_t)argchar[i]; + } + } + + ret = func(argval[0], argval[1], argval[2], argval[3], argval[4], + argval[5], argval[6], argval[7], argval[8], argval[9]); + + return ret; +} + +uint32_t osp_ape_shell_wrapper(char **arg, uint32_t len, OSP_FUNCPTR func) +{ + uint32_t i = 0; + uint32_t ullen = 0; + char aCmd[128] = {0}; + + memset(argchar, 0, sizeof(argchar)); + for (i = 0; i < len; i++) + { + ullen = strlen(arg[i]); + if(ullen > 12) + { + UCP_PRINT_SHELL("len should less 12\n" ); + return OSP_ERROR; + } + + if ((arg[i][0] == '"')) + { + strncpy(argchar[i], &arg[i][1],ullen-2); + } + else + { + strcpy(argchar[i], arg[i]); + } + + } + + sprintf(aCmd, "%s %s %s %s %s %s %s %s %s %s %s %s", gac_cmd, argchar[0], argchar[1], \ + argchar[2], argchar[3], argchar[4], \ + argchar[5], argchar[6], argchar[7], \ + argchar[8], argchar[9], argchar[10]); + + UCP_PRINT_LOG("osp_ape_shell_wrapper gac_cmd:%s aCmd:%s\n", gac_cmd, aCmd); + osp_ape_msg_send((char *)aCmd); + + return 0; +} + + +int32_t osp_shell_str_wrapper(char **arg, int32_t len, OSP_FUNCPTR func) +{ + int32_t i; + int32_t ret; + + memset(argchar, 0, sizeof(argchar)); + for (i = 0; i < len; i++) + { + strcpy(argchar[i], arg[i]); + argval[i] = (int64_t)argchar[i]; + UCP_PRINT_SHELL("osp_shell_str_wrapper argval[%d] = %ld ; argchar[%d] = %s ", i, argval[i], i, argchar[i]); + } + + ret = func(argval[0], argval[1], argval[2], argval[3], argval[4], + argval[5], argval[6], argval[7], argval[8], argval[9]); + + return ret; +} + +/* + * getFullCmdMatch - get matched command name list + * input: + * pCmd : the prefix of a command + * return + * none + */ + +int32_t osp_get_full_cmd_match(char*pCmd) +{ + int32_t index; + char*pMatch; + + for (index = 0; index < OSP_NELEMENTS(ospCmdRtnTbl); index++) + { + pMatch = strstr(ospCmdRtnTbl[index].cmd, pCmd); + if ((pMatch != NULL) && (pMatch == ospCmdRtnTbl[index].cmd)) + { + strcpy(cmdMatchBuf[cmdMatched], ospCmdRtnTbl[index].cmd); + cmdMatched++; + } + } + return cmdMatched; +} + + +/* + * osp_getcmdarg - split command to params,then save to array arg + * input: + * cmd : pointer to command + * return + * params number + */ + +int32_t osp_getcmdarg(char *cmd) +{ + char seps[]=" ,\t\n"; + char *token; + char **p; + + nCmdField = 0; + + token = strtok(cmd, seps); + + while (token != NULL) + { + if (nCmdField >= maxCmdField) + { + maxCmdField *= 2; + p = (char **)realloc(arg, maxCmdField * sizeof(arg[0])); + if (p == NULL) + return -1; + else + arg = p; + } + arg[nCmdField] = token; + token = strtok(NULL, seps); + + nCmdField++; + } + + return nCmdField; +} + + +/* + * osp_execcmd - execute command + * input: + * none + * return + * OSP_OK,or + * OSP_ERROR(fail) + */ + +int32_t osp_execcmd(void) +{ + int32_t i; + int32_t ret = 0; + + if (nCmdField > 0) + { + /*本地命令*/ + for (i = 0; i < SHELL_CMD_NUM; i++) + { + if (strcmp(ospCmdRtnTbl[i].cmd, arg[0]) == 0) + { + if (ospCmdRtnTbl[i].argnum != nCmdField-1) + { + UCP_PRINT_ERROR("input wrong argnum should be %d\n", ospCmdRtnTbl[i].argnum); + return OSP_ERROR; + } + if(osp_is_ape_cmd(ospCmdRtnTbl[i].cmd))/*ape侧命令*/ + { + memcpy(gac_cmd, ospCmdRtnTbl[i].cmd, strlen(ospCmdRtnTbl[i].cmd)); + UCP_PRINT_SHELL("i:%u gac_cmd:%s ospCmdRtnTbl[i].cmd:%s\n", i, gac_cmd, ospCmdRtnTbl[i].cmd); + ret = (*ospCmdRtnTbl[i].wrapper)(&arg[1], nCmdField-1, ospCmdRtnTbl[i].routine); + memset(gac_cmd, 0, sizeof(gac_cmd)); + + return (OSP_OK); + } + ret = (*ospCmdRtnTbl[i].wrapper)(&arg[1], nCmdField-1, ospCmdRtnTbl[i].routine); + sprintf(shellOut, "\r\nvalue = %d = 0x%X\r\n", ret, ret); + osp_set_outstr(shellOut); + + return (OSP_OK); + } + } + for (i = 0; i < SHELL_CMD_NUM_EXT; i++) + { + if (strcmp(ospCmdRtnTblExt[i].cmd, arg[0]) == 0) + { + if (ospCmdRtnTblExt[i].argnum != nCmdField-1) + { + UCP_PRINT_ERROR("input wrong argnum should be %d\n", ospCmdRtnTblExt[i].argnum); + return OSP_ERROR; + } + if(osp_is_ape_cmd(ospCmdRtnTblExt[i].cmd))/*ape侧命令*/ + { + memcpy(gac_cmd, ospCmdRtnTblExt[i].cmd, strlen(ospCmdRtnTblExt[i].cmd)); + UCP_PRINT_LOG("i:%u gac_cmd:%s ospCmdRtnTblExt[i].cmd:%s\n", i, gac_cmd, ospCmdRtnTblExt[i].cmd); + ret = (*ospCmdRtnTblExt[i].wrapper)(&arg[1], nCmdField-1, ospCmdRtnTblExt[i].routine); + memset(gac_cmd, 0, sizeof(gac_cmd)); + + return (OSP_OK); + } + + ret = (*ospCmdRtnTblExt[i].wrapper)(&arg[1], nCmdField - 1, ospCmdRtnTblExt[i].routine); + sprintf(shellOut, "\r\nvalue = %d = 0x%X\r\n", ret, ret); + osp_set_outstr(shellOut); + return (OSP_OK); + } + } + ret = osp_shell_symo(&arg[0], nCmdField); + return ret; + } + return (OSP_ERROR); +} + +/* + * osp_shell_writebs - delete a character of command line + * input: + * none + * return + * none + */ + +void osp_shell_writebs() +{ + char szTemp[3]; + szTemp[0] = '\b'; + szTemp[1] = ' '; + szTemp[2] = '\b'; + write(STDOUT_FILENO, szTemp, 3); +} + +/* + * osp_shell_deal_input - handle keypress + * input: + * input: input key code + * return + * none + */ + +void osp_shell_deal_input(char input) +{ + if (nCmdInputCount == MAX_CMD_LEN) + return; + + if (nCmdInputCursor < nCmdInputCount) + { + char szTemp[MAX_CMD_LEN] = {0}; + char *pCmd = szCmdNow; + int32_t nBackCount = nCmdInputCount - nCmdInputCursor; + szTemp[0] = input; + memcpy(&szTemp[1], &pCmd[nCmdInputCursor], nBackCount); + write(STDOUT_FILENO, szTemp, nBackCount + 1); + memcpy(&pCmd[nCmdInputCursor], &szTemp, nBackCount + 1); + + memset(szTemp, '\b', nBackCount); + write(STDOUT_FILENO, szTemp, nBackCount); + } + else + { + write(STDOUT_FILENO, &input, 1); + szCmdNow[nCmdInputCount] = input; + } + + nCmdInputCursor++; + nCmdInputCount++; +} + +/* + * osp_shell_deal_backspace - handle key 'Backspace' + * input: + * none + * return + * none + */ + +void osp_shell_deal_backspace() +{ + if (nCmdInputCursor > 0) + { + if (nCmdInputCursor == nCmdInputCount) //cursor at the end + osp_shell_writebs(); + else + { + char szTemp[MAX_CMD_LEN] = {0}; + char*pCmd = szCmdNow; + int32_t nBackCount = nCmdInputCount - nCmdInputCursor; + szTemp[0] = '\b'; + memcpy(&szTemp[1], &pCmd[nCmdInputCursor], nBackCount); + szTemp[nBackCount+1] = ' '; + write(STDOUT_FILENO, szTemp, nBackCount + 2); + memcpy(&pCmd[nCmdInputCursor - 1], &szTemp[1], nBackCount); + + memset(szTemp, '\b', nBackCount + 1); + write(STDOUT_FILENO, szTemp, nBackCount + 1); + } + nCmdInputCount--; + nCmdInputCursor--; + } +} + +/* + * osp_shell_deal_delete - handle key 'Delete' + * input: + * none + * return + * none + */ + +void osp_shell_deal_delete() +{ + if (nCmdInputCursor < nCmdInputCount) + { + char szTemp[MAX_CMD_LEN] = {0}; + char *pCmd = szCmdNow; + + int32_t nBackCount = nCmdInputCount - nCmdInputCursor - 1; + memcpy(szTemp, &pCmd[nCmdInputCursor + 1], nBackCount); + szTemp[nBackCount] = ' '; + write(STDOUT_FILENO, szTemp, nBackCount + 1); + memcpy(&pCmd[nCmdInputCursor], szTemp, nBackCount); + + memset(szTemp, '\b', nBackCount + 1); + write(STDOUT_FILENO, szTemp, nBackCount + 1); + nCmdInputCount--; + } +} + +/* + * osp_shell_deal_doubleesc - clear command line + * input: + * none + * return + * none + */ + +void osp_shell_deal_doubleesc() +{ + if (nCmdInputCount > 0) + { + char *pCmd = szCmdNow; + + //move to end + while (nCmdInputCursor < nCmdInputCount) + { + write(STDOUT_FILENO, &pCmd[nCmdInputCursor], 1); + nCmdInputCursor++; + } + + //clear all inputs + int32_t i = 0; + for (i = 0; i < nCmdInputCount; i++) + osp_shell_writebs(); + nCmdInputCount = 0; + nCmdInputCursor = 0; + } +} + +/* + * osp_shell_deal_upkey - handle key 'up' + * input: + * none + * return + * none + */ + +void osp_shell_deal_upkey() +{ + if (nCmdCursor == 0) + return; + + nCmdCursor --; + + //clear all inputs + osp_shell_deal_doubleesc(); + + char *pCmdHistory = &szCmdHistory[nCmdCursor][0]; + memcpy(szCmdNow, pCmdHistory, MAX_CMD_LEN); + nCmdInputCount = strlen(szCmdNow); + nCmdInputCursor = nCmdInputCount; + write(STDOUT_FILENO, szCmdNow, nCmdInputCount); +} + +/* + * osp_shell_deal_downkey - handle key 'down' + * input: + * none + * return + * none + */ + +void osp_shell_deal_downkey() +{ + if (nCmdCursor >= (nCmdIndex-1)) return; + nCmdCursor ++; + + //clear all inputs + osp_shell_deal_doubleesc(); + + char*pCmdHistory = &szCmdHistory[nCmdCursor][0]; + memcpy(szCmdNow, pCmdHistory, MAX_CMD_LEN); + nCmdInputCount = strlen(szCmdNow); + nCmdInputCursor = nCmdInputCount; + write(STDOUT_FILENO, szCmdNow, nCmdInputCount); + +} + +/* + * osp_shell_deal_leftkey - handle key 'left' + * input: + * none + * return + * none + */ + +void osp_shell_deal_leftkey() +{ + if (nCmdInputCursor > 0) + { + char c = '\b'; + write(STDOUT_FILENO, &c, 1); + nCmdInputCursor--; + } +} + +/* + * osp_shell_deal_rightkey - handle key 'right' + * input: + * none + * return + * none + */ + +void osp_shell_deal_rightkey() +{ + if (nCmdInputCursor < nCmdInputCount) + { + char *pCmd = szCmdNow; + char c = pCmd[nCmdInputCursor]; + write(STDOUT_FILENO, &c, 1); + nCmdInputCursor++; + } +} + +/* + * osp_shell_deal_enter - handle key 'Enter' + * input: + * none + * return + * none + */ + +void osp_shell_deal_enter() +{ + szCmdNow[nCmdInputCount] = '\0'; + char szTemp[] = {"\r\n"}; + write(STDOUT_FILENO, szTemp, strlen(szTemp)); + nCmdInputCount = 0; + nCmdInputCursor = 0; + + if (strlen(szCmdNow) == 0) + return; + + if (nCmdIndex == MAX_CMD_HISTORY) + { + char szTempCmd[MAX_CMD_HISTORY][MAX_CMD_LEN]; + memcpy(szTempCmd, &szCmdHistory[1][0], MAX_CMD_LEN * (MAX_CMD_HISTORY - 1)); + memcpy(szCmdHistory, szTempCmd, MAX_CMD_LEN * (MAX_CMD_HISTORY - 1)); + nCmdIndex = MAX_CMD_HISTORY - 1; + nCmdCursor = nCmdIndex; + } + + memcpy(szCmdHistory[nCmdIndex], szCmdNow, MAX_CMD_LEN); + + nCmdIndex++; + nCmdCursor = nCmdIndex; +} + + +/* + * osp_shell_deal_tab - handle key 'tab' + * input: + * none + * return + * none + */ + +void osp_shell_deal_tab() +{ + int32_t matchNum; + int32_t matchIndex; + int32_t lenDiff; + int32_t cmdBufLen = 0; + char cmdPre[MAX_CMD_LEN] = {0}; + + cmdBufLen = nCmdInputCursor; + szCmdNow[cmdBufLen] = '\0'; + + strcpy(cmdPre, szCmdNow); + matchNum = osp_get_full_cmd_match(cmdPre); + + memset(cmdShowBuf, 0, sizeof(cmdShowBuf)); + if (matchNum == 1) + { + strcpy(cmdShowBuf, cmdMatchBuf[0]); + + lenDiff = strlen(cmdShowBuf) - strlen(cmdPre); + write(STDOUT_FILENO, &cmdShowBuf[cmdBufLen], lenDiff); + + strcpy(szCmdNow, cmdShowBuf); + nCmdInputCursor += lenDiff; + nCmdInputCount += lenDiff; + } + else + { + strcat(cmdShowBuf, "\r\n"); + + for (matchIndex = 0; matchIndex < matchNum; matchIndex++) + { + strcat(cmdShowBuf, cmdMatchBuf[matchIndex]); + strcat(cmdShowBuf, " "); + if ((matchIndex + 1) % 4 == 0) + { + strcat(cmdShowBuf, "\r\n"); + } + } + strcat(cmdShowBuf, "\r\n"); + strcat(cmdShowBuf, szPrompt); + strcat(cmdShowBuf, szCmdNow); + osp_set_outstr(cmdShowBuf); + } + memset(cmdMatchBuf, 0, sizeof(cmdMatchBuf)); + cmdMatched = 0; +} + +/* + * osp_shell_get_line - read whole command line string + * input: + * none + * return + * none + */ + +void osp_shell_get_line() +{ + bool bGetEnter = false; + while (true) + { + char input; + input = getchar(); + + switch (waitKeyState) + { + case WKS_WAIT : + if (isprint(input)) + osp_shell_deal_input(input); + else + { + if (input == '\t') + { + osp_shell_deal_tab(); + } + else if (input == KEY_BACKSPACE) + { + osp_shell_deal_backspace(); + } + else if (input == KEY_ENTER) + { + osp_shell_deal_enter(); + bGetEnter = true; + } + else if (input == '\x1b') + waitKeyState = WKS_RECV1B; + else + waitKeyState = WKS_WAIT; + } + break; + + case WKS_RECV1B: + if (input == '\x1b') + { + osp_shell_deal_doubleesc(); + waitKeyState = WKS_RECV1B; + } + else if (input == '[') //maybe "up/down/left/right" + { + waitKeyState = WKS_UDLR; + } + else //after pressing 'ESC' + { + if (isprint(input)) + osp_shell_deal_input(input); + waitKeyState = WKS_WAIT; + } + break; + + case WKS_UDLR: + if (input == 'A') //up + osp_shell_deal_upkey(); + else if (input == 'B') //down + osp_shell_deal_downkey(); + else if (input == 'D') //left + osp_shell_deal_leftkey(); + else if (input == 'C') //right + osp_shell_deal_rightkey(); + else if (input == 51) //maybe key 'delete' + { + waitKeyState = WKS_DEL; + break; + } + else + { + if (isprint(input)) + osp_shell_deal_input(input); + } + waitKeyState = WKS_WAIT; + break; + + case WKS_DEL: + if (input == 126) + osp_shell_deal_delete(); + else + { + if (isprint(input)) + osp_shell_deal_input(input); + } + waitKeyState = WKS_WAIT; + break; + + default: + break; + } + + if (bGetEnter) + { + break; + } + } +} + +int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc) +{ + OSP_CMD_RTN *tlb; + int32_t num; + + if ((name == NULL) || pfunc == NULL) + { + return -1; + + } + osp_sem_take(ospCmdInsertSem, -1); + tlb = ospCmdRtnTblExt; + num = SHELL_CMD_NUM_EXT; + + memcpy(tlb[num].cmd, name, strlen(name) + 1); + tlb[num].wrapper = (OSP_FUNCPTR)osp_shell_wrapper; + tlb[num].routine = pfunc; + + SHELL_CMD_NUM_EXT++; + osp_sem_give(ospCmdInsertSem); + return 0; +} +int32_t osp_insert_cmd_ext(char *name, OSP_FUNCPTR pfunc, char *desc, int32_t argnum) +{ + OSP_CMD_RTN *tlb; + int32_t num; + + if ((name == NULL) || pfunc == NULL) + { + return -1; + + } + tlb = ospCmdRtnTblExt; + num = SHELL_CMD_NUM_EXT; + + memcpy(tlb[num].cmd, name, strlen(name) + 1); + memcpy(tlb[num].descption, desc, strlen(desc) + 1); + + tlb[num].wrapper = (OSP_FUNCPTR)osp_ape_shell_wrapper; + //tlb[num].routine = pfunc; + tlb[num].argnum = argnum; + + UCP_PRINT_SHELL("osp_insert_cmd_ext cmd:%s num:%u descption:%s desc:%s argnum:%u", + tlb[num].cmd,num, tlb[num].descption, desc, tlb[num].argnum); + + SHELL_CMD_NUM_EXT++; + + return 0; +} + + +int32_t osp_shell_init(void) +{ + + ospCmdRtnTblExt = (OSP_CMD_RTN *)osp_get_init_mem(sizeof(OSP_CMD_RTN) * MAX_EXT_CMD_NUM); + ospCmdInsertSem = (lx_sem_t *)osp_get_init_mem(sizeof(lx_sem_t)); + + + if (0 == g_ProcessId) + { + memset(ospCmdRtnTblExt, 0, sizeof(OSP_CMD_RTN) *MAX_EXT_CMD_NUM); + osp_semsm_create(ospCmdInsertSem); + } + + /*閰嶇疆鏂囦欢璇诲彇server ip ,port*/ + osp_server_get(); + return 0; +} + +bool osp_is_ape_cmd(char *pCmd) +{ + if(NULL == pCmd) + { + return false; + } + + if (strstr(pCmd, "_ape")) + { + return true; + } + + return false; +} + +void osp_get_ape_id(uint8_t ucApeid) +{ + if (ucApeid > 7) + { + return; + } + + guc_ape_id = ucApeid; + + return; +} + +void osp_set_ape_log_mode(uint8_t ucIsEcho) +{ + if(ucIsEcho > 3) + { + UCP_PRINT_ERROR("osp_set_ape_log_mode error ucIsEcho:%u \n", ucIsEcho); + return; + } + + g_ulApeLogMode = ucIsEcho; + + osp_log_mode_cfg(); + + UCP_PRINT_LOG("osp_set_ape_log_mode g_ulApeLogMode:%u \n", g_ulApeLogMode); +} + +void osp_set_platform_log_mode(uint8_t ucIsEcho) +{ + if(ucIsEcho > 3) + { + UCP_PRINT_ERROR("osp_set_ape_log_mode error ucIsEcho:%u \n", ucIsEcho); + return; + } + + g_ucPlatformMode = ucIsEcho; + + UCP_PRINT_LOG("osp_set_ape_log_mode g_ucPlatformMode:%u \n", g_ucPlatformMode); +} + + +void osp_set_arm_log_mode(uint8_t ucIsNet) +{ + if(ucIsNet > 3) + { + UCP_PRINT_ERROR("osp_set_arm_log_mode error log_mode:%u \n", ucIsNet); + return; + } + + g_ulArmLogMode = ucIsNet; + + osp_log_mode_cfg(); + + UCP_PRINT_LOG("osp_set_arm_log_mode g_ulArmLogMode:%u \n", g_ulArmLogMode); +} + +void osp_reget_ape_cmd() +{ + UCP_PRINT_SHELL("osp_reget_ape_cmd cmd:%s\n", gac_cmd); + SHELL_CMD_NUM_EXT = 0; + + osp_ape_msg_send((char *)gac_cmd); + + return; +} + +void osp_ape_insert_msg_send() +{ + + UCP_PRINT_SHELL("osp_ape_insert_msg_send begin gac_cmd:%s\n", gac_cmd); + osp_ape_msg_send((char *)gac_cmd); + UCP_PRINT_SHELL("osp_ape_insert_msg_send END\n"); + + return; +} + + +void osp_show_ape_taskinfo() +{ + UCP_PRINT_SHELL("osp_show_ape_taskinfo cmd:%s\n", gac_cmd); + + osp_ape_msg_send((char *)gac_cmd); + + return; +} + +void osp_set_print_level(uint8_t ucLevel) +{ + if(ucLevel > 0x10) + { + UCP_PRINT_SHELL("osp_set_print_level leve:%u\n", ucLevel); + return; + } + + guc_print_level = ucLevel; + + return; +} + +void osp_show_print_level() +{ + UCP_PRINT_SHELL("arm print level:0x%x\n", guc_print_level); + + return; +} + +void osp_set_oam(uint8_t ucOam) +{ + if(ucOam > 5) + { + UCP_PRINT_SHELL("osp_set_oam ucOam:%u\n", ucOam); + return; + } + + guc_oam = ucOam; + + return; +} + + +void osp_ape_set_log_level(uint8_t ucLevel) +{ + if(ucLevel > 5) + { + UCP_PRINT_ERROR("osp_ape_set_log_level leve:%u\n", ucLevel); + return; + } + + UCP_PRINT_SHELL("osp_ape_set_log_level begin cmd:%s\n", gac_cmd); + osp_ape_msg_send((char *)gac_cmd); + + return; +} + +void osp_ape_csu_stop_cfg(uint8_t ucstop, uint8_t ucadvance) +{ + char aCmd[32] = {0}; + + if(ucstop > 2) + { + UCP_PRINT_ERROR("osp_csu_stop_cfg ucstop:%u\n", ucstop); + return; + } + + sprintf(aCmd, "%s %u\r\n", gac_cmd, ucstop); + + UCP_PRINT_SHELL("osp_csu_stop_cfg aCmd:%s\n", aCmd); + osp_ape_msg_send((char *)aCmd); + + return; +} + + +void osp_ape_csu_int_cnt() +{ + UCP_PRINT_LOG("osp_show_ape_taskinfo cmd:%s\n", gac_cmd); + + osp_ape_msg_send((char *)gac_cmd); + + return; +} + + +void osp_ape_msg_send(char *pcmd) +{ + uint8_t i = 0; + int8_t *pi8buf = NULL; + uint16_t u16offset = sizeof(osp_sw_msg_info_t); + osp_sw_msg_info_t stMsg; + + if(NULL == pcmd) + { + return; + } + + for(i = 12;i < 24; i++) + { + pi8buf = osp_sw_mem_malloc(i); + if (NULL == pi8buf) + { + UCP_PRINT_ERROR("osp_ape_msg_send call spu_sw_mem_malloc return null\n"); + return ; + } + + memset((char *)stMsg.i8Data, 0, strlen(pcmd)); + + stMsg.u8PktType = UCP4008_OSP_SHELL; + stMsg.u8CoreId = i-12; /*spu core id*/ + stMsg.u16DataLen = sizeof(osp_sw_msg_info_t)+strlen(pcmd); + memcpy((char *)stMsg.i8Data ,pcmd, strlen(pcmd)); + + memcpy((void *)(pi8buf-u16offset), (void *)&stMsg, stMsg.u16DataLen); + + //UCP_PRINT_LOG("u8PktType:%d cmd:%s u8CoreId:%u len:%d\n", stMsg.u8PktType, stMsg.i8Data, stMsg.u8CoreId, stMsg.u16DataLen); + + osp_sw_enque(i, pi8buf); + } + + return; +} +void osp_cmd_register(OSP_CMD_EXT *pCmdExt) +{ + uint32_t num = 0; + uint32_t i = 0; + + if (NULL == pCmdExt) + { + return; + } + + for(i =0; i cmd)) + { + return; + } + } + + num = SHELL_CMD_NUM_EXT; + + strcpy(ospCmdRtnTblExt[num].cmd, pCmdExt->cmd); + + ospCmdRtnTblExt[num].wrapper = (OSP_FUNCPTR)osp_ape_shell_wrapper; + ospCmdRtnTblExt[num].argnum = pCmdExt->argnum; + + SHELL_CMD_NUM_EXT++; + + return ; +} + +#if 0 +void osp_cmd_insert_proc(Osp_Ape_Msg_Head *pMsg) +{ + char *pbuf = NULL; + OSP_CMD_RTN *tlb = NULL; + uint32_t num = 0; + + if (NULL == pMsg) + { + return; + } + + osp_sem_take(ospCmdInsertSem, -1); + + pbuf = APE_MSG_HEAD_TO_COMM(pMsg); + + tlb = (OSP_CMD_RTN *)pbuf; + num = SHELL_CMD_NUM_EXT; + + strcpy(ospCmdRtnTblExt[num].cmd, tlb->cmd); + strcpy(ospCmdRtnTblExt[num].descption, tlb->descption); + ospCmdRtnTblExt[num].wrapper = (OSP_FUNCPTR)osp_ape_shell_wrapper; + ospCmdRtnTblExt[num].argnum = tlb->argnum; + + UCP_PRINT_SHELL("osp_cmd_insert_proc num:%u cmd:%s descption:%s argnum:%u", SHELL_CMD_NUM_EXT, ospCmdRtnTblExt[num].cmd, ospCmdRtnTblExt[num].descption, ospCmdRtnTblExt[num].argnum); + + SHELL_CMD_NUM_EXT++; + osp_sem_give(ospCmdInsertSem); + + return; +} +#endif + +void osp_cmd_insert_proc(osp_sw_msg_info_t *pMsg) +{ + char *pbuf = NULL; + uint32_t ulLen = 0; + OSP_CMD_EXT stCmdExt; + + if (NULL == pMsg) + { + return; + } + + osp_sem_take(ospCmdInsertSem, -1); + + pbuf = SPU_SHELL_MSG_HEAD_TO_COMM(pMsg); + ulLen = SPU_SHELL_MSG_DADA_LEN(pMsg); + + memcpy(&stCmdExt, pbuf, ulLen); + + switch(pMsg->u8CoreId) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + osp_cmd_register(&stCmdExt); + break; + } + + osp_sem_give(ospCmdInsertSem); + + return; +} + +void osp_ape_shell_out(Osp_Ape_Msg_Head *pMsg) +{ +#if 0 + bool bIsApeCmd = false; + + if (NULL == pMsg) + { + return; + } + + UCP_PRINT_LOG("osp_ape_shell_out pMsg:%p MsgType: 0x%x pMsg->msg_size:%u src_core_id: %u", (char *)pMsg,pMsg->msg_type, pMsg->msg_size ,pMsg->src_core_id); + + bIsApeCmd = osp_is_ape_cmd_insert(pMsg); + + switch(pMsg->msg_type) + { + case UCP4008_OSP_SHELL: + case UCP4008_OSP_SHELL_ECHO: + if(true == bIsApeCmd) + { + osp_cmd_insert_proc(pMsg); + break; + } + write(STDOUT_FILENO, APE_MSG_HEAD_TO_COMM(pMsg), APE_MSG_DADA_LEN(pMsg)); + break; + case OSP_STR_LOG: + case OSP_BIN_LOG: + osp_dbg_log_main(pMsg); + break; + default: + UCP_PRINT_ERROR("osp_ape_shell_out pMsg:%p MsgType: 0x%x pMsg->msg_size:%u src_core_id: %u", (char *)pMsg,pMsg->msg_type, pMsg->msg_size ,pMsg->src_core_id); + break; + } +#endif + return; + +} + +void osp_ape_shell_proc(osp_sw_msg_info_t *pMsg) +{ + if (NULL == pMsg) + { + return; + } + + UCP_PRINT_LOG("osp_ape_shell_proc u8PktType:%d cmd:%s u8CoreId:%u u16DataLen:%u\n", pMsg->u8PktType, pMsg->i8Data, pMsg->u8CoreId, pMsg->u16DataLen); + + switch(pMsg->u8PktType) + { + case UCP4008_OSP_SHELL: + case UCP4008_OSP_SHELL_ECHO: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case UCP4008_OSP_SHELL_REG: + osp_cmd_insert_proc(pMsg); + break; + default: + UCP_PRINT_ERROR("osp_ape_shell_proc u8PktType:%d cmd:%s u8CoreId:%u u16DataLen:%u\n", pMsg->u8PktType, pMsg->i8Data, pMsg->u8CoreId, pMsg->u16DataLen); + break; + } + + return; + +} + +void osp_show_info_by_coreid(osp_sw_msg_info_t *pMsg) +{ + if (NULL == pMsg) + { + return; + } + + switch(pMsg->u8CoreId) + { + case 0: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 1: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 2: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 3: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 4: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 5: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 6: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 7: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 8: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 9: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 10: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + case 11: + write(STDOUT_FILENO, pMsg->i8Data, SPU_SHELL_MSG_DADA_LEN(pMsg)); + break; + default: + UCP_PRINT_SHELL("osp_ape_shell_proc u8PktType:%d cmd:%s u8CoreId:%u u16DataLen:%u\n", pMsg->u8PktType, pMsg->i8Data, pMsg->u8CoreId, pMsg->u16DataLen); + break; + } + + return; +} + + +uint64_t osp_shell_task(void) +{ + uint8_t u8loop = 0; + osp_sw_msg_info_t *pstsw_msg = NULL; + static uint32_t su32LogCnt = 0; + + ++su32LogCnt; + //printf("LogTask Enter >>> %d\r\n", su32LogCnt); + + /* 浠庤蒋闃熷垪閲屽彇鍑 */ + for(u8loop = 24; u8loop < 36; u8loop++) + { + while(OSP_OK == osp_sw_deque(u8loop, &pstsw_msg)) + { + UCP_PRINT_LOG("u8loop = %d, addr = %p, len = %d, coreid = %d, type = %d\r\n", u8loop, pstsw_msg, pstsw_msg->u16DataLen, pstsw_msg->u8CoreId, pstsw_msg->u8PktType); + osp_ape_shell_proc(pstsw_msg); + } + } + + usleep(10); + + return OSP_OK; +} + +uint32_t rev_shell_log_data(uint32_t port_id,uint32_t queue_num,uint32_t el_ind,const char* buf,uint32_t remainedLength,uint32_t* handledLength) +{ +#if 0 + //osp_get_current_time(); + //UCP_PRINT_DEBUG("rev_shell_log_data begin %s\n", g_time_now); + Osp_Ape_Msg_Head *pMsg = NULL; + + if(NULL == buf) + { + return 1; + } + + pMsg = (Osp_Ape_Msg_Head*)buf; + *handledLength = pMsg->msg_size; + + /*闃熷垪UCP4008_TRAFFIC_LOG*/ + if(7 == queue_num) + { + UCP_PRINT_LOG("rev_shell_log_data queue_num[%u] el_ind[%u] buf[%p]!\n", queue_num, el_ind, buf); + osp_ape_shell_out(pMsg); + osp_msg_transfer_free(7, 0, (char *)pMsg); + } + else + { + UCP_PRINT_LOG("rev_shell_log_data free queue_num[%u] el_ind[%u] buf[%p]!\n", queue_num, el_ind, buf); + /*閲婃斁UCP4008_TRAFFIC_LOG*/ + osp_msg_transfer_free(7, 0, (char *)pMsg); + } + + //osp_get_current_time(); + //UCP_PRINT_SHELL("rev_shell_log_data end %s\n", g_time_now); +#endif + return 0; +} + + +void osp_show_queue_ul_info() +{ + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + uint8_t i,j; + + printf("inst_id\tque_id\t\ttype_id\t\talloc\t\tape_tx_num\t\tarm_rx_num\n\r"); + + for (i = 0; i < MAX_INSTANCE_NUM; i++) { + for (j = 0; j < UCP4008_TRAFFIC_MAX_NUM; j++) { + printf("%d %d\t\t%-4d\t\t%4d\t\t%4d\t\t\t%4d\n", i, j, pPetSmLocalMgt->pQueueCfg[i][j]->handler.type_id, pPetSmLocalMgt->pUlQueue[i][j]->alloc, pPetSmLocalMgt->pUlQueue[i][j]->in, pPetSmLocalMgt->pUlQueue[i][j]->out); + } + } + + return; +} + +void osp_show_queue_dl_info() +{ + PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt(); + uint8_t i,j; + + printf("inst_id\tque_id\t\ttype_id\t\talloc\t\tarm_tx_num\t\tape_rx_num\n\r"); + + for (i = 0; i < MAX_INSTANCE_NUM; i++) { + for (j = 0; j < UCP4008_TRAFFIC_MAX_NUM; j++) { + printf("%d %d\t\t%-4d\t\t%4d\t\t%4d\t\t\t%4d\n", i, j, pPetSmLocalMgt->pQueueCfg[i][j]->handler.type_id, pPetSmLocalMgt->pDlQueue[i][j]->alloc, pPetSmLocalMgt->pDlQueue[i][j]->in, pPetSmLocalMgt->pDlQueue[i][j]->out); + } + } + + return; +} + +int8_t osp_server_cfg(uint8_t *ip, uint32_t ulport) +{ + int8_t ret = 0; + FILE *fp = NULL; + + if(NULL == ip) + { + UCP_PRINT_SHELL("ip is null"); + return ret; + } + + memcpy(gst_server_log.ip, ip, 15); + gst_server_log.ulport = ulport; + + if (access("./server", F_OK) != 0) + { + osp_mkdirs("./server", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + fp = fopen("./server/logmode", "w+"); + if (fp < 0) + { + UCP_PRINT_ERROR("osp_server_cfg file open failure \n"); + return ret; + } + + ret = fprintf(fp,"ip:%s\r\nport:%u\napelog:%u\narmlog:%u\nlogpath:%s", \ + gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, \ + gst_server_log.path); + if(ret < 0) + { + UCP_PRINT_ERROR("fwrite error ret:%d\n", ret); + fclose(fp); + return ret; + } + + fflush(fp); + fclose(fp); + + return ret; +} + +void osp_server_cfg_show() +{ + UCP_PRINT_SHELL("ip:%s\nport:%u\napelog:%u\narmlog:%u\nlogpath:%s\n", \ + gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, gst_server_log.path); + + return; +} + + +void osp_log_path_cfg(char *path) +{ + int32_t ret = 0; + FILE *fp = NULL; + + if(NULL == path) + { + UCP_PRINT_SHELL("path is null"); + return; + } + + if (access(path, F_OK) != 0) + { + osp_mkdirs(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + memset(gst_server_log.path, 0, 128); + sprintf((char *)gst_server_log.path, "%s", path); + + if (access(LOG_MODE_PATH, F_OK) != 0) + { + osp_mkdirs(LOG_MODE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + fp = fopen(LOG_MODE_PATH, "w+"); + if (fp < 0) + { + UCP_PRINT_ERROR("osp_server_cfg file open failure \n"); + return; + } + + ret = fprintf(fp,"ip:%s\r\nport:%u\napelog:%u\narmlog:%u\nlogpath:%s", \ + gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, gst_server_log.path); + if(ret < 0) + { + UCP_PRINT_ERROR("fwrite error ret:%d\n", ret); + fclose(fp); + return; + } + + fflush(fp); + fclose(fp); + + sleep(1); + osp_log_cfg_reload(); + + return; +} + + + +void osp_server_get() +{ + FILE *fp = NULL; + + if (access("./server", F_OK) != 0) + { + osp_mkdirs("./server", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + fp = fopen("./server/logmode", "r+"); + if (NULL == fp) + { + UCP_PRINT_ERROR("osp_server_get file open failure \n"); + return; + } + + fscanf(fp,"%s %d\n", gst_server_log.ip, &gst_server_log.ulport); + + /*ret = fread((char *)&gst_server_log, sizeof(char), sizeof(Osp_Server_Head), fp); + if(ret < 0) + { + UCP_PRINT_ERROR("fwrite read ret:%d\n", ret); + fclose(fp); + return ret; + }*/ + + fclose(fp); + + return; +} + + +int32_t osp_shell_main() +{ + struct termios nt; + int32_t ret; + char shellbuf[MAX_CMD_LEN] = {0}; + tcgetattr(STDIN_FILENO, &saveterm); + nt = saveterm; + nt.c_lflag &= (~ICANON); + nt.c_lflag &= (~ECHO); + nt.c_cc[VMIN] = 1; + nt.c_cc[VTIME] = 0; + tcsetattr(STDIN_FILENO, TCSANOW, &nt); + + //arg = (char **)malloc(maxCmdField * sizeof(arg[0])); + arg = (char **)gul_arg; + + osp_set_prompt(); + { + osp_shell_get_line(); + memcpy(shellbuf, szCmdNow, strlen(szCmdNow)); + shellbuf[strlen(szCmdNow)] = '\0'; + + osp_getcmdarg(szCmdNow); + ret = osp_execcmd(); + + if (OSP_ERROR == ret) + { + system(shellbuf); + } + } + //free(arg); + + return ret; +} + +#if 0 +void osp_get_tfu_location_info( ) +{ + location_info_s stlocat_ptr; + + get_tfu_location_info(&stlocat_ptr); + + UCP_PRINT_SHELL("latitude:%d longitude:%d altitude:%d\n\r",stlocat_ptr.latitude, stlocat_ptr.longitude, stlocat_ptr.altitude); + + return; +} + +void osp_get_clock_tracking_state(void) +{ + int32_t u32ret = 0; + tracking_info_s sttrk_ptr; + + u32ret = get_clock_tracking_state(&sttrk_ptr); + if(OSP_OK != u32ret) + { + return; + } + + UCP_PRINT_SHELL("lock_flag:%d leap_valid:%d view_sats:%d\n\r",sttrk_ptr.lock_flag, sttrk_ptr.leap_valid, sttrk_ptr.view_sats); + UCP_PRINT_SHELL("track_sats:%d survey_in:%d alma_complete:%d\n\r",sttrk_ptr.track_sats, sttrk_ptr.survey_in, sttrk_ptr.alma_complete); + + return; +} + +void osp_reset_clock_module(void) +{ + int32_t i32ret = 0; + + i32ret = reset_clock_module(); + if(OSP_OK != i32ret) + { + UCP_PRINT_SHELL("i32ret:%d\n\r", i32ret); + return; + } + + return; +} + +void osp_set_clk_mode(clk_flag_e pseudo_flag) +{ + if(pseudo_flag > 1) + { + UCP_PRINT_SHELL("pseudo_flag :%d should be 0 or 1\n\r", pseudo_flag); + return; + } + + set_clk_mode(pseudo_flag); + + return; +} +#endif +void osp_show_swqueue_info() +{ + uint8_t i; + uint16_t u16Size = SPU_SW_QUEUE_SHARE_INFO_SIZE; + + spu_sw_queue_share_info_t *pstsw_queue_share_ture = NULL; + spu_sw_queue_share_info_t *pstsw_queue_share_base = (spu_sw_queue_share_info_t*)gpsw_que_share_mem; + + printf("queue\tdeque_id\tenque_id\talloc_id\tfree_id\n\r"); + + for (i = 12; i < 24; i++) + { + pstsw_queue_share_ture = (spu_sw_queue_share_info_t*)((int8_t*)pstsw_queue_share_base + i*u16Size); + printf("%d\t%4d\t\t%4d\t\t%4d\t\t%4d\n", + i, + pstsw_queue_share_ture->u16queue_deque_idx, + pstsw_queue_share_ture->u16queue_enque_idx, + pstsw_queue_share_ture->u16queue_alloc_idx, + pstsw_queue_share_ture->u16queue_free_idx); + } + + return; +} + + + diff --git a/osp/src/ospSoftQue.c b/osp/src/ospSoftQue.c new file mode 100644 index 0000000..4360a2c --- /dev/null +++ b/osp/src/ospSoftQue.c @@ -0,0 +1,209 @@ +#include +#include +#include +#include + + + + +#include "osp.h" + + +/* + Dep must be Power of 2 +*/ +int32_t osp_create_softque(Osp_SoftQue *que, int32_t Dep, char *name) +{ + static int32_t id = 0; + void *p; + + if (!OSP_IS_POWEOF2(Dep)) + { + return -1; + } + p = osp_semsm_create(&que->mutex); + if (NULL == p) + { + return -1; + } + que->Id = id++; + strcpy(que->Name, name); + que->EnIdx = 0; + que->DeIdx = 0; + que->Dep = Dep; + que->CurNum = 0; + que->EnCnt = 0; + que->DeCnt = 0; + que->FullCnt = 0; + que->EmptyCnt = 0; + que->Mask = que->Dep-1; + + p = osp_semss_create(&que->sem); + if (NULL == p) + { + return -1; + } + + return que->Id; +} + + +int32_t osp_soft_que_enque(uint64_t value, Osp_SoftQue *que, int32_t IsNeedWake) +{ + + int32_t CurNum; + + osp_sem_take(&que->mutex, -1); + CurNum = que->CurNum; + if (CurNum == que->Dep)/*full */ + { + que->FullCnt ++; + osp_sem_give(&que->mutex); + return -1; + } + que->Buf[que->EnIdx] = value; + que->EnIdx = (que->EnIdx + 1) & (que->Mask); + osp_atomic_inc((int32_t *)&que->CurNum); + que->EnCnt ++; + osp_sem_give(&que->mutex); + + if (IsNeedWake) + { + osp_sem_give(&que->sem); + } + return 0; + + +} + +int32_t osp_softque_deque(uint64_t *pvalue, Osp_SoftQue *que, int32_t IsBlock) +{ + int32_t CurNum; + + if (IsBlock) + { + osp_sem_take(&que->sem,-1); + } + + osp_sem_take(&que->mutex, -1); + + CurNum = que->CurNum; + if (CurNum == 0)/*empty*/ + { + que->EmptyCnt ++; + osp_sem_give(&que->mutex); + return -1; + } + *pvalue = que->Buf[que->DeIdx]; + que->DeIdx = (que->DeIdx + 1) & que->Mask; + osp_atomic_dec((int32_t *)&que->CurNum); + que->DeCnt ++; + osp_sem_give(&que->mutex); + + return 0; + +} + +int32_t osp_softque_dequetry(uint64_t *pvalue, Osp_SoftQue *que) +{ + int32_t ret; + int32_t CurNum; + + + ret = osp_sem_taketry(&que->sem); + if (0 != ret) + { + return ret; + } + + CurNum = que->CurNum; + if (CurNum == 0)/*empty*/ + { + que->EmptyCnt ++; + + return -1; + } + *pvalue=que->Buf[que->DeIdx]; + que->DeIdx = (que->DeIdx + 1) & que->Mask; + osp_atomic_dec((int32_t *)&que->CurNum); + que->DeCnt ++; + + return 0; + +} + +int32_t osp_softque_dequeTimeOut(uint64_t *pvalue, Osp_SoftQue *que, uint32_t timeout) +{ + int32_t ret; + int32_t CurNum; + + ret = osp_sem_take(&que->sem, timeout); + if (0 != ret) + { + return ret; + } + + CurNum = que->CurNum; + if (CurNum == 0)/*empty*/ + { + que->EmptyCnt ++; + + return -1; + } + *pvalue = que->Buf[que->DeIdx]; + que->DeIdx = (que->DeIdx + 1)&que->Mask; + osp_atomic_dec((int32_t*)&que->CurNum); + que->DeCnt ++; + + return 0; + +} + +int32_t osp_soft_que_is_vaild(Osp_SoftQue *que) +{ + return ((que->Dep) != 0); +} + +int32_t osp_get_soft_que_desc(char *pbuf) +{ + int32_t len = 0; + osp_assert(pbuf != NULL); + + len = sprintf(pbuf, "%-8s%-24s%-12s%-12s%-12s%-12s%-12s%-12s%-12s%-12s%-12s\n", "Id", "Name", "EnIdx", + "DeIdx", "Dep", "CurNum", "EnCnt", "DeCnt", "FullCnt", "EmptyCnt", "Mask"); + + return len; +} + +int32_t osp_get_soft_que_info(Osp_SoftQue *que, char *pbuf) +{ + int32_t len = 0; + + osp_assert(pbuf != NULL); + + if (osp_soft_que_is_vaild(que)) + { + + + len += sprintf(pbuf + len, "%-8d%-24s%-12d%-12d%-12d%-12d%-12lu%-12lu%-12lu%-12lu%-12d\n", + que->Id, que->Name, + que->EnIdx, + que->DeIdx, + que->Dep, + que->CurNum, + que->EnCnt, + que->DeCnt, + que->FullCnt, + que->EmptyCnt, + que->Mask); + }; + return len; + +} + + + + + + + diff --git a/osp/src/ospSwQueue.c b/osp/src/ospSwQueue.c new file mode 100644 index 0000000..53c3881 --- /dev/null +++ b/osp/src/ospSwQueue.c @@ -0,0 +1,170 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : ospSwQueue.c +// Author : +// Created On : 2023-01-19 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#include +#include +#include "ospTypes.h" +#include "ospSwQueue.h" +#include "ospHeap.h" +#include "ucp_printf.h" + +#define OSP_APE_RFM_LOG_OFFSET (0x0AE00000) /* APE_LOG璧峰鍦板潃涓猴細0xA800 0000 ,Log鐨勫疄闄呭湴鍧涓猴細0xB2E00000 */ +#define OSP_APE_RFM_LOG_SIZE (0x00080000) /* Log杞欢闃熷垪涓涓槦鍒楃殑鎬诲唴瀛(512K) */ + +#define OSP_APE_RFM_SHELL_OFFSET (0x0B600000)//(0x00800000) +#define OSP_APE_RFM_SHELL_SIZE (0x00001000) /* Shell杞欢闃熷垪涓涓槦鍒楃殑鎬诲唴瀛(512*8) */ + +#define OSP_APE_RFM_QUE_NUM (36) /* 涓鍏36涓蒋鍒楅槦 */ + +#define OSP_APE_SHARE_OFFSET (0x0B618000)//(0x00818000) + +#define SPU_APE_RFM_QUE_FLAG_USED (0x5a5a) +#define SPU_APE_FRM_QUE_FLAG_POS (2) + +void *gpsw_que_share_mem = NULL; +void *gpsw_que_static_mem = NULL; +uint64_t gsw_que_static_mem_size = 0; +spu_sw_queue_mem_t gstsw_queue_mem[OSP_APE_RFM_QUE_NUM]; +spu_sw_queue_share_info_t gstsw_queue_share_info[OSP_APE_RFM_QUE_NUM] = {0}; + +uint8_t osp_sw_queue_mem_init(void) +{ + gsw_que_static_mem_size = 0; + + gpsw_que_static_mem = get_static_mem(APE_LOG, &gsw_que_static_mem_size); + if (0 == gsw_que_static_mem_size) + { + UCP_PRINT_ERROR("[osp_sw_queue_mem_init]: get_static_mem(APE_LOG) return error."); + return OSP_ERROR; + } + gpsw_que_share_mem = gpsw_que_static_mem + OSP_APE_SHARE_OFFSET; + return OSP_OK; +} + +uint8_t osp_sw_queue_init() +{ + uint8_t u8ret = 0; + uint8_t u8loop = 0; + void* pvlog_addr = NULL; + + memset(&gstsw_queue_mem, 0, sizeof(gstsw_queue_mem)); + memset(&gstsw_queue_share_info, 0, sizeof(gstsw_queue_share_info)); + + u8ret = osp_sw_queue_mem_init(); + if (OSP_OK != u8ret) + { + UCP_PRINT_ERROR("[osp_sw_queue_init]: osp_sw_queue_mem_init return error."); + return OSP_ERROR; + } + + /* 鍒濆鍖 */ + /* APE_RFM_LOG */ + pvlog_addr = gpsw_que_static_mem + OSP_APE_RFM_LOG_OFFSET; + for (u8loop = 0; u8loop < OSP_APE_RFM_LOG_NUM; u8loop++) + { + gstsw_queue_mem[u8loop].pvaddr = pvlog_addr + (u8loop*OSP_APE_RFM_LOG_SIZE); + gstsw_queue_mem[u8loop].u16queue_id = u8loop; + gstsw_queue_mem[u8loop].u16queue_type = OSP_SW_QUEUE_LOG; + gstsw_queue_mem[u8loop].u8queue_offset = 8; + gstsw_queue_mem[u8loop].u16queue_dep = OSP_APE_RFM_MSG_QUE_DEP; + gstsw_queue_mem[u8loop].u16queue_mask = (OSP_APE_RFM_MSG_QUE_DEP - 1); + gstsw_queue_mem[u8loop].u16queue_mem_idx = 0; + gstsw_queue_mem[u8loop].u32queue_full_count = 0; + gstsw_queue_mem[u8loop].u32queue_empty_count = 0; + } + + /* APE_RFM_SHELL */ + pvlog_addr = gpsw_que_static_mem + OSP_APE_RFM_SHELL_OFFSET; + for (u8loop = 0; u8loop < OSP_APE_RFM_SHELL_NUM; u8loop++) + { + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].pvaddr = pvlog_addr + (u8loop*OSP_APE_RFM_SHELL_SIZE); + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u16queue_id = (OSP_APE_RFM_LOG_NUM + u8loop); + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u16queue_type = OSP_SW_QUEUE_SHELL; + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u8queue_offset = 8; + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u16queue_dep = OSP_APE_RFM_SHELL_QUE_DEP; + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u16queue_mask = (OSP_APE_RFM_SHELL_QUE_DEP - 1); + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u16queue_mem_idx = 0; + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u32queue_full_count = 0; + gstsw_queue_mem[u8loop+OSP_APE_RFM_LOG_NUM].u32queue_empty_count = 0; + } + return OSP_OK; +} + +int8_t *osp_sw_mem_malloc(osp_sw_queue_index_e emqueue_idx) +{ + uint64_t u64addr = 0; + u64addr = (uint64_t)((gstsw_queue_mem[emqueue_idx].u16queue_mem_idx << 9) + gstsw_queue_mem[emqueue_idx].pvaddr); + gstsw_queue_mem[emqueue_idx].u16queue_mem_idx = (gstsw_queue_mem[emqueue_idx].u16queue_mem_idx + 1)&(gstsw_queue_mem[emqueue_idx].u16queue_mask); + return ((int8_t*)(u64addr + (gstsw_queue_mem[emqueue_idx].u8queue_offset))); +} + +uint8_t osp_sw_enque(osp_sw_queue_index_e emqueue_idx, int8_t *pi8addr) +{ + uint16_t u16Size = SPU_SW_QUEUE_SHARE_INFO_SIZE; + uint16_t u16enque_idx = ((uint64_t)(pi8addr) - (uint64_t)(gstsw_queue_mem[emqueue_idx].pvaddr) - gstsw_queue_mem[emqueue_idx].u8queue_offset)/SPU_APE_RFM_QUE_SIG_SIZE; + uint16_t u16queue_enque_idx = 0; + + spu_sw_queue_share_info_t *pstsw_queue_share_ture = NULL; + spu_sw_queue_share_info_t *pstsw_queue_share_base = (spu_sw_queue_share_info_t*)gpsw_que_share_mem; + pstsw_queue_share_ture = (spu_sw_queue_share_info_t*)((int8_t*)pstsw_queue_share_base + emqueue_idx*u16Size); + + if ((pstsw_queue_share_ture->u16queue_enque_idx - pstsw_queue_share_ture->u16queue_deque_idx) >= gstsw_queue_mem[emqueue_idx].u16queue_dep) + { + gstsw_queue_mem[emqueue_idx].u32queue_full_count++; + UCP_PRINT_LOG("[osp_sw_enque]: queue[%d] is full.", emqueue_idx); + return 3; + } + + u16queue_enque_idx = (pstsw_queue_share_ture->u16queue_enque_idx)&(gstsw_queue_mem[emqueue_idx].u16queue_mask); + pstsw_queue_share_ture->u16queue_msg[u16queue_enque_idx] = u16enque_idx; + pstsw_queue_share_ture->u16queue_enque_idx = (pstsw_queue_share_ture->u16queue_enque_idx + 1); + //pstsw_queue_share_ture->u16queue_enque_idx = (pstsw_queue_share_ture->u16queue_enque_idx + 1)&(gstsw_queue_mem[emqueue_idx].u16queue_mask); + //pstsw_queue_share_ture->u16queue_enque_count++; + return 0; + +} + +uint8_t osp_sw_deque(osp_sw_queue_index_e emqueue_idx, osp_sw_msg_info_t **pstmsg_info) +{ + uint16_t u16Size = SPU_SW_QUEUE_SHARE_INFO_SIZE; + uint16_t u16queue_msg_idx = 0; + uint16_t u16queue_deque_idx = 0; + + spu_sw_queue_share_info_t *pstsw_queue_share_ture = NULL; + spu_sw_queue_share_info_t *pstsw_queue_share_base = (spu_sw_queue_share_info_t*)gpsw_que_share_mem; + pstsw_queue_share_ture = (spu_sw_queue_share_info_t*)((int8_t*)pstsw_queue_share_base + emqueue_idx*u16Size); + + u16queue_deque_idx = pstsw_queue_share_ture->u16queue_deque_idx&(gstsw_queue_mem[emqueue_idx].u16queue_mask); + if (pstsw_queue_share_ture->u16queue_deque_idx == pstsw_queue_share_ture->u16queue_enque_idx) + { + //UCP_PRINT_ERROR("[osp_sw_deque]: queue[%d] is empty.", emqueue_idx); + return 4; + } + + u16queue_msg_idx = pstsw_queue_share_ture->u16queue_msg[u16queue_deque_idx]; + + /*printf("[deque]: idx = %d, d_idx = %d, e_idx = %d, addr = %p\r\n", + u16queue_msg_idx, + //pstsw_queue_share_ture->u16queue_alloc_idx, + pstsw_queue_share_ture->u16queue_deque_idx, + //pstsw_queue_share_ture->u16queue_deque_count, + pstsw_queue_share_ture->u16queue_enque_idx, + //pstsw_queue_share_ture->u16queue_enque_count, + gstsw_queue_mem[emqueue_idx].pvaddr);*/ + + *pstmsg_info = (osp_sw_msg_info_t*)((gstsw_queue_mem[emqueue_idx].pvaddr) + (u16queue_msg_idx*SPU_APE_RFM_QUE_SIG_SIZE)); + pstsw_queue_share_ture->u16queue_deque_idx = (pstsw_queue_share_ture->u16queue_deque_idx + 1); + return 0; +} + + diff --git a/osp/src/ospSwTimer.c b/osp/src/ospSwTimer.c new file mode 100644 index 0000000..f21155f --- /dev/null +++ b/osp/src/ospSwTimer.c @@ -0,0 +1,189 @@ +#include "ospTypes.h" +#include "ospSwTimer.h" +#include "ospSem.h" +#include "ucp_printf.h" +#include + +#define OSP_TMR_TIME_SET (1000) + +OspSwTimer_t gOspSwTmrList[OSP_SW_TIMER_NUM]; +lx_sem_t * gOspSwTmrSem = NULL; + +static void OspCheckTimer(OspSwTimer_t *pOspSwTimer) +{ + if (NULL == pOspSwTimer) + { + UCP_PRINT_ERROR("OspCheckTimer input parameter is NULL.\r\n"); + return ; + } + + if (OSP_TMR_FREE == pOspSwTimer->u8Using) + { + return ; + } + + /* 鍒ゅ畾瀹氭椂鏃堕棿 */ + if (OSP_TMR_TIME_SET <= pOspSwTimer->u32RealTime) + { + /* 鏃堕棿鏈埌 */ + pOspSwTimer->u32RealTime = pOspSwTimer->u32RealTime - OSP_TMR_TIME_SET; + } + else + { + /* 鏍规嵁瀹氭椂鍣ㄧ被鍨嬶紝淇敼瀹氭椂鍣ㄧ姸鎬 */ + if (OSP_TMR_ONESHOT == pOspSwTimer->emTmrType) + { + /* 涓娆℃у畾鏃跺櫒锛屽垯淇敼瀹氭椂鍣ㄧ姸鎬 */ + pOspSwTimer->emTmrStatus = OSP_TMR_STOPED; + pOspSwTimer->u32RealTime = 0; + } + else + { + /* 鍛ㄦ湡鎬у畾鏃跺櫒锛屽垯淇敼瀹氭椂鍣ㄧ殑鏃堕棿 */ + pOspSwTimer->u32RealTime = pOspSwTimer->u32TimeOut; + } + + /* 瀹氭椂鍒帮紝璋冪敤娉ㄥ唽鏃剁殑瀹氭椂鍣ㄥ洖璋冨嚱鏁 */ + return pOspSwTimer->pfnTmrCallBack(pOspSwTimer->pArg); + } + return ; +} + +static void OspTmrProc(void) +{ + uint8_t u8Loop = 0; + for (u8Loop = 0; u8Loop < OSP_SW_TIMER_NUM; u8Loop++) + { + OspCheckTimer(&gOspSwTmrList[u8Loop]); + } +} + +uint64_t OspTimerTask(void) +{ + if (NULL == gOspSwTmrSem) + { + UCP_PRINT_ERROR("OspTimerTask gOspSwTmrSem is NULL.\r\n"); + return -OSP_ERROR; + } + osp_sem_take(gOspSwTmrSem, OSP_TMR_TIME_SET); + //UCP_PRINT_ERROR("OspTimerTask osp_sem_take return %d\r\n", ret); + OspTmrProc(); + return OSP_OK; +} + +/* 瀹氭椂鍣ㄥ垵濮嬪寲鍑芥暟锛氬厛鍒濆鍖栧畾鏃舵ā鍧楋紝鍚庡垱寤轰换鍔 */ +int8_t OspTmrInit() +{ + /* 鍒涘缓瀹氭椂鐐归摼琛 */ + memset(gOspSwTmrList, 0, sizeof(gOspSwTmrList)); + + /* 鍒涘缓瀹氭椂鐐逛俊鍙烽噺 */ + gOspSwTmrSem = osp_semc_create(0); + if (NULL == gOspSwTmrSem) + { + UCP_PRINT_ERROR("OspTmrInit call osp_semc_create return NULL.\r\n"); + return OSP_ERROR; + } + return OSP_OK; +} + +/* 鍒涘缓瀹氭椂鍣 */ +int8_t OspTmrCreate(const char* pu8Name, + uint32_t u32TimeOut, + OspTmrType emTmrType, + OSP_CALLBACK pfnTmrCallBack, + void* pArg) +{ + uint8_t u8Loop = 0; + uint32_t u32TimerLen = 0; + + /* 鎵炬槸鍚︽湁绌洪棽瀹氭椂鍣 */ + for (u8Loop = 0; u8Loop < OSP_SW_TIMER_NUM; u8Loop++) + { + if (OSP_TMR_FREE == gOspSwTmrList[u8Loop].u8Using) + { + u32TimerLen = (uint32_t)strlen(pu8Name); + u32TimerLen = OSP_GET_MIN(u32TimerLen, (OSP_SW_TIMER_NAME_LEN-1)); + memcpy(gOspSwTmrList[u8Loop].u8TmrName, pu8Name, u32TimerLen); + + gOspSwTmrList[u8Loop].u32RealTime = u32TimeOut; /* 鍓╀綑鏃堕棿=瓒呮椂鏃堕棿 */ + gOspSwTmrList[u8Loop].u32TimeOut = u32TimeOut; /* 瓒呮椂鏃堕棿 */ + gOspSwTmrList[u8Loop].emTmrStatus = emTmrType; + gOspSwTmrList[u8Loop].pfnTmrCallBack = pfnTmrCallBack; + gOspSwTmrList[u8Loop].pArg = pArg; + gOspSwTmrList[u8Loop].emTmrStatus = OSP_TMR_STOPED; + gOspSwTmrList[u8Loop].u8Using = OSP_TMR_BUSY; + + return (u8Loop); + } + } + UCP_PRINT_DEBUG("OspTmrCreate no timer free.\r\n"); + return OSP_ERROR; +} + +/* 鍒犻櫎瀹氭椂鍣 */ +int8_t OspTmrDelete(uint8_t u8TmrIndex) +{ + if (u8TmrIndex > OSP_SW_TIMER_NUM) + { + UCP_PRINT_ERROR("OspTmrDelete input parameter is error(%d).\r\n", u8TmrIndex); + return OSP_ERROR; + } + + if (OSP_TMR_FREE == gOspSwTmrList[u8TmrIndex].u8Using) + { + UCP_PRINT_ERROR("OspTmrDelete TmrIndex(%d) is free. Can't delete.\r\n", u8TmrIndex); + return OSP_ERROR; + } + + memset(&(gOspSwTmrList[u8TmrIndex]), 0, sizeof(OspSwTimer_t)); + return OSP_OK; +} + +/* 鍚姩瀹氭椂鍣 */ +int8_t OspTmrStart(uint8_t u8TmrIndex) +{ + if (u8TmrIndex > OSP_SW_TIMER_NUM) + { + UCP_PRINT_ERROR("OspTmrStart input parameter is error(%d).\r\n", u8TmrIndex); + return OSP_ERROR; + } + + /* 濡傛灉瀹氭椂鍣ㄥ凡缁忚繍琛岋紝鐩存帴杩斿洖 */ + if (OSP_TMR_RUNING == gOspSwTmrList[u8TmrIndex].emTmrStatus) + { + return OSP_OK; + } + + /* 鏇存柊瀹氭椂鍣ㄥ畾鏃舵椂闂 */ + gOspSwTmrList[u8TmrIndex].u32RealTime = gOspSwTmrList[u8TmrIndex].u32TimeOut; + + /* 鏇存柊瀹氭椂鍣ㄧ姸鎬 */ + gOspSwTmrList[u8TmrIndex].emTmrStatus = OSP_TMR_RUNING; + return OSP_OK; +} + +/* 鍋滄瀹氭椂鍣 */ +int8_t OspTmrStop(uint8_t u8TmrIndex) +{ + if (u8TmrIndex > OSP_SW_TIMER_NUM) + { + UCP_PRINT_ERROR("OspTmrStop input parameter is error(%d).\r\n", u8TmrIndex); + return OSP_ERROR; + } + + /* 濡傛灉瀹氭椂鍣ㄥ凡缁忚繍琛岋紝鐩存帴杩斿洖 */ + if (OSP_TMR_STOPED == gOspSwTmrList[u8TmrIndex].emTmrStatus) + { + return OSP_OK; + } + + /* 鏇存柊瀹氭椂鍣ㄥ畾鏃舵椂闂 */ + gOspSwTmrList[u8TmrIndex].u32RealTime = gOspSwTmrList[u8TmrIndex].u32TimeOut; + + /* 鏇存柊瀹氭椂鍣ㄧ姸鎬 */ + gOspSwTmrList[u8TmrIndex].emTmrStatus = OSP_TMR_STOPED; + return OSP_OK; +} + + diff --git a/osp/src/ospTask.c b/osp/src/ospTask.c new file mode 100644 index 0000000..f1a859a --- /dev/null +++ b/osp/src/ospTask.c @@ -0,0 +1,534 @@ +#define _GNU_SOURCE + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ucp_printf.h" +#include "ospLog.h" +#include "osp.h" + + +void *g_SemStartWork; +void *g_SemRegTask; + +OSP_TASKCB *gOspTask; + +extern OSP_UDP_TASK_DATA udp_shell_rx_task; +#ifdef HEARTBEAT_ENABLE +extern uint64_t OspTimerTask(void); +#endif +int32_t osp_task_is_shell(uint32_t taskid) +{ + return gOspTask[taskid].is_shell; +} +void osp_set_task_shell(uint32_t taskid) +{ + gOspTask[taskid].is_shell = 1; +} +int32_t osp_task_is_reged(uint32_t taskid) +{ + return gOspTask[taskid].Active; +} + +int32_t osp_local_shell_task_is_reged(void) +{ + return osp_task_is_reged(localshellin); +} + +int32_t osp_set_cpu(int32_t i) +{ + if (OSP_NO_AFFIINITY == i) + { + return 0; + } + else + { + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(i, &mask); + osp_assert(0 == pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask)); + return 0; + } +} + +OSP_TASKMSG_REG g_TaskRegTbl[] = +{ + //{DbgLogTask, "OspDbglog", NOMARL_MSG_PRI(7), NULL, (OSP_FUNCPTR)osp_dbg_log_main, 0, OSP_PROCESS_MSG}, + //{localshellout, "localshellout", RT_MSG_PRI(10), NULL, (OSP_FUNCPTR)osp_local_shell_out_main, 0, OSP_PROCESS_MSG}, + {localshellin, "localshellin", RT_NOMSG_PRI(98), NULL, (OSP_FUNCPTR)osp_shell_main, 0, OSP_PROCESS_MSG}, + {remoteshellout, "remoteshellout", RT_NOMSG_PRI(98), NULL, (OSP_FUNCPTR)osp_shell_task, 0, OSP_OTHER_MSG}, + {OspTickLess, "OspTickLess", RT_NOMSG_PRI(20), NULL, (OSP_FUNCPTR)osp_tick_less, 1, OSP_PROCESS_MSG}, +#ifdef HEARTBEAT_ENABLE + {OspTmrTask, "OspTmrTask", RT_NOMSG_PRI(99), NULL, (OSP_FUNCPTR)OspTimerTask, 2, OSP_OTHER_MSG}, +#endif + {OspDbgLog, "OspLogTask", RT_NOMSG_PRI(75), NULL, (OSP_FUNCPTR)osp_oam_msg_proc_task, 0, OSP_OTHER_MSG}, + //{ospnetshellrx, "ospnetshellrx", NOMARL_MSG_PRI(6), (OSP_FUNCPTR)osp_net_shell_init, (OSP_FUNCPTR)osp_net_shell_main, 0, OSP_UDP_MSG, (U64)&udp_shell_rx_task}, + +}; + +__thread __typeof__(uint32_t) thread_local_TaskId = 0; + +const char *g_OspSoPath = {"/usr/lib/libosp.so"}; +extern const char *g_UserSoPath; +uint32_t g_OspSoNum = 2; + +void *osp_find_sym(char *pName) +{ + void *handle = NULL; + void *pSym = NULL; + + + { + handle = dlopen(g_OspSoPath, RTLD_NOW); + if (NULL == handle) + { + UCP_PRINT_ERROR("%s %s \r\n", g_OspSoPath, strerror(errno)); + //osp_debug_out_with_time(ERR_DEBUG_LEVEL, "%s %s \r\n", g_OspSoPath, strerror(errno)); + } + else + { + pSym = dlsym(handle, pName); + if (pSym) + return pSym; + } + } + +#if 0 + { + handle = dlopen(g_UserSoPath, RTLD_NOW); +// handle = dlopen(USER_SO_PATH, RTLD_NOW); + if (NULL == handle) + { +// osp_debug_out_with_time(ERR_DEBUG_LEVEL, "%s %s \r\n", USER_SO_PATH, strerror(errno)); + osp_debug_out_with_time(ERR_DEBUG_LEVEL, "%s %s \r\n", g_UserSoPath, strerror(errno)); + } + else + { + pSym = dlsym(handle, pName); + if (pSym) + return pSym; + } + } +#endif + return pSym; +} + + + + + +const uint32_t g_RegTaskNum=OSP_NELEMENTS(g_TaskRegTbl); + + +void osp_task_entry(OSP_TASKCB *Osp_TaskCB) +{ + struct sched_param struSchedParam; + OSP_STATUS ret; + pthread_t PhreadId; + uint32_t MaxTaskPri; + uint32_t MinTaskPri; + Osp_Msg_Head *pHead; + OSP_FUNCPTR Init; + + + CURRENT_TASKID = Osp_TaskCB->Osp_TaskMsg_Reg.TaskId; + Osp_TaskCB->PhreadId = pthread_self(); + + Init = Osp_TaskCB->Osp_TaskMsg_Reg.Init; + + if (Init) + { + ret = Init(); + if (ret) + { + osp_debug_out_with_time(ERR_DEBUG_LEVEL, "task-%s int32_t err\n", Osp_TaskCB->Osp_TaskMsg_Reg.TaskName); + osp_suspend_task(CURRENT_TASKID); + } +// osp_assert(OSP_OK == ret); + } + Osp_TaskCB->TId = syscall(SYS_gettid); + osp_set_cpu(Osp_TaskCB->Osp_TaskMsg_Reg.Cpu); + + + if ((NORMALTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & POLICYMASK)) + && (MSGTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & MSGMASK))) + { + // sprintf(buf, "renice -n %d -p %d", ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & PRIMASK), + // Osp_TaskCB->TId); + // system(buf); + setpriority(PRIO_PROCESS, 0, Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri); + + + osp_sem_take(g_SemStartWork, -1); + while (1) + { + pHead = osp_rev_msg(); + Osp_TaskCB->Osp_TaskMsg_Reg.MainLoop(pHead); + TASK_RUNCNT(CURRENT_TASKID)++; + } + } + else if ((NORMALTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & POLICYMASK)) + && (NOMSGTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & MSGMASK))) + { + // sprintf(buf, "renice -n %d -p %d", ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & PRIMASK), + // Osp_TaskCB->TId); + // system(buf); + setpriority(PRIO_PROCESS, 0, Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri); + + osp_sem_take(g_SemStartWork, -1); + while (1) + { + Osp_TaskCB->Osp_TaskMsg_Reg.MainLoop(); + TASK_RUNCNT(CURRENT_TASKID)++; + + } + } + else if (RTTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & POLICYMASK)) + { + Osp_TaskCB->IsRt =1; + MaxTaskPri = sched_get_priority_max(SCHED_FIFO); + MinTaskPri = sched_get_priority_min(SCHED_FIFO); + osp_assert((((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & PRIMASK) <= MaxTaskPri) && + (((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri)&PRIMASK) >= MinTaskPri)); + + struSchedParam.sched_priority = ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & PRIMASK); + + PhreadId = pthread_self(); + + + ret = pthread_setschedparam(PhreadId, (int32_t)SCHED_FIFO, &struSchedParam); + osp_assert(OSP_OK == ret); + Osp_TaskCB->OsTaskPri = getpriority(PRIO_PROCESS, Osp_TaskCB->TId); + if (NOMSGTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & MSGMASK)) + { + osp_sem_take(g_SemStartWork, -1); + while (1) + { + Osp_TaskCB->Osp_TaskMsg_Reg.MainLoop(); + TASK_RUNCNT(CURRENT_TASKID)++; + } + } + else if (MSGTASK == ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & MSGMASK)) + { + if (XXTASK != ((Osp_TaskCB->Osp_TaskMsg_Reg.TaskPri) & XXMASK)) + { + osp_sem_take(g_SemStartWork, -1); + while (1) + { + pHead = osp_rev_msg(); + + Osp_TaskCB->Osp_TaskMsg_Reg.MainLoop(pHead); + TASK_RUNCNT(CURRENT_TASKID)++; + } + } + else + { + osp_sem_take(g_SemStartWork, -1); + while (1) + { + + osp_sem_take(Osp_TaskCB->sem, -1); + Osp_TaskCB->Osp_TaskMsg_Reg.MainLoop(NULL); + TASK_RUNCNT(CURRENT_TASKID)++; + } + } + } + } + else + { + osp_assert(0); + } + +} + +static uint32_t osp_get_free_task_id(void) +{ + int32_t i; + + for (i = 1; i < OSP_MAX_TASK; i++) + { + if (0 == gOspTask[i].Active) + { + return i; + } + } + + return OSP_INVALID_TASKID; +} + + +OSP_STATUS osp_regtask(OSP_TASKMSG_REG *TaskRegTbl) +{ + pthread_t Thread; + pthread_attr_t ThreadAttr; + OSP_STATUS ret =0; + uint32_t TaskId; + + osp_assert(NULL != TaskRegTbl); + + osp_sem_take(g_SemRegTask, -1); + + + TaskId = TaskRegTbl->TaskId; + + if (OSP_INVALID_TASKID == TaskId) + { + TaskId = osp_get_free_task_id(); + if (OSP_INVALID_TASKID == TaskId) + { + osp_sem_give(g_SemRegTask); + return OSP_ERROR; + } + TaskRegTbl->TaskId = TaskId; + } + + osp_assert(TaskId < OSP_MAX_TASK); + /*ospshell will retart,so this is not ok*/ + osp_assert(0 == gOspTask[TaskId].Active); + gOspTask[TaskId].sem = osp_semc_create(0); + + + if ((OSP_NO_AFFIINITY != TaskRegTbl->Cpu) && ((OSP_CPU_NUM - 1) < TaskRegTbl->Cpu)) + { + osp_sem_give(g_SemRegTask); + return OSP_ERROR; + } + + gOspTask[TaskId].Active = 1; + gOspTask[TaskId].State = TASK_RUNNING; + (void)memcpy(&(gOspTask[TaskId].Osp_TaskMsg_Reg), TaskRegTbl, sizeof(OSP_TASKMSG_REG)); + + if (OSP_PROCESS_MSG == TaskRegTbl->MsgType) + { + osp_create_msgq((Osp_MsgQ_Tcb *)(gOspMsgQue + OSP_ROUND_UP(OSP_MSG_QUE_SIZE,32) * TaskId), + (char *)(gOspTask[TaskId].Osp_TaskMsg_Reg.TaskName)); + + gOspTask[TaskId].send_msg_func = (OSP_FUNCPTR)osp_send_por_msg; + gOspTask[TaskId].rev_msg_func = (OSP_FUNCPTR)osp_rev_promsg; + gOspTask[TaskId].Msg_Que = (uint64_t)(gOspMsgQue + OSP_ROUND_UP(OSP_MSG_QUE_SIZE,32) * TaskId); +// gOspTask[TaskId].MsgQId = QueId; + + } + + if (OSP_UDP_MSG == TaskRegTbl->MsgType) + { + int32_t rxudpid = 0; + int32_t txudppid = 0; + OSP_UDP_TASK_DATA *pdata; + + pdata = (OSP_UDP_TASK_DATA *)TaskRegTbl->MsgTypeData; + + if (pdata->IsRx) + { + rxudpid = osp_create_rxucp(pdata->port); + txudppid = osp_create_txucp(pdata->port, "127.0.0.1"); + } + else + { + txudppid = osp_create_txucp(pdata->port, pdata->ip); + } + gOspTask[TaskId].send_msg_func = (OSP_FUNCPTR)osp_send_udpmsg; + gOspTask[TaskId].rev_msg_func = (OSP_FUNCPTR)osp_rev_udpmsg; + gOspTask[TaskId].Msg_Que = OSP_UDPID_TO_QUE(txudppid, rxudpid); + } + + if (OSP_OTHER_MSG == TaskRegTbl->MsgType) + { + + gOspTask[TaskId].send_msg_func = (OSP_FUNCPTR)osp_send_othermsg; + gOspTask[TaskId].rev_msg_func = (OSP_FUNCPTR)osp_rev_other_msg; + gOspTask[TaskId].Msg_Que = TaskRegTbl->MsgTypeData; + + + } + /*if task has no mainloop, then it is stub task*/ + if (NULL == TaskRegTbl->MainLoop) + { + osp_sem_give(g_SemRegTask); + return OSP_OK; + } + + + + + ret = pthread_attr_init(&ThreadAttr); + osp_assert(OSP_OK == ret); +// ret = pthread_attr_setstacksize(&ThreadAttr, OSP_TASK_STACK); +// osp_assert(OSP_OK == ret); + + if (IS_RT_PRI(TaskRegTbl->TaskPri)) + { + ret = pthread_attr_setschedpolicy(&ThreadAttr, + SCHED_FIFO); + osp_assert(OSP_OK == ret); + } + ret = pthread_create(&Thread, + &ThreadAttr, + (void *(*)(void *))osp_task_entry, + &gOspTask[TaskId]); + osp_assert(OSP_OK == ret); + + osp_sem_give(g_SemRegTask); + + return OSP_OK; +} + + + +OSP_STATUS osp_reg_task_tlb(OSP_TASKMSG_REG *TaskRegTbl, uint32_t TaskNum) +{ + int32_t i; + + osp_assert(NULL != TaskRegTbl); + osp_assert(TaskNum <= OSP_MAX_TASK); + + for (i = 0; i < TaskNum; i++) + { + osp_regtask(&TaskRegTbl[i]); + } + + return OSP_OK; +} + +int32_t osp_set_net_task_msg_que(int32_t taskid, int32_t txudpid, int32_t rxudpid) +{ + if ((taskid >= OSP_MAX_TASK) || (taskid <0)) + { + return -1; + } + + gOspTask[taskid].Msg_Que = OSP_UDPID_TO_QUE(txudpid, rxudpid); + + return 0; +} +void osp_start_task_all(void) +{ + uint32_t i; + for (i = 0; i < OSP_MAX_TASK; i++) + { + osp_sem_give(g_SemStartWork); + } + +} +OSP_STATUS osp_regtaskAll(void) +{ + //OSP_TASKMSG_REG *pTaskRegTbl = 0; + //U32 *pRegTaskNum = NULL; + OSP_STATUS ret; + g_SemStartWork = osp_semc_create(0); + g_SemRegTask = osp_semm_create(); + + + if (0 == g_ProcessId) + { + ret = osp_reg_task_tlb(g_TaskRegTbl, g_RegTaskNum); + osp_assert(OSP_OK == ret); + + } + + usleep(100); /*to keep setup order*/ + +#if 0 + pTaskRegTbl = osp_find_sym("TaskRegTbl"); + pRegTaskNum = osp_find_sym("TegTaskNum"); + if ((NULL !=pTaskRegTbl) && (NULL != pRegTaskNum)) + { + ret = osp_reg_task_tlb(pTaskRegTbl, *pRegTaskNum); + } + osp_reg_task_tlb(g_TestRegTbl, g_RegTestNum); +#endif + return OSP_OK; + +} + +void osp_show_task_info(void) +{ + int32_t i; + char *pbuf; + int32_t len = 0; + char *p; + char state[12] = {0}; + + pbuf = malloc(10 * 1024); + osp_assert(pbuf != NULL); + + len = sprintf(pbuf, "%-8s%-8s%-16s%-12s%-12s%-12s%-12s%-12s%-12s%-12s%-12s%-12s%-12s%-12s\n", + "Id", "OsId", "Name", "state", "Run", "MsgRx", "MsgTx", "Cpu-Pri", "Type", + "MsgAlloc", "LogMsgAlloc", "MsgFree", "MemAlloc", "MemFree"); + for (i = 0; i < OSP_MAX_TASK; i++) + { + if (0 == TASK_SYSID(i)) + { + continue; + } + + if (gOspTask[i].Active) + { + if (TASK_RUNNING == TASK_STATE(i)) + sprintf(state, "%s", "running"); + else if (TASK_SUSPEND == TASK_STATE(i)) + sprintf(state, "%s", "suspended"); + + len += sprintf(pbuf + len, "%-8d%-8d%-16s%-12s%-12lu%-12d%-12d%d-%-12d%-12s%-12d%-12d%-12d%-12d%-12d\n", + gOspTask[i].Osp_TaskMsg_Reg.TaskId, TASK_SYSID(i), gOspTask[i].Osp_TaskMsg_Reg.TaskName, state, + TASK_RUNCNT(i), + TASK_MSG_RXCNT(i), TASK_MSG_TXCNT(i), + gOspTask[i].Osp_TaskMsg_Reg.Cpu, ((gOspTask[i].Osp_TaskMsg_Reg.TaskPri) & PRIMASK), + gOspTask[i].IsRt ? "RT" : "*", + TASK_MSG_ALLOCCNT(i), TASK_LOGMSG_ALLOCCNT(i), TASK_MSG_FREECNT(i), + TASK_MEM_ALLOCCNT(i), TASK_MEM_FREECNT(i)); + } + } + for (p = pbuf; p < pbuf + len; p += (MAX_DBGINFO_LEN - 1)) + { + printf("%s", p); + } + free(pbuf); +} + +OSP_STATUS osp_task_init(void) +{ + osp_set_task_shell(localshellin); + osp_set_task_shell(localshellout); + osp_set_task_shell(ospnetshellrx); + + osp_regtaskAll(); + osp_task_dbg_out_enable_all(); + + return OSP_OK; + +} +int32_t osp_get_task_num(void) +{ + return OSP_MAX_TASK; +} +OSP_TASKCB *osp_get_taskcb_base(void) +{ + return gOspTask; +} + +int32_t osp_set_taskcpu(int32_t taskid, int32_t cpuid) +{ + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(cpuid, &mask); + + osp_assert(0 == pthread_setaffinity_np(gOspTask[taskid].PhreadId, sizeof(mask), &mask)); + return 0; +} + + + diff --git a/osp/src/ospTcp.c b/osp/src/ospTcp.c new file mode 100644 index 0000000..df40d67 --- /dev/null +++ b/osp/src/ospTcp.c @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "osp.h" +#include "ospTcp.h" + + +int32_t osp_tcp_send(int32_t socket_fd, char *pMsg, int32_t msgLen) +{ + return send(socket_fd, pMsg, msgLen, MSG_NOSIGNAL); + +} + +int32_t osp_tcp_rev(int32_t socket_fd, char *pMsg, int32_t msgLen) +{ + return recv(socket_fd, pMsg, msgLen, 0); +} +#if 0 +int tcpSerCreat(int port) +{ + int socket_fd; + struct sockaddr_in servaddr; + int opt; + int optLen = sizeof(int); + + if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) + { + return -1; + } + + + + + + opt=(64*1024); + setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF,(char*)&opt, sizeof(opt)); + getsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(opt)); + + opt=(64*1024); + setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF,(char*)&opt, sizeof(opt)); + getsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt)); + opt = 1; + setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR,(char*)&opt, sizeof(opt)); + + + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + + + if (bind(socket_fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1) + { + return -1; + } + if (listen(socket_fd, 10) == -1) + { + return -1; + } + return socket_fd; + +} + +int tcpCliCreat(int port) +{ + int socket_fd; + int reuse = 0; + int opt; + struct sockaddr_in servaddr; + + + if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + return -1; + } + + opt=(64*1024); + setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF,(char*)&opt, sizeof(opt)); + getsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(opt)); + + opt=(64*1024); + setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF,(char*)&opt, sizeof(opt)); + getsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt)); + opt = 1; + setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR,(char*)&opt, sizeof(opt)); + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); +#if 0 + if (bind(socket_fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1) + { + return -1; + } +#endif + return socket_fd; + + +} + +int tcpAccept(int socket_fd) +{ + int connect_fd; + + if ((connect_fd = accept(socket_fd, (struct sockaddr*)NULL, NULL)) == -1) + { + return -1; + } + return connect_fd; +} + +int tcpConnet(int socket_fd, char *targetIp, int port) +{ + struct sockaddr_in servaddr; + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(port); + servaddr.sin_addr.s_addr = inet_addr(targetIp); + + + if (connect(socket_fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) + { + return -1; + } + return 0; +} +#endif + + diff --git a/osp/src/ospTest.c b/osp/src/ospTest.c new file mode 100644 index 0000000..9e636e6 --- /dev/null +++ b/osp/src/ospTest.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "osp.h" + + +static int32_t osp_tesk_init1(void) +{ + void *pTimer; + int32_t ret; + + pTimer = osp_timer_create_sim(OspTestTask, 1, 1, 0); + ret = osp_timer_start(pTimer); + + + return ret; +} + + + +static void osp_tesk_main1(Osp_Msg_Head *pMsg) +{ + char buf[] = "Osposp_tesk_main1***************************************************************************************************************************************************************************************"; + + osp_dbg_log(buf, strlen(buf)); + + +} + + +OSP_TASKMSG_REG g_TestRegTbl[] = +{ + + {OspTestTask, "OspTestTask", NOMARL_NOMSG_PRI(20), (OSP_FUNCPTR)osp_tesk_init1, (OSP_FUNCPTR)osp_tesk_main1, 0, OSP_PROCESS_MSG}, + +}; + +const uint32_t g_RegTestNum = OSP_NELEMENTS(g_TestRegTbl); + + diff --git a/osp/src/ospTimer.c b/osp/src/ospTimer.c new file mode 100644 index 0000000..bdf399b --- /dev/null +++ b/osp/src/ospTimer.c @@ -0,0 +1,529 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "osp.h" + +uint64_t ospTicks = 0; +#define ARTCH_TIMER_SIZE 4096 +#define ARTCH_TIMER_OFFSET 8 + + +Node **gp_TimerList = NULL; + + +void *gOspTimerSemId; +static int32_t timerfd; + + + +OSP_STATUS osp_timer_pool_init(void) +{ + gOspTimerSemId = osp_get_init_mem(sizeof(lx_sem_t)); + gp_TimerList = (Node **)osp_get_init_mem(sizeof(Node)); + + osp_semsm_create(gOspTimerSemId); + timerfd = timerfd_create(CLOCK_MONOTONIC, 0); + return (OSP_OK); +} + +OSP_STATUS osp_timer_start(void *Timer) +{ + OSP_timer_Tcb *timer = Timer; + timer->State = TIMER_RUNNING; + return 0; +} + + +void *osp_timer_create_sim(uint32_t DstTaskId, bool isRepeat, uint32_t Period, uint32_t Delay) +{ + OSP_timer_Tcb *timer; + Node *TmpNode; + + osp_sem_take(gOspTimerSemId, -1); + /*if first one*/ + if ((NULL == (*gp_TimerList)) || (BUFFER_BASE == (char *)(*gp_TimerList))) + { + (*gp_TimerList) = (Node *)osp_alloc_mem(sizeof(Node)); + (*gp_TimerList)->TimerOff = (uint64_t)osp_alloc_mem(sizeof(OSP_timer_Tcb)) - (uint64_t)BUFFER_BASE; + (*gp_TimerList)->NextNodeOff = 0; + + timer = (OSP_timer_Tcb *)((*gp_TimerList)->TimerOff + BUFFER_BASE); + timer->Delay = Delay; + timer->Repeat =isRepeat; + timer->Period = Period; + timer->TimeOut = Period + Delay; + timer->DstTaskId = DstTaskId; + timer->RunCnt = 0; + timer->State = TIMER_READY; + timer->Valid = 1; + } + /*if not first one*/ + else + { + TmpNode = (*gp_TimerList); + while (TmpNode->NextNodeOff) + { + TmpNode = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + } + + TmpNode->NextNodeOff = (uint64_t)osp_alloc_mem(sizeof(Node)) - (uint64_t)BUFFER_BASE; + TmpNode = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + TmpNode->TimerOff = (uint64_t)osp_alloc_mem(sizeof(OSP_timer_Tcb)) - (uint64_t)BUFFER_BASE; + TmpNode->NextNodeOff = 0; + + timer = (OSP_timer_Tcb *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE); + timer->Delay = Delay; + timer->Repeat = isRepeat; + timer->Period = Period; + timer->TimeOut = Period + Delay; + timer->DstTaskId = DstTaskId; + timer->RunCnt = 0; + timer->State = TIMER_READY; + timer->Valid = 1; + } + + osp_sem_give(gOspTimerSemId); + return timer; +} +void osp_timer_del_sim(void *timer) +{ + Node *TmpNode; + Node *Pre; + OSP_timer_Tcb *ptimer; + if ((NULL == (*gp_TimerList)) || (BUFFER_BASE == (char *)(*gp_TimerList))) + { + return; + } + if (NULL == timer) + { + return; + } + + ptimer = timer; + if (1 != ptimer->Valid) + { + return; + } + + osp_sem_take(gOspTimerSemId, -1); + TmpNode = (*gp_TimerList); + + /*if head is the one*/ + if (timer == (OSP_timer_Tcb *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE)) + { + (*gp_TimerList) = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + osp_free_mem((char *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE)); + osp_free_mem((char *)TmpNode); + osp_sem_give(gOspTimerSemId); + return; + } + + /*middle or tail*/ + while (timer != (OSP_timer_Tcb *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE)) + { + Pre = TmpNode; + TmpNode = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + } + + Pre->NextNodeOff = TmpNode->NextNodeOff; + osp_free_mem((char *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE)); + osp_free_mem((char *)TmpNode); + osp_sem_give(gOspTimerSemId); + +} + +void osp_timer_suspend_sim(void *timer) +{ + OSP_timer_Tcb *ptimer; + + ptimer = (OSP_timer_Tcb *)timer; + + osp_sem_take(gOspTimerSemId, -1); + printf("timer id %p\n", timer); + + ptimer->State = TIMER_SUSPEND; + osp_sem_give(gOspTimerSemId); + + + +} + + + + +void osp_wait_timeout(int32_t ms) +{ + + static int32_t lastms = 0; + struct itimerspec ts1; + uint64_t tmp; + + if (lastms != ms) + { + lastms = ms; + ts1.it_value.tv_sec = 0; + ts1.it_value.tv_nsec = ms * 1000000; //!1ms + + ts1.it_interval = ts1.it_value; + //-------------------create timer + timerfd_settime(timerfd, 0, &ts1, NULL); + } + read(timerfd, &tmp, sizeof(uint64_t)); + + + +} + + + + + + + +void osp_pridel_time(void) +{ + static uint32_t usecondold; + static uint32_t usecondcur; + static uint32_t useconddel; + + OSP_RTCTIME osptime; + osp_get_rtc_time(&osptime); + + usecondold = usecondcur; + usecondcur = osptime.usecond; + if (usecondcur < usecondold) + { + useconddel = usecondcur + 1000000 - usecondold; + } + else + { + useconddel = usecondcur - usecondold; + } + + printf("***************************************************%d\r\n", useconddel); + + +} + +void osp_tick_less(void) +{ + Node *TmpNode; + Node *Pre; + + OSP_timer_Tcb *timer; + static uint32_t next_time = 1; + uint32_t min_time = 0xffffffff; + /*if osp init not finish, we need keep 1S period Delay run. so that OSP_tick will not run always*/ + + + /*if has no timer, we need keep 1S period Delay run. so that OSP_tick will not run always*/ + if ((NULL == (*gp_TimerList)) || (BUFFER_BASE == (char *)(*gp_TimerList))) + { + osp_wait_timeout(999); + return; + } + + + ospTicks += next_time; + osp_wait_timeout(next_time); + + osp_sem_take(gOspTimerSemId, -1); + TmpNode = (*gp_TimerList); + Pre = TmpNode; + + while (TmpNode->TimerOff) + { + timer = (OSP_timer_Tcb *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE); + + if (timer->State == TIMER_RUNNING) + { + timer->TimeOut -= next_time; + + if (0 >= timer->TimeOut) + { + timer->RunCnt++; + osp_timer_callback(timer->DstTaskId, (uint64_t)timer); + if (timer->Repeat) + { + timer->TimeOut = timer->Period; + min_time = (min_time >= timer->TimeOut) ? timer->TimeOut: min_time; + } + /*rm if not Repeat*/ + else + { + /*if head is the one*/ + if (TmpNode == (*gp_TimerList)) + { + (*gp_TimerList) = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + osp_free_mem((char *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE)); + osp_free_mem((char *)TmpNode); + } + + /*middle or tail*/ + else + { + + Pre->NextNodeOff = TmpNode->NextNodeOff; + osp_free_mem((char *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE)); + osp_free_mem((char *)TmpNode); + } + } + } + else + { + min_time = (min_time >= timer->TimeOut) ? timer->TimeOut: min_time; + } + } + /*tail*/ + if (0 == TmpNode->NextNodeOff) + { + osp_sem_give(gOspTimerSemId); + next_time = min_time; + + return; + } + + Pre = TmpNode; + TmpNode = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + } + osp_sem_give(gOspTimerSemId); +} + +uint64_t osp_get_osp_ticks(void) +{ + return (ospTicks); +} + +#ifdef X86 +unsigned long rdtsc(void) +{ + uint32_t low,high; + asm volatile("rdtsc" : "=a"(low), "=d"(high)); + return low | (unsigned long)high << 32; + +} + +#else +uint64_t osp_arch_counter_get_cntpct(void) +{ + static int32_t fd = -1; + static uint32_t *base = NULL; + + uint64_t cval = 0; + if (-1 == fd) + { + fd = open("/dev/archtimer", O_RDWR); + if (-1 == fd) + return 0; + base = (uint32_t *)mmap(NULL, ARTCH_TIMER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0); + } + if (base) + { + cval = *(base + 3); + cval = cval << 32; + cval |= *(base + 2); + } + return cval; +} +#endif +uint64_t osp_get_cycel(void) +{ +#ifdef X86 + + return rdtsc(); +#else + return osp_arch_counter_get_cntpct(); +#endif +} +/* + * osp_set_ticks - set ospTicks + * input: + * ticks + * return + * none + */ + +void osp_set_ticks(uint64_t ticks) +{ + ospTicks = ticks; +} + +/* + * osp_timer_callback - default OSP timer's callcack routine + * input: + * ospTaskId + * timerId timer ID + * param??§oo user specified param + * return + * OSP_OK,or + * OSP_ERROR(execute fail) + */ + +OSP_STATUS osp_timer_callback(uint64_t DstTaskId, uint64_t timer) +{ + Osp_Msg_Head *phead = osp_alloc_msgTimer(); + + + if (NULL != phead) + { + phead->MsgType = OSP_TIMER_TYPE; + phead->DstId = DstTaskId; + phead->SrcId = CURRENT_TASKID; + *(uint64_t *)((uint64_t)phead + MSG_HEAD_SIZE) = timer; + + osp_send_msg(phead); + } + return (OSP_OK); + +} + +void *osp_get_timer_from_msg(Osp_Msg_Head *pmsg) +{ + Osp_Timer_Msg_Block *timerblock = (Osp_Timer_Msg_Block *)pmsg; + return (void *)(timerblock->data); +} + +/* +*osp_timer_callback - display timer count(started/stoped/deleted) +*input: +* none +*return +* none +*/ +/*lint -e826*/ +void osp_show_timer_count(void) +{} + + +/* + * osp_clk_rate_get - query system clock frequency + * input: + * none + * return + * ticks/per second + */ + +int32_t osp_clk_rate_get(void) +{ + return 100; +} + + + +/* + * OSP_getOneTimerInfo - get timer's information + * input: + * pNode : pointer to OSP timer + * return + * OSP_ERROR + */ + + + +/* + * showRunTimerInfo - print run timer's information + * input: + * none + * return + * none + */ + +void osp_show_timer_info(void) +{ + Node *TmpNode; + + OSP_timer_Tcb *timer; + char *pbuf; + int32_t len = 0; + + + /*if has no timer, we need keep 1S period Delay run. so that OSP_tick will not run always*/ + if ((NULL == (*gp_TimerList)) || (BUFFER_BASE == (char *)(*gp_TimerList))) + { + osp_debug_out(CMD_DEBUG_LEVEL, "%s\r\n", "no timer"); + return; + } + + pbuf = malloc(10 * 1024); + if (pbuf == NULL) + return; + len = sprintf(pbuf + len, "%-8s%-16s%-16s%-12s%-12s%-12s%-12s%-12s%-12s\n", "TaskId", "TskName", + "point", "Repeat", "RunCnt", "Period", "TimeOut", "Delay", "Suspend/Running"); + + + + + + osp_sem_take(gOspTimerSemId, -1); + TmpNode = (*gp_TimerList); + + while (TmpNode->TimerOff) + { + timer = (OSP_timer_Tcb *)(TmpNode->TimerOff + (uint64_t)BUFFER_BASE); + len += sprintf(pbuf + len, "%-8d%-16s%-16p%-12s%-12lu%-12d%-12d%-12d%s\n", + timer->DstTaskId, gOspTask[timer->DstTaskId].Osp_TaskMsg_Reg.TaskName, + timer, + (timer->Period) ? "ture" : "faulse", + timer->RunCnt, + timer->Period, + timer->TimeOut, + timer->Delay, + (timer->State == TIMER_RUNNING) ? "Running" : "Suspend"); + + /*tail*/ + if (0 == TmpNode->NextNodeOff) + { + osp_sem_give(gOspTimerSemId); + break; + } + + TmpNode = (Node *)(TmpNode->NextNodeOff + (uint64_t)BUFFER_BASE); + } + pbuf[len] = '\0'; + osp_debug_out(CMD_DEBUG_LEVEL, "%s", pbuf); + free(pbuf); +} + + + + + + + +/* + * osp_get_systick - get the value of the kernel's tick counter + * input: + * none + * return + * the current value of the tick counter(per 1ms) + */ + +uint32_t osp_get_systick() +{ + uint32_t currentTime; + + + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + currentTime = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; + + return currentTime; +} + + + + + + + + + + diff --git a/osp/src/ospUdp.c b/osp/src/ospUdp.c new file mode 100644 index 0000000..df3931d --- /dev/null +++ b/osp/src/ospUdp.c @@ -0,0 +1,365 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "osp.h" +#include "ucp_printf.h" + + +typedef struct tag_OSP_UDP_SOCKET +{ + lx_sem_t mutex; + char ip[64]; + int32_t port; + int32_t taskid; + int32_t direction;/**/ + int32_t pkgnum; + int64_t totalsize; + int32_t errcnt; + struct sockaddr_in servAddr; + int32_t socket; + int32_t valid; +}OSP_UDP_SOCKET; + + + +#define OSP_MAX_UDP_CONNECT_NUM 256 + +OSP_UDP_SOCKET osp_udp[OSP_MAX_UDP_CONNECT_NUM] = {0}; + +#define OSPUDP_MSG_LEN (1500 + MSG_HEAD_SIZE) + + + +void *udp_sem; + +int32_t osp_get_udp(char *ip, int32_t port, int32_t direction) +{ + int32_t i; + + for (i = 0; i < OSP_MAX_UDP_CONNECT_NUM; i++) + { + if ((osp_udp[i].valid) && (strcmp(osp_udp[i].ip, ip) == 0) && (osp_udp[i].port == port) && (osp_udp[i].direction == direction)) + { + return i; + } + } + + return -1; +} + +int32_t osp_get_rxudp(char *ip, int32_t port) +{ + return osp_get_udp(ip, port, OSP_UDP_RX); +} + +int32_t osp_get_txudp(char *ip, int32_t port) +{ + return osp_get_udp(ip, port, OSP_UDP_TX); +} + + +int32_t osp_get_ip_port(int32_t udpid, char *ip, int32_t *port) +{ + if ((udpid < 0) || (udpid > OSP_MAX_UDP_CONNECT_NUM) || NULL == ip || NULL == port) + { + return -1; + } + strcpy(ip, osp_udp[udpid].ip); + *port = osp_udp[udpid].port; + + return -1; +} + + + + +int32_t osp_check_udpid(int32_t udpid) +{ + if ((udpid < 0) || (udpid > OSP_MAX_UDP_CONNECT_NUM) || !(osp_udp[udpid].valid)) + { + return 0; + } + + return 1; +} +int32_t osp_set_udp_noblock(int32_t udpid) +{ + if (osp_check_udpid(udpid)) + return -1; + return fcntl(osp_udp[udpid].socket, F_SETFL, O_NONBLOCK); +} + + + + +int32_t osp_add_udp(char *ip, int32_t port, int32_t direction) +{ + int32_t i; + osp_sem_take(udp_sem, -1); + + for (i = 0; i < OSP_MAX_UDP_CONNECT_NUM; i++) + { + if (osp_udp[i].valid == 0) + { + strcpy(osp_udp[i].ip, ip); + osp_udp[i].port = port; + osp_udp[i].valid = 1; + osp_udp[i].direction = direction; + osp_sem_give(udp_sem); + return i; + } + } + osp_sem_give(udp_sem); + return -1; + +} + + + + + +int32_t osp_del_udp(int32_t udpid) +{ + if (!osp_check_udpid(udpid)) + { + return 0; + } + + osp_udp[udpid].valid = 0; + close(osp_udp[udpid].socket); + + return 0; + + +} + + +int32_t osp_create_rxucp(int32_t port) +{ + int32_t res; + int32_t sockset; + int32_t tmp = 1; + int32_t addrlen; + int32_t udp_id; + int32_t idx; + + if (osp_get_rxudp("127.0.0.1", port) >= 0) + { + return -1; + } + + + + idx = osp_add_udp("127.0.0.1", port, OSP_UDP_RX); + if (idx < 0) + { + return -1; + } + + osp_udp[idx].taskid = CURRENT_TASKID; + osp_udp[idx].direction = OSP_UDP_RX; + + sockset = socket(AF_INET, SOCK_DGRAM, 0); + if (sockset == -1) { + perror("socket"); + return -1; + } + + setsockopt(sockset, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(int32_t)); + + osp_udp[idx].socket = sockset; + osp_udp[idx].servAddr.sin_family = AF_INET; + osp_udp[idx].servAddr.sin_port = htons(port); + osp_udp[idx].servAddr.sin_addr.s_addr = htonl(INADDR_ANY); + + addrlen = sizeof(struct sockaddr); + res = bind(sockset, (struct sockaddr *)&osp_udp[idx].servAddr, addrlen); + if (res == -1) { + perror("bind"); + return -1; + } + + udp_id = idx; + return udp_id; +} + +int32_t osp_create_txucp(int32_t port, char *targetIp) +{ + int32_t sockset; + int32_t udp_id; + int32_t idx; + + if (osp_get_txudp(targetIp, port) >= 0) + { + return -1; + } + idx = osp_add_udp(targetIp, port, OSP_UDP_TX); + if (idx < 0) + { + return -1; + } + + osp_udp[idx].taskid = CURRENT_TASKID; + osp_udp[idx].direction = OSP_UDP_TX; + + sockset = socket(AF_INET, SOCK_DGRAM, 0); + if (sockset == -1) { + perror("socket"); + return -1; + } + + + + osp_udp[idx].socket = sockset; + osp_udp[idx].servAddr.sin_family = AF_INET; + osp_udp[idx].servAddr.sin_addr.s_addr = inet_addr(targetIp); + osp_udp[idx].servAddr.sin_port = htons(port); + + udp_id = idx; + + return udp_id; +} + + +int32_t osp_udp_receive(char *pMsg, int32_t len, int32_t udp_id) +{ +// struct sockaddr_in sin; + socklen_t sin_len; + + sin_len = sizeof(struct sockaddr); + len = recvfrom(osp_udp[udp_id].socket, pMsg, len, 0, (struct sockaddr *)&osp_udp[udp_id].servAddr, &sin_len); + if (len <= 0) + { + osp_atomic_inc(&osp_udp[udp_id].errcnt); + return len; + } + + osp_atomic_inc(&osp_udp[udp_id].pkgnum); + osp_sem_take(&osp_udp[udp_id].mutex, -1); + osp_udp[udp_id].totalsize += len; + osp_sem_give(&osp_udp[udp_id].mutex); + + return len; + +} + +int32_t osp_udp_send(char *pMsg, int32_t msgLen, int32_t udp_id) +{ + int32_t Len; + + if ((pMsg == NULL) || !osp_check_udpid(udp_id)) + { + return (-1); + } + + Len = sendto(osp_udp[udp_id].socket, pMsg, msgLen, 0, (struct sockaddr *)&osp_udp[udp_id].servAddr, sizeof(struct sockaddr_in)); + if (Len != msgLen) + { + //osp_atomic_inc(&osp_udp[udp_id].errcnt); + return (-1); + } + +#if 0 + osp_atomic_inc(&osp_udp[udp_id].pkgnum); + + osp_sem_take(&osp_udp[udp_id].mutex, -1); + osp_udp[udp_id].totalsize += Len; + osp_sem_give(&osp_udp[udp_id].mutex); +#endif + return (0); + +} + +int32_t osp_send_udpmsg(Osp_Msg_Head *pMsg, uint64_t udp_id) +{ + int32_t ret; + ret = osp_udp_send((char*)pMsg, pMsg->MsgSize + MSG_HEAD_SIZE, OSP_UDPID_TO_TX(udp_id)); + + osp_free_msg(pMsg); + return ret; +} + +Osp_Msg_Head *osp_rev_udpmsg(uint64_t udp_id) +{ + char *pbuf; + int32_t ret; + + pbuf = (char *) osp_alloc_msg(OSPUDP_MSG_LEN); + if (NULL == pbuf) + { + return NULL; + } + + ret = osp_udp_receive(pbuf, OSPUDP_MSG_LEN, OSP_UDPID_TO_RX(udp_id)); + if (ret <= 0) + { + return NULL; + } + + return (Osp_Msg_Head *)pbuf; + +} + + + +int32_t osp_udp_init(void) +{ + int32_t i; + + udp_sem = osp_semm_create(); + + for (i = 0; i < OSP_MAX_UDP_CONNECT_NUM; i++) + { + osp_semsm_create(&(osp_udp[i].mutex)); + } + return 0; +} + + + + + +void osp_show_udp(void) +{ + int32_t i; + char buf[4096]; + int32_t len = 0; + + len += sprintf(buf + len, "\n%-16s%-16s%-16s%-16s%-16s%-16s%-16s%-16s%-16s\n", "direction", "udpid", "taskid", "socket", "ip", "port", "pkgnum", "totalsize", "errcnt"); + for (i = 0; i < OSP_MAX_UDP_CONNECT_NUM; i++) + { + if ((osp_udp[i].valid) && (osp_udp[i].direction == OSP_UDP_RX)) + { + len += sprintf(buf + len, "%-16s%-16d%-16d%-16d%-16s%-16d%-16d%-16lu%-16d\n", + "rx", i, osp_udp[i].taskid, osp_udp[i].socket, osp_udp[i].ip, osp_udp[i].port, osp_udp[i].pkgnum, osp_udp[i].totalsize, osp_udp[i].errcnt); + } + } + + len += sprintf(buf + len, "\n"); + + for (i = 0; i < OSP_MAX_UDP_CONNECT_NUM; i++) + { + if ((osp_udp[i].valid) && (osp_udp[i].direction == OSP_UDP_TX)) + { + len += sprintf(buf + len, "%-16s%-16d%-16d%-16d%-16s%-16d%-16d%-16lu%-16d\n", + "tx", i, osp_udp[i].taskid, osp_udp[i].socket, osp_udp[i].ip, osp_udp[i].port, osp_udp[i].pkgnum, osp_udp[i].totalsize, osp_udp[i].errcnt); + + + } + } + + UCP_PRINT_SHELL("%s\n", buf); +} + + + diff --git a/test/case0/src/testcase.c b/test/case0/src/testcase.c new file mode 100644 index 0000000..5dd7f4e --- /dev/null +++ b/test/case0/src/testcase.c @@ -0,0 +1,369 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include + +#include "typedef.h" +#include "ucp_printf.h" +#include "msg_transfer_mem.h" +#include "pet_sm_mgt.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "ospLog.h" +#include "ospCfgToBin.h" +#include "drv_init.h" + +uint32_t slot_ind_flag = 0; +uint32_t slot_ind_time_flag = 0; +uint32_t g_slot_time = 0; +uint32_t gu32_value = 0; +uint32_t gu32_tick_receive_ctrl = 0; +uint32_t gu32_tick_from_tx_ctrl = 0; + +uint32_t rx_callback_data(const char* buf,uint32_t payloadSize) +{ + uint32_t stc_cnt = read_stc_local_timer(); + + uint32_t value = *(uint32_t *)buf; + uint16_t sfn = value >> 16; + uint16_t slot = value & 0xffff; + + uint32_t tick_from_tx_ctrl = *(uint32_t *)(buf+4); + + slot_ind_flag = 1; + gu32_value = value; + gu32_tick_receive_ctrl = stc_cnt; + gu32_tick_from_tx_ctrl = tick_from_tx_ctrl; + uint32_t diff = stc_cnt - tick_from_tx_ctrl; + //UCP_PRINT_LOG("a72_rx[%d], ape_tx[%d],offset[%d]",stc_cnt,tick_from_tx_ctrl,diff); + //UCP_PRINT_LOG("qNO[%d],sfn[%d],slot[%d]",UCP4008_TRAFFIC_NR_eMBB_DATA,sfn,slot); + + if(0 == slot_ind_time_flag) + { + slot_ind_time_flag = 1; + diff = 500000; + } + else + { + diff = stc_cnt - g_slot_time; + } + g_slot_time = stc_cnt; + + if ((diff > 520000) || (diff < 480000)) + { + UCP_PRINT_ERROR("qNO[%d],sfn[%d],slot[%d],diff[%d]",UCP4008_TRAFFIC_NR_eMBB_DATA,sfn,slot,diff); + } + + //EcsSmLocalMgt_t* pEcsSmLocalMgt = get_ecs_sm_local_mgt(); + ///MsgQueueCommonInfo_t* chCommon = pEcsSmLocalMgt->pUlQueue[0][UCP4008_TRAFFIC_NR_eMBB_DATA]; + //UCP_PRINT_DEBUG("rx_callback_data chCommon info alloc[%d],in[%d],out[%d]",chCommon->alloc,chCommon->in,chCommon->out); + + return payloadSize; +} + +uint32_t rx1_callback_data(const char* buf,uint32_t payloadSize) +{ + return payloadSize; +} + +uint32_t rx_callback_ctrl(const char* buf,uint32_t payloadSize) +{ +#if 0 + EcsSmLocalMgt_t* pEcsSmLocalMgt = get_ecs_sm_local_mgt(); + MsgQueueCommonInfo_t* chCommon = pEcsSmLocalMgt->pUlQueue[0][UCP4008_TRAFFIC_NR_eMBB_CTRL]; + UCP_PRINT_DEBUG("rx_callback_ctrl chCommon info alloc[%d],in[%d],out[%d]",chCommon->alloc,chCommon->in,chCommon->out); +#endif + return payloadSize; +} + +static inline void get_msg_transfer_info(uint16_t port_index, uint16_t inst_id, uint16_t transfer_type, transfer_type_info_s* transfer_type_info_ptr) +{ + queue_info_s c_plane,u_plane; + + switch (transfer_type) { + case CU_SPLIT: + c_plane.rx_block_size = 0x25800; + c_plane.rx_block_num = 32; + c_plane.rx_callback = rx_callback_ctrl; + c_plane.tx_block_size = 0x8000; + c_plane.tx_block_num = 8; + c_plane.tx_callback = NULL; + + u_plane.rx_block_size = 0x28000; + u_plane.rx_block_num = 8; + //u_plane.rx_callback = rx_callback_data; + if (0 == inst_id) + { + u_plane.rx_callback = rx_callback_data; + } + else + { + u_plane.rx_callback = rx1_callback_data; + } + u_plane.tx_block_size = 0x28000; + u_plane.tx_block_num = 8; + u_plane.tx_callback = NULL; + + transfer_type_info_ptr->queue_cplane_info = c_plane; + transfer_type_info_ptr->queue_uplane_info = u_plane; + break; + case OAM: + c_plane.rx_block_size = 0x100000; + c_plane.rx_block_num = 32; + c_plane.rx_callback = rx_callback_oam; + c_plane.tx_block_size = 0x8000; + c_plane.tx_block_num = 8; + c_plane.tx_callback = NULL; + + transfer_type_info_ptr->queue_cplane_info = c_plane; + break; + default: + UCP_PRINT_ERROR("get_msg_queue_cfg doesn't support transfer_type[%d] .",transfer_type); + break; + } + + return; +} + +static inline void msg_transfer_cfg(void) +{ + uint8_t port_id = 0; + uint16_t inst_id = 0; + uint16_t transfer_type = 0; + int32_t handle_id = 0; + transfer_type_info_s transfer_type_info; + + for (inst_id=0; inst_idpSyncInfo->queueCfgFlag = ++pMsgQueueLocalMgt->localSyncInfo.queueCfgFlag; + + return; +} + +static inline void msg_transfer_queue_polling(void) +{ + uint8_t port_id = 0; + HandleId_t handler; + uint16_t cu_flag; + uint32_t offset = 0; + uint32_t len = 0; + uint8_t* msg_ptr; + + for (uint32_t i = 0; i < MAX_INSTANCE_NUM; i++) { + handler.port_id = port_id; + handler.inst_id = i; + handler.type_id = CU_SPLIT; + cu_flag = C_PLANE; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + + cu_flag = U_PLANE; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + + handler.type_id = OAM; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + } + + return; +} + +#define CELL_SETUP_TYPE_SIMULATION (0x5a6b7c8d) + +void cell_setup_simulation() +{ + uint32_t size = 16; + char* buf; + uint32_t availableSize,offset; + + uint16_t cu_flag = C_PLANE; + HandleId_t handler; + handler.port_id = 0; + handler.inst_id = 0; + handler.type_id = CU_SPLIT; + + //usleep(10000); + sleep(1); + + int32_t ret = msg_transfer_send_start(handler.value,cu_flag); + + /************C_PLANE***************/ + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("cell_setup_simulation call msg_transfer_alloc_msg err."); + return ; + //continue; + } + + *(uint32_t*)(buf + 0) = CELL_SETUP_TYPE_SIMULATION; + *(uint32_t*)(buf + 4) = read_stc_local_timer(); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + ret = msg_transfer_send_end(handler.value,cu_flag); + + return; +} + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 0."); + + osp_read_spe_cfg_file("/ramfs/cfgDat"); + + msg_transfer_mem_init(); + msg_transfer_cfg(); + ucp_handshake(); + + UCP_PRINT_DEBUG("start transfering message."); + + uint32_t size = 100; + char* buf; + uint32_t availableSize,offset; + uint8_t* ptr; + + uint16_t cu_flag = C_PLANE; + HandleId_t handler; + handler.port_id = 0; + handler.inst_id = 0; + handler.type_id = CU_SPLIT; + + int32_t ret; + + cell_setup_simulation(); + + while(1) { + msg_transfer_queue_polling(); + + if(1 == slot_ind_flag) + { + slot_ind_flag = 0; + + handler.inst_id = 0; + + /************C_PLANE***************/ + cu_flag = C_PLANE; + ret = msg_transfer_send_start(handler.value,cu_flag); + + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("0,c_plane alloc error\r\n"); + continue; + } + + ptr = (uint8_t *)buf; + *(uint32_t*)(ptr + 0) = gu32_value; + *(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl; + *(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl; + *(uint32_t*)(ptr + 12) = read_stc_local_timer(); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("0,c_plane send error\r\n"); + } + + ret = msg_transfer_send_end(handler.value,cu_flag); + + /************U_PLANE***************/ + cu_flag = U_PLANE; + ret = msg_transfer_send_start(handler.value,cu_flag); + + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("0,u_plane alloc error\r\n"); + continue; + } + + ptr = (uint8_t *)buf; + *(uint32_t*)(ptr + 0) = gu32_value; + *(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl; + *(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl; + *(uint32_t*)(ptr + 12) = read_stc_local_timer(); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("0,u_plane send error\r\n"); + } + + ret = msg_transfer_send_end(handler.value,cu_flag); + + handler.inst_id = 1; + /************C_PLANE***************/ + cu_flag = C_PLANE; + ret = msg_transfer_send_start(handler.value,cu_flag); + + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("1,c_plane alloc error\r\n"); + continue; + } + + ptr = (uint8_t *)buf; + *(uint32_t*)(ptr + 0) = gu32_value; + *(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl; + *(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl; + *(uint32_t*)(ptr + 12) = read_stc_local_timer(); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("1,c_plane send error\r\n"); + } + + ret = msg_transfer_send_end(handler.value,cu_flag); + + /************U_PLANE***************/ + cu_flag = U_PLANE; + ret = msg_transfer_send_start(handler.value,cu_flag); + + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("1,u_plane alloc error\r\n"); + continue; + } + + ptr = (uint8_t *)buf; + *(uint32_t*)(ptr + 0) = gu32_value; + *(uint32_t*)(ptr + 4) = gu32_tick_from_tx_ctrl; + *(uint32_t*)(ptr + 8) = gu32_tick_receive_ctrl; + *(uint32_t*)(ptr + 12) = read_stc_local_timer(); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("1,u_plane send error\r\n"); + } + + ret = msg_transfer_send_end(handler.value,cu_flag); + } + } + return 0; +} + diff --git a/test/case1/src/testcase.c b/test/case1/src/testcase.c new file mode 100644 index 0000000..4a3140c --- /dev/null +++ b/test/case1/src/testcase.c @@ -0,0 +1,279 @@ +//test define start +#define _GNU_SOURCE +#include +#include +#include +//#include +#include +#include +#include +#include "typedef.h" +#include "ospHeap.h" +#include "ucp_printf.h" + +/*typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef long int int64_t; +typedef unsigned long int uint64_t;*/ + +extern int32_t g_dev_mem_fd; + +static uint64_t get_cycle() + { + uint64_t cycle; + + asm volatile("mrs %0, pmccntr_el0" : "=r" (cycle)); + + return cycle; + } + +int32_t test_case(uint32_t argc, int32_t* argvp) +//test_case(int argc, char *argv[]) +{ + uint64_t stack_len = 0; + uint32_t memset_len = 0; + uint32_t ctl = 0,cnt, i = 0, j = 0, temp_len = 0; + //uint8_t *memset_ptr; + char *memset_stack_heap_ptr; + char *memset_msg_heap_ptr; + char *memset_ape_phy_heap_ptr; + void *stack_heap_ptr; + void *stack_static_ptr; + void *msg_heap_ptr; + void *msg_static_ptr; + void *ape_phy_heap_ptr; + void *ape_phy_static_ptr; + struct timeval begin,end,medium; + uint64_t start_cnt = 0, end_cnt = 0, medium_cnt = 0; + + UCP_PRINT_DEBUG("start running testcase 1."); + + if(argc < 3) + { + printf("paramete need to be 3: len,ctl,cnt\n"); + return -1; + } + + memset_len = (uint32_t)argvp[0]; + ctl = (uint32_t)argvp[1]; + cnt = (uint32_t)argvp[2]; + + stack_static_ptr = get_static_mem(ARM_STACK, &stack_len); + if((void *)OSP_ERROR == stack_static_ptr) + { + printf("get_static_mem-ARM_STACK:error\n"); + } + else + { + printf("get_static_mem-ARM_STACK:ok! stack_static_ptr = %lx\n",(uint64_t)stack_static_ptr); + } + stack_heap_ptr = osp_heap_mem_init(stack_static_ptr, stack_len, stack_static_ptr, ARM_STACK); + memset_stack_heap_ptr = (char *)osp_alloc_heap_mem(stack_heap_ptr,memset_len); + + msg_static_ptr = get_static_mem(ARM_APE_MSG, &stack_len); + if((void *)OSP_ERROR == msg_static_ptr) + { + printf("get_static_mem-MSG:error\n"); + } + else + { + printf("get_static_mem-MSG:ok! msg_static_ptr = %lx\n",(uint64_t)msg_static_ptr); + } + msg_heap_ptr = osp_heap_mem_init(msg_static_ptr, stack_len, msg_static_ptr, ARM_APE_MSG); + memset_msg_heap_ptr = (char *)osp_alloc_heap_mem(msg_heap_ptr,memset_len); + + ape_phy_static_ptr = get_static_mem(APE_PHY, &stack_len); + if((void *)OSP_ERROR == ape_phy_static_ptr) + { + printf("get_static_mem-APE_PHY:error\n"); + } + else + { + printf("get_static_mem-APE_PHY:ok! ape_phy_static_ptr = %lx\n",(uint64_t)ape_phy_static_ptr); + } + ape_phy_heap_ptr = osp_heap_mem_init(ape_phy_static_ptr, stack_len, ape_phy_static_ptr, APE_PHY); + memset_ape_phy_heap_ptr = (char *)osp_alloc_heap_mem(ape_phy_heap_ptr,memset_len); + + + if(0 == ctl) + { + memset_msg_heap_ptr += 0x20; + while(1) + { + memset(memset_msg_heap_ptr, 0xa5 + i, 0x80); + i++; + osp_clean_dcache_area(memset_msg_heap_ptr, 0x54); + //usleep(300); + } + } + else if(1 == ctl) //上行 + { + for(i = 0; i < cnt; i++) + { + memset(memset_msg_heap_ptr,0xa5 + i,memset_len); + gettimeofday(&begin, NULL); + start_cnt = get_cycle(); + //memset(memset_ptr,0x5A,memset_len); + //invalid + osp_invalid_dcache_area(ARM_APE_MSG,(uint64_t)memset_msg_heap_ptr,memset_len); + medium_cnt = get_cycle(); + gettimeofday(&medium, NULL); + memcpy(memset_stack_heap_ptr,memset_msg_heap_ptr,memset_len); + end_cnt = get_cycle(); + gettimeofday(&end, NULL); + printf("gettimeofday_msg2stack start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",begin.tv_usec,medium.tv_usec,end.tv_usec,medium.tv_usec - begin.tv_usec,end.tv_usec - begin.tv_usec); + //printf("gettimeofday_medium start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",medium.tv_usec,medium.tv_usec,medium.tv_usec - begin.tv_usec); + printf("TSC_msg2stack start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",start_cnt,medium_cnt,end_cnt,medium_cnt - start_cnt,end_cnt - start_cnt); + + memset(memset_ape_phy_heap_ptr,0x55,memset_len); + gettimeofday(&begin, NULL); + start_cnt = get_cycle(); + memcpy(memset_stack_heap_ptr,memset_ape_phy_heap_ptr,memset_len); + end_cnt = get_cycle(); + gettimeofday(&end, NULL); + printf("gettimeofday_phy2stack start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + printf("TSC_phy2stack start_cnt=%#lx,end_cnt=%#lx,diff=%ld\n\n",start_cnt,end_cnt,end_cnt - start_cnt); + } + } + else if(2 == ctl) //下行 + { + for(i = 0; i < cnt; i++) + { + memset(memset_stack_heap_ptr,0x5a + i,memset_len); + gettimeofday(&begin, NULL); + start_cnt = get_cycle(); + memcpy(memset_msg_heap_ptr,memset_stack_heap_ptr,memset_len); + medium_cnt = get_cycle(); + gettimeofday(&medium, NULL); + osp_clean_dcache_area(memset_msg_heap_ptr,memset_len); + end_cnt = get_cycle(); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",begin.tv_usec,medium.tv_usec,end.tv_usec,medium.tv_usec - begin.tv_usec,end.tv_usec - begin.tv_usec); + //printf("gettimeofday_medium start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",medium.tv_usec,medium.tv_usec,medium.tv_usec - begin.tv_usec); + printf("TSC_stack2msg start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",start_cnt,medium_cnt,end_cnt,medium_cnt - start_cnt,end_cnt - start_cnt); + + gettimeofday(&begin, NULL); + start_cnt = get_cycle(); + memcpy(memset_ape_phy_heap_ptr,memset_stack_heap_ptr,memset_len); + end_cnt = get_cycle(); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2phy start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + printf("TSC_stack2phy start_cnt=%#lx,end_cnt=%#lx,diff=%ld\n\n",start_cnt,end_cnt,end_cnt - start_cnt); + } + } + else if(3 == ctl) //上行,先invalidate stack、msg,再memcpy + { + for(i = 0; i < cnt; i++) + { + memset(memset_msg_heap_ptr,0xa5 + i,memset_len); + + //invalid + gettimeofday(&begin, NULL); + osp_invalid_dcache_area(ARM_STACK,(uint64_t)memset_stack_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg_invalidate stack buf start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + + //invalid + gettimeofday(&begin, NULL); + osp_invalid_dcache_area(ARM_APE_MSG,(uint64_t)memset_msg_heap_ptr,memset_len); + gettimeofday(&end, NULL); + + printf("gettimeofday_stack2msg_invalidate msg buf start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + gettimeofday(&begin, NULL); + memcpy(memset_stack_heap_ptr,memset_msg_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_msg2stack start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",begin.tv_usec,medium.tv_usec,end.tv_usec,medium.tv_usec - begin.tv_usec,end.tv_usec - begin.tv_usec); + + + memset(memset_ape_phy_heap_ptr,0x55,memset_len); + gettimeofday(&begin, NULL); + osp_invalid_dcache_area(ARM_STACK,(uint64_t)memset_stack_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg_invalidate stack buf start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + + gettimeofday(&begin, NULL); + memcpy(memset_stack_heap_ptr,memset_ape_phy_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_phy2stack start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + + } + } + else if(4 == ctl) //下行,先invalidate stack,再memcpy + { + memset(memset_stack_heap_ptr, 0x5a + i, memset_len); + + for(i = 0; i < cnt; i++) + { + //invalid + gettimeofday(&begin, NULL); + osp_invalid_dcache_area(ARM_STACK,(uint64_t)memset_stack_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg_invalidate stack buf start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + + temp_len = 0; + gettimeofday(&begin, NULL); + for(j = 0; j < 100; j++) + { + memcpy(memset_msg_heap_ptr + temp_len, memset_stack_heap_ptr + temp_len, 1400); + temp_len += 1400; + } + gettimeofday(&medium, NULL); + osp_clean_dcache_area(memset_msg_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg start_cnt=%#lx,medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",begin.tv_usec,medium.tv_usec,end.tv_usec,medium.tv_usec - begin.tv_usec,end.tv_usec - begin.tv_usec); + + + //invalid + gettimeofday(&begin, NULL); + osp_invalid_dcache_area(ARM_STACK,(uint64_t)memset_stack_heap_ptr,memset_len); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg_invalidate stack buf start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + + temp_len = 0; + gettimeofday(&begin, NULL); + for(j = 0; j < 100; j++) + { + memcpy(memset_ape_phy_heap_ptr + temp_len, memset_stack_heap_ptr + temp_len, memset_len); + temp_len += 1400; + } + gettimeofday(&end, NULL); + printf("gettimeofday_stack2phy start_cnt=%#lx,end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + } + + } + else if(5 == ctl) + { + for(i = 0; i < cnt; i++) + { + memset(memset_stack_heap_ptr,0x5a + i,memset_len); + gettimeofday(&begin, NULL); + start_cnt = get_cycle(); + memcpy(memset_msg_heap_ptr,memset_stack_heap_ptr,memset_len); + medium_cnt = get_cycle(); + gettimeofday(&medium, NULL); + osp_clean_dcache_area(memset_msg_heap_ptr,memset_len); + end_cnt = get_cycle(); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2msg start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",begin.tv_usec,medium.tv_usec,end.tv_usec,medium.tv_usec - begin.tv_usec,end.tv_usec - begin.tv_usec); + //printf("gettimeofday_medium start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",medium.tv_usec,medium.tv_usec,medium.tv_usec - begin.tv_usec); + printf("TSC_stack2msg start_cnt=%#lx, medium_cnt=%lx,end_cnt=%#lx,diff0 = %ld,diff1 = %ld\n\n",start_cnt,medium_cnt,end_cnt,medium_cnt - start_cnt,end_cnt - start_cnt); + + gettimeofday(&begin, NULL); + start_cnt = get_cycle(); + memcpy(memset_ape_phy_heap_ptr,memset_stack_heap_ptr,memset_len); + end_cnt = get_cycle(); + gettimeofday(&end, NULL); + printf("gettimeofday_stack2phy start_cnt=%#lx, end_cnt=%#lx,diff = %ld\n\n",begin.tv_usec,end.tv_usec,end.tv_usec - begin.tv_usec); + printf("TSC_stack2phy start_cnt=%#lx,end_cnt=%#lx,diff=%ld\n\n",start_cnt,end_cnt,end_cnt - start_cnt); + } + } + //free(memset_ptr); + osp_free_heap_mem(stack_heap_ptr,memset_stack_heap_ptr); + osp_free_heap_mem(msg_heap_ptr,memset_msg_heap_ptr); + osp_free_heap_mem(ape_phy_heap_ptr,memset_ape_phy_heap_ptr); + + return 0; +} + diff --git a/test/case2/src/testcase.c b/test/case2/src/testcase.c new file mode 100644 index 0000000..fe50b91 --- /dev/null +++ b/test/case2/src/testcase.c @@ -0,0 +1,592 @@ +//test define start +#define _GNU_SOURCE +#include +#include +#include +//#include +#include +#include +#include +#include "typedef.h" +#include "ospHeap.h" +#include "ucp_printf.h" +#include "arm_csu.h" +#include "memcpy_csu.h" + +extern int32_t g_dev_mem_fd; + +static uint64_t get_cycle() +{ + uint64_t cycle; + + asm volatile("mrs %0, pmccntr_el0" : "=r" (cycle)); + + return cycle; +} + +// mode=0, memcpy +// mode=1, csu +int32_t test_arm_csu_simple(uint64_t addrVirSrc, uint64_t addrVirDst, int dataLen) +{ + struct timeval begin,end; + UCP_PRINT_DEBUG("init src data. \r\n"); + for (int i = 0; i < (dataLen>>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen); + + UCP_PRINT_DEBUG("src addr virt to phy. \r\n"); + uint64_t addrSrc = 0; + osp_virt_to_phy(APE_PHY, addrVirSrc, &addrSrc); + UCP_PRINT_DEBUG("src phy addr = 0x%lx .\r\n", addrSrc); + + UCP_PRINT_DEBUG("dst addr virt to phy. \r\n"); + uint64_t addrDst = 0; + osp_virt_to_phy(APE_PHY, addrVirDst, &addrDst); + UCP_PRINT_DEBUG("dst phy addr = 0x%lx .\r\n", addrDst); + + UCP_PRINT_DEBUG("start csu transfer. \r\n"); + gettimeofday(&begin, NULL); + int tag = arm_csu_dma_1D_transfer((uint64_t)addrSrc, (uint64_t)addrDst, dataLen); + arm_csu_wait_done(tag); +#if 0 + while (0 == (status&(1<>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen*cycle); + + UCP_PRINT_DEBUG("src addr virt to phy. \r\n"); + uint64_t addrSrc = 0; + osp_virt_to_phy(APE_PHY, addrVirSrc, &addrSrc); + UCP_PRINT_DEBUG("src phy addr = 0x%lx .\r\n", addrSrc); + + UCP_PRINT_DEBUG("dst addr virt to phy. \r\n"); + uint64_t addrDst = 0; + osp_virt_to_phy(APE_PHY, addrVirDst, &addrDst); + UCP_PRINT_DEBUG("dst phy addr = 0x%lx .\r\n", addrDst); + + if (0 == mode) + { + UCP_PRINT_DEBUG("memcpy cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy((void*)inAddrDst, (void*)inAddrSrc, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("100 of nocache to nocache memcpy cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0004) = (end.tv_usec - begin.tv_usec); + } + else + { + UCP_PRINT_DEBUG("arm csu cost test start ..... \r\n"); + inAddrSrc = addrSrc; + inAddrDst = addrDst; + int tag = 0; + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + tag = arm_csu_dma_1D_transfer(inAddrSrc, inAddrDst, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + arm_csu_wait_done(tag); + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("last tag = %d. \r\n", tag); + UCP_PRINT_DEBUG("100 of nocache to nocache arm csu cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0008) = (end.tv_usec - begin.tv_usec); + } + + return 0; +} + + +int32_t test_cache_to_nocache(uint64_t addrVirSrc, uint64_t addrVirDst, int dataLen, int cycle, int mode) +{ + uint64_t inAddrSrc = addrVirSrc; + uint64_t inAddrDst = addrVirDst; + struct timeval begin,end; + + UCP_PRINT_DEBUG("init src data. \r\n"); + for (int i = 0; i < ((dataLen*cycle)>>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen*cycle); + + UCP_PRINT_DEBUG("src addr virt to phy. \r\n"); + uint64_t addrSrc = 0; + osp_virt_to_phy(ARM_STACK, addrVirSrc, &addrSrc); + UCP_PRINT_DEBUG("src phy addr = 0x%lx .\r\n", addrSrc); + + UCP_PRINT_DEBUG("dst addr virt to phy. \r\n"); + uint64_t addrDst = 0; + osp_virt_to_phy(APE_TEXT, addrVirDst, &addrDst); + UCP_PRINT_DEBUG("dst phy addr = 0x%lx .\r\n", addrDst); + + if (0 == mode) + { + UCP_PRINT_DEBUG("memcpy cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy((void*)inAddrDst, (void*)inAddrSrc, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("100 of cache to noncache memcpy cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0010) = (end.tv_usec - begin.tv_usec); + } + else + { + int tag = 0; + UCP_PRINT_DEBUG("arm csu cost test start ..... \r\n"); + inAddrSrc = addrSrc; + inAddrDst = addrDst; + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { +// osp_clean_dcache_area((void*)inAddrSrc, dataLen); + osp_clean_dcache_area((void*)(addrVirSrc+i*dataLen), dataLen); + tag = arm_csu_dma_1D_transfer(inAddrSrc, inAddrDst, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + arm_csu_wait_all_done(); + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("last tag = %d. \r\n", tag); + UCP_PRINT_DEBUG("100 of cache to noncache arm csu cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0014) = (end.tv_usec - begin.tv_usec); + } + + return 0; +} + +int32_t test_nocache_to_cache(uint64_t addrVirSrc, uint64_t addrVirDst, int dataLen, int cycle, int mode) +{ + uint64_t inAddrSrc = addrVirSrc; + uint64_t inAddrDst = addrVirDst; + struct timeval begin,end; + + UCP_PRINT_DEBUG("init src data. \r\n"); + for (int i = 0; i < ((dataLen*cycle)>>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen*cycle); + + UCP_PRINT_DEBUG("src addr virt to phy. \r\n"); + uint64_t addrSrc = 0; + osp_virt_to_phy(APE_TEXT, addrVirSrc, &addrSrc); + UCP_PRINT_DEBUG("src phy addr = 0x%lx .\r\n", addrSrc); + + UCP_PRINT_DEBUG("dst addr virt to phy. \r\n"); + uint64_t addrDst = 0; + osp_virt_to_phy(ARM_STACK, addrVirDst, &addrDst); + UCP_PRINT_DEBUG("dst phy addr = 0x%lx .\r\n", addrDst); + + if (0 == mode) + { + UCP_PRINT_DEBUG("memcpy cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy((void*)inAddrDst, (void*)inAddrSrc, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("100 of nocache to cache memcpy cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0020) = (end.tv_usec - begin.tv_usec); + } + else + { + int tag = 0; + int lenAlign = dataLen; + if (dataLen & (~0x3F)) + { + lenAlign = (((dataLen>>6)+1)<<6); + } + UCP_PRINT_DEBUG("arm csu cost test start ..... \r\n"); + UCP_PRINT_DEBUG("lenAlign = %d. \r\n", lenAlign); + inAddrSrc = addrSrc; + inAddrDst = addrDst; + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + osp_flush_dcache_area((void*)(addrVirDst+i*lenAlign), dataLen); + tag = arm_csu_dma_1D_transfer(inAddrSrc, inAddrDst, dataLen); +// osp_invalid_dcache_area(ARM_STACK, (addrVirDst+i*lenAlign), lenAlign); + inAddrSrc += dataLen; + inAddrDst += lenAlign; + } + arm_csu_wait_all_done(); + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("last tag = %d. \r\n", tag); + UCP_PRINT_DEBUG("100 of nocache to cache arm csu cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0024) = (end.tv_usec - begin.tv_usec); + } + + return 0; +} + +int32_t test_cache_to_cache(uint64_t addrVirSrc, uint64_t addrVirDst, int dataLen, int cycle, int mode) +{ + uint64_t inAddrSrc = addrVirSrc; + uint64_t inAddrDst = addrVirDst; + struct timeval begin,end; + + UCP_PRINT_DEBUG("init src data. \r\n"); + for (int i = 0; i < ((dataLen*cycle)>>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen*cycle); + + UCP_PRINT_DEBUG("src addr virt to phy. \r\n"); + uint64_t addrSrc = 0; + osp_virt_to_phy(ARM_STACK, addrVirSrc, &addrSrc); + UCP_PRINT_DEBUG("src phy addr = 0x%lx .\r\n", addrSrc); + + UCP_PRINT_DEBUG("dst addr virt to phy. \r\n"); + uint64_t addrDst = 0; + osp_virt_to_phy(ARM_STACK, addrVirDst, &addrDst); + UCP_PRINT_DEBUG("dst phy addr = 0x%lx .\r\n", addrDst); + + if (0 == mode) + { + UCP_PRINT_DEBUG("memcpy cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy((void*)inAddrDst, (void*)inAddrSrc, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("100 of cache to cache memcpy cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0030) = (end.tv_usec - begin.tv_usec); + } + else + { + int tag = 0; + int lenAlign = dataLen; + if (dataLen & (~0x3F)) + { + lenAlign = (((dataLen>>6)+1)<<6); + } + UCP_PRINT_DEBUG("arm csu cost test start ..... \r\n"); + UCP_PRINT_DEBUG("lenAlign = %d. \r\n", lenAlign); + inAddrSrc = addrSrc; + inAddrDst = addrDst; + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + osp_clean_dcache_area((void*)(addrVirSrc+i*dataLen), dataLen); + osp_flush_dcache_area((void*)(addrVirDst+i*lenAlign), dataLen); + tag = arm_csu_dma_1D_transfer(inAddrSrc, inAddrDst, dataLen); + //osp_invalid_dcache_area(ARM_STACK, (addrVirDst+i*lenAlign), lenAlign); + inAddrSrc += dataLen; + inAddrDst += lenAlign; + } + arm_csu_wait_all_done(); + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("last tag = %d. \r\n", tag); + UCP_PRINT_DEBUG("100 of cache to cache arm csu cost: %ld. \r\n", (end.tv_usec - begin.tv_usec)); + *((uint32_t*)addrVirSrc+0xF0034) = (end.tv_usec - begin.tv_usec); + } + + return 0; +} + +void test_arm_csu(void) +{ + uint64_t stack_len = 0; + void *stack_static_ptr; + void *ape_phy_static_ptr; + void *ape_txt_static_ptr; + + stack_static_ptr = get_static_mem(ARM_STACK, &stack_len); // cache, 4g + if((void *)OSP_ERROR == stack_static_ptr) + { + UCP_PRINT_ERROR("get_static_mem-ARM_STACK:error\n"); + } + else + { + UCP_PRINT_DEBUG("get_static_mem-ARM_STACK:ok! stack_static_ptr = %lx\n",(uint64_t)stack_static_ptr); + } + + ape_phy_static_ptr = get_static_mem(APE_PHY, &stack_len); // noncache, 2g + if((void *)OSP_ERROR == ape_phy_static_ptr) + { + UCP_PRINT_ERROR("get_static_mem-APE_PHY:error\n"); + } + else + { + UCP_PRINT_DEBUG("get_static_mem-APE_PHY:ok! ape_phy_static_ptr = %lx\n",(uint64_t)ape_phy_static_ptr); + } + + ape_txt_static_ptr = get_static_mem(APE_TEXT, &stack_len); // noncache, 2g + if((void *)OSP_ERROR == ape_txt_static_ptr) + { + UCP_PRINT_ERROR("get_static_mem-APE_TEXT:error\n"); + } + else + { + UCP_PRINT_DEBUG("get_static_mem-APE_TEXT:ok! ape_txt_static_ptr = %lx\n",(uint64_t)ape_txt_static_ptr); + } + + int dataLen = 0; + uint64_t addrVirSrc = 0; + uint64_t addrVirDst = 0; + + UCP_PRINT_DEBUG("arm csu simple test start ...... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)ape_phy_static_ptr; + addrVirDst = (uint64_t)(ape_phy_static_ptr+0x80000); + test_arm_csu_simple(addrVirSrc, addrVirDst, dataLen); + + UCP_PRINT_DEBUG("nocache to noncache memcpy cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(ape_phy_static_ptr + dataLen); + addrVirDst = (uint64_t)(ape_phy_static_ptr+0x80000+dataLen); + test_nocache_to_nocache(addrVirSrc, addrVirDst, dataLen, 100, 0); + + UCP_PRINT_DEBUG("nocache to noncache arm csu cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc += (dataLen*100); + addrVirDst += (dataLen*100); + test_nocache_to_nocache(addrVirSrc, addrVirDst, dataLen, 100, 1); + + UCP_PRINT_DEBUG("cache to noncache memcpy cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)stack_static_ptr; + addrVirDst = (uint64_t)ape_txt_static_ptr; + test_cache_to_nocache(addrVirSrc, addrVirDst, dataLen, 100, 0); + + UCP_PRINT_DEBUG("cache to noncache arm csu cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(stack_static_ptr+0x40000); + addrVirDst = (uint64_t)(ape_txt_static_ptr+0x40000); + test_cache_to_nocache(addrVirSrc, addrVirDst, dataLen, 100, 1); + + + UCP_PRINT_DEBUG("nocache to cache memcpy cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(ape_txt_static_ptr+0x80000); + addrVirDst = (uint64_t)(stack_static_ptr+0x80000); + test_nocache_to_cache(addrVirSrc, addrVirDst, dataLen, 100, 0); + + UCP_PRINT_DEBUG("nocache to cache arm csu cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(ape_txt_static_ptr+0xC0000); + addrVirDst = (uint64_t)(stack_static_ptr+0xC0000); + test_nocache_to_cache(addrVirSrc, addrVirDst, dataLen, 100, 1); + + + UCP_PRINT_DEBUG("cache to cache memcpy cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(stack_static_ptr+0x100000); + addrVirDst = (uint64_t)(stack_static_ptr+0x180000); + test_cache_to_cache(addrVirSrc, addrVirDst, dataLen, 100, 0); + + UCP_PRINT_DEBUG("cache to cache arm csu cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(stack_static_ptr+0x140000); + addrVirDst = (uint64_t)(stack_static_ptr+0x1C0000); + test_cache_to_cache(addrVirSrc, addrVirDst, dataLen, 100, 1); +} + +int32_t test_memcpy_csu_stack_to_msg(uint64_t addrVirSrc, uint64_t addrVirDst, int dataLen, int cycle, int mode) +{ + uint64_t inAddrSrc = addrVirSrc; + uint64_t inAddrDst = addrVirDst; + struct timeval begin,end; + + UCP_PRINT_DEBUG("init src data. \r\n"); + for (int i = 0; i < ((dataLen*cycle)>>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen*cycle); + + if (0 == mode) + { + UCP_PRINT_DEBUG("memcpy cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy((void*)inAddrDst, (void*)inAddrSrc, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("%d of stack to msg memcpy cost: %ld. \r\n", cycle, (end.tv_usec - begin.tv_usec)); + } + else + { + UCP_PRINT_DEBUG("arm csu cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy_csu(inAddrDst, inAddrSrc, dataLen, STACK2MSG, 0); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + arm_csu_wait_all_done(); + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("%d of stack to msg arm csu cost: %ld. \r\n", cycle, (end.tv_usec - begin.tv_usec)); + } + + return 0; +} + +int32_t test_memcpy_csu_msg_to_stack(uint64_t addrVirSrc, uint64_t addrVirDst, int dataLen, int cycle, int mode) +{ + uint64_t inAddrSrc = addrVirSrc; + uint64_t inAddrDst = addrVirDst; + struct timeval begin,end; + + UCP_PRINT_DEBUG("init src data. \r\n"); + for (int i = 0; i < ((dataLen*cycle)>>2); i++) + { + *((uint32_t*)addrVirSrc+i) = i; + } + UCP_PRINT_DEBUG("init dst data. \r\n"); + memset((void*)addrVirDst, 0, dataLen*cycle); + + if (0 == mode) + { + UCP_PRINT_DEBUG("memcpy cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy((void*)inAddrDst, (void*)inAddrSrc, dataLen); + osp_clean_dcache_area((void *)inAddrDst, dataLen); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("%d of msg to stack memcpy cost: %ld. \r\n", cycle, (end.tv_usec - begin.tv_usec)); + } + else + { + UCP_PRINT_DEBUG("arm csu cost test start ..... \r\n"); + gettimeofday(&begin, NULL); + for (int i = 0; i < cycle; i++) + { + memcpy_csu(inAddrDst, inAddrSrc, dataLen, MSG2STACK, 1); + inAddrSrc += dataLen; + inAddrDst += dataLen; + } +// arm_csu_wait_all_done(); + gettimeofday(&end, NULL); + UCP_PRINT_DEBUG("%d of msg to stack arm csu cost: %ld. \r\n", cycle, (end.tv_usec - begin.tv_usec)); + } + + return 0; +} + + +void test_memcpy_csu(void) +{ + uint64_t stack_len = 0; + uint64_t msg_len = 0; + void *stack_static_ptr = NULL; + void *msg_static_ptr = NULL; + + stack_static_ptr = get_static_mem(ARM_STACK, &stack_len); // cache, 4g + if((void *)OSP_ERROR == stack_static_ptr) + { + UCP_PRINT_ERROR("get_static_mem-ARM_STACK:error\n"); + } + else + { + UCP_PRINT_DEBUG("get_static_mem-ARM_STACK:ok! stack_static_ptr = %lx, len = %lx.\n",(uint64_t)stack_static_ptr, stack_len); + } + + msg_static_ptr = get_static_mem(ARM_APE_MSG, &msg_len); // noncache, 128M + if((void *)OSP_ERROR == msg_static_ptr) + { + UCP_PRINT_ERROR("get_static_mem-ARM_APE_MSG:error\n"); + } + else + { + UCP_PRINT_DEBUG("get_static_mem-ARM_APE_MSG:ok! msg_static_ptr = %lx, len = %lx.\n",(uint64_t)msg_static_ptr, msg_len); + } + + int dataLen = 0; + uint64_t addrVirSrc = 0; + uint64_t addrVirDst = 0; + + UCP_PRINT_DEBUG("stack to msg memcpy cost test start ...... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(stack_static_ptr); + addrVirDst = (uint64_t)(msg_static_ptr); + test_memcpy_csu_stack_to_msg(addrVirSrc, addrVirDst, dataLen, 100, 0); + + UCP_PRINT_DEBUG("stack to msg arm csu cost test start ..... \r\n"); + dataLen = 1400; + addrVirSrc = (uint64_t)(stack_static_ptr+0x40000); + addrVirDst = (uint64_t)(msg_static_ptr+0x40000); + test_memcpy_csu_stack_to_msg(addrVirSrc, addrVirDst, dataLen, 100, 1); + + + UCP_PRINT_DEBUG("msg to stack memcpy cost test start ...... \r\n"); + dataLen = 140000; + addrVirSrc = (uint64_t)(msg_static_ptr+0x80000); + addrVirDst = (uint64_t)(stack_static_ptr+0x80000); + test_memcpy_csu_msg_to_stack(addrVirSrc, addrVirDst, dataLen, 1, 0); + + UCP_PRINT_DEBUG("msg to stack arm csu cost test start ..... \r\n"); + dataLen = 140000; + addrVirSrc = (uint64_t)(msg_static_ptr+0xC0000); + addrVirDst = (uint64_t)(stack_static_ptr+0xC0000); + test_memcpy_csu_msg_to_stack(addrVirSrc, addrVirDst, dataLen, 1, 1); +} + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 2."); + + UCP_PRINT_DEBUG("start arm csu init. \r\n"); +// arm_csu_init(); + + test_memcpy_csu(); + + return 0; +} + diff --git a/test/case3/src/testcase.c b/test/case3/src/testcase.c new file mode 100644 index 0000000..97c5b7e --- /dev/null +++ b/test/case3/src/testcase.c @@ -0,0 +1,169 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include + +#include "typedef.h" +#include "msg_transfer_layer.h" +#include "ucp_handshake.h" +#include "typedef.h" +#include "ucp_printf.h" +#include "msg_transfer_mem.h" +#include "ecs_sm_mgt.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "ospLog.h" +#include "ospDump.h" + +static inline void get_msg_transfer_info(uint16_t port_index, uint16_t inst_id, uint16_t transfer_type, transfer_type_info_s* transfer_type_info_ptr) +{ + queue_info_s c_plane,u_plane; + + switch (transfer_type) { + case CU_SPLIT: + c_plane.rx_block_size = 0x25800; + c_plane.rx_block_num = 32; + c_plane.rx_callback = NULL; + c_plane.tx_block_size = 0x8000; + c_plane.tx_block_num = 8; + c_plane.tx_callback = NULL; + + u_plane.rx_block_size = 0x28000; + u_plane.rx_block_num = 8; + //u_plane.rx_callback = rx_callback_data; + if (0 == inst_id) + { + u_plane.rx_callback = NULL; + } + else + { + u_plane.rx_callback = NULL; + } + u_plane.tx_block_size = 0x28000; + u_plane.tx_block_num = 8; + u_plane.tx_callback = NULL; + + transfer_type_info_ptr->queue_cplane_info = c_plane; + transfer_type_info_ptr->queue_uplane_info = u_plane; + break; + case OAM: + c_plane.rx_block_size = 0x100000; + c_plane.rx_block_num = 32; + c_plane.rx_callback = rx_callback_oam; + c_plane.tx_block_size = 0x8000; + c_plane.tx_block_num = 8; + c_plane.tx_callback = NULL; + + transfer_type_info_ptr->queue_cplane_info = c_plane; + break; + default: + UCP_PRINT_ERROR("get_msg_queue_cfg doesn't support transfer_type[%d] .",transfer_type); + break; + } + + return; +} + +static inline void msg_transfer_cfg(void) +{ + uint8_t port_id = 0; + uint16_t inst_id = 0; + uint16_t transfer_type = 0; + int32_t handle_id = 0; + transfer_type_info_s transfer_type_info; + + for (inst_id=0; inst_idpSyncInfo->queueCfgFlag = ++pMsgQueueLocalMgt->localSyncInfo.queueCfgFlag; + + return; +} + +static inline void msg_transfer_queue_polling(void) +{ + uint8_t port_id = 0; + HandleId_t handler; + uint16_t cu_flag; + uint32_t offset = 0; + uint32_t len = 0; + uint8_t* msg_ptr; + + for (uint32_t i = 0; i < MAX_INSTANCE_NUM; i++) { + handler.port_id = port_id; + handler.inst_id = i; + handler.type_id = CU_SPLIT; + cu_flag = C_PLANE; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + + cu_flag = U_PLANE; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + + handler.type_id = OAM; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + } + + return; +} + +OSP_FUNCPTR arm_log_test() +{ + char abuf1[128] = "test1234test1234test1234test1234test1234test1234test1234test1234test1234test1234test1234test1234test1234test1234test1234test567"; + char abuf2[10] = "abcdefg\n"; + + osp_write_diaglog(abuf1, strlen(abuf1), 13, 0x61); + osp_write_diaglog(abuf2, strlen(abuf2), 13, 0x60); + + return OSP_OK; + +} + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 3."); + + msg_transfer_mem_init(); + msg_transfer_cfg(); + ucp_handshake(); + + UCP_PRINT_DEBUG("start transfering message."); + + while(1) { + usleep(500); + msg_transfer_queue_polling(); + } + + return 0; +} + diff --git a/test/case30/src/testcase30.c b/test/case30/src/testcase30.c new file mode 100644 index 0000000..50de651 --- /dev/null +++ b/test/case30/src/testcase30.c @@ -0,0 +1,233 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ +#include +#include +#include +#include +#include +#include + +#include "typedef.h" +#include "ucp_printf.h" +#include "ucp_common.h" +#include "msg_transfer_layer.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "stc_drv.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include "ospTask.h" + +#define port 9000 +#define FastCMDataLen (512)//(44*4*16)//pionter = 20 +struct sockaddr_in SrcAddr; +struct sockaddr_in DstAddr; + +char pBuffer[4096] = {0}; +char recvBuffer[4096] = {0}; +int32_t sockfd,rawsockfd; +int32_t Len0; +int32_t Len1; + +void Cpri_GmacTx_Data_Init(void) +{ + int32_t i=0; + + for(i=0;i<4096;i++) + { + //pBuffer[i] = (0x11223344+i); + pBuffer[i] = 0x5a; + } +} +//TX +int8_t Cpri_Gmac_Socket(void) +{ + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + perror("socket"); + return -1; + } + printf("socket init pass!!!!!!!!\r\n"); + + memset(&DstAddr, 0, sizeof(DstAddr)); + + DstAddr.sin_family = AF_INET; + DstAddr.sin_port = htons(port); + DstAddr.sin_addr.s_addr = inet_addr("192.168.30.241"); +// DstAddr.sin_addr.s_addr = htonl(INADDR_ANY); + return 0; + +} +//RX +int8_t Cpri_Gmac_RawSocket(void) +{ + //rawsockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP); + rawsockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + + //rawsockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP)); + //rawsockfd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW); + if (rawsockfd < 0) { + perror("socket"); + return -1; + } + printf("RAWsocket init pass!!!!!!!!\r\n"); + + return 0; + +} + +int8_t Cpri_GmacTx(void) +{ + + //while(1) + for(uint32_t i = 0; i<10 ;i++) + { + Len0 = sendto(sockfd, pBuffer, FastCMDataLen, 0, (struct sockaddr *)&DstAddr, sizeof(struct sockaddr_in)); + printf("Start sendto:%d!!!!!!!!\r\n",Len0); + if (Len0 != FastCMDataLen) + { + return (-1); + printf("send error!!!!!!!!!!\r\n"); + } + usleep(1000); + printf("send cycle:%d!!!!!!!!\r\n",i); + } + while(1); + return 0; +} + +void Cpri_GmacRx(void) +{ + char *ethhead,*iphead;//*p; + void *stack_static_ptr; + uint64_t stack_len; + uint8_t iProtocol; + uint16_t iPlen; + // uint32_t iDstPort; +// uint32_t n=0xFF; + uint32_t cycle = 0; + stack_static_ptr = get_static_mem(APE_PHY, &stack_len); + if((void *)OSP_ERROR == stack_static_ptr) + { + printf("get_static_mem-ARM_STACK:error\n"); + } + else + { + printf("get_static_mem-ARM_STACK:ok! stack_static_ptr = %lx\n",(uint64_t)stack_static_ptr); + } + printf("stack_static_len = %lx\n",stack_len); + while(1) + { + Len1 = recvfrom(rawsockfd, recvBuffer, 1024, 0, NULL, NULL); + //printf("recv length:%d!!!!!!!!\r\n",Len1); + + ethhead = recvBuffer; + + iphead = ethhead + 14 ; + + iProtocol = (*(iphead +9)); + iPlen = ((iphead[2]<<8) | (iphead[3])); + // p = iphead + 20; + // iDstPort = ((p[2]<<8)&0xff00) | (p[3]&n); + // printf("recv DstPort:%d!!!!!!!!\r\n",iDstPort); + printf("recv iProtocol:%d!!!!!!!!\r\n",iProtocol); + printf("recv iPlen:%d!!!!!!!!\r\n",iPlen); + + + //if((Len1 >= 512) && (cycle < 100)) + //if(cycle < 100) + if(iProtocol == 17) + { + if(iPlen == 540) + { + memcpy((char *)stack_static_ptr + 0x70000000+1024*cycle , recvBuffer,Len1); + cycle++; + } + } + + + printf("recv cycle:%d!!!!!!!!\r\n",cycle); + // printf("recv end!!!!!!!!\r\n"); + } + +} + +int8_t start_CpriGmacTx_task(void) +{ + OSP_TASKMSG_REG Gmac_Tx_task; + + memset(&Gmac_Tx_task, 0, sizeof(Gmac_Tx_task)); + Gmac_Tx_task.TaskId = CpriGmacTx; + memcpy(Gmac_Tx_task.TaskName, "CpriGmacTx", 10); + Gmac_Tx_task.TaskPri = RT_NOMSG_PRI(96); + Gmac_Tx_task.Init = NULL; + Gmac_Tx_task.MainLoop = (OSP_FUNCPTR)Cpri_GmacTx; + Gmac_Tx_task.Cpu = 2; + Gmac_Tx_task.MsgType = OSP_OTHER_MSG; + + if (OSP_OK != osp_regtask(&Gmac_Tx_task)) + { + UCP_PRINT_ERROR("[start_log_task]: osp_regtask error!\n"); + return OSP_ERROR; + } + return OSP_OK; +} + +int8_t start_CpriGmacRx_task(void) +{ + OSP_TASKMSG_REG Gmac_Rx_task; + + memset(&Gmac_Rx_task, 0, sizeof(Gmac_Rx_task)); + Gmac_Rx_task.TaskId = CpriGmacRx; + memcpy(Gmac_Rx_task.TaskName, "CpriGmacRx", 10); + Gmac_Rx_task.TaskPri = RT_NOMSG_PRI(95); + Gmac_Rx_task.Init = NULL; + Gmac_Rx_task.MainLoop = (OSP_FUNCPTR)Cpri_GmacRx; + Gmac_Rx_task.Cpu = 3; + Gmac_Rx_task.MsgType = OSP_OTHER_MSG; + + if (OSP_OK != osp_regtask(&Gmac_Rx_task)) + { + UCP_PRINT_ERROR("[start_log_task]: osp_regtask error!\n"); + return OSP_ERROR; + } + return OSP_OK; +} + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + + UCP_PRINT_DEBUG("start running testcase 30."); + ucp_mem_init(); + + ucp_handshake(); + sleep(10); + Cpri_GmacTx_Data_Init(); + Cpri_Gmac_Socket(); + Cpri_Gmac_RawSocket(); + + start_CpriGmacTx_task(); + start_CpriGmacRx_task(); + + UCP_PRINT_DEBUG("start cpri gmac tx."); + return 0; +} + diff --git a/test/case4/src/testcase.c b/test/case4/src/testcase.c new file mode 100644 index 0000000..07a1ca7 --- /dev/null +++ b/test/case4/src/testcase.c @@ -0,0 +1,448 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include + +#include "typedef.h" +#include "msg_transfer_layer.h" +#include "ucp_handshake.h" +#include "typedef.h" +#include "ucp_printf.h" +#include "msg_transfer_mem.h" +#include "pet_sm_mgt.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "ospLog.h" +#include "ospDump.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 MSG_TRANSFER_OAM_MSG_TYPE 0x125 + +extern uint8_t guc_oam; + +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; +} 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; +} 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; + +uint32_t rx_callback_oam_spu(const char* buf,uint32_t payloadSize) +{ + OamMsgTransferHeader_t *header_ptr = NULL; + SpuOamBaseDelaySetRsp_t *oam_base_delay_set_rsp_ptr = NULL; + SpuOamBaseDelayQryRsp_t *oam_base_delay_qry_rsp_ptr = NULL; + SpuOamFiberDelayQryRsp_t *oam_fiber_delay_qry_rsp_ptr = NULL; + + header_ptr = (OamMsgTransferHeader_t *)buf; + header_ptr->msgLen = payloadSize; + + //UCP_PRINT_ERROR("rx_callback_oam_spu msgType: 0x%x payloadSize:%d buf:%p\n", header_ptr->msgType, payloadSize, buf); + + switch(header_ptr->msgType) + { + case MSG_TRANSFER_LOG_MSG_TYPE: + rx_callback_oam(buf, payloadSize); + break; + case SPU_OAM_BASE_DELAY_SET_RSP: + oam_base_delay_set_rsp_ptr = (SpuOamBaseDelaySetRsp_t *)(buf+sizeof(OamMsgTransferHeader_t)); + UCP_PRINT_SHELL("cellIndex:%d u8result:%u u8fiber_port:%u\n", \ + header_ptr->cellIndex,\ + oam_base_delay_set_rsp_ptr->u8result, \ + oam_base_delay_set_rsp_ptr->u8fiber_port); + //memset((void *)buf, 0, payloadSize); + break; + case SPU_OAM_BASE_DELAY_QRY_RSP: + oam_base_delay_qry_rsp_ptr = (SpuOamBaseDelayQryRsp_t *)(buf+sizeof(OamMsgTransferHeader_t)); + UCP_PRINT_SHELL("u8fiber_port:%u u8result:%u u32dl_frame_offset:0x%x u32ul_frame_offset:0x%x\n", \ + oam_base_delay_qry_rsp_ptr->u8fiber_port, oam_base_delay_qry_rsp_ptr->u8result, \ + oam_base_delay_qry_rsp_ptr->u32dl_frame_offset, oam_base_delay_qry_rsp_ptr->u32ul_frame_offset); + //memset((void *)buf, 0, payloadSize); + break; + case SPU_OAM_FIBER_DELAY_QRY_RSP: + oam_fiber_delay_qry_rsp_ptr = (SpuOamFiberDelayQryRsp_t *)(buf+sizeof(OamMsgTransferHeader_t)); + UCP_PRINT_SHELL("u8fiber_port:%u u8result:%u u8rsv[0]:%d u8rsv[1]:%d u32t14_val:0x%x\n", \ + oam_fiber_delay_qry_rsp_ptr->u8fiber_port, oam_fiber_delay_qry_rsp_ptr->u8result, \ + oam_fiber_delay_qry_rsp_ptr->u8rsv[0], oam_fiber_delay_qry_rsp_ptr->u8rsv[1], oam_fiber_delay_qry_rsp_ptr->u32t14_val); + //memset((void *)buf, 0, payloadSize); + break; + } + + return payloadSize; +} + +static inline void get_msg_transfer_info(uint16_t port_index, uint16_t inst_id, uint16_t transfer_type, transfer_type_info_s* transfer_type_info_ptr) +{ + queue_info_s c_plane,u_plane; + + switch (transfer_type) { + case CU_SPLIT: + c_plane.rx_block_size = 0x25800; + c_plane.rx_block_num = 32; + c_plane.rx_callback = NULL; + c_plane.tx_block_size = 0x8000; + c_plane.tx_block_num = 8; + c_plane.tx_callback = NULL; + + u_plane.rx_block_size = 0x28000; + u_plane.rx_block_num = 8; + //u_plane.rx_callback = rx_callback_data; + if (0 == inst_id) + { + u_plane.rx_callback = NULL; + } + else + { + u_plane.rx_callback = NULL; + } + u_plane.tx_block_size = 0x28000; + u_plane.tx_block_num = 8; + u_plane.tx_callback = NULL; + + transfer_type_info_ptr->queue_cplane_info = c_plane; + transfer_type_info_ptr->queue_uplane_info = u_plane; + break; + case OAM: + c_plane.rx_block_size = 0x100000; + c_plane.rx_block_num = 32; + c_plane.rx_callback = rx_callback_oam_spu; + //c_plane.rx_callback = rx_callback_oam; + c_plane.tx_block_size = 0x8000; + c_plane.tx_block_num = 8; + c_plane.tx_callback = NULL; + + transfer_type_info_ptr->queue_cplane_info = c_plane; + break; + default: + UCP_PRINT_ERROR("get_msg_queue_cfg doesn't support transfer_type[%d] .",transfer_type); + break; + } + + return; +} + +static inline void msg_transfer_cfg(void) +{ + uint8_t port_id = 0; + uint16_t inst_id = 0; + uint16_t transfer_type = 0; + int32_t handle_id = 0; + transfer_type_info_s transfer_type_info; + + for (inst_id=0; inst_idpSyncInfo->queueCfgFlag = ++pMsgQueueLocalMgt->localSyncInfo.queueCfgFlag; + + return; +} + +static inline void msg_transfer_queue_polling(void) +{ + uint8_t port_id = 0; + HandleId_t handler; + uint16_t cu_flag; + uint32_t offset = 0; + uint32_t len = 0; + uint8_t* msg_ptr; + + for (uint32_t i = 0; i < MAX_INSTANCE_NUM; i++) { + handler.port_id = port_id; + handler.inst_id = i; + handler.type_id = CU_SPLIT; + cu_flag = C_PLANE; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + + cu_flag = U_PLANE; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + + handler.type_id = OAM; + msg_transfer_receive(handler.value, cu_flag, offset, len, &msg_ptr); + } + + return; +} + +void oam_msg_base_delay_set_test() +{ + uint32_t size = 24; + char* buf; + uint32_t availableSize,offset; + OamMsgTransferHeader_t stOamMsg; + SpuOamBaseDelaySetReq_t stOamDelayReq; + + uint16_t cu_flag = C_PLANE; + HandleId_t handler; + handler.port_id = 0; + handler.inst_id = 0; + handler.type_id = OAM; + + int32_t ret = msg_transfer_send_start(handler.value, cu_flag); + + /************C_PLANE***************/ + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("oam_msg_test call msg_transfer_alloc_msg err."); + return ; + } + + + stOamMsg.cellIndex = 0; + stOamMsg.numMsg = 1; + stOamMsg.msgType = SPU_OAM_BASE_DELAY_SET_REQ; + stOamMsg.msgLen = size; + + stOamDelayReq.u8fiber_port = 2; + stOamDelayReq.u32dl_frame_offset = 0xab; + stOamDelayReq.u32ul_frame_offset = 0xcd; + + //memset(buf, 0, size); + //memcpy((uint8_t *)stOamMsg.msgData, (uint8_t *)&stOamDelayReq, sizeof(SpuOamBaseDelaySetReq_t)); + memcpy(buf, (uint8_t *)&stOamMsg, sizeof(OamMsgTransferHeader_t)); + memcpy((uint8_t *)(buf+sizeof(OamMsgTransferHeader_t)), (uint8_t *)&stOamDelayReq, sizeof(SpuOamBaseDelaySetReq_t)); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("msg_transfer_send_msg send error\r\n"); + } + msg_transfer_send_end(handler.value,cu_flag); + + printf("\n-----------------------------------------------------------\n"); + for (int i = 0; i < size;i++) + { + printf("%02x ", buf[i]); + + if ((i & 0x7) == 0x7) + { + printf("\n"); + } + } + + return; +} + +void oam_msg_base_delay_qry_test() +{ + uint32_t size = sizeof(OamMsgTransferHeader_t)+sizeof(SpuOamBaseDelayQryReq_t); + char* buf; + uint32_t availableSize,offset; + OamMsgTransferHeader_t stOamMsg; + SpuOamBaseDelayQryReq_t stOamBaseDelayReq; + + uint16_t cu_flag = C_PLANE; + HandleId_t handler; + handler.port_id = 0; + handler.inst_id = 0; + handler.type_id = OAM; + + int32_t ret = msg_transfer_send_start(handler.value, cu_flag); + + /************C_PLANE***************/ + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("oam_msg_test call msg_transfer_alloc_msg err."); + return ; + } + + stOamMsg.cellIndex = 0; + stOamMsg.numMsg = 1; + stOamMsg.msgType = SPU_OAM_BASE_DELAY_QRY_REQ; + stOamMsg.msgLen = size; + + stOamBaseDelayReq.u8fiber_port = 3; + stOamBaseDelayReq.u8rsv[0] = 0; + stOamBaseDelayReq.u8rsv[1] = 0; + stOamBaseDelayReq.u8rsv[2] = 0; + + //memcpy((uint8_t *)stOamMsg.msgData, (uint8_t *)&stOamBaseDelayReq, sizeof(SpuOamBaseDelayQryReq_t)); + memcpy(buf, (uint8_t *)&stOamMsg, size); + memcpy((uint8_t *)(buf+sizeof(OamMsgTransferHeader_t)), (uint8_t *)&stOamBaseDelayReq, sizeof(SpuOamBaseDelayQryReq_t)); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("msg_transfer_send_msg send error\r\n"); + } + + msg_transfer_send_end(handler.value, cu_flag); + + printf("\n-----------------------------------------------------------\n"); + for (int i = 0; i < size;i++) + { + printf("%02x ", buf[i]); + + if ((i & 0x7) == 0x7) + { + printf("\n"); + } + } + + return; +} + +void oam_msg_fiber_deley_qry_test() +{ + uint32_t size = sizeof(OamMsgTransferHeader_t) + sizeof(SpuOamFiberDelayQryReq_t); + char* buf; + uint32_t availableSize,offset; + OamMsgTransferHeader_t stOamMsg; + SpuOamFiberDelayQryReq_t stOamFiberDelayQryReq; + + uint16_t cu_flag = C_PLANE; + HandleId_t handler; + handler.port_id = 0; + handler.inst_id = 0; + handler.type_id = OAM; + + int32_t ret = msg_transfer_send_start(handler.value, cu_flag); + + /************C_PLANE***************/ + ret = msg_transfer_alloc_msg(handler.value, cu_flag, size, &buf, &availableSize, &offset); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("oam_msg_test call msg_transfer_alloc_msg err."); + return ; + } + + stOamMsg.cellIndex = 0; + stOamMsg.numMsg = 1; + stOamMsg.msgType = SPU_OAM_FIBER_DELAY_QRY_REQ; + stOamMsg.msgLen = size; + + stOamFiberDelayQryReq.u8fiber_port = 4; + stOamFiberDelayQryReq.u8rsv[0] = 0; + stOamFiberDelayQryReq.u8rsv[1] = 0; + stOamFiberDelayQryReq.u8rsv[2] = 0; + + //memcpy((uint8_t *)stOamMsg.msgData, (uint8_t *)&stOamFiberDelayQryReq, sizeof(SpuOamFiberDelayQryReq_t)); + memcpy(buf, (uint8_t *)&stOamMsg, size); + memcpy((uint8_t *)(buf+sizeof(OamMsgTransferHeader_t)), (uint8_t *)&stOamFiberDelayQryReq, sizeof(SpuOamFiberDelayQryReq_t)); + + ret = msg_transfer_send_msg(handler.value, cu_flag, (uint8_t *)buf, offset, size); + if ( SUCCESS != ret) { + UCP_PRINT_ERROR("msg_transfer_send_msg send error\r\n"); + } + msg_transfer_send_end(handler.value, cu_flag); + + printf("\n-----------------------------------------------------------\n"); + for (int i = 0; i < size;i++) + { + printf("%02x ", buf[i]); + + if ((i & 0x7) == 0x7) + { + printf("\n"); + } + } + + return; +} + + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 4."); + + msg_transfer_mem_init(); + msg_transfer_cfg(); + ucp_handshake(); + + UCP_PRINT_DEBUG("start transfering message."); + + while(1) + { + switch(guc_oam) + { + case 1: + oam_msg_base_delay_set_test(); + break; + case 2: + oam_msg_base_delay_qry_test(); + break; + case 3: + oam_msg_fiber_deley_qry_test(); + break; + } + guc_oam = 0; + usleep(500); + msg_transfer_queue_polling(); + } + + return 0; +} + diff --git a/test/case40/inc/ucp_api_clockGen.h b/test/case40/inc/ucp_api_clockGen.h new file mode 100644 index 0000000..578a326 --- /dev/null +++ b/test/case40/inc/ucp_api_clockGen.h @@ -0,0 +1,33 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_clockGen.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_CLOCKGEN_H_ +#define UCP_API_CLOCKGEN_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_CLOCKGEN_Reset(void); +extern void UCP_API_CLOCKGEN_Init(void); +extern void UCP_API_CLOCKGEN_LockStatus(void); +extern void UCP_API_CLOCKGEN_OnePluse(void); +extern uint8_t UCP_API_CLOCKGEN_getLockStatus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_CLOCKGEN_H_ */ diff --git a/test/case40/inc/ucp_api_jesd.h b/test/case40/inc/ucp_api_jesd.h new file mode 100644 index 0000000..357b9a3 --- /dev/null +++ b/test/case40/inc/ucp_api_jesd.h @@ -0,0 +1,47 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_jesd.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_JESD_H_ +#define UCP_API_JESD_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_JESD_PlatformSetup (void); +extern void UCP_API_JESD_Reset(void); +extern void UCP_API_JESD_CRG_Cfg(void); +extern void UCP_API_JESD_PMA_Cfg(void); +extern void UCP_API_JESD_JsSubCtrl_Cfg(void); +extern void UCP_API_JESD_SUB_Init(void); +extern void UCP_API_JESD_Gpio_Cfg(void); +extern void UCP_API_RF_PA_Pow(void); +extern void UCP_API_RF_PA_Set(void); +extern void UCP_API_RF_PA_Get(void); +extern void UCP_API_RF_LNA_Pow(void); +extern void UCP_API_RF_LNA_Set(void); +extern void UCP_API_RF_LNA_Get(void); +extern void UCP_API_RF_RFFE_Tx(void); +extern void UCP_API_RF_RFFE_Rx(void); +extern void UCP_API_RF_RFFE_Att_Set(void); +extern void UCP_API_RF_RFFE_Att_Get(void); +extern void UCP_API_RF_RFFE_Gain_Set(void); +extern void UCP_API_RF_RFFE_Gain_Get(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_JESD_H_ */ diff --git a/test/case40/inc/ucp_api_transceiver.h b/test/case40/inc/ucp_api_transceiver.h new file mode 100644 index 0000000..7376d23 --- /dev/null +++ b/test/case40/inc/ucp_api_transceiver.h @@ -0,0 +1,50 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_transceiver.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_TRANSCEIVER_H_ +#define UCP_API_TRANSCEIVER_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_TRANSCEIVER_Reset(void); +extern void UCP_API_TRANSCEIVER_Init(void); +extern void UCP_API_TRANSCEIVER_MGC_Cfg(void); +extern void UCP_API_TRANSCEIVER_Gain_Set(void); +extern void UCP_API_TRANSCEIVER_Gain_Get(void); +extern void UCP_API_TRANSCEIVER_Att_Set(void); +extern void UCP_API_TRANSCEIVER_Att_Get(void); +extern void UCP_API_TRANSCEIVER_TRX_Cfg(void); +extern void UCP_API_TRANSCEIVER_Tx(void); +extern void UCP_API_TRANSCEIVER_Rx(void); +extern void UCP_API_TRANSCEIVER_LO_Set(void); +extern void UCP_API_TRANSCEIVER_LO_Get(void); +extern void UCP_API_TRANSCEIVER_IQ_Cal(void); +extern void UCP_API_TRANSCEIVER_MCS(void); +extern void UCP_API_TRANSCEIVER_SampleRate_Get(void); +extern void UCP_API_TRANSCEIVER_Bandwidth_Get(void); +extern void UCP_API_TRANSCEIVER_LinkStatus(void); +extern void UCP_API_TRANSCEIVER_Tone(bool set); +extern int16_t UCP_API_TRANSCEIVER_getTemperature(void); +extern uint32_t UCP_API_TRANSCEIVER_getLockStatus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_TRANSCEIVER_H_ */ diff --git a/test/case40/src/testcase.c b/test/case40/src/testcase.c new file mode 100644 index 0000000..feb1768 --- /dev/null +++ b/test/case40/src/testcase.c @@ -0,0 +1,49 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include + +#include "typedef.h" +#include "ucp_printf.h" +#include "msg_transfer_mem.h" +#include "ecs_sm_mgt.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "stc_drv.h" +#include "ospLog.h" +#include "osp_cfg_to_bin.h" + +#include "ucp_api_jesd.h" +#include "ucp_api_transceiver.h" + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 40."); + + UCP_PRINT_DEBUG("start monitor temperature and lock status."); + + while (1) + { + UCP_API_TRANSCEIVER_getTemperature(); + UCP_API_TRANSCEIVER_getLockStatus(); + + sleep(2); + } + + return 0; +} + diff --git a/test/case41/inc/ucp_api_clockGen.h b/test/case41/inc/ucp_api_clockGen.h new file mode 100644 index 0000000..578a326 --- /dev/null +++ b/test/case41/inc/ucp_api_clockGen.h @@ -0,0 +1,33 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_clockGen.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_CLOCKGEN_H_ +#define UCP_API_CLOCKGEN_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_CLOCKGEN_Reset(void); +extern void UCP_API_CLOCKGEN_Init(void); +extern void UCP_API_CLOCKGEN_LockStatus(void); +extern void UCP_API_CLOCKGEN_OnePluse(void); +extern uint8_t UCP_API_CLOCKGEN_getLockStatus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_CLOCKGEN_H_ */ diff --git a/test/case41/inc/ucp_api_jesd.h b/test/case41/inc/ucp_api_jesd.h new file mode 100644 index 0000000..357b9a3 --- /dev/null +++ b/test/case41/inc/ucp_api_jesd.h @@ -0,0 +1,47 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_jesd.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_JESD_H_ +#define UCP_API_JESD_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_JESD_PlatformSetup (void); +extern void UCP_API_JESD_Reset(void); +extern void UCP_API_JESD_CRG_Cfg(void); +extern void UCP_API_JESD_PMA_Cfg(void); +extern void UCP_API_JESD_JsSubCtrl_Cfg(void); +extern void UCP_API_JESD_SUB_Init(void); +extern void UCP_API_JESD_Gpio_Cfg(void); +extern void UCP_API_RF_PA_Pow(void); +extern void UCP_API_RF_PA_Set(void); +extern void UCP_API_RF_PA_Get(void); +extern void UCP_API_RF_LNA_Pow(void); +extern void UCP_API_RF_LNA_Set(void); +extern void UCP_API_RF_LNA_Get(void); +extern void UCP_API_RF_RFFE_Tx(void); +extern void UCP_API_RF_RFFE_Rx(void); +extern void UCP_API_RF_RFFE_Att_Set(void); +extern void UCP_API_RF_RFFE_Att_Get(void); +extern void UCP_API_RF_RFFE_Gain_Set(void); +extern void UCP_API_RF_RFFE_Gain_Get(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_JESD_H_ */ diff --git a/test/case41/inc/ucp_api_transceiver.h b/test/case41/inc/ucp_api_transceiver.h new file mode 100644 index 0000000..7376d23 --- /dev/null +++ b/test/case41/inc/ucp_api_transceiver.h @@ -0,0 +1,50 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_transceiver.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_TRANSCEIVER_H_ +#define UCP_API_TRANSCEIVER_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_TRANSCEIVER_Reset(void); +extern void UCP_API_TRANSCEIVER_Init(void); +extern void UCP_API_TRANSCEIVER_MGC_Cfg(void); +extern void UCP_API_TRANSCEIVER_Gain_Set(void); +extern void UCP_API_TRANSCEIVER_Gain_Get(void); +extern void UCP_API_TRANSCEIVER_Att_Set(void); +extern void UCP_API_TRANSCEIVER_Att_Get(void); +extern void UCP_API_TRANSCEIVER_TRX_Cfg(void); +extern void UCP_API_TRANSCEIVER_Tx(void); +extern void UCP_API_TRANSCEIVER_Rx(void); +extern void UCP_API_TRANSCEIVER_LO_Set(void); +extern void UCP_API_TRANSCEIVER_LO_Get(void); +extern void UCP_API_TRANSCEIVER_IQ_Cal(void); +extern void UCP_API_TRANSCEIVER_MCS(void); +extern void UCP_API_TRANSCEIVER_SampleRate_Get(void); +extern void UCP_API_TRANSCEIVER_Bandwidth_Get(void); +extern void UCP_API_TRANSCEIVER_LinkStatus(void); +extern void UCP_API_TRANSCEIVER_Tone(bool set); +extern int16_t UCP_API_TRANSCEIVER_getTemperature(void); +extern uint32_t UCP_API_TRANSCEIVER_getLockStatus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_TRANSCEIVER_H_ */ diff --git a/test/case41/src/testcase.c b/test/case41/src/testcase.c new file mode 100644 index 0000000..9559d97 --- /dev/null +++ b/test/case41/src/testcase.c @@ -0,0 +1,45 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include + +#include "typedef.h" +#include "ucp_printf.h" +#include "msg_transfer_mem.h" +#include "ecs_sm_mgt.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "stc_drv.h" +#include "ospLog.h" +#include "osp_cfg_to_bin.h" + +#include "ucp_api_jesd.h" +#include "ucp_api_transceiver.h" + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 41."); + + UCP_PRINT_DEBUG("start transceiver tone."); + + UCP_API_JESD_PlatformSetup(); + UCP_API_TRANSCEIVER_Init(); + UCP_API_TRANSCEIVER_Tone(true); + + return 0; +} + diff --git a/test/case42/inc/ucp_api_clockGen.h b/test/case42/inc/ucp_api_clockGen.h new file mode 100644 index 0000000..578a326 --- /dev/null +++ b/test/case42/inc/ucp_api_clockGen.h @@ -0,0 +1,33 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_clockGen.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_CLOCKGEN_H_ +#define UCP_API_CLOCKGEN_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_CLOCKGEN_Reset(void); +extern void UCP_API_CLOCKGEN_Init(void); +extern void UCP_API_CLOCKGEN_LockStatus(void); +extern void UCP_API_CLOCKGEN_OnePluse(void); +extern uint8_t UCP_API_CLOCKGEN_getLockStatus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_CLOCKGEN_H_ */ diff --git a/test/case42/inc/ucp_api_jesd.h b/test/case42/inc/ucp_api_jesd.h new file mode 100644 index 0000000..357b9a3 --- /dev/null +++ b/test/case42/inc/ucp_api_jesd.h @@ -0,0 +1,47 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_jesd.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_JESD_H_ +#define UCP_API_JESD_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_JESD_PlatformSetup (void); +extern void UCP_API_JESD_Reset(void); +extern void UCP_API_JESD_CRG_Cfg(void); +extern void UCP_API_JESD_PMA_Cfg(void); +extern void UCP_API_JESD_JsSubCtrl_Cfg(void); +extern void UCP_API_JESD_SUB_Init(void); +extern void UCP_API_JESD_Gpio_Cfg(void); +extern void UCP_API_RF_PA_Pow(void); +extern void UCP_API_RF_PA_Set(void); +extern void UCP_API_RF_PA_Get(void); +extern void UCP_API_RF_LNA_Pow(void); +extern void UCP_API_RF_LNA_Set(void); +extern void UCP_API_RF_LNA_Get(void); +extern void UCP_API_RF_RFFE_Tx(void); +extern void UCP_API_RF_RFFE_Rx(void); +extern void UCP_API_RF_RFFE_Att_Set(void); +extern void UCP_API_RF_RFFE_Att_Get(void); +extern void UCP_API_RF_RFFE_Gain_Set(void); +extern void UCP_API_RF_RFFE_Gain_Get(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_JESD_H_ */ diff --git a/test/case42/inc/ucp_api_transceiver.h b/test/case42/inc/ucp_api_transceiver.h new file mode 100644 index 0000000..7376d23 --- /dev/null +++ b/test/case42/inc/ucp_api_transceiver.h @@ -0,0 +1,50 @@ +//******************** (C) COPYRIGHT 2022 SmartLogic******************************* +// FileName : ucp_api_transceiver.h +// Author : boheng.lin@smartlogictech.com +// Date First Issued : 2023-03-04 02:37:50 PM +// Last Modified : +// Description : +// ------------------------------------------------------------ +// Modification History: +// Version Date Author Modification Description +// +//********************************************************************************** + +#ifndef UCP_API_TRANSCEIVER_H_ +#define UCP_API_TRANSCEIVER_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void UCP_API_TRANSCEIVER_Reset(void); +extern void UCP_API_TRANSCEIVER_Init(void); +extern void UCP_API_TRANSCEIVER_MGC_Cfg(void); +extern void UCP_API_TRANSCEIVER_Gain_Set(void); +extern void UCP_API_TRANSCEIVER_Gain_Get(void); +extern void UCP_API_TRANSCEIVER_Att_Set(void); +extern void UCP_API_TRANSCEIVER_Att_Get(void); +extern void UCP_API_TRANSCEIVER_TRX_Cfg(void); +extern void UCP_API_TRANSCEIVER_Tx(void); +extern void UCP_API_TRANSCEIVER_Rx(void); +extern void UCP_API_TRANSCEIVER_LO_Set(void); +extern void UCP_API_TRANSCEIVER_LO_Get(void); +extern void UCP_API_TRANSCEIVER_IQ_Cal(void); +extern void UCP_API_TRANSCEIVER_MCS(void); +extern void UCP_API_TRANSCEIVER_SampleRate_Get(void); +extern void UCP_API_TRANSCEIVER_Bandwidth_Get(void); +extern void UCP_API_TRANSCEIVER_LinkStatus(void); +extern void UCP_API_TRANSCEIVER_Tone(bool set); +extern int16_t UCP_API_TRANSCEIVER_getTemperature(void); +extern uint32_t UCP_API_TRANSCEIVER_getLockStatus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* #ifndef UCP_API_TRANSCEIVER_H_ */ diff --git a/test/case42/src/testcase.c b/test/case42/src/testcase.c new file mode 100644 index 0000000..150c790 --- /dev/null +++ b/test/case42/src/testcase.c @@ -0,0 +1,46 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : test.c +// Author : xianfeng.du +// Created On : 2022-11-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#include +#include +#include +#include + +#include "typedef.h" +#include "ucp_printf.h" +#include "msg_transfer_mem.h" +#include "ecs_sm_mgt.h" +#include "ucp_handshake.h" +#include "ospShell.h" +#include "stc_drv.h" +#include "ospLog.h" +#include "osp_cfg_to_bin.h" + +#include "ucp_api_jesd.h" +#include "ucp_api_transceiver.h" + +extern void ad9025_rssi(void); + +int32_t test_case(uint32_t argc, int32_t* argvp) +{ + UCP_PRINT_DEBUG("start running testcase 42s."); + UCP_PRINT_DEBUG("print rssi."); + + UCP_API_JESD_PlatformSetup(); + UCP_API_TRANSCEIVER_Init(); + ad9025_rssi(); + + return 0; +} + diff --git a/tool/libncurses.tar.gz b/tool/libncurses.tar.gz new file mode 100644 index 0000000..0af3f61 Binary files /dev/null and b/tool/libncurses.tar.gz differ diff --git a/tool/readme.txt b/tool/readme.txt new file mode 100644 index 0000000..9f5b180 --- /dev/null +++ b/tool/readme.txt @@ -0,0 +1,11 @@ +1:将terminfo.tar.gz解压,传到evb单板侧替换/usr/share/terminfo,并设置TERMINFO,TERM环境变量; + +export TERMINFO=/usr/share/terminfo + +export TERM=xterms + +2: tmux-3.2.tar.gz 为tmux源码; + +3: tmux 放到/usr/sbin 、/usr/bin目录下 + +4:执行./tmux diff --git a/tool/terminfo.tar.gz b/tool/terminfo.tar.gz new file mode 100644 index 0000000..56d5546 Binary files /dev/null and b/tool/terminfo.tar.gz differ diff --git a/tool/tmux b/tool/tmux new file mode 100644 index 0000000..908491d Binary files /dev/null and b/tool/tmux differ diff --git a/tool/tmux-3.2.tar.gz b/tool/tmux-3.2.tar.gz new file mode 100644 index 0000000..3eabd55 Binary files /dev/null and b/tool/tmux-3.2.tar.gz differ