Merge branch 'rv-integration' into release

This commit is contained in:
marqs 2018-11-14 19:06:59 +02:00
commit 4c1b211641
80 changed files with 13600 additions and 10562 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "ip/pulpino_qsys"]
path = ip/pulpino_qsys
url = https://github.com/marqs85/pulpino_qsys.git

View File

@ -12,6 +12,7 @@ Requirements for building and debugging firmware
* Software
* [Altera Quartus II + Cyclone IV support](http://dl.altera.com/?edition=lite) (v 16.1 or higher - free Lite Edition suffices)
* [RISC-V GNU Compiler Toolchain](https://github.com/riscv/riscv-gnu-toolchain)
* GCC (or another C compiler) for host architecture (for building a SD card image)
* Make
* [iconv](https://en.wikipedia.org/wiki/Iconv) (for building with JP lang menu)
@ -19,31 +20,51 @@ Requirements for building and debugging firmware
Architecture
------------------------------
* [Reference board schematics](https://www.niksula.hut.fi/~mhiienka/ossc/diy-v1.5/ossc_v1.5-diy_schematic.pdf)
* [Reference board schematics](https://github.com/marqs85/ossc_pcb/raw/v1.6/ossc_board.pdf)
* [Reference PCB project](https://github.com/marqs85/ossc_pcb)
SW toolchain build procedure
--------------------------
1. Download, configure, build and install RISC-V toolchain with Newlib + RV32EMC support:
~~~~
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=/opt/riscv --with-arch=rv32emc --with-abi=ilp32e
sudo make # sudo needed if installing under default /opt/riscv location
~~~~
2. Compile custom binary to IHEX converter:
~~~~
gcc tools/bin2hex.c -o tools/bin2hex
~~~~
Building RTL (bitstream)
--------------------------
1. Initialize pulpino submodules (once after cloning ossc project or when submoduled have been updated)
~~~~
git submodule update --init --recursive ip/pulpino_qsys
~~~~
2. Load the project (ossc.qpf) in Quartus
3. Generate QSYS output files (only needed before first compilation or when QSYS structure has been modified)
* Open Platform Designer (Tools -> Platform Designer)
* Load platform configuration (sys.qsys)
* Generate output (Generate -> Generate HDL, Generate)
* Close Platform Designer
* Run "touch software/sys_controller_bsp/bsp_timestamp" to acknowledge QSYS update
3. Generate the FPGA bitstream (Processing -> Start Compilation)
4. Ensure that there are no severe timing violations by looking into Timing Analyzer report
NOTE: If the software image (software/sys_controller/mem_init/sys_onchip_memory2_0.hex) was not up to date at the time of compilation, bitstream can be quickly rebuilt with updated hex by running "Processing->Update Memory Initialization File" and "Processing->Start->Start Assembler" in Quartus.
Building software image
--------------------------
1. Enter BSP directory:
~~~~
cd software/sys_controller_bsp
~~~~
2. (Optionally) edit BSP settings:
~~~~
nios2-bsp-editor
~~~~
3. Generate BSP:
~~~~
nios2-bsp-generate-files --bsp-dir . --settings settings.bsp
~~~~
NOTE: the previous step must be done every time after RTL/bitstream is built
4. Enter software root directory:
1. Enter software root directory:
~~~~
cd software/sys_controller
~~~~
5. Build SW for target configuration:
2. Build SW for target configuration:
~~~~
make [OPTIONS] [TARGET]
~~~~
@ -52,24 +73,16 @@ OPTIONS may include following definitions:
* ENABLE_AUDIO=y (Includes audio setup code for v1.6 PCB / DIY audio add-on board)
TARGET is typically one of the following:
* all (Default target. Compiles an ELF for direct downloading to Nios2 during testing)
* generate_hex (Generates a memory initialization file required for bitstream)
* all (Default target. Compiles an ELF file)
* generate_hex (Generates a memory initialization file required for bitstream and direct download)
* clean (cleans ELF and intermediate files. Should be invoked every time OPTIONS are changed between compilations, expect with generate_hex where it is done automatically)
6. Optionally test updated SW by downloading ELF to Nios2 CPU via JTAG (RTL-SW interface in active FW must be compatible new SW BSP configuration)
3. Optionally test updated SW by directly downloading memory image to block RAM via JTAG
~~~~
nios2-download -g --accept-bad-sysid sys_controller.elf
make rv-reprogram
~~~~
Building RTL / bitstream
--------------------------
1. Load the project (ossc.qpf) in Quartus
2. Generate the FPGA bitstream (Processing -> Start Compilation). NOTE: make sure software image (software/sys_controller/mem_init/sys_onchip_memory2_0.hex) is up to date before generating bitstream.
3. Ensure that there are no severe timing violations by looking into Timing Analyzer report
If only software image is updated, bitstream can be quickly rebuilt by running "Processing->Update Memory Initialization File" and "Processing->Start->Start Assembler" in Quartus.
Installing firmware via JTAG
--------------------------
The bitstream can be either directly programmed into FPGA (volatile method, suitable for quick testing), or into serial flash chip where it is automatically loaded every time FPGA is subsequently powered on (nonvolatile method, suitable for long-term use).
@ -101,12 +114,12 @@ Debugging
--------------------------
1. Rebuild the software in debug mode:
~~~~
make clean && make APP_CFLAGS_DEBUG_LEVEL="-DDEBUG"
make clean && make APP_CFLAGS_DEBUG_LEVEL="-DDEBUG" generate_hex
~~~~
NOTE: Fw update functionality via SD card is disabled in debug builds due to code space limitations. If audio support is enabled on debug build, other functionality needs to be disabled as well.
2. Program Nios2 CPU via JTAG and open terminal for UART
2. Download memory image via JTAG and open terminal for UART
~~~~
nios2-download -g --accept-bad-sysid sys_controller.elf && nios2-terminal
make rv-reprogram && nios2-terminal
~~~~
Remember to close nios2-terminal after debug session, otherwise any JTAG transactions will hang/fail.

View File

@ -43,6 +43,7 @@
ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments(alt_epcq_controller_dev *flash_info,alt_u32 offset, alt_u32 length);
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info);
ALT_INLINE unsigned char static bitswap8(unsigned char v);
/*
* Public API
@ -334,6 +335,10 @@ int alt_epcq_controller_write_block
/* prepare the word to be written */
memcpy((((void*)&word_to_write)) + padding, ((void*)data) + buffer_offset, bytes_to_copy);
// Bit-reverse bytes for flash
for (int i=0; i<bytes_to_copy; i++)
*((unsigned char*)&word_to_write+i) = bitswap8(*((unsigned char*)&word_to_write+i));
/* update offset and length variables */
buffer_offset += bytes_to_copy;
remaining_length -= bytes_to_copy;
@ -508,6 +513,10 @@ int alt_epcq_controller_read
if(0 == ret_code)
{
memcpy(dest_addr, (alt_u8*)epcq_flash_info->data_base + offset, length);
// Bit-reverse bytes read from flash
for (int i=0; i<length; i++)
*((unsigned char*)dest_addr+i) = bitswap8(*((unsigned char*)dest_addr+i));
}
return ret_code;
@ -794,4 +803,10 @@ alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_
return 0;
}
ALT_INLINE unsigned char static bitswap8(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}

View File

@ -1,56 +0,0 @@
// (C) 2001-2015 Altera Corporation. All rights reserved.
// Your use of Altera Corporation's design tools, logic functions and other
// software and tools, and its AMPP partner logic functions, and any output
// files any of the foregoing (including device programming or simulation
// files), and any associated documentation or information are expressly subject
// to the terms and conditions of the Altera Program License Subscription
// Agreement, Altera MegaCore Function License Agreement, or other applicable
// license agreement, including, without limitation, that your use is for the
// sole purpose of programming logic devices manufactured by Altera and sold by
// Altera or its authorized distributors. Please refer to the applicable
// agreement for further details.
//Legal Notice: (C)2010 Altera Corporation. All rights reserved. Your
//use of Altera Corporation's design tools, logic functions and other
//software and tools, and its AMPP partner logic functions, and any
//output files any of the foregoing (including device programming or
//simulation files), and any associated documentation or information are
//expressly subject to the terms and conditions of the Altera Program
//License Subscription Agreement or other applicable license agreement,
//including, without limitation, that your use is for the sole purpose
//of programming logic devices manufactured by Altera and sold by Altera
//or its authorized distributors. Please refer to the applicable
//agreement for further details.
// synthesis translate_off
`timescale 1ns / 1ps
// synthesis translate_on
// turn off superfluous verilog processor warnings
// altera message_level Level1
// altera message_off 10034 10035 10036 10037 10230 10240 10030
module endianconverter_qsys (
// inputs:
dataa,
datab,
// outputs:
result
)
;
output [ 31: 0] result;
input [ 31: 0] dataa;
input [ 31: 0] datab;
wire [ 31: 0] result;
//s1, which is an e_custom_instruction_slave
assign result[7 : 0] = dataa[31 : 24];
assign result[15 : 8] = dataa[23 : 16];
assign result[23 : 16] = dataa[15 : 8];
assign result[31 : 24] = dataa[7 : 0];
endmodule

View File

@ -1,84 +0,0 @@
# (C) 2001-2015 Altera Corporation. All rights reserved.
# Your use of Altera Corporation's design tools, logic functions and other
# software and tools, and its AMPP partner logic functions, and any output
# files any of the foregoing (including device programming or simulation
# files), and any associated documentation or information are expressly subject
# to the terms and conditions of the Altera Program License Subscription
# Agreement, Altera MegaCore Function License Agreement, or other applicable
# license agreement, including, without limitation, that your use is for the
# sole purpose of programming logic devices manufactured by Altera and sold by
# Altera or its authorized distributors. Please refer to the applicable
# agreement for further details.
# TCL File Generated by Component Editor 10.1
# Tue Aug 17 15:04:48 MYT 2010
# DO NOT MODIFY
# +-----------------------------------
# |
# |
# | ./converter_0.v syn, sim
# |
# +-----------------------------------
# +-----------------------------------
# | request TCL package from ACDS 10.1
# |
package require -exact sopc 10.1
# |
# +-----------------------------------
# +-----------------------------------
# | module altera_nios_custom_instr_endian_converter
# |
set_module_property NAME altera_nios_custom_instr_endianconverter
set_module_property VERSION 17.1
set_module_property INTERNAL false
set_module_property GROUP "Custom Instruction Modules"
set_module_property AUTHOR "Altera Corporation"
set_module_property DISPLAY_NAME "Endian Converter"
set_module_property HIDE_FROM_SOPC true
set_module_property TOP_LEVEL_HDL_FILE endianconverter_qsys.v
set_module_property TOP_LEVEL_HDL_MODULE endianconverter_qsys
set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
set_module_property SIMULATION_MODEL_IN_VHDL true
set_module_property EDITABLE false
set_module_property ANALYZE_HDL FALSE
# |
# +-----------------------------------
# +-----------------------------------
# | files
# |
add_file endianconverter_qsys.v {SYNTHESIS SIMULATION}
# |
# +-----------------------------------
# +-----------------------------------
# | parameters
# |
# |
# +-----------------------------------
# +-----------------------------------
# | display items
# |
# |
# +-----------------------------------
# +-----------------------------------
# | connection point s1
# |
add_interface s1 nios_custom_instruction end
set_interface_property s1 clockCycle 1
set_interface_property s1 operands 1
set_interface_property s1 ENABLED true
add_interface_port s1 dataa dataa Input 32
add_interface_port s1 datab datab Input 32
add_interface_port s1 result result Output 32
# |
# +-----------------------------------

View File

@ -0,0 +1,105 @@
#
# request TCL package from ACDS 16.1
#
package require -exact qsys 16.1
#
# module pulpino
#
set_module_property DESCRIPTION "HW CRC32"
set_module_property NAME hw_crc32
#set_module_property VERSION 1.0
set_module_property INTERNAL false
set_module_property OPAQUE_ADDRESS_MAP true
set_module_property GROUP "DSP"
set_module_property AUTHOR ""
set_module_property DISPLAY_NAME hw_crc32
set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
set_module_property EDITABLE true
set_module_property REPORT_TO_TALKBACK false
set_module_property ALLOW_GREYBOX_GENERATION false
set_module_property REPORT_HIERARCHY false
set adv_dbg_if false
#
# file sets
#
add_fileset QUARTUS_SYNTH QUARTUS_SYNTH "" ""
set_fileset_property QUARTUS_SYNTH TOP_LEVEL CRC_Component
set_fileset_property QUARTUS_SYNTH ENABLE_RELATIVE_INCLUDE_PATHS false
set_fileset_property QUARTUS_SYNTH ENABLE_FILE_OVERWRITE_MODE false
add_fileset_file CRC_Component.v SYSTEM_VERILOG PATH CRC_Component.v TOP_LEVEL_FILE
add_fileset sim_verilog SIM_VERILOG "" "Verilog Simulation"
set_fileset_property SIM_VERILOG ENABLE_RELATIVE_INCLUDE_PATHS false
set_fileset_property SIM_VERILOG ENABLE_FILE_OVERWRITE_MODE false
set_fileset_property SIM_VERILOG TOP_LEVEL CRC_Component
add_fileset_file CRC_Component.v SYSTEM_VERILOG PATH CRC_Component.v TOP_LEVEL_FILE
#
# connection point clk_sink
#
add_interface clk_sink clock end
set_interface_property clk_sink ENABLED true
set_interface_property clk_sink EXPORT_OF ""
set_interface_property clk_sink PORT_NAME_MAP ""
set_interface_property clk_sink CMSIS_SVD_VARIABLES ""
set_interface_property clk_sink SVD_ADDRESS_GROUP ""
add_interface_port clk_sink clk clk Input 1
#
# connection point reset_sink
#
add_interface reset_sink reset end
set_interface_property reset_sink associatedClock clk_sink
set_interface_property reset_sink synchronousEdges DEASSERT
set_interface_property reset_sink ENABLED true
set_interface_property reset_sink EXPORT_OF ""
set_interface_property reset_sink PORT_NAME_MAP ""
set_interface_property reset_sink CMSIS_SVD_VARIABLES ""
set_interface_property reset_sink SVD_ADDRESS_GROUP ""
add_interface_port reset_sink reset reset Input 1
#
# connection point avalon_slave
#
add_interface avalon_slave avalon end
set_interface_property avalon_slave addressUnits WORDS
set_interface_property avalon_slave associatedClock clk_sink
set_interface_property avalon_slave associatedReset reset_sink
set_interface_property avalon_slave bitsPerSymbol 8
set_interface_property avalon_slave burstOnBurstBoundariesOnly false
set_interface_property avalon_slave burstcountUnits WORDS
set_interface_property avalon_slave explicitAddressSpan 0
set_interface_property avalon_slave holdTime 0
set_interface_property avalon_slave linewrapBursts false
set_interface_property avalon_slave maximumPendingReadTransactions 0
set_interface_property avalon_slave readLatency 1
set_interface_property avalon_slave readWaitTime 1
set_interface_property avalon_slave setupTime 0
set_interface_property avalon_slave timingUnits Cycles
set_interface_property avalon_slave writeWaitTime 0
set_interface_property avalon_slave ENABLED true
set_interface_property avalon_slave EXPORT_OF ""
set_interface_property avalon_slave PORT_NAME_MAP ""
set_interface_property avalon_slave CMSIS_SVD_VARIABLES ""
set_interface_property avalon_slave SVD_ADDRESS_GROUP ""
add_interface_port avalon_slave address address Input 3
add_interface_port avalon_slave readdata readdata Output 32
add_interface_port avalon_slave read read Input 1
add_interface_port avalon_slave chipselect chipselect Input 1
add_interface_port avalon_slave byteenable byteenable Input 4
add_interface_port avalon_slave write write Input 1
add_interface_port avalon_slave writedata writedata Input 32

View File

@ -69,7 +69,7 @@ int I2C_start(alt_u32 base, alt_u32 add, alt_u32 read)
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_STA_MSK | I2C_OPENCORES_CR_WR_MSK );
/* wait for the trnasaction to be over.*/
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
while (IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK) {}
/* now check to see if the address was acknowledged */
if(IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_RXNACK_MSK)
@ -119,7 +119,7 @@ alt_u32 I2C_read(alt_u32 base,alt_u32 last)
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_RD_MSK );
}
/* wait for the trnasaction to be over.*/
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
while (IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK) {}
/* now read the data */
return (IORD_I2C_OPENCORES_RXR(base));
@ -162,7 +162,7 @@ alt_u32 I2C_write(alt_u32 base,alt_u8 data, alt_u32 last)
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_WR_MSK );
}
/* wait for the trnasaction to be over.*/
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
while (IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK) {}
/* now check to see if the address was acknowledged */
if(IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_RXNACK_MSK)

View File

@ -1,224 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/******************************************************************************
* Author - JCJB *
* *
* This design uses the following CRC-32 implementations: *
* *
* --> Software - Uses modulo 2 division to perform the remainder calculation. *
* --> Optimized Software - Uses a lookup table of all possible division *
* values. The calculation operates on 8 bit data. *
* --> Custom Instruction - Uses a parallel hardware CRC circuit to calculate *
* the remainder. The calculation operates on 8, *
* 16, 24, or 32 bit data. *
* *
* The software implementations can be changed to CRC-16 or CRC-CCITT however *
* the custom instruction must be modified as well to support the same *
* standard. Simply use the values defined in crc.h to change the standard *
* used (using the same values in the hardware parameterization) or define *
* your own standard. *
*******************************************************************************/
#include "system.h"
#include "stdio.h"
#include "crc.h"
#include "ci_crc.h"
#include "sys/alt_timestamp.h"
#include "stdlib.h"
/* Modify these values to adjust the test being performed */
#define NUMBER_OF_BUFFERS 32
#define BUFFER_SIZE 256 /* in bytes */
/* Change the name of memory device according to what you are using
* e.g.: DDR_SDRAM_0 ##_SPAN
* SSRAM_0 ##_SPAN
*/
#define MEMORY_DEVICE_SIZE 32768
/* Make sure there is room left for Nios II text, rodata, rwdata, stack,
* and heap. This software and the buffer space must fit within the
* size of memory device. A total of 1.5 MBytes is reserved. If BUFFER_SIZE
* is a multiple of four then exactly 256kB will be left, otherwise is
* amount will be less since the column dimension needs some padding to
* stay 32 bit aligned
*/
#if ((BUFFER_SIZE * NUMBER_OF_BUFFERS) >= MEMORY_DEVICE_SIZE - 10000)
#error Your buffer space has exceeded the maximum allowable space. Please\
reduce the buffer space so that there is enough room to hold Nios II\
code.
#endif
/* This will line up the data onto a 32 bit (or greater) boundary. A 2d array
* is being used here for simplicity. The first dimension represents a byte
* of data and the second dimension represents an individual buffer
*/
#if ((BUFFER_SIZE & 0x3) == 0)
unsigned char data_buffer_region[NUMBER_OF_BUFFERS][BUFFER_SIZE] __attribute__ ((aligned(4)));
#else /* need to allocate extra bytes so that all buffers start on a 32 bit
boundaries by rounding up the column dimension to the next power of 4
*/
unsigned char data_buffer_region[NUMBER_OF_BUFFERS][BUFFER_SIZE + 4 - (BUFFER_SIZE&0x3)] __attribute__ ((aligned(4)));
#endif
int main()
{
unsigned long buffer_counter, data_counter;
unsigned long sw_slow_results[NUMBER_OF_BUFFERS];
unsigned long sw_fast_results[NUMBER_OF_BUFFERS];
unsigned long ci_results[NUMBER_OF_BUFFERS];
unsigned char random_data = 0x5A;
//unsigned long sw_slow_timeA, sw_slow_timeB;
// unsigned long sw_fast_timeA, sw_fast_timeB;
// unsigned long ci_timeA, ci_timeB;
alt_u32 sw_slow_timeA, sw_slow_timeB;
alt_u32 sw_fast_timeA, sw_fast_timeB;
alt_u32 ci_timeA, ci_timeB;
printf("+-----------------------------------------------------------+\n");
printf("| Comparison between software and custom instruction CRC32 |\n");
printf("+-----------------------------------------------------------+\n\n\n");
printf("System specification\n");
printf("--------------------\n");
printf("System clock speed = %lu MHz\n", (unsigned long)ALT_CPU_FREQ /(unsigned long)1000000);
printf("Number of buffer locations = %d\n", NUMBER_OF_BUFFERS);
printf("Size of each buffer = %d bytes\n\n\n", BUFFER_SIZE);
/* Initializing the data buffers */
printf("Initializing all of the buffers with pseudo-random data\n");
printf("-------------------------------------------------------\n");
for(buffer_counter = 0; buffer_counter < NUMBER_OF_BUFFERS; buffer_counter++)
{
for(data_counter = 0; data_counter < BUFFER_SIZE; data_counter++)
{
data_buffer_region[buffer_counter][data_counter] = random_data;
random_data = (random_data >> 4) + (random_data << 4) + (data_counter & 0xFF);
}
}
printf("Initialization completed\n\n\n");
if(alt_timestamp_start() < 0) // starts the timestamp timer
{
printf("Please add the high resolution timer to the timestamp timer setting in the syslib properties page.\n");
exit(1);
}
/* Slow software CRC based on a modulo 2 division implementation */
printf("Running the software CRC\n");
printf("------------------------\n");
sw_slow_timeA = alt_timestamp();
for(buffer_counter = 0; buffer_counter < NUMBER_OF_BUFFERS; buffer_counter++)
{
sw_slow_results[buffer_counter] = crcSlow(data_buffer_region[buffer_counter], BUFFER_SIZE);
}
sw_slow_timeB = alt_timestamp();
printf("Completed\n\n\n");
/* Fast software CRC based on a lookup table implementation */
crcInit();
printf("Running the optimized software CRC\n");
printf("----------------------------------\n");
sw_fast_timeA = alt_timestamp();
for(buffer_counter = 0; buffer_counter < NUMBER_OF_BUFFERS; buffer_counter++)
{
sw_fast_results[buffer_counter] = crcFast(data_buffer_region[buffer_counter], BUFFER_SIZE);
}
sw_fast_timeB = alt_timestamp();
printf("Completed\n\n\n");
/* Custom instruction CRC */
printf("Running the custom instruction CRC\n");
printf("----------------------------------\n");
ci_timeA = alt_timestamp();
for(buffer_counter = 0; buffer_counter < NUMBER_OF_BUFFERS; buffer_counter++)
{
ci_results[buffer_counter] = crcCI(data_buffer_region[buffer_counter], BUFFER_SIZE);
}
ci_timeB = alt_timestamp();
printf("Completed\n\n\n");
/* Validation of results */
printf("Validating the CRC results from all implementations\n");
printf("----------------------------------------------------\n");
for(buffer_counter = 0; buffer_counter < NUMBER_OF_BUFFERS; buffer_counter++)
{
/* Test every combination of results to make sure they are consistant */
if((sw_slow_results[buffer_counter] != ci_results[buffer_counter]) |
(sw_fast_results[buffer_counter] != ci_results[buffer_counter]))
{
printf("FAILURE! Software CRC = 0x%lx, Optimized Software CRC = 0x%lx, Custom Instruction CRC = 0x%lx,\n",
sw_slow_results[buffer_counter], sw_fast_results[buffer_counter], ci_results[buffer_counter]);
exit(1);
}
}
printf("All CRC implementations produced the same results\n\n\n");
// Report processing times
printf("Processing time for each implementation\n");
printf("---------------------------------------\n");
printf("Software CRC = %.2lu ms\n", 1000*((unsigned long)(sw_slow_timeB-sw_slow_timeA))/((unsigned long)alt_timestamp_freq()));
printf("Optimized software CRC = %.2lu ms\n", 1000*((unsigned long)(sw_fast_timeB-sw_fast_timeA))/((unsigned long)alt_timestamp_freq()));
printf("Custom instruction CRC = %.2lu ms\n\n\n", 1000*((unsigned long)(ci_timeB-ci_timeA))/((unsigned long)alt_timestamp_freq()));
printf("Processing throughput for each implementation\n"); // throughput = total bits / (time(s) * 1000000)
printf("---------------------------------------------\n");
printf("Software CRC = %.2lu Mbps\n", (8 * NUMBER_OF_BUFFERS * BUFFER_SIZE)/(1000000*(unsigned long)(sw_slow_timeB-sw_slow_timeA)/((unsigned long)alt_timestamp_freq())));
printf("Optimized software CRC = %.2lu Mbps\n", (8 * NUMBER_OF_BUFFERS * BUFFER_SIZE)/(1000000*(unsigned long)(sw_fast_timeB-sw_fast_timeA)/((unsigned long)alt_timestamp_freq())));
printf("Custom instruction CRC = %.2lu Mbps\n\n\n", (8 * NUMBER_OF_BUFFERS * BUFFER_SIZE)/(1000000*(unsigned long)(ci_timeB-ci_timeA)/((unsigned long)alt_timestamp_freq())));
printf("Speedup ratio\n");
printf("-------------\n");
printf("Custom instruction CRC vs software CRC = %lu\n", ((unsigned long)(sw_slow_timeB-sw_slow_timeA))/((unsigned long)(ci_timeB-ci_timeA)));
printf("Custom instruction CRC vs optimized software CRC = %lu\n", ((unsigned long)(sw_fast_timeB-sw_fast_timeA))/((unsigned long)(ci_timeB-ci_timeA)));
printf("Optimized software CRC vs software CRC= %lu\n", ((unsigned long)(sw_slow_timeB-sw_slow_timeA))/((unsigned long)(sw_fast_timeB-sw_fast_timeA)));
return 0;
}

View File

@ -1,109 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/**********************************************************************
*
* Filename: crc.h
*
* Description: A header file describing the various CRC standards.
*
* Notes:
*
*
* 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 _crc_h
#define _crc_h
#define FALSE 0
#define TRUE !FALSE
/*
* Select the CRC standard from the list that follows.
*/
#define CRC32
#if defined(CRC_CCITT)
typedef unsigned short crc;
#define CRC_NAME "CRC-CCITT"
#define POLYNOMIAL 0x1021
#define INITIAL_REMAINDER 0xFFFF
#define FINAL_XOR_VALUE 0x0000
#define REFLECT_DATA FALSE
#define REFLECT_REMAINDER FALSE
#define CHECK_VALUE 0x29B1
#elif defined(CRC16)
typedef unsigned short crc;
#define CRC_NAME "CRC-16"
#define POLYNOMIAL 0x8005
#define INITIAL_REMAINDER 0x0000
#define FINAL_XOR_VALUE 0x0000
#define REFLECT_DATA TRUE
#define REFLECT_REMAINDER TRUE
#define CHECK_VALUE 0xBB3D
#elif defined(CRC32)
typedef unsigned long crc;
#define CRC_NAME "CRC-32"
#define POLYNOMIAL 0x04C11DB7
#define INITIAL_REMAINDER 0xFFFFFFFF
#define FINAL_XOR_VALUE 0xFFFFFFFF
#define REFLECT_DATA TRUE
#define REFLECT_REMAINDER TRUE
#define CHECK_VALUE 0xCBF43926
#else
#error "One of CRC_CCITT, CRC16, or CRC32 must be #define'd."
#endif
void crcInit(void);
crc crcSlow(unsigned char const message[], int nBytes);
crc crcFast(unsigned char const message[], int nBytes);
#endif /* _crc_h */

View File

@ -1,97 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/**********************************************************************
*
* Filename: ci_crc.c
*
* Description: Custom instruction implementations of the CRC.
*
* Notes: A macro is defined that is used to access the CRC custom
* instruction.
*********************************************************************/
#include "system.h"
/*The n values and their corresponding operation are as follow:
* n = 0, Initialize the custom instruction to the initial remainder value
* n = 1, Write 8 bits data to custom instruction
* n = 2, Write 16 bits data to custom instruction
* n = 3, Write 32 bits data to custom instruction
* n = 4, Read 32 bits data from the custom instruction
* n = 5, Read 64 bits data from the custom instruction
* n = 6, Read 96 bits data from the custom instruction
* n = 7, Read 128 bits data from the custom instruction*/
#define CRC_CI_MACRO(n, A) __builtin_custom_ini(ALT_CI_NIOS2_HW_CRC32_0_N + (n & 0x7), (A))
unsigned long crcCI(unsigned char * input_data, unsigned long input_data_length, int do_initialize)
{
unsigned long index;
/* copy of the data buffer pointer so that it can advance by different widths */
void * input_data_copy = (void *)input_data;
/* The custom instruction CRC will initialize to the inital remainder value */
if (do_initialize)
CRC_CI_MACRO(0,0);
/* Write 32 bit data to the custom instruction. If the buffer does not end
* on a 32 bit boundary then the remaining data will be sent to the custom
* instruction in the 'if' statement below.
*/
for(index = 0; index < (input_data_length & 0xFFFFFFFC); index+=4)
{
CRC_CI_MACRO(3, *(unsigned long *)input_data_copy);
input_data_copy += 4; /* void pointer, must move by 4 for each word */
}
/* Write the remainder of the buffer if it does not end on a word boundary */
if((input_data_length & 0x3) == 0x3) /* 3 bytes left */
{
CRC_CI_MACRO(2, *(unsigned short *)input_data_copy);
input_data_copy += 2;
CRC_CI_MACRO(1, *(unsigned char *)input_data_copy);
}
else if((input_data_length & 0x3) == 0x2) /* 2 bytes left */
{
CRC_CI_MACRO(2, *(unsigned short *)input_data_copy);
}
else if((input_data_length & 0x3) == 0x1) /* 1 byte left */
{
CRC_CI_MACRO(1, *(unsigned char *)input_data_copy);
}
/* There are 4 registers in the CRC custom instruction. Since
* this example uses CRC-32 only the first register must be read
* in order to receive the full result.
*/
return CRC_CI_MACRO(4, 0);
}

View File

@ -1,265 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/**********************************************************************
*
* Filename: crc.c
*
* Description: Slow and fast implementations of the CRC standards.
*
* Notes: The parameters for each supported CRC standard are
* defined in the header file crc.h. The implementations
* here should stand up to further additions to that list.
*
*
* 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.
**********************************************************************/
#include "crc.h"
/*
* Derive parameters from the standard-specific parameters in crc.h.
*/
#define WIDTH (8 * sizeof(crc))
#define TOPBIT (1 << (WIDTH - 1))
#if (REFLECT_DATA == TRUE)
#undef REFLECT_DATA
#define REFLECT_DATA(X) ((unsigned char) reflect((X), 8))
#else
#undef REFLECT_DATA
#define REFLECT_DATA(X) (X)
#endif
#if (REFLECT_REMAINDER == TRUE)
#undef REFLECT_REMAINDER
#define REFLECT_REMAINDER(X) ((crc) reflect((X), WIDTH))
#else
#undef REFLECT_REMAINDER
#define REFLECT_REMAINDER(X) (X)
#endif
/*********************************************************************
*
* Function: reflect()
*
* Description: Reorder the bits of a binary sequence, by reflecting
* them about the middle position.
*
* Notes: No checking is done that nBits <= 32.
*
* Returns: The reflection of the original data.
*
*********************************************************************/
static unsigned long
reflect(unsigned long data, unsigned char nBits)
{
unsigned long reflection = 0x00000000;
unsigned char bit;
/*
* Reflect the data about the center bit.
*/
for (bit = 0; bit < nBits; ++bit)
{
/*
* If the LSB bit is set, set the reflection of it.
*/
if (data & 0x01)
{
reflection |= (1 << ((nBits - 1) - bit));
}
data = (data >> 1);
}
return (reflection);
} /* reflect() */
/*********************************************************************
*
* Function: crcSlow()
*
* Description: Compute the CRC of a given message.
*
* Notes:
*
* Returns: The CRC of the message.
*
*********************************************************************/
crc
crcSlow(unsigned char const message[], int nBytes)
{
crc remainder = INITIAL_REMAINDER;
int byte;
unsigned char bit;
/*
* Perform modulo-2 division, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
/*
* Bring the next byte into the remainder.
*/
remainder ^= (REFLECT_DATA(message[byte]) << (WIDTH - 8));
/*
* Perform modulo-2 division, a bit at a time.
*/
for (bit = 8; bit > 0; --bit)
{
/*
* Try to divide the current data bit.
*/
if (remainder & TOPBIT)
{
remainder = (remainder << 1) ^ POLYNOMIAL;
}
else
{
remainder = (remainder << 1);
}
}
}
/*
* The final remainder is the CRC result.
*/
return (REFLECT_REMAINDER(remainder) ^ FINAL_XOR_VALUE);
} /* crcSlow() */
crc crcTable[256];
/*********************************************************************
*
* Function: crcInit()
*
* Description: Populate the partial CRC lookup table.
*
* Notes: This function must be rerun any time the CRC standard
* is changed. If desired, it can be run "offline" and
* the table results stored in an embedded system's ROM.
*
* Returns: None defined.
*
*********************************************************************/
void
crcInit(void)
{
crc remainder;
int dividend;
unsigned char bit;
/*
* Compute the remainder of each possible dividend.
*/
for (dividend = 0; dividend < 256; ++dividend)
{
/*
* Start with the dividend followed by zeros.
*/
remainder = dividend << (WIDTH - 8);
/*
* Perform modulo-2 division, a bit at a time.
*/
for (bit = 8; bit > 0; --bit)
{
/*
* Try to divide the current data bit.
*/
if (remainder & TOPBIT)
{
remainder = (remainder << 1) ^ POLYNOMIAL;
}
else
{
remainder = (remainder << 1);
}
}
/*
* Store the result into the table.
*/
crcTable[dividend] = remainder;
}
} /* crcInit() */
/*********************************************************************
*
* Function: crcFast()
*
* Description: Compute the CRC of a given message.
*
* Notes: crcInit() must be called first.
*
* Returns: The CRC of the message.
*
*********************************************************************/
crc
crcFast(unsigned char const message[], int nBytes)
{
crc remainder = INITIAL_REMAINDER;
unsigned char data;
int byte;
/*
* Divide the message by the polynomial, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
data = REFLECT_DATA(message[byte]) ^ (remainder >> (WIDTH - 8));
remainder = crcTable[data] ^ (remainder << 8);
}
/*
* The final remainder is the CRC.
*/
return (REFLECT_REMAINDER(remainder) ^ FINAL_XOR_VALUE);
} /* crcFast() */

View File

@ -1,101 +0,0 @@
/*
Legal Notice: (C)2006 Altera Corporation. All rights reserved. Your
use of Altera Corporation's design tools, logic functions and other
software and tools, and its AMPP partner logic functions, and any
output files any of the foregoing (including device programming or
simulation files), and any associated documentation or information are
expressly subject to the terms and conditions of the Altera Program
License Subscription Agreement or other applicable license agreement,
including, without limitation, that your use is for the sole purpose
of programming logic devices manufactured by Altera and sold by Altera
or its authorized distributors. Please refer to the applicable
agreement for further details.
*/
/*
This thin wrapper re-uses the CRC Avalon component as a Nios II
custom instruction. The n port of custom instruction is used as
control to the CRC Avalon component. Below are the values of n and
the corresponding operations perform by the custom instruction:
n = 0, Initialize the custom instruction to the initial remainder value
n = 1, Write 8 bits data to custom instruction
n = 2, Write 16 bits data to custom instruction
n = 3, Write 32 bits data to custom instruction
n = 4, Read 32 bits data from the custom instruction
n = 5, Read 64 bits data from the custom instruction
n = 6, Read 96 bits data from the custom instruction
n = 7, Read 128 bits data from the custom instruction
*/
module CRC_Custom_Instruction(clk,
reset,
dataa,
n,
clk_en,
start,
done,
result);
/*
See the Avalon CRC component for details on the meaning of each
parameter listed below.
*/
parameter crc_width = 32;
parameter polynomial_inital = 32'hFFFFFFFF;
parameter polynomial = 32'h04C11DB7;
parameter reflected_input = 1;
parameter reflected_output = 1;
parameter xor_output = 32'hFFFFFFFF;
input clk;
input reset;
input [31:0] dataa;
input [2:0] n;
input clk_en;
input start;
output done;
output [31:0] result;
wire [2:0] address;
wire [3:0] byteenable;
wire write;
wire read;
reg done_delay;
assign write = (n<4);
assign read = (n>3);
assign byteenable = (n==1)?4'b0001 : (n==2)?4'b0011 : (n==3)?4'b1111 : 4'b0000;
assign address = (n==0)?3'b000 : ((n==1)|(n==2)|(n==3))?3'b001 : (n==4)?3'b100 : (n==5)?3'b101 : (n==6)?3'b110 : 3'b111;
assign done = (n>3)? done_delay : start;
always @ (posedge clk or posedge reset)
begin
if (reset)
done_delay <= 0;
else
done_delay <= start;
end
/*
Instantiating the Avalon CRC component and wiring it to be
custom instruction compilant
*/
CRC_Component wrapper_wiring(.clk(clk),
.reset(reset),
.address(address),
.writedata(dataa),
.byteenable(byteenable),
.write(write & start),
.read(read),
.chipselect(clk_en),
.readdata(result));
defparam wrapper_wiring.crc_width = crc_width;
defparam wrapper_wiring.polynomial_inital = polynomial_inital;
defparam wrapper_wiring.polynomial = polynomial;
defparam wrapper_wiring.reflected_input = reflected_input;
defparam wrapper_wiring.reflected_output = reflected_output;
defparam wrapper_wiring.xor_output = xor_output;
endmodule

View File

@ -1,116 +0,0 @@
# TCL File Generated by Component Editor 15.1
# Tue Dec 22 18:46:40 EET 2015
# DO NOT MODIFY
#
# nios2_hw_crc32 "nios2_hw_crc32" v1.0
# 2015.12.22.18:46:40
#
#
#
# request TCL package from ACDS 15.1
#
package require -exact qsys 15.1
#
# module nios2_hw_crc32
#
set_module_property DESCRIPTION ""
set_module_property NAME nios2_hw_crc32
set_module_property VERSION 17.1
set_module_property INTERNAL false
set_module_property OPAQUE_ADDRESS_MAP true
set_module_property GROUP "Custom Instruction Modules"
set_module_property AUTHOR ""
set_module_property DISPLAY_NAME nios2_hw_crc32
set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
set_module_property EDITABLE true
set_module_property REPORT_TO_TALKBACK false
set_module_property ALLOW_GREYBOX_GENERATION false
set_module_property REPORT_HIERARCHY false
#
# file sets
#
add_fileset QUARTUS_SYNTH QUARTUS_SYNTH "" ""
set_fileset_property QUARTUS_SYNTH TOP_LEVEL CRC_Custom_Instruction
set_fileset_property QUARTUS_SYNTH ENABLE_RELATIVE_INCLUDE_PATHS false
set_fileset_property QUARTUS_SYNTH ENABLE_FILE_OVERWRITE_MODE false
add_fileset_file CRC_Component.v VERILOG PATH hdl/CRC_Component.v
add_fileset_file CRC_Custom_Instruction.v VERILOG PATH hdl/CRC_Custom_Instruction.v TOP_LEVEL_FILE
#
# parameters
#
add_parameter crc_width INTEGER 32
set_parameter_property crc_width DEFAULT_VALUE 32
set_parameter_property crc_width DISPLAY_NAME crc_width
set_parameter_property crc_width TYPE INTEGER
set_parameter_property crc_width UNITS None
set_parameter_property crc_width HDL_PARAMETER true
add_parameter polynomial_inital STD_LOGIC_VECTOR 4294967295
set_parameter_property polynomial_inital DEFAULT_VALUE 4294967295
set_parameter_property polynomial_inital DISPLAY_NAME polynomial_inital
set_parameter_property polynomial_inital TYPE STD_LOGIC_VECTOR
set_parameter_property polynomial_inital UNITS None
set_parameter_property polynomial_inital ALLOWED_RANGES 0:17179869183
set_parameter_property polynomial_inital HDL_PARAMETER true
add_parameter polynomial STD_LOGIC_VECTOR 79764919
set_parameter_property polynomial DEFAULT_VALUE 79764919
set_parameter_property polynomial DISPLAY_NAME polynomial
set_parameter_property polynomial TYPE STD_LOGIC_VECTOR
set_parameter_property polynomial UNITS None
set_parameter_property polynomial ALLOWED_RANGES 0:17179869183
set_parameter_property polynomial HDL_PARAMETER true
add_parameter reflected_input INTEGER 1
set_parameter_property reflected_input DEFAULT_VALUE 1
set_parameter_property reflected_input DISPLAY_NAME reflected_input
set_parameter_property reflected_input TYPE INTEGER
set_parameter_property reflected_input UNITS None
set_parameter_property reflected_input HDL_PARAMETER true
add_parameter reflected_output INTEGER 1
set_parameter_property reflected_output DEFAULT_VALUE 1
set_parameter_property reflected_output DISPLAY_NAME reflected_output
set_parameter_property reflected_output TYPE INTEGER
set_parameter_property reflected_output UNITS None
set_parameter_property reflected_output HDL_PARAMETER true
add_parameter xor_output STD_LOGIC_VECTOR 4294967295
set_parameter_property xor_output DEFAULT_VALUE 4294967295
set_parameter_property xor_output DISPLAY_NAME xor_output
set_parameter_property xor_output TYPE STD_LOGIC_VECTOR
set_parameter_property xor_output UNITS None
set_parameter_property xor_output ALLOWED_RANGES 0:17179869183
set_parameter_property xor_output HDL_PARAMETER true
#
# display items
#
#
# connection point nios_custom_instruction_slave
#
add_interface nios_custom_instruction_slave nios_custom_instruction end
set_interface_property nios_custom_instruction_slave clockCycle 0
set_interface_property nios_custom_instruction_slave operands 1
set_interface_property nios_custom_instruction_slave ENABLED true
set_interface_property nios_custom_instruction_slave EXPORT_OF ""
set_interface_property nios_custom_instruction_slave PORT_NAME_MAP ""
set_interface_property nios_custom_instruction_slave CMSIS_SVD_VARIABLES ""
set_interface_property nios_custom_instruction_slave SVD_ADDRESS_GROUP ""
add_interface_port nios_custom_instruction_slave clk clk Input 1
add_interface_port nios_custom_instruction_slave clk_en clk_en Input 1
add_interface_port nios_custom_instruction_slave dataa dataa Input 32
add_interface_port nios_custom_instruction_slave done done Output 1
add_interface_port nios_custom_instruction_slave n n Input 3
add_interface_port nios_custom_instruction_slave reset reset Input 1
add_interface_port nios_custom_instruction_slave result result Output 32
add_interface_port nios_custom_instruction_slave start start Input 1

View File

@ -1,58 +0,0 @@
# (C) 2001-2015 Altera Corporation. All rights reserved.
# Your use of Altera Corporation's design tools, logic functions and other
# software and tools, and its AMPP partner logic functions, and any output
# files any of the foregoing (including device programming or simulation
# files), and any associated documentation or information are expressly subject
# to the terms and conditions of the Altera Program License Subscription
# Agreement, Altera MegaCore Function License Agreement, or other applicable
# license agreement, including, without limitation, that your use is for the
# sole purpose of programming logic devices manufactured by Altera and sold by
# Altera or its authorized distributors. Please refer to the applicable
# agreement for further details.
# TCL File Generated by Altera University Program
# DO NOT MODIFY
set aup_version 15.1
# Create a new driver - this name must be different than the
# hardware component name
create_driver nios2_hw_crc32_driver
# Associate it with some hardware
set_sw_property hw_class_name nios2_hw_crc32
# The version of this driver
set_sw_property version $aup_version
# This driver is proclaimed to be compatible with 'component'
# as old as version "1.0". The component hardware version is set in the
# _hw.tcl file - If the hardware component version number is not equal
# or greater than the min_compatable_hw_version number, the driver
# source files will not be copied over to the BSP driver directory
set_sw_property min_compatible_hw_version 1.0
# Initialize the driver in alt_sys_init()
set_sw_property auto_initialize false
# Location in generated BSP that sources will be copied into
set_sw_property bsp_subdirectory drivers
#
# Source file listings...
#
# C/C++ source files
add_sw_property c_source HAL/src/ci_crc.c
add_sw_property c_source HAL/src/crc.c
# Include files
add_sw_property include_source HAL/inc/ci_crc.h
add_sw_property include_source HAL/inc/crc.h
# This driver supports HAL type
add_sw_property supported_bsp_type HAL
# End of file

1
ip/pulpino_qsys Submodule

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

View File

@ -57,7 +57,7 @@ set_global_assignment -name STRATIX_DEVICE_IO_STANDARD "3.3-V LVTTL"
set_location_assignment PIN_25 -to clk27
set_location_assignment PIN_99 -to reset_n
set_location_assignment PIN_99 -to hw_reset_n
set_location_assignment PIN_23 -to ir_rx
#============================================================
@ -224,17 +224,18 @@ set_global_assignment -name ENABLE_SIGNALTAP OFF
set_global_assignment -name USE_SIGNALTAP_FILE output_files/ossc_la.stp
set_global_assignment -name FITTER_EFFORT "AUTO FIT"
set_global_assignment -name SEED 3
set_global_assignment -name SEED 12
set_global_assignment -name VERILOG_FILE rtl/videogen.v
set_global_assignment -name QIP_FILE software/sys_controller/mem_init/meminit.qip
set_global_assignment -name VERILOG_FILE rtl/ir_rcv.v
set_global_assignment -name SDC_FILE ossc.sdc
set_global_assignment -name QSYS_FILE sys.qsys
set_global_assignment -name VERILOG_FILE rtl/ossc.v
set_global_assignment -name VERILOG_FILE rtl/scanconverter.v
set_global_assignment -name VERILOG_FILE rtl/lat_tester.v
set_global_assignment -name QIP_FILE sys/synthesis/sys.qip
set_global_assignment -name QIP_FILE software/sys_controller/mem_init/meminit.qip
set_global_assignment -name QIP_FILE rtl/linebuf.qip
set_global_assignment -name QIP_FILE rtl/pll_2x.qip
set_global_assignment -name QIP_FILE rtl/pll_3x.qip
@ -242,7 +243,7 @@ set_global_assignment -name QIP_FILE rtl/lpm_mult_4_hybr_ref_pre.qip
set_global_assignment -name QIP_FILE rtl/lpm_mult_4_hybr_ref.qip
set_global_assignment -name QIP_FILE rtl/lpm_mult_4_sl.qip
set_global_assignment -name QIP_FILE rtl/mux5.qip
set_global_assignment -name SDC_FILE ossc.sdc
set_global_assignment -name CDF_FILE output_files/Chain1.cdf
set_global_assignment -name SIGNALTAP_FILE output_files/ossc_la.stp
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="ossc_sw_bsp" InternalType="">
<CodeLite_Project Name="ossc_sw_bsp" InternalType="" Version="10.0.0">
<Plugins>
<Plugin Name="qmake">
<![CDATA[00020001N0005Debug0000000000000001N0007Release000000000000]]>
@ -280,10 +280,9 @@
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<Target Name="nios2-bsp-editor">nios2-bsp-editor</Target>
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>nios2-bsp-generate-files --bsp-dir . --settings settings.bsp</BuildCommand>
<BuildCommand>make</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
@ -320,10 +319,9 @@
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<Target Name="nios2-bsp-editor">nios2-bsp-editor</Target>
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>nios2-bsp-generate-files --bsp-dir ./ --settings settings.bsp</BuildCommand>
<BuildCommand>make</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>

View File

@ -19,7 +19,7 @@
//`define DEBUG
`define VIDEOGEN
`define CPU_RESET_WIDTH 27 //1us
`define PO_RESET_WIDTH 27 //1us
module ossc (
input clk27,
@ -43,7 +43,7 @@ module ossc (
output HDMI_TX_PCLK,
input HDMI_TX_INT_N,
input HDMI_TX_MODE,
output reset_n,
output hw_reset_n,
output LED_G,
output LED_R,
output LCD_RS,
@ -81,8 +81,10 @@ wire PCLK_out_videogen;
wire DE_out_videogen;
reg [7:0] cpu_reset_ctr = 0;
reg cpu_reset_n = 1'b0;
reg [7:0] po_reset_ctr = 0;
reg po_reset_n = 1'b0;
wire jtagm_reset_req;
wire sys_reset_n = (po_reset_n & ~jtagm_reset_req);
reg [7:0] R_in_L, G_in_L, B_in_L;
reg HSYNC_in_L, VSYNC_in_L, FID_in_L;
@ -105,9 +107,9 @@ wire lcd_bl_timeout;
// Latch inputs from TVP7002 (synchronized to PCLK_in)
always @(posedge PCLK_in or negedge reset_n)
always @(posedge PCLK_in or negedge hw_reset_n)
begin
if (!reset_n) begin
if (!hw_reset_n) begin
R_in_L <= 8'h00;
G_in_L <= 8'h00;
B_in_L <= 8'h00;
@ -125,9 +127,9 @@ begin
end
// Insert synchronizers to async inputs (synchronize to CPU clock)
always @(posedge clk27 or negedge cpu_reset_n)
always @(posedge clk27 or negedge po_reset_n)
begin
if (!cpu_reset_n) begin
if (!po_reset_n) begin
btn_L <= 2'b00;
btn_LL <= 2'b00;
ir_rx_L <= 1'b0;
@ -148,16 +150,16 @@ begin
end
end
// CPU reset pulse generation (is this really necessary?)
// Power-on reset pulse generation (not strictly necessary)
always @(posedge clk27)
begin
if (cpu_reset_ctr == `CPU_RESET_WIDTH)
cpu_reset_n <= 1'b1;
if (po_reset_ctr == `PO_RESET_WIDTH)
po_reset_n <= 1'b1;
else
cpu_reset_ctr <= cpu_reset_ctr + 1'b1;
po_reset_ctr <= po_reset_ctr + 1'b1;
end
assign reset_n = sys_ctrl[0]; //HDMI_TX_RST_N in v1.2 PCB
assign hw_reset_n = sys_ctrl[0]; //HDMI_TX_RST_N in v1.2 PCB
`ifdef DEBUG
@ -171,7 +173,7 @@ assign LED_G = (ir_code == 0);
assign SD_DAT[3] = sys_ctrl[7]; //SD_SPI_SS_N
assign LCD_CS_N = sys_ctrl[6];
assign LCD_RS = sys_ctrl[5];
wire lcd_bl_on = sys_ctrl[4]; //reset_n in v1.2 PCB
wire lcd_bl_on = sys_ctrl[4]; //hw_reset_n in v1.2 PCB
wire [1:0] lcd_bl_time = sys_ctrl[3:2];
assign LCD_BL = lcd_bl_on ? (~lcd_bl_timeout | lt_active) : 1'b0;
@ -226,7 +228,12 @@ end
sys sys_inst(
.clk_clk (clk27),
.reset_reset_n (cpu_reset_n),
.reset_reset_n (sys_reset_n),
.pulpino_0_config_testmode_i (1'b0),
.pulpino_0_config_fetch_enable_i (1'b1),
.pulpino_0_config_clock_gating_i (1'b0),
.pulpino_0_config_boot_addr_i (32'h00010000),
.master_0_master_reset_reset (jtagm_reset_req),
.i2c_opencores_0_export_scl_pad_io (scl),
.i2c_opencores_0_export_sda_pad_io (sda),
.i2c_opencores_0_export_spi_miso_pad_i (1'b0),
@ -245,7 +252,7 @@ sys sys_inst(
);
scanconverter scanconverter_inst (
.reset_n (reset_n),
.reset_n (hw_reset_n),
.PCLK_in (PCLK_in),
.clk27 (clk27),
.HSYNC_in (HSYNC_in_L),
@ -279,7 +286,7 @@ scanconverter scanconverter_inst (
ir_rcv ir0 (
.clk27 (clk27),
.reset_n (cpu_reset_n),
.reset_n (po_reset_n),
.ir_rx (ir_rx_LL),
.ir_code (ir_code),
.ir_code_ack (),
@ -304,7 +311,7 @@ lat_tester lt0 (
`ifdef VIDEOGEN
videogen vg0 (
.clk27 (clk27),
.reset_n (cpu_reset_n & videogen_sel),
.reset_n (po_reset_n & videogen_sel),
.lt_active (lt_active),
.lt_mode (lt_mode_synced),
.R_out (R_out_videogen),

View File

@ -42,6 +42,7 @@
`define H_MULTMODE_FULLWIDTH 2'h0
`define H_MULTMODE_ASPECTFIX 2'h1
`define H_MULTMODE_OPTIMIZED 2'h2
`define H_MULTMODE_OPTIMIZED_1X 2'h3
`define SCANLINES_OFF 2'h0
`define SCANLINES_H 2'h1
@ -187,6 +188,8 @@ reg [2:0] H_OPT_SCALE;
reg [2:0] H_OPT_SAMPLE_MULT;
reg [2:0] H_OPT_SAMPLE_SEL;
reg [9:0] H_L5BORDER;
reg [9:0] H_L3BORDER;
reg [6:0] H_L3_OPT_SAMPLE_COMP;
reg [3:0] X_MASK_BR;
reg X_SCANLINE_METHOD;
reg [4:0] X_SCANLINE_HYBRSTR;
@ -375,12 +378,18 @@ case (V_MULTMODE)
col_id_act = {2'b00, hcnt_2x[0]};
rlpf_trigger_act = 1'b1;
end
`H_MULTMODE_OPTIMIZED: begin
`H_MULTMODE_OPTIMIZED_1X: begin
pclk_mux_sel = `PCLK_MUX_1X; //special case: pclk bypass to enable 2x native sampling
linebuf_hoffset = hcnt_2x_opt;
col_id_act = {2'b00, hcnt_2x[1]};
rlpf_trigger_act = (hcnt_2x_opt_ctr == 0);
end
`H_MULTMODE_OPTIMIZED: begin
pclk_mux_sel = `PCLK_MUX_2X;
linebuf_hoffset = hcnt_2x_opt;
col_id_act = hcnt_2x_opt_ctr;
rlpf_trigger_act = (hcnt_2x_opt_ctr == 0);
end
endcase
end
`V_MULTMODE_3X: begin
@ -870,6 +879,10 @@ begin
// H_L5BORDER <= h_info[29] ? (11'd1920-h_info[10:0])/2 : (11'd1600-h_info[10:0])/2;
H_L5BORDER <= h_info[29] ? H_L5BORDER_1920_tmp[10:1] : H_L5BORDER_1600_tmp[10:1];
// For Line3x 240x360
H_L3BORDER <= h_info[28] ? H_L5BORDER_1920_tmp[10:1] : 10'd0;
H_L3_OPT_SAMPLE_COMP <= h_info[28] ? 7'd90 : 7'd0;
H_OPT_SCALE <= h_info2[18:16];
H_OPT_SAMPLE_SEL <= h_info2[15:13];
@ -990,7 +1003,7 @@ begin
if ((pclk_3x_cnt == 0) & (line_change | frame_change)) begin //aligned with posedge of pclk_1x
if (!(frame_change & (FID_cur == `FID_ODD))) begin
hcnt_3x <= 0;
hcnt_3x_opt <= H_OPT_SAMPLE_SEL;
hcnt_3x_opt <= H_OPT_SAMPLE_SEL + H_L3_OPT_SAMPLE_COMP;
hcnt_3x_opt_ctr <= 0;
line_out_idx_3x <= 0;
end
@ -1001,7 +1014,7 @@ begin
end else if (hcnt_3x == hmax[~line_idx]) begin
hcnt_3x <= 0;
line_out_idx_3x <= line_out_idx_3x + 1'b1;
hcnt_3x_opt <= H_OPT_SAMPLE_SEL;
hcnt_3x_opt <= H_OPT_SAMPLE_SEL + H_L3_OPT_SAMPLE_COMP;
hcnt_3x_opt_ctr <= 0;
end else begin
hcnt_3x <= hcnt_3x + 1'b1;
@ -1032,7 +1045,7 @@ begin
VSYNC_3x <= ~`VSYNC_POL;
end
DE_3x <= ((hcnt_3x >= H_AVIDSTART) & (hcnt_3x < H_AVIDSTOP)) & ((vcnt_3x >= V_AVIDSTART) & (vcnt_3x < V_AVIDSTOP));
DE_3x <= ((hcnt_3x >= H_AVIDSTART-H_L3BORDER) & (hcnt_3x < H_AVIDSTOP+H_L3BORDER)) & ((vcnt_3x >= V_AVIDSTART) & (vcnt_3x < V_AVIDSTOP));
end
end

25
scripts/rv-reprogram.tcl Normal file
View File

@ -0,0 +1,25 @@
#Select the master service type and check for available service paths.
set service_paths [get_service_paths master]
#Set the master service path.
set master_service_path [lindex $service_paths 0]
#Open the master service.
set claim_path [claim_service master $master_service_path mylib]
puts "Halting CPU"
master_write_32 $claim_path 0x0 0x1
puts "Writing block RAM"
master_write_from_file $claim_path mem_init/sys_onchip_memory2_0.bin 0x10000
close_service master $claim_path
set jtag_debug_list [get_service_paths jtag_debug]
set jd [ lindex $jtag_debug_list 0 ]
open_service jtag_debug $jd
puts "Resetting system"
jtag_debug_reset_system $jd
close_service jtag_debug $jd
puts "Done"

View File

@ -121,7 +121,7 @@
</Compiler>
<Linker Options="" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Debug" Command="nios2-download -g --accept-bad-sysid sys_controller.elf &amp;&amp; nios2-terminal" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(ProjectPath)/sys_controller" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<General OutputFile="" IntermediateDirectory="./Debug" Command="make rv-reprogram &amp;&amp; nios2-terminal" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(ProjectPath)/sys_controller" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
@ -134,7 +134,9 @@
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<Target Name="diy-audio-debug">make ENABLE_AUDIO=y APP_CFLAGS_DEBUG_LEVEL="-DDEBUG"</Target>
<Target Name="compile_image_debug">make APP_CFLAGS_DEBUG_LEVEL="-DDEBUG" generate_hex</Target>
<Target Name="compile_image_aud-debug">make ENABLE_AUDIO=y APP_CFLAGS_DEBUG_LEVEL="-DDEBUG" generate_hex</Target>
<Target Name="Ack BSP update">cd ../sys_controller_bsp &amp;&amp; touch bsp_timestamp</Target>
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>make APP_CFLAGS_DEBUG_LEVEL="-DDEBUG"</BuildCommand>
@ -161,7 +163,7 @@
</Compiler>
<Linker Options="-O2" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Release" Command="nios2-download -g --accept-bad-sysid sys_controller.elf" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(ProjectPath)/sys_controller" PauseExecWhenProcTerminates="no" IsGUIProgram="no" IsEnabled="yes"/>
<General OutputFile="" IntermediateDirectory="./Release" Command="make rv-reprogram" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(ProjectPath)/sys_controller" PauseExecWhenProcTerminates="no" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
@ -180,6 +182,7 @@
<Target Name="compile_image">make generate_hex</Target>
<Target Name="Build_jp">make OSDLANG=JP</Target>
<Target Name="Build_audio">make ENABLE_AUDIO=y</Target>
<Target Name="Ack BSP update">cd ../sys_controller_bsp &amp;&amp; touch bsp_timestamp</Target>
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>make</BuildCommand>

View File

@ -17,7 +17,7 @@ ALT_LIBRARY_NAMES :=
# List of library names for -msys-lib linker option (-msys-lib added when used).
# These are libraries that might be located in the BSP and depend on the BSP
# library, or vice versa
ALT_BSP_DEP_LIBRARY_NAMES :=
ALT_BSP_DEP_LIBRARY_NAMES := libhal_bsp.a
# List of dependencies for the linker. This is usually the full pathname
# of each library (*.a) file.
@ -165,10 +165,11 @@ else
C_SRCS += ossc/menu.c
endif
C_SRCS += ossc/userdata.c
C_SRCS += ossc/utils.c
C_SRCS += ulibSD/sd_io.c
C_SRCS += ulibSD/spi_io.c
CXX_SRCS :=
ASM_SRCS :=
ASM_SRCS := crt0.boot_E.S
# Path to root of object file tree.
@ -344,12 +345,12 @@ ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)
# Detect if small newlib C library is requested.
# If yes, remove the -msmallc option because it is
# now handled by other means.
ifneq ($(filter -msmallc,$(ALT_LDFLAGS)),)
ALT_LDFLAGS := $(filter-out -msmallc,$(ALT_LDFLAGS))
ALT_C_LIBRARY := smallc
else
ALT_C_LIBRARY := c
endif
#ifneq ($(filter -msmallc,$(ALT_LDFLAGS)),)
#ALT_LDFLAGS := $(filter-out -msmallc,$(ALT_LDFLAGS))
#ALT_C_LIBRARY := smallc
#else
#ALT_C_LIBRARY := c
#endif
# Put each BSP dependent library in a group to avoid circular dependencies.
APP_BSP_DEP_LIBS := $(foreach l,$(ALT_BSP_DEP_LIBRARY_NAMES),-Wl,--start-group -l$(ALT_C_LIBRARY) -lgcc -l$(l) -Wl,--end-group)
@ -359,7 +360,8 @@ else # !AVOID_NIOS2_GCC3_OPTIONS
#
# Use Nios II GCC 3.X options.
#
APP_BSP_DEP_LIBS := $(addprefix -msys-lib=, $(ALT_BSP_DEP_LIBRARY_NAMES))
#APP_BSP_DEP_LIBS := $(addprefix -msys-lib=, $(ALT_BSP_DEP_LIBRARY_NAMES))
APP_BSP_DEP_LIBS := $(addprefix -l:, $(ALT_BSP_DEP_LIBRARY_NAMES))
endif # !AVOID_NIOS2_GCC3_OPTIONS
@ -389,7 +391,7 @@ APP_ASFLAGS := $(APP_ASM_INC_DIRS) \
$(ASFLAGS)
# Arguments only for the linker.
APP_LDFLAGS := $(APP_LDFLAGS_USER)
APP_LDFLAGS := $(APP_LDFLAGS_USER) --specs=nano.specs -nostartfiles
ifneq ($(LINKER_SCRIPT),)
APP_LDFLAGS += -T'$(LINKER_SCRIPT)'
@ -410,17 +412,16 @@ else # !AVOID_NIOS2_GCC3_OPTIONS
# Use Nios II GCC 3.x options.
ifneq ($(CRT0),)
APP_LDFLAGS += -msys-crt0='$(CRT0)'
#APP_LDFLAGS += -msys-crt0='$(CRT0)'
endif
ifneq ($(SYS_LIB),)
APP_LDFLAGS += -msys-lib=$(SYS_LIB)
#APP_LDFLAGS += -msys-lib=$(SYS_LIB)
endif
endif # !AVOID_NIOS2_GCC3_OPTIONS
APP_LDFLAGS += \
$(APP_LIB_DIRS) \
$(ALT_LDFLAGS) \
$(LDFLAGS)
LINKER_MAP_NAME := $(APP_NAME).map
@ -651,23 +652,24 @@ build_post_process :
# included makefile fragment.
#
ifeq ($(DEFAULT_CROSS_COMPILE),)
DEFAULT_CROSS_COMPILE := nios2-elf-
DEFAULT_CROSS_COMPILE := riscv32-unknown-elf-
endif
ifeq ($(DEFAULT_STACKREPORT),)
DEFAULT_STACKREPORT := nios2-stackreport
DEFAULT_STACKREPORT := riscv32-unknown-elf-size
endif
ifeq ($(DEFAULT_DOWNLOAD),)
DEFAULT_DOWNLOAD := nios2-download
DEFAULT_DOWNLOAD := anios2-download
endif
ifeq ($(DEFAULT_FLASHPROG),)
DEFAULT_FLASHPROG := nios2-flash-programmer
DEFAULT_FLASHPROG := anios2-flash-programmer
endif
DISABLE_ELFPATCH := 1
ifeq ($(DEFAULT_ELFPATCH),)
DEFAULT_ELFPATCH := nios2-elf-insert
DEFAULT_ELFPATCH := anios2-elf-insert
endif
ifeq ($(DEFAULT_RM),)
@ -732,7 +734,7 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
endif
ifeq ($(STACKREPORT),)
STACKREPORT := $(DEFAULT_STACKREPORT) --prefix $(CROSS_COMPILE)
STACKREPORT := $(DEFAULT_STACKREPORT)
else
DISABLE_STACKREPORT := 1
endif
@ -753,6 +755,8 @@ ifeq ($(MKDIR),)
MKDIR := $(DEFAULT_MKDIR)
endif
RV_OBJCOPY = riscv32-unknown-elf-objcopy
#------------------------------------------------------------------------------
# PATTERN RULES TO BUILD OBJECTS
#------------------------------------------------------------------------------
@ -1126,5 +1130,16 @@ print-elf-name:
ossc/menu_sjis.c: ossc/menu.c
iconv -f UTF-8 -t SHIFT-JIS ossc/menu.c > ossc/menu_sjis.c
mem_init/sys_onchip_memory2_0.hex: sys_controller.elf
$(RV_OBJCOPY) --change-addresses -0x10000 -O binary --gap-fill 0 $< mem_init/sys_onchip_memory2_0.bin
../../tools/bin2hex mem_init/sys_onchip_memory2_0.bin mem_init/sys_onchip_memory2_0.hex
.PHONY: mem_init_generate_new
mem_init_generate_new: mem_init/sys_onchip_memory2_0.hex
.PHONY: generate_hex
generate_hex: clean mem_init_generate
generate_hex: clean mem_init_generate_new
.PHONY: rv-reprogram
rv-reprogram: mem_init_generate_new
system-console -cli --script ../../scripts/rv-reprogram.tcl

View File

@ -0,0 +1,103 @@
// Copyright 2017 ETH Zurich and University of Bologna.
// Copyright and related rights are licensed under the Solderpad Hardware
// License, Version 0.51 (the License); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
// or agreed to in writing, software, hardware and materials distributed under
// this 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.
#include "pulpino.h"
#define EXCEPTION_STACK_SIZE 72
/* ========================================================= [ entry ] === */
.section .text
default_exc_handler:
jal x0, default_exc_handler
reset_handler:
/* set all registers to zero */
mv x1, x0
mv x2, x1
mv x3, x1
mv x4, x1
mv x5, x1
mv x6, x1
mv x7, x1
mv x8, x1
mv x9, x1
mv x10, x1
mv x11, x1
mv x12, x1
mv x13, x1
mv x14, x1
mv x15, x1
mv x16, x1
mv x17, x1
mv x18, x1
mv x19, x1
mv x20, x1
mv x21, x1
mv x22, x1
mv x23, x1
mv x24, x1
mv x25, x1
mv x26, x1
mv x27, x1
mv x28, x1
mv x29, x1
mv x30, x1
mv x31, x1
/* stack initilization */
la x2, _stack_start
_start:
.global _start
/* clear BSS */
la x26, _bss_start
la x27, _bss_end
bge x26, x27, zero_loop_end
zero_loop:
sw x0, 0(x26)
addi x26, x26, 4
ble x26, x27, zero_loop
zero_loop_end:
main_entry:
/* jump to alt_main program entry point */
jal alt_main
/* =================================================== [ exceptions ] === */
/* This section has to be down here, since we have to disable rvc for it */
.section .vectors, "ax"
.option norvc;
// external interrupts are handled by the same callback
// until compiler supports IRQ routines
.org 0x00
.rept 31
nop
.endr
jal x0, default_exc_handler
// reset vector
.org 0x80
jal x0, reset_handler
// illegal instruction exception
.org 0x84
jal x0, default_exc_handler
// ecall handler
.org 0x88
jal x0, default_exc_handler

View File

@ -0,0 +1,87 @@
// Copyright 2017 ETH Zurich and University of Bologna.
// Copyright and related rights are licensed under the Solderpad Hardware
// License, Version 0.51 (the License); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
// or agreed to in writing, software, hardware and materials distributed under
// this 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.
#include "pulpino.h"
#define EXCEPTION_STACK_SIZE 72
/* ========================================================= [ entry ] === */
.section .text
default_exc_handler:
jal x0, default_exc_handler
reset_handler:
/* set all registers to zero */
mv x1, x0
mv x2, x1
mv x3, x1
mv x4, x1
mv x5, x1
mv x6, x1
mv x7, x1
mv x8, x1
mv x9, x1
mv x10, x1
mv x11, x1
mv x12, x1
mv x13, x1
mv x14, x1
mv x15, x1
/* stack initilization */
la x2, _stack_start
_start:
.global _start
/* clear BSS */
la x14, _bss_start
la x15, _bss_end
bge x14, x15, zero_loop_end
zero_loop:
sw x0, 0(x14)
addi x14, x14, 4
ble x14, x15, zero_loop
zero_loop_end:
main_entry:
/* jump to alt_main program entry point */
jal alt_main
/* =================================================== [ exceptions ] === */
/* This section has to be down here, since we have to disable rvc for it */
.section .vectors, "ax"
.option norvc;
// external interrupts are handled by the same callback
// until compiler supports IRQ routines
.org 0x00
.rept 31
nop
.endr
jal x0, default_exc_handler
// reset vector
.org 0x80
jal x0, reset_handler
// illegal instruction exception
.org 0x84
jal x0, default_exc_handler
// ecall handler
.org 0x88
jal x0, default_exc_handler

View File

@ -52,7 +52,7 @@
//#define NULL 0
//typedef unsigned char bool;
#include "Altera_UP_SD_Card_Avalon_Interface_mod.h"
typedef unsigned char bool;
#include "sysconfig.h"
// Hardwired to CPU reset

View File

@ -0,0 +1,135 @@
SEARCH_DIR(.)
__DYNAMIC = 0;
MEMORY
{
dataram : ORIGIN = 0x00010000, LENGTH = 0x9000
}
/* Stack information variables */
_min_stack = 0x400; /* 1K - minimum stack space to reserve */
_stack_start = ORIGIN(dataram) + LENGTH(dataram);
/* We have to align each sector to word boundaries as our current s19->slm
* conversion scripts are not able to handle non-word aligned sections. */
SECTIONS
{
.vectors :
{
. = ALIGN(4);
KEEP(*(.vectors))
} > dataram
.text : {
. = ALIGN(4);
_stext = .;
*(.text)
*(.text.*)
_etext = .;
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
*(.ctors)
LONG(0)
__CTOR_END__ = .;
__DTOR_LIST__ = .;
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
*(.dtors)
LONG(0)
__DTOR_END__ = .;
*(.lit)
*(.shdata)
_endtext = .;
} > dataram
/*--------------------------------------------------------------------*/
/* Global constructor/destructor segement */
/*--------------------------------------------------------------------*/
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > dataram
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array ))
PROVIDE_HIDDEN (__init_array_end = .);
} > dataram
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array ))
PROVIDE_HIDDEN (__fini_array_end = .);
} > dataram
.rodata : {
. = ALIGN(4);
*(.rodata);
*(.rodata.*)
} > dataram
.shbss :
{
. = ALIGN(4);
*(.shbss)
} > dataram
.data : {
. = ALIGN(4);
sdata = .;
_sdata = .;
*(.data);
*(.data.*)
*(.sdata);
*(.sdata.*)
*(.sdata2);
*(.sdata2.*)
edata = .;
_edata = .;
} > dataram
.bss :
{
. = ALIGN(4);
_bss_start = .;
*(.bss)
*(.bss.*)
*(.sbss)
*(.sbss.*)
*(COMMON)
_bss_end = .;
} > dataram
/* ensure there is enough room for stack */
.stack (NOLOAD): {
. = ALIGN(4);
. = . + _min_stack ;
. = ALIGN(4);
stack = . ;
_stack = . ;
} > dataram
.stab 0 (NOLOAD) :
{
[ .stab ]
}
.stabstr 0 (NOLOAD) :
{
[ .stabstr ]
}
.bss :
{
. = ALIGN(4);
_end = .;
} > dataram
}

View File

@ -0,0 +1,7 @@
/* not needed, but we need separate linker scripts anyway */
OUTPUT_ARCH(riscv)
/* required to correctly link newlib */
GROUP( -lc -lgloss -lgcc -lsupc++ )
INCLUDE link.common.ld

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@
#include <string.h>
#include "system.h"
#include "flash.h"
#include "ci_crc.h"
#include "utils.h"
extern alt_epcq_controller_dev epcq_controller_0;
@ -49,9 +49,6 @@ int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf)
if (retval != 0)
return -FLASH_READ_ERROR;
for (i=0; i<length; i++)
dstbuf[i] = ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0(dstbuf[i]) >> 24;
return 0;
}
@ -69,10 +66,6 @@ int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum)
}
}
// Bit-reverse bytes for flash
for (i=0; i<length; i++)
pagedata[i] = ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0(pagedata[i]) >> 24;
retval = alt_epcq_controller_write_block(&epcq_controller_dev->dev, (pagenum/PAGES_PER_SECTOR)*PAGES_PER_SECTOR*PAGESIZE, pagenum*PAGESIZE, pagedata, length);
if (retval != 0) {
@ -83,6 +76,26 @@ int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum)
return 0;
}
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum)
{
int retval;
alt_u32 bytes_to_w;
while (length > 0) {
bytes_to_w = (length > PAGESIZE) ? PAGESIZE : length;
retval = write_flash_page(buf, bytes_to_w, pagenum);
if (retval != 0)
return retval;
buf += bytes_to_w;
length -= bytes_to_w;
++pagenum;
}
return 0;
}
int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf)
{
alt_u32 crcval=0, i, bytes_to_read;
@ -95,7 +108,7 @@ int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmp
if (retval != 0)
return retval;
crcval = crcCI(tmpbuf, bytes_to_read, (i==0));
crcval = crc32(tmpbuf, bytes_to_read, (i==0));
}
if (crcval != golden_crc)

View File

@ -44,6 +44,8 @@ int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf);
int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum);
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum);
int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf);
#endif /* FLASH_H_ */

View File

@ -19,6 +19,7 @@
#include <io.h>
#include "sdcard.h"
#include "flash.h"
#include "lcd.h"
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
@ -36,3 +37,28 @@ int check_sdcard(alt_u8 *databuf)
return SD_Read(&sdcard_dev, databuf, 0, 0, 512);
}
int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, alt_u8 *tmpbuf)
{
int retval;
alt_u32 bytes_to_rw;
while (length > 0) {
bytes_to_rw = (length < SD_BLK_SIZE) ? length : SD_BLK_SIZE;
retval = SD_Read(&sdcard_dev, tmpbuf, sd_blknum, 0, bytes_to_rw);
if (retval != 0) {
printf("Failed to read SD card\n");
return -retval;
}
retval = write_flash(tmpbuf, bytes_to_rw, flash_pagenum);
if (retval != 0)
return retval;
++sd_blknum;
flash_pagenum += bytes_to_rw/PAGESIZE;
length -= bytes_to_rw;
}
return 0;
}

View File

@ -25,5 +25,6 @@
#include "sd_io.h"
int check_sdcard(alt_u8 *databuf);
int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, alt_u8 *tmpbuf);
#endif /* SDCARD_H_ */

View File

@ -41,6 +41,7 @@
#include "HDMI_TX.h"
#include "hdmitx.h"
#include "sd_io.h"
#include "sys/alt_timestamp.h"
#define STABLE_THOLD 1
#define MIN_LINES_PROGRESSIVE 200
@ -69,6 +70,7 @@ alt_u8 stable_frames;
alt_u8 update_cur_vm;
alt_u8 vm_sel, vm_edit, profile_sel, profile_sel_menu, input_profiles[AV_LAST], lt_sel, def_input, profile_link, lcd_bl_timeout;
alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr = 1, auto_av3_ypbpr;
alt_u16 tc_h_samplerate, tc_h_synclen, tc_h_bporch, tc_h_active, tc_v_synclen, tc_v_bporch, tc_v_active;
char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
@ -78,6 +80,7 @@ avinput_t target_input;
alt_u8 pcm1862_active;
alt_u32 read_it2(alt_u32 regaddr);
inline void lcd_write_menu()
{
@ -361,8 +364,8 @@ status_t get_status(tvp_input_t input, video_format format)
return status;
}
// h_info: [31:30] [29] [28] [27:20] [19:11] [10:0]
// | H_MULTMODE[1:0] | H_L5FMT | | H_SYNCLEN[7:0] | H_BACKPORCH[8:0] | H_ACTIVE[10:0] |
// h_info: [31:30] [29] [28] [27:20] [19:11] [10:0]
// | H_MULTMODE[1:0] | H_L5FMT | H_L3_240x360 | H_SYNCLEN[7:0] | H_BACKPORCH[8:0] | H_ACTIVE[10:0] |
//
// h_info2: [31:30] [29:19] [18:16] [15:13] [12:10] [9:0]
// | | H_MASK[10:0] | H_OPT_SCALE[2:0] | H_OPT_SAMPLE_SEL[2:0] | H_OPT_SAMPLE_MULT[2:0] | H_OPT_STARTOFF[9:0] |
@ -398,6 +401,7 @@ void set_videoinfo()
switch (cm.target_lm) {
case MODE_L2_320_COL:
case MODE_L2_240x360:
h_opt_scale = 4;
break;
case MODE_L2_256_COL:
@ -409,36 +413,30 @@ void set_videoinfo()
case MODE_L3_256_COL:
h_opt_scale = 4-cm.cc.ar_256col;
break;
case MODE_L3_240x360:
h_opt_scale = 6;
break;
case MODE_L4_320_COL:
h_opt_scale = 4;
break;
case MODE_L4_256_COL:
h_opt_scale = 5-cm.cc.ar_256col;
break;
case MODE_L5_GEN_4_3:
if (cm.cc.l5_fmt == L5FMT_1920x1080) {
v_active -= 24;
v_backporch += 12;
}
break;
case MODE_L5_320_COL:
h_opt_scale = 5;
if (cm.cc.l5_fmt == L5FMT_1920x1080) {
v_active -= 24;
v_backporch += 12;
}
break;
case MODE_L5_256_COL:
h_opt_scale = 6-cm.cc.ar_256col;
if (cm.cc.l5_fmt == L5FMT_1920x1080) {
v_active -= 24;
v_backporch += 12;
}
break;
default:
break;
}
if (cm.target_lm >= MODE_L5_GEN_4_3 && cm.cc.l5_fmt == L5FMT_1920x1080) {
v_active -= 24;
v_backporch += 12;
}
// CEA-770.3 HDTV modes use tri-level syncs which have twice the width of bi-level syncs of corresponding CEA-861 modes
if (target_type == VIDEO_HDTV)
h_synclen *= 2;
@ -456,6 +454,7 @@ void set_videoinfo()
IOWR_ALTERA_AVALON_PIO_DATA(PIO_3_BASE, (cm.fpga_hmultmode<<30) |
((cm.cc.l5_fmt!=L5FMT_1600x1200)<<29) |
((cm.target_lm==MODE_L3_240x360)<<28) |
(((cm.sample_mult*h_synclen)&0xff)<<20) |
(((cm.sample_mult*(alt_u16)video_modes[cm.id].h_backporch)&0x1ff)<<11) |
((cm.sample_mult*video_modes[cm.id].h_active)&0x7ff));
@ -549,7 +548,7 @@ void program_mode()
int load_profile() {
int retval;
retval = read_userdata(profile_sel_menu);
retval = read_userdata(profile_sel_menu, 0);
if (retval == 0) {
profile_sel = profile_sel_menu;
@ -682,8 +681,8 @@ int init_hw()
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap));
// Load initconfig and profile
read_userdata(INIT_CONFIG_SLOT);
read_userdata(profile_sel);
read_userdata(INIT_CONFIG_SLOT, 0);
read_userdata(profile_sel, 0);
// Setup remote keymap
if (!(IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & PB1_BIT))
@ -695,15 +694,6 @@ int init_hw()
return 0;
}
#ifdef DEBUG
int latency_test()
{
sniprintf(menu_row2, LCD_ROW_LEN+1, "Unavailable");
lcd_write_menu();
usleep(1000000);
return -1;
}
#else
int latency_test() {
alt_u32 lt_status, btn_vec, btn_vec_prev=1;
alt_u16 latency_ms_x100, stb_ms_x100;
@ -736,7 +726,9 @@ int latency_test() {
SPI_Timer_Off();
latency_ms_x100 = lt_status & 0xffff;
stb_ms_x100 = (lt_status >> 16) & 0xfff;
if ((latency_ms_x100 == 0) || (latency_ms_x100 == 0xffff))
if (latency_ms_x100 == 0)
sniprintf(menu_row2, LCD_ROW_LEN+1, "False trigger");
else if (latency_ms_x100 == 0xffff)
sniprintf(menu_row2, LCD_ROW_LEN+1, "Timeout");
else if (stb_ms_x100 == 0xfff)
sniprintf(menu_row2, LCD_ROW_LEN+1, "%u.%.2ums", latency_ms_x100/100, latency_ms_x100%100);
@ -760,7 +752,6 @@ int latency_test() {
return 0;
}
#endif
// Enable chip outputs
void enable_outputs()
@ -785,6 +776,12 @@ int main()
alt_u32 input_vec;
alt_u32 auto_input_timestamp = 300 * (alt_timestamp_freq() >> 10);
alt_u8 auto_input_changed = 0;
alt_u8 auto_input_ctr = 0;
alt_u8 auto_input_current_ctr = AUTO_CURRENT_MAX_COUNT;
alt_u8 auto_input_keep_current = 0;
int init_stat, man_input_change;
init_stat = init_hw();
@ -806,6 +803,9 @@ int main()
while (1) {}
}
// start timer for auto input
alt_timestamp_start();
// Mainloop
while(1) {
// Read remote control and PCB button status
@ -826,11 +826,68 @@ int main()
btn_code = 0;
}
// Auto input switching
if (auto_input != AUTO_OFF && cm.avinput != AV_TESTPAT && !cm.sync_active && !menu_active
&& alt_timestamp() >= auto_input_timestamp && auto_input_ctr < AUTO_MAX_COUNT) {
// Keep switching on the same physical input when set to Current input or a short time after losing sync.
auto_input_keep_current = (auto_input == AUTO_CURRENT_INPUT || auto_input_current_ctr < AUTO_CURRENT_MAX_COUNT);
switch(cm.avinput) {
case AV1_RGBs:
target_input = auto_av1_ypbpr ? AV1_YPBPR : AV1_RGsB;
break;
case AV1_RGsB:
case AV1_YPBPR:
target_input = auto_input_keep_current ? AV1_RGBs : (auto_av2_ypbpr ? AV2_YPBPR : AV2_RGsB);
break;
case AV2_YPBPR:
case AV2_RGsB:
target_input = auto_input_keep_current ? target_input : AV3_RGBHV;
break;
case AV3_RGBHV:
target_input = AV3_RGBs;
break;
case AV3_RGBs:
target_input = auto_av3_ypbpr ? AV3_YPBPR : AV3_RGsB;
break;
case AV3_RGsB:
case AV3_YPBPR:
target_input = auto_input_keep_current ? AV3_RGBHV : AV1_RGBs;
break;
default:
break;
}
auto_input_ctr++;
if (auto_input_current_ctr < AUTO_CURRENT_MAX_COUNT)
auto_input_current_ctr++;
// For input linked profile loading below
auto_input_changed = 1;
// reset timer
alt_timestamp_start();
}
man_input_change = parse_control();
if (menu_active)
display_menu(0);
// Only auto load profile when input is manually changed or when sync is active after automatic switch.
if ((target_input != cm.avinput && man_input_change) || (auto_input_changed && cm.sync_active)) {
// The input changed, so load the appropriate profile if
// input->profile link is enabled
if (profile_link && (profile_sel != input_profiles[target_input])) {
profile_sel = input_profiles[target_input];
read_userdata(profile_sel, 0);
}
auto_input_changed = 0;
}
if (target_input != cm.avinput) {
target_tvp = TVP_INPUT1;
@ -873,13 +930,6 @@ int main()
printf("### SWITCH MODE TO %s ###\n", avinput_str[target_input]);
// The input changed, so load the appropriate profile if
// input->profile link is enabled
if (profile_link && (profile_sel != input_profiles[target_input])) {
profile_sel = input_profiles[target_input];
read_userdata(profile_sel);
}
cm.avinput = target_input;
cm.sync_active = 0;
ths_source_sel(target_ths, (cm.cc.video_lpf > 1) ? (VIDEO_LPF_MAX-cm.cc.video_lpf) : THS_LPF_BYPASS);
@ -895,9 +945,14 @@ int main()
strncpy(row2, " NO SYNC", LCD_ROW_LEN+1);
if (!menu_active)
lcd_write_status();
// record last input if it was selected manually
if ((def_input == AV_LAST) && man_input_change)
write_userdata(INIT_CONFIG_SLOT);
if (man_input_change) {
// record last input if it was selected manually
if (def_input == AV_LAST)
write_userdata(INIT_CONFIG_SLOT);
// Reset auto input timer when input is manually changed
auto_input_ctr = 0;
alt_timestamp_start();
}
}
// Check here to enable regardless of input
@ -933,6 +988,9 @@ int main()
strncpy(row2, " NO SYNC", LCD_ROW_LEN+1);
if (!menu_active)
lcd_write_status();
alt_timestamp_start();// reset auto input timer
auto_input_ctr = 0;
auto_input_current_ctr = 0;
}
break;
case MODE_CHANGE:

View File

@ -55,12 +55,18 @@
#define FPGA_H_MULTMODE_FULLWIDTH 0
#define FPGA_H_MULTMODE_ASPECTFIX 1
#define FPGA_H_MULTMODE_OPTIMIZED 2
#define FPGA_H_MULTMODE_OPTIMIZED_1X 3
#define FPGA_SCANLINEMODE_OFF 0
#define FPGA_SCANLINEMODE_H 1
#define FPGA_SCANLINEMODE_V 2
#define FPGA_SCANLINEMODE_ALT 3
#define AUTO_OFF 0
#define AUTO_CURRENT_INPUT 1
#define AUTO_MAX_COUNT 100
#define AUTO_CURRENT_MAX_COUNT 6
// In reverse order of importance
typedef enum {
NO_CHANGE = 0,

View File

@ -105,11 +105,9 @@ typedef struct {
alt_u8 full_tx_setup;
alt_u8 vga_ilace_fix;
alt_u8 reverse_lpf;
#ifdef ENABLE_AUDIO
alt_u8 audio_dw_sampl;
alt_u8 audio_swap_lr;
alt_u8 audio_gain;
#endif
color_setup_t col;
avinput_t link_av;
} __attribute__((packed)) avconfig_t;

View File

@ -119,6 +119,8 @@ int parse_control()
alt_u8* pmcfg_ptr[] = { &pt_only, &tc.pm_240p, &tc.pm_384p, &tc.pm_480i, &tc.pm_480p, &tc.pm_480p, &tc.pm_1080i };
alt_u8 valid_pm[] = { 0x1, 0x1f, 0x3, 0xf, 0x3, 0x3, 0x3 };
avinput_t next_input = (cm.avinput == AV3_YPBPR) ? AV1_RGBs : (cm.avinput+1);
if (remote_code)
printf("RCODE: 0x%.4lx, %d\n", remote_code, remote_rpt);
@ -163,7 +165,7 @@ int parse_control()
((fpga_status >> 16) & 0x3) ? '*' : ' ',
fpga_v_hz_x100/100,
fpga_v_hz_x100%100);*/
sniprintf(menu_row2, LCD_ROW_LEN+1, "%4lu%c%c %u", (((fpga_status & 0x7ff)+1)<<fpga_ilace)+fpga_ilace,
sniprintf(menu_row2, LCD_ROW_LEN+1, "%4lu%c%c %lu", (((fpga_status & 0x7ff)+1)<<fpga_ilace)+fpga_ilace,
fpga_ilace ? 'i' : 'p',
((fpga_status >> 16) & 0x3) ? '*' : ' ',
IORD_ALTERA_AVALON_PIO_DATA(PIO_8_BASE));
@ -239,6 +241,10 @@ int parse_control()
lcd_write_status();
menu_active = 0;
break;
case RC_RIGHT:
if (!menu_active)
man_target_input = next_input;
break;
default: break;
}
@ -246,7 +252,7 @@ int parse_control()
Button_Check:
if (btn_code & PB0_BIT)
man_target_input = (cm.avinput == AV3_YPBPR) ? AV1_RGBs : (cm.avinput+1);
man_target_input = next_input;
if (btn_code & PB1_BIT)
tc.sl_mode = tc.sl_mode < SL_MODE_MAX ? tc.sl_mode + 1 : 0;

View File

@ -26,7 +26,7 @@
#include "tvp7002.h"
#include "av_controller.h"
#include "lcd.h"
#include "ci_crc.h"
#include "utils.h"
#include "altera_avalon_pio_regs.h"
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
@ -48,19 +48,19 @@ static int check_fw_header(alt_u8 *databuf, fw_hdr *hdr)
hdr->version_suffix[7] = 0;
memcpy(&tmp, databuf+14, 4);
hdr->hdr_len = ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0(tmp);
hdr->hdr_len = bswap32(tmp);
memcpy(&tmp, databuf+18, 4);
hdr->data_len = ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0(tmp);
hdr->data_len = bswap32(tmp);
memcpy(&tmp, databuf+22, 4);
hdr->data_crc = ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0(tmp);
hdr->data_crc = bswap32(tmp);
// Always at bytes [508-511]
memcpy(&tmp, databuf+508, 4);
hdr->hdr_crc = ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0(tmp);
hdr->hdr_crc = bswap32(tmp);
if (hdr->hdr_len < 26 || hdr->hdr_len > 508)
return FW_HDR_ERROR;
crcval = crcCI(databuf, hdr->hdr_len, 1);
crcval = crc32(databuf, hdr->hdr_len, 1);
if (crcval != hdr->hdr_crc)
return FW_HDR_CRC_ERROR;
@ -81,7 +81,7 @@ static int check_fw_image(alt_u32 offset, alt_u32 size, alt_u32 golden_crc, alt_
if (retval != SD_OK)
return retval;
crcval = crcCI(tmpbuf, bytes_to_read, (i==0));
crcval = crc32(tmpbuf, bytes_to_read, (i==0));
}
if (crcval != golden_crc)
@ -90,15 +90,6 @@ static int check_fw_image(alt_u32 offset, alt_u32 size, alt_u32 golden_crc, alt_
return 0;
}
#ifdef DEBUG
int fw_update()
{
sniprintf(menu_row2, LCD_ROW_LEN+1, "Unavailable");
lcd_write_menu();
usleep(1000000);
return -1;
}
#else
int fw_update()
{
int retval, i;
@ -163,24 +154,9 @@ update_init:
strncpy(menu_row2, "please wait...", LCD_ROW_LEN+1);
lcd_write_menu();
for (i=0; i<fw_header.data_len; i=i+SD_BLK_SIZE) {
bytes_to_rw = ((fw_header.data_len-i < SD_BLK_SIZE) ? (fw_header.data_len-i) : SD_BLK_SIZE);
retval = SD_Read(&sdcard_dev, databuf, (512+i)/SD_BLK_SIZE, 0, bytes_to_rw);
if (retval != 0) {
retval = -retval; //flag any SD errors critical to trigger update retry
goto failure;
}
retval = write_flash_page(databuf, ((bytes_to_rw < PAGESIZE) ? bytes_to_rw : PAGESIZE), (i/PAGESIZE));
if (retval != 0)
goto failure;
//TODO: support multiple page sizes
if (bytes_to_rw > PAGESIZE) {
retval = write_flash_page(databuf+PAGESIZE, (bytes_to_rw-PAGESIZE), (i/PAGESIZE)+1);
if (retval != 0)
goto failure;
}
}
retval = copy_sd_to_flash(512/SD_BLK_SIZE, 0, fw_header.data_len, databuf);
if (retval != 0)
goto failure;
strncpy(menu_row1, "Verifying flash", LCD_ROW_LEN+1);
strncpy(menu_row2, "please wait...", LCD_ROW_LEN+1);
@ -249,4 +225,3 @@ failure:
return -1;
}
#endif

View File

@ -24,7 +24,7 @@
#include "sysconfig.h"
#define FW_VER_MAJOR 0
#define FW_VER_MINOR 81
#define FW_VER_MINOR 82
#ifdef ENABLE_AUDIO
#define FW_SUFFIX1 "a"

View File

@ -42,6 +42,8 @@ extern alt_u16 tc_h_samplerate, tc_h_synclen, tc_h_bporch, tc_h_active, tc_v_syn
extern alt_u32 remote_code;
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
extern alt_u8 vm_sel, profile_sel_menu, lt_sel, def_input, profile_link, lcd_bl_timeout;
extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
extern char target_profile_name[PROFILE_NAME_LEN+1];
alt_u8 menu_active;
@ -50,12 +52,13 @@ static const char *video_lpf_desc[] = { LNG("Auto","オート"), LNG("Off","オ
static const char *ypbpr_cs_desc[] = { "Rec. 601", "Rec. 709" };
static const char *s480p_mode_desc[] = { LNG("Auto","オート"), "DTV 480p", "VESA 640x480@60" };
static const char *sync_lpf_desc[] = { LNG("2.5MHz (max)","2.5MHz (サイダイ)"), LNG("10MHz (med)","10MHz (チュウイ)"), LNG("33MHz (min)","33MHz (サイショウ)"), LNG("Off","オフ") };
static const char *l3_mode_desc[] = { LNG("Generic 16:9","ジェネリック 16:9"), LNG("Generic 4:3","ジェネリック 4:3"), LNG("320x240 optim.","320x240 サイテキカ."), LNG("256x240 optim.","256x240 サイテキカ.") };
static const char *l2l4l5_mode_desc[] = { LNG("Generic 4:3","ジェネリック 4:3"), LNG("320x240 optim.","320x240 サイテキカ."), LNG("256x240 optim.","256x240 サイテキカ.") };
static const char *l3_mode_desc[] = { LNG("Generic 16:9","ジェネリック 16:9"), LNG("Generic 4:3","ジェネリック 4:3"), LNG("512x240 optim.","512x240 サイテキカ."), LNG("320x240 optim.","320x240 サイテキカ."), LNG("256x240 optim.","256x240 サイテキカ.") };
static const char *l2l4l5_mode_desc[] = { LNG("Generic 4:3","ジェネリック 4:3"), LNG("512x240 optim.","512x240 サイテキカ."), LNG("320x240 optim.","320x240 サイテキカ."), LNG("256x240 optim.","256x240 サイテキカ.") };
static const char *l5_fmt_desc[] = { "1920x1080", "1600x1200", "1920x1200" };
static const char *pm_240p_desc[] = { LNG("Passthru","パススルー"), "Line2x", "Line3x", "Line4x", "Line5x" };
static const char *pm_480i_desc[] = { LNG("Passthru","パススルー"), "Line2x (bob)", "Line3x (laced)", "Line4x (bob)" };
static const char *pm_384p_480p_desc[] = { LNG("Passthru","パススルー"), "Line2x" };
static const char *pm_384p_desc[] = { LNG("Passthru","パススルー"), "Line2x", "Line2x 240x360", "Line3x 240x360" };
static const char *pm_480p_desc[] = { LNG("Passthru","パススルー"), "Line2x" };
static const char *pm_1080i_desc[] = { LNG("Passthru","パススルー"), "Line2x (bob)" };
static const char *ar_256col_desc[] = { "4:3", "8:7" };
static const char *tx_mode_desc[] = { "HDMI", "DVI" };
@ -66,6 +69,8 @@ static const char *sl_id_desc[] = { LNG("Top","ウエ"), LNG("Bottom","シタ")
static const char *audio_dw_sampl_desc[] = { LNG("Off (fs = 96kHz)","オフ (fs = 96kHz)"), "2x (fs = 48kHz)" };
static const char *lt_desc[] = { "Top-left", "Center", "Bottom-right" };
static const char *lcd_bl_timeout_desc[] = { "Off", "3s", "10s", "30s" };
static const char *rgsb_ypbpr_desc[] = { "RGsB", "YPbPr" };
static const char *auto_input_desc[] = { "Off", "Current input", "All inputs" };
static void sampler_phase_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%d deg","%d ド"), (v*1125)/100); }
static void sync_vth_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d mV", (v*1127)/100); }
@ -80,10 +85,11 @@ static void lt_disp(alt_u8 v) { strncpy(menu_row2, lt_desc[v], LCD_ROW_LEN+1); }
static void aud_db_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d dB", ((alt_8)v-AUDIO_GAIN_0DB)); }
static void vm_display_name (alt_u8 v) { strncpy(menu_row2, video_modes[v].name, LCD_ROW_LEN+1); }
static void link_av_desc (avinput_t v) { strncpy(menu_row2, v == AV_LAST ? "No link" : avinput_str[v], LCD_ROW_LEN+1); }
static void profile_disp(alt_u8 v) { read_userdata(v, 1); sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (target_profile_name[0] == 0) ? "<empty>" : target_profile_name); }
//static void coarse_gain_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%u.%u", ((v*10)+50)/100, (((v*10)+50)%100)/10); }
static const arg_info_t vm_arg_info = {&vm_sel, VIDEO_MODES_CNT-1, vm_display_name};
static const arg_info_t profile_arg_info = {&profile_sel_menu, MAX_PROFILE, value_disp};
static const arg_info_t profile_arg_info = {&profile_sel_menu, MAX_PROFILE, profile_disp};
static const arg_info_t lt_arg_info = {&lt_sel, (sizeof(lt_desc)/sizeof(char*))-1, lt_disp};
@ -129,9 +135,9 @@ MENU(menu_sync, P99_PROTECT({ \
MENU(menu_output, P99_PROTECT({ \
{ LNG("240p/288p proc","240p/288pショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_240p, OPT_WRAP, SETTING_ITEM(pm_240p_desc) } } },
{ LNG("384p proc","384pショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_384p, OPT_WRAP, SETTING_ITEM(pm_384p_480p_desc) } } },
{ LNG("384p proc","384pショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_384p, OPT_WRAP, SETTING_ITEM(pm_384p_desc) } } },
{ LNG("480i/576i proc","480i/576iショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_480i, OPT_WRAP, SETTING_ITEM(pm_480i_desc) } } },
{ LNG("480p/576p proc","480p/576pショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_480p, OPT_WRAP, SETTING_ITEM(pm_384p_480p_desc) } } },
{ LNG("480p/576p proc","480p/576pショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_480p, OPT_WRAP, SETTING_ITEM(pm_480p_desc) } } },
{ LNG("960i/1080i proc","960i/1080iショリ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.pm_1080i, OPT_WRAP, SETTING_ITEM(pm_1080i_desc) } } },
{ LNG("Line2x mode","Line2xモード"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.l2_mode, OPT_WRAP, SETTING_ITEM(l2l4l5_mode_desc) } } },
{ LNG("Line3x mode","Line3xモード"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.l3_mode, OPT_WRAP, SETTING_ITEM(l3_mode_desc) } } },
@ -180,8 +186,15 @@ MENU(menu_settings, P99_PROTECT({ \
{ LNG("Link prof->input","Link prof->input"), OPT_AVCONFIG_NUMVALUE, { .num = { &tc.link_av, OPT_WRAP, AV1_RGBs, AV_LAST, link_av_desc } } },
{ LNG("Link input->prof","Link input->prof"), OPT_AVCONFIG_SELECTION, { .sel = { &profile_link, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
{ "Autodetect input", OPT_AVCONFIG_SELECTION, { .sel = { &auto_input, OPT_WRAP, SETTING_ITEM(auto_input_desc) } } },
{ "Auto AV1 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av1_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
{ "Auto AV2 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av2_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
{ "Auto AV3 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av3_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
{ "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } },
#ifndef DEBUG
{ "<Import sett. >", OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
#endif
}))

View File

@ -30,10 +30,12 @@
#define printf(...)
#else
#include <stdio.h>
#include "utils.h"
#define OS_PRINTF printf
#define ErrorF printf
// use reduced printf
//#define printf alt_printf
#define printf dd_printf
#endif
#define WAITLOOP_SLEEP_US 10000

View File

@ -18,11 +18,15 @@
//
#include <string.h>
#include <unistd.h>
#include "userdata.h"
#include "flash.h"
#include "sdcard.h"
#include "firmware.h"
#include "lcd.h"
#include "controls.h"
#include "av_controller.h"
#include "altera_avalon_pio_regs.h"
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
extern avmode_t cm;
@ -34,6 +38,11 @@ extern alt_u8 input_profiles[AV_LAST];
extern alt_u8 profile_sel;
extern alt_u8 def_input, profile_link;
extern alt_u8 lcd_bl_timeout;
extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
extern SD_DEV sdcard_dev;
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
char target_profile_name[PROFILE_NAME_LEN+1];
int write_userdata(alt_u8 entry)
{
@ -62,6 +71,10 @@ int write_userdata(alt_u8 entry)
((ude_initcfg*)databuf)->def_input = def_input;
((ude_initcfg*)databuf)->profile_link = profile_link;
((ude_initcfg*)databuf)->lcd_bl_timeout = lcd_bl_timeout;
((ude_initcfg*)databuf)->auto_input = auto_input;
((ude_initcfg*)databuf)->auto_av1_ypbpr = auto_av1_ypbpr;
((ude_initcfg*)databuf)->auto_av2_ypbpr = auto_av2_ypbpr;
((ude_initcfg*)databuf)->auto_av3_ypbpr = auto_av3_ypbpr;
memcpy(((ude_initcfg*)databuf)->keys, rc_keymap, sizeof(rc_keymap));
retval = write_flash_page(databuf, sizeof(ude_initcfg), (USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE);
if (retval != 0)
@ -74,6 +87,11 @@ int write_userdata(alt_u8 entry)
((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t);
((ude_profile*)databuf)->vm_data_len = vm_to_write;
if (target_profile_name[0] == 0)
sniprintf(target_profile_name, PROFILE_NAME_LEN+1, "<used>");
strncpy(((ude_profile*)databuf)->name, target_profile_name, PROFILE_NAME_LEN+1);
pageoffset = offsetof(ude_profile, avc);
// assume that sizeof(avconfig_t) << PAGESIZE
@ -87,15 +105,8 @@ int write_userdata(alt_u8 entry)
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE));
// then write the rest
pageno = 1;
while (vm_to_write > 0) {
bytes_to_w = (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write;
memcpy(databuf, (char*)video_modes+srcoffset, bytes_to_w);
write_flash_page(databuf, bytes_to_w, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
srcoffset += bytes_to_w;
vm_to_write -= bytes_to_w;
++pageno;
}
if (vm_to_write > 0)
write_flash((alt_u8*)video_modes+srcoffset, vm_to_write, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + 1);
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+VIDEO_MODES_SIZE);
break;
@ -106,7 +117,7 @@ int write_userdata(alt_u8 entry)
return 0;
}
int read_userdata(alt_u8 entry)
int read_userdata(alt_u8 entry, int dry_run)
{
int retval, i;
alt_u8 databuf[PAGESIZE];
@ -114,6 +125,8 @@ int read_userdata(alt_u8 entry)
alt_u16 pageoffset, dstoffset;
alt_u8 pageno;
target_profile_name[0] = 0;
if (entry > MAX_USERDATA_ENTRY) {
printf("invalid entry\n");
return -1;
@ -138,6 +151,9 @@ int read_userdata(alt_u8 entry)
switch (((ude_hdr*)databuf)->type) {
case UDE_INITCFG:
if (((ude_initcfg*)databuf)->data_len == sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)) {
if (dry_run)
return 0;
for (i = 0; i < sizeof(input_profiles)/sizeof(*input_profiles); ++i)
if (((ude_initcfg*)databuf)->last_profile[i] <= MAX_PROFILE)
input_profiles[i] = ((ude_initcfg*)databuf)->last_profile[i];
@ -146,6 +162,10 @@ int read_userdata(alt_u8 entry)
target_input = def_input;
else if (((ude_initcfg*)databuf)->last_input < AV_LAST)
target_input = ((ude_initcfg*)databuf)->last_input;
auto_input = ((ude_initcfg*)databuf)->auto_input;
auto_av1_ypbpr = ((ude_initcfg*)databuf)->auto_av1_ypbpr;
auto_av2_ypbpr = ((ude_initcfg*)databuf)->auto_av2_ypbpr;
auto_av3_ypbpr = ((ude_initcfg*)databuf)->auto_av3_ypbpr;
profile_link = ((ude_initcfg*)databuf)->profile_link;
profile_sel = input_profiles[AV_TESTPAT]; // Global profile
lcd_bl_timeout = ((ude_initcfg*)databuf)->lcd_bl_timeout;
@ -155,6 +175,10 @@ int read_userdata(alt_u8 entry)
break;
case UDE_PROFILE:
if ((((ude_profile*)databuf)->avc_data_len == sizeof(avconfig_t)) && (((ude_profile*)databuf)->vm_data_len == VIDEO_MODES_SIZE)) {
strncpy(target_profile_name, ((ude_profile*)databuf)->name, PROFILE_NAME_LEN+1);
if (dry_run)
return 0;
vm_to_read = ((ude_profile*)databuf)->vm_data_len;
pageno = 0;
@ -192,3 +216,92 @@ int read_userdata(alt_u8 entry)
return 0;
}
int import_userdata()
{
int retval;
int n, entries_imported=0;
char *errmsg;
alt_u8 databuf[SD_BLK_SIZE];
ude_hdr header;
alt_u32 btn_vec;
retval = check_sdcard(databuf);
SPI_CS_High();
if (retval != 0)
goto failure;
strncpy(menu_row1, "Import? 1=Y, 2=N", LCD_ROW_LEN+1);
*menu_row2 = '\0';
lcd_write_menu();
while (1) {
btn_vec = IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & RC_MASK;
if (btn_vec == rc_keymap[RC_BTN1]) {
break;
} else if (btn_vec == rc_keymap[RC_BTN2]) {
retval = UDATA_IMPT_CANCELLED;
goto failure;
}
usleep(WAITLOOP_SLEEP_US);
}
strncpy(menu_row1, "Loading settings", LCD_ROW_LEN+1);
strncpy(menu_row2, "please wait...", LCD_ROW_LEN+1);
lcd_write_menu();
// Import the userdata
for (n=0; n<=MAX_USERDATA_ENTRY; ++n) {
retval = SD_Read(&sdcard_dev, &header, (512+n*SECTORSIZE)/SD_BLK_SIZE, 0, sizeof(header));
if (retval != 0) {
printf("Failed to read SD card\n");
retval = -retval;
goto failure;
}
if (strncmp(header.userdata_key, "USRDATA", 8)) {
printf("Not an userdata entry at 0x%x\n", 512+n*SECTORSIZE);
continue;
}
if ((header.version_major != FW_VER_MAJOR) || (header.version_minor != FW_VER_MINOR)) {
printf("Data version %u.%u does not match fw\n", header.version_major, header.version_minor);
continue;
}
if (header.type > UDE_PROFILE) {
printf("Unknown userdata entry type %u\n", header.type);
continue;
}
// Just blindly write the entry to flash
retval = copy_sd_to_flash((512+n*SECTORSIZE)/SD_BLK_SIZE, (n*PAGES_PER_SECTOR)+(USERDATA_OFFSET/PAGESIZE),
(header.type == UDE_PROFILE) ? sizeof(ude_profile) : sizeof(ude_initcfg), databuf);
if (retval != 0) {
printf("Copy from SD to flash failed (error %d)\n", retval);
goto failure;
}
entries_imported++;
}
SPI_CS_High();
read_userdata(INIT_CONFIG_SLOT, 0);
profile_sel = input_profiles[target_input];
read_userdata(profile_sel, 0);
sniprintf(menu_row1, LCD_ROW_LEN+1, "%d entries", entries_imported);
strncpy(menu_row2, "imported", LCD_ROW_LEN+1);
lcd_write_menu();
usleep(1000000);
return 0;
failure:
SPI_CS_High();
return -1;
}

View File

@ -28,9 +28,13 @@
#include "video_modes.h"
#include "flash.h"
#define MAX_PROFILE 9
#define PROFILE_NAME_LEN 12
#define MAX_PROFILE (MAX_USERDATA_ENTRY-1)
#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY
#define UDATA_IMPT_CANCELLED 104
typedef enum {
UDE_INITCFG = 0,
UDE_PROFILE,
@ -51,11 +55,16 @@ typedef struct {
avinput_t last_input;
avinput_t def_input;
alt_u8 lcd_bl_timeout;
alt_u8 auto_input;
alt_u8 auto_av1_ypbpr;
alt_u8 auto_av2_ypbpr;
alt_u8 auto_av3_ypbpr;
alt_u16 keys[REMOTE_MAX_KEYS];
} __attribute__((packed, __may_alias__)) ude_initcfg;
typedef struct {
ude_hdr hdr;
char name[PROFILE_NAME_LEN+1];
alt_u16 avc_data_len;
alt_u16 vm_data_len;
avconfig_t avc;
@ -63,6 +72,7 @@ typedef struct {
} __attribute__((packed, __may_alias__)) ude_profile;
int write_userdata(alt_u8 entry);
int read_userdata(alt_u8 entry);
int read_userdata(alt_u8 entry, int dry_run);
int import_userdata();
#endif

View File

@ -0,0 +1,93 @@
//
// Copyright (C) 2018 Markus Hiienkari <mhiienka@niksula.hut.fi>
//
// This file is part of Open Source Scan Converter project.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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 <stdio.h>
#include <stdarg.h>
#include "sys/alt_stdio.h"
#include "utils.h"
#include "system.h"
#include "sysconfig.h"
#include "io.h"
alt_u32 bswap32(alt_u32 w)
{
return (((w << 24) & 0xff000000) |
((w << 8) & 0x00ff0000) |
((w >> 8) & 0x0000ff00) |
((w >> 24) & 0x000000ff));
}
unsigned long crc32(unsigned char *input_data, unsigned long input_data_length, int do_initialize)
{
unsigned long index;
/* copy of the data buffer pointer so that it can advance by different widths */
void * input_data_copy = (void *)input_data;
/* The custom instruction CRC will initialize to the inital remainder value */
if (do_initialize)
IOWR_32DIRECT(HW_CRC32_0_BASE, 0x0, 0x0);
/* Write 32 bit data to the custom instruction. If the buffer does not end
* on a 32 bit boundary then the remaining data will be sent to the custom
* instruction in the 'if' statement below.
*/
for(index = 0; index < (input_data_length & 0xFFFFFFFC); index+=4)
{
IOWR_32DIRECT(HW_CRC32_0_BASE, 0x4, *(unsigned long *)input_data_copy);
input_data_copy += 4; /* void pointer, must move by 4 for each word */
}
/* Write the remainder of the buffer if it does not end on a word boundary */
if((input_data_length & 0x3) == 0x3) /* 3 bytes left */
{
IOWR_16DIRECT(HW_CRC32_0_BASE, 0x4, *(unsigned short *)input_data_copy);
input_data_copy += 2;
IOWR_8DIRECT(HW_CRC32_0_BASE, 0x4, *(unsigned char *)input_data_copy);
}
else if((input_data_length & 0x3) == 0x2) /* 2 bytes left */
{
IOWR_16DIRECT(HW_CRC32_0_BASE, 0x4, *(unsigned short *)input_data_copy);
}
else if((input_data_length & 0x3) == 0x1) /* 1 byte left */
{
IOWR_8DIRECT(HW_CRC32_0_BASE, 0x4, *(unsigned char *)input_data_copy);
}
/* There are 4 registers in the CRC custom instruction. Since
* this example uses CRC-32 only the first register must be read
* in order to receive the full result.
*/
return IORD_32DIRECT(HW_CRC32_0_BASE, 0x10);
}
/* printf for direct driver interface */
int dd_printf(const char *__restrict fmt, ...) {
int ret;
va_list ap;
char buf[PRINTF_BUFSIZE];
va_start(ap, fmt);
ret = vsnprintf(buf, PRINTF_BUFSIZE, fmt, ap);
va_end(ap);
if (ret > 0)
alt_putstr(buf);
return 0;
}

View File

@ -0,0 +1,35 @@
//
// Copyright (C) 2018 Markus Hiienkari <mhiienka@niksula.hut.fi>
//
// This file is part of Open Source Scan Converter project.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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/>.
//
#ifndef UTILS_H_
#define UTILS_H_
#include <alt_types.h>
#define PRINTF_BUFSIZE 512
unsigned char bitswap8(unsigned char v);
alt_u32 bswap32(alt_u32 w);
unsigned long crc32(unsigned char *input_data, unsigned long input_data_length, int do_initialize);
int dd_printf(const char *__restrict fmt, ...);
#endif

View File

@ -0,0 +1,91 @@
// Copyright 2017 ETH Zurich and University of Bologna.
// Copyright and related rights are licensed under the Solderpad Hardware
// License, Version 0.51 (the “License”); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
// or agreed to in writing, software, hardware and materials distributed under
// this 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.
/**
* @file
* @brief Register mapping for PULPino peripherals.
*
* Contains event register mappings for the PULPino SOC as
* well as some general definitions for the overall system.
*
* @author Florian Zaruba
*
* @version 1.0
*
* @date 2/10/2015
*
*/
#ifndef PULPINO_H
#define PULPINO_H
#define PULPINO_BASE_ADDR 0x10000000
/** SOC PERIPHERALS */
#define SOC_PERIPHERALS_BASE_ADDR ( PULPINO_BASE_ADDR + 0xA100000 )
#define UART_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x0000 )
#define GPIO_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x1000 )
#define SPI_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x2000 )
#define TIMER_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x3000 )
#define EVENT_UNIT_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x4000 )
#define I2C_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x5000 )
#define FLL_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x6000 )
#define SOC_CTRL_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x7000 )
/** STDOUT */
#define STDOUT_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x10000 )
#define FPUTCHAR_BASE_ADDR ( STDOUT_BASE_ADDR + 0x1000 )
#define FILE_CMD_BASE_ADDR ( STDOUT_BASE_ADDR + 0x2000 )
#define STREAM_BASE_ADDR ( STDOUT_BASE_ADDR + 0x3000 )
/** Instruction RAM */
#define INSTR_RAM_BASE_ADDR ( 0x00 )
#define INSTR_RAM_START_ADDR ( 0x80 )
/** ROM */
#define ROM_BASE_ADDR ( 0x10000 )
/** Data RAM */
#define DATA_RAM_BASE_ADDR ( 0x00100000 )
/** Registers and pointers */
#define REGP(x) ((volatile unsigned int*)(x))
#define REG(x) (*((volatile unsigned int*)(x)))
#define REGP_8(x) (((volatile uint8_t*)(x)))
/* pointer to mem of apb pulpino unit - PointerSocCtrl */
#define __PSC__(a) *(unsigned volatile int*) (SOC_CTRL_BASE_ADDR + a)
/** Peripheral Clock gating */
#define CGREG __PSC__(0x04)
/** Clock gate SPI */
#define CGSPI 0x00
/** Clock gate UART */
#define CGUART 0x01
/** Clock gate GPIO */
#define CGGPIO 0x02
/** Clock gate SPI Master */
#define CGGSPIM 0x03
/** Clock gate Timer */
#define CGTIM 0x04
/** Clock gate Event Unit */
#define CGEVENT 0x05
/** Clock gate I2C */
#define CGGI2C 0x06
/** Clock gate FLL */
#define CGFLL 0x07
/** Boot address register */
#define BOOTREG __PSC__(0x08)
#define RES_STATUS __PSC__(0x14)
#endif

View File

@ -49,7 +49,11 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
switch (video_modes[i].group) {
case GROUP_NONE:
case GROUP_240P:
break;
case GROUP_384P:
//fixed Line2x/3x mode for 240x360p
valid_lm[2] = MODE_L2_240x360;
valid_lm[3] = MODE_L3_240x360;
break;
case GROUP_480I:
//fixed Line3x/4x mode for 480i
@ -107,7 +111,7 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
cm.fpga_vmultmode = FPGA_V_MULTMODE_2X;
// Use native 2x sampling with low-res modes when possible to minimize jitter and generate min. 25MHz input pclk for FPGA PLL
if ((!cm.cc.vga_ilace_fix) && (video_modes[i].h_total < 1400) && ((video_modes[i].group == GROUP_240P) || (video_modes[i].group == GROUP_384P) || (video_modes[i].group == GROUP_480I))) {
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED_1X;
cm.sample_mult = 2;
} else {
cm.fpga_hmultmode = FPGA_H_MULTMODE_FULLWIDTH;
@ -122,16 +126,26 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
}
}
break;
case MODE_L2_256_COL:
case MODE_L2_512_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_2X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 2;
break;
case MODE_L2_256_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_2X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED_1X;
cm.sample_mult = 6;
break;
case MODE_L2_320_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_2X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED_1X;
cm.sample_mult = 4;
break;
case MODE_L2_240x360:
cm.fpga_vmultmode = FPGA_V_MULTMODE_2X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 5;
break;
case MODE_L3_GEN_16_9:
cm.fpga_vmultmode = FPGA_V_MULTMODE_3X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_FULLWIDTH;
@ -147,6 +161,11 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
cm.fpga_vmultmode = FPGA_V_MULTMODE_3X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_ASPECTFIX;
break;
case MODE_L3_512_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_3X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 2;
break;
case MODE_L3_320_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_3X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
@ -157,6 +176,12 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 5;
break;
case MODE_L3_240x360:
cm.fpga_vmultmode = FPGA_V_MULTMODE_3X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 7;
cm.hsync_cut = 13;
break;
case MODE_L4_GEN_4_3:
cm.fpga_vmultmode = FPGA_V_MULTMODE_4X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_FULLWIDTH;
@ -168,6 +193,11 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
cm.tx_pixelrep = TX_PIXELREP_2X;
}
break;
case MODE_L4_512_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_4X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 2;
break;
case MODE_L4_320_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_4X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
@ -183,6 +213,12 @@ alt_8 get_mode_id(alt_u32 totlines, alt_u8 progressive, alt_u32 hz, video_type t
cm.fpga_hmultmode = FPGA_H_MULTMODE_FULLWIDTH;
cm.hsync_cut = 120;
break;
case MODE_L5_512_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_5X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;
cm.sample_mult = 3;
cm.hsync_cut = 40;
break;
case MODE_L5_320_COL:
cm.fpga_vmultmode = FPGA_V_MULTMODE_5X;
cm.fpga_hmultmode = FPGA_H_MULTMODE_OPTIMIZED;

View File

@ -1,5 +1,5 @@
//
// Copyright (C) 2015-2017 Markus Hiienkari <mhiienka@niksula.hut.fi>
// Copyright (C) 2015-2018 Markus Hiienkari <mhiienka@niksula.hut.fi>
//
// This file is part of Open Source Scan Converter project.
//
@ -24,7 +24,7 @@
#include "sysconfig.h"
#define H_TOTAL_MIN 300
#define H_TOTAL_MAX 2300
#define H_TOTAL_MAX 2800
#define H_SYNCLEN_MIN 10
#define H_SYNCLEN_MAX 255
#define H_BPORCH_MIN 1
@ -35,7 +35,7 @@
#define V_SYNCLEN_MAX 7
#define V_BPORCH_MIN 1
#define V_BPORCH_MAX 63
#define V_ACTIVE_MIN 200
#define V_ACTIVE_MIN 160
#define V_ACTIVE_MAX 1200
typedef enum {
@ -68,18 +68,24 @@ typedef enum {
//at least one of the flags below must be set for each mode
MODE_PT = (1<<2),
MODE_L2 = (1<<3),
MODE_L2_320_COL = (1<<4),
MODE_L2_256_COL = (1<<5),
MODE_L3_GEN_16_9 = (1<<6),
MODE_L3_GEN_4_3 = (1<<7),
MODE_L3_320_COL = (1<<8),
MODE_L3_256_COL = (1<<9),
MODE_L4_GEN_4_3 = (1<<10),
MODE_L4_320_COL = (1<<11),
MODE_L4_256_COL = (1<<12),
MODE_L5_GEN_4_3 = (1<<13),
MODE_L5_320_COL = (1<<14),
MODE_L5_256_COL = (1<<15),
MODE_L2_512_COL = (1<<4),
MODE_L2_320_COL = (1<<5),
MODE_L2_256_COL = (1<<6),
MODE_L2_240x360 = (1<<7),
MODE_L3_GEN_16_9 = (1<<8),
MODE_L3_GEN_4_3 = (1<<9),
MODE_L3_512_COL = (1<<10),
MODE_L3_320_COL = (1<<11),
MODE_L3_256_COL = (1<<12),
MODE_L3_240x360 = (1<<13),
MODE_L4_GEN_4_3 = (1<<14),
MODE_L4_512_COL = (1<<15),
MODE_L4_320_COL = (1<<16),
MODE_L4_256_COL = (1<<17),
MODE_L5_GEN_4_3 = (1<<18),
MODE_L5_512_COL = (1<<19),
MODE_L5_320_COL = (1<<20),
MODE_L5_256_COL = (1<<21),
} mode_flags;
typedef struct {
@ -100,19 +106,24 @@ typedef struct {
#define VIDEO_MODES_DEF { \
/* 240p modes */ \
{ "1536x240", 1536, 240, 2046, 262, 234, 15, 150, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L5_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "1600x240", 1600, 240, 2046, 262, 202, 15, 150, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L5_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "1280x240", 1280, 240, 1560, 262, 170, 15, 72, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L3_GEN_16_9 | MODE_L4_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "960x240", 960, 240, 1170, 262, 128, 15, 54, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L3_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "512x240", 512, 240, 682, 262, 77, 14, 50, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L2_512_COL | MODE_L3_512_COL | MODE_L4_512_COL | MODE_L5_512_COL) }, \
{ "320x240", 320, 240, 426, 262, 49, 14, 31, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L2_320_COL | MODE_L3_320_COL | MODE_L4_320_COL | MODE_L5_320_COL) }, \
{ "256x240", 256, 240, 341, 262, 39, 14, 25, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L2_256_COL | MODE_L3_256_COL | MODE_L4_256_COL | MODE_L5_256_COL) }, \
{ "240p", 720, 240, 858, 262, 57, 15, 62, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_PT | MODE_L2 | MODE_PLLDIVBY2) }, \
/* 288p modes */ \
{ "1536x240L", 1536, 240, 2046, 312, 234, 41, 150, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L5_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "1600x240L", 1600, 240, 2046, 312, 202, 41, 150, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L5_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "1280x288", 1280, 288, 1560, 312, 170, 15, 72, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L3_GEN_16_9 | MODE_L4_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "960x288", 960, 288, 1170, 312, 128, 15, 54, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L3_GEN_4_3 | MODE_PLLDIVBY2) }, \
{ "512x240LB", 512, 240, 682, 312, 77, 41, 50, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L2_512_COL | MODE_L3_512_COL | MODE_L4_512_COL | MODE_L5_512_COL) }, \
{ "320x240LB", 320, 240, 426, 312, 49, 41, 31, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L2_320_COL | MODE_L3_320_COL | MODE_L4_320_COL | MODE_L5_320_COL) }, \
{ "256x240LB", 256, 240, 341, 312, 39, 41, 25, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_L2_256_COL | MODE_L3_256_COL | MODE_L4_256_COL | MODE_L5_256_COL) }, \
{ "288p", 720, 288, 864, 312, 69, 19, 63, 3, (VIDEO_SDTV | VIDEO_PC), GROUP_240P, (MODE_PT | MODE_L2 | MODE_PLLDIVBY2) }, \
/* 360p: GBI */ \
{ "480x360", 480, 360, 600, 375, 63, 10, 38, 3, (VIDEO_EDTV), GROUP_384P, (MODE_PT | MODE_L2 | MODE_PLLDIVBY2) }, \
{ "240x360", 256, 360, 300, 375, 24, 10, 18, 3, (VIDEO_EDTV), GROUP_384P, (MODE_L2_240x360 | MODE_L3_240x360) }, \
/* 384p: Sega Model 2 */ \
{ "384p", 496, 384, 640, 423, 50, 29, 62, 3, (VIDEO_EDTV), GROUP_384P, (MODE_PT | MODE_L2 | MODE_PLLDIVBY2) }, \
/* 640x400, VGA Mode 13h */ \

View File

@ -51,18 +51,18 @@ extern "C"
((void *)(((alt_u8*)BASE) + (OFFSET)))
#define IORD_32DIRECT(BASE, OFFSET) \
__builtin_ldwio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)))
(*(volatile alt_u32*)(__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))))
#define IORD_16DIRECT(BASE, OFFSET) \
__builtin_ldhuio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)))
(*(volatile alt_u16*)(__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))))
#define IORD_8DIRECT(BASE, OFFSET) \
__builtin_ldbuio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)))
(*(volatile alt_u8*)(__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))))
#define IOWR_32DIRECT(BASE, OFFSET, DATA) \
__builtin_stwio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)), (DATA))
(*(volatile alt_u32*)(__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))) = (DATA))
#define IOWR_16DIRECT(BASE, OFFSET, DATA) \
__builtin_sthio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)), (DATA))
(*(volatile alt_u16*)(__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))) = (DATA))
#define IOWR_8DIRECT(BASE, OFFSET, DATA) \
__builtin_stbio (__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET)), (DATA))
(*(volatile alt_u8*)(__IO_CALC_ADDRESS_DYNAMIC ((BASE), (OFFSET))) = (DATA))
/* Native bus access functions */
@ -70,9 +70,9 @@ extern "C"
((void *)(((alt_u8*)BASE) + ((REGNUM) * (SYSTEM_BUS_WIDTH/8))))
#define IORD(BASE, REGNUM) \
__builtin_ldwio (__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM)))
(*(volatile alt_u32*)(__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM))))
#define IOWR(BASE, REGNUM, DATA) \
__builtin_stwio (__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM)), (DATA))
(*(volatile alt_u32*)(__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM))) = (DATA))
#ifdef __cplusplus
}

View File

@ -57,77 +57,13 @@ unsigned int alt_busy_sleep (unsigned int us)
* skipped to speed up simulation.
*/
#ifndef ALT_SIM_OPTIMIZE
int i;
int big_loops;
alt_u32 cycles_per_loop;
if (!strcmp(NIOS2_CPU_IMPLEMENTATION,"tiny"))
{
cycles_per_loop = 9;
}
else
{
cycles_per_loop = 3;
}
unsigned long i, loops;
big_loops = us / (INT_MAX/
(ALT_CPU_FREQ/(cycles_per_loop * 1000000)));
// 1 loop >= 7 cyc
loops = ((ALT_CPU_FREQ/1000000)*us)/7;
if (big_loops)
{
for(i=0;i<big_loops;i++)
{
/*
* Do NOT Try to single step the asm statement below
* (single step will never return)
* Step out of this function or set a breakpoint after the asm statements
*/
__asm__ volatile (
"\n0:"
"\n\taddi %0,%0, -1"
"\n\tbne %0,zero,0b"
"\n1:"
"\n\t.pushsection .debug_alt_sim_info"
"\n\t.int 4, 0, 0b, 1b"
"\n\t.popsection"
:: "r" (INT_MAX));
us -= (INT_MAX/(ALT_CPU_FREQ/
(cycles_per_loop * 1000000)));
}
/*
* Do NOT Try to single step the asm statement below
* (single step will never return)
* Step out of this function or set a breakpoint after the asm statements
*/
__asm__ volatile (
"\n0:"
"\n\taddi %0,%0, -1"
"\n\tbne %0,zero,0b"
"\n1:"
"\n\t.pushsection .debug_alt_sim_info"
"\n\t.int 4, 0, 0b, 1b"
"\n\t.popsection"
:: "r" (us*(ALT_CPU_FREQ/(cycles_per_loop * 1000000))));
}
else
{
/*
* Do NOT Try to single step the asm statement below
* (single step will never return)
* Step out of this function or set a breakpoint after the asm statements
*/
__asm__ volatile (
"\n0:"
"\n\taddi %0,%0, -1"
"\n\tbgt %0,zero,0b"
"\n1:"
"\n\t.pushsection .debug_alt_sim_info"
"\n\t.int 4, 0, 0b, 1b"
"\n\t.popsection"
:: "r" (us*(ALT_CPU_FREQ/(cycles_per_loop * 1000000))));
}
for (i=7; i<loops; i++)
asm volatile ("nop");
#endif /* #ifndef ALT_SIM_OPTIMIZE */
return 0;
}

View File

@ -39,7 +39,7 @@
#include "sys/alt_dev.h"
#include "sys/alt_sys_init.h"
#include "sys/alt_irq.h"
//#include "sys/alt_irq.h"
#include "sys/alt_dev.h"
#include "os/alt_hooks.h"
@ -51,6 +51,8 @@
#include "sys/alt_log_printf.h"
extern void alt_irq_init ( const void* base );
extern void _do_ctors(void);
extern void _do_dtors(void);

View File

@ -1,38 +1,80 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#ifndef _CRCCI_H_
#define _CRCCI_H_
unsigned long crcCI(unsigned char * input_data, unsigned long input_data_length, int do_initialize);
#endif //_CRCCI_H_
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2015 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#ifdef ALT_SEMIHOSTING
#include "sys/alt_stdio.h"
#include "unistd.h"
#ifndef ALT_PUTBUF_SIZE
#define ALT_PUTBUF_SIZE 64
#endif
// Buffer for the printed chars
static char buf[ALT_PUTBUF_SIZE] ={0};
// index into the buffer
static unsigned int fill_index;
/*
* ALT putcharbuf funtion
* Used only for semihosting.
* Not thread safe!
* This fucntion buffers up chars to be printed until either alt_putbufflush()
* is called or the buffer is full.
* It is called by alt_printf when semihosting is turned on
* Its purpose is to minimize the number of Break 1 issuesd by the semihosting
* libraries.
*/
int
alt_putcharbuf(int c)
{
buf[fill_index++] = (char)(c & 0xff);
if(fill_index >= ALT_PUTBUF_SIZE)
alt_putbufflush();
return c;
}
/*
* ALT putbufflush
* used only for smehosting
* Not thread safe!
* Dumps all the chars in the buffer to STDOUT
*/
int
alt_putbufflush()
{
int results;
results = write(STDOUT_FILENO,buf,fill_index);
fill_index = 0;
return results;
}
#endif

View File

@ -112,10 +112,10 @@ SOPC_FILE := ../../sys.sopcinfo
#-------------------------------------------------------------------------------
# Archiver command. Creates library files.
AR = nios2-elf-ar
AR = riscv32-unknown-elf-ar
# Assembler command. Note that CC is used for .S files.
AS = nios2-elf-gcc
AS = riscv32-unknown-elf-gcc
# Custom flags only passed to the archiver. This content of this variable is
# directly passed to the archiver rather than the more standard "ARFLAGS". The
@ -139,10 +139,10 @@ BSP_CFLAGS_OPTIMIZATION = -Os
BSP_CFLAGS_WARNINGS = -Wall
# C compiler command.
CC = nios2-elf-gcc -xc
CC = riscv32-unknown-elf-gcc -xc
# C++ compiler command.
CXX = nios2-elf-gcc -xc++
CXX = riscv32-unknown-elf-gcc -xc++
# Command used to remove files during 'clean' target.
RM = rm -f
@ -222,7 +222,6 @@ altera_avalon_timer_driver_SRCS_ROOT := drivers
# altera_avalon_timer_driver sources
altera_avalon_timer_driver_C_LIB_SRCS := \
$(altera_avalon_timer_driver_SRCS_ROOT)/src/altera_avalon_timer_sc.c \
$(altera_avalon_timer_driver_SRCS_ROOT)/src/altera_avalon_timer_ts.c \
$(altera_avalon_timer_driver_SRCS_ROOT)/src/altera_avalon_timer_vars.c
@ -238,96 +237,29 @@ altera_nios2_gen2_hal_driver_SRCS_ROOT := HAL
# altera_nios2_gen2_hal_driver sources
altera_nios2_gen2_hal_driver_C_LIB_SRCS := \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/altera_nios2_gen2_irq.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_usleep.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_printf.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_putchar.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_putstr.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_busy_sleep.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_irq_vars.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_icache_flush.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_icache_flush_all.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_dcache_flush.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_dcache_flush_all.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_dcache_flush_no_writeback.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_ecc_fatal_exception.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_instruction_exception_entry.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_irq_register.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_iic.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_remap_cached.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_remap_uncached.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_uncached_free.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_uncached_malloc.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_do_ctors.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_do_dtors.c \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_gmon.c
altera_nios2_gen2_hal_driver_ASM_LIB_SRCS := \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_ecc_fatal_entry.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_exception_entry.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_exception_trap.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_exception_muldiv.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_irq_entry.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_software_exception.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_mcount.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_log_macro.S \
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/crt0.S
$(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_do_dtors.c
# hal sources root
hal_SRCS_ROOT := HAL
# hal sources
hal_C_LIB_SRCS := \
$(hal_SRCS_ROOT)/src/alt_alarm_start.c \
$(hal_SRCS_ROOT)/src/alt_close.c \
$(hal_SRCS_ROOT)/src/alt_dev.c \
$(hal_SRCS_ROOT)/src/alt_dev_llist_insert.c \
$(hal_SRCS_ROOT)/src/alt_dma_rxchan_open.c \
$(hal_SRCS_ROOT)/src/alt_dma_txchan_open.c \
$(hal_SRCS_ROOT)/src/alt_environ.c \
$(hal_SRCS_ROOT)/src/alt_env_lock.c \
$(hal_SRCS_ROOT)/src/alt_errno.c \
$(hal_SRCS_ROOT)/src/alt_execve.c \
$(hal_SRCS_ROOT)/src/alt_exit.c \
$(hal_SRCS_ROOT)/src/alt_fcntl.c \
$(hal_SRCS_ROOT)/src/alt_fd_lock.c \
$(hal_SRCS_ROOT)/src/alt_fd_unlock.c \
$(hal_SRCS_ROOT)/src/alt_find_dev.c \
$(hal_SRCS_ROOT)/src/alt_find_file.c \
$(hal_SRCS_ROOT)/src/alt_flash_dev.c \
$(hal_SRCS_ROOT)/src/alt_fork.c \
$(hal_SRCS_ROOT)/src/alt_fs_reg.c \
$(hal_SRCS_ROOT)/src/alt_fstat.c \
$(hal_SRCS_ROOT)/src/alt_get_fd.c \
$(hal_SRCS_ROOT)/src/alt_getchar.c \
$(hal_SRCS_ROOT)/src/alt_getpid.c \
$(hal_SRCS_ROOT)/src/alt_gettod.c \
$(hal_SRCS_ROOT)/src/alt_iic_isr_register.c \
$(hal_SRCS_ROOT)/src/alt_instruction_exception_register.c \
$(hal_SRCS_ROOT)/src/alt_ioctl.c \
$(hal_SRCS_ROOT)/src/alt_io_redirect.c \
$(hal_SRCS_ROOT)/src/alt_irq_handler.c \
$(hal_SRCS_ROOT)/src/alt_isatty.c \
$(hal_SRCS_ROOT)/src/alt_kill.c \
$(hal_SRCS_ROOT)/src/alt_link.c \
$(hal_SRCS_ROOT)/src/alt_load.c \
$(hal_SRCS_ROOT)/src/alt_log_printf.c \
$(hal_SRCS_ROOT)/src/alt_lseek.c \
$(hal_SRCS_ROOT)/src/alt_main.c \
$(hal_SRCS_ROOT)/src/alt_malloc_lock.c \
$(hal_SRCS_ROOT)/src/alt_open.c \
$(hal_SRCS_ROOT)/src/alt_printf.c \
$(hal_SRCS_ROOT)/src/alt_putchar.c \
$(hal_SRCS_ROOT)/src/alt_putcharbuf.c \
$(hal_SRCS_ROOT)/src/alt_putstr.c \
$(hal_SRCS_ROOT)/src/alt_read.c \
$(hal_SRCS_ROOT)/src/alt_release_fd.c \
$(hal_SRCS_ROOT)/src/alt_rename.c \
$(hal_SRCS_ROOT)/src/alt_sbrk.c \
$(hal_SRCS_ROOT)/src/alt_settod.c \
$(hal_SRCS_ROOT)/src/alt_stat.c \
$(hal_SRCS_ROOT)/src/alt_tick.c \
$(hal_SRCS_ROOT)/src/alt_times.c \
$(hal_SRCS_ROOT)/src/alt_unlink.c \
$(hal_SRCS_ROOT)/src/alt_wait.c \
$(hal_SRCS_ROOT)/src/alt_write.c
$(hal_SRCS_ROOT)/src/alt_main.c
# i2c_opencores_driver sources root
i2c_opencores_driver_SRCS_ROOT := drivers
@ -339,11 +271,6 @@ i2c_opencores_driver_C_LIB_SRCS := \
# nios2_hw_crc32_driver sources root
nios2_hw_crc32_driver_SRCS_ROOT := drivers
# nios2_hw_crc32_driver sources
nios2_hw_crc32_driver_C_LIB_SRCS := \
$(nios2_hw_crc32_driver_SRCS_ROOT)/src/ci_crc.c \
$(nios2_hw_crc32_driver_SRCS_ROOT)/src/crc.c
# Assemble all component C source files
COMPONENT_C_LIB_SRCS += \
@ -444,8 +371,7 @@ GENERATED_H_FILES := $(ABS_BSP_ROOT)/system.h
GENERATED_LINKER_SCRIPT := $(ABS_BSP_ROOT)/linker.x
GENERATED_FILES += $(GENERATED_H_FILES) \
$(GENERATED_LINKER_SCRIPT)
GENERATED_FILES += $(GENERATED_H_FILES)
#------------------------------------------------------------------------------
@ -503,7 +429,7 @@ $(OBJS): $(wildcard $(FORCE_REBUILD_DEP)) $(wildcard $(FORCE_REBUILD_ALL_DEP))
.PHONY: all
all: build_pre_process
all: Makefile $(GENERATED_FILES) $(BSP_LIB) $(NEWLIB_DIR)
all: Makefile bsp_timestamp $(GENERATED_FILES) $(BSP_LIB) $(NEWLIB_DIR)
all: build_post_process
@ -516,7 +442,6 @@ ifneq ($(wildcard $(NEWLIB_DIR)),)
endif
@$(ECHO) [BSP clean complete]
#------------------------------------------------------------------------------
# BUILD PRE/POST PROCESS
#------------------------------------------------------------------------------
@ -543,37 +468,39 @@ ifneq ($(wildcard $(SETTINGS_FILE)),$(SETTINGS_FILE))
$(warning Warning: BSP Settings File $(SETTINGS_FILE) could not be found.)
endif
Makefile: $(wildcard $(SETTINGS_FILE))
@$(ECHO) Makefile not up to date.
@$(ECHO) $(SETTINGS_FILE) has been modified since the BSP Makefile was generated.
@$(ECHO)
@$(ECHO) Generate the BSP to update the Makefile, and then build again.
@$(ECHO)
@$(ECHO) To generate from Eclipse:
@$(ECHO) " 1. Right-click the BSP project."
@$(ECHO) " 2. In the Nios II Menu, click Generate BSP."
@$(ECHO)
@$(ECHO) To generate from the command line:
@$(ECHO) " nios2-bsp-generate-files --settings=<settings file> --bsp-dir=<target bsp files directory>"
@$(ECHO)
@exit 1
#Makefile: $(wildcard $(SETTINGS_FILE))
# @$(ECHO) Makefile not up to date.
# @$(ECHO) $(SETTINGS_FILE) has been modified since the BSP Makefile was generated.
# @$(ECHO)
# @$(ECHO) Update system.h etc. BSP files manually, then run \"touch public.mk Makefile\" on BSP dir.
# @$(ECHO)
# @exit 1
ifneq ($(wildcard $(SOPC_FILE)),$(SOPC_FILE))
$(warning Warning: SOPC File $(SOPC_FILE) could not be found.)
endif
public.mk: $(wildcard $(SOPC_FILE))
@$(ECHO) Makefile not up to date.
@$(ECHO) $(SOPC_FILE) has been modified since the BSP was generated.
#public.mk: $(wildcard $(SOPC_FILE))
# @$(ECHO) Makefile not up to date.
# @$(ECHO) $(SOPC_FILE) has been modified since the BSP was generated.
# @$(ECHO)
# @$(ECHO) Update system.h etc. BSP files manually, then run \"touch public.mk Makefile\" on BSP dir.
# @$(ECHO)
# @exit 1
bsp_timestamp: $(wildcard $(SOPC_FILE))
@$(ECHO) BSP not up to date.
@$(ECHO) $(SOPC_FILE) has been modified since the BSP was last updated.
@$(ECHO)
@$(ECHO) Generate the BSP to update the Makefile, and then build again.
@$(ECHO) "If you have not customized QSYS platform:"
@$(ECHO) " 1. Open sys.qsys in Quartus Platform Designer, generate platform"
@$(ECHO) " files (Generate -> Generate HDL, Generate) and run compilation"
@$(ECHO) " 2. Run \"touch bsp_timestamp\" in BSP dir"
@$(ECHO)
@$(ECHO) To generate from Eclipse:
@$(ECHO) " 1. Right-click the BSP project."
@$(ECHO) " 2. In the Nios II Menu, click Generate BSP."
@$(ECHO)
@$(ECHO) To generate from the command line:
@$(ECHO) " nios2-bsp-generate-files --settings=<settings file> --bsp-dir=<target bsp files directory>"
@$(ECHO) "If you have customized and regenerated QSYS platform:"
@$(ECHO) " 1. Update system.h, public.mk, Makefile etc. BSP files manually"
@$(ECHO) " to match your updates"
@$(ECHO) " 2. Run \"touch bsp_timestamp\" in BSP dir"
@$(ECHO)
@exit 1

View File

@ -49,7 +49,7 @@
*/
#include "system.h"
#include "sys/alt_irq.h"
//#include "sys/alt_irq.h"
#include "sys/alt_sys_init.h"
#include <stddef.h>
@ -58,7 +58,7 @@
* Device headers
*/
#include "altera_nios2_gen2_irq.h"
//#include "altera_nios2_gen2_irq.h"
#include "altera_avalon_jtag_uart.h"
#include "altera_avalon_timer.h"
#include "altera_epcq_controller_mod.h"
@ -68,7 +68,7 @@
* Allocate the device storage
*/
ALTERA_NIOS2_GEN2_IRQ_INSTANCE ( NIOS2_QSYS_0, nios2_qsys_0);
//ALTERA_NIOS2_GEN2_IRQ_INSTANCE ( NIOS2_QSYS_0, nios2_qsys_0);
ALTERA_AVALON_JTAG_UART_INSTANCE ( JTAG_UART_0, jtag_uart_0);
ALTERA_AVALON_TIMER_INSTANCE ( TIMER_0, timer_0);
ALTERA_EPCQ_CONTROLLER_MOD_AVL_MEM_AVL_CSR_INSTANCE ( EPCQ_CONTROLLER_0, EPCQ_CONTROLLER_0_AVL_MEM, EPCQ_CONTROLLER_0_AVL_CSR, epcq_controller_0);
@ -85,8 +85,8 @@ I2C_OPENCORES_INSTANCE ( I2C_OPENCORES_1, i2c_opencores_1);
void alt_irq_init ( const void* base )
{
ALTERA_NIOS2_GEN2_IRQ_INIT ( NIOS2_QSYS_0, nios2_qsys_0);
alt_irq_cpu_enable_interrupts();
/*ALTERA_NIOS2_GEN2_IRQ_INIT ( NIOS2_QSYS_0, nios2_qsys_0);
alt_irq_cpu_enable_interrupts();*/
}
/*

View File

@ -1,166 +0,0 @@
#ifndef __ALTERA_UP_SD_CARD_AVALON_INTERFACE_H__
#define __ALTERA_UP_SD_CARD_AVALON_INTERFACE_H__
#include <stddef.h>
#include <alt_types.h>
#include <sys/alt_dev.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define SD_RAW_IFACE
/*
* Device structure definition. Each instance of the driver uses one
* of these structures to hold its associated state.
*/
typedef struct alt_up_sd_card_dev {
/// @brief character mode device structure
/// @sa Developing Device Drivers for the HAL in Nios II Software Developer's Handbook
alt_dev dev;
/// @brief the base address of the device
unsigned int base;
} alt_up_sd_card_dev;
#ifndef bool
typedef enum e_bool { false = 0, true = 1 } bool;
#endif
//////////////////////////////////////////////////////////////////////////
// HAL system functions
alt_up_sd_card_dev* alt_up_sd_card_open_dev(const char *name);
/* Open an SD Card Interface if it is connected to the system. */
bool alt_up_sd_card_is_Present(void);
/* Check if there is an SD Card insterted into the SD Card socket.
*/
#ifndef SD_RAW_IFACE
bool alt_up_sd_card_is_FAT16(void);
/* This function reads the SD card data in an effort to determine if the card is formated as a FAT16
* volume. Please note that FAT12 has a similar format, but will not be supported by this driver.
*/
short int alt_up_sd_card_fopen(char *name, bool create);
/* This function reads the SD card data in an effort to determine if the card is formated as a FAT16
* volume. Please note that FAT12 has a similar format, but will not be supported by this driver.
*
* Inputs:
* name - a file name including a directory, relative to the root directory
* create - a flag set to true to create a file if it does not already exist
* Output:
* An index to the file record assigned to the specified file. -1 is returned if the file could not be opened.
*/
short int alt_up_sd_card_find_first(char *directory_to_search_through, char *file_name);
/* This function sets up a search algorithm to go through a given directory looking for files.
* If the search directory is valid, then the function searches for the first file it finds.
* Inputs:
* directory_to_search_through - name of the directory to search through
* file_name - an array to store a name of the file found. Must be 13 bytes long (12 bytes for file name and 1 byte of NULL termination).
* Outputs:
* 0 - success
* 1 - invalid directory
* 2 - No card or incorrect card format.
*
* To specify a directory give the name in a format consistent with the following regular expression:
* [{[valid_chars]+}/]*.
*
* In other words, give a path name starting at the root directory, where each directory name is followed by a '/'.
* Then, append a '.' to the directory name. Examples:
* "." - look through the root directory
* "first/." - look through a directory named "first" that is located in the root directory.
* "first/sub/." - look through a directory named "sub", that is located within the subdirectory named "first". "first" is located in the root directory.
* Invalid examples include:
* "/.", "/////." - this is not the root directory.
* "/first/." - the first character may not be a '/'.
*/
short int alt_up_sd_card_find_next(char *file_name);
/* This function searches for the next file in a given directory, as specified by the find_first function.
* Inputs:
* file_name - an array to store a name of the file found. Must be 13 bytes long (12 bytes for file name and 1 byte of NULL termination).
* Outputs:
* -1 - end of directory.
* 0 - success
* 2 - No card or incorrect card format.
* 4 - find_first has not been called successfully.
*/
void alt_up_sd_card_set_attributes(short int file_handle, short int attributes);
/* Set file attributes as needed.
*/
short int alt_up_sd_card_get_attributes(short int file_handle);
/* Return file attributes, or -1 if the file_handle is invalid.
*/
short int alt_up_sd_card_read(short int file_handle);
/* Read a single character from the given file. Return -1 if at the end of a file. Any other negative number
* means that the file could not be read. A number between 0 and 255 is an ASCII character read from the SD Card. */
bool alt_up_sd_card_write(short int file_handle, char byte_of_data);
/* Write a single character to a given file. Return true if successful, and false otherwise. */
bool alt_up_sd_card_fclose(short int file_handle);
// This function closes an opened file and saves data to SD Card if necessary.
#else
bool Write_Sector_Data(int sector_index, int partition_offset);
bool Save_Modified_Sector();
bool Read_Sector_Data(int sector_index, int partition_offset);
#endif //SD_RAW_IFACE
//////////////////////////////////////////////////////////////////////////
// file-like operation functions
//////////////////////////////////////////////////////////////////////////
// direct operation functions
/*
* Macros used by alt_sys_init
*/
#define ALTERA_UP_SD_CARD_AVALON_INTERFACE_MOD_INSTANCE(name, device) \
static alt_up_sd_card_dev device = \
{ \
{ \
ALT_LLIST_ENTRY, \
name##_NAME, \
NULL , /* open */ \
NULL , /* close */ \
NULL, /* read */ \
NULL, /* write */ \
NULL , /* lseek */ \
NULL , /* fstat */ \
NULL , /* ioctl */ \
}, \
name##_BASE, \
}
#define ALTERA_UP_SD_CARD_AVALON_INTERFACE_MOD_INIT(name, device) \
{ \
alt_dev_reg(&device.dev); \
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ALTERA_UP_SD_CARD_AVALON_INTERFACE_H__ */

View File

@ -0,0 +1,193 @@
#ifndef __ALT_AVALON_TIMER_H__
#define __ALT_AVALON_TIMER_H__
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#include <string.h>
#include "alt_types.h"
#include "sys/alt_dev.h"
#include "sys/alt_warning.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define __ALT_COUNTER_SIZE(name) name##_COUNTER_SIZE
#define _ALT_COUNTER_SIZE(name) __ALT_COUNTER_SIZE(name)
#define ALT_SYS_CLK_COUNTER_SIZE _ALT_COUNTER_SIZE(ALT_SYS_CLK)
#define ALT_TIMESTAMP_COUNTER_SIZE _ALT_COUNTER_SIZE(ALT_TIMESTAMP_CLK)
#if (ALT_SYS_CLK_COUNTER_SIZE == 64)
#define alt_sysclk_type alt_u64
#else
#define alt_sysclk_type alt_u32
#endif
#if (ALT_TIMESTAMP_COUNTER_SIZE == 64)
#define alt_timestamp_type alt_u64
#else
#define alt_timestamp_type alt_u32
#endif
/*
* The function alt_avalon_timer_sc_init() is the initialisation function for
* the system clock. It registers the timers interrupt handler, and then calls
* the system clock regestration function, alt_sysclk_init().
*/
extern void alt_avalon_timer_sc_init (void* base, alt_u32 irq_controller_id,
alt_u32 irq, alt_u32 freq);
/*
* Variables used to store the timestamp parameters, when the device is to be
* accessed using the high resolution timestamp driver.
*/
extern void* altera_avalon_timer_ts_base;
extern alt_u32 altera_avalon_timer_ts_freq;
/*
* ALTERA_AVALON_TIMER_INSTANCE is the macro used by alt_sys_init() to
* allocate any per device memory that may be required. In this case no
* allocation is necessary.
*/
#define ALTERA_AVALON_TIMER_INSTANCE(name, dev) extern int alt_no_storage
/*
* Macro used to calculate the timer interrupt frequency. Although this is
* somewhat fearsome, when compiled with -O2 it will be resolved at compile
* time to a constant value.
*/
#define ALTERA_AVALON_TIMER_FREQ(freq, period, units) \
strcmp (units, "us") ? \
(strcmp (units, "ms") ? \
(strcmp (units, "s") ? \
((freq + (period - 1))/period) \
: 1) \
: (1000 + (period - 1))/period) \
: ((1000000 + (period - 1))/period)
/*
* Construct macros which contain the base address of the system clock and the
* timestamp device. These are used below to determine which driver to use for
* a given timer.
*/
#define __ALT_CLK_BASE(name) name##_BASE
#define _ALT_CLK_BASE(name) __ALT_CLK_BASE(name)
#define ALT_SYS_CLK_BASE _ALT_CLK_BASE(ALT_SYS_CLK)
#define ALT_TIMESTAMP_CLK_BASE _ALT_CLK_BASE(ALT_TIMESTAMP_CLK)
/*
* If there is no system clock, then the above macro will result in
* ALT_SYS_CLK_BASE being set to none_BASE. We therefore need to provide an
* invalid value for this, so that no timer is wrongly identified as the system
* clock.
*/
#define none_BASE 0xffffffff
/*
* ALTERA_AVALON_TIMER_INIT is the macro used by alt_sys_init() to provide
* the run time initialisation of the device. In this case this translates to
* a call to alt_avalon_timer_sc_init() if the device is the system clock, i.e.
* if it has the name "sysclk".
*
* If the device is not the system clock, then it is used to provide the
* timestamp facility.
*
* To ensure as much as possible is evaluated at compile time, rather than
* compare the name of the device to "/dev/sysclk" using strcmp(), the base
* address of the device is compared to SYSCLK_BASE to determine whether it's
* the system clock. Since the base address of a device must be unique, these
* two aproaches are equivalent.
*
* This macro performs a sanity check to ensure that the interrupt has been
* connected for this device. If not, then an apropriate error message is
* generated at build time.
*/
#define ALTERA_AVALON_TIMER_INIT(name, dev) \
if (name##_BASE == ALT_SYS_CLK_BASE) \
{ \
if (name##_IRQ == ALT_IRQ_NOT_CONNECTED) \
{ \
ALT_LINK_ERROR ("Error: Interrupt not connected for " #dev ". " \
"The system clock driver requires an interrupt to be " \
"connected. Please select an IRQ for this device in " \
"SOPC builder."); \
} \
else \
{ \
alt_avalon_timer_sc_init((void*) name##_BASE, \
name##_IRQ_INTERRUPT_CONTROLLER_ID, \
name##_IRQ, \
ALTERA_AVALON_TIMER_FREQ(name##_FREQ, \
name##_PERIOD, \
name##_PERIOD_UNITS));\
} \
} \
else if (name##_BASE == ALT_TIMESTAMP_CLK_BASE) \
{ \
if (name##_SNAPSHOT) \
{ \
altera_avalon_timer_ts_base = (void*) name##_BASE; \
altera_avalon_timer_ts_freq = name##_FREQ; \
} \
else \
{ \
ALT_LINK_ERROR ("Error: Snapshot register not available for " \
#dev ". " \
"The timestamp driver requires the snapshot register " \
"to be readable. Please enable this register for this " \
"device in SOPC builder."); \
} \
}
/*
*
*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __ALT_AVALON_TIMER_H__ */

View File

@ -0,0 +1,202 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
******************************************************************************/
#ifndef __ALTERA_AVALON_TIMER_REGS_H__
#define __ALTERA_AVALON_TIMER_REGS_H__
#include <io.h>
/* STATUS register */
#define ALTERA_AVALON_TIMER_STATUS_REG 0
#define IOADDR_ALTERA_AVALON_TIMER_STATUS(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_STATUS_REG)
#define IORD_ALTERA_AVALON_TIMER_STATUS(base) \
IORD(base, ALTERA_AVALON_TIMER_STATUS_REG)
#define IOWR_ALTERA_AVALON_TIMER_STATUS(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_STATUS_REG, data)
#define ALTERA_AVALON_TIMER_STATUS_TO_MSK (0x1)
#define ALTERA_AVALON_TIMER_STATUS_TO_OFST (0)
#define ALTERA_AVALON_TIMER_STATUS_RUN_MSK (0x2)
#define ALTERA_AVALON_TIMER_STATUS_RUN_OFST (1)
/* CONTROL register */
#define ALTERA_AVALON_TIMER_CONTROL_REG 1
#define IOADDR_ALTERA_AVALON_TIMER_CONTROL(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_CONTROL_REG)
#define IORD_ALTERA_AVALON_TIMER_CONTROL(base) \
IORD(base, ALTERA_AVALON_TIMER_CONTROL_REG)
#define IOWR_ALTERA_AVALON_TIMER_CONTROL(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_CONTROL_REG, data)
#define ALTERA_AVALON_TIMER_CONTROL_ITO_MSK (0x1)
#define ALTERA_AVALON_TIMER_CONTROL_ITO_OFST (0)
#define ALTERA_AVALON_TIMER_CONTROL_CONT_MSK (0x2)
#define ALTERA_AVALON_TIMER_CONTROL_CONT_OFST (1)
#define ALTERA_AVALON_TIMER_CONTROL_START_MSK (0x4)
#define ALTERA_AVALON_TIMER_CONTROL_START_OFST (2)
#define ALTERA_AVALON_TIMER_CONTROL_STOP_MSK (0x8)
#define ALTERA_AVALON_TIMER_CONTROL_STOP_OFST (3)
/* Period and SnapShot Register for COUNTER_SIZE = 32 */
/*----------------------------------------------------*/
/* PERIODL register */
#define ALTERA_AVALON_TIMER_PERIODL_REG 2
#define IOADDR_ALTERA_AVALON_TIMER_PERIODL(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIODL_REG)
#define IORD_ALTERA_AVALON_TIMER_PERIODL(base) \
IORD(base, ALTERA_AVALON_TIMER_PERIODL_REG)
#define IOWR_ALTERA_AVALON_TIMER_PERIODL(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_PERIODL_REG, data)
#define ALTERA_AVALON_TIMER_PERIODL_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_PERIODL_OFST (0)
/* PERIODH register */
#define ALTERA_AVALON_TIMER_PERIODH_REG 3
#define IOADDR_ALTERA_AVALON_TIMER_PERIODH(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIODH_REG)
#define IORD_ALTERA_AVALON_TIMER_PERIODH(base) \
IORD(base, ALTERA_AVALON_TIMER_PERIODH_REG)
#define IOWR_ALTERA_AVALON_TIMER_PERIODH(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_PERIODH_REG, data)
#define ALTERA_AVALON_TIMER_PERIODH_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_PERIODH_OFST (0)
/* SNAPL register */
#define ALTERA_AVALON_TIMER_SNAPL_REG 4
#define IOADDR_ALTERA_AVALON_TIMER_SNAPL(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAPL_REG)
#define IORD_ALTERA_AVALON_TIMER_SNAPL(base) \
IORD(base, ALTERA_AVALON_TIMER_SNAPL_REG)
#define IOWR_ALTERA_AVALON_TIMER_SNAPL(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_SNAPL_REG, data)
#define ALTERA_AVALON_TIMER_SNAPL_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_SNAPL_OFST (0)
/* SNAPH register */
#define ALTERA_AVALON_TIMER_SNAPH_REG 5
#define IOADDR_ALTERA_AVALON_TIMER_SNAPH(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAPH_REG)
#define IORD_ALTERA_AVALON_TIMER_SNAPH(base) \
IORD(base, ALTERA_AVALON_TIMER_SNAPH_REG)
#define IOWR_ALTERA_AVALON_TIMER_SNAPH(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_SNAPH_REG, data)
#define ALTERA_AVALON_TIMER_SNAPH_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_SNAPH_OFST (0)
/* Period and SnapShot Register for COUNTER_SIZE = 64 */
/*----------------------------------------------------*/
/* PERIOD_0 register */
#define ALTERA_AVALON_TIMER_PERIOD_0_REG 2
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_0(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_0_REG)
#define IORD_ALTERA_AVALON_TIMER_PERIOD_0(base) \
IORD(base, ALTERA_AVALON_TIMER_PERIOD_0_REG)
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_0(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_0_REG, data)
#define ALTERA_AVALON_TIMER_PERIOD_0_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_PERIOD_0_OFST (0)
/* PERIOD_1 register */
#define ALTERA_AVALON_TIMER_PERIOD_1_REG 3
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_1(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_1_REG)
#define IORD_ALTERA_AVALON_TIMER_PERIOD_1(base) \
IORD(base, ALTERA_AVALON_TIMER_PERIOD_1_REG)
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_1(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_1_REG, data)
#define ALTERA_AVALON_TIMER_PERIOD_1_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_PERIOD_1_OFST (0)
/* PERIOD_2 register */
#define ALTERA_AVALON_TIMER_PERIOD_2_REG 4
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_2(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_2_REG)
#define IORD_ALTERA_AVALON_TIMER_PERIOD_2(base) \
IORD(base, ALTERA_AVALON_TIMER_PERIOD_2_REG)
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_2(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_2_REG, data)
#define ALTERA_AVALON_TIMER_PERIOD_2_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_PERIOD_2_OFST (0)
/* PERIOD_3 register */
#define ALTERA_AVALON_TIMER_PERIOD_3_REG 5
#define IOADDR_ALTERA_AVALON_TIMER_PERIOD_3(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_PERIOD_3_REG)
#define IORD_ALTERA_AVALON_TIMER_PERIOD_3(base) \
IORD(base, ALTERA_AVALON_TIMER_PERIOD_3_REG)
#define IOWR_ALTERA_AVALON_TIMER_PERIOD_3(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_PERIOD_3_REG, data)
#define ALTERA_AVALON_TIMER_PERIOD_3_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_PERIOD_3_OFST (0)
/* SNAP_0 register */
#define ALTERA_AVALON_TIMER_SNAP_0_REG 6
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_0(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_0_REG)
#define IORD_ALTERA_AVALON_TIMER_SNAP_0(base) \
IORD(base, ALTERA_AVALON_TIMER_SNAP_0_REG)
#define IOWR_ALTERA_AVALON_TIMER_SNAP_0(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_SNAP_0_REG, data)
#define ALTERA_AVALON_TIMER_SNAP_0_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_SNAP_0_OFST (0)
/* SNAP_1 register */
#define ALTERA_AVALON_TIMER_SNAP_1_REG 7
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_1(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_1_REG)
#define IORD_ALTERA_AVALON_TIMER_SNAP_1(base) \
IORD(base, ALTERA_AVALON_TIMER_SNAP_1_REG)
#define IOWR_ALTERA_AVALON_TIMER_SNAP_1(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_SNAP_1_REG, data)
#define ALTERA_AVALON_TIMER_SNAP_1_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_SNAP_1_OFST (0)
/* SNAP_2 register */
#define ALTERA_AVALON_TIMER_SNAP_2_REG 8
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_2(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_2_REG)
#define IORD_ALTERA_AVALON_TIMER_SNAP_2(base) \
IORD(base, ALTERA_AVALON_TIMER_SNAP_2_REG)
#define IOWR_ALTERA_AVALON_TIMER_SNAP_2(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_SNAP_2_REG, data)
#define ALTERA_AVALON_TIMER_SNAP_2_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_SNAP_2_OFST (0)
/* SNAP_3 register */
#define ALTERA_AVALON_TIMER_SNAP_3_REG 9
#define IOADDR_ALTERA_AVALON_TIMER_SNAP_3(base) \
__IO_CALC_ADDRESS_NATIVE(base, ALTERA_AVALON_TIMER_SNAP_3_REG)
#define IORD_ALTERA_AVALON_TIMER_SNAP_3(base) \
IORD(base, ALTERA_AVALON_TIMER_SNAP_3_REG)
#define IOWR_ALTERA_AVALON_TIMER_SNAP_3(base, data) \
IOWR(base, ALTERA_AVALON_TIMER_SNAP_3_REG, data)
#define ALTERA_AVALON_TIMER_SNAP_3_MSK (0xFFFF)
#define ALTERA_AVALON_TIMER_SNAP_3_OFST (0)
#endif /* __ALTERA_AVALON_TIMER_REGS_H__ */

View File

@ -1,109 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/**********************************************************************
*
* Filename: crc.h
*
* Description: A header file describing the various CRC standards.
*
* Notes:
*
*
* 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 _crc_h
#define _crc_h
#define FALSE 0
#define TRUE !FALSE
/*
* Select the CRC standard from the list that follows.
*/
#define CRC32
#if defined(CRC_CCITT)
typedef unsigned short crc;
#define CRC_NAME "CRC-CCITT"
#define POLYNOMIAL 0x1021
#define INITIAL_REMAINDER 0xFFFF
#define FINAL_XOR_VALUE 0x0000
#define REFLECT_DATA FALSE
#define REFLECT_REMAINDER FALSE
#define CHECK_VALUE 0x29B1
#elif defined(CRC16)
typedef unsigned short crc;
#define CRC_NAME "CRC-16"
#define POLYNOMIAL 0x8005
#define INITIAL_REMAINDER 0x0000
#define FINAL_XOR_VALUE 0x0000
#define REFLECT_DATA TRUE
#define REFLECT_REMAINDER TRUE
#define CHECK_VALUE 0xBB3D
#elif defined(CRC32)
typedef unsigned long crc;
#define CRC_NAME "CRC-32"
#define POLYNOMIAL 0x04C11DB7
#define INITIAL_REMAINDER 0xFFFFFFFF
#define FINAL_XOR_VALUE 0xFFFFFFFF
#define REFLECT_DATA TRUE
#define REFLECT_REMAINDER TRUE
#define CHECK_VALUE 0xCBF43926
#else
#error "One of CRC_CCITT, CRC16, or CRC32 must be #define'd."
#endif
void crcInit(void);
crc crcSlow(unsigned char const message[], int nBytes);
crc crcFast(unsigned char const message[], int nBytes);
#endif /* _crc_h */

View File

@ -35,7 +35,7 @@
#include <sys/stat.h>
#include "sys/alt_irq.h"
//#include "sys/alt_irq.h"
#include "sys/alt_alarm.h"
#include "sys/ioctl.h"
#include "alt_types.h"

View File

@ -35,7 +35,7 @@
#include <sys/stat.h>
#include "sys/alt_irq.h"
//#include "sys/alt_irq.h"
#include "sys/alt_alarm.h"
#include "sys/ioctl.h"
#include "alt_types.h"

View File

@ -35,7 +35,7 @@
#include <sys/stat.h>
#include "sys/alt_irq.h"
//#include "sys/alt_irq.h"
#include "sys/alt_alarm.h"
#include "sys/ioctl.h"
#include "alt_types.h"

View File

@ -0,0 +1,110 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#include <string.h>
#include "sys/alt_alarm.h"
#include "sys/alt_irq.h"
#include "altera_avalon_timer.h"
#include "altera_avalon_timer_regs.h"
#include "alt_types.h"
#include "sys/alt_log_printf.h"
/*
* alt_avalon_timer_sc_irq() is the interrupt handler used for the system
* clock. This is called periodically when a timer interrupt occurs. The
* function first clears the interrupt condition, and then calls the
* alt_tick() function to notify the system that a timer tick has occurred.
*
* alt_tick() increments the system tick count, and updates any registered
* alarms, see alt_tick.c for further details.
*/
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
static void alt_avalon_timer_sc_irq (void* base)
#else
static void alt_avalon_timer_sc_irq (void* base, alt_u32 id)
#endif
{
alt_irq_context cpu_sr;
/* clear the interrupt */
IOWR_ALTERA_AVALON_TIMER_STATUS (base, 0);
/*
* Dummy read to ensure IRQ is negated before the ISR returns.
* The control register is read because reading the status
* register has side-effects per the register map documentation.
*/
IORD_ALTERA_AVALON_TIMER_CONTROL (base);
/* ALT_LOG - see altera_hal/HAL/inc/sys/alt_log_printf.h */
ALT_LOG_SYS_CLK_HEARTBEAT();
/*
* Notify the system of a clock tick. disable interrupts
* during this time to safely support ISR preemption
*/
cpu_sr = alt_irq_disable_all();
alt_tick ();
alt_irq_enable_all(cpu_sr);
}
/*
* alt_avalon_timer_sc_init() is called to initialise the timer that will be
* used to provide the periodic system clock. This is called from the
* auto-generated alt_sys_init() function.
*/
void alt_avalon_timer_sc_init (void* base, alt_u32 irq_controller_id,
alt_u32 irq, alt_u32 freq)
{
/* set the system clock frequency */
alt_sysclk_init (freq);
/* set to free running mode */
IOWR_ALTERA_AVALON_TIMER_CONTROL (base,
ALTERA_AVALON_TIMER_CONTROL_ITO_MSK |
ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
ALTERA_AVALON_TIMER_CONTROL_START_MSK);
/* register the interrupt handler, and enable the interrupt */
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
alt_ic_isr_register(irq_controller_id, irq, alt_avalon_timer_sc_irq,
base, NULL);
#else
alt_irq_register (irq, base, alt_avalon_timer_sc_irq);
#endif
}

View File

@ -0,0 +1,143 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#include <string.h>
#include "system.h"
#include "sys/alt_timestamp.h"
#include "altera_avalon_timer.h"
#include "altera_avalon_timer_regs.h"
#include "alt_types.h"
/*
* These functions are only available if a timestamp device has been selected
* for this system.
*/
#if (ALT_TIMESTAMP_CLK_BASE != none_BASE)
/*
* The function alt_timestamp_start() can be called at application level to
* initialise the timestamp facility. In this case the period register is
* set to full scale, i.e. 0xffffffff, and then started running. Note that
* the period register may not be writable, depending on the hardware
* configuration, in which case this function does not reset the period.
*
* The timer is not run in continuous mode, so that the user can detect timer
* roll-over, i.e. alt_timestamp() returns 0.
*
* The return value of this function is 0 upon sucess and -1 if in timestamp
* device has not been registered.
*/
int alt_timestamp_start(void)
{
void* base = altera_avalon_timer_ts_base;
if (!altera_avalon_timer_ts_freq)
{
return -1;
}
else
{
if(ALT_TIMESTAMP_COUNTER_SIZE == 64) {
IOWR_ALTERA_AVALON_TIMER_CONTROL (base,ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
IOWR_ALTERA_AVALON_TIMER_PERIOD_0 (base, 0xFFFF);
IOWR_ALTERA_AVALON_TIMER_PERIOD_1 (base, 0xFFFF);;
IOWR_ALTERA_AVALON_TIMER_PERIOD_2 (base, 0xFFFF);
IOWR_ALTERA_AVALON_TIMER_PERIOD_3 (base, 0xFFFF);
IOWR_ALTERA_AVALON_TIMER_CONTROL (base, ALTERA_AVALON_TIMER_CONTROL_START_MSK);
} else {
IOWR_ALTERA_AVALON_TIMER_CONTROL (base,ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
IOWR_ALTERA_AVALON_TIMER_PERIODL (base, 0xFFFF);
IOWR_ALTERA_AVALON_TIMER_PERIODH (base, 0xFFFF);
IOWR_ALTERA_AVALON_TIMER_CONTROL (base, ALTERA_AVALON_TIMER_CONTROL_START_MSK);
}
}
return 0;
}
/*
* alt_timestamp() returns the current timestamp count. In the event that
* the timer has run full period, or there is no timestamp available, this
* function return -1.
*
* The returned timestamp counts up from the last time the period register
* was reset.
*/
alt_timestamp_type alt_timestamp(void)
{
void* base = altera_avalon_timer_ts_base;
if (!altera_avalon_timer_ts_freq)
{
#if (ALT_TIMESTAMP_COUNTER_SIZE == 64)
return 0xFFFFFFFFFFFFFFFFULL;
#else
return 0xFFFFFFFF;
#endif
}
else
{
#if (ALT_TIMESTAMP_COUNTER_SIZE == 64)
IOWR_ALTERA_AVALON_TIMER_SNAP_0 (base, 0);
alt_timestamp_type snap_0 = IORD_ALTERA_AVALON_TIMER_SNAP_0(base) & ALTERA_AVALON_TIMER_SNAP_0_MSK;
alt_timestamp_type snap_1 = IORD_ALTERA_AVALON_TIMER_SNAP_1(base) & ALTERA_AVALON_TIMER_SNAP_1_MSK;
alt_timestamp_type snap_2 = IORD_ALTERA_AVALON_TIMER_SNAP_2(base) & ALTERA_AVALON_TIMER_SNAP_2_MSK;
alt_timestamp_type snap_3 = IORD_ALTERA_AVALON_TIMER_SNAP_3(base) & ALTERA_AVALON_TIMER_SNAP_3_MSK;
return (0xFFFFFFFFFFFFFFFFULL - ( (snap_3 << 48) | (snap_2 << 32) | (snap_1 << 16) | (snap_0) ));
#else
IOWR_ALTERA_AVALON_TIMER_SNAPL (base, 0);
alt_timestamp_type lower = IORD_ALTERA_AVALON_TIMER_SNAPL(base) & ALTERA_AVALON_TIMER_SNAPL_MSK;
alt_timestamp_type upper = IORD_ALTERA_AVALON_TIMER_SNAPH(base) & ALTERA_AVALON_TIMER_SNAPH_MSK;
return (0xFFFFFFFF - ((upper << 16) | lower));
#endif
}
}
/*
* Return the number of timestamp ticks per second. This will be 0 if no
* timestamp device has been registered.
*/
alt_u32 alt_timestamp_freq(void)
{
return altera_avalon_timer_ts_freq;
}
#endif /* timestamp available */

View File

@ -1,38 +1,45 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#ifndef _CRCCI_H_
#define _CRCCI_H_
unsigned long crcCI(unsigned char * input_data, unsigned long input_data_length, int do_initialize);
#endif //_CRCCI_H_
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
#include <string.h>
#include "altera_avalon_timer.h"
#include "alt_types.h"
/*
* Variables used to store the timestamp parameters. These are initialised
* from alt_sys_init() using the ALTERA_AVALON_TIMER_INIT macro
* defined in altera_avalon_timer.h.
*/
void* altera_avalon_timer_ts_base = (void*) 0;
alt_u32 altera_avalon_timer_ts_freq = 0;

View File

@ -43,6 +43,7 @@
ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments(alt_epcq_controller_dev *flash_info,alt_u32 offset, alt_u32 length);
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info);
ALT_INLINE unsigned char static bitswap8(unsigned char v);
/*
* Public API
@ -334,6 +335,10 @@ int alt_epcq_controller_write_block
/* prepare the word to be written */
memcpy((((void*)&word_to_write)) + padding, ((void*)data) + buffer_offset, bytes_to_copy);
// Bit-reverse bytes for flash
for (int i=0; i<bytes_to_copy; i++)
*((unsigned char*)&word_to_write+i) = bitswap8(*((unsigned char*)&word_to_write+i));
/* update offset and length variables */
buffer_offset += bytes_to_copy;
remaining_length -= bytes_to_copy;
@ -508,6 +513,10 @@ int alt_epcq_controller_read
if(0 == ret_code)
{
memcpy(dest_addr, (alt_u8*)epcq_flash_info->data_base + offset, length);
// Bit-reverse bytes read from flash
for (int i=0; i<length; i++)
*((unsigned char*)dest_addr+i) = bitswap8(*((unsigned char*)dest_addr+i));
}
return ret_code;
@ -794,4 +803,10 @@ alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_
return 0;
}
ALT_INLINE unsigned char static bitswap8(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}

View File

@ -1,97 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/**********************************************************************
*
* Filename: ci_crc.c
*
* Description: Custom instruction implementations of the CRC.
*
* Notes: A macro is defined that is used to access the CRC custom
* instruction.
*********************************************************************/
#include "system.h"
/*The n values and their corresponding operation are as follow:
* n = 0, Initialize the custom instruction to the initial remainder value
* n = 1, Write 8 bits data to custom instruction
* n = 2, Write 16 bits data to custom instruction
* n = 3, Write 32 bits data to custom instruction
* n = 4, Read 32 bits data from the custom instruction
* n = 5, Read 64 bits data from the custom instruction
* n = 6, Read 96 bits data from the custom instruction
* n = 7, Read 128 bits data from the custom instruction*/
#define CRC_CI_MACRO(n, A) __builtin_custom_ini(ALT_CI_NIOS2_HW_CRC32_0_N + (n & 0x7), (A))
unsigned long crcCI(unsigned char * input_data, unsigned long input_data_length, int do_initialize)
{
unsigned long index;
/* copy of the data buffer pointer so that it can advance by different widths */
void * input_data_copy = (void *)input_data;
/* The custom instruction CRC will initialize to the inital remainder value */
if (do_initialize)
CRC_CI_MACRO(0,0);
/* Write 32 bit data to the custom instruction. If the buffer does not end
* on a 32 bit boundary then the remaining data will be sent to the custom
* instruction in the 'if' statement below.
*/
for(index = 0; index < (input_data_length & 0xFFFFFFFC); index+=4)
{
CRC_CI_MACRO(3, *(unsigned long *)input_data_copy);
input_data_copy += 4; /* void pointer, must move by 4 for each word */
}
/* Write the remainder of the buffer if it does not end on a word boundary */
if((input_data_length & 0x3) == 0x3) /* 3 bytes left */
{
CRC_CI_MACRO(2, *(unsigned short *)input_data_copy);
input_data_copy += 2;
CRC_CI_MACRO(1, *(unsigned char *)input_data_copy);
}
else if((input_data_length & 0x3) == 0x2) /* 2 bytes left */
{
CRC_CI_MACRO(2, *(unsigned short *)input_data_copy);
}
else if((input_data_length & 0x3) == 0x1) /* 1 byte left */
{
CRC_CI_MACRO(1, *(unsigned char *)input_data_copy);
}
/* There are 4 registers in the CRC custom instruction. Since
* this example uses CRC-32 only the first register must be read
* in order to receive the full result.
*/
return CRC_CI_MACRO(4, 0);
}

View File

@ -1,265 +0,0 @@
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
/**********************************************************************
*
* Filename: crc.c
*
* Description: Slow and fast implementations of the CRC standards.
*
* Notes: The parameters for each supported CRC standard are
* defined in the header file crc.h. The implementations
* here should stand up to further additions to that list.
*
*
* 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.
**********************************************************************/
#include "crc.h"
/*
* Derive parameters from the standard-specific parameters in crc.h.
*/
#define WIDTH (8 * sizeof(crc))
#define TOPBIT (1 << (WIDTH - 1))
#if (REFLECT_DATA == TRUE)
#undef REFLECT_DATA
#define REFLECT_DATA(X) ((unsigned char) reflect((X), 8))
#else
#undef REFLECT_DATA
#define REFLECT_DATA(X) (X)
#endif
#if (REFLECT_REMAINDER == TRUE)
#undef REFLECT_REMAINDER
#define REFLECT_REMAINDER(X) ((crc) reflect((X), WIDTH))
#else
#undef REFLECT_REMAINDER
#define REFLECT_REMAINDER(X) (X)
#endif
/*********************************************************************
*
* Function: reflect()
*
* Description: Reorder the bits of a binary sequence, by reflecting
* them about the middle position.
*
* Notes: No checking is done that nBits <= 32.
*
* Returns: The reflection of the original data.
*
*********************************************************************/
static unsigned long
reflect(unsigned long data, unsigned char nBits)
{
unsigned long reflection = 0x00000000;
unsigned char bit;
/*
* Reflect the data about the center bit.
*/
for (bit = 0; bit < nBits; ++bit)
{
/*
* If the LSB bit is set, set the reflection of it.
*/
if (data & 0x01)
{
reflection |= (1 << ((nBits - 1) - bit));
}
data = (data >> 1);
}
return (reflection);
} /* reflect() */
/*********************************************************************
*
* Function: crcSlow()
*
* Description: Compute the CRC of a given message.
*
* Notes:
*
* Returns: The CRC of the message.
*
*********************************************************************/
crc
crcSlow(unsigned char const message[], int nBytes)
{
crc remainder = INITIAL_REMAINDER;
int byte;
unsigned char bit;
/*
* Perform modulo-2 division, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
/*
* Bring the next byte into the remainder.
*/
remainder ^= (REFLECT_DATA(message[byte]) << (WIDTH - 8));
/*
* Perform modulo-2 division, a bit at a time.
*/
for (bit = 8; bit > 0; --bit)
{
/*
* Try to divide the current data bit.
*/
if (remainder & TOPBIT)
{
remainder = (remainder << 1) ^ POLYNOMIAL;
}
else
{
remainder = (remainder << 1);
}
}
}
/*
* The final remainder is the CRC result.
*/
return (REFLECT_REMAINDER(remainder) ^ FINAL_XOR_VALUE);
} /* crcSlow() */
crc crcTable[256];
/*********************************************************************
*
* Function: crcInit()
*
* Description: Populate the partial CRC lookup table.
*
* Notes: This function must be rerun any time the CRC standard
* is changed. If desired, it can be run "offline" and
* the table results stored in an embedded system's ROM.
*
* Returns: None defined.
*
*********************************************************************/
void
crcInit(void)
{
crc remainder;
int dividend;
unsigned char bit;
/*
* Compute the remainder of each possible dividend.
*/
for (dividend = 0; dividend < 256; ++dividend)
{
/*
* Start with the dividend followed by zeros.
*/
remainder = dividend << (WIDTH - 8);
/*
* Perform modulo-2 division, a bit at a time.
*/
for (bit = 8; bit > 0; --bit)
{
/*
* Try to divide the current data bit.
*/
if (remainder & TOPBIT)
{
remainder = (remainder << 1) ^ POLYNOMIAL;
}
else
{
remainder = (remainder << 1);
}
}
/*
* Store the result into the table.
*/
crcTable[dividend] = remainder;
}
} /* crcInit() */
/*********************************************************************
*
* Function: crcFast()
*
* Description: Compute the CRC of a given message.
*
* Notes: crcInit() must be called first.
*
* Returns: The CRC of the message.
*
*********************************************************************/
crc
crcFast(unsigned char const message[], int nBytes)
{
crc remainder = INITIAL_REMAINDER;
unsigned char data;
int byte;
/*
* Divide the message by the polynomial, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
data = REFLECT_DATA(message[byte]) ^ (remainder >> (WIDTH - 8));
remainder = crcTable[data] ^ (remainder << 8);
}
/*
* The final remainder is the CRC.
*/
return (REFLECT_REMAINDER(remainder) ^ FINAL_XOR_VALUE);
} /* crcFast() */

View File

@ -69,7 +69,7 @@ int I2C_start(alt_u32 base, alt_u32 add, alt_u32 read)
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_STA_MSK | I2C_OPENCORES_CR_WR_MSK );
/* wait for the trnasaction to be over.*/
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
while (IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK) {}
/* now check to see if the address was acknowledged */
if(IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_RXNACK_MSK)
@ -119,7 +119,7 @@ alt_u32 I2C_read(alt_u32 base,alt_u32 last)
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_RD_MSK );
}
/* wait for the trnasaction to be over.*/
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
while (IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK) {}
/* now read the data */
return (IORD_I2C_OPENCORES_RXR(base));
@ -162,7 +162,7 @@ alt_u32 I2C_write(alt_u32 base,alt_u8 data, alt_u32 last)
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_WR_MSK );
}
/* wait for the trnasaction to be over.*/
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
while (IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK) {}
/* now check to see if the address was acknowledged */
if(IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_RXNACK_MSK)

View File

@ -4,7 +4,7 @@
* Machine generated for CPU 'nios2_qsys_0' in SOPC Builder design 'sys'
* SOPC Builder design path: ../../sys.sopcinfo
*
* Generated: Sun Oct 16 12:18:06 EEST 2016
* Generated: Fri Oct 05 19:59:02 EEST 2018
*/
/*
@ -65,11 +65,11 @@
*
*/
#define EPCQ_CONTROLLER_0_AVL_MEM_REGION_BASE 0x0
#define EPCQ_CONTROLLER_0_AVL_MEM_REGION_BASE 0x800000
#define EPCQ_CONTROLLER_0_AVL_MEM_REGION_SPAN 8388608
#define ONCHIP_MEMORY2_0_REGION_BASE 0x810020
#define ONCHIP_MEMORY2_0_REGION_SPAN 40928
#define RESET_REGION_BASE 0x810000
#define ONCHIP_MEMORY2_0_REGION_BASE 0x10020
#define ONCHIP_MEMORY2_0_REGION_SPAN 36832
#define RESET_REGION_BASE 0x10000
#define RESET_REGION_SPAN 32

View File

@ -4,7 +4,7 @@
* Machine generated for CPU 'nios2_qsys_0' in SOPC Builder design 'sys'
* SOPC Builder design path: ../../sys.sopcinfo
*
* Generated: Sun Oct 16 12:18:06 EEST 2016
* Generated: Fri Oct 05 19:59:02 EEST 2018
*/
/*
@ -50,14 +50,14 @@
MEMORY
{
epcq_controller_0_avl_mem : ORIGIN = 0x0, LENGTH = 8388608
reset : ORIGIN = 0x810000, LENGTH = 32
onchip_memory2_0 : ORIGIN = 0x810020, LENGTH = 40928
reset : ORIGIN = 0x10000, LENGTH = 32
onchip_memory2_0 : ORIGIN = 0x10020, LENGTH = 36832
epcq_controller_0_avl_mem : ORIGIN = 0x800000, LENGTH = 8388608
}
/* Define symbols for each memory base-address */
__alt_mem_epcq_controller_0_avl_mem = 0x0;
__alt_mem_onchip_memory2_0 = 0x810000;
__alt_mem_onchip_memory2_0 = 0x10000;
__alt_mem_epcq_controller_0_avl_mem = 0x800000;
OUTPUT_FORMAT( "elf32-littlenios2",
"elf32-littlenios2",
@ -309,24 +309,7 @@ SECTIONS
*
*/
.epcq_controller_0_avl_mem : AT ( LOADADDR (.bss) + SIZEOF (.bss) )
{
PROVIDE (_alt_partition_epcq_controller_0_avl_mem_start = ABSOLUTE(.));
*(.epcq_controller_0_avl_mem .epcq_controller_0_avl_mem. epcq_controller_0_avl_mem.*)
. = ALIGN(4);
PROVIDE (_alt_partition_epcq_controller_0_avl_mem_end = ABSOLUTE(.));
} > epcq_controller_0_avl_mem
PROVIDE (_alt_partition_epcq_controller_0_avl_mem_load_addr = LOADADDR(.epcq_controller_0_avl_mem));
/*
*
* This section's LMA is set to the .text region.
* crt0 will copy to this section's specified mapped region virtual memory address (VMA)
*
*/
.onchip_memory2_0 LOADADDR (.epcq_controller_0_avl_mem) + SIZEOF (.epcq_controller_0_avl_mem) : AT ( LOADADDR (.epcq_controller_0_avl_mem) + SIZEOF (.epcq_controller_0_avl_mem) )
.onchip_memory2_0 LOADADDR (.bss) + SIZEOF (.bss) : AT ( LOADADDR (.bss) + SIZEOF (.bss) )
{
PROVIDE (_alt_partition_onchip_memory2_0_start = ABSOLUTE(.));
*(.onchip_memory2_0 .onchip_memory2_0. onchip_memory2_0.*)
@ -339,6 +322,23 @@ SECTIONS
PROVIDE (_alt_partition_onchip_memory2_0_load_addr = LOADADDR(.onchip_memory2_0));
/*
*
* This section's LMA is set to the .text region.
* crt0 will copy to this section's specified mapped region virtual memory address (VMA)
*
*/
.epcq_controller_0_avl_mem : AT ( LOADADDR (.onchip_memory2_0) + SIZEOF (.onchip_memory2_0) )
{
PROVIDE (_alt_partition_epcq_controller_0_avl_mem_start = ABSOLUTE(.));
*(.epcq_controller_0_avl_mem .epcq_controller_0_avl_mem. epcq_controller_0_avl_mem.*)
. = ALIGN(4);
PROVIDE (_alt_partition_epcq_controller_0_avl_mem_end = ABSOLUTE(.));
} > epcq_controller_0_avl_mem
PROVIDE (_alt_partition_epcq_controller_0_avl_mem_load_addr = LOADADDR(.epcq_controller_0_avl_mem));
/*
* Stabs debugging sections.
*
@ -386,7 +386,7 @@ SECTIONS
/*
* Don't override this, override the __alt_stack_* symbols instead.
*/
__alt_data_end = 0x81a000;
__alt_data_end = 0x19000;
/*
* The next two symbols define the location of the default stack. You can
@ -402,4 +402,4 @@ PROVIDE( __alt_stack_limit = __alt_stack_base );
* Override this symbol to put the heap in a different memory.
*/
PROVIDE( __alt_heap_start = end );
PROVIDE( __alt_heap_limit = 0x81a000 );
PROVIDE( __alt_heap_limit = 0x19000 );

View File

@ -161,7 +161,7 @@ ACDS_VERSION := 17.1
SIM_OPTIMIZE ?= 0
# The CPU reset address as needed by elf2flash
RESET_ADDRESS ?= 0x00810000
RESET_ADDRESS ?= 0x00010000
# The specific Nios II ELF file format to use.
NIOS2_ELF_FORMAT ?= elf32-littlenios2
@ -175,8 +175,8 @@ MEM_0 := epcq_controller_0
$(MEM_0)_NAME := epcq_controller_0
HEX_FILES += $(MEM_INIT_DIR)/$(MEM_0).hex
MEM_INIT_INSTALL_FILES += $(MEM_INIT_INSTALL_DIR)/$(MEM_0).hex
$(MEM_0)_START := 0x00000000
$(MEM_0)_END := 0x007fffff
$(MEM_0)_START := 0x00800000
$(MEM_0)_END := 0x00ffffff
$(MEM_0)_SPAN := 0x00800000
$(MEM_0)_HIERARCHICAL_PATH := epcq_controller_0
$(MEM_0)_WIDTH := 32
@ -198,9 +198,9 @@ DAT_FILES += $(HDL_SIM_DIR)/$(MEM_1).dat
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_1).dat
SYM_FILES += $(HDL_SIM_DIR)/$(MEM_1).sym
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_1).sym
$(MEM_1)_START := 0x00810000
$(MEM_1)_END := 0x00819fff
$(MEM_1)_SPAN := 0x0000a000
$(MEM_1)_START := 0x00010000
$(MEM_1)_END := 0x00018fff
$(MEM_1)_SPAN := 0x00009000
$(MEM_1)_HIERARCHICAL_PATH := onchip_memory2_0
$(MEM_1)_WIDTH := 32
$(MEM_1)_HEX_DATA_WIDTH := 32
@ -304,10 +304,10 @@ ELF_TO_HEX_CMD = $(strip $(if $(flash_mem_boot_loader_flag), \
$(ELF_TO_HEX_CMD_NO_BOOTLOADER) \
))
$(HEX_FILES): %.hex: $(ELF)
$(post-process-info)
@$(MKDIR) $(@D)
$(ELF_TO_HEX_CMD)
#$(HEX_FILES): %.hex: $(ELF)
# $(post-process-info)
# @$(MKDIR) $(@D)
# $(ELF_TO_HEX_CMD)
$(SYM_FILES): %.sym: $(ELF)
$(post-process-info)

View File

@ -3,7 +3,7 @@
# Machine generated for CPU 'nios2_qsys_0' in SOPC Builder design 'sys'
# SOPC Builder design path: ../../sys.sopcinfo
#
# Generated: Sun Oct 16 12:18:06 EEST 2016
# Generated: Fri Oct 05 19:59:02 EEST 2018
# DO NOT MODIFY THIS FILE
#
@ -46,8 +46,8 @@
# The cache attribute is specified which improves GDB performance
# by allowing GDB to cache memory contents on the host.
# epcq_controller_0_avl_mem
memory 0x0 0x800000 cache
# onchip_memory2_0
memory 0x810000 0x81a000 cache
memory 0x10000 0x19000 cache
# epcq_controller_0_avl_mem
memory 0x800000 0x1000000 cache

View File

@ -19,7 +19,7 @@
# Path to the provided linker script.
BSP_LINKER_SCRIPT := $(ALT_LIBRARY_ROOT_DIR)/linker.x
BSP_LINKER_SCRIPT := link.riscv.ld
# Include paths:
# The path to root of all header files that a library wishes to make
@ -119,15 +119,15 @@ ELF_PATCH_FLAG += --cpu_name $(CPU_NAME)
# Hardware Divider present.
# setting HARDWARE_DIVIDE is false
ALT_CFLAGS += -mno-hw-div
#ALT_CFLAGS += -mno-hw-div
# Hardware Multiplier present.
# setting HARDWARE_MULTIPLY is false
ALT_CFLAGS += -mno-hw-mul
#ALT_CFLAGS += -mno-hw-mul
# Hardware Mulx present.
# setting HARDWARE_MULX is false
ALT_CFLAGS += -mno-hw-mulx
#ALT_CFLAGS += -mno-hw-mulx
# Debug Core present.
# setting HAS_DEBUG_CORE is true
@ -258,7 +258,8 @@ ALT_CPPFLAGS += -DSMALL_C_LIB
# generate GP-relative accesses for small data objects that are external, weak,
# or common. none
# setting hal.make.cflags_mgpopt is -mgpopt=global
ALT_CFLAGS += -mgpopt=global
#ALT_CFLAGS += -mgpopt=global
ALT_CFLAGS += -march=rv32emc -mabi=ilp32e
# Enable BSP generation to query if SOPC system is big endian. If true ignores
# export of 'ALT_CFLAGS += -meb' to public.mk if big endian system. none

View File

@ -2,8 +2,8 @@
<sch:Settings xmlns:sch="http://www.altera.com/embeddedsw/bsp/schema">
<BspType>hal</BspType>
<BspVersion>default</BspVersion>
<BspGeneratedTimeStamp>Apr 18, 2018 10:30:05 PM</BspGeneratedTimeStamp>
<BspGeneratedUnixTimeStamp>1524079805195</BspGeneratedUnixTimeStamp>
<BspGeneratedTimeStamp>Oct 5, 2018 8:21:01 PM</BspGeneratedTimeStamp>
<BspGeneratedUnixTimeStamp>1538758741996</BspGeneratedUnixTimeStamp>
<BspGeneratedLocation>./</BspGeneratedLocation>
<BspSettingsFile>settings.bsp</BspSettingsFile>
<SopcDesignFile>../../sys.sopcinfo</SopcDesignFile>
@ -898,101 +898,101 @@
<Enabled>false</Enabled>
<Group xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</Setting>
<MemoryMap>
<slaveDescriptor>epcq_controller_0_avl_mem</slaveDescriptor>
<addressRange>0x00000000 - 0x007FFFFF</addressRange>
<addressSpan>8388608</addressSpan>
<attributes>flash, memory, non-volatile</attributes>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>onchip_memory2_0</slaveDescriptor>
<addressRange>0x00810000 - 0x00819FFF</addressRange>
<addressRange>0x00010000 - 0x00019FFF</addressRange>
<addressSpan>40960</addressSpan>
<attributes>memory</attributes>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>timer_0</slaveDescriptor>
<addressRange>0x00821000 - 0x0082101F</addressRange>
<addressRange>0x00020000 - 0x0002001F</addressRange>
<addressSpan>32</addressSpan>
<attributes>timer</attributes>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>jtag_uart_0</slaveDescriptor>
<addressRange>0x00020020 - 0x00020027</addressRange>
<addressSpan>8</addressSpan>
<attributes>printable</attributes>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>epcq_controller_0_avl_csr</slaveDescriptor>
<addressRange>0x00821020 - 0x0082103F</addressRange>
<addressRange>0x00020100 - 0x0002011F</addressRange>
<addressSpan>32</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>i2c_opencores_1</slaveDescriptor>
<addressRange>0x00821040 - 0x0082105F</addressRange>
<addressRange>0x00021020 - 0x0002103F</addressRange>
<addressSpan>32</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>i2c_opencores_0</slaveDescriptor>
<addressRange>0x00821060 - 0x0082107F</addressRange>
<addressRange>0x00021040 - 0x0002105F</addressRange>
<addressSpan>32</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_8</slaveDescriptor>
<addressRange>0x00821080 - 0x0082108F</addressRange>
<addressRange>0x00021060 - 0x0002106F</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_7</slaveDescriptor>
<addressRange>0x00821090 - 0x0082109F</addressRange>
<addressRange>0x00021070 - 0x0002107F</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_6</slaveDescriptor>
<addressRange>0x008210A0 - 0x008210AF</addressRange>
<addressRange>0x00021080 - 0x0002108F</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_5</slaveDescriptor>
<addressRange>0x008210B0 - 0x008210BF</addressRange>
<addressRange>0x00021090 - 0x0002109F</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_4</slaveDescriptor>
<addressRange>0x008210C0 - 0x008210CF</addressRange>
<addressRange>0x000210A0 - 0x000210AF</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_3</slaveDescriptor>
<addressRange>0x008210D0 - 0x008210DF</addressRange>
<addressRange>0x000210B0 - 0x000210BF</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_2</slaveDescriptor>
<addressRange>0x008210E0 - 0x008210EF</addressRange>
<addressRange>0x000210C0 - 0x000210CF</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_1</slaveDescriptor>
<addressRange>0x008210F0 - 0x008210FF</addressRange>
<addressRange>0x000210D0 - 0x000210DF</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>pio_0</slaveDescriptor>
<addressRange>0x00821100 - 0x0082110F</addressRange>
<addressRange>0x000210E0 - 0x000210EF</addressRange>
<addressSpan>16</addressSpan>
<attributes/>
</MemoryMap>
<MemoryMap>
<slaveDescriptor>jtag_uart_0</slaveDescriptor>
<addressRange>0x00821110 - 0x00821117</addressRange>
<addressSpan>8</addressSpan>
<attributes>printable</attributes>
<slaveDescriptor>epcq_controller_0_avl_mem</slaveDescriptor>
<addressRange>0x00800000 - 0x00FFFFFF</addressRange>
<addressSpan>8388608</addressSpan>
<attributes>flash, memory, non-volatile</attributes>
</MemoryMap>
<LinkerSection>
<sectionName>.text</sectionName>
@ -1018,4 +1018,4 @@
<sectionName>.stack</sectionName>
<regionName>onchip_memory2_0</regionName>
</LinkerSection>
</sch:Settings>
</sch:Settings>

View File

@ -4,7 +4,7 @@
* Machine generated for CPU 'nios2_qsys_0' in SOPC Builder design 'sys'
* SOPC Builder design path: ../../sys.sopcinfo
*
* Generated: Sun Mar 25 16:51:03 EEST 2018
* Generated: Fri Oct 05 19:59:02 EEST 2018
*/
/*
@ -62,7 +62,7 @@
#define ALT_CPU_ARCHITECTURE "altera_nios2_gen2"
#define ALT_CPU_BIG_ENDIAN 0
#define ALT_CPU_BREAK_ADDR 0x00820820
#define ALT_CPU_BREAK_ADDR 0x00000820
#define ALT_CPU_CPU_ARCH_NIOS2_R1
#define ALT_CPU_CPU_FREQ 27000000u
#define ALT_CPU_CPU_ID_SIZE 1
@ -72,7 +72,7 @@
#define ALT_CPU_DCACHE_LINE_SIZE 0
#define ALT_CPU_DCACHE_LINE_SIZE_LOG2 0
#define ALT_CPU_DCACHE_SIZE 0
#define ALT_CPU_EXCEPTION_ADDR 0x00810020
#define ALT_CPU_EXCEPTION_ADDR 0x00010020
#define ALT_CPU_FLASH_ACCELERATOR_LINES 0
#define ALT_CPU_FLASH_ACCELERATOR_LINE_SIZE 0
#define ALT_CPU_FLUSHDA_SUPPORTED
@ -87,10 +87,10 @@
#define ALT_CPU_ICACHE_LINE_SIZE 0
#define ALT_CPU_ICACHE_LINE_SIZE_LOG2 0
#define ALT_CPU_ICACHE_SIZE 0
#define ALT_CPU_INST_ADDR_WIDTH 0x18
#define ALT_CPU_INST_ADDR_WIDTH 0x11
#define ALT_CPU_NAME "nios2_qsys_0"
#define ALT_CPU_OCI_VERSION 1
#define ALT_CPU_RESET_ADDR 0x00810000
#define ALT_CPU_RESET_ADDR 0x00010000
/*
@ -99,7 +99,7 @@
*/
#define NIOS2_BIG_ENDIAN 0
#define NIOS2_BREAK_ADDR 0x00820820
#define NIOS2_BREAK_ADDR 0x00000820
#define NIOS2_CPU_ARCH_NIOS2_R1
#define NIOS2_CPU_FREQ 27000000u
#define NIOS2_CPU_ID_SIZE 1
@ -109,7 +109,7 @@
#define NIOS2_DCACHE_LINE_SIZE 0
#define NIOS2_DCACHE_LINE_SIZE_LOG2 0
#define NIOS2_DCACHE_SIZE 0
#define NIOS2_EXCEPTION_ADDR 0x00810020
#define NIOS2_EXCEPTION_ADDR 0x00010020
#define NIOS2_FLASH_ACCELERATOR_LINES 0
#define NIOS2_FLASH_ACCELERATOR_LINE_SIZE 0
#define NIOS2_FLUSHDA_SUPPORTED
@ -123,9 +123,9 @@
#define NIOS2_ICACHE_LINE_SIZE 0
#define NIOS2_ICACHE_LINE_SIZE_LOG2 0
#define NIOS2_ICACHE_SIZE 0
#define NIOS2_INST_ADDR_WIDTH 0x18
#define NIOS2_INST_ADDR_WIDTH 0x11
#define NIOS2_OCI_VERSION 1
#define NIOS2_RESET_ADDR 0x00810000
#define NIOS2_RESET_ADDR 0x00010000
/*
@ -133,13 +133,13 @@
*
*/
#define ALT_CI_NIOS2_HW_CRC32_0(n,A) __builtin_custom_ini(ALT_CI_NIOS2_HW_CRC32_0_N+(n&ALT_CI_NIOS2_HW_CRC32_0_N_MASK),(A))
/*#define ALT_CI_NIOS2_HW_CRC32_0(n,A) __builtin_custom_ini(ALT_CI_NIOS2_HW_CRC32_0_N+(n&ALT_CI_NIOS2_HW_CRC32_0_N_MASK),(A))
#define ALT_CI_NIOS2_HW_CRC32_0_N 0x0
#define ALT_CI_NIOS2_HW_CRC32_0_N_MASK ((1<<3)-1)
#define ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0(A) __builtin_custom_ini(ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0_N,(A))
#define ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0_N 0x9
#define ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0(A) __builtin_custom_ini(ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0_N,(A))
#define ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0_N 0x8
#define ALT_CI_NIOS_CUSTOM_INSTR_ENDIANCONVERTER_0_N 0x8*/
/*
@ -175,19 +175,19 @@
#define ALT_NUM_INTERNAL_INTERRUPT_CONTROLLERS 1
#define ALT_NUM_INTERRUPT_CONTROLLERS 1
#define ALT_STDERR "/dev/jtag_uart_0"
#define ALT_STDERR_BASE 0x821110
#define ALT_STDERR_BASE 0x20020
#define ALT_STDERR_DEV jtag_uart_0
#define ALT_STDERR_IS_JTAG_UART
#define ALT_STDERR_PRESENT
#define ALT_STDERR_TYPE "altera_avalon_jtag_uart"
#define ALT_STDIN "/dev/jtag_uart_0"
#define ALT_STDIN_BASE 0x821110
#define ALT_STDIN_BASE 0x20020
#define ALT_STDIN_DEV jtag_uart_0
#define ALT_STDIN_IS_JTAG_UART
#define ALT_STDIN_PRESENT
#define ALT_STDIN_TYPE "altera_avalon_jtag_uart"
#define ALT_STDOUT "/dev/jtag_uart_0"
#define ALT_STDOUT_BASE 0x821110
#define ALT_STDOUT_BASE 0x20020
#define ALT_STDOUT_DEV jtag_uart_0
#define ALT_STDOUT_IS_JTAG_UART
#define ALT_STDOUT_PRESENT
@ -201,7 +201,7 @@
*/
#define ALT_MODULE_CLASS_epcq_controller_0_avl_csr altera_epcq_controller_mod
#define EPCQ_CONTROLLER_0_AVL_CSR_BASE 0x821020
#define EPCQ_CONTROLLER_0_AVL_CSR_BASE 0x20100
#define EPCQ_CONTROLLER_0_AVL_CSR_FLASH_TYPE "EPCS64"
#define EPCQ_CONTROLLER_0_AVL_CSR_IRQ 2
#define EPCQ_CONTROLLER_0_AVL_CSR_IRQ_INTERRUPT_CONTROLLER_ID 0
@ -221,7 +221,7 @@
*/
#define ALT_MODULE_CLASS_epcq_controller_0_avl_mem altera_epcq_controller_mod
#define EPCQ_CONTROLLER_0_AVL_MEM_BASE 0x0
#define EPCQ_CONTROLLER_0_AVL_MEM_BASE 0x800000
#define EPCQ_CONTROLLER_0_AVL_MEM_FLASH_TYPE "EPCS64"
#define EPCQ_CONTROLLER_0_AVL_MEM_IRQ -1
#define EPCQ_CONTROLLER_0_AVL_MEM_IRQ_INTERRUPT_CONTROLLER_ID -1
@ -251,7 +251,7 @@
*/
#define ALT_MODULE_CLASS_i2c_opencores_0 i2c_opencores
#define I2C_OPENCORES_0_BASE 0x821060
#define I2C_OPENCORES_0_BASE 0x21040
#define I2C_OPENCORES_0_IRQ 3
#define I2C_OPENCORES_0_IRQ_INTERRUPT_CONTROLLER_ID 0
#define I2C_OPENCORES_0_NAME "/dev/i2c_opencores_0"
@ -265,7 +265,7 @@
*/
#define ALT_MODULE_CLASS_i2c_opencores_1 i2c_opencores
#define I2C_OPENCORES_1_BASE 0x821040
#define I2C_OPENCORES_1_BASE 0x21020
#define I2C_OPENCORES_1_IRQ 4
#define I2C_OPENCORES_1_IRQ_INTERRUPT_CONTROLLER_ID 0
#define I2C_OPENCORES_1_NAME "/dev/i2c_opencores_1"
@ -279,7 +279,7 @@
*/
#define ALT_MODULE_CLASS_jtag_uart_0 altera_avalon_jtag_uart
#define JTAG_UART_0_BASE 0x821110
#define JTAG_UART_0_BASE 0x20020
#define JTAG_UART_0_IRQ 1
#define JTAG_UART_0_IRQ_INTERRUPT_CONTROLLER_ID 0
#define JTAG_UART_0_NAME "/dev/jtag_uart_0"
@ -299,7 +299,7 @@
#define ALT_MODULE_CLASS_onchip_memory2_0 altera_avalon_onchip_memory2
#define ONCHIP_MEMORY2_0_ALLOW_IN_SYSTEM_MEMORY_CONTENT_EDITOR 0
#define ONCHIP_MEMORY2_0_ALLOW_MRAM_SIM_CONTENTS_ONLY_FILE 0
#define ONCHIP_MEMORY2_0_BASE 0x810000
#define ONCHIP_MEMORY2_0_BASE 0x10000
#define ONCHIP_MEMORY2_0_CONTENTS_INFO ""
#define ONCHIP_MEMORY2_0_DUAL_PORT 0
#define ONCHIP_MEMORY2_0_GUI_RAM_BLOCK_TYPE "AUTO"
@ -319,6 +319,13 @@
#define ONCHIP_MEMORY2_0_TYPE "altera_avalon_onchip_memory2"
#define ONCHIP_MEMORY2_0_WRITABLE 1
/*
* hw_crc32_0 configuration
*
*/
#define ALT_MODULE_CLASS_hw_crc32_0 hw_crc32
#define HW_CRC32_0_BASE 0x21000
/*
* pio_0 configuration
@ -326,7 +333,7 @@
*/
#define ALT_MODULE_CLASS_pio_0 altera_avalon_pio
#define PIO_0_BASE 0x821100
#define PIO_0_BASE 0x210e0
#define PIO_0_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_0_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_0_CAPTURE 0
@ -353,7 +360,7 @@
*/
#define ALT_MODULE_CLASS_pio_1 altera_avalon_pio
#define PIO_1_BASE 0x8210f0
#define PIO_1_BASE 0x210d0
#define PIO_1_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_1_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_1_CAPTURE 0
@ -380,7 +387,7 @@
*/
#define ALT_MODULE_CLASS_pio_2 altera_avalon_pio
#define PIO_2_BASE 0x8210e0
#define PIO_2_BASE 0x210c0
#define PIO_2_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_2_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_2_CAPTURE 0
@ -407,7 +414,7 @@
*/
#define ALT_MODULE_CLASS_pio_3 altera_avalon_pio
#define PIO_3_BASE 0x8210d0
#define PIO_3_BASE 0x210b0
#define PIO_3_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_3_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_3_CAPTURE 0
@ -434,7 +441,7 @@
*/
#define ALT_MODULE_CLASS_pio_4 altera_avalon_pio
#define PIO_4_BASE 0x8210c0
#define PIO_4_BASE 0x210a0
#define PIO_4_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_4_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_4_CAPTURE 0
@ -461,7 +468,7 @@
*/
#define ALT_MODULE_CLASS_pio_5 altera_avalon_pio
#define PIO_5_BASE 0x8210b0
#define PIO_5_BASE 0x21090
#define PIO_5_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_5_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_5_CAPTURE 0
@ -488,7 +495,7 @@
*/
#define ALT_MODULE_CLASS_pio_6 altera_avalon_pio
#define PIO_6_BASE 0x8210a0
#define PIO_6_BASE 0x21080
#define PIO_6_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_6_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_6_CAPTURE 0
@ -515,7 +522,7 @@
*/
#define ALT_MODULE_CLASS_pio_7 altera_avalon_pio
#define PIO_7_BASE 0x821090
#define PIO_7_BASE 0x21070
#define PIO_7_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_7_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_7_CAPTURE 0
@ -542,7 +549,7 @@
*/
#define ALT_MODULE_CLASS_pio_8 altera_avalon_pio
#define PIO_8_BASE 0x821080
#define PIO_8_BASE 0x21060
#define PIO_8_BIT_CLEARING_EDGE_REGISTER 0
#define PIO_8_BIT_MODIFYING_OUTPUT_REGISTER 0
#define PIO_8_CAPTURE 0
@ -570,7 +577,7 @@
#define ALT_MODULE_CLASS_timer_0 altera_avalon_timer
#define TIMER_0_ALWAYS_RUN 0
#define TIMER_0_BASE 0x821000
#define TIMER_0_BASE 0x20000
#define TIMER_0_COUNTER_SIZE 32
#define TIMER_0_FIXED_PERIOD 0
#define TIMER_0_FREQ 27000000

851
sys.qsys

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

53
tools/bin2hex.c Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define MEMBLK 1024
int main(int argc, char **argv)
{
unsigned char block[4];
unsigned int csum;
int fd_i;
FILE *fd_o;
struct stat fileinfo;
unsigned int i;
if (argc != 3) {
printf("usage: %s binfile hexfile\n", argv[0]);
return -1;
}
if ((fd_i = open(argv[1], O_RDONLY)) == -1 || fstat(fd_i, &fileinfo) == -1) {
printf("Couldn't open file\n");
return -1;
}
printf("size: %u bytes\n", fileinfo.st_size);
if ((fd_o = fopen(argv[2], "w")) == NULL) {
printf("invalid outfile\n");
return -1;
}
for (i=0; i<fileinfo.st_size; i+=4) {
read(fd_i, (void*)block, 4);
csum = 0x04+((i/4)>>8)+((i/4)&0xff)+block[3]+block[2]+block[1]+block[0];
csum &= 0xff;
csum = (~csum+1)&0xff;
fprintf(fd_o, ":04%.4X00%.2X%.2X%.2X%.2X%.2X\n", i/4, block[3],block[2],block[1],block[0],csum);
}
fprintf(fd_o, ":00000001FF\n");
fclose(fd_o);
close(fd_i);
return 0;
}