First commit

This commit is contained in:
chao1.wang 2023-07-12 14:14:31 +08:00
parent c86d963f9f
commit 2c80fc7f3c
137 changed files with 22660 additions and 0 deletions

6
.gitmodules vendored Normal file
View File

@ -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

52
app/inc/mem_sections.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

34
app/inc/pet_sm_mgt.h Normal file
View File

@ -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

31
app/inc/typedef.h Normal file
View File

@ -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

38
app/inc/ucp_handshake.h Normal file
View File

@ -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

74
app/inc/ucp_printf.h Normal file
View File

@ -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 <stdio.h>
//#include <stddef.h>
#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

41
app/inc/ucp_utility.h Normal file
View File

@ -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 <pthread.h>
#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

83
app/src/main.c Normal file
View File

@ -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 <sched.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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; i<count;i++) {
args[i] = (int32_t)strtoul(argvp[i+1],NULL,0);
}
test_case(count, args);
#endif
while (1)
{
usleep(100);
}
return 0;
}

127
app/src/mem_sections.c Normal file
View File

@ -0,0 +1,127 @@
// +FHDR------------------------------------------------------------
// Copyright (c) 2022 SmartLogic.
// ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename : mem_section.c
// Author : xianfeng.du
// Created On : 2022-06-25
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------
#include "mem_sections.h"
#include "ucp_printf.h"
MEM_SECTION_INFO RFM_IM_SECTION EcsSram = {
.baseAddr = (ECS_SRAM_BASE_ADDR + 0x0),
.currAddr = (ECS_SRAM_BASE_ADDR + 0x0),
.maxSize = ECS_SRAM_SIZE,
.memSectionName = "ECS_SRAM"
};
MEM_SECTION_INFO RFM_IM_SECTION PetSram = {
.baseAddr = (PET_SRAM_BASE_ADDR + 0x0),
.currAddr = (PET_SRAM_BASE_ADDR + 0x0),
.maxSize = PET_SRAM_SIZE,
.memSectionName = "PET_SRAM"
};
MEM_SECTION_INFO RFM_IM_SECTION MsgDdrMem = {
.baseAddr = (UCP_MSG_MEM_BASE_ADDR + 0x0),
.currAddr = (UCP_MSG_MEM_BASE_ADDR + 0x0),
.maxSize = UCP_MSG_MEM_SIZE,
.memSectionName = "MSG_DDR_MEM"
};
void memSectionInit(MEM_SECTION_INFO* memSecInfo, uint64_t baseAddr, uint32_t maxSize, char* memSectionName)
{
UCP_PRINT_LOG("[memSectionInit]: 0x%lx, 0x%lx, %u, %s", (uint64_t)memSecInfo, baseAddr, maxSize, memSectionName);
memSecInfo->baseAddr = 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;
}

View File

@ -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 <stddef.h>
#include <string.h>
#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;
}

View File

@ -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 <string.h>
#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;
}

View File

@ -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 <stdatomic.h>
#include <assert.h>
#include <stddef.h>
#include <string.h>
#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;
}

60
app/src/pet_sm_mgt.s.c Normal file
View File

@ -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;
}

44
app/src/ucp_handshake.c Normal file
View File

@ -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;
}

65
app/src/ucp_utility.c Normal file
View File

@ -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;
}

54
build.sh Executable file
View File

@ -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}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <assert.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#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<<tag)); // 0: not finished, 1: finished
}
int arm_csu_wait_done(uint8_t tag)
{
if (31 < tag)
{
UCP_PRINT_ERROR("input para error! tag = %d. \r\n", tag);
return -1;
}
volatile uint32_t status = 0;
while (1)
{
status = VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS);
// printf("tag = %d, dmastatus = 0x%x. \r\n", tag, status);
if (0 != (status&(1<<tag)))
{
break;
}
}
// while (0 == (VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS) & (1<<tag)));
return 0;
}
int arm_csu_wait_all_done(void)
{
#if 0
for (int i = 0; i < 32; i++)
{
arm_csu_wait_done(i);
}
#endif
while (1)
{
int cmdNum = 0;
for (int i = 0; i < 4; i++)
{
cmdNum += VIR_ADDR_VAL(virMemAddr, AP_CSU_CMDFIFO0_NUM+(i<<2));
}
if (0 == cmdNum)
{
break;
}
}
return 0;
}
//CmdFIFO 0 1 2 3
//tag 0 1 2 3 reg_group = 0(0->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<<regGroup)))
{
return -1;
}
return ((fifoNum<<16) | regGroup); // [31:16]fifoNum(0~3), [15:0]reg group(0~7)
}
int get_free_channel()
{
while (1)
{
for (int tag = 0; tag < 32; tag++)
{
if (0 == (VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS) & (1<<tag)))
{
continue;
}
else
{
uint32_t temp = get_free_reg_group(tag);
if (-1 == temp)
{
continue;
}
else
{
uint8_t regGroup = temp & 0xFF;
uint8_t fifoNum = (temp>>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;
}

View File

@ -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;
}

25
driver/cache/Makefile vendored Normal file
View File

@ -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

78
driver/cache/cache.S vendored Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <linux/errno.h>
#include <linux/linkage.h>
#include <linux/init.h>
//#include <asm/assembler.h>
#include <asm/alternative.h>
#include <asm/asm-uaccess.h>
/*
* 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)

532
driver/cache/osp_sm_ddr.c vendored Normal file
View File

@ -0,0 +1,532 @@
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/mod_devicetable.h>
#include <linux/of_address.h>
#include <asm/io.h>
#include <linux/async_tx.h>
#include <linux/dmaengine.h>
#include <linux/gfp.h>
#include <linux/dma-mapping.h>
/*函数原型*/
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");

View File

@ -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

View File

@ -0,0 +1,75 @@
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
//#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
#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;
}

20
driver/ioreg/Makefile Normal file
View File

@ -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

182
driver/ioreg/ioreg.c Normal file
View File

@ -0,0 +1,182 @@
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/device.h>
#include <linux/mm.h>
#include <linux/mod_devicetable.h>
#include <linux/of_address.h>
#include <asm/io.h>
#include <linux/async_tx.h>
#include <linux/dmaengine.h>
#include <linux/gfp.h>
#include <linux/dma-mapping.h>
#include <linux/list.h>
#include <linux/delay.h>
#include <linux/mailbox_client.h>
#include <asm/div64.h>
#include <linux/of_irq.h>
#include <linux/io.h>
#include <linux/semaphore.h>
#include <linux/interrupt.h>
#include <linux/clk.h>
#include <linux/timex.h>
#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);

288
driver/mem_dump/mem_dump.c Normal file
View File

@ -0,0 +1,288 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/poll.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <asm/io.h>
#include <linux/mm.h>//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);
/******************************* 源文件结束 ***********************************/

1
driver/rfic Submodule

@ -0,0 +1 @@
Subproject commit 1f8aef08469197a952e766f439fc0bfbc9a28ea5

25
driver/stc-dev/Makefile Normal file
View File

@ -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

357
driver/stc-dev/stc-dev.c Normal file
View File

@ -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 <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#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");

69
driver/stc-dev/stc_def.h Normal file
View File

@ -0,0 +1,69 @@
#ifndef _STC_DEF_H_
#define _STC_DEF_H_
#include <linux/module.h>
#include <linux/kernel.h> /*声明printk()这个内核态的函数*/
#include <linux/fs.h> /*文件系统有关的结构体file_operations也在fs头文件定义*/
#include <linux/init.h> /*init和exit相关宏*/
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/irq.h> /*linux中断定义*/
#include <asm/irq.h>
#include <linux/interrupt.h> /*包含与中断相关的大部分宏及结构体的定义request_irq()等*/
#include <asm/uaccess.h> /*linux中的用户态内存交互函数copy_from_user(),copy_to_user()等*/
#include <linux/platform_device.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h> /*misc混合设备注册与注销*/
#include <asm/io.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/workqueue.h>
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

1
driver/tfu Submodule

@ -0,0 +1 @@
Subproject commit 7908793098da2a3fcc5da3f3f2831c84fe4947f7

18
driver/tsc/Makefile Normal file
View File

@ -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

67
driver/tsc/tsc.c Normal file
View File

@ -0,0 +1,67 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/smp.h>
#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");

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,325 @@
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/device.h>
#include <linux/mm.h>
#include <linux/mod_devicetable.h>
#include <linux/of_address.h>
#include <asm/io.h>
#include <linux/async_tx.h>
#include <linux/dmaengine.h>
#include <linux/gfp.h>
#include <linux/dma-mapping.h>
#include "ucp_2_revmem.h"
/*暂时将ucp_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);

View File

@ -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

108
interface/arm_interface.h Normal file
View File

@ -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__ */

59
interface/memcpy_csu.h Normal file
View File

@ -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: 10
*
* Output(s):
*
*
* Returns:
*
********************************************************************/
void memcpy_csu_stack2stack(uint64_t dst_phy_addr, uint64_t src_phy_addr, uint32_t size,uint8_t check_flag);
/******************************************************************
* descriptionfapi消息内存之间数据搬移
* Input(s):
* stack_phy_addr:()
* msg_virt_addr:fapi消息内存地址()
* size:
* typeSTACK2MSG/MSG2STACK
* check_flag: 10
* 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

View File

@ -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

109
interface/ospHeap.h Normal file
View File

@ -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):
* modulemodule_type_e类型枚举值FAPI消息类型为ARM_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):
* modulemodule_type_e类型枚举值FAPI消息类型为ARM_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):
* <none>
*
* Returns:
* <none>
********************************************************************/
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):
* modulemodule_type_e类型枚举值FAPI消息类型为ARM_APE_MSG
* addr
* len
*
* Output(s):
* <none>
*
* 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

31
interface/typedef.h Normal file
View File

@ -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

1589
kernel/dts/ucp4008-evb.dts Normal file

File diff suppressed because it is too large Load Diff

0
lib/.gitignore vendored Normal file
View File

167
makefile Normal file
View File

@ -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)

23
osp/inc/OspMutProcess.h Normal file
View File

@ -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__ */

6
osp/inc/crc32.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __CRC32H__
#define __CRC32H__
uint32_t osp_crc32(uint32_t crc, const unsigned char *p, uint32_t len);
#endif

66
osp/inc/osp.h Normal file
View File

@ -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__ */

31
osp/inc/ospAtomicOp.h Normal file
View File

@ -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__ */

100
osp/inc/ospBuf.h Normal file
View File

@ -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__ */

34
osp/inc/ospCfgToBin.h Normal file
View File

@ -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__ */

79
osp/inc/ospDbg.h Normal file
View File

@ -0,0 +1,79 @@
#ifndef __OSPDBGH__
#define __OSPDBGH__
#ifdef __cplusplus
extern "C" {
#endif
#include <signal.h>
#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__ */

23
osp/inc/ospDelay.h Normal file
View File

@ -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__ */

98
osp/inc/ospDiag.h Normal file
View File

@ -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__ */

47
osp/inc/ospDump.h Normal file
View File

@ -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

36
osp/inc/ospFile.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _FILE_H_
#define _FILE_H_
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#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

57
osp/inc/ospHeap.h Normal file
View File

@ -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

14
osp/inc/ospHeartbeat.h Normal file
View File

@ -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__ */

810
osp/inc/ospList.h Normal file
View File

@ -0,0 +1,810 @@
#ifndef __HPP_LIST_H__
#define __HPP_LIST_H__
#include <stdbool.h>
#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

112
osp/inc/ospLog.h Normal file
View File

@ -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

22
osp/inc/ospMem.h Normal file
View File

@ -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

130
osp/inc/ospMsg.h Normal file
View File

@ -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__ */

26
osp/inc/ospNetShell.h Normal file
View File

@ -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__ */

20
osp/inc/ospOtherMsg.h Normal file
View File

@ -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__ */

31
osp/inc/ospRtc.h Normal file
View File

@ -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__ */

59
osp/inc/ospSem.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef __OSPSEMH__
#define __OSPSEMH__
#ifdef __cplusplus
extern "C" {
#endif
#include "ospTypes.h"
#include <sched.h>
#include <pthread.h>
#include <semaphore.h>
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__ */

119
osp/inc/ospShell.h Normal file
View File

@ -0,0 +1,119 @@
#ifndef _ospshelllxh
#define _ospshelllxh
#ifdef __cplusplus
extern "C" {
#endif
#include <termios.h>
#include <ctype.h>
#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; /* 目的核ID */
uint8_t src_task_id; /* 源任务ID */
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 */

63
osp/inc/ospSoftQue.h Normal file
View File

@ -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__ */

133
osp/inc/ospSwQueue.h Normal file
View File

@ -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__ */

66
osp/inc/ospSwTimer.h Normal file
View File

@ -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__ */

187
osp/inc/ospTask.h Normal file
View File

@ -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__ */

18
osp/inc/ospTcp.h Normal file
View File

@ -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__ */

19
osp/inc/ospTest.h Normal file
View File

@ -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__ */

80
osp/inc/ospTimer.h Normal file
View File

@ -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__ */

23
osp/inc/ospTypes.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef __OSPTYPESH__
#define __OSPTYPESH__
#include <stdbool.h>
#include "typedef.h"
#define OSP_OK (0) /* 正常返回 */
#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__ */

46
osp/inc/ospUdp.h Normal file
View File

@ -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__ */

123
osp/inc/ospUtil.h Normal file
View File

@ -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__ */

46
osp/src/OspMutProcess.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#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;
}

237
osp/src/crc32.c Normal file
View File

@ -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 <stddef.h>
#include <string.h>
#include <stdio.h>
#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));
}

200
osp/src/osp.c Normal file
View File

@ -0,0 +1,200 @@
/*
* ospInit - Initailize OSP
* input:
* none
* return
* OSP_OK
*/
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <limits.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#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

127
osp/src/ospAtomicOp.c Normal file
View File

@ -0,0 +1,127 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}
}

373
osp/src/ospBuf.c Normal file
View File

@ -0,0 +1,373 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ucontext.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#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<<SIZE_ORDER_SHELL), OSP_BUFQ_DECNT(que), (OSP_BUFQ_ENCNT(que) - OSP_BUFQ_DEP(que)),
(OSP_BUFQ_DEP(que) - OSP_BUFQ_CUR(que)), OSP_BUFQ_DEP(que), ((OSP_BUFQ_DEP(que) - OSP_BUFQ_CUR(que)) * 100) / (OSP_BUFQ_DEP(que)), "shell");
que = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_PRINT_LOG;
len += sprintf(pbuf+len, "%-16d%-16ld%-16ld%-16d%-16d%d%%\t\t%s\n", (1<<SIZE_ORDER_PRINT_LOG), OSP_BUFQ_DECNT(que), (OSP_BUFQ_ENCNT(que) - OSP_BUFQ_DEP(que)),
(OSP_BUFQ_DEP(que) - OSP_BUFQ_CUR(que)), OSP_BUFQ_DEP(que), ((OSP_BUFQ_DEP(que) - OSP_BUFQ_CUR(que)) * 100) / (OSP_BUFQ_DEP(que)), "Print&Log");
quebase = (Osp_BufQ_Tcb *)BUFFERQUE_BASE_NOR;
for (order = MIN_SIZE_ORDER; order < MAX_SIZE_ORDER+1; order++)
{
que = &quebase[order - MIN_SIZE_ORDER];
len += sprintf(pbuf+len, "%-16d%-16ld%-16ld%-16d%-16d%d%%\t\t%s\n", (1<<order), OSP_BUFQ_DECNT(que), (OSP_BUFQ_ENCNT(que) - OSP_BUFQ_DEP(que)),
(OSP_BUFQ_DEP(que) - OSP_BUFQ_CUR(que)), OSP_BUFQ_DEP(que), ((OSP_BUFQ_DEP(que) - OSP_BUFQ_CUR(que)) * 100) / (OSP_BUFQ_DEP(que)), "normal");
}
for (p = pbuf; p < pbuf+len; p += (MAX_DBGINFO_LEN-1))
{
osp_debug_out(CMD_DEBUG_LEVEL, "%s", p);
}
free(pbuf);
}
/*************************************************************************
* |--------|OspBufferBase(OspBufferqueBasePrintLog)
* | |timer_buffer queue的头
* | |512MAX_BLOCK_NUM4KB多点
* | |
* |--------|OspBufferDataBasePrintLog
* | |timer buffer512
* | |64KB32M
* | |
* |--------|OspBufferqueBaseShell
* | |"cmd_buffer"queue的头
* | |512MAX_BLOCK_NUM4KB多点
* | |
* |--------|OspBufferDataBaseShell
* | |"cmd_buffer"512
* | |64KB32M
* | |
* |--------|OspBufferQueBaseNor
* | |"normal_buffer"queue的头19-6+1
* | |512MAX_BLOCK_NUM4KB*14=56KB多
* | |
* |--------|OspBufferDataBaseShell
* | |"normal_buffer"
* | |2^6=64B 512
* | |2^7=128B 512
* | |2^8=256B 512
* | |...
* | |...
* | |...
* |--------|2^19=512KB512,512Mosp_buf_init一共申请约576M
***************************************************************************/
OSP_STATUS osp_buf_init(void)
{
int32_t ret = 0;
uint32_t SizeOfMem;
OspBufferBase = osp_get_init_mem(OSPBUF_SIZE);
OspBufferqueBasePrintLog = (char *)OSP_ROUND_UP(OspBufferBase, 32);
OspBufferDataBasePrintLog = (char *)OSP_ROUND_UP(OspBufferqueBasePrintLog + OSP_BUFQ_TCBSIZE, 32);
OspBufferqueBaseShell = (char *)OSP_ROUND_UP(OspBufferDataBasePrintLog + (1 << SIZE_ORDER_PRINT_LOG) * MAX_BLOCK_NUM, 32);
OspBufferDataBaseShell = (char *)OSP_ROUND_UP(OspBufferqueBaseShell + OSP_BUFQ_TCBSIZE,32);
OspBufferQueBaseNor = (char *)OSP_ROUND_UP(OspBufferDataBaseShell + (1 << SIZE_ORDER_SHELL) * MAX_BLOCK_NUM, 32);
OspBufferDataBaseNor = (char *)OSP_ROUND_UP(OspBufferQueBaseNor + OSP_BUFQ_TCBSIZE * (MAX_SIZE_ORDER - MIN_SIZE_ORDER + 1), 32);
if (0 == g_ProcessId)
{
ret = osp_buf_cb_init(&SizeOfMem);
osp_assert(SizeOfMem <= OSPBUF_SIZE);
// osp_debug_out_with_time(CMD_DEBUG_LEVEL, "osp_buf_init SizeOfMem is %d\r\n", SizeOfMem);
}
return (ret);
}

655
osp/src/ospCfgToBin.c Normal file
View File

@ -0,0 +1,655 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#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) /* 配置文件起始地址相对于PHY空间偏移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字节FlAG4字节NUM */
#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

627
osp/src/ospDbg.c Normal file
View File

@ -0,0 +1,627 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <termios.h>
#define _GNU_SOURCE
#include <dlfcn.h>
#include <signal.h>
#include <stdarg.h>
#include <execinfo.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#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);
}
}

57
osp/src/ospDelay.c Normal file
View File

@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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));
}

163
osp/src/ospDiag.c Normal file
View File

@ -0,0 +1,163 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#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;
}

713
osp/src/ospDump.c Normal file
View File

@ -0,0 +1,713 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <execinfo.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
#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<ullen;i++)
{
abuf[i] = i;
}
switch (ucApcId)
{
case APC_CORE_ID_0:
{
u64_start_offset = 0;
break;
}
case APC_CORE_ID_1:
{
u64_start_offset = SPU_DM_SIZE;
break;
}
case APC_CORE_ID_2:
{
u64_start_offset = SPU_DM_SIZE*2;
break;
}
case APC_CORE_ID_3:
{
u64_start_offset = SPU_DM_SIZE*3;
break;
}
default:
{
UCP_PRINT_ERROR("osp_show_dm_by_apcid: ucApcId:%u error\r\n", ucApcId);
break;
}
}
memcpy(gp_static_dm_mem+u64_start_offset, abuf, ullen);
osp_show_dm_by_apcid(ucApcId, ullAddr,ullen);
sprintf(filename, "apc%d.bin",ucApcId);
osp_dump_dm_by_apcid(filename, ucApcId, ullAddr, ullen);
//osp_dump_proc("test1125",pbuf,ullen);
//osp_dump_dis_mem(pbuf, ullen);
//osp_write_diaglog(gp_dump_buf, ullen, 0, 0x62);
return;
}
void osp_mem_print(char *addr , uint32_t ulLen)
{
uint32_t i;
if (NULL == addr)
{
return;
}
if (ulLen > 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;
}

146
osp/src/ospFile.c Normal file
View File

@ -0,0 +1,146 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#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;
}

655
osp/src/ospHeap.c Normal file
View File

@ -0,0 +1,655 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ucontext.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
#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璁惧<E79281>
{
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璁惧<E79281>
{
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;
}

350
osp/src/ospHeartbeat.c Normal file
View File

@ -0,0 +1,350 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#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;
}

57
osp/src/ospList.c Normal file
View File

@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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)

1305
osp/src/ospLog.c Normal file

File diff suppressed because it is too large Load Diff

72
osp/src/ospMem.c Normal file
View File

@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#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;
}

Some files were not shown because too many files have changed in this diff Show More