#include #include "tl2cdr.h" #include "mstMainCfg.h" #include "sysDef.h" volatile uint32_t *plic_priority_3 = (uint32_t*)( 0xc000000U + 0X000004 * 3); volatile uint32_t *plic_priority_4 = (uint32_t*)( 0xc000000U + 0X000004 * 4); volatile uint32_t *plic_priority_5 = (uint32_t*)( 0xc000000U + 0X000004 * 5); volatile uint32_t *plic_priority_6 = (uint32_t*)( 0xc000000U + 0X000004 * 6); volatile uint32_t *plic_priority_TxEnd = (uint32_t*)( 0xc000000U + 0X000004 * CDR_INT_TXEND); volatile uint32_t *plic_priority_RxError = (uint32_t*)( 0xc000000U + 0X000004 * CDR_INT_RXERROR); volatile uint32_t *plic_priority_RxStart = (uint32_t*)( 0xc000000U + 0X000004 * CDR_INT_RXSTART); volatile uint32_t *plic_priority_RxEnd = (uint32_t*)( 0xc000000U + 0X000004 * CDR_INT_RXEND); volatile uint32_t *plic_priority_18 = (uint32_t*)( 0xc000000U + 0X000004 * 18); volatile uint32_t *plic_priority_19 = (uint32_t*)( 0xc000000U + 0X000004 * 19); volatile uint32_t *plic_priority_20 = (uint32_t*)( 0xc000000U + 0X000004 * 20); volatile uint32_t *plic_priority_21 = (uint32_t*)( 0xc000000U + 0X000004 * 21); volatile uint32_t *plic_pending_0_31 = (uint32_t*)( 0xc000000U + 0X001000 ); 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); } extern const uint8_t int_svr_code[]; uint32_t (*sys_call)(uint32_t no, ...); void main() { #if 0 uint32_t readDat; uint32_t operator; uint32_t downRecvLen; uint32_t upRecvLen; uint32_t slvNum; uint32_t totNum; uint32_t isLast; uint32_t crc; #endif int i; /*初始化plic*/ *plic_enable_0_31 = 1 << CDR_INT_TX0END //| 1 << CDR_INT_TX1END //| 1 << CDR_INT_RX0ERROR | 1 << CDR_INT_RX1ERROR //| 1 << CDR_INT_RX0START | 1 << CDR_INT_RX1START //| 1 << CDR_INT_RX0END | 1 << CDR_INT_RX1END | 1 << CDR_INT_TX0_FIFO_DEQ //| 1 << CDR_INT_TX1_FIFO_DEQ //| 1 << CDR_INT_RX0_FIFO_ENQ | 1 << CDR_INT_RX1_FIFO_ENQ ; *plic_priority_TxEnd = 1; *plic_priority_RxError = 1; *plic_priority_RxStart = 1; *plic_priority_RxEnd = 1; *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 //while (init_svr_code() != 1); sys_call = (void *)int_svr_code; //复位脉冲 *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 / 4 - 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 }