├── .gitignore ├── .gitmodules ├── CREDITS ├── LICENSE ├── README.md ├── ip ├── altera_jtag_avalon_master_mod │ └── altera_jtag_avalon_master_mod_hw.tcl ├── hw_crc32_qsys │ ├── CRC_Component.v │ └── hw_crc32_hw.tcl ├── i2c_opencores │ ├── Docs │ │ ├── I2C_tests.c │ │ └── i2c_specs.pdf │ ├── HAL │ │ ├── inc │ │ │ └── i2c_opencores.h │ │ └── src │ │ │ ├── component.mk │ │ │ └── i2c_opencores.c │ ├── i2c_master_bit_ctrl.v │ ├── i2c_master_byte_ctrl.v │ ├── i2c_master_defines.v │ ├── i2c_master_top.v │ ├── i2c_opencores.v │ ├── i2c_opencores_hw.tcl │ ├── i2c_opencores_sw.tcl │ ├── inc │ │ └── i2c_opencores_regs.h │ └── timescale.v ├── osd_generator │ ├── bin │ │ ├── ASCII_KANA_8x8.bin │ │ ├── IBM_VGA_8x8.bin │ │ └── char_rom.hex │ ├── inc │ │ └── osd_generator_regs.h │ ├── osd_generator_hw.tcl │ ├── osd_generator_sw.tcl │ └── osd_generator_top.sv ├── pll_reconfig │ ├── inc │ │ └── pll_reconfig_regs.h │ ├── pll_reconfig_hw.tcl │ ├── pll_reconfig_sw.tcl │ └── pll_reconfig_top.sv └── sc_config │ ├── inc │ └── sc_config_regs.h │ ├── sc_config_hw.tcl │ ├── sc_config_sw.tcl │ └── sc_config_top.sv ├── ossc.cof ├── ossc.qpf ├── ossc.qsf ├── ossc.sdc ├── ossc.workspace ├── ossc_rtl.project ├── ossc_sw_bsp.project ├── rtl ├── char_array.qip ├── char_array.v ├── char_rom.qip ├── char_rom.v ├── ir_rcv.v ├── lat_tester.v ├── lat_tester_includes.v ├── linebuf.qip ├── linebuf.v ├── linebuf_top.v ├── lpm_mult_8x5_9.qip ├── lpm_mult_8x5_9.v ├── lpm_mult_sl.qip ├── lpm_mult_sl.v ├── ossc.v ├── pll_2x.ppf ├── pll_2x.qip ├── pll_2x.v ├── pll_config_2x_5x_data.mif ├── pll_config_3x_4x_data.mif ├── pll_config_default_data.mif ├── scanconverter.v ├── timescale.v ├── tvp7002_frontend.v └── videogen.v ├── scripts ├── qsys.patch ├── reprogram.sh └── rv-reprogram.tcl ├── software ├── ossc_sw.project ├── sys_controller │ ├── Makefile │ ├── crt0.boot.S │ ├── crt0.boot_E.S │ ├── it6613 │ │ ├── EDID.c │ │ ├── HDMI_COMMON.h │ │ ├── HDMI_TX.c │ │ ├── HDMI_TX.h │ │ ├── edid.h │ │ ├── hdmitx.h │ │ ├── hdmitx_nios2.c │ │ ├── it6613.c │ │ ├── it6613.h │ │ ├── it6613_drv.c │ │ ├── it6613_drv.h │ │ ├── it6613_sys.c │ │ ├── it6613_sys.h │ │ └── typedef.h │ ├── link.common.ld │ ├── link.riscv.ld │ ├── mem_init │ │ ├── epcq_controller_0.hex │ │ ├── meminit.qip │ │ └── meminit.spd │ ├── memory │ │ ├── flash.c │ │ ├── flash.h │ │ ├── sdcard.c │ │ └── sdcard.h │ ├── ossc │ │ ├── av_controller.c │ │ ├── av_controller.h │ │ ├── avconfig.c │ │ ├── avconfig.h │ │ ├── controls.c │ │ ├── controls.h │ │ ├── fat16_export.c │ │ ├── fat16_export.h │ │ ├── firmware.c │ │ ├── firmware.h │ │ ├── menu.c │ │ ├── menu.h │ │ ├── sysconfig.h │ │ ├── userdata.c │ │ ├── userdata.h │ │ ├── utils.c │ │ ├── utils.h │ │ ├── video_modes.c │ │ ├── video_modes.h │ │ └── video_modes_list.c │ ├── pcm1862 │ │ ├── pcm1862.c │ │ ├── pcm1862.h │ │ └── pcm1862_regs.h │ ├── pulpino.h │ ├── spi_charlcd │ │ ├── lcd.c │ │ └── lcd.h │ ├── ths7353 │ │ ├── ths7353.c │ │ └── ths7353.h │ ├── tvp7002 │ │ ├── tvp7002.c │ │ ├── tvp7002.h │ │ └── tvp7002_regs.h │ └── ulibSD │ │ ├── integer.h │ │ ├── sd_io.c │ │ ├── sd_io.h │ │ ├── spi_io.c │ │ └── spi_io.h └── sys_controller_bsp │ ├── HAL │ ├── inc │ │ ├── alt_types.h │ │ ├── altera_nios2_gen2_irq.h │ │ ├── io.h │ │ ├── nios2.h │ │ ├── os │ │ │ ├── alt_flag.h │ │ │ ├── alt_hooks.h │ │ │ ├── alt_sem.h │ │ │ └── alt_syscall.h │ │ ├── priv │ │ │ ├── alt_alarm.h │ │ │ ├── alt_busy_sleep.h │ │ │ ├── alt_dev_llist.h │ │ │ ├── alt_exception_handler_registry.h │ │ │ ├── alt_file.h │ │ │ ├── alt_iic_isr_register.h │ │ │ ├── alt_irq_table.h │ │ │ ├── alt_legacy_irq.h │ │ │ ├── alt_no_error.h │ │ │ └── nios2_gmon_data.h │ │ └── sys │ │ │ ├── alt_alarm.h │ │ │ ├── alt_cache.h │ │ │ ├── alt_debug.h │ │ │ ├── alt_dev.h │ │ │ ├── alt_dma.h │ │ │ ├── alt_dma_dev.h │ │ │ ├── alt_driver.h │ │ │ ├── alt_errno.h │ │ │ ├── alt_exceptions.h │ │ │ ├── alt_flash.h │ │ │ ├── alt_flash_dev.h │ │ │ ├── alt_flash_types.h │ │ │ ├── alt_irq.h │ │ │ ├── alt_irq_entry.h │ │ │ ├── alt_license_reminder_ucosii.h │ │ │ ├── alt_llist.h │ │ │ ├── alt_load.h │ │ │ ├── alt_log_printf.h │ │ │ ├── alt_set_args.h │ │ │ ├── alt_sim.h │ │ │ ├── alt_stack.h │ │ │ ├── alt_stdio.h │ │ │ ├── alt_sys_init.h │ │ │ ├── alt_sys_wrappers.h │ │ │ ├── alt_timestamp.h │ │ │ ├── alt_warning.h │ │ │ ├── ioctl.h │ │ │ └── termios.h │ └── src │ │ ├── alt_alarm_start.c │ │ ├── alt_busy_sleep.c │ │ ├── alt_close.c │ │ ├── alt_dcache_flush.c │ │ ├── alt_dcache_flush_all.c │ │ ├── alt_dcache_flush_no_writeback.c │ │ ├── alt_dev.c │ │ ├── alt_dev_llist_insert.c │ │ ├── alt_dma_rxchan_open.c │ │ ├── alt_dma_txchan_open.c │ │ ├── alt_do_ctors.c │ │ ├── alt_do_dtors.c │ │ ├── alt_ecc_fatal_entry.S │ │ ├── alt_ecc_fatal_exception.c │ │ ├── alt_env_lock.c │ │ ├── alt_environ.c │ │ ├── alt_errno.c │ │ ├── alt_exception_entry.S │ │ ├── alt_exception_muldiv.S │ │ ├── alt_exception_trap.S │ │ ├── alt_execve.c │ │ ├── alt_exit.c │ │ ├── alt_fcntl.c │ │ ├── alt_fd_lock.c │ │ ├── alt_fd_unlock.c │ │ ├── alt_find_dev.c │ │ ├── alt_find_file.c │ │ ├── alt_flash_dev.c │ │ ├── alt_fork.c │ │ ├── alt_fs_reg.c │ │ ├── alt_fstat.c │ │ ├── alt_get_fd.c │ │ ├── alt_getchar.c │ │ ├── alt_getpid.c │ │ ├── alt_gettod.c │ │ ├── alt_gmon.c │ │ ├── alt_icache_flush.c │ │ ├── alt_icache_flush_all.c │ │ ├── alt_iic.c │ │ ├── alt_iic_isr_register.c │ │ ├── alt_instruction_exception_entry.c │ │ ├── alt_instruction_exception_register.c │ │ ├── alt_io_redirect.c │ │ ├── alt_ioctl.c │ │ ├── alt_irq_entry.S │ │ ├── alt_irq_handler.c │ │ ├── alt_irq_register.c │ │ ├── alt_irq_vars.c │ │ ├── alt_isatty.c │ │ ├── alt_kill.c │ │ ├── alt_link.c │ │ ├── alt_load.c │ │ ├── alt_log_macro.S │ │ ├── alt_log_printf.c │ │ ├── alt_lseek.c │ │ ├── alt_main.c │ │ ├── alt_malloc_lock.c │ │ ├── alt_mcount.S │ │ ├── alt_open.c │ │ ├── alt_printf.c │ │ ├── alt_putchar.c │ │ ├── alt_putcharbuf.c │ │ ├── alt_putstr.c │ │ ├── alt_read.c │ │ ├── alt_release_fd.c │ │ ├── alt_remap_cached.c │ │ ├── alt_remap_uncached.c │ │ ├── alt_rename.c │ │ ├── alt_sbrk.c │ │ ├── alt_settod.c │ │ ├── alt_software_exception.S │ │ ├── alt_stat.c │ │ ├── alt_tick.c │ │ ├── alt_times.c │ │ ├── alt_uncached_free.c │ │ ├── alt_uncached_malloc.c │ │ ├── alt_unlink.c │ │ ├── alt_usleep.c │ │ ├── alt_wait.c │ │ ├── alt_write.c │ │ ├── altera_nios2_gen2_irq.c │ │ └── crt0.S │ ├── Makefile │ ├── alt_sys_init.c │ ├── create-this-bsp │ ├── drivers │ ├── inc │ │ ├── altera_avalon_jtag_uart.h │ │ ├── altera_avalon_jtag_uart_fd.h │ │ ├── altera_avalon_jtag_uart_regs.h │ │ ├── altera_avalon_pio_regs.h │ │ ├── altera_avalon_timer.h │ │ ├── altera_avalon_timer_regs.h │ │ ├── altera_epcq_controller2.h │ │ ├── altera_epcq_controller2_regs.h │ │ ├── i2c_opencores.h │ │ ├── i2c_opencores_regs.h │ │ ├── osd_generator_regs.h │ │ ├── pll_reconfig_regs.h │ │ └── sc_config_regs.h │ └── src │ │ ├── altera_avalon_jtag_uart_fd.c │ │ ├── altera_avalon_jtag_uart_init.c │ │ ├── altera_avalon_jtag_uart_ioctl.c │ │ ├── altera_avalon_jtag_uart_read.c │ │ ├── altera_avalon_jtag_uart_write.c │ │ ├── altera_avalon_timer_sc.c │ │ ├── altera_avalon_timer_ts.c │ │ ├── altera_avalon_timer_vars.c │ │ ├── altera_epcq_controller2.c │ │ └── i2c_opencores.c │ ├── libhal_bsp.a │ ├── linker.h │ ├── linker.x │ ├── mem_init.mk │ ├── memory.gdb │ ├── public.mk │ ├── settings.bsp │ └── system.h ├── sys.qsys ├── sys.sopcinfo ├── tools.project └── tools ├── Makefile ├── bin2hex.c └── create_fw_img.c /.gitignore: -------------------------------------------------------------------------------- 1 | *_bb.v 2 | *_inst.v 3 | *.ppf 4 | *.qws 5 | greybox_tmp 6 | .DS_Store 7 | software/sys_controller/.cproject 8 | software/sys_controller/.force_relink 9 | software/sys_controller/.project 10 | software/sys_controller/.settings/* 11 | software/sys_controller/obj/* 12 | db/* 13 | sys/* 14 | software/sys_controller_bsp/obj/* 15 | output_files/* 16 | incremental_db/* 17 | .cproject 18 | software/*/.settings/* 19 | software/sys_controller/mem_init/hdl_sim/* 20 | software/sys_controller_bsp/summary.html 21 | software/sys_controller/sys_controller.objdump 22 | software/sys_controller/sys_controller.map 23 | software/sys_controller/sys_controller.elf 24 | .qsys_edit/* 25 | PLLJ_PLLSPE_INFO.txt 26 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ip/pulpino_qsys"] 2 | path = ip/pulpino_qsys 3 | url = https://github.com/marqs85/pulpino_qsys.git 4 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | Original design and code 2 | * marqs 3 | 4 | Audio add-on board, scanline improvements 5 | * borti4938 6 | 7 | Reverse LPF, scanline improvements 8 | * paulb_nl 9 | 10 | Technical advisory, testing 11 | * Fudoh 12 | 13 | Sales & support, testing 14 | * BuckoA51 15 | 16 | Profile improvements 17 | * megari 18 | 19 | Japanese translation 20 | * 511141 / lui 21 | 22 | Early testing 23 | * juji82 24 | * Konsolkongen 25 | * Edenal 26 | * NYYRIKKI 27 | * stt 28 | * oasiz 29 | -------------------------------------------------------------------------------- /ip/i2c_opencores/Docs/i2c_specs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marqs85/ossc/429b0f720178f98e96b7ab63ff79934ed6026536/ip/i2c_opencores/Docs/i2c_specs.pdf -------------------------------------------------------------------------------- /ip/i2c_opencores/HAL/inc/i2c_opencores.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_OPENCORES_H__ 2 | #define __I2C_OPENCORES_H__ 3 | 4 | 5 | #include "alt_types.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif /* __cplusplus */ 11 | 12 | #define SCL_MIN_CLKDIV 10 13 | 14 | 15 | void I2C_init(alt_u32 base,alt_u32 clk,alt_u32 speed); 16 | int I2C_start(alt_u32 base, alt_u32 add, alt_u32 read); 17 | alt_u32 I2C_read(alt_u32 base,alt_u32 last); 18 | alt_u32 I2C_write(alt_u32 base,alt_u8 data, alt_u32 last); 19 | void SPI_read(alt_u32 base, alt_u8 *rdata, int len); 20 | void SPI_write(alt_u32 base, const alt_u8 *wdata, int len); 21 | #define I2C_OK (0) 22 | #define I2C_ACK (0) 23 | #define I2C_NOACK (1) 24 | #define I2C_ABITRATION_LOST (2) 25 | 26 | #define I2C_OPENCORES_INSTANCE(name, dev) extern int alt_no_storage 27 | #define I2C_OPENCORES_INIT(name, dev) while (0) 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif /* __cplusplus */ 32 | 33 | #endif /* __I2C_OPENCORES_H__ */ 34 | -------------------------------------------------------------------------------- /ip/i2c_opencores/HAL/src/component.mk: -------------------------------------------------------------------------------- 1 | # ******************************************************************************* 2 | # * * 3 | # * License Agreement * 4 | # * * 5 | # * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 6 | # * All rights reserved. * 7 | # * * 8 | # * Permission is hereby granted, free of charge, to any person obtaining a * 9 | # * copy of this software and associated documentation files (the "Software"), * 10 | # * to deal in the Software without restriction, including without limitation * 11 | # * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | # * and/or sell copies of the Software, and to permit persons to whom the * 13 | # * Software is furnished to do so, subject to the following conditions: * 14 | # * * 15 | # * The above copyright notice and this permission notice shall be included in * 16 | # * all copies or substantial portions of the Software. * 17 | # * * 18 | # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | # * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | # * DEALINGS IN THE SOFTWARE. * 25 | # * * 26 | # * This agreement shall be governed in all respects by the laws of the State * 27 | # * of California and by the laws of the United States of America. * 28 | # * * 29 | # * Altera does not recommend, suggest or require that this reference design * 30 | # * file be used in conjunction or combination with any other product. * 31 | # ******************************************************************************* 32 | 33 | # List all source files supplied by this component. 34 | 35 | C_LIB_SRCS += i2c_opencores.c 36 | 37 | ASM_LIB_SRCS += 38 | 39 | -------------------------------------------------------------------------------- /ip/i2c_opencores/i2c_opencores.v: -------------------------------------------------------------------------------- 1 | // 2 | // fixed for 9.1 jan 21 2010 cruben 3 | // 4 | `include "timescale.v" 5 | `include "i2c_master_defines.v" 6 | 7 | module i2c_opencores 8 | ( 9 | wb_clk_i, wb_rst_i, wb_adr_i, wb_dat_i, wb_dat_o, 10 | wb_we_i, wb_stb_i, /*wb_cyc_i,*/ wb_ack_o, wb_inta_o, 11 | scl_pad_io, sda_pad_io, spi_miso_pad_i 12 | ); 13 | 14 | parameter dedicated_spi = 0; 15 | 16 | // Common bus signals 17 | input wb_clk_i; // WISHBONE clock 18 | input wb_rst_i; // WISHBONE reset 19 | 20 | // Slave signals 21 | input [2:0] wb_adr_i; // WISHBONE address input 22 | input [7:0] wb_dat_i; // WISHBONE data input 23 | output [7:0] wb_dat_o; // WISHBONE data output 24 | input wb_we_i; // WISHBONE write enable input 25 | input wb_stb_i; // WISHBONE strobe input 26 | //input wb_cyc_i; // WISHBONE cycle input 27 | output wb_ack_o; // WISHBONE acknowledge output 28 | output wb_inta_o; // WISHBONE interrupt output 29 | 30 | // I2C signals 31 | inout scl_pad_io; // I2C clock io 32 | inout sda_pad_io; // I2C data io 33 | 34 | // SPI MISO 35 | input spi_miso_pad_i; 36 | 37 | wire wb_cyc_i; // WISHBONE cycle input 38 | // Wire tri-state scl/sda 39 | wire scl_pad_i; 40 | wire scl_pad_o; 41 | wire scl_pad_io; 42 | wire scl_padoen_o; 43 | 44 | assign wb_cyc_i = wb_stb_i; 45 | assign scl_pad_i = scl_pad_io; 46 | assign scl_pad_io = scl_padoen_o ? (dedicated_spi ? 1'b1 : 1'bZ) : scl_pad_o; 47 | 48 | wire sda_pad_i; 49 | wire sda_pad_o; 50 | wire sda_pad_io; 51 | wire sda_padoen_o; 52 | 53 | assign sda_pad_i = sda_pad_io; 54 | assign sda_pad_io = sda_padoen_o ? (dedicated_spi ? 1'b1 : 1'bZ) : sda_pad_o; 55 | 56 | // Avalon doesn't have an asynchronous reset 57 | // set it to be inactive and just use synchronous reset 58 | // reset level is a parameter, 0 is the default (active-low reset) 59 | wire arst_i; 60 | 61 | assign arst_i = 1'b1; 62 | 63 | // Connect the top level I2C core 64 | i2c_master_top #(.dedicated_spi(dedicated_spi)) i2c_master_top_inst 65 | ( 66 | .wb_clk_i(wb_clk_i), .wb_rst_i(wb_rst_i), .arst_i(arst_i), 67 | 68 | .wb_adr_i(wb_adr_i), .wb_dat_i(wb_dat_i), .wb_dat_o(wb_dat_o), 69 | .wb_we_i(wb_we_i), .wb_stb_i(wb_stb_i), .wb_cyc_i(wb_cyc_i), 70 | .wb_ack_o(wb_ack_o), .wb_inta_o(wb_inta_o), 71 | 72 | .scl_pad_i(scl_pad_i), .scl_pad_o(scl_pad_o), .scl_padoen_o(scl_padoen_o), 73 | .sda_pad_i(sda_pad_i), .sda_pad_o(sda_pad_o), .sda_padoen_o(sda_padoen_o), 74 | .spi_miso_pad_i(spi_miso_pad_i) 75 | ); 76 | 77 | endmodule 78 | -------------------------------------------------------------------------------- /ip/i2c_opencores/i2c_opencores_sw.tcl: -------------------------------------------------------------------------------- 1 | # 2 | # opencores_i2c_sw.tcl 3 | # 4 | 5 | # Create a new driver 6 | create_driver i2c_opencores_driver 7 | 8 | # Associate it with some hardware known as "opencores_i2c" 9 | set_sw_property hw_class_name i2c_opencores 10 | 11 | # The version of this driver 12 | set_sw_property version 11.0 13 | 14 | # This driver may be incompatible with versions of hardware less 15 | # than specified below. Updates to hardware and device drivers 16 | # rendering the driver incompatible with older versions of 17 | # hardware are noted with this property assignment. 18 | # 19 | # Multiple-Version compatibility was introduced in version 7.1; 20 | # prior versions are therefore excluded. 21 | set_sw_property min_compatible_hw_version 7.1 22 | 23 | # Initialize the driver in alt_sys_init() 24 | set_sw_property auto_initialize true 25 | 26 | # Location in generated BSP that above sources will be copied into 27 | set_sw_property bsp_subdirectory drivers 28 | 29 | 30 | # Interrupt properties: 31 | # This peripheral has an IRQ output but the driver doesn't currently 32 | # have any interrupt service routine. To ensure that the BSP tools 33 | # do not otherwise limit the BSP functionality for users of the 34 | # Nios II enhanced interrupt port, these settings advertise 35 | # compliance with both legacy and enhanced interrupt APIs, and to state 36 | # that any driver ISR supports preemption. If an interrupt handler 37 | # is added to this driver, these must be re-examined for validity. 38 | set_sw_property isr_preemption_supported true 39 | set_sw_property supported_interrupt_apis "legacy_interrupt_api enhanced_interrupt_api" 40 | 41 | # 42 | # Source file listings... 43 | # 44 | 45 | # C/C++ source files 46 | add_sw_property c_source HAL/src/i2c_opencores.c 47 | 48 | # Include files 49 | add_sw_property include_source HAL/inc/i2c_opencores.h 50 | add_sw_property include_source inc/i2c_opencores_regs.h 51 | 52 | # This driver supports HAL & UCOSII BSP (OS) types 53 | add_sw_property supported_bsp_type HAL 54 | add_sw_property supported_bsp_type UCOSII 55 | 56 | # End of file 57 | -------------------------------------------------------------------------------- /ip/i2c_opencores/timescale.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 10ps 2 | 3 | -------------------------------------------------------------------------------- /ip/osd_generator/bin/ASCII_KANA_8x8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marqs85/ossc/429b0f720178f98e96b7ab63ff79934ed6026536/ip/osd_generator/bin/ASCII_KANA_8x8.bin -------------------------------------------------------------------------------- /ip/osd_generator/bin/IBM_VGA_8x8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marqs85/ossc/429b0f720178f98e96b7ab63ff79934ed6026536/ip/osd_generator/bin/IBM_VGA_8x8.bin -------------------------------------------------------------------------------- /ip/osd_generator/inc/osd_generator_regs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2019-2020 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef OSD_GENERATOR_REGS_H_ 21 | #define OSD_GENERATOR_REGS_H_ 22 | 23 | #define OSD_CHAR_ROWS 30 24 | #define OSD_CHAR_COLS 16 25 | #define OSD_CHAR_SECTIONS 2 26 | 27 | #include 28 | 29 | typedef union { 30 | struct { 31 | uint8_t enable:1; 32 | uint8_t status_refresh:1; 33 | uint8_t menu_active:1; 34 | uint8_t status_timeout:2; 35 | uint8_t x_offset:3; 36 | uint8_t y_offset:3; 37 | uint8_t x_size:2; 38 | uint8_t y_size:2; 39 | uint8_t border_color:2; 40 | uint32_t osd_rsv:15; 41 | } __attribute__((packed, __may_alias__)); 42 | uint32_t data; 43 | } osd_config_reg; 44 | 45 | // char regs 46 | typedef struct { 47 | char data[OSD_CHAR_ROWS][OSD_CHAR_SECTIONS][OSD_CHAR_COLS]; 48 | } osd_char_array; 49 | 50 | typedef struct { 51 | uint32_t mask; 52 | } osd_enable_color_reg; 53 | 54 | typedef struct { 55 | osd_char_array osd_array; 56 | osd_config_reg osd_config; 57 | osd_enable_color_reg osd_sec_enable[OSD_CHAR_SECTIONS]; 58 | osd_enable_color_reg osd_row_color; 59 | } __attribute__((packed, __may_alias__)) osd_regs; 60 | 61 | #endif //OSD_GENERATOR_REGS_H_ 62 | -------------------------------------------------------------------------------- /ip/osd_generator/osd_generator_sw.tcl: -------------------------------------------------------------------------------- 1 | # 2 | # osd_generator_sw.tcl 3 | # 4 | 5 | # Create a new driver 6 | create_driver osd_generator_driver 7 | 8 | # Associate it with some hardware known as "opencores_i2c" 9 | set_sw_property hw_class_name osd_generator 10 | 11 | # The version of this driver 12 | set_sw_property version 1.0 13 | 14 | # This driver may be incompatible with versions of hardware less 15 | # than specified below. Updates to hardware and device drivers 16 | # rendering the driver incompatible with older versions of 17 | # hardware are noted with this property assignment. 18 | # 19 | # Multiple-Version compatibility was introduced in version 7.1; 20 | # prior versions are therefore excluded. 21 | set_sw_property min_compatible_hw_version 1.0 22 | 23 | # Initialize the driver in alt_sys_init() 24 | set_sw_property auto_initialize false 25 | 26 | # Location in generated BSP that above sources will be copied into 27 | set_sw_property bsp_subdirectory drivers 28 | 29 | 30 | # Interrupt properties: 31 | # This peripheral has an IRQ output but the driver doesn't currently 32 | # have any interrupt service routine. To ensure that the BSP tools 33 | # do not otherwise limit the BSP functionality for users of the 34 | # Nios II enhanced interrupt port, these settings advertise 35 | # compliance with both legacy and enhanced interrupt APIs, and to state 36 | # that any driver ISR supports preemption. If an interrupt handler 37 | # is added to this driver, these must be re-examined for validity. 38 | set_sw_property isr_preemption_supported true 39 | set_sw_property supported_interrupt_apis "legacy_interrupt_api enhanced_interrupt_api" 40 | 41 | # 42 | # Source file listings... 43 | # 44 | 45 | # C/C++ source files 46 | 47 | # Include files 48 | add_sw_property include_source inc/osd_generator_regs.h 49 | 50 | # This driver supports HAL & UCOSII BSP (OS) types 51 | add_sw_property supported_bsp_type HAL 52 | add_sw_property supported_bsp_type UCOSII 53 | 54 | # End of file 55 | -------------------------------------------------------------------------------- /ip/pll_reconfig/inc/pll_reconfig_regs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2019 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef PLL_RECONFIG_REGS_H_ 21 | #define PLL_RECONFIG_REGS_H_ 22 | 23 | #include 24 | 25 | typedef union { 26 | struct { 27 | alt_u8 reset:1; 28 | alt_u8 update:1; 29 | alt_u8 t_config_id:4; 30 | alt_u32 pll_reconfig_rsv:21; 31 | alt_u8 c_config_id:4; 32 | alt_u8 busy:1; 33 | } __attribute__((packed, __may_alias__)); 34 | alt_u32 data; 35 | } pll_config_status_reg; 36 | 37 | // char regs 38 | typedef struct { 39 | char data[160]; 40 | } pll_config_data_regs; 41 | 42 | typedef struct { 43 | pll_config_status_reg pll_config_status; 44 | pll_config_data_regs pll_config_data; 45 | } __attribute__((packed, __may_alias__)) pll_reconfig_regs; 46 | 47 | #endif //OSD_GENERATOR_REGS_H_ 48 | -------------------------------------------------------------------------------- /ip/pll_reconfig/pll_reconfig_sw.tcl: -------------------------------------------------------------------------------- 1 | # 2 | # pll_reconfig_sw.tcl 3 | # 4 | 5 | # Create a new driver 6 | create_driver pll_reconfig_driver 7 | 8 | # Associate it with some hardware known as "opencores_i2c" 9 | set_sw_property hw_class_name pll_reconfig 10 | 11 | # The version of this driver 12 | set_sw_property version 1.0 13 | 14 | # This driver may be incompatible with versions of hardware less 15 | # than specified below. Updates to hardware and device drivers 16 | # rendering the driver incompatible with older versions of 17 | # hardware are noted with this property assignment. 18 | # 19 | # Multiple-Version compatibility was introduced in version 7.1; 20 | # prior versions are therefore excluded. 21 | set_sw_property min_compatible_hw_version 7.1 22 | 23 | # Initialize the driver in alt_sys_init() 24 | set_sw_property auto_initialize false 25 | 26 | # Location in generated BSP that above sources will be copied into 27 | set_sw_property bsp_subdirectory drivers 28 | 29 | 30 | # Interrupt properties: 31 | # This peripheral has an IRQ output but the driver doesn't currently 32 | # have any interrupt service routine. To ensure that the BSP tools 33 | # do not otherwise limit the BSP functionality for users of the 34 | # Nios II enhanced interrupt port, these settings advertise 35 | # compliance with both legacy and enhanced interrupt APIs, and to state 36 | # that any driver ISR supports preemption. If an interrupt handler 37 | # is added to this driver, these must be re-examined for validity. 38 | set_sw_property isr_preemption_supported true 39 | set_sw_property supported_interrupt_apis "legacy_interrupt_api enhanced_interrupt_api" 40 | 41 | # 42 | # Source file listings... 43 | # 44 | 45 | # C/C++ source files 46 | 47 | # Include files 48 | add_sw_property include_source inc/pll_reconfig_regs.h 49 | 50 | # This driver supports HAL & UCOSII BSP (OS) types 51 | add_sw_property supported_bsp_type HAL 52 | add_sw_property supported_bsp_type UCOSII 53 | 54 | # End of file 55 | -------------------------------------------------------------------------------- /ip/sc_config/sc_config_sw.tcl: -------------------------------------------------------------------------------- 1 | # 2 | # opencores_i2c_sw.tcl 3 | # 4 | 5 | # Create a new driver 6 | create_driver sc_config_driver 7 | 8 | # Associate it with some hardware known as "opencores_i2c" 9 | set_sw_property hw_class_name sc_config 10 | 11 | # The version of this driver 12 | set_sw_property version 1.0 13 | 14 | # This driver may be incompatible with versions of hardware less 15 | # than specified below. Updates to hardware and device drivers 16 | # rendering the driver incompatible with older versions of 17 | # hardware are noted with this property assignment. 18 | # 19 | # Multiple-Version compatibility was introduced in version 7.1; 20 | # prior versions are therefore excluded. 21 | set_sw_property min_compatible_hw_version 1.0 22 | 23 | # Initialize the driver in alt_sys_init() 24 | set_sw_property auto_initialize false 25 | 26 | # Location in generated BSP that above sources will be copied into 27 | set_sw_property bsp_subdirectory drivers 28 | 29 | 30 | # Interrupt properties: 31 | # This peripheral has an IRQ output but the driver doesn't currently 32 | # have any interrupt service routine. To ensure that the BSP tools 33 | # do not otherwise limit the BSP functionality for users of the 34 | # Nios II enhanced interrupt port, these settings advertise 35 | # compliance with both legacy and enhanced interrupt APIs, and to state 36 | # that any driver ISR supports preemption. If an interrupt handler 37 | # is added to this driver, these must be re-examined for validity. 38 | set_sw_property isr_preemption_supported true 39 | set_sw_property supported_interrupt_apis "legacy_interrupt_api enhanced_interrupt_api" 40 | 41 | # 42 | # Source file listings... 43 | # 44 | 45 | # C/C++ source files 46 | 47 | # Include files 48 | add_sw_property include_source inc/sc_config_regs.h 49 | 50 | # This driver supports HAL & UCOSII BSP (OS) types 51 | add_sw_property supported_bsp_type HAL 52 | add_sw_property supported_bsp_type UCOSII 53 | 54 | # End of file 55 | -------------------------------------------------------------------------------- /ossc.cof: -------------------------------------------------------------------------------- 1 | 2 | 3 | EPCS16 4 | EP4CE15 5 | output_files/ossc.jic 6 | 1 7 | 1 8 | 7 9 | 10 | Page_0 11 | 1 12 | 13 | output_files/ossc.sof1 14 | 15 | 16 | 10 17 | 0 18 | 0 19 | 0 20 | 1 21 | 22 | 0 23 | 24 | 25 | 0 26 | 2 27 | 0 28 | -1 29 | -1 30 | 1 31 | 32 | -------------------------------------------------------------------------------- /ossc.qpf: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- # 2 | # 3 | # Copyright (C) 1991-2013 Altera Corporation 4 | # Your use of Altera Corporation's design tools, logic functions 5 | # and other software and tools, and its AMPP partner logic 6 | # functions, and any output files from any of the foregoing 7 | # (including device programming or simulation files), and any 8 | # associated documentation or information are expressly subject 9 | # to the terms and conditions of the Altera Program License 10 | # Subscription Agreement, Altera MegaCore Function License 11 | # Agreement, or other applicable license agreement, including, 12 | # without limitation, that your use is for the sole purpose of 13 | # programming logic devices manufactured by Altera and sold by 14 | # Altera or its authorized distributors. Please refer to the 15 | # applicable agreement for further details. 16 | # 17 | # -------------------------------------------------------------------------- # 18 | # 19 | # Quartus II 64-Bit 20 | # Version 13.1.0 Build 162 10/23/2013 SJ Web Edition 21 | # Date created = 17:27:03 May 17, 2014 22 | # 23 | # -------------------------------------------------------------------------- # 24 | 25 | QUARTUS_VERSION = "13.1" 26 | DATE = "17:27:03 May 17, 2014" 27 | 28 | # Revisions 29 | 30 | PROJECT_REVISION = "ossc" 31 | -------------------------------------------------------------------------------- /ossc.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /rtl/char_array.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name IP_TOOL_NAME "RAM: 2-PORT" 2 | set_global_assignment -name IP_TOOL_VERSION "23.1" 3 | set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{Cyclone IV E}" 4 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "char_array.v"] 5 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "char_array_inst.v"] 6 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "char_array_bb.v"] 7 | -------------------------------------------------------------------------------- /rtl/char_rom.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name IP_TOOL_NAME "ROM: 1-PORT" 2 | set_global_assignment -name IP_TOOL_VERSION "23.1" 3 | set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{Cyclone IV E}" 4 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "char_rom.v"] 5 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "char_rom_inst.v"] 6 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "char_rom_bb.v"] 7 | -------------------------------------------------------------------------------- /rtl/lat_tester_includes.v: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2017 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | `define LT_POS_NONE 2'b00 21 | `define LT_POS_TOPLEFT 2'b01 22 | `define LT_POS_CENTER 2'b10 23 | `define LT_POS_BOTTOMRIGHT 2'b11 24 | 25 | `define LT_WIDTH_DIV 4'h8 26 | `define LT_HEIGHT_DIV 4'h8 27 | -------------------------------------------------------------------------------- /rtl/linebuf.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name IP_TOOL_NAME "RAM: 2-PORT" 2 | set_global_assignment -name IP_TOOL_VERSION "23.1" 3 | set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{Cyclone IV E}" 4 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "linebuf.v"] 5 | -------------------------------------------------------------------------------- /rtl/lpm_mult_8x5_9.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name IP_TOOL_NAME "LPM_MULT" 2 | set_global_assignment -name IP_TOOL_VERSION "23.1" 3 | set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{Cyclone IV E}" 4 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "lpm_mult_8x5_9.v"] 5 | -------------------------------------------------------------------------------- /rtl/lpm_mult_sl.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name IP_TOOL_NAME "LPM_MULT" 2 | set_global_assignment -name IP_TOOL_VERSION "23.1" 3 | set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{Cyclone IV E}" 4 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "lpm_mult_sl.v"] 5 | -------------------------------------------------------------------------------- /rtl/pll_2x.ppf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /rtl/pll_2x.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name IP_TOOL_NAME "ALTPLL" 2 | set_global_assignment -name IP_TOOL_VERSION "23.1" 3 | set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{Cyclone IV E}" 4 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "pll_2x.v"] 5 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "pll_2x.ppf"] 6 | -------------------------------------------------------------------------------- /rtl/timescale.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 10ps 2 | 3 | -------------------------------------------------------------------------------- /scripts/qsys.patch: -------------------------------------------------------------------------------- 1 | --- sys/synthesis/submodules/altera_asmi2_xip_controller.sv 2024-07-15 02:34:49.476724296 +0300 2 | +++ sys/synthesis/submodules/altera_asmi2_xip_controller.sv 2024-07-15 02:50:24.750038794 +0300 3 | @@ -611,7 +611,7 @@ 4 | .USE_PACKETS (1), 5 | .USE_FILL_LEVEL (0), 6 | .EMPTY_LATENCY (3), 7 | - .USE_MEMORY_BLOCKS (1), 8 | + .USE_MEMORY_BLOCKS (0), 9 | .USE_STORE_FORWARD (0), 10 | .USE_ALMOST_FULL_IF (0), 11 | .USE_ALMOST_EMPTY_IF (0) 12 | 13 | --- sys/synthesis/submodules/sys_master_0.v 2024-07-15 02:34:47.396703537 +0300 14 | +++ sys/synthesis/submodules/sys_master_0.v 2024-07-15 02:50:14.617938092 +0300 15 | @@ -163,7 +163,7 @@ 16 | .USE_PACKETS (0), 17 | .USE_FILL_LEVEL (0), 18 | .EMPTY_LATENCY (3), 19 | - .USE_MEMORY_BLOCKS (1), 20 | + .USE_MEMORY_BLOCKS (0), 21 | .USE_STORE_FORWARD (0), 22 | .USE_ALMOST_FULL_IF (0), 23 | .USE_ALMOST_EMPTY_IF (0) 24 | 25 | --- sys/synthesis/submodules/sys_onchip_memory2_0.v 2024-07-15 02:34:47.540704974 +0300 26 | +++ sys/synthesis/submodules/sys_onchip_memory2_0.v 2024-07-15 02:49:59.685789671 +0300 27 | @@ -71,7 +71,7 @@ 28 | defparam the_altsyncram.byte_size = 8, 29 | the_altsyncram.init_file = INIT_FILE, 30 | the_altsyncram.lpm_type = "altsyncram", 31 | - the_altsyncram.maximum_depth = 10496, 32 | + the_altsyncram.maximum_depth = 2048, 33 | the_altsyncram.numwords_a = 10496, 34 | the_altsyncram.operation_mode = "SINGLE_PORT", 35 | the_altsyncram.outdata_reg_a = "UNREGISTERED", 36 | -------------------------------------------------------------------------------- /scripts/reprogram.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | jtagconfig 4 | make rv-reprogram 5 | 6 | if [ $# -eq 1 ] && [ $1 = "jtag_uart" ] && [ $(pgrep -c nios2-terminal) = 0 ]; then 7 | nios2-terminal 8 | fi 9 | -------------------------------------------------------------------------------- /scripts/rv-reprogram.tcl: -------------------------------------------------------------------------------- 1 | #Select the master service type and check for available service paths. 2 | while 1 { 3 | set service_paths [get_service_paths master] 4 | if {[llength $service_paths] > 0} { 5 | break 6 | } 7 | puts "Refreshing connections..." 8 | refresh_connections 9 | after 100 10 | } 11 | 12 | #Set the master service path. 13 | set master_service_path [lindex $service_paths 0] 14 | 15 | #Open the master service. 16 | set claim_path [claim_service master $master_service_path mylib] 17 | 18 | puts "Halting CPU" 19 | master_write_32 $claim_path 0x0 0x10000 20 | 21 | puts "Writing block RAM" 22 | master_write_from_file $claim_path mem_init/sys_onchip_memory2_0.bin 0x10000 23 | 24 | close_service master $claim_path 25 | 26 | 27 | set jtag_debug_list [get_service_paths jtag_debug] 28 | set jd [ lindex $jtag_debug_list 0 ] 29 | open_service jtag_debug $jd 30 | puts "Resetting system" 31 | jtag_debug_reset_system $jd 32 | close_service jtag_debug $jd 33 | puts "Done" 34 | -------------------------------------------------------------------------------- /software/sys_controller/crt0.boot.S: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ETH Zurich and University of Bologna. 2 | // Copyright and related rights are licensed under the Solderpad Hardware 3 | // License, Version 0.51 (the “License”); you may not use this file except in 4 | // compliance with the License. You may obtain a copy of the License at 5 | // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law 6 | // or agreed to in writing, software, hardware and materials distributed under 7 | // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 8 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | // specific language governing permissions and limitations under the License. 10 | 11 | #include "pulpino.h" 12 | 13 | #define EXCEPTION_STACK_SIZE 72 14 | 15 | 16 | /* ========================================================= [ entry ] === */ 17 | .section .text 18 | 19 | default_exc_handler: 20 | jal x0, default_exc_handler 21 | 22 | reset_handler: 23 | /* set all registers to zero */ 24 | mv x1, x0 25 | mv x2, x1 26 | mv x3, x1 27 | mv x4, x1 28 | mv x5, x1 29 | mv x6, x1 30 | mv x7, x1 31 | mv x8, x1 32 | mv x9, x1 33 | mv x10, x1 34 | mv x11, x1 35 | mv x12, x1 36 | mv x13, x1 37 | mv x14, x1 38 | mv x15, x1 39 | mv x16, x1 40 | mv x17, x1 41 | mv x18, x1 42 | mv x19, x1 43 | mv x20, x1 44 | mv x21, x1 45 | mv x22, x1 46 | mv x23, x1 47 | mv x24, x1 48 | mv x25, x1 49 | mv x26, x1 50 | mv x27, x1 51 | mv x28, x1 52 | mv x29, x1 53 | mv x30, x1 54 | mv x31, x1 55 | 56 | /* stack initilization */ 57 | la x2, _stack_start 58 | 59 | _start: 60 | .global _start 61 | 62 | /* clear BSS */ 63 | la x26, _bss_start 64 | la x27, _bss_end 65 | 66 | bge x26, x27, zero_loop_end 67 | 68 | zero_loop: 69 | sw x0, 0(x26) 70 | addi x26, x26, 4 71 | ble x26, x27, zero_loop 72 | zero_loop_end: 73 | 74 | 75 | main_entry: 76 | /* jump to alt_main program entry point */ 77 | jal alt_main 78 | 79 | /* =================================================== [ exceptions ] === */ 80 | /* This section has to be down here, since we have to disable rvc for it */ 81 | 82 | .section .vectors, "ax" 83 | .option norvc; 84 | 85 | // external interrupts are handled by the same callback 86 | // until compiler supports IRQ routines 87 | .org 0x00 88 | .rept 31 89 | nop 90 | .endr 91 | jal x0, default_exc_handler 92 | 93 | // reset vector 94 | .org 0x80 95 | jal x0, reset_handler 96 | 97 | // illegal instruction exception 98 | .org 0x84 99 | jal x0, default_exc_handler 100 | 101 | // ecall handler 102 | .org 0x88 103 | jal x0, default_exc_handler 104 | -------------------------------------------------------------------------------- /software/sys_controller/crt0.boot_E.S: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ETH Zurich and University of Bologna. 2 | // Copyright and related rights are licensed under the Solderpad Hardware 3 | // License, Version 0.51 (the “License”); you may not use this file except in 4 | // compliance with the License. You may obtain a copy of the License at 5 | // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law 6 | // or agreed to in writing, software, hardware and materials distributed under 7 | // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 8 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | // specific language governing permissions and limitations under the License. 10 | 11 | #include "pulpino.h" 12 | 13 | #define EXCEPTION_STACK_SIZE 72 14 | 15 | 16 | /* ========================================================= [ entry ] === */ 17 | .section .text 18 | 19 | default_exc_handler: 20 | jal x0, default_exc_handler 21 | 22 | reset_handler: 23 | /* set all registers to zero */ 24 | mv x1, x0 25 | mv x2, x1 26 | mv x3, x1 27 | mv x4, x1 28 | mv x5, x1 29 | mv x6, x1 30 | mv x7, x1 31 | mv x8, x1 32 | mv x9, x1 33 | mv x10, x1 34 | mv x11, x1 35 | mv x12, x1 36 | mv x13, x1 37 | mv x14, x1 38 | mv x15, x1 39 | 40 | /* stack initilization */ 41 | la x2, _stack_start 42 | 43 | _start: 44 | .global _start 45 | 46 | /* clear BSS */ 47 | la x14, _bss_start 48 | la x15, _bss_end 49 | 50 | bge x14, x15, zero_loop_end 51 | 52 | zero_loop: 53 | sw x0, 0(x14) 54 | addi x14, x14, 4 55 | ble x14, x15, zero_loop 56 | zero_loop_end: 57 | 58 | 59 | main_entry: 60 | /* jump to alt_main program entry point */ 61 | jal alt_main 62 | 63 | /* =================================================== [ exceptions ] === */ 64 | /* This section has to be down here, since we have to disable rvc for it */ 65 | 66 | .section .vectors, "ax" 67 | .option norvc; 68 | 69 | // external interrupts are handled by the same callback 70 | // until compiler supports IRQ routines 71 | .org 0x00 72 | .rept 31 73 | nop 74 | .endr 75 | jal x0, default_exc_handler 76 | 77 | // reset vector 78 | .org 0x80 79 | jal x0, reset_handler 80 | 81 | // illegal instruction exception 82 | .org 0x84 83 | jal x0, default_exc_handler 84 | 85 | // ecall handler 86 | .org 0x88 87 | jal x0, default_exc_handler 88 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/HDMI_COMMON.h: -------------------------------------------------------------------------------- 1 | #ifndef HDMI_COMMON_H_ 2 | #define HDMI_COMMON_H_ 3 | 4 | typedef enum{ 5 | COLOR_RGB444 = 0, 6 | COLOR_YUV422, 7 | COLOR_YUV444, 8 | COLOR_MODE_NUM 9 | }COLOR_TYPE; 10 | 11 | #endif /*HDMI_COMMON_H_*/ 12 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/HDMI_TX.h: -------------------------------------------------------------------------------- 1 | #ifndef HDMI_TX_H_ 2 | #define HDMI_TX_H_ 3 | 4 | #include "HDMI_COMMON.h" 5 | #include "alt_types.h" 6 | #include "hdmitx.h" 7 | 8 | 9 | 10 | bool HDMITX_Init(void); 11 | bool HDMITX_ChipVerify(void); 12 | bool HDMITX_HPD(void); 13 | void HDMITX_ChangeVideoTiming(int VIC); 14 | void HDMITX_ChangeVideoTimingAndColor(int VIC, COLOR_TYPE Color); 15 | void HDMITX_SetAVIInfoFrame(alt_u8 VIC, alt_u8 OutputColorMode, bool b16x9, bool ITU709, bool ITC, alt_u8 pixelrep); 16 | 17 | void HDMITX_DisableVideoOutput(void); 18 | void HDMITX_EnableVideoOutput(void); 19 | void HDMITX_SetColorSpace(COLOR_TYPE InputColor, COLOR_TYPE OutputColor); 20 | bool HDMITX_DevLoopProc(void); 21 | 22 | bool HDMITX_IsSinkSupportYUV444(void); 23 | bool HDMITX_IsSinkSupportYUV422(void); 24 | 25 | bool HDMITX_IsSinkSupportColorDepth36(void); 26 | bool HDMITX_IsSinkSupportColorDepth30(void); 27 | void HDMITX_SetOutputColorDepth(int ColorDepth); 28 | 29 | void HDMITX_SetAudioInfoFrame(BYTE bAudioDwSampling); 30 | void HDMITX_SetHDRInfoFrame(BYTE enableHDR); 31 | void HDMITX_SetVRRInfoFrame(BYTE enable); 32 | 33 | #endif /*HDMI_TX_H_*/ 34 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/edid.h: -------------------------------------------------------------------------------- 1 | #ifndef _EDID_H_ 2 | #define _EDID_H_ 3 | 4 | #include "hdmitx.h" 5 | 6 | #ifdef SUPPORT_EDID 7 | 8 | ///////////////////////////////////////// 9 | // RX Capability. 10 | ///////////////////////////////////////// 11 | typedef struct { 12 | BYTE b16bit:1 ; 13 | BYTE b20bit:1 ; 14 | BYTE b24bit:1 ; 15 | BYTE Rsrv:5 ; 16 | } LPCM_BitWidth ; 17 | 18 | typedef enum { 19 | AUD_RESERVED_0 = 0 , 20 | AUD_LPCM, 21 | AUD_AC3, 22 | AUD_MPEG1, 23 | AUD_MP3, 24 | AUD_MPEG2, 25 | AUD_AAC, 26 | AUD_DTS, 27 | AUD_ATRAC, 28 | AUD_ONE_BIT_AUDIO, 29 | AUD_DOLBY_DIGITAL_PLUS, 30 | AUD_DTS_HD, 31 | AUD_MAT_MLP, 32 | AUD_DST, 33 | AUD_WMA_PRO, 34 | AUD_RESERVED_15 35 | } AUDIO_FORMAT_CODE ; 36 | 37 | typedef union { 38 | struct { 39 | BYTE channel:3 ; 40 | BYTE AudioFormatCode:4 ; 41 | BYTE Rsrv1:1 ; 42 | 43 | BYTE b32KHz:1 ; 44 | BYTE b44_1KHz:1 ; 45 | BYTE b48KHz:1 ; 46 | BYTE b88_2KHz:1 ; 47 | BYTE b96KHz:1 ; 48 | BYTE b176_4KHz:1 ; 49 | BYTE b192KHz:1 ; 50 | BYTE Rsrv2:1 ; 51 | BYTE ucCode ; 52 | } s ; 53 | BYTE uc[3] ; 54 | 55 | } AUDDESCRIPTOR ; 56 | 57 | typedef union { 58 | struct { 59 | BYTE FL_FR:1 ; 60 | BYTE LFE:1 ; 61 | BYTE FC:1 ; 62 | BYTE RL_RR:1 ; 63 | BYTE RC:1 ; 64 | BYTE FLC_FRC:1 ; 65 | BYTE RLC_RRC:1 ; 66 | BYTE Reserve:1 ; 67 | BYTE Unuse[2] ; 68 | } s ; 69 | BYTE uc[3] ; 70 | } SPK_ALLOC ; 71 | 72 | #define CEA_SUPPORT_UNDERSCAN (1<<7) 73 | #define CEA_SUPPORT_AUDIO (1<<6) 74 | #define CEA_SUPPORT_YUV444 (1<<5) 75 | #define CEA_SUPPORT_YUV422 (1<<4) 76 | #define CEA_NATIVE_MASK 0xF 77 | 78 | typedef union _tag_DCSUPPORT { 79 | struct { 80 | BYTE DVI_Dual:1 ; 81 | BYTE Rsvd:2 ; 82 | BYTE DC_Y444:1 ; 83 | BYTE DC_30Bit:1 ; 84 | BYTE DC_36Bit:1 ; 85 | BYTE DC_48Bit:1 ; 86 | BYTE SUPPORT_AI:1 ; 87 | } info ; 88 | BYTE uc ; 89 | } DCSUPPORT ; // Richard Note: Color Depth 90 | 91 | typedef union _LATENCY_SUPPORT{ 92 | struct { 93 | BYTE Rsvd:6 ; 94 | BYTE I_Latency_Present:1 ; 95 | BYTE Latency_Present:1 ; 96 | } info ; 97 | BYTE uc ; 98 | } LATENCY_SUPPORT ; 99 | 100 | #define HDMI_IEEEOUI 0x0c03 101 | 102 | typedef struct _RX_CAP{ 103 | BYTE Valid; // richard add 104 | BYTE VideoMode ; 105 | BYTE VDOModeCount ; 106 | BYTE idxNativeVDOMode ; 107 | BYTE VDOMode[128] ; 108 | BYTE AUDDesCount ; 109 | AUDDESCRIPTOR AUDDes[32] ; 110 | ULONG IEEEOUI ; 111 | DCSUPPORT dc ; 112 | BYTE MaxTMDSClock ; 113 | LATENCY_SUPPORT lsupport ; 114 | BYTE V_Latency ; 115 | BYTE A_Latency ; 116 | BYTE V_I_Latency ; 117 | BYTE A_I_Latency ; 118 | SPK_ALLOC SpeakerAllocBlk ; 119 | BYTE ValidCEA:1 ; 120 | BYTE ValidHDMI:1 ; 121 | } RX_CAP ; 122 | 123 | SYS_STATUS ParseVESAEDID(BYTE *pEDID) ; 124 | SYS_STATUS ParseCEAEDID(BYTE *pCEAEDID, RX_CAP *pRxCap) ; 125 | 126 | 127 | 128 | #endif // SUPPORT_EDID 129 | #endif // _EDID_H_ 130 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/hdmitx.h: -------------------------------------------------------------------------------- 1 | #ifndef _HDMITX_H_ 2 | #define _HDMITX_H_ 3 | 4 | #ifdef EXTERN_HDCPROM 5 | #pragma message("Defined EXTERN_HDCPROM") 6 | #endif // EXTERN_HDCPROM 7 | 8 | #define SUPPORT_EDID 9 | //#define SUPPORT_HDCP 10 | #define SUPPORT_INPUTRGB 11 | //#define SUPPORT_INPUTYUV444 12 | //#define SUPPORT_INPUTYUV422 13 | //#define SUPPORT_SYNCEMBEDDED 14 | //#define SUPPORT_DEGEN 15 | //#define SUPPORT_INPUTYUV // richard add 16 | //#define INVERT_VID_LATCHEDGE //latch at falling edge 17 | 18 | 19 | #ifdef SUPPORT_SYNCEMBEDDED 20 | #pragma message("defined SUPPORT_SYNCEMBEDDED for Sync Embedded timing input or CCIR656 input.") 21 | #endif 22 | 23 | #ifndef _MCU_ // DSSSHA need large computation data rather than 8051 supported. 24 | #define SUPPORT_DSSSHA 25 | #endif 26 | 27 | #if defined(SUPPORT_INPUTYUV444) || defined(SUPPORT_INPUTYUV422) 28 | #define SUPPORT_INPUTYUV 29 | #endif 30 | 31 | /*#ifdef _MCU_ 32 | #include "mcu.h" 33 | #else // not MCU 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include "ioaccess.h" 41 | #include "install.h" 42 | #include "pc.h" 43 | #endif // MCU*/ 44 | 45 | #include "typedef.h" 46 | #include "HDMI_COMMON.h" 47 | /*typedef unsigned char BYTE; 48 | #define _CODE const 49 | #define SYS_STATUS unsigned int 50 | #define TRUE 1 51 | #define FALSE 0*/ 52 | //#define NULL 0 53 | 54 | //typedef unsigned char bool; 55 | typedef unsigned char bool; 56 | #include "sysconfig.h" 57 | 58 | // Hardwired to CPU reset 59 | #define HDMITX_Reset(x) 60 | 61 | #ifndef SUPPORT_HDCP 62 | static SYS_STATUS 63 | HDCP_Authenticate() 64 | { 65 | return ER_SUCCESS; 66 | } 67 | 68 | static void 69 | HDCP_ResetAuth() 70 | { 71 | return; 72 | } 73 | 74 | static void 75 | HDCP_ResumeAuthentication() 76 | { 77 | return; 78 | } 79 | #endif 80 | 81 | void DelayMS(unsigned int ms); 82 | 83 | //#include "edid.h" 84 | // #include "dss_sha.h" 85 | #include "it6613_drv.h" 86 | 87 | #define HDMITX_INSTANCE_MAX 1 88 | 89 | #define SIZEOF_CSCMTX 18 90 | #define SIZEOF_CSCGAIN 6 91 | #define SIZEOF_CSCOFFSET 3 92 | 93 | /////////////////////////////////////////////////////////////////////// 94 | // Output Mode Type 95 | /////////////////////////////////////////////////////////////////////// 96 | 97 | #define RES_ASPEC_4x3 0 98 | #define RES_ASPEC_16x9 1 99 | #define F_MODE_REPT_NO 0 100 | #define F_MODE_REPT_TWICE 1 101 | #define F_MODE_REPT_QUATRO 3 102 | #define F_MODE_CSC_ITU601 0 103 | #define F_MODE_CSC_ITU709 1 104 | 105 | /////////////////////////////////////////////////////////////////////// 106 | // ROM OFFSET 107 | /////////////////////////////////////////////////////////////////////// 108 | #define ROMOFF_INT_TYPE 0 109 | #define ROMOFF_INPUT_VIDEO_TYPE 1 110 | #define ROMOFF_OUTPUT_AUDIO_MODE 8 111 | #define ROMOFF_AUDIO_CH_SWAP 9 112 | 113 | 114 | 115 | #define TIMER_LOOP_LEN 10 116 | #define MS(x) (((x)+(TIMER_LOOP_LEN-1))/TIMER_LOOP_LEN) ; // for timer loop 117 | 118 | 119 | 120 | #endif // _HDMITX_H_ 121 | 122 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/hdmitx_nios2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "system.h" 4 | #include "i2c_opencores.h" 5 | #include "hdmitx.h" 6 | #include "it6613.h" 7 | 8 | inline alt_u32 read_it2(alt_u32 regaddr) 9 | { 10 | I2C_start(I2CA_BASE, IT_BASE, 0); 11 | I2C_write(I2CA_BASE, regaddr, 0); 12 | I2C_start(I2CA_BASE, IT_BASE, 1); 13 | return I2C_read(I2CA_BASE,1); 14 | } 15 | 16 | inline void write_it2(alt_u32 regaddr, alt_u8 data) 17 | { 18 | I2C_start(I2CA_BASE, IT_BASE, 0); 19 | I2C_write(I2CA_BASE, regaddr, 0); 20 | I2C_write(I2CA_BASE, data, 1); 21 | } 22 | 23 | BYTE I2C_Read_Byte(BYTE Addr,BYTE RegAddr) 24 | { 25 | I2C_start(I2CA_BASE, Addr, 0); 26 | I2C_write(I2CA_BASE, RegAddr, 0); 27 | I2C_start(I2CA_BASE, Addr, 1); 28 | return I2C_read(I2CA_BASE,1); 29 | } 30 | 31 | SYS_STATUS I2C_Write_Byte(BYTE Addr,BYTE RegAddr,BYTE Data) 32 | { 33 | I2C_start(I2CA_BASE, Addr, 0); 34 | I2C_write(I2CA_BASE, RegAddr, 0); 35 | I2C_write(I2CA_BASE, Data, 1); 36 | return 0; 37 | } 38 | 39 | SYS_STATUS I2C_Read_ByteN(BYTE Addr,BYTE RegAddr,BYTE *pData,int N) 40 | { 41 | int i; 42 | 43 | for (i=0; i 2 | #include 3 | #include "system.h" 4 | #include "i2c_opencores.h" 5 | #include "it6613.h" 6 | 7 | volatile alt_u8 cur_bank; 8 | 9 | inline void select_bank_it(alt_u8 bank) { 10 | cur_bank = bank; 11 | I2C_start(I2CA_BASE, IT_BASE, 0); 12 | I2C_write(I2CA_BASE, IT_CURBANK, 0); 13 | I2C_write(I2CA_BASE, cur_bank, 1); 14 | } 15 | 16 | inline alt_u32 read_it(alt_u32 regaddr) { 17 | if ((regaddr > 0xFF) && (cur_bank == 0)) 18 | select_bank_it(1); 19 | else if ((regaddr <= 0xFF) && (cur_bank == 1)) 20 | select_bank_it(0); 21 | 22 | I2C_start(I2CA_BASE, IT_BASE, 0); 23 | I2C_write(I2CA_BASE, (regaddr & 0xFF), 1); 24 | I2C_start(I2CA_BASE, IT_BASE, 1); 25 | return I2C_read(I2CA_BASE,1); 26 | } 27 | 28 | inline void write_it(alt_u32 regaddr, alt_u8 data) { 29 | if ((regaddr > 0xFF) && (cur_bank == 0)) 30 | select_bank_it(1); 31 | else if ((regaddr <= 0xFF) && (cur_bank == 1)) 32 | select_bank_it(0); 33 | 34 | I2C_start(I2CA_BASE, IT_BASE, 0); 35 | I2C_write(I2CA_BASE, (regaddr & 0xFF), 0); 36 | I2C_write(I2CA_BASE, data, 1); 37 | } 38 | 39 | /*inline void reset_it() { 40 | usleep(100000); 41 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x00); 42 | usleep(100000); 43 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x01); 44 | usleep(100000); 45 | }*/ 46 | 47 | int init_it() { 48 | alt_u32 vendor_id, device_id; 49 | alt_u32 i; 50 | 51 | cur_bank = 0; 52 | select_bank_it(cur_bank); 53 | 54 | vendor_id = read_it(IT_VENDORID); 55 | device_id = read_it(IT_DEVICEID); 56 | 57 | printf("VEN: 0x%.2lX, DEV: 0x%.2lX\n", vendor_id, device_id); 58 | 59 | if (!((vendor_id == IT6613_VENDORID) && (device_id == IT6613_DEVICEID))) 60 | return -1; 61 | 62 | write_it(REG_TX_SW_RST,B_REF_RST|B_VID_RST|B_AUD_RST|B_AREF_RST|B_HDCP_RST) ; 63 | usleep(1000); 64 | write_it(REG_TX_SW_RST,B_VID_RST|B_AUD_RST|B_AREF_RST|B_HDCP_RST) ; 65 | 66 | write_it(IT_DRIVECTRL, 0x10); 67 | 68 | write_it(IT_HDMIMODE, 0); 69 | for (i=0xC1; i<=0xD0; i++) 70 | write_it(i, 0); 71 | 72 | write_it(IT_OUTCOLOR, 0); 73 | 74 | // enable video 75 | //HDMITX_WriteI2C_Byte(REG_TX_SW_RST,B_VID_RST|B_AUD_RST|B_AREF_RST|B_HDCP_RST) ; 76 | 77 | write_it(REG_TX_SW_RST, B_AUD_RST|B_AREF_RST|B_HDCP_RST) ; 78 | usleep(1000); 79 | 80 | 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/it6613.h: -------------------------------------------------------------------------------- 1 | #ifndef IT6613_H_ 2 | #define IT6613_H_ 3 | 4 | #include "sysconfig.h" 5 | 6 | #define IT6613_VENDORID 0xCA 7 | #define IT6613_DEVICEID 0x13 8 | 9 | #define IT_BASE (0x98>>1) 10 | #define IT_VENDORID 0x01 11 | #define IT_DEVICEID 0x02 12 | #define IT_RESET 0x04 13 | #define IT_CURBANK 0x0F 14 | #define IT_DRIVECTRL 0x61 15 | #define IT_HDMIMODE 0xC0 16 | #define IT_OUTCOLOR 0x158 17 | 18 | #define REG_TX_SW_RST 0x04 19 | #define B_ENTEST (1<<7) 20 | #define B_REF_RST (1<<5) 21 | #define B_AREF_RST (1<<4) 22 | #define B_VID_RST (1<<3) 23 | #define B_AUD_RST (1<<2) 24 | #define B_HDMI_RST (1<<1) 25 | #define B_HDCP_RST (1<<0) 26 | 27 | #endif /* IT6613_H_ */ 28 | -------------------------------------------------------------------------------- /software/sys_controller/it6613/it6613_sys.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAT6611_SYS_H_ 2 | #define _CAT6611_SYS_H_ 3 | //////////////////////////////////////////////////////////////////////////////// 4 | // Internal Data Type 5 | //////////////////////////////////////////////////////////////////////////////// 6 | 7 | typedef enum tagHDMI_Video_Type { 8 | HDMI_Unknown = 0 , 9 | HDMI_640x480p60 = 1 , 10 | HDMI_480p60, 11 | HDMI_480p60_16x9, 12 | HDMI_720p60, 13 | HDMI_1080i60, 14 | HDMI_480i60, 15 | HDMI_480i60_16x9, 16 | HDMI_240p60, 17 | HDMI_1080p60 = 16, 18 | HDMI_576p50, 19 | HDMI_576p50_16x9, 20 | HDMI_720p50 = 19, 21 | HDMI_1080i50, 22 | HDMI_576i50, 23 | HDMI_576i50_16x9, 24 | HDMI_288p50, 25 | HDMI_1080p50 = 31, 26 | /*HDMI_1080p24, 27 | HDMI_1080p25, 28 | HDMI_1080p30, 29 | HDMI_1080i120 = 46,*/ // richard add 30 | } HDMI_Video_Type ; 31 | 32 | typedef enum tagHDMI_Aspec { 33 | HDMI_4x3 , 34 | HDMI_16x9 35 | } HDMI_Aspec; 36 | 37 | typedef enum tagHDMI_OutputColorMode { 38 | HDMI_RGB444, 39 | HDMI_YUV444, 40 | HDMI_YUV422 41 | } HDMI_OutputColorMode ; 42 | 43 | typedef enum tagHDMI_Colorimetry { 44 | HDMI_ITU601, 45 | HDMI_ITU709 46 | } HDMI_Colorimetry ; 47 | 48 | /////////////////////////////////////////////////////////////////////// 49 | // Output Mode Type 50 | /////////////////////////////////////////////////////////////////////// 51 | 52 | #define RES_ASPEC_4x3 0 53 | #define RES_ASPEC_16x9 1 54 | #define F_MODE_REPT_NO 0 55 | #define F_MODE_REPT_TWICE 1 56 | #define F_MODE_REPT_QUATRO 3 57 | #define F_MODE_CSC_ITU601 0 58 | #define F_MODE_CSC_ITU709 1 59 | 60 | void HDMITX_ChangeDisplayOption(HDMI_Video_Type VideoMode, HDMI_OutputColorMode OutputColorMode); 61 | void HDMITX_SetOutput(); 62 | 63 | 64 | 65 | #endif // _CAT6611_SYS_H_ 66 | -------------------------------------------------------------------------------- /software/sys_controller/link.riscv.ld: -------------------------------------------------------------------------------- 1 | /* not needed, but we need separate linker scripts anyway */ 2 | OUTPUT_ARCH(riscv) 3 | 4 | /* required to correctly link newlib */ 5 | GROUP( -lc -lgcc ) 6 | 7 | INCLUDE link.common.ld 8 | -------------------------------------------------------------------------------- /software/sys_controller/mem_init/epcq_controller_0.hex: -------------------------------------------------------------------------------- 1 | :00000001FF 2 | -------------------------------------------------------------------------------- /software/sys_controller/mem_init/meminit.qip: -------------------------------------------------------------------------------- 1 | set_global_assignment -name SEARCH_PATH $::quartus(qip_path) 2 | -------------------------------------------------------------------------------- /software/sys_controller/mem_init/meminit.spd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /software/sys_controller/memory/flash.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2016 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #include 21 | #include 22 | #include "system.h" 23 | #include "flash.h" 24 | #include "utils.h" 25 | 26 | // save some code space 27 | #define SINGLE_FLASH_INSTANCE 28 | 29 | alt_flash_dev *epcq_dev; 30 | 31 | 32 | int init_flash() 33 | { 34 | #ifdef SINGLE_FLASH_INSTANCE 35 | extern alt_llist alt_flash_dev_list; 36 | epcq_dev = (alt_flash_dev*)alt_flash_dev_list.next; 37 | #else 38 | epcq_dev = alt_flash_open_dev(EPCQ_CONTROLLER2_0_AVL_MEM_NAME); 39 | #endif 40 | 41 | if (epcq_dev == NULL) 42 | return -1; 43 | 44 | return 0; 45 | } 46 | 47 | int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf) 48 | { 49 | alt_u32 crcval=0, i, j, bytes_to_read; 50 | int retval; 51 | 52 | for (i=0; i 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef FLASH_H_ 21 | #define FLASH_H_ 22 | 23 | #include "alt_types.h" 24 | #include "sysconfig.h" 25 | #include "altera_epcq_controller2.h" 26 | 27 | // EPCS16 pagesize is 256 bytes 28 | // Flash is split 50-50 to FW and userdata, 1MB each 29 | #define PAGESIZE 256 30 | #define PAGES_PER_SECTOR 256 //EPCS "sector" corresponds to "block" on Spansion flash 31 | #define SECTORSIZE (PAGESIZE*PAGES_PER_SECTOR) 32 | #define USERDATA_OFFSET 0x100000 33 | #define MAX_USERDATA_ENTRY 15 // 16 sectors for userdata 34 | 35 | #define FLASH_VERIFY_ERROR 204 36 | 37 | 38 | int init_flash(); 39 | int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf); 40 | 41 | #endif /* FLASH_H_ */ 42 | -------------------------------------------------------------------------------- /software/sys_controller/memory/sdcard.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2016 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef SDCARD_H_ 21 | #define SDCARD_H_ 22 | 23 | #include "alt_types.h" 24 | #include "sysconfig.h" 25 | #include "sd_io.h" 26 | 27 | int check_sdcard(alt_u8 *databuf); 28 | int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, alt_u8 *tmpbuf); 29 | int copy_flash_to_sd(alt_u32 flash_pagenum, alt_u32 sd_blknum, alt_u32 length, alt_u8 *tmpbuf); 30 | 31 | #endif /* SDCARD_H_ */ 32 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/av_controller.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2023 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef AV_CONTROLLER_H_ 21 | #define AV_CONTROLLER_H_ 22 | 23 | #include "avconfig.h" 24 | #include "sysconfig.h" 25 | #include "sc_config_regs.h" 26 | #include "osd_generator_regs.h" 27 | #include "pll_reconfig_regs.h" 28 | 29 | // sys_ctrl bits 30 | #define LT_ACTIVE (1<<15) 31 | #define LT_ARMED (1<<14) 32 | #define LT_MODE_OFFS 12 33 | #define VSYNC_I_TYPE (1<<10) 34 | #define PLL_BYPASS (1<<9) 35 | #define REMOTE_EVENT (1<<8) 36 | #define SD_SPI_SS_N (1<<7) 37 | #define LCD_CS_N (1<<6) 38 | #define LCD_RS (1<<5) 39 | #define LCD_BL (1<<4) 40 | #define LCD_BL_TIMEOUT_OFFS 2 41 | #define VIDGEN_OFF (1<<1) 42 | #define AV_RESET_N (1<<0) 43 | 44 | #define LT_CTRL_MASK 0xf000 45 | 46 | #define HDMITX_MODE_MASK 0x00040000 47 | #define PLL_ACTIVECLK_MASK 0x00080000 48 | #define VSYNC_FLAG_MASK 0x00100000 49 | 50 | #define AUTO_OFF 0 51 | #define AUTO_CURRENT_INPUT 1 52 | #define AUTO_MAX_COUNT 100 53 | #define AUTO_CURRENT_MAX_COUNT 6 54 | 55 | #define PLL_CONFIG_VG 0 56 | 57 | // In reverse order of importance 58 | typedef enum { 59 | NO_CHANGE = 0, 60 | SC_CONFIG_CHANGE = 1, 61 | MODE_CHANGE = 2, 62 | TX_MODE_CHANGE = 3, 63 | ACTIVITY_CHANGE = 4 64 | } status_t; 65 | 66 | typedef enum { 67 | TX_HDMI_RGB = 0, 68 | TX_HDMI_YCBCR444 = 1, 69 | TX_DVI = 2 70 | } tx_mode_t; 71 | 72 | typedef struct { 73 | alt_u32 data[5]; 74 | } pll_config_t; 75 | 76 | //TODO: transform binary values into flags 77 | typedef struct { 78 | alt_u32 totlines; 79 | alt_u32 pcnt_field; 80 | alt_u32 hsync_width; 81 | alt_u32 clkcnt; 82 | alt_u8 progressive; 83 | alt_8 id; 84 | alt_u8 sync_active; 85 | alt_u8 hdmitx_pclk_level; 86 | alt_u32 pclk_o_hz; 87 | avinput_t avinput; 88 | // Current configuration 89 | avconfig_t cc; 90 | } avmode_t; 91 | 92 | void ui_disp_menu(alt_u8 osd_mode); 93 | void ui_disp_status(alt_u8 refresh_osd_timer); 94 | 95 | void set_sampler_phase(uint8_t sampler_phase, uint8_t update_sc); 96 | 97 | int load_profile(); 98 | int save_profile(); 99 | 100 | void print_vm_stats(); 101 | int latency_test(); 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/avconfig.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2023 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #include 21 | #include "system.h" 22 | #include "avconfig.h" 23 | #include "av_controller.h" 24 | #include "altera_avalon_pio_regs.h" 25 | #include "tvp7002.h" 26 | 27 | #define DEFAULT_ON 1 28 | 29 | extern alt_u8 update_cur_vm; 30 | 31 | // Target configuration 32 | avconfig_t tc; 33 | 34 | // Default configuration 35 | const avconfig_t tc_default = { 36 | .pm_240p = 1, 37 | .pm_384p = 1, 38 | .pm_480i = 1, 39 | .pm_1080i = 1, 40 | .l3_mode = 1, 41 | .clamp_offset = SIGNED_NUMVAL_ZERO, 42 | .sl_altern = 1, 43 | .sync_vth = DEFAULT_SYNC_VTH, 44 | .linelen_tol = DEFAULT_LINELEN_TOL, 45 | .vsync_thold = DEFAULT_VSYNC_THOLD, 46 | .pre_coast = DEFAULT_PRE_COAST, 47 | .post_coast = DEFAULT_POST_COAST, 48 | .adc_pll_bw = 1, 49 | .sync_lpf = DEFAULT_SYNC_LPF, 50 | .alc_h_filter = DEFAULT_ALC_H_FILTER, 51 | .alc_v_filter = DEFAULT_ALC_V_FILTER, 52 | .col = { 53 | .r_f_gain = DEFAULT_FINE_GAIN, 54 | .g_f_gain = DEFAULT_FINE_GAIN, 55 | .b_f_gain = DEFAULT_FINE_GAIN, 56 | .r_f_off = DEFAULT_FINE_OFFSET, 57 | .g_f_off = DEFAULT_FINE_OFFSET, 58 | .b_f_off = DEFAULT_FINE_OFFSET, 59 | .c_gain = DEFAULT_COARSE_GAIN, 60 | }, 61 | .mask_br = 8, 62 | #ifdef ENABLE_AUDIO 63 | .audio_dw_sampl = DEFAULT_ON, 64 | .audio_gain = AUDIO_GAIN_0DB, 65 | #endif 66 | .link_av = AV_LAST, 67 | }; 68 | 69 | int set_default_avconfig() 70 | { 71 | memcpy(&tc, &tc_default, sizeof(avconfig_t)); 72 | 73 | tc.tx_mode = (IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & HDMITX_MODE_MASK) ? TX_DVI : TX_HDMI_RGB; 74 | 75 | set_default_vm_table(); 76 | update_cur_vm = 1; 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/controls.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2018 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef CONTROLS_H_ 21 | #define CONTROLS_H_ 22 | 23 | #include "sysconfig.h" 24 | 25 | #define RC_MASK 0x0000ffff 26 | #define PB_MASK 0x00030000 27 | #define PB0_BIT 0x00010000 28 | #define PB1_BIT 0x00020000 29 | 30 | typedef enum { 31 | RC_BTN1 = 0, 32 | RC_BTN2, 33 | RC_BTN3, 34 | RC_BTN4, 35 | RC_BTN5, 36 | RC_BTN6, 37 | RC_BTN7, 38 | RC_BTN8, 39 | RC_BTN9, 40 | RC_BTN0, 41 | RC_MENU, 42 | RC_OK, 43 | RC_BACK, 44 | RC_UP, 45 | RC_DOWN, 46 | RC_LEFT, 47 | RC_RIGHT, 48 | RC_INFO, 49 | RC_LCDBL, 50 | RC_SL_MODE, 51 | RC_SL_TYPE, 52 | RC_SL_PLUS, 53 | RC_SL_MINUS, 54 | RC_LM_MODE, 55 | RC_PHASE_PLUS, 56 | RC_PHASE_MINUS, 57 | RC_PROF_HOTKEY, 58 | } rc_code_t; 59 | 60 | #define REMOTE_MAX_KEYS (RC_PROF_HOTKEY-RC_BTN1+1) 61 | 62 | void setup_rc(); 63 | int parse_control(); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/fat16_export.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2020 Ari Sundholm 3 | // 4 | // This file has been contributed to the Open Source Scan Converter project 5 | // developed by Markus Hiienkari Markus Hiienkari 6 | // and other members of the retro gaming community. 7 | // 8 | // This program is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program. If not, see . 20 | // 21 | 22 | #ifndef FAT16_EXPORT_H_ 23 | #define FAT16_EXPORT_H_ 24 | 25 | #include "alt_types.h" 26 | 27 | /* Use a sector size of 512 bytes. */ 28 | #define FAT16_SECTOR_SIZE 512U 29 | 30 | /* This volume has 2048-byte clusters. */ 31 | #define FAT16_CLUSTER_SIZE 2048U 32 | #define FAT16_SECTORS_PER_CLUSTER (FAT16_CLUSTER_SIZE/FAT16_SECTOR_SIZE) 33 | 34 | /* Offsets of the two File Allocation Tables. */ 35 | #define FAT16_1_OFS 0x10000UL 36 | #define FAT16_2_OFS 0x14000UL 37 | 38 | /* Each FAT16 entry is a 16-bit little-endian integer. */ 39 | #define FAT16_ENTRY_SIZE 2U 40 | #define FAT16_ENTRY_SHIFT 1U 41 | #define FAT16_ENTRIES_PER_SECTOR (FAT16_SECTOR_SIZE >> FAT16_ENTRY_SHIFT) 42 | 43 | /* On this volume, each FAT will be 16 kiB in size. */ 44 | #define FAT16_SIZE 0x04000UL 45 | 46 | /* The first sector of the root directory. */ 47 | #define FAT16_ROOT_DIR_FIRST_SECTOR 192U 48 | 49 | /* The length of the root directory in sectors. */ 50 | #define FAT16_ROOT_DIR_SECTORS 128U 51 | 52 | /* 53 | * Define the properties and contents of the directory entry for the 54 | * settings file. 55 | */ 56 | #define PROF_DIRENT_16_OFS 0x18000UL 57 | #define PROF_DIRENT_16_SIZE 32U 58 | 59 | extern const alt_u8 prof_dirent_16[PROF_DIRENT_16_SIZE]; 60 | 61 | #define PROF_16_DATA_OFS 0x028000UL 62 | #define PROF_16_DATA_SIZE 0x100200UL 63 | #define PROF_16_CLUSTER_COUNT ((PROF_16_DATA_SIZE/FAT16_CLUSTER_SIZE)+!!(PROF_16_DATA_SIZE%FAT16_CLUSTER_SIZE)) 64 | /* Profile file data starts at offset 0x00028000 */ 65 | /* Profile file data ends at offset 0x00128200 */ 66 | /* Profile file data is 1049088 bytes long. */ 67 | 68 | 69 | /* Generate a FAT16 boot sector. 70 | * buf must be at least FAT16_BOOT_SECTOR_SIZE bytes long, 71 | * and is assumed to be pre-zeroed. 72 | */ 73 | void generate_boot_sector_16(alt_u8 *buf); 74 | 75 | /* 76 | * Generate a FAT of a FAT16 volume. 77 | * The buffer is assumed to be zeroed out and have a size of at least 512 bytes. 78 | * The number of clusters already written are given as an argument. 79 | * The function returns the total number of clusters written so far. 80 | */ 81 | alt_u16 generate_fat16(void *buf, alt_u16 written); 82 | 83 | #endif // FAT16_EXPORT_H_ 84 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/firmware.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2023 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef FIRMWARE_H_ 21 | #define FIRMWARE_H_ 22 | 23 | #include "alt_types.h" 24 | #include "sysconfig.h" 25 | 26 | #define FW_VER_MAJOR 1 27 | #define FW_VER_MINOR 12 28 | 29 | #define PROFILE_VER_MAJOR 1 30 | #define PROFILE_VER_MINOR 12 31 | 32 | #define INITCFG_VER_MAJOR 1 33 | #define INITCFG_VER_MINOR 0 34 | 35 | #ifdef ENABLE_AUDIO 36 | #define FW_SUFFIX1 "a" 37 | #else 38 | #define FW_SUFFIX1 "" 39 | #endif 40 | 41 | #ifdef OSDLANG_JP 42 | #define FW_SUFFIX2 "j" 43 | #else 44 | #define FW_SUFFIX2 "" 45 | #endif 46 | 47 | #define FW_UPDATE_RETRIES 3 48 | 49 | #define FW_IMAGE_ERROR 100 50 | #define FW_HDR_ERROR 101 51 | #define FW_HDR_CRC_ERROR 102 52 | #define FW_DATA_CRC_ERROR 103 53 | #define FW_UPD_CANCELLED 104 54 | 55 | typedef struct { 56 | char fw_key[4]; 57 | alt_u8 version_major; 58 | alt_u8 version_minor; 59 | char version_suffix[8]; 60 | alt_u32 hdr_len; 61 | alt_u32 data_len; 62 | alt_u32 data_crc; 63 | alt_u32 hdr_crc; 64 | } fw_hdr; 65 | 66 | int fw_update(); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/sysconfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2016 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef SYSCONFIG_H_ 21 | #define SYSCONFIG_H_ 22 | 23 | //#define I2C_DEBUG 24 | #define I2CA_BASE I2C_OPENCORES_0_BASE 25 | #define SD_SPI_BASE I2C_OPENCORES_1_BASE 26 | 27 | #ifndef DEBUG 28 | #include 29 | #define OS_PRINTF(...) 30 | #define ErrorF(...) 31 | #define printf(...) 32 | #else 33 | #include 34 | #include "utils.h" 35 | #define OS_PRINTF printf 36 | #define ErrorF printf 37 | // use reduced printf 38 | //#define printf alt_printf 39 | #define printf dd_printf 40 | #endif 41 | 42 | #define sniprintf snprintf 43 | 44 | #define WAITLOOP_SLEEP_US 10000 45 | 46 | #endif /* SYSCONFIG_H_ */ 47 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/userdata.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2023 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef USERDATA_H_ 21 | #define USERDATA_H_ 22 | 23 | #include "alt_types.h" 24 | #include "sysconfig.h" 25 | #include "controls.h" 26 | #include "av_controller.h" 27 | #include "avconfig.h" 28 | #include "video_modes.h" 29 | #include "flash.h" 30 | 31 | #define PROFILE_NAME_LEN 12 32 | 33 | #define MAX_PROFILE (MAX_USERDATA_ENTRY-1) 34 | #define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY 35 | 36 | #define UDATA_IMPT_CANCELLED 104 37 | #define UDATA_EXPT_CANCELLED 105 38 | 39 | typedef enum { 40 | UDE_INITCFG = 0, 41 | UDE_PROFILE, 42 | } ude_type; 43 | 44 | typedef struct { 45 | char userdata_key[8]; 46 | alt_u8 version_major; 47 | alt_u8 version_minor; 48 | ude_type type; 49 | } __attribute__((packed, __may_alias__)) ude_hdr; 50 | 51 | typedef struct { 52 | ude_hdr hdr; 53 | alt_u16 data_len; 54 | alt_u8 last_profile[AV_LAST]; 55 | alt_u8 profile_link; 56 | avinput_t last_input; 57 | avinput_t def_input; 58 | alt_u8 lcd_bl_timeout; 59 | alt_u8 auto_input; 60 | alt_u8 auto_av1_ypbpr; 61 | alt_u8 auto_av2_ypbpr; 62 | alt_u8 auto_av3_ypbpr; 63 | alt_u8 osd_enable; 64 | alt_u8 osd_status_timeout; 65 | alt_u8 phase_hotkey_enable; 66 | alt_u16 keys[REMOTE_MAX_KEYS]; 67 | } __attribute__((packed, __may_alias__)) ude_initcfg; 68 | 69 | typedef struct { 70 | ude_hdr hdr; 71 | char name[PROFILE_NAME_LEN+1]; 72 | alt_u16 avc_data_len; 73 | alt_u16 vm_data_len; 74 | avconfig_t avc; 75 | //mode_data_t vm[VIDEO_MODES_CNT]; 76 | } __attribute__((packed, __may_alias__)) ude_profile; 77 | 78 | int write_userdata(alt_u8 entry); 79 | int read_userdata(alt_u8 entry, int dry_run); 80 | int import_userdata(); 81 | int export_userdata(); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /software/sys_controller/ossc/utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef UTILS_H_ 21 | #define UTILS_H_ 22 | 23 | #include 24 | 25 | #define PRINTF_BUFSIZE 512 26 | 27 | inline unsigned char bitswap8(unsigned char v); 28 | 29 | alt_u32 bswap32(alt_u32 w); 30 | 31 | unsigned long crc32(unsigned char *input_data, unsigned long input_data_length, int do_initialize); 32 | 33 | int dd_printf(const char *__restrict fmt, ...); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /software/sys_controller/pcm1862/pcm1862.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2017 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef PCM1862_H_ 21 | #define PCM1862_H_ 22 | 23 | #include "pcm1862_regs.h" 24 | #include "sysconfig.h" 25 | 26 | typedef enum { 27 | PCM_INPUT1 = 0, 28 | PCM_INPUT2 = 1, 29 | PCM_INPUT3 = 2, 30 | PCM_INPUT4 = 3 31 | } pcm_input_t; 32 | 33 | void pcm_source_sel(pcm_input_t input); 34 | 35 | void pcm_set_stereo_mode(int mono_enable); 36 | 37 | void pcm_set_gain(alt_8 db_gain); 38 | 39 | int pcm1862_init(); 40 | 41 | #endif /* PCM1862_H_ */ 42 | -------------------------------------------------------------------------------- /software/sys_controller/pcm1862/pcm1862_regs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2017 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef PCM1862_REGS_H_ 21 | #define PCM1862_REGS_H_ 22 | 23 | #define PCM1862_BASE (0x94>>1) 24 | 25 | #define PCM1862_PAGESEL 0x00 26 | 27 | /* Page 0 registers */ 28 | 29 | #define PCM1862_PGA1L 0x01 30 | #define PCM1862_PGA1R 0x02 31 | #define PCM1862_PGA2L 0x03 32 | #define PCM1862_PGA2R 0x04 33 | #define PCM1862_PGACONFIG 0x05 34 | #define PCM1862_ADC1L 0x06 35 | #define PCM1862_ADC1R 0x07 36 | #define PCM1862_ADC2L 0x08 37 | #define PCM1862_ADC2R 0x09 38 | #define PCM1862_ADC2CONFIG 0x0A 39 | #define PCM1862_PCMFMT 0x0B 40 | #define PCM1862_TDMFMT 0x0C 41 | #define PCM1862_TXTDM_OFFSET 0x0D 42 | #define PCM1862_RXTDM_OFFSET 0x0E 43 | #define PCM1862_DPGA1_GAIN_L 0x0F 44 | 45 | #define PCM1862_DPGA1_GAIN_R 0x16 46 | #define PCM1862_DPGA2_GAIN_L 0x17 47 | #define PCM1862_DPGA2_GAIN_R 0x18 48 | #define PCM1862_DPGA_CONFIG 0x19 49 | #define PCM1862_DMIC_CONFIG 0x1A 50 | #define PCM1862_DIN_RESAMPLE 0x1B 51 | 52 | #define PCM1862_CLKCONFIG 0x20 53 | #define PCM1862_DSP1_CLKDIV 0x21 54 | #define PCM1862_DSP2_CLKDIV 0x22 55 | #define PCM1862_ADC_CLKDIV 0x23 56 | 57 | #define PCM1862_PLLCONFIG 0x28 58 | 59 | #define PCM1862_PWR_CTRL 0x70 60 | #define PCM1862_DSP_CTRL 0x71 61 | 62 | 63 | /* Page 1 registers */ 64 | 65 | #define PCM1862_DSP2_CFG 0x01 66 | #define PCM1862_DSP2_ADDR 0x02 67 | #define PCM1862_DSP2_WDATA0 0x04 68 | #define PCM1862_DSP2_WDATA1 0x05 69 | #define PCM1862_DSP2_WDATA2 0x06 70 | #define PCM1862_DSP2_RDATA0 0x08 71 | #define PCM1862_DSP2_RDATA1 0x09 72 | #define PCM1862_DSP2_RDATA2 0x0A 73 | 74 | 75 | #endif /* PCM1862_REGS_H_ */ 76 | -------------------------------------------------------------------------------- /software/sys_controller/pulpino.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 ETH Zurich and University of Bologna. 2 | // Copyright and related rights are licensed under the Solderpad Hardware 3 | // License, Version 0.51 (the “License”); you may not use this file except in 4 | // compliance with the License. You may obtain a copy of the License at 5 | // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law 6 | // or agreed to in writing, software, hardware and materials distributed under 7 | // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 8 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | // specific language governing permissions and limitations under the License. 10 | 11 | /** 12 | * @file 13 | * @brief Register mapping for PULPino peripherals. 14 | * 15 | * Contains event register mappings for the PULPino SOC as 16 | * well as some general definitions for the overall system. 17 | * 18 | * @author Florian Zaruba 19 | * 20 | * @version 1.0 21 | * 22 | * @date 2/10/2015 23 | * 24 | */ 25 | #ifndef PULPINO_H 26 | #define PULPINO_H 27 | 28 | #define PULPINO_BASE_ADDR 0x10000000 29 | 30 | /** SOC PERIPHERALS */ 31 | #define SOC_PERIPHERALS_BASE_ADDR ( PULPINO_BASE_ADDR + 0xA100000 ) 32 | 33 | #define UART_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x0000 ) 34 | #define GPIO_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x1000 ) 35 | #define SPI_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x2000 ) 36 | #define TIMER_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x3000 ) 37 | #define EVENT_UNIT_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x4000 ) 38 | #define I2C_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x5000 ) 39 | #define FLL_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x6000 ) 40 | #define SOC_CTRL_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x7000 ) 41 | 42 | /** STDOUT */ 43 | #define STDOUT_BASE_ADDR ( SOC_PERIPHERALS_BASE_ADDR + 0x10000 ) 44 | #define FPUTCHAR_BASE_ADDR ( STDOUT_BASE_ADDR + 0x1000 ) 45 | #define FILE_CMD_BASE_ADDR ( STDOUT_BASE_ADDR + 0x2000 ) 46 | #define STREAM_BASE_ADDR ( STDOUT_BASE_ADDR + 0x3000 ) 47 | 48 | /** Instruction RAM */ 49 | #define INSTR_RAM_BASE_ADDR ( 0x00 ) 50 | #define INSTR_RAM_START_ADDR ( 0x80 ) 51 | 52 | /** ROM */ 53 | #define ROM_BASE_ADDR ( 0x10000 ) 54 | 55 | /** Data RAM */ 56 | #define DATA_RAM_BASE_ADDR ( 0x00100000 ) 57 | 58 | /** Registers and pointers */ 59 | #define REGP(x) ((volatile unsigned int*)(x)) 60 | #define REG(x) (*((volatile unsigned int*)(x))) 61 | #define REGP_8(x) (((volatile uint8_t*)(x))) 62 | 63 | /* pointer to mem of apb pulpino unit - PointerSocCtrl */ 64 | #define __PSC__(a) *(unsigned volatile int*) (SOC_CTRL_BASE_ADDR + a) 65 | 66 | /** Peripheral Clock gating */ 67 | #define CGREG __PSC__(0x04) 68 | 69 | /** Clock gate SPI */ 70 | #define CGSPI 0x00 71 | /** Clock gate UART */ 72 | #define CGUART 0x01 73 | /** Clock gate GPIO */ 74 | #define CGGPIO 0x02 75 | /** Clock gate SPI Master */ 76 | #define CGGSPIM 0x03 77 | /** Clock gate Timer */ 78 | #define CGTIM 0x04 79 | /** Clock gate Event Unit */ 80 | #define CGEVENT 0x05 81 | /** Clock gate I2C */ 82 | #define CGGI2C 0x06 83 | /** Clock gate FLL */ 84 | #define CGFLL 0x07 85 | 86 | /** Boot address register */ 87 | #define BOOTREG __PSC__(0x08) 88 | 89 | #define RES_STATUS __PSC__(0x14) 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /software/sys_controller/spi_charlcd/lcd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2016 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef LCD_H_ 21 | #define LCD_H_ 22 | 23 | #include "system.h" 24 | #include 25 | #include "sysconfig.h" 26 | 27 | #define LCD_ROW_LEN 16 28 | 29 | void lcd_init(); 30 | 31 | void lcd_write(char *row1, char *row2); 32 | 33 | #endif /* LCD_H_ */ 34 | -------------------------------------------------------------------------------- /software/sys_controller/ths7353/ths7353.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2015-2016 Markus Hiienkari 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #include 21 | #include 22 | #include "system.h" 23 | #include "altera_avalon_pio_regs.h" 24 | #include "i2c_opencores.h" 25 | #include "ths7353.h" 26 | 27 | inline alt_u32 ths_readreg(alt_u8 channel) 28 | { 29 | //Phase 1 30 | I2C_start(I2CA_BASE, THS_BASE, 0); 31 | I2C_write(I2CA_BASE, channel, 1); 32 | 33 | //Phase 2 34 | I2C_start(I2CA_BASE, THS_BASE, 1); 35 | return I2C_read(I2CA_BASE,1); 36 | } 37 | 38 | inline void ths_writereg(alt_u8 channel, alt_u8 data) 39 | { 40 | I2C_start(I2CA_BASE, THS_BASE, 0); 41 | I2C_write(I2CA_BASE, channel, 0); 42 | I2C_write(I2CA_BASE, data, 1); 43 | } 44 | 45 | int ths_init() 46 | { 47 | //Avoid random FIFO state (see datasheet p.37) 48 | I2C_write(I2CA_BASE, 0x00, 0); 49 | usleep(10); 50 | 51 | //Initialize all channels 52 | ths_writereg(THS_CH1, (THS_LPF_DEFAULT< 3 | // 4 | // This file is part of Open Source Scan Converter project. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | // 19 | 20 | #ifndef THS7353_H_ 21 | #define THS7353_H_ 22 | 23 | #include "sysconfig.h" 24 | 25 | #define THS_BASE (0x58>>1) 26 | 27 | #define THS_CH1 0x01 28 | #define THS_CH2 0x02 29 | #define THS_CH3 0x03 30 | 31 | typedef enum { 32 | THS_INPUT_A = 0, 33 | THS_INPUT_B = 1, 34 | THS_STANDBY = 2 35 | } ths_input_t; 36 | 37 | #define THS_LPF_9MHZ 0x00 38 | #define THS_LPF_16MHZ 0x01 39 | #define THS_LPF_35MHZ 0x02 40 | #define THS_LPF_BYPASS 0x03 41 | #define THS_LPF_DEFAULT 0x3 42 | #define THS_LPF_MASK 0x18 43 | #define THS_LPF_OFFS 3 44 | 45 | #define THS_SRC_MASK 0x20 46 | #define THS_SRC_OFFS 5 47 | 48 | #define THS_MODE_MASK 0x7 49 | #define THS_MODE_OFFS 0 50 | 51 | #define THS_MODE_DISABLE 0 52 | #define THS_MODE_AVMUTE 1 53 | #define THS_MODE_AC_BIAS 4 54 | #define THS_MODE_STC 6 //mid bias 55 | 56 | int ths_init(); 57 | 58 | void ths_set_lpf(alt_u8 val); 59 | 60 | void ths_source_sel(ths_input_t input, alt_u8 lpf); 61 | 62 | #endif /* THS7353_H_ */ 63 | -------------------------------------------------------------------------------- /software/sys_controller/ulibSD/integer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: integer.h 3 | * Author: Nelson Lombardo 4 | * Year: 2015 5 | * e-mail: nelson.lombardo@gmail.com 6 | * License at the end of file. 7 | */ 8 | 9 | /*****************************************************************************/ 10 | /* Integer type definitions */ 11 | /*****************************************************************************/ 12 | #ifndef _INTEGER_H_ 13 | #define _INTEGER_H_ 14 | 15 | #include 16 | #include 17 | #if 0 18 | /* 16-bit, 32-bit or larger integer */ 19 | typedef int16_t INT; 20 | typedef uint16_t UINT; 21 | 22 | /* 8-bit integer */ 23 | typedef int8_t CHAR; 24 | typedef uint8_t UCHAR; 25 | typedef uint8_t BYTE; 26 | typedef uint8_t BOOL; 27 | 28 | /* 16-bit integer */ 29 | typedef int16_t SHORT; 30 | typedef uint16_t USHORT; 31 | typedef uint16_t WORD; 32 | typedef uint16_t WCHAR; 33 | 34 | /* 32-bit integer */ 35 | typedef int32_t LONG; 36 | typedef uint32_t ULONG; 37 | typedef uint32_t DWORD; 38 | 39 | /* Boolean type */ 40 | typedef enum { FALSE = 0, TRUE } BOOLEAN; 41 | #endif 42 | typedef enum { LOW = 0, HIGH } THROTTLE; 43 | #endif 44 | 45 | // «integer.h» is part of: 46 | /*----------------------------------------------------------------------------/ 47 | / ulibSD - Library for SD cards semantics (C)Nelson Lombardo, 2015 48 | /-----------------------------------------------------------------------------/ 49 | / ulibSD library is a free software that opened under license policy of 50 | / following conditions. 51 | / 52 | / Copyright (C) 2015, ChaN, all right reserved. 53 | / 54 | / 1. Redistributions of source code must retain the above copyright notice, 55 | / this condition and the following disclaimer. 56 | / 57 | / This software is provided by the copyright holder and contributors "AS IS" 58 | / and any warranties related to this software are DISCLAIMED. 59 | / The copyright owner or contributors be NOT LIABLE for any damages caused 60 | / by use of this software. 61 | /----------------------------------------------------------------------------*/ 62 | 63 | // Derived from Mister Chan works on FatFs code (http://elm-chan.org/fsw/ff/00index_e.html): 64 | /*----------------------------------------------------------------------------/ 65 | / FatFs - FAT file system module R0.11 (C)ChaN, 2015 66 | /-----------------------------------------------------------------------------/ 67 | / FatFs module is a free software that opened under license policy of 68 | / following conditions. 69 | / 70 | / Copyright (C) 2015, ChaN, all right reserved. 71 | / 72 | / 1. Redistributions of source code must retain the above copyright notice, 73 | / this condition and the following disclaimer. 74 | / 75 | / This software is provided by the copyright holder and contributors "AS IS" 76 | / and any warranties related to this software are DISCLAIMED. 77 | / The copyright owner or contributors be NOT LIABLE for any damages caused 78 | / by use of this software. 79 | /----------------------------------------------------------------------------*/ 80 | -------------------------------------------------------------------------------- /software/sys_controller/ulibSD/spi_io.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "i2c_opencores.h" 7 | #include "spi_io.h" 8 | #include "av_controller.h" 9 | 10 | extern alt_u32 sys_ctrl; 11 | 12 | alt_u32 sd_timer_ts; 13 | 14 | void SPI_Init (void) { 15 | I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,400000); 16 | } 17 | 18 | void SPI_W(const BYTE *wd, int len) { 19 | SPI_write(SD_SPI_BASE, wd, len); 20 | } 21 | 22 | void SPI_R(BYTE *rd, int len) { 23 | SPI_read(SD_SPI_BASE, rd, len); 24 | } 25 | 26 | void SPI_WW(BYTE d) { 27 | SPI_W(&d, 1); 28 | } 29 | 30 | BYTE SPI_RW (BYTE d) { 31 | BYTE w; 32 | SPI_R(&w, 1); 33 | 34 | return w; 35 | } 36 | 37 | void SPI_Release (void) { 38 | return; 39 | } 40 | 41 | inline void SPI_CS_Low (void) { 42 | sys_ctrl &= ~SD_SPI_SS_N; 43 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl); 44 | } 45 | 46 | inline void SPI_CS_High (void){ 47 | sys_ctrl |= SD_SPI_SS_N; 48 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl); 49 | } 50 | 51 | inline void SPI_Freq_High (void) { 52 | I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,ALT_CPU_FREQ/SCL_MIN_CLKDIV); 53 | } 54 | 55 | inline void SPI_Freq_Low (void) { 56 | I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,400000); 57 | } 58 | 59 | int SPI_Timer_On (WORD ms) { 60 | if (!sd_timer_ts) { 61 | sd_timer_ts = alt_timestamp() + ms*(TIMER_0_FREQ/1000); 62 | return 0; 63 | } 64 | return 1; 65 | } 66 | 67 | inline BOOL SPI_Timer_Status (void) { 68 | return alt_timestamp() < sd_timer_ts; 69 | } 70 | 71 | inline void SPI_Timer_Off (void) { 72 | sd_timer_ts = 0; 73 | return; 74 | } 75 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/alt_types.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALT_TYPES_H__ 2 | #define __ALT_TYPES_H__ 3 | 4 | /****************************************************************************** 5 | * * 6 | * License Agreement * 7 | * * 8 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 9 | * All rights reserved. * 10 | * * 11 | * Permission is hereby granted, free of charge, to any person obtaining a * 12 | * copy of this software and associated documentation files (the "Software"), * 13 | * to deal in the Software without restriction, including without limitation * 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 15 | * and/or sell copies of the Software, and to permit persons to whom the * 16 | * Software is furnished to do so, subject to the following conditions: * 17 | * * 18 | * The above copyright notice and this permission notice shall be included in * 19 | * all copies or substantial portions of the Software. * 20 | * * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 27 | * DEALINGS IN THE SOFTWARE. * 28 | * * 29 | * This agreement shall be governed in all respects by the laws of the State * 30 | * of California and by the laws of the United States of America. * 31 | * * 32 | * Altera does not recommend, suggest or require that this reference design * 33 | * file be used in conjunction or combination with any other product. * 34 | ******************************************************************************/ 35 | 36 | /* 37 | * Don't declare these typedefs if this file is included by assembly source. 38 | */ 39 | #ifndef ALT_ASM_SRC 40 | typedef signed char alt_8; 41 | typedef unsigned char alt_u8; 42 | typedef signed short alt_16; 43 | typedef unsigned short alt_u16; 44 | typedef signed long alt_32; 45 | typedef unsigned long alt_u32; 46 | typedef long long alt_64; 47 | typedef unsigned long long alt_u64; 48 | #endif 49 | 50 | #define ALT_INLINE __inline__ 51 | #define ALT_ALWAYS_INLINE __attribute__ ((always_inline)) 52 | #define ALT_WEAK __attribute__((weak)) 53 | 54 | #endif /* __ALT_TYPES_H__ */ 55 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/priv/alt_busy_sleep.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALT_BUSY_SLEEP_H 2 | #define __ALT_BUSY_SLEEP_H 3 | 4 | /* 5 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. 6 | * All rights reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to 10 | * deal in the Software without restriction, including without limitation the 11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 12 | * sell copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | * DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | /* 28 | * The function alt_busy_sleep provides a busy loop implementation of usleep. 29 | * This is used to provide usleep for the standalone HAL, or when the timer is 30 | * unavailable in uC/OS-II. 31 | */ 32 | 33 | extern unsigned int alt_busy_sleep (unsigned int us); 34 | 35 | #endif /* __ALT_BUSY_SLEEP_H */ 36 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/priv/alt_exception_handler_registry.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALT_EXCEPTION_HANDLER_REGISTRY_H__ 2 | #define __ALT_EXCEPTION_HANDLER_REGISTRY_H__ 3 | 4 | /****************************************************************************** 5 | * * 6 | * License Agreement * 7 | * * 8 | * Copyright (c) 2008 Altera Corporation, San Jose, California, USA. * 9 | * All rights reserved. * 10 | * * 11 | * Permission is hereby granted, free of charge, to any person obtaining a * 12 | * copy of this software and associated documentation files (the "Software"), * 13 | * to deal in the Software without restriction, including without limitation * 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 15 | * and/or sell copies of the Software, and to permit persons to whom the * 16 | * Software is furnished to do so, subject to the following conditions: * 17 | * * 18 | * The above copyright notice and this permission notice shall be included in * 19 | * all copies or substantial portions of the Software. * 20 | * * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 27 | * DEALINGS IN THE SOFTWARE. * 28 | * * 29 | * This agreement shall be governed in all respects by the laws of the State * 30 | * of California and by the laws of the United States of America. * 31 | * * 32 | ******************************************************************************/ 33 | #include "sys/alt_exceptions.h" 34 | 35 | /* Function pointer to exception callback routine */ 36 | extern alt_exception_result (*alt_instruction_exception_handler) 37 | (alt_exception_cause, alt_u32, alt_u32); 38 | 39 | #endif /* __ALT_EXCEPTION_HANDLER_REGISTRY_H__ */ 40 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/priv/alt_iic_isr_register.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALT_IIC_ISR_REGISTER_H_ 2 | #define __ALT_IIC_ISR_REGISTER_H_ 3 | 4 | /****************************************************************************** 5 | * * 6 | * License Agreement * 7 | * * 8 | * Copyright (c) 2009 Altera Corporation, San Jose, California, USA. * 9 | * All rights reserved. * 10 | * * 11 | * Permission is hereby granted, free of charge, to any person obtaining a * 12 | * copy of this software and associated documentation files (the "Software"), * 13 | * to deal in the Software without restriction, including without limitation * 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 15 | * and/or sell copies of the Software, and to permit persons to whom the * 16 | * Software is furnished to do so, subject to the following conditions: * 17 | * * 18 | * The above copyright notice and this permission notice shall be included in * 19 | * all copies or substantial portions of the Software. * 20 | * * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 27 | * DEALINGS IN THE SOFTWARE. * 28 | * * 29 | * This agreement shall be governed in all respects by the laws of the State * 30 | * of California and by the laws of the United States of America. * 31 | * * 32 | ******************************************************************************/ 33 | #include "alt_types.h" 34 | #include "sys/alt_irq.h" 35 | 36 | extern int alt_iic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr, 37 | void *isr_context, void *flags); 38 | 39 | #endif /* __ALT_IIC_ISR_REGISTER_H_ */ 40 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/priv/nios2_gmon_data.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | #ifndef NIOS2_GMON_DATA_H 31 | #define NIOS2_GMON_DATA_H 32 | 33 | #define GMON_DATA_SIG 0 34 | #define GMON_DATA_WORDS 1 35 | #define GMON_DATA_PROFILE_DATA 2 36 | #define GMON_DATA_PROFILE_LOWPC 3 37 | #define GMON_DATA_PROFILE_HIGHPC 4 38 | #define GMON_DATA_PROFILE_BUCKET 5 39 | #define GMON_DATA_PROFILE_RATE 6 40 | #define GMON_DATA_MCOUNT_START 7 41 | #define GMON_DATA_MCOUNT_LIMIT 8 42 | 43 | #define GMON_DATA_SIZE 9 44 | 45 | extern unsigned int alt_gmon_data[GMON_DATA_SIZE]; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/sys/alt_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALT_DEBUG_H__ 2 | #define __ALT_DEBUG_H__ 3 | 4 | /****************************************************************************** 5 | * * 6 | * License Agreement * 7 | * * 8 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 9 | * All rights reserved. * 10 | * * 11 | * Permission is hereby granted, free of charge, to any person obtaining a * 12 | * copy of this software and associated documentation files (the "Software"), * 13 | * to deal in the Software without restriction, including without limitation * 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 15 | * and/or sell copies of the Software, and to permit persons to whom the * 16 | * Software is furnished to do so, subject to the following conditions: * 17 | * * 18 | * The above copyright notice and this permission notice shall be included in * 19 | * all copies or substantial portions of the Software. * 20 | * * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 27 | * DEALINGS IN THE SOFTWARE. * 28 | * * 29 | * This agreement shall be governed in all respects by the laws of the State * 30 | * of California and by the laws of the United States of America. * 31 | * * 32 | ******************************************************************************/ 33 | 34 | /* 35 | * The ALT_DEVUG_ASSERT macro can be used to generate a debugger break 36 | * from within software. The break is generated if "condition" evaluates to 37 | * false. 38 | */ 39 | 40 | #define ALT_DEBUG_ASSERT(condition) if (!condition) \ 41 | { \ 42 | __asm__ volatile ("break"); \ 43 | } 44 | 45 | #endif /* __ALT_DEBUG_H__ */ 46 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/sys/alt_irq_entry.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | /* 32 | * This file pulls in the IRQ entry assembler and C code, which is only 33 | * required if there are any interruptes in the system. 34 | */ 35 | 36 | __asm__( "\n\t.globl alt_irq_entry" ); 37 | 38 | __asm__( "\n\t.globl alt_irq_handler" ); 39 | 40 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/inc/sys/alt_timestamp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALT_TIMESTAMP_H__ 2 | #define __ALT_TIMESTAMP_H__ 3 | 4 | /****************************************************************************** 5 | * * 6 | * License Agreement * 7 | * * 8 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 9 | * All rights reserved. * 10 | * * 11 | * Permission is hereby granted, free of charge, to any person obtaining a * 12 | * copy of this software and associated documentation files (the "Software"), * 13 | * to deal in the Software without restriction, including without limitation * 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 15 | * and/or sell copies of the Software, and to permit persons to whom the * 16 | * Software is furnished to do so, subject to the following conditions: * 17 | * * 18 | * The above copyright notice and this permission notice shall be included in * 19 | * all copies or substantial portions of the Software. * 20 | * * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 27 | * DEALINGS IN THE SOFTWARE. * 28 | * * 29 | * This agreement shall be governed in all respects by the laws of the State * 30 | * of California and by the laws of the United States of America. * 31 | * * 32 | * Altera does not recommend, suggest or require that this reference design * 33 | * file be used in conjunction or combination with any other product. * 34 | ******************************************************************************/ 35 | 36 | /****************************************************************************** 37 | * * 38 | * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. * 39 | * * 40 | ******************************************************************************/ 41 | 42 | #include "alt_types.h" 43 | #include "altera_avalon_timer.h" 44 | 45 | #ifdef __cplusplus 46 | extern "C" 47 | { 48 | #endif /* __cplusplus */ 49 | 50 | extern int alt_timestamp_start (void); 51 | 52 | extern alt_timestamp_type alt_timestamp (void); 53 | 54 | extern alt_u32 alt_timestamp_freq (void); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* __ALT_TIMESTAMP_H__ */ 61 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_busy_sleep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2004 Altera Corporation, San Jose, California, USA. 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * 23 | * ------------ 24 | * 25 | * Altera does not recommend, suggest or require that this reference design 26 | * file be used in conjunction or combination with any other product. 27 | * 28 | * alt_busy_sleep.c - Microsecond delay routine which uses a calibrated busy 29 | * loop to perform the delay. This is used to implement 30 | * usleep for both uC/OS-II and the standalone HAL. 31 | * 32 | * Author PRR 33 | * 34 | * Calibrated delay with no timer required 35 | * 36 | * The ASM instructions in the routine are equivalent to 37 | * 38 | * for (i=0;i 45 | #include 46 | 47 | #include "system.h" 48 | #include "alt_types.h" 49 | 50 | #include "priv/alt_busy_sleep.h" 51 | 52 | unsigned int alt_busy_sleep (unsigned int us) 53 | { 54 | /* 55 | * Only delay if ALT_SIM_OPTIMIZE is not defined; i.e., if software 56 | * is built targetting ModelSim RTL simulation, the delay will be 57 | * skipped to speed up simulation. 58 | */ 59 | #ifndef ALT_SIM_OPTIMIZE 60 | unsigned long i, loops; 61 | 62 | // 1 loop >= 7 cyc 63 | loops = ((ALT_CPU_FREQ/1000000)*us)/7; 64 | 65 | for (i=7; i 0 49 | 50 | char* i; 51 | char* end = ((char*) start) + len; 52 | 53 | for (i = start; i < end; i+= NIOS2_DCACHE_LINE_SIZE) 54 | { 55 | ALT_FLUSH_DATA(i); 56 | } 57 | 58 | /* 59 | * For an unaligned flush request, we've got one more line left. 60 | * Note that this is dependent on NIOS2_DCACHE_LINE_SIZE to be a 61 | * multiple of 2 (which it always is). 62 | */ 63 | 64 | if (((alt_u32) start) & (NIOS2_DCACHE_LINE_SIZE - 1)) 65 | { 66 | ALT_FLUSH_DATA(i); 67 | } 68 | 69 | #endif /* NIOS2_DCACHE_SIZE > 0 */ 70 | } 71 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_dcache_flush_all.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003-2005 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | #include "nios2.h" 32 | #include "system.h" 33 | 34 | #include "alt_types.h" 35 | #include "sys/alt_cache.h" 36 | 37 | /* 38 | * alt_dcache_flush_all() is called to flush the entire data cache. 39 | */ 40 | 41 | void alt_dcache_flush_all (void) 42 | { 43 | #if NIOS2_DCACHE_SIZE > 0 44 | char* i; 45 | 46 | for (i = (char*) 0; i < (char*) NIOS2_DCACHE_SIZE; i+= NIOS2_DCACHE_LINE_SIZE) 47 | { 48 | __asm__ volatile ("flushd (%0)" :: "r" (i)); 49 | } 50 | #endif /* NIOS2_DCACHE_SIZE > 0 */ 51 | } 52 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_dev_llist_insert.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "priv/alt_dev_llist.h" 34 | #include "sys/alt_errno.h" 35 | 36 | /* 37 | * 38 | */ 39 | 40 | int alt_dev_llist_insert (alt_dev_llist* dev, alt_llist* list) 41 | { 42 | /* 43 | * check that the device exists, and that it has a valid name. 44 | */ 45 | 46 | if (!dev || !dev->name) 47 | { 48 | ALT_ERRNO = EINVAL; 49 | return -EINVAL; 50 | } 51 | 52 | /* 53 | * register the device. 54 | */ 55 | 56 | alt_llist_insert(list, &dev->llist); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_dma_rxchan_open.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_dma.h" 34 | #include "sys/alt_errno.h" 35 | #include "priv/alt_file.h" 36 | 37 | /* 38 | * The list of registered DMA receive channels. 39 | */ 40 | 41 | ALT_LLIST_HEAD(alt_dma_rxchan_list); 42 | 43 | /* 44 | * alt_dma_txchan_open() is used to obtain an "alt_dma_txchan" descriptor for 45 | * a DMA transmit device. The name is the name of the associated physical 46 | * device (e.g. "/dev/dma_0"). 47 | * 48 | * The return value will be NULL on failure, and non-NULL otherwise. 49 | */ 50 | 51 | alt_dma_rxchan alt_dma_rxchan_open (const char* name) 52 | { 53 | alt_dma_rxchan dev; 54 | 55 | dev = (alt_dma_rxchan) alt_find_dev (name, &alt_dma_rxchan_list); 56 | 57 | if (!dev) 58 | { 59 | ALT_ERRNO = ENODEV; 60 | } 61 | 62 | return dev; 63 | } 64 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_dma_txchan_open.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_dma.h" 34 | #include "sys/alt_errno.h" 35 | #include "priv/alt_file.h" 36 | 37 | /* 38 | * The list of registered receive channels. 39 | */ 40 | 41 | ALT_LLIST_HEAD(alt_dma_txchan_list); 42 | 43 | /* 44 | * alt_dma_txchan_open() is used to obtain an "alt_dma_txchan" descriptor for 45 | * a DMA transmit device. The name is the name of the associated physical 46 | * device (e.g. "/dev/dma_0"). 47 | * 48 | * The return value will be NULL on failure, and non-NULL otherwise. 49 | */ 50 | 51 | alt_dma_txchan alt_dma_txchan_open (const char* name) 52 | { 53 | alt_dma_txchan dev; 54 | 55 | dev = (alt_dma_txchan) alt_find_dev (name, &alt_dma_txchan_list); 56 | 57 | if (!dev) 58 | { 59 | ALT_ERRNO = ENODEV; 60 | } 61 | 62 | return dev; 63 | } 64 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_env_lock.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | /* 36 | * These are the empty env lock/unlock stubs required by newlib. These are 37 | * used to make accesses to environment variables thread safe. The default HAL 38 | * configuration is single threaded, so there is nothing to do here. Note that 39 | * this requires that environment variables are never manipulated by an interrupt 40 | * service routine. 41 | */ 42 | 43 | void __env_lock ( struct _reent *_r ) 44 | { 45 | } 46 | 47 | /* 48 | * 49 | */ 50 | 51 | void __env_unlock ( struct _reent *_r ) 52 | { 53 | } 54 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_environ.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "os/alt_syscall.h" 34 | 35 | /* 36 | * These are the environment variables passed to the C code. By default there 37 | * are no variables registered. An application can manipulate this list using 38 | * getenv() and setenv(). 39 | */ 40 | 41 | char *__env[1] = { 0 }; 42 | char **ALT_ENVIRON = __env; 43 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_errno.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | /* 34 | * This file defines the alt_errno global variable. See comments in 35 | * alt_errno.h for the use of this variable. 36 | */ 37 | 38 | 39 | #include "sys/alt_errno.h" 40 | #include "alt_types.h" 41 | 42 | extern int ALT_WEAK *__errno (void); 43 | 44 | int* (*alt_errno) (void) = __errno; 45 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_execve.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_errno.h" 34 | #include "sys/alt_warning.h" 35 | #include "os/alt_syscall.h" 36 | 37 | /* 38 | * execve() is used by newlib to launch new processes. This is unsupported in 39 | * the HAL environment. However a "do-nothing" implementation is still 40 | * provied for newlib compatability. 41 | * 42 | * ALT_EXECVE is mapped onto the execve() system call in alt_syscall.h 43 | */ 44 | 45 | int ALT_EXECVE (char *name, char ** argv, char** env) 46 | { 47 | /* Generate a link time warning, should this function ever be called. */ 48 | 49 | ALT_STUB_WARNING(execve); 50 | 51 | /* Indicate an error */ 52 | 53 | ALT_ERRNO = ENOSYS; 54 | return -1; 55 | } 56 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_fd_unlock.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | #include "priv/alt_file.h" 36 | 37 | /* 38 | * alt_fd_unlock() is the inverse of alt_fd_lock(). It is called as a 39 | * consequence of a TIOCNXCL ioctl request, e.g: 40 | * 41 | * ioctl (fd, TIOCNXCL, NULL); 42 | * 43 | * It enables multiple file descriptors to exist for the same device. This 44 | * is normally the case, but it may have been disabled by a previous call to 45 | * alt_fd_lock(). 46 | * 47 | * Return zero on sucess, and a negative value on failure. 48 | * 49 | * The current implementation always succeeds. 50 | */ 51 | 52 | int alt_fd_unlock (alt_fd* fd) 53 | { 54 | fd->fd_flags &= ~ALT_FD_EXCL; 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_fork.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_warning.h" 34 | #include "sys/alt_errno.h" 35 | #include "os/alt_syscall.h" 36 | 37 | /* 38 | * The fork() system call is used by newlib to create a duplicate copy of the 39 | * curent process. This is unsupported in the HAL environment. However a 40 | * "do-nothing" implementation is still provied for newlib compatability. 41 | * 42 | * ALT_FORK is mapped onto the fork() system call in alt_syscall.h 43 | */ 44 | 45 | int ALT_FORK (void) 46 | { 47 | /* Generate a link time warning, should this function ever be called. */ 48 | 49 | ALT_STUB_WARNING(fork); 50 | 51 | /* Indicate an error */ 52 | 53 | ALT_ERRNO = ENOSYS; 54 | return -1; 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_getpid.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "os/alt_syscall.h" 34 | 35 | /* 36 | * The getpid() system call is used by newlib to obtain the current process 37 | * id. Since there is only ever a single process in the HAL environment, 38 | * this just returns a constant. 39 | * 40 | * ALT_GETPID is mapped onto the getpid() system call in alt_syscall.h 41 | */ 42 | 43 | int ALT_GETPID (void) 44 | { 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_icache_flush_all.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | #include "nios2.h" 32 | #include "system.h" 33 | 34 | #include "alt_types.h" 35 | #include "sys/alt_cache.h" 36 | 37 | /* 38 | * alt_icache_flush_all() is called to flush the entire instruction cache. 39 | */ 40 | 41 | void alt_icache_flush_all (void) 42 | { 43 | #if NIOS2_ICACHE_SIZE > 0 44 | alt_icache_flush (0, NIOS2_ICACHE_SIZE); 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_irq_vars.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | #include "alt_types.h" 32 | 33 | #include "system.h" 34 | 35 | /* 36 | * These global variables are used to save the current list of enabled 37 | * interrupts. See alt_irq.h for further details. 38 | */ 39 | 40 | volatile alt_u32 alt_irq_active = 0; 41 | 42 | #ifndef ALT_EXCEPTION_STACK 43 | 44 | volatile alt_u32 alt_priority_mask = (alt_u32) -1; 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_link.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_warning.h" 34 | #include "sys/alt_errno.h" 35 | #include "os/alt_syscall.h" 36 | 37 | /* 38 | * link() is used by newlib to create a new link to an existing file. This is 39 | * unsupported in the HAL environment. However a "do-nothing" implementation 40 | * is still provied for newlib compatability. 41 | * 42 | * ALT_LINK is mapped onto the link() system call in alt_syscall.h 43 | */ 44 | 45 | int ALT_LINK ( char *existing, char *new) 46 | { 47 | /* Generate a link time warning, should this function ever be called. */ 48 | 49 | ALT_STUB_WARNING(link); 50 | 51 | /* Indicate an error */ 52 | 53 | ALT_ERRNO = ENOSYS; 54 | return -1; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_log_macro.S: -------------------------------------------------------------------------------- 1 | /* alt_log_macro.S 2 | * 3 | * Implements the function tx_log_str, called by the assembly macro 4 | * ALT_LOG_PUTS(). The macro will be empty when logging is turned off, 5 | * and this function will not be compiled. When logging is on, 6 | * this function is used to print out the strings defined in the beginning 7 | * of alt_log_printf.c, using port information taken from system.h and 8 | * alt_log_printf.h. 9 | * 10 | * This routine only handles strings, and sends a character into the defined 11 | * output device's output buffer when the device is ready. It's intended for 12 | * debugging purposes, where messages can be set to print out at certain 13 | * points in the boot code to indicate the progress of the program. 14 | * 15 | */ 16 | 17 | #ifndef __ALT_LOG_MACROS__ 18 | #define __ALT_LOG_MACROS__ 19 | 20 | /* define this flag to skip assembly-incompatible parts 21 | * of various include files. */ 22 | #define ALT_ASM_SRC 23 | 24 | #ifdef ALT_LOG_ENABLE // only compile this function if this flag is defined. 25 | 26 | #include "system.h" 27 | #include "sys/alt_log_printf.h" 28 | 29 | .global tx_log_str 30 | tx_log_str: 31 | /* load base uart / jtag uart address into r6 */ 32 | movhi r6, %hiadj(ALT_LOG_PORT_BASE) 33 | addi r6, r6, %lo(ALT_LOG_PORT_BASE) 34 | tx_next_char: 35 | /* if pointer points to null, return 36 | * r4 is the pointer to the str to be printed, set by ALT_LOG_PUTS */ 37 | ldb r7, (r4) 38 | beq r0, r7, end_tx 39 | 40 | /* check device transmit ready */ 41 | wait_tx_ready_loop: 42 | ldwio r8, ALT_LOG_PRINT_REG_OFFSET(r6) 43 | /*UART, ALT_LOG_PRINT_MSK == 0x40 44 | JTAG UART, ALT_LOG_PRINT_MSK == 0xFFFF0000 */ 45 | andhi r5, r8, %hi(ALT_LOG_PRINT_MSK) 46 | andi r8, r8, %lo(ALT_LOG_PRINT_MSK) 47 | or r5, r5, r8 48 | beq r5, r0, wait_tx_ready_loop 49 | /* write char */ 50 | stwio r7, ALT_LOG_PRINT_TXDATA_REG_OFFSET (r6) 51 | /* advance string pointer */ 52 | addi r4, r4, 1 53 | br tx_next_char 54 | end_tx: 55 | ret 56 | 57 | #endif 58 | 59 | #endif /* __ALT_LOG_MACROS__ */ 60 | 61 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_malloc_lock.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | /* 36 | * These are the empty malloc lock/unlock stubs required by newlib. These are 37 | * used to make newlib's malloc() function thread safe. The default HAL 38 | * configuration is single threaded, so there is nothing to do here. Note that 39 | * this requires that malloc is never called by an interrupt service routine. 40 | */ 41 | 42 | void __malloc_lock ( struct _reent *_r ) 43 | { 44 | } 45 | 46 | /* 47 | * 48 | */ 49 | 50 | void __malloc_unlock ( struct _reent *_r ) 51 | { 52 | } 53 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_putchar.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2015 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | #ifdef ALT_USE_DIRECT_DRIVERS 36 | #include "system.h" 37 | #include "sys/alt_driver.h" 38 | #include "sys/alt_stdio.h" 39 | #endif 40 | #ifdef ALT_SEMIHOSTING 41 | #include "sys/alt_stdio.h" 42 | #include "unistd.h" 43 | #endif 44 | 45 | /* 46 | * Uses the ALT_DRIVER_WRITE() macro to call directly to driver if available. 47 | * Otherwise, uses newlib provided putchar() routine. 48 | */ 49 | int 50 | alt_putchar(int c) 51 | { 52 | #ifdef ALT_SEMIHOSTING 53 | char c1 = (char)(c & 0xff); 54 | return write(STDOUT_FILENO,&c1,1); 55 | #else 56 | #ifdef ALT_USE_DIRECT_DRIVERS 57 | ALT_DRIVER_WRITE_EXTERNS(ALT_STDOUT_DEV); 58 | char c1 = (char)(c & 0xff); 59 | 60 | if (ALT_DRIVER_WRITE(ALT_STDOUT_DEV, &c1, 1, 0) == -1) { 61 | return -1; 62 | } 63 | return c; 64 | #else 65 | return putchar(c); 66 | #endif 67 | #endif 68 | } 69 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_putstr.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2015 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | #ifdef ALT_USE_DIRECT_DRIVERS 36 | #include 37 | #include "system.h" 38 | #include "sys/alt_driver.h" 39 | #include "sys/alt_stdio.h" 40 | #endif 41 | #ifdef ALT_SEMIHOSTING 42 | #include 43 | #include "sys/alt_stdio.h" 44 | #include "unistd.h" 45 | #endif 46 | 47 | /* 48 | * Uses the ALT_DRIVER_WRITE() macro to call directly to driver if available. 49 | * Otherwise, uses newlib provided fputs() routine. 50 | */ 51 | int 52 | alt_putstr(const char* str) 53 | { 54 | #ifdef ALT_SEMIHOSTING 55 | return write(STDOUT_FILENO,str,strlen(str)); 56 | #else 57 | #ifdef ALT_USE_DIRECT_DRIVERS 58 | ALT_DRIVER_WRITE_EXTERNS(ALT_STDOUT_DEV); 59 | return ALT_DRIVER_WRITE(ALT_STDOUT_DEV, str, strlen(str), 0); 60 | #else 61 | return fputs(str, stdout); 62 | #endif 63 | #endif 64 | } 65 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_release_fd.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_dev.h" 34 | #include "priv/alt_file.h" 35 | 36 | /* 37 | * alt_release_fd() is called to free an allocated file descriptor. This is 38 | * done by setting the device pointer in the file descriptor structure to zero. 39 | * 40 | * File descriptors correcponding to standard in, standard out and standard 41 | * error cannont be released backed to the pool. They are always reserved. 42 | */ 43 | 44 | void alt_release_fd (int fd) 45 | { 46 | if (fd > 2) 47 | { 48 | alt_fd_list[fd].fd_flags = 0; 49 | alt_fd_list[fd].dev = 0; 50 | } 51 | } 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_remap_cached.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003,2007 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | #include "sys/alt_warning.h" 32 | #include "sys/alt_cache.h" 33 | #include "system.h" 34 | 35 | /* 36 | * Convert a pointer to a block of uncached memory into a block of cached memory. 37 | * Return a pointer that should be used to access the cached memory. 38 | */ 39 | 40 | void* 41 | alt_remap_cached(volatile void* ptr, alt_u32 len) 42 | { 43 | #if ALT_CPU_DCACHE_SIZE > 0 44 | #ifdef ALT_CPU_DCACHE_BYPASS_MASK 45 | return (void*) (((alt_u32)ptr) & ~ALT_CPU_DCACHE_BYPASS_MASK); 46 | #else /* No address mask option enabled. */ 47 | /* Generate a link time error, should this function ever be called. */ 48 | ALT_LINK_ERROR("alt_remap_cached() is not available because CPU is not configured to use bit 31 of address to bypass data cache"); 49 | return NULL; 50 | #endif /* No address mask option enabled. */ 51 | #else /* No data cache */ 52 | /* Nothing needs to be done to the pointer. */ 53 | return (void*) ptr; 54 | #endif /* No data cache */ 55 | } 56 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_rename.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_errno.h" 34 | #include "sys/alt_warning.h" 35 | #include "os/alt_syscall.h" 36 | 37 | /* 38 | * _rename() is used by newlib to rename an existing file. This is unsupported 39 | * in the HAL environment. However a "do-nothing" implementation is still 40 | * provied for newlib compatability. 41 | * 42 | * ALT_RENAME is mapped onto the _rename() system call in alt_syscall.h 43 | */ 44 | 45 | int ALT_RENAME (char *existing, char *new) 46 | { 47 | /* Generate a link time warning, should this function ever be called. */ 48 | 49 | ALT_STUB_WARNING(_rename); 50 | 51 | /* Indicate an error */ 52 | 53 | ALT_ERRNO = ENOSYS; 54 | return -1; 55 | } 56 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_software_exception.S: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003-2005 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | /* 32 | * This file provides the global symbol: software_exception. It is provided to 33 | * support legacy code, and should not be used by new software. 34 | * 35 | * It is used by legacy code to invoke the software exception handler as 36 | * defined by version 1.0 of the Nios II kit. It should only be used when you 37 | * are providing your own interrupt entry point, i.e. you are not using 38 | * alt_irq_entry. 39 | */ 40 | 41 | #include "system.h" 42 | 43 | /* 44 | * Pull in the exception handler. 45 | */ 46 | 47 | .globl alt_exception 48 | 49 | .section .exceptions.entry.label, "xa" 50 | 51 | .globl software_exception 52 | .type software_exception, @function 53 | software_exception: 54 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_stat.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "os/alt_syscall.h" 39 | 40 | /* 41 | * The stat() function is similar to the fstat() function in that it is used to 42 | * obtain status information about a file. Instead of using an open file 43 | * descriptor (like fstat()), stat() takes the name of a file as an input 44 | * argument. 45 | * 46 | * ALT_STAT is mapped onto the stat() system call in alt_syscall.h 47 | */ 48 | 49 | int ALT_STAT (const char *file, struct stat *st) 50 | { 51 | int fd; 52 | int rc; 53 | 54 | fd = open (file, 0); 55 | rc = fstat (fd, st); 56 | close (fd); 57 | 58 | return rc; 59 | } 60 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_uncached_free.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003,2007 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | ******************************************************************************/ 30 | 31 | #include "sys/alt_warning.h" 32 | #include "sys/alt_cache.h" 33 | #include "system.h" 34 | 35 | /* 36 | * Free a block of uncached memory. 37 | */ 38 | 39 | void 40 | alt_uncached_free(volatile void* ptr) 41 | { 42 | #if ALT_CPU_DCACHE_SIZE > 0 43 | #ifdef ALT_CPU_DCACHE_BYPASS_MASK 44 | free((void*) (((alt_u32)ptr) & ~ALT_CPU_DCACHE_BYPASS_MASK)); 45 | #else /* No address mask option enabled. */ 46 | /* Generate a link time error, should this function ever be called. */ 47 | ALT_LINK_ERROR("alt_uncached_free() is not available because CPU is not configured to use bit 31 of address to bypass data cache"); 48 | #endif /* No address mask option enabled. */ 49 | #else /* No data cache */ 50 | /* Nothing needs to be done to the pointer. */ 51 | free((void*)ptr); 52 | #endif /* No data cache */ 53 | } 54 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_unlink.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_errno.h" 34 | #include "sys/alt_warning.h" 35 | #include "os/alt_syscall.h" 36 | 37 | /* 38 | * unlink() is used by newlib to delete an existing link to a file. This is 39 | * unsupported in the HAL environment. However a "do-nothing" implementation 40 | * is still provied for newlib compatability. 41 | * 42 | * ALT_UNLINK is mapped onto the unlink() system call in alt_syscall.h 43 | */ 44 | 45 | int ALT_UNLINK (char *name) 46 | { 47 | /* Generate a link time warning, should this function ever be called. */ 48 | 49 | ALT_STUB_WARNING(unlink); 50 | 51 | /* Indicate an error */ 52 | 53 | ALT_ERRNO = ENOSYS; 54 | return -1; 55 | } 56 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_usleep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * 23 | * ------------ 24 | * 25 | * Altera does not recommend, suggest or require that this reference design 26 | * file be used in conjunction or combination with any other product. 27 | * 28 | * usleep.c - Microsecond delay routine 29 | */ 30 | 31 | #include 32 | 33 | #include "priv/alt_busy_sleep.h" 34 | #include "os/alt_syscall.h" 35 | 36 | /* 37 | * This function simply calls alt_busy_sleep() to perform the delay. This 38 | * function implements the delay as a calibrated "busy loop". 39 | * 40 | * ALT_USLEEP is mapped onto the usleep() system call in alt_syscall.h 41 | */ 42 | 43 | 44 | 45 | #if defined (__GNUC__) && __GNUC__ >= 4 46 | int ALT_USLEEP (useconds_t us) 47 | #else 48 | unsigned int ALT_USLEEP (unsigned int us) 49 | #endif 50 | { 51 | return alt_busy_sleep(us); 52 | } 53 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/alt_wait.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include "sys/alt_errno.h" 34 | #include "os/alt_syscall.h" 35 | 36 | /* 37 | * wait() is used by newlib to wait for all child processes to exit. Since the 38 | * HAL does not support spawning child processes, this returns immediately as 39 | * there can't be anythign to wait for. 40 | * 41 | * ALT_WAIT is mapped onto the wait() system call in alt_syscall.h 42 | */ 43 | 44 | int ALT_WAIT (int *status) 45 | { 46 | *status = 0; 47 | 48 | ALT_ERRNO = ECHILD; 49 | 50 | return -1; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/HAL/src/altera_nios2_gen2_irq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Altera Corporation, San Jose, California, USA. 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * 23 | * altera_nios2_gen2_irq.c - Support for Nios II internal interrupt controller. 24 | * 25 | */ 26 | 27 | #include "sys/alt_irq.h" 28 | #include "altera_nios2_gen2_irq.h" 29 | 30 | /* 31 | * To initialize the internal interrupt controller, just clear the IENABLE 32 | * register so that all possible IRQs are disabled. 33 | */ 34 | void altera_nios2_gen2_irq_init(void) 35 | { 36 | NIOS2_WRITE_IENABLE(0); 37 | } 38 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/create-this-bsp: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script creates the ucosii_net_zipfs Board Support Package (BSP). 4 | 5 | BSP_TYPE=hal 6 | BSP_DIR=. 7 | SOPC_DIR=../../ 8 | SOPC_FILE=../../sys.sopcinfo 9 | NIOS2_BSP_ARGS="" 10 | CPU_NAME= 11 | 12 | if [ -n "$CPU_NAME" ]; then 13 | NIOS2_BSP_ARGS="$NIOS2_BSP_ARGS --cpu-name $CPU_NAME" 14 | fi 15 | 16 | # Don't run make if create-this-app script is called with --no-make arg 17 | SKIP_MAKE= 18 | while [ $# -gt 0 ] 19 | do 20 | case "$1" in 21 | --no-make) 22 | SKIP_MAKE=1 23 | ;; 24 | *) 25 | NIOS2_BSP_ARGS="$NIOS2_BSP_ARGS $1" 26 | ;; 27 | esac 28 | shift 29 | done 30 | 31 | 32 | # Run nios2-bsp utility to create a hal BSP in this directory 33 | # for the system with a .sopc file in $SOPC_FILE. 34 | # Deprecating $SOPC_DIR in 10.1. Multiple .sopcinfo files in a directory may exist. 35 | 36 | if [ -z "$SOPC_FILE" ]; then 37 | echo "WARNING: Use of a directory for locating a .sopcinfo file is deprecated in 10.1. Multiple .sopcinfo files may exist. You must specify the full .sopcinfo path." 38 | cmd="nios2-bsp $BSP_TYPE $BSP_DIR $SOPC_DIR $NIOS2_BSP_ARGS" 39 | else 40 | cmd="nios2-bsp $BSP_TYPE $BSP_DIR $SOPC_FILE $NIOS2_BSP_ARGS" 41 | fi 42 | 43 | 44 | echo "create-this-bsp: Running \"$cmd\"" 45 | $cmd || { 46 | echo "$cmd failed" 47 | exit 1 48 | } 49 | if [ -z "$SKIP_MAKE" ]; then 50 | echo "create-this-bsp: Running make" 51 | make 52 | fi 53 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/inc/i2c_opencores.h: -------------------------------------------------------------------------------- 1 | ../../../../ip/i2c_opencores/HAL/inc/i2c_opencores.h -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/inc/i2c_opencores_regs.h: -------------------------------------------------------------------------------- 1 | ../../../../ip/i2c_opencores/inc/i2c_opencores_regs.h -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/inc/osd_generator_regs.h: -------------------------------------------------------------------------------- 1 | ../../../../ip/osd_generator/inc/osd_generator_regs.h -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/inc/pll_reconfig_regs.h: -------------------------------------------------------------------------------- 1 | ../../../../ip/pll_reconfig/inc/pll_reconfig_regs.h -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/inc/sc_config_regs.h: -------------------------------------------------------------------------------- 1 | ../../../../ip/sc_config/inc/sc_config_regs.h -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/src/altera_avalon_timer_vars.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * License Agreement * 4 | * * 5 | * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. * 6 | * All rights reserved. * 7 | * * 8 | * Permission is hereby granted, free of charge, to any person obtaining a * 9 | * copy of this software and associated documentation files (the "Software"), * 10 | * to deal in the Software without restriction, including without limitation * 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 12 | * and/or sell copies of the Software, and to permit persons to whom the * 13 | * Software is furnished to do so, subject to the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be included in * 16 | * all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * 24 | * DEALINGS IN THE SOFTWARE. * 25 | * * 26 | * This agreement shall be governed in all respects by the laws of the State * 27 | * of California and by the laws of the United States of America. * 28 | * * 29 | * Altera does not recommend, suggest or require that this reference design * 30 | * file be used in conjunction or combination with any other product. * 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | #include "altera_avalon_timer.h" 36 | #include "alt_types.h" 37 | 38 | /* 39 | * Variables used to store the timestamp parameters. These are initialised 40 | * from alt_sys_init() using the ALTERA_AVALON_TIMER_INIT macro 41 | * defined in altera_avalon_timer.h. 42 | */ 43 | 44 | void* altera_avalon_timer_ts_base = (void*) 0; 45 | alt_u32 altera_avalon_timer_ts_freq = 0; 46 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/drivers/src/i2c_opencores.c: -------------------------------------------------------------------------------- 1 | ../../../../ip/i2c_opencores/HAL/src/i2c_opencores.c -------------------------------------------------------------------------------- /software/sys_controller_bsp/libhal_bsp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marqs85/ossc/429b0f720178f98e96b7ab63ff79934ed6026536/software/sys_controller_bsp/libhal_bsp.a -------------------------------------------------------------------------------- /software/sys_controller_bsp/linker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linker.h - Linker script mapping information 3 | * 4 | * Machine generated for CPU 'nios2_qsys_0' in SOPC Builder design 'sys' 5 | * SOPC Builder design path: ../../sys.sopcinfo 6 | * 7 | * Generated: Fri Oct 05 19:59:02 EEST 2018 8 | */ 9 | 10 | /* 11 | * DO NOT MODIFY THIS FILE 12 | * 13 | * Changing this file will have subtle consequences 14 | * which will almost certainly lead to a nonfunctioning 15 | * system. If you do modify this file, be aware that your 16 | * changes will be overwritten and lost when this file 17 | * is generated again. 18 | * 19 | * DO NOT MODIFY THIS FILE 20 | */ 21 | 22 | /* 23 | * License Agreement 24 | * 25 | * Copyright (c) 2008 26 | * Altera Corporation, San Jose, California, USA. 27 | * All rights reserved. 28 | * 29 | * Permission is hereby granted, free of charge, to any person obtaining a 30 | * copy of this software and associated documentation files (the "Software"), 31 | * to deal in the Software without restriction, including without limitation 32 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 33 | * and/or sell copies of the Software, and to permit persons to whom the 34 | * Software is furnished to do so, subject to the following conditions: 35 | * 36 | * The above copyright notice and this permission notice shall be included in 37 | * all copies or substantial portions of the Software. 38 | * 39 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 44 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 45 | * DEALINGS IN THE SOFTWARE. 46 | * 47 | * This agreement shall be governed in all respects by the laws of the State 48 | * of California and by the laws of the United States of America. 49 | */ 50 | 51 | #ifndef __LINKER_H_ 52 | #define __LINKER_H_ 53 | 54 | 55 | /* 56 | * BSP controls alt_load() behavior in crt0. 57 | * 58 | */ 59 | 60 | #define ALT_LOAD_EXPLICITLY_CONTROLLED 61 | 62 | 63 | /* 64 | * Base address and span (size in bytes) of each linker region 65 | * 66 | */ 67 | 68 | #define EPCQ_CONTROLLER_0_AVL_MEM_REGION_BASE 0x800000 69 | #define EPCQ_CONTROLLER_0_AVL_MEM_REGION_SPAN 8388608 70 | #define ONCHIP_MEMORY2_0_REGION_BASE 0x10020 71 | #define ONCHIP_MEMORY2_0_REGION_SPAN 36832 72 | #define RESET_REGION_BASE 0x10000 73 | #define RESET_REGION_SPAN 32 74 | 75 | 76 | /* 77 | * Devices associated with code sections 78 | * 79 | */ 80 | 81 | #define ALT_EXCEPTIONS_DEVICE ONCHIP_MEMORY2_0 82 | #define ALT_RESET_DEVICE ONCHIP_MEMORY2_0 83 | #define ALT_RODATA_DEVICE ONCHIP_MEMORY2_0 84 | #define ALT_RWDATA_DEVICE ONCHIP_MEMORY2_0 85 | #define ALT_TEXT_DEVICE ONCHIP_MEMORY2_0 86 | 87 | 88 | /* 89 | * Initialization code at the reset address is allowed (e.g. no external bootloader). 90 | * 91 | */ 92 | 93 | #define ALT_ALLOW_CODE_AT_RESET 94 | 95 | 96 | /* 97 | * The alt_load() facility is called from crt0 to copy sections into RAM. 98 | * 99 | */ 100 | 101 | #define ALT_LOAD_COPY_RWDATA 102 | 103 | #endif /* __LINKER_H_ */ 104 | -------------------------------------------------------------------------------- /software/sys_controller_bsp/memory.gdb: -------------------------------------------------------------------------------- 1 | # memory.gdb - GDB memory region definitions 2 | # 3 | # Machine generated for CPU 'nios2_qsys_0' in SOPC Builder design 'sys' 4 | # SOPC Builder design path: ../../sys.sopcinfo 5 | # 6 | # Generated: Fri Oct 05 19:59:02 EEST 2018 7 | 8 | # DO NOT MODIFY THIS FILE 9 | # 10 | # Changing this file will have subtle consequences 11 | # which will almost certainly lead to a nonfunctioning 12 | # system. If you do modify this file, be aware that your 13 | # changes will be overwritten and lost when this file 14 | # is generated again. 15 | # 16 | # DO NOT MODIFY THIS FILE 17 | 18 | # License Agreement 19 | # 20 | # Copyright (c) 2008 21 | # Altera Corporation, San Jose, California, USA. 22 | # All rights reserved. 23 | # 24 | # Permission is hereby granted, free of charge, to any person obtaining a 25 | # copy of this software and associated documentation files (the "Software"), 26 | # to deal in the Software without restriction, including without limitation 27 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 28 | # and/or sell copies of the Software, and to permit persons to whom the 29 | # Software is furnished to do so, subject to the following conditions: 30 | # 31 | # The above copyright notice and this permission notice shall be included in 32 | # all copies or substantial portions of the Software. 33 | # 34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 39 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 40 | # DEALINGS IN THE SOFTWARE. 41 | # 42 | # This agreement shall be governed in all respects by the laws of the State 43 | # of California and by the laws of the United States of America. 44 | 45 | # Define memory regions for each memory connected to the CPU. 46 | # The cache attribute is specified which improves GDB performance 47 | # by allowing GDB to cache memory contents on the host. 48 | 49 | # onchip_memory2_0 50 | memory 0x10000 0x19000 cache 51 | 52 | # epcq_controller_0_avl_mem 53 | memory 0x800000 0x1000000 cache 54 | -------------------------------------------------------------------------------- /tools/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: generate_hex update_mif generate_firmware assemble_ossc 2 | 3 | all: generate_firmware 4 | 5 | generate_hex: bin2hex 6 | $(MAKE) -C ../software/sys_controller generate_hex 7 | 8 | update_mif: generate_hex 9 | cd .. && quartus_cdb ossc --update_mif 10 | 11 | assemble_ossc: update_mif 12 | cd .. && quartus_asm ossc 13 | 14 | generate_firmware: assemble_ossc create_fw_img 15 | ./create_fw_img ../output_files/ossc.rbf 0.86 aud-psp 16 | 17 | bin2hex: bin2hex.c 18 | $(CC) bin2hex.c -o bin2hex 19 | 20 | create_fw_img: create_fw_img.c 21 | gcc create_fw_img.c -o create_fw_img 22 | 23 | # vim: set noet ts=2 sw=2 sts=2 24 | -------------------------------------------------------------------------------- /tools/bin2hex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) 11 | { 12 | unsigned char block[256]; 13 | unsigned int csum; 14 | 15 | int fd_i, bc; 16 | FILE *fd_o; 17 | struct stat fileinfo; 18 | 19 | unsigned int i, j; 20 | 21 | if (argc != 4) { 22 | printf("usage: %s width binfile hexfile\n", argv[0]); 23 | return -1; 24 | } 25 | 26 | bc = atoi(argv[1]); 27 | if ((bc < 1) || (bc > 255)) { 28 | printf("byte count per line must be 1-255"); 29 | return -1; 30 | } 31 | 32 | if ((fd_i = open(argv[2], O_RDONLY)) == -1 || fstat(fd_i, &fileinfo) == -1) { 33 | printf("Couldn't open file\n"); 34 | return -1; 35 | } 36 | 37 | printf("size: %u bytes\n", fileinfo.st_size); 38 | 39 | if ((fd_o = fopen(argv[3], "w")) == NULL) { 40 | printf("invalid outfile\n"); 41 | return -1; 42 | } 43 | 44 | for (i=0; i>8)+((i/bc)&0xff); 47 | for (j=0; j