增加了一个c语言查询版本的代码,便于沟通调试;如果编译C语言版本,Makefile中控制系统都采用rv32i的march编译即可。

This commit is contained in:
2025-02-10 14:38:49 +08:00
parent 94acbfae03
commit 4d853a29d7
9 changed files with 539 additions and 592 deletions

View File

@@ -2,7 +2,14 @@
#include "tl2cdr.h"
#include "system_cfg.h"
#include "sysDef.h"
#include "halfLvdsMacSvr.h"
#ifdef __riscv_i
#define USING_POLL_STRATEGY
#endif
//-------------------------------------------------------------------
volatile uint32_t *const plic_priority = (uint32_t *)(0xc000000U);
volatile uint32_t *plic_pending_0_31 = (uint32_t*)( 0xc000000U + 0X001000 );
@@ -11,20 +18,39 @@ volatile uint32_t *plic_enable_0_31 = (uint32_t*)( 0xc000000U + 0X002000 );
volatile uint32_t *plic_threshold_0 = (uint32_t*)( 0xc000000U + 0X200000 );
volatile uint32_t *plic_claim = (uint32_t*)( 0xc000000U + 0X200004 );
uint8_t MST_TX_BUF[TX_BUF_NUM * TX_BUF_MAX_LEN] __attribute__((aligned(32)));
uint8_t MST_RX_BUF[RX_BUF_NUM * RX_BUF_MAX_LEN] __attribute__((aligned(32)));
static inline void error() {
while(1);
}
//-------------------------------------------------------------------
//internal function
static uint32_t init_plic(void);
static void error() ;
extern const uint8_t int_svr_code[];
uint32_t (*sys_call)(uint32_t no, ...);
void main()
{
int i;
//初始化plic
init_plic();
//延迟等待从机复位,初始化
for (i = 0; i < 100; i++)
asm volatile("nop");
#ifdef USING_POLL_STRATEGY
//使用查询策略 POLL_STRATEGY 操作 half lvds mac
HLM_poll(WORKMODE_MASTER);
#else
//使用中断策略操作half lvds mac
HLM_work_with_isr(WORKMODE_MASTER);
#endif
while (1);
}
uint32_t init_plic(void)
{
/*初始化plic*/
*plic_enable_0_31 = 1 << CDR_INT_TX0END
//| 1 << CDR_INT_TX1END
@@ -60,156 +86,12 @@ void main()
*plic_threshold_0 = 0;
#if 0
//再写一次实现延迟,等从机的复位完成
*plic_enable_0_31 = 1 << CDR_INT_TXEND | 1 << CDR_INT_RXERROR | 1 << CDR_INT_RXSTART | 1 << CDR_INT_RXEND;
*plic_priority_TxEnd = 1;
*plic_priority_RxError = 1;
*plic_priority_RxStart = 1;
*plic_priority_RxEnd = 1;
*plic_threshold_0 = 0;
#else
//延迟等待从机复位,初始化
for (i = 0; i < 100; i++)
asm volatile("nop");
#endif
return 0;
}
//while (init_svr_code() != 1);
sys_call = (void *)int_svr_code;
void error() {
while(1);
}
//复位脉冲
*tx0_softReset = 1;
*tx1_softReset = 1;
*rx0_softReset = 1;
*rx1_softReset = 1;
//tx0 下行
//tx1 上行
//rx0 下行
//rx1 上行
uint32_t tx_len;
tx_len = 32;
for (i = 0; i < tx_len - 1; i++)
{
MST_TX_BUF[i] = i;
}
sys_call(SYS_SET_RECV_INFO, MST_RX_BUF);
sys_call(SYS_SEND_DATA, MST_TX_BUF, tx_len);
while (1);
#if 0
*cdr_txLen = 520; //总长520
*cdr_txFifo = (512 << 20) |( 0 << 16) | 0x0000; //负载长度512操作数0 参数全0
*cdr_txFifo = 0x00000000;
for( uint32_t i = 0; i < 512/4 - 1; i ++ ){
*cdr_txFifo = 0x00000000;
}
crc = *cdr_txCrc;
*cdr_txFifo = crc;
//等待发送完成标志
// asm volatile (
// "1:\n"
// "andi %0, sp, 0x01\n"
// "beqz %0, 1b\n"
// "andi sp, sp, 0xFE\n"
// :"+r"(flag)
// );
while( !flag_intTxEnd );
flag_intTxEnd = 0;
*cdr_softReset = 1; //复位脉冲
*cdr_direct = 1; //方向切换上行
//接收第一个包
// asm volatile (
// "1:\n"
// "andi %0, sp, 0x04\n"
// "beqz %0, 1b\n"
// "andi sp, sp, 0xFB\n"
// :"+r"(flag)
// );
while(!flag_intRxStart);
flag_intRxStart = 0;
readDat = *cdr_rxFifo;
// operator = (readDat >> 16) & 0xf; //速度不够,不校验
upRecvLen = readDat >> 20;
//接收第二个包
// asm volatile (
// "andi %0, sp, 0x08\n"
// "1:\n"
// "bnez %0, 1b\n" //error //速度不够,不校验
// :"+r"(flag),
// );
if( flag_intRxError ){
while(1);
}
uint32_t temp = *cdr_rxFifo;
//上行转发负载
for( uint32_t i = 0; i < (upRecvLen >> 2); i ++ ){ //一次传4byte
if( flag_intRxError ){
while(1);
}
// register uint32_t upData;
// asm volatile (
// "andi %0, sp, 0x80\n"
// "1:\n"
// "bnez %0, 1b\n" //error 速度不够,不再检查接收
// "lw %1, 0x01c(x0)\n"
// :"+r"(flag), "+r"(upData)
// );
}
//CRC
if( flag_intRxError ){
while(1);
}
// asm volatile (
// "andi %0, sp, 0x08\n"
// "1:\n"
// "bnez %0, 1b\n" //error
// :"+r"(flag)
// );
//uint32_t crc = *cdr_rxFifo; //CRC
//等待接收完成标志
// asm volatile (
// "1:\n"
// "andi %0, sp, 0x08\n"
// "beqz %0, 1b\n"
// "andi sp, sp, 0xF7\n"
// :"+r"(flag)
// );
while(!flag_intRxEnd);
flag_intRxEnd = 0;
totNum = (upRecvLen >> 3);
#endif
}