mirror of https://github.com/efabless/caravel.git
Add test uart_loopback
This commit is contained in:
parent
6830c79ae8
commit
8e72d5e13e
|
@ -186,7 +186,12 @@
|
|||
"GL":["r_gl","nightly","weekly","tape_out"],
|
||||
"GL_SDF":["r_sdf","weekly","tape_out"],
|
||||
"description":"test uart reception"}
|
||||
|
||||
,"uart_loopback" :{"level":0,
|
||||
"SW":true,
|
||||
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
|
||||
"GL":["r_gl","nightly","weekly","tape_out"],
|
||||
"GL_SDF":["r_sdf","weekly","tape_out"],
|
||||
"description":"test uart in loopback mode input and output is shorted"}
|
||||
,"spi_master_rd" :{"level":0,
|
||||
"SW":true,
|
||||
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from curses import baudrate
|
||||
import random
|
||||
import cocotb
|
||||
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer
|
||||
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer,Edge
|
||||
import cocotb.log
|
||||
from cpu import RiskV
|
||||
from defsParser import Regs
|
||||
|
@ -72,7 +72,6 @@ async def uart_rx(dut):
|
|||
clk = clock.period/1000
|
||||
global bit_time_ns
|
||||
bit_time_ns = round(10**5 * clk / (96))
|
||||
print (clk)
|
||||
# send first char
|
||||
await wait_reg1(cpu,caravelEnv,0XAA)
|
||||
await uart_send_char(caravelEnv,"B")
|
||||
|
@ -123,4 +122,43 @@ async def uart_check_char_recieved(caravelEnv,cpu):
|
|||
cocotb.log.error(f"[TEST] Failed cpu has recieved the wrong character {chr(int(reg_uart_data,2))}")
|
||||
return
|
||||
|
||||
await ClockCycles(caravelEnv.clk,1)
|
||||
|
||||
@cocotb.test()
|
||||
@repot_test
|
||||
async def uart_loopback(dut):
|
||||
caravelEnv,clock = await test_configure(dut,timeout_cycles=216756)
|
||||
cpu = RiskV(dut)
|
||||
cpu.cpu_force_reset()
|
||||
cpu.cpu_release_reset()
|
||||
cocotb.log.info(f"[TEST] Start uart test")
|
||||
await cocotb.start( connect_5_6(dut,caravelEnv)) # short gpio 6 and 5
|
||||
caravelEnv.drive_gpio_in((0,0),0) # IO[0] affects the uart selecting btw system and debug
|
||||
|
||||
# setup watcher loopback results
|
||||
await cocotb.start(uart_check_char_recieved_loopback(caravelEnv,cpu))
|
||||
|
||||
await ClockCycles(caravelEnv.clk,197000)
|
||||
|
||||
async def connect_5_6(dut,caravelEnv):
|
||||
while True:
|
||||
caravelEnv.drive_gpio_in(5,dut.bin6_monitor.value)
|
||||
await Edge(dut.bin6_monitor)
|
||||
|
||||
|
||||
async def uart_check_char_recieved_loopback(caravelEnv,cpu):
|
||||
# check cpu recieved the correct character
|
||||
while True:
|
||||
reg_uart_data = caravelEnv.caravel_hdl.soc.core.uart_rxtx_w.value.binstr
|
||||
reg1 = cpu.read_debug_reg1()
|
||||
cocotb.log.debug(f"[TEST] reg1 = {hex(reg1)}")
|
||||
if reg1 == 0x1B:
|
||||
cocotb.log.info(f"[TEST] Pass cpu has sent and recieved the correct character {chr(int(reg_uart_data,2))}")
|
||||
await wait_reg1(cpu,caravelEnv,0)
|
||||
|
||||
if reg1 == 0x1E:
|
||||
cocotb.log.error(f"[TEST] Failed cpu has sent and recieved the wrong character {chr(int(reg_uart_data,2))}")
|
||||
await wait_reg1(cpu,caravelEnv,0)
|
||||
|
||||
|
||||
await ClockCycles(caravelEnv.clk,1)
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Efabless Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <defs.h>
|
||||
#include <stub.c>
|
||||
#include <uart.h>
|
||||
// --------------------------------------------------------
|
||||
|
||||
void wait_for_char(char *c){
|
||||
while (uart_rxempty_read() == 1);
|
||||
if (reg_uart_data == *c){
|
||||
reg_debug_1 = 0x1B; // recieved the correct character
|
||||
}else{
|
||||
reg_debug_1 = 0x1E; // timeout didn't recieve the character
|
||||
}
|
||||
reg_debug_1 =0;
|
||||
uart_ev_pending_write(UART_EV_RX);
|
||||
}
|
||||
|
||||
void main(){
|
||||
int j;
|
||||
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
|
||||
reg_debug_1 = 0x0;
|
||||
reg_debug_2 = 0x0;
|
||||
|
||||
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
|
||||
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
|
||||
|
||||
// Now, apply the configuration
|
||||
reg_mprj_xfer = 1;
|
||||
while (reg_mprj_xfer == 1);
|
||||
|
||||
reg_uart_enable = 1;
|
||||
|
||||
print("M");
|
||||
wait_for_char("M");
|
||||
|
||||
print("B");
|
||||
wait_for_char("B");
|
||||
|
||||
print("A");
|
||||
wait_for_char("A");
|
||||
|
||||
print("5");
|
||||
wait_for_char("5");
|
||||
|
||||
print("o");
|
||||
wait_for_char("o");
|
||||
|
||||
}
|
Loading…
Reference in New Issue