OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 21 to Rev 22
    Reverse comparison

Rev 21 → Rev 22

/qaz_libs/trunk/sim_template/tests/debug/wip.do
0,0 → 1,12
#
 
# vcom -explicit -O0 -f ../../libs/FPGA_VHDL/lib.f
# vlog -O0 -f ../../libs/sim_verilog/bfm.f
 
# simulation $root
vlog -O0 ../../src/tb_top.sv
 
# compile test last
vlog ./the_test.sv
 
/qaz_libs/trunk/sim_template/tests/debug/init_test.do
0,0 → 1,32
# ------------------------------------
#
# ------------------------------------
 
# load sim
do ../../scripts/sim_procs.do
 
global env
 
set env(ROOT_DIR) ../../../..
set env(PROJECT_DIR) ../../..
set env(SIM_TARGET) fpga
 
radix -hexadecimal
 
make_lib work 1
 
sim_compile_all sim
# sim_compile_all FPGA
 
# simulation $root
vlog -O0 ../../src/tb_top.sv
 
# compile test last
vlog -O0 ./the_test.sv
 
 
# run the sim
sim_run_test
 
 
 
/qaz_libs/trunk/sim_template/tests/debug/the_test.sv
0,0 → 1,40
// --------------------------------------------------------------------
//
// --------------------------------------------------------------------
 
 
module the_test(
input tb_clk,
input tb_rst
);
 
// --------------------------------------------------------------------
//
task run_the_test;
 
// --------------------------------------------------------------------
// insert test below
// --------------------------------------------------------------------
 
$display("^^^---------------------------------");
$display("^^^ %16.t | Testbench begun.\n", $time);
$display("^^^---------------------------------");
 
 
wait(~tb_rst);
 
repeat(1000) @(posedge tb_clk);
 
// $stop();
 
 
// --------------------------------------------------------------------
// insert test above
// --------------------------------------------------------------------
 
endtask
 
 
endmodule
 
/qaz_libs/trunk/sim_template/tests/debug/sim.do
0,0 → 1,17
#
#
 
 
quit -sim
 
vsim -novopt work.tb_top
# vsim -voptargs="+acc=rn+/tb_top/dut" -L secureip -L simprims_ver -L unisims_ver work.glbl work.tb_top
# vsim -pli "C:/Xilinx/Vivado/2015.4/lib/win64.o/libxil_vsim.dll" -novopt -L secureip -L simprims_ver -L unisims_ver work.glbl work.tb_top
 
 
# # log all signals
# log -r *
 
# run -all ;
 
 
/qaz_libs/trunk/sim_template/scripts/sim_procs.do
0,0 → 1,108
# ------------------------------------
#
# ------------------------------------
 
 
# ------------------------------------
#
proc sim_compile_all { target } {
 
global env
 
echo "INFO: compiling $target rtl"
foreach filename [glob -nocomplain -directory ../../libs/${target}_verilog/ *.f] {
echo "INFO: compiling $filename"
vlog -O0 -f $filename
}
foreach filename [glob -nocomplain -directory ../../libs/${target}_VHDL/ *.f] {
echo "INFO: compiling $filename"
vcom -explicit -O0 -f $filename
}
}
 
 
# ------------------------------------
#
proc sim_run_sim { } {
 
if {[file exists ./sim.do]} {
do ./sim.do
} elseif {[file exists ../../libs/sim.do]} {
do ../../libs/sim.do
} elseif {[file exists ../../libs/altera_sim.f]} {
vsim -novopt -f ../../libs/altera_sim.f -l transcript.txt work.tb_top
} elseif {[file exists ../../libs/xilinx_sim.f]} {
vsim -novopt -f ../../libs/xilinx_sim.f -l transcript.txt work.tb_top work.glbl
}
if { [file exists ./wave.do] } {
do ./wave.do
}
}
 
 
# ------------------------------------
#
proc sim_run_test { } {
 
global env
 
# unique setup
if { [file exists ./setup_test.do] } {
do ./setup_test.do
}
 
if { [info exists env(MAKEFILE_TEST_RUN)] } {
vlog +define+MAKEFILE_TEST_RUN ../../src/tb_top.v
} else {
sim_run_sim
}
 
run -all
}
 
 
# ------------------------------------
#
proc sim_restart { } {
 
global env
 
# work in progress files to compile
if { [file exists ./wip.do] } {
echo "INFO: found ./wip.do"
do ./wip.do
}
if { [string equal nodesign [runStatus]] } {
sim_run_sim
} else {
restart -force
}
 
run -all
}
 
 
# ------------------------------------
#
proc make_lib { lib {rebuild 0} } {
 
if {[file exists $lib/_info]} {
echo "INFO: Simulation library $lib already exists"
if { $rebuild != 0 } {
echo "INFO: Rebuilding library. Deleting ./$lib and recompiling all"
quit -sim
file delete -force ./$lib
vlib $lib
vmap $lib $lib
}
} else {
vlib $lib
vmap $lib $lib
}
}
/qaz_libs/trunk/sim_template/scripts/sim_run_test.do
0,0 → 1,13
# ------------------------------------
#
# ------------------------------------
 
do ../../scripts/sim_procs.do
 
 
sim_run_test
 
quit
 
 
 
/qaz_libs/trunk/sim_template/libs/sim_verilog/tb_lib.f
0,0 → 1,16
#
 
-mfcu
 
${ROOT_DIR}/opencores/qaz_libs/tb_class/src/tb_clk_class.sv
 
${ROOT_DIR}/opencores/qaz_libs/tb_class/src/tb_clk.sv
${ROOT_DIR}/opencores/qaz_libs/tb_class/src/tb_base.sv
 
 
 
 
 
 
 
 
/qaz_libs/trunk/video_frame_class/src/video_frame_pkg.sv
0,0 → 1,266
// --------------------------------------------------------------------
//
 
package video_frame_pkg;
 
 
typedef struct
{
int pixel[];
} line_s;
 
 
class video_frame_class;
rand int frame_id;
rand int pixels_per_line;
rand int lines_per_frame;
rand int bits_per_pixel;
line_s lines[];
 
constraint default_pixels_per_line
{
pixels_per_line >= 4;
pixels_per_line % 2 == 0;
pixels_per_line <= 16384;
}
 
constraint default_lines_per_frame
{
lines_per_frame >= 4;
lines_per_frame % 2 == 0;
lines_per_frame <= 16384;
}
 
constraint default_bits_per_pixel
{
bits_per_pixel >= 1 && bits_per_pixel <= 32;
}
 
 
//--------------------------------------------------------------------
function new;
this.frame_id = 0;
endfunction: new
 
extern function void init
(
input int pixels_per_line,
input int lines_per_frame,
input int bits_per_pixel
);
 
extern virtual function void make_constant
(
input int pixel
);
 
extern virtual function void make_counting();
 
extern virtual function void make_random();
 
extern virtual function void copy
(
ref video_frame_class to
);
 
extern virtual function int compare
(
input int max_mismatches,
ref video_frame_class to
);
extern virtual function void print_line
(
input int line,
input int pixel,
input int count
);
 
endclass: video_frame_class
 
 
// --------------------------------------------------------------------
//
function void video_frame_class::init
(
input int pixels_per_line,
input int lines_per_frame,
input int bits_per_pixel
);
$display("^^^ %16.t | %m", $time);
this.pixels_per_line = pixels_per_line;
this.lines_per_frame = lines_per_frame;
this.bits_per_pixel = bits_per_pixel;
this.make_constant( 0 );
endfunction: init
 
 
// --------------------------------------------------------------------
//
function void video_frame_class::make_constant
(
input int pixel
);
$display("^^^ %16.t | %m", $time);
 
this.lines = new[lines_per_frame];
 
foreach( this.lines[l] )
begin
 
this.lines[l].pixel = new[pixels_per_line];
 
foreach( this.lines[l].pixel[p] )
this.lines[l].pixel[p] = pixel;
 
end
 
endfunction: make_constant
 
 
// --------------------------------------------------------------------
//
function void video_frame_class::make_counting();
$display("^^^ %16.t | %m", $time);
 
this.lines = new[lines_per_frame];
 
foreach( this.lines[l] )
begin
 
this.lines[l].pixel = new[pixels_per_line];
 
foreach( this.lines[l].pixel[p] )
this.lines[l].pixel[p] = (pixels_per_line * l) + p;
 
end
 
endfunction: make_counting
 
 
// --------------------------------------------------------------------
//
function void video_frame_class::make_random();
$display("^^^ %16.t | %m", $time);
 
this.lines = new[lines_per_frame];
 
foreach( this.lines[l] )
begin
 
this.lines[l].pixel = new[pixels_per_line];
 
foreach( this.lines[l].pixel[p] )
this.lines[l].pixel[p] = $urandom_range( ((2 ** bits_per_pixel) - 1), 0 );
 
end
 
endfunction: make_random
 
 
// --------------------------------------------------------------------
//
function void video_frame_class::copy
(
ref video_frame_class to
);
$display("^^^ %16.t | %m", $time);
 
to.frame_id = this.frame_id;
to.pixels_per_line = this.pixels_per_line;
to.lines_per_frame = this.lines_per_frame;
to.bits_per_pixel =this.bits_per_pixel ;
 
to.lines = new[lines_per_frame];
 
foreach( this.lines[l] )
begin
 
to.lines[l].pixel = new[pixels_per_line];
 
foreach( this.lines[l].pixel[p] )
to.lines[l].pixel[p] = this.lines[l].pixel[p];
 
end
endfunction: copy
 
 
// --------------------------------------------------------------------
//
function int video_frame_class::compare
(
input int max_mismatches,
ref video_frame_class to
);
 
int mismatch_count = 0;
$display("^^^ %16.t | %m", $time);
 
if( to.pixels_per_line != this.pixels_per_line )
begin
$display( "^^^ %16.t | to.pixels_per_line != this.pixels_per_line", $time );
return( -1 );
end
 
if( to.lines_per_frame != this.lines_per_frame )
begin
$display( "^^^ %16.t | to.lines_per_frame != this.lines_per_frame", $time );
return( -2 );
end
 
if( to.bits_per_pixel != this.bits_per_pixel )
begin
$display( "^^^ %16.t | to.bits_per_pixel != this.bits_per_pixel", $time );
return( -3 );
end
 
foreach( this.lines[l] )
begin
foreach( this.lines[l].pixel[p] )
if( to.lines[l].pixel[p] != this.lines[l].pixel[p] )
begin
 
if( max_mismatches > 0 )
mismatch_count++;
 
$display( "^^^ %16.t | mismatch @ frame[%4h][%4h] | to == %4h | this == %4h ", $time, l, p, to.lines[l].pixel[p], this.lines[l].pixel[p] );
 
if( mismatch_count > max_mismatches )
return( mismatch_count );
 
end
end
 
return( mismatch_count );
 
endfunction: compare
 
 
// --------------------------------------------------------------------
//
function void video_frame_class::print_line
(
input int line,
input int pixel,
input int count
);
 
$display("^^^ %16.t | %m", $time);
for( int i = 0; i < count; i++ )
$display( "^^^ %16.t | %4h @ frame[%4h][%4h]", $time, this.lines[line].pixel[(pixel + i)], line, (pixel + i) );
 
endfunction: print_line
 
 
endpackage: video_frame_pkg
 
/qaz_libs/trunk/cli/cli/memtest.c
0,0 → 1,222
/**********************************************************************
*
* Filename: memtest.c
*
* Description: General-purpose memory testing functions.
*
* Notes: This software can be easily ported to systems with
* different data bus widths by redefining 'datum'.
*
*
* Copyright (c) 1998 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/
 
 
#include "memtest.h"
 
 
/**********************************************************************
*
* Function: memTestDataBus()
*
* Description: Test the data bus wiring in a memory region by
* performing a walking 1's test at a fixed address
* within that region. The address (and hence the
* memory region) is selected by the caller.
*
* Notes:
*
* Returns: 0 if the test succeeds.
* A non-zero result is the first pattern that failed.
*
**********************************************************************/
datum
memTestDataBus(volatile datum * address)
{
datum pattern;
 
 
/*
* Perform a walking 1's test at the given address.
*/
for (pattern = 1; pattern != 0; pattern <<= 1)
{
/*
* Write the test pattern.
*/
*address = pattern;
 
/*
* Read it back (immediately is okay for this test).
*/
if (*address != pattern)
{
return (pattern);
}
}
 
return (0);
 
} /* memTestDataBus() */
 
 
/**********************************************************************
*
* Function: memTestAddressBus()
*
* Description: Test the address bus wiring in a memory region by
* performing a walking 1's test on the relevant bits
* of the address and checking for aliasing. This test
* will find single-bit address failures such as stuck
* -high, stuck-low, and shorted pins. The base address
* and size of the region are selected by the caller.
*
* Notes: For best results, the selected base address should
* have enough LSB 0's to guarantee single address bit
* changes. For example, to test a 64-Kbyte region,
* select a base address on a 64-Kbyte boundary. Also,
* select the region size as a power-of-two--if at all
* possible.
*
* Returns: NULL if the test succeeds.
* A non-zero result is the first address at which an
* aliasing problem was uncovered. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum *
memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long addressMask = (nBytes/sizeof(datum) - 1);
unsigned long offset;
unsigned long testOffset;
 
datum pattern = (datum) 0xAAAAAAAA;
datum antipattern = (datum) 0x55555555;
 
 
/*
* Write the default pattern at each of the power-of-two offsets.
*/
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
baseAddress[offset] = pattern;
}
 
/*
* Check for address bits stuck high.
*/
testOffset = 0;
baseAddress[testOffset] = antipattern;
 
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
}
 
baseAddress[testOffset] = pattern;
 
/*
* Check for address bits stuck low or shorted.
*/
for (testOffset = 1; (testOffset & addressMask) != 0; testOffset <<= 1)
{
baseAddress[testOffset] = antipattern;
 
if (baseAddress[0] != pattern)
{
return ((datum *) &baseAddress[testOffset]);
}
 
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
if ((baseAddress[offset] != pattern) && (offset != testOffset))
{
return ((datum *) &baseAddress[testOffset]);
}
}
 
baseAddress[testOffset] = pattern;
}
 
return (NULL);
 
} /* memTestAddressBus() */
 
 
/**********************************************************************
*
* Function: memTestDevice()
*
* Description: Test the integrity of a physical memory device by
* performing an increment/decrement test over the
* entire region. In the process every storage bit
* in the device is tested as a zero and a one. The
* base address and the size of the region are
* selected by the caller.
*
* Notes:
*
* Returns: NULL if the test succeeds.
*
* A non-zero result is the first address at which an
* incorrect value was read back. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum *
memTestDevice(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long offset;
unsigned long nWords = nBytes / sizeof(datum);
 
datum pattern;
datum antipattern;
 
 
/*
* Fill memory with a known pattern.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
baseAddress[offset] = pattern;
}
 
/*
* Check each location and invert it for the second pass.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
 
antipattern = ~pattern;
baseAddress[offset] = antipattern;
}
 
/*
* Check each location for the inverted pattern and zero it.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
antipattern = ~pattern;
if (baseAddress[offset] != antipattern)
{
return ((datum *) &baseAddress[offset]);
}
}
 
return (NULL);
 
} /* memTestDevice() */
 
/qaz_libs/trunk/cli/cli/sys_cmd.c
0,0 → 1,129
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sys_cmd.h"
 
 
/*-----------------------------------------------------------*/
static unsigned int cli_no_of_commands;
 
void cli_init( void )
{
int i;
for(i = 0; cli_commands[i].func != NULL; i++);
cli_no_of_commands = i;
}
 
 
/*-----------------------------------------------------------*/
static int cmd_cmp( const void *e1, const void *e2 )
{
struct cli_cmd_tab_t *p_cmd_1 = (struct cli_cmd_tab_t *)e1;
struct cli_cmd_tab_t *p_cmd_2 = (struct cli_cmd_tab_t *)e2;
 
return strncmp( p_cmd_1->cmd, p_cmd_2->cmd, MAX_CMD_LENGTH );
}
 
 
/*-----------------------------------------------------------*/
cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check )
{
struct cli_cmd_tab_t *cli_cmd;
cli_cmd = (struct cli_cmd_tab_t *) bsearch( cmd_to_check, cli_commands, cli_no_of_commands, sizeof(struct cli_cmd_tab_t), cmd_cmp );
 
return(cli_cmd);
}
 
 
/*-----------------------------------------------------------*/
static char func_help( const unsigned char argc, const char *argv[] )
{
unsigned int i;
 
PRINTF_MACRO( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
PRINTF_MACRO( "\r\n" );
PRINTF_MACRO( "Commands:\r\n" );
 
for( i = 0; i < cli_no_of_commands; i++ )
puts( cli_commands[i].help_string );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
static char func_peek( const unsigned char argc, const char *argv[] )
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
 
PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
static char func_poke( const unsigned char argc, const char *argv[] )
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
unsigned int value = strtoul( argv[2], (char **)NULL, 16 );
 
*((volatile unsigned int *)address) = value;
 
PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2] );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
#include "memtest.h"
 
static char func_memtest( const unsigned char argc, const char *argv[] )
{
datum *address = (datum *)( strtoul( argv[1], (char **)NULL, 16 ) );
unsigned long nBytes = strtoul( argv[2], (char **)NULL, 16 );
 
if( argc != 3 || address == NULL || nBytes == 0 )
{
PRINTF_MACRO( "memtest: bad args \r\n" );
return( EXIT_FAILURE );
}
 
PRINTF_MACRO( "running memTestDataBus() ... " );
 
if( memTestDataBus( address ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
 
PRINTF_MACRO( "running memTestAddressBus() ... " );
 
if( memTestAddressBus( address, nBytes ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
 
PRINTF_MACRO( "running memTestDevice() ... " );
 
if( memTestDevice( address, nBytes ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
// command table
#include "sys_cmd_table.h"
 
 
/qaz_libs/trunk/cli/cli/memtest.h
0,0 → 1,41
/**********************************************************************
*
* Filename: memtest.h
*
* Description: Memory-testing module API.
*
* Notes: The memory tests can be easily ported to systems with
* different data bus widths by redefining 'datum' type.
*
*
* Copyright (c) 2000 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/
 
#ifndef _memtest_h
#define _memtest_h
 
 
/*
* Define NULL pointer value.
*/
#ifndef NULL
#define NULL (void *) 0
#endif
 
/*
* Set the data bus width.
*/
typedef unsigned long datum;
 
/*
* Function prototypes.
*/
datum memTestDataBus(volatile datum * address);
datum * memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes);
datum * memTestDevice(volatile datum * baseAddress, unsigned long nBytes);
 
 
#endif /* _memtest_h */
/qaz_libs/trunk/cli/cli/sys_cli.c
0,0 → 1,251
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
#include "sys_cmd.h"
#include "sys_error.h"
 
 
 
/*-----------------------------------------------------------*/
#ifdef ANSI_ESCAPE_CODE
#define ASCII_ESC '\x1b'
 
static void send_csi( char c )
{
putchar( ASCII_ESC );
putchar( '[' );
putchar( c );
}
#else
static void send_csi( char c ) {};
#endif
 
 
/*-----------------------------------------------------------*/
static char *cli_edit_buffer( char *in_buffer, char *out_buffer, unsigned int line_length )
{
static char *out_ptr;
static char *begin_ptr;
static char *end_ptr;
 
#ifdef ANSI_ESCAPE_CODE
static char prev_char;
static unsigned int csi;
#endif
 
unsigned int i;
 
if( out_buffer != NULL )
{
out_ptr = out_buffer;
begin_ptr = out_buffer;
end_ptr = out_buffer + INPUT_LINE_LENGTH;
 
#ifdef ANSI_ESCAPE_CODE
prev_char = 0;
csi = 0;
#endif
}
 
for( i = 0 ; i < line_length ; i++ )
{
 
if( out_ptr >= end_ptr )
{
*end_ptr = '\0';
return( NULL );
}
 
if( out_ptr < begin_ptr )
sys_error_fatal( FATAL_ERROR_CLI );
 
switch( in_buffer[i] )
{
case '\0':
return( NULL );
break;
 
case '\n':
*out_ptr = '\0';
return( NULL );
break;
 
case '\r':
*out_ptr = '\0';
return( NULL );
break;
 
case '\b':
if( out_ptr != begin_ptr )
{
send_csi( 'P' );
out_ptr--;
} else
{
putchar( ' ' );
send_csi( '\a' );
}
break;
 
#ifdef ANSI_ESCAPE_CODE
case ASCII_ESC:
break;
 
case '[':
if( prev_char == ASCII_ESC )
{
csi = 1;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'A':
if( csi )
{
send_csi( 'B' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'B':
if( csi == 0 )
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'C':
if( csi )
{
send_csi( 'D' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'D':
if( csi )
{
send_csi( 'C' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
#endif
 
default:
*out_ptr = in_buffer[i];
out_ptr++;
break;
}
 
#ifdef ANSI_ESCAPE_CODE
prev_char = in_buffer[i];
#endif
}
 
return( out_ptr );
}
 
 
/*-----------------------------------------------------------*/
void sys_cli_task( void )
{
char last_return_value = EXIT_SUCCESS;
char in_buffer[INPUT_LINE_LENGTH + 1];
char out_buffer[INPUT_LINE_LENGTH + 1];
char *cli_ptr;
struct cli_cmd_tab_t cmd_to_check = { "", NULL, NULL };
unsigned char cli_argc;
char *cli_argv[MAX_CLI_ARGC];
struct cli_cmd_tab_t *cli_cmd;
unsigned int bytes_read;
 
cli_init();
 
PRINTF_MACRO( "\r\n" );
 
for( ;; )
{
PRINTF_MACRO( "%d > ", last_return_value );
 
cli_argc = 0;
last_return_value = EXIT_SUCCESS;
 
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) );
cli_ptr = cli_edit_buffer( in_buffer, out_buffer, bytes_read );
 
while( cli_ptr != NULL )
{
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) );
cli_ptr = cli_edit_buffer( in_buffer, NULL, bytes_read );
}
 
if( out_buffer[0] == '\0' )
{
PRINTF_MACRO( " NULL String! Command ignored\r\n" );
last_return_value = EXIT_FAILURE;
}
 
while( last_return_value != EXIT_FAILURE )
{
cli_ptr = strtok( out_buffer, " \t" );
 
strncpy( cmd_to_check.cmd, out_buffer, MAX_CMD_LENGTH );
cli_cmd = cli_find_command( &cmd_to_check );
 
if ( cli_cmd == NULL )
{
PRINTF_MACRO( "\r\n Command not found!\r\n" );
last_return_value = EXIT_FAILURE;
break;
}
 
if( cli_ptr == NULL )
{
cli_argv[cli_argc] = out_buffer;
cli_argc++;
} else
{
while( cli_ptr != NULL )
{
cli_argv[cli_argc] = cli_ptr;
cli_argc++;
 
cli_ptr = strtok( NULL, " \t" );
}
}
 
PRINTF_MACRO( "\r\n" );
 
last_return_value = cli_cmd->func( cli_argc, (const char **)cli_argv );
break;
}
 
}
}
 
/qaz_libs/trunk/cli/cli/sys_cmd.h
0,0 → 1,39
/*-----------------------------------------------------------*/
 
 
#ifndef _SYS_CMD_H_
#define _SYS_CMD_H_
 
#define INPUT_LINE_LENGTH 50
#define MAX_CMD_LENGTH 20
#define MAX_CLI_ARGC 6
 
// #include <xil_printf.h>
 
// #define ANSI_ESCAPE_CODE
 
#define PRINTF_MACRO xil_printf
// #define PRINTF_MACRO iprintf
 
typedef char (*cli_cmd_func)( const unsigned char argc, const char * argv[] );
 
typedef struct cli_cmd_tab_t
{
char cmd[MAX_CMD_LENGTH];
cli_cmd_func func;
const char *help_string;
} cli_cmd_tab_t;
 
extern struct cli_cmd_tab_t cli_commands[];
 
 
/*-----------------------------------------------------------*/
extern void sys_cli_task(void);
extern cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check );
extern void cli_init( void );
 
 
/*-----------------------------------------------------------*/
 
 
#endif // _SYS_CMD_H_
/qaz_libs/trunk/cli/cli/sys_error.c
0,0 → 1,9
/*-----------------------------------------------------------*/
 
void sys_error_fatal( unsigned int error )
{
// (*( (volatile unsigned int *) (0x8000003c) )) = error; // write to scratch pad reg in FPGA
while(1) {};
}
 
/qaz_libs/trunk/cli/cli/sys_error.h
0,0 → 1,17
/*-----------------------------------------------------------*/
 
#ifndef _SYS_ERROR_H_
#define _SYS_ERROR_H_
 
typedef enum
{
FATAL_ERROR_CLI = 0,
FATAL_ERROR_FD_SSP0_0,
} sys_error_fatal_type;
 
 
/*-----------------------------------------------------------*/
void sys_error_fatal( unsigned int error );
 
#endif // _SYS_ERROR_H_
 
/qaz_libs/trunk/cli/cli/sys_cmd_table.h
0,0 → 1,30
/*-----------------------------------------------------------*/
 
#include "sys_cmd.h"
 
extern char func_mw( const unsigned char argc, const char *argv[] );
extern char func_md( const unsigned char argc, const char *argv[] );
 
 
/*-----------------------------------------------------------*/
// command table
 
/*-----------------------------------------------------------*/
/* put in alphabetical order by command name */
struct cli_cmd_tab_t cli_commands[] =
{
{ "help", func_help, " help ~ print help message\r" },
{ "md", func_md, " md [.b, .w, .l] address [# of objects] ~ memory display\r" },
{ "md.b", func_md, " md.w [.b, .w, .l] address [# of objects] ~ memory display\r" },
{ "md.w", func_md, " md.w [.b, .w, .l] address [# of objects] ~ memory display\r" },
{ "memtest", func_memtest, " memtest base_address size\r" },
{ "mw", func_mw, " mw [.b, .w, .l] address value [count] ~ memory write (fill)\r" },
{ "mw.b", func_mw, " mw.w [.b, .w, .l] address value [count] ~ memory write (fill)\r" },
{ "mw.w", func_mw, " mw.w [.b, .w, .l] address value [count] ~ memory write (fill)\r" },
{ "peek", func_peek, " peek address\r" },
{ "poke", func_poke, " poke address value\r" },
{ "~", NULL, NULL }
};
 
 
 
/qaz_libs/trunk/cli/util/util_bits.c
0,0 → 1,58
/*-----------------------------------------------------------*/
 
#include "util_bits.h"
 
 
/*-----------------------------------------------------------*/
void inline
util_set_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask,
unsigned int data
)
{
volatile unsigned int *word_pointer = (volatile unsigned int *)(address);
unsigned int buffer;
data <<= bit_offset;
data &= bit_mask;
 
buffer = *word_pointer;
buffer &= ~bit_mask;
buffer |= data;
 
*word_pointer = buffer;
}
 
 
/*-----------------------------------------------------------*/
unsigned int inline
util_get_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask
)
{
volatile unsigned int *word_pointer = (volatile unsigned int *)(address);
unsigned int buffer;
 
buffer = *word_pointer;
buffer &= bit_mask;
buffer >>= bit_offset;
return(buffer);
}
 
 
/*-----------------------------------------------------------*/
unsigned char ReverseBits7ops32bit(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}
 
 
 
/qaz_libs/trunk/cli/util/uboot_lib.c
0,0 → 1,138
/*-----------------------------------------------------------*/
 
#include "uboot_lib.h"
 
 
/*-----------------------------------------------------------*/
int cmd_get_data_size(const char * arg, int default_size)
{
/* Check for a size specification .b, .w or .l.
*/
int len = strlen(arg);
if (len > 2 && arg[len-2] == '.') {
switch (arg[len-1]) {
case 'b':
return 1;
case 'w':
return 2;
case 'l':
return 4;
case 's':
return -2;
default:
return -1;
}
}
return default_size;
}
 
 
/*-----------------------------------------------------------*/
unsigned long simple_strtoul(const char *cp, char **endp,
unsigned int base)
{
unsigned long result = 0;
 
result = strtoul( cp, endp, base );
 
return result;
}
 
 
/*-----------------------------------------------------------*/
#define MAX_LINE_LENGTH_BYTES (64)
#define DEFAULT_LINE_LENGTH_BYTES (16)
int print_buffer(ulong addr, const void *data, uint width, uint count,
uint linelen)
{
/* linebuf as a union causes proper alignment */
union linebuf {
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
#endif
uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
} lb;
int i;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
uint64_t __maybe_unused x;
#else
uint32_t __maybe_unused x;
#endif
 
if (linelen*width > MAX_LINE_LENGTH_BYTES)
linelen = MAX_LINE_LENGTH_BYTES / width;
if (linelen < 1)
linelen = DEFAULT_LINE_LENGTH_BYTES / width;
 
while (count) {
uint thislinelen = linelen;
PRINTF_MACRO("%08lx:", addr);
 
/* check for overflow condition */
if (count < thislinelen)
thislinelen = count;
 
/* Copy from memory into linebuf and print hex values */
for (i = 0; i < thislinelen; i++) {
if (width == 4)
{
x = lb.ui[i] = *(volatile uint32_t *)data;
PRINTF_MACRO(" %08x", x);
}
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
else if (width == 8)
{
x = lb.uq[i] = *(volatile uint64_t *)data;
PRINTF_MACRO(" %016llx", (long long)x);
}
#endif
else if (width == 2)
{
x = lb.us[i] = *(volatile uint16_t *)data;
PRINTF_MACRO(" %04x", x);
}
else
{
x = lb.uc[i] = *(volatile uint8_t *)data;
PRINTF_MACRO(" %02x", x);
}
// #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
// PRINTF_MACRO(" %0*llx", width * 2, (long long)x);
// #else
// PRINTF_MACRO(" %0*x", width * 2, x);
// #endif
data += width;
}
 
while (thislinelen < linelen) {
/* fill line with whitespace for nice ASCII print */
for (i=0; i<width*2+1; i++)
puts(" ");
linelen--;
}
 
/* Print data in ASCII characters */
for (i = 0; i < thislinelen * width; i++) {
if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
lb.uc[i] = '.';
}
lb.uc[i] = '\0';
PRINTF_MACRO(" %s\r\n", lb.uc);
 
/* update references */
addr += thislinelen * width;
count -= thislinelen;
 
// if (ctrlc())
// return -1;
}
 
return 0;
}
 
 
 
 
 
/qaz_libs/trunk/cli/util/util_mem.h
0,0 → 1,24
/*-----------------------------------------------------------*/
 
#ifndef _UTIL_MEM_H_
#define _UTIL_MEM_H_
 
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "sys_cmd.h"
#include "uboot_lib.h"
 
#undef CONFIG_HAS_DATAFLASH
#undef CONFIG_BLACKFIN
 
/*-----------------------------------------------------------*/
 
 
#endif // _UTIL_MEM_H_
 
 
 
 
/qaz_libs/trunk/cli/util/mapmem.h
0,0 → 1,32
/*
* Copyright (c) 2015 National Instruments
*
* (C) Copyright 2015
* Joe Hershberger <joe.hershberger@ni.com>
*
* SPDX-License-Identifier: GPL-2.0
*/
 
#ifndef __MAPMEM_H
#define __MAPMEM_H
 
/* Define a null map_sysmem() if the architecture doesn't use it */
# ifdef CONFIG_ARCH_MAP_SYSMEM
#include <asm/io.h>
# else
static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
{
return (void *)(uintptr_t)paddr;
}
 
static inline void unmap_sysmem(const void *vaddr)
{
}
 
static inline phys_addr_t map_to_sysmem(const void *ptr)
{
return (phys_addr_t)(uintptr_t)ptr;
}
# endif
 
#endif /* __MAPMEM_H */
/qaz_libs/trunk/cli/util/util_bits.h
0,0 → 1,39
/*-----------------------------------------------------------*/
 
#ifndef _UTIL_BITS_H_
#define _UTIL_BITS_H_
 
 
 
/*-----------------------------------------------------------*/
extern void inline
util_set_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask,
unsigned int data
);
 
/*-----------------------------------------------------------*/
extern unsigned int inline
util_get_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask
);
/*-----------------------------------------------------------*/
extern unsigned char ReverseBits7ops32bit(unsigned char v);
 
 
 
 
#endif // _UTIL_BITS_H_
 
 
 
 
/qaz_libs/trunk/cli/util/uboot_lib.h
0,0 → 1,70
/*-----------------------------------------------------------*/
 
#ifndef _UBOOT_LIB_H_
#define _UBOOT_LIB_H_
 
#include <stdint.h>
#include <inttypes.h>
#include "types.h"
 
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
 
#undef CONFIG_ARCH_MAP_SYSMEM
#include "mapmem.h"
 
#include "sys_cmd.h"
 
 
/*
* Error codes that commands return to cmd_process(). We use the standard 0
* and 1 for success and failure, but add one more case - failure with a
* request to call cmd_usage(). But the cmd_process() function handles
* CMD_RET_USAGE itself and after calling cmd_usage() it will return 1.
* This is just a convenience for commands to avoid them having to call
* cmd_usage() all over the place.
*/
enum command_ret_t {
CMD_RET_SUCCESS, /* 0 = Success */
CMD_RET_FAILURE, /* 1 = Failure */
CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */
};
 
typedef int cmd_tbl_t;
 
/* sysv */
typedef unsigned char unchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
 
 
/*
* Command Flags:
*/
#define CMD_FLAG_REPEAT 0x0001 /* repeat last command */
#define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
#define CMD_FLAG_ENV 0x0004 /* command is from the environment */
 
 
#define __maybe_unused __attribute__((unused))
 
 
/*-----------------------------------------------------------*/
#undef CONFIG_SYS_SUPPORT_64BIT_DATA
 
 
 
/*-----------------------------------------------------------*/
extern int cmd_get_data_size(const char * arg, int default_size);
extern unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base);
extern int print_buffer(ulong addr, const void *data, uint width, uint count, uint linelen);
 
 
#endif // _UBOOT_LIB_H_
 
 
 
 
/qaz_libs/trunk/cli/util/types.h
0,0 → 1,55
/*
* Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0+
*/
 
#ifndef __ASM_ARC_TYPES_H
#define __ASM_ARC_TYPES_H
 
// typedef unsigned short umode_t;
 
// /*
// * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
// * header files exported to user space
// */
 
// typedef __signed__ char __s8;
// typedef unsigned char __u8;
 
// typedef __signed__ short __s16;
// typedef unsigned short __u16;
 
// typedef __signed__ int __s32;
// typedef unsigned int __u32;
 
// #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
// typedef __signed__ long long __s64;
// typedef unsigned long long __u64;
// #endif
 
// /*
// * These aren't exported outside the kernel to avoid name space clashes
// */
typedef signed char s8;
typedef unsigned char u8;
 
typedef signed short s16;
typedef unsigned short u16;
 
typedef signed int s32;
typedef unsigned int u32;
 
typedef signed long long s64;
typedef unsigned long long u64;
 
// #define BITS_PER_LONG 32
 
// /* Dma addresses are 32-bits wide. */
 
// typedef u32 dma_addr_t;
 
typedef unsigned long phys_addr_t;
typedef unsigned long phys_size_t;
 
#endif /* __ASM_ARC_TYPES_H */
/qaz_libs/trunk/cli/util/util_mem.c
0,0 → 1,203
/*-----------------------------------------------------------*/
 
#include "util_mem.h"
 
 
/*-----------------------------------------------------------*/
 
/* Display values from last command.
* Memory modify remembered values are different from display memory.
*/
static ulong dp_last_addr, dp_last_size;
static ulong dp_last_length = 0x40;
// static ulong mm_last_addr, mm_last_size;
 
static ulong base_address = 0;
 
/* Memory Display
*
* Syntax:
* md{.b, .w, .l, .q} {addr} {len}
*/
#define DISP_LINE_LEN 16
static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
{
ulong addr, length;
#if defined(CONFIG_HAS_DATAFLASH)
ulong nbytes, linebytes;
#endif
int size;
int rc = 0;
 
/* We use the last specified parameters, unless new ones are
* entered.
*/
addr = dp_last_addr;
size = dp_last_size;
length = dp_last_length;
 
if (argc < 2)
return CMD_RET_USAGE;
 
if ((flag & CMD_FLAG_REPEAT) == 0) {
/* New command specified. Check for a size specification.
* Defaults to long if no or incorrect specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 0)
return 1;
 
/* Address is specified since argc > 1
*/
addr = simple_strtoul(argv[1], NULL, 16);
addr += base_address;
 
/* If another parameter, it is the length to display.
* Length is the number of objects, not number of bytes.
*/
if (argc > 2)
length = simple_strtoul(argv[2], NULL, 16);
}
 
#if defined(CONFIG_HAS_DATAFLASH)
/* Print the lines.
*
* We buffer all read data, so we can make sure data is read only
* once, and all accesses are with the specified bus width.
*/
nbytes = length * size;
do {
char linebuf[DISP_LINE_LEN];
void* p;
linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
 
rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
 
nbytes -= linebytes;
addr += linebytes;
if (ctrlc()) {
rc = 1;
break;
}
} while (nbytes > 0);
#else
 
# if defined(CONFIG_BLACKFIN)
/* See if we're trying to display L1 inst */
if (addr_bfin_on_chip_mem(addr)) {
char linebuf[DISP_LINE_LEN];
ulong linebytes, nbytes = length * size;
do {
linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
memcpy(linebuf, (void *)addr, linebytes);
print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
 
nbytes -= linebytes;
addr += linebytes;
if (ctrlc()) {
rc = 1;
break;
}
} while (nbytes > 0);
} else
# endif
 
{
ulong bytes = size * length;
const void *buf = map_sysmem(addr, bytes);
 
/* Print the lines. */
print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
addr += bytes;
unmap_sysmem(buf);
}
#endif
 
dp_last_addr = addr;
dp_last_length = length;
dp_last_size = size;
return (rc);
}
 
 
/*-----------------------------------------------------------*/
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
{
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
u64 writeval;
#else
ulong writeval;
#endif
ulong addr, count;
int size;
void *buf, *start;
ulong bytes;
 
if ((argc < 3) || (argc > 4))
return CMD_RET_USAGE;
 
/* Check for size specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 1)
return 1;
 
/* Address is specified since argc > 1
*/
addr = simple_strtoul(argv[1], NULL, 16);
addr += base_address;
 
/* Get the value to write.
*/
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
writeval = simple_strtoull(argv[2], NULL, 16);
#else
writeval = simple_strtoul(argv[2], NULL, 16);
#endif
 
/* Count ? */
if (argc == 4) {
count = simple_strtoul(argv[3], NULL, 16);
} else {
count = 1;
}
 
bytes = size * count;
start = map_sysmem(addr, bytes);
buf = start;
while (count-- > 0) {
if (size == 4)
*((u32 *)buf) = (u32)writeval;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
else if (size == 8)
*((u64 *)buf) = (u64)writeval;
#endif
else if (size == 2)
*((u16 *)buf) = (u16)writeval;
else
*((u8 *)buf) = (u8)writeval;
buf += size;
}
unmap_sysmem(start);
return 0;
}
 
 
/*-----------------------------------------------------------*/
char func_mw( const unsigned char argc, const char *argv[] )
{
return do_mem_mw(0, 0, argc, argv);
}
 
 
/*-----------------------------------------------------------*/
char func_md( const unsigned char argc, const char *argv[] )
{
return do_mem_md(0, 0, argc, argv);
}
 
 
 
 
 
 
/qaz_libs/trunk/docs/bits_and_nibbles_reversed.pdf Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
qaz_libs/trunk/docs/bits_and_nibbles_reversed.pdf Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: qaz_libs/trunk/docs/bits_and_nibbles_reversed.xlsx =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: qaz_libs/trunk/docs/bits_and_nibbles_reversed.xlsx =================================================================== --- qaz_libs/trunk/docs/bits_and_nibbles_reversed.xlsx (nonexistent) +++ qaz_libs/trunk/docs/bits_and_nibbles_reversed.xlsx (revision 22)
qaz_libs/trunk/docs/bits_and_nibbles_reversed.xlsx Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: qaz_libs/trunk/misc/bit_connect_big_to_little.v =================================================================== --- qaz_libs/trunk/misc/bit_connect_big_to_little.v (nonexistent) +++ qaz_libs/trunk/misc/bit_connect_big_to_little.v (revision 22) @@ -0,0 +1,31 @@ +// -------------------------------------------------------------------- +// +// -------------------------------------------------------------------- + + +module + bit_connect_big_to_little + #( + parameter SIZE = 32 + ) + ( + input [0:SIZE-1] in, + output [SIZE-1:0] out + ); + + + // -------------------------------------------------------------------- + // + genvar i; + generate + begin : swap + for (i = 0; i < SIZE ; i = i + 1) + begin : swap_it + assign out[i] = in[(SIZE-1) - i]; + end + end + endgenerate + + +endmodule + Index: qaz_libs/trunk/misc/bit_connect_little_to_big.v =================================================================== --- qaz_libs/trunk/misc/bit_connect_little_to_big.v (nonexistent) +++ qaz_libs/trunk/misc/bit_connect_little_to_big.v (revision 22) @@ -0,0 +1,31 @@ +// -------------------------------------------------------------------- +// +// -------------------------------------------------------------------- + + +module + bit_connect_little_to_big + #( + parameter SIZE = 32 + ) + ( + input [SIZE-1:0] in, + output [0:SIZE-1] out + ); + + + // -------------------------------------------------------------------- + // + genvar i; + generate + begin : swap + for (i = 0; i < SIZE ; i = i + 1) + begin : swap_it + assign out[i] = in[(SIZE-1) - i]; + end + end + endgenerate + + +endmodule +

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.