Compare commits

...

2 Commits

Author SHA1 Message Date
marqs
3194ec6ed3 integrate userdata structure from Ossc Pro 2025-08-27 18:27:19 +03:00
marqs
05a9e351d4 integrate general improvements from Ossc Pro
* OSD timing optimizations and cursor color selection
* flash robustness fixes
2025-08-21 18:51:46 +03:00
25 changed files with 613 additions and 16240 deletions

View File

@ -36,8 +36,9 @@ typedef union {
uint8_t y_offset:3; uint8_t y_offset:3;
uint8_t x_size:2; uint8_t x_size:2;
uint8_t y_size:2; uint8_t y_size:2;
uint8_t border_color:2; uint8_t border_color:3;
uint32_t osd_rsv:15; uint8_t highlight_color:3;
uint32_t osd_rsv:11;
} __attribute__((packed, __may_alias__)); } __attribute__((packed, __may_alias__));
uint32_t data; uint32_t data;
} osd_config_reg; } osd_config_reg;

View File

@ -156,4 +156,4 @@ add_interface_port osd_if vclk vclk Input 1
add_interface_port osd_if xpos xpos Input 11 add_interface_port osd_if xpos xpos Input 11
add_interface_port osd_if ypos ypos Input 11 add_interface_port osd_if ypos ypos Input 11
add_interface_port osd_if osd_enable osd_enable Output 1 add_interface_port osd_if osd_enable osd_enable Output 1
add_interface_port osd_if osd_color osd_color Output 2 add_interface_port osd_if osd_color osd_color Output 3

View File

@ -35,7 +35,7 @@ module osd_generator_top (
input [10:0] xpos, input [10:0] xpos,
input [10:0] ypos, input [10:0] ypos,
output reg osd_enable, output reg osd_enable,
output reg [1:0] osd_color output reg [2:0] osd_color
); );
localparam CHAR_ROWS = 30; localparam CHAR_ROWS = 30;
@ -43,10 +43,10 @@ localparam CHAR_COLS = 16;
localparam CHAR_SECTIONS = 2; localparam CHAR_SECTIONS = 2;
localparam CHAR_SEC_SEPARATOR = 2; localparam CHAR_SEC_SEPARATOR = 2;
localparam BG_BLACK = 2'h0; localparam BG_BLACK = 3'h0;
localparam BG_BLUE = 2'h1; localparam BG_BLUE = 3'h1;
localparam BG_YELLOW = 2'h2; localparam BG_YELLOW = 3'h6;
localparam BG_WHITE = 2'h3; localparam BG_WHITE = 3'h7;
localparam OSD_CONFIG_REGNUM = 8'hf0; localparam OSD_CONFIG_REGNUM = 8'hf0;
localparam OSD_ROW_LSEC_ENABLE_REGNUM = 8'hf1; localparam OSD_ROW_LSEC_ENABLE_REGNUM = 8'hf1;
@ -59,7 +59,9 @@ reg [31:0] config_reg[OSD_ROW_LSEC_ENABLE_REGNUM:OSD_ROW_COLOR_REGNUM] /* synthe
reg [10:0] xpos_osd_area_scaled, xpos_text_scaled; reg [10:0] xpos_osd_area_scaled, xpos_text_scaled;
reg [10:0] ypos_osd_area_scaled, ypos_text_scaled; reg [10:0] ypos_osd_area_scaled, ypos_text_scaled;
reg [7:0] x_ptr[2:5], y_ptr[2:5] /* synthesis ramstyle = "logic" */; reg [7:0] x_ptr[2:5], y_ptr[2:5] /* synthesis ramstyle = "logic" */;
reg osd_text_act_pp[2:6], osd_act_pp[3:6]; reg osd_text_act_lsec_x_hit, osd_text_act_lsec_en, osd_text_act_rsec_x_hit, osd_text_act_rsec_en, osd_text_act_y_hit;
reg osd_act_lsec_x_hit, osd_act_lsec_en, osd_act_rsec_x_hit, osd_act_rsec_en, osd_act_y_hit;
reg osd_text_act_pp[3:6], osd_act_pp[4:6];
reg [14:0] to_ctr, to_ctr_ms; reg [14:0] to_ctr, to_ctr_ms;
reg char_px; reg char_px;
@ -71,7 +73,8 @@ wire [2:0] x_offset = osd_config[7:5];
wire [2:0] y_offset = osd_config[10:8]; wire [2:0] y_offset = osd_config[10:8];
wire [1:0] x_size = osd_config[12:11]; wire [1:0] x_size = osd_config[12:11];
wire [1:0] y_size = osd_config[14:13]; wire [1:0] y_size = osd_config[14:13];
wire [1:0] border_color = osd_config[16:15]; wire [2:0] border_color = osd_config[17:15];
wire [2:0] highlight_color = osd_config[20:18];
wire [10:0] xpos_scaled_w = (xpos >> x_size)-({3'h0, x_offset} << 3); wire [10:0] xpos_scaled_w = (xpos >> x_size)-({3'h0, x_offset} << 3);
wire [10:0] ypos_scaled_w = (ypos >> y_size)-({3'h0, y_offset} << 3); wire [10:0] ypos_scaled_w = (ypos >> y_size)-({3'h0, y_offset} << 3);
@ -123,21 +126,27 @@ always @(posedge vclk) begin
y_ptr[pp_idx] <= y_ptr[pp_idx-1]; y_ptr[pp_idx] <= y_ptr[pp_idx-1];
end end
osd_text_act_pp[2] <= render_enable & osd_text_act_lsec_x_hit <= (xpos_text_scaled < 8*CHAR_COLS);
osd_text_act_lsec_en <= config_reg[OSD_ROW_LSEC_ENABLE_REGNUM][ypos_text_scaled/8];
osd_text_act_rsec_x_hit <= (xpos_text_scaled >= 8*(CHAR_COLS+CHAR_SEC_SEPARATOR)) & (xpos_text_scaled < 8*(2*CHAR_COLS+CHAR_SEC_SEPARATOR));
osd_text_act_rsec_en <= config_reg[OSD_ROW_RSEC_ENABLE_REGNUM][ypos_text_scaled/8];
osd_text_act_y_hit <= (ypos_text_scaled < 8*CHAR_ROWS);
osd_text_act_pp[3] <= render_enable &
(menu_active || (to_ctr_ms > 0)) & (menu_active || (to_ctr_ms > 0)) &
(((xpos_text_scaled < 8*CHAR_COLS) & config_reg[OSD_ROW_LSEC_ENABLE_REGNUM][ypos_text_scaled/8]) | ((osd_text_act_lsec_x_hit & osd_text_act_lsec_en) | (osd_text_act_rsec_x_hit & osd_text_act_rsec_en)) & osd_text_act_y_hit;
((xpos_text_scaled >= 8*(CHAR_COLS+CHAR_SEC_SEPARATOR)) & (xpos_text_scaled < 8*(2*CHAR_COLS+CHAR_SEC_SEPARATOR)) & config_reg[OSD_ROW_RSEC_ENABLE_REGNUM][ypos_text_scaled/8])) & for(pp_idx = 4; pp_idx <= 6; pp_idx = pp_idx+1) begin
(ypos_text_scaled < 8*CHAR_ROWS);
for(pp_idx = 3; pp_idx <= 6; pp_idx = pp_idx+1) begin
osd_text_act_pp[pp_idx] <= osd_text_act_pp[pp_idx-1]; osd_text_act_pp[pp_idx] <= osd_text_act_pp[pp_idx-1];
end end
osd_act_pp[3] <= render_enable & osd_act_lsec_x_hit <= (xpos_osd_area_scaled/8 < (CHAR_COLS+1));
osd_act_lsec_en <= config_reg[OSD_ROW_LSEC_ENABLE_REGNUM][(ypos_osd_area_scaled/8) ? ((ypos_osd_area_scaled/8)-1) : 0];
osd_act_rsec_x_hit <= (xpos_osd_area_scaled/8 >= (CHAR_COLS+1)) & (xpos_osd_area_scaled/8 < (2*CHAR_COLS+CHAR_SEC_SEPARATOR+1));
osd_act_rsec_en <= (config_reg[OSD_ROW_RSEC_ENABLE_REGNUM][(ypos_osd_area_scaled/8)-1] | config_reg[OSD_ROW_RSEC_ENABLE_REGNUM][ypos_osd_area_scaled/8]);
osd_act_y_hit <= (ypos_osd_area_scaled < 8*(CHAR_ROWS+1));
osd_act_pp[4] <= render_enable &
(menu_active || (to_ctr_ms > 0)) & (menu_active || (to_ctr_ms > 0)) &
(((xpos_osd_area_scaled/8 < (CHAR_COLS+1)) & config_reg[OSD_ROW_LSEC_ENABLE_REGNUM][(ypos_osd_area_scaled/8) ? ((ypos_osd_area_scaled/8)-1) : 0]) | ((osd_act_lsec_x_hit & osd_act_lsec_en) | (osd_act_rsec_x_hit & osd_act_rsec_en)) & osd_act_y_hit;
((xpos_osd_area_scaled/8 >= (CHAR_COLS+1)) & (xpos_osd_area_scaled/8 < (2*CHAR_COLS+CHAR_SEC_SEPARATOR+1)) & (config_reg[OSD_ROW_RSEC_ENABLE_REGNUM][(ypos_osd_area_scaled/8)-1] | config_reg[OSD_ROW_RSEC_ENABLE_REGNUM][ypos_osd_area_scaled/8]))) & for(pp_idx = 5; pp_idx <= 6; pp_idx = pp_idx+1) begin
(ypos_osd_area_scaled < 8*(CHAR_ROWS+1));
for(pp_idx = 4; pp_idx <= 6; pp_idx = pp_idx+1) begin
osd_act_pp[pp_idx] <= osd_act_pp[pp_idx-1]; osd_act_pp[pp_idx] <= osd_act_pp[pp_idx-1];
end end
@ -147,7 +156,7 @@ always @(posedge vclk) begin
if (osd_text_act_pp[6]) begin if (osd_text_act_pp[6]) begin
if (char_px) begin if (char_px) begin
osd_color <= config_reg[OSD_ROW_COLOR_REGNUM][char_row] ? BG_YELLOW : BG_WHITE; osd_color <= config_reg[OSD_ROW_COLOR_REGNUM][char_row] ? highlight_color : BG_WHITE;
end else begin end else begin
osd_color <= BG_BLUE; osd_color <= BG_BLUE;
end end

View File

@ -16,7 +16,7 @@
<hex_block> <hex_block>
<hex_filename>software/sys_controller/mem_init/flash.hex</hex_filename> <hex_filename>software/sys_controller/mem_init/flash.hex</hex_filename>
<hex_addressing>relative</hex_addressing> <hex_addressing>relative</hex_addressing>
<hex_offset>524288</hex_offset> <hex_offset>327680</hex_offset>
<hex_little_endian>0</hex_little_endian> <hex_little_endian>0</hex_little_endian>
</hex_block> </hex_block>
<version>10</version> <version>10</version>

View File

@ -2,10 +2,12 @@
create_clock -period 27MHz -name clk27 [get_ports clk27] create_clock -period 27MHz -name clk27 [get_ports clk27]
set_input_delay -clock clk27 0 [get_ports {sda scl SD_CMD SD_DAT* *ALTERA_DATA0}] set_input_delay -clock clk27 0 [get_ports {sda scl SD_CMD SD_DAT*}]
set_false_path -from [get_ports {btn* cfg* ir_rx HDMI_TX_INT_N LED_R}] set_false_path -from [get_ports {btn* cfg* ir_rx HDMI_TX_INT_N LED_R}]
set_false_path -to {sys:sys_inst|sys_pio_1:pio_1|readdata*} set_false_path -to {sys:sys_inst|sys_pio_1:pio_1|readdata*}
create_generated_clock -name flash_clk -divide_by 2 -source clk27 [get_pins sys:sys_inst|sys_intel_generic_serial_flash_interface_top_0:intel_generic_serial_flash_interface_top_0|sys_intel_generic_serial_flash_interface_top_0_qspi_inf_inst:qspi_inf_inst|flash_clk_reg|q]
create_generated_clock -name flash_clk_out -master_clock flash_clk -source [get_pins sys:sys_inst|sys_intel_generic_serial_flash_interface_top_0:intel_generic_serial_flash_interface_top_0|sys_intel_generic_serial_flash_interface_top_0_qspi_inf_inst:qspi_inf_inst|flash_clk_reg|q] -multiply_by 1 [get_ports *ALTERA_DCLK]
### Scanconverter clock constraints ### ### Scanconverter clock constraints ###
@ -55,6 +57,11 @@ set_false_path -to [remove_from_collection [all_outputs] $critoutputs_hdmi]
# Lumacode (constrained to max. 60MHz sampling) # Lumacode (constrained to max. 60MHz sampling)
set_max_delay 16.6 -from [get_registers sys:sys_inst|sc_config_top:sc_config_0|altsyncram:lumacode_pal_ram|*] set_max_delay 16.6 -from [get_registers sys:sys_inst|sc_config_top:sc_config_0|altsyncram:lumacode_pal_ram|*]
# Flash controller (delays from N25Q128A datasheet)
set_input_delay -clock flash_clk_out -clock_fall 5 [get_ports *ALTERA_DATA0]
set_output_delay -clock flash_clk_out 4 [get_ports *ALTERA_SCE]
set_output_delay -clock flash_clk_out 2 [get_ports *ALTERA_SDO]
### CPU/scanconverter clock relations ### ### CPU/scanconverter clock relations ###

View File

@ -137,7 +137,7 @@ reg remote_event_prev;
reg [14:0] to_ctr, to_ctr_ms; reg [14:0] to_ctr, to_ctr_ms;
wire lcd_bl_timeout; wire lcd_bl_timeout;
wire [1:0] osd_color; wire [2:0] osd_color;
wire osd_enable_pre; wire osd_enable_pre;
wire osd_enable = osd_enable_pre & ~lt_active; wire osd_enable = osd_enable_pre & ~lt_active;
wire [10:0] xpos_sc; wire [10:0] xpos_sc;
@ -325,15 +325,7 @@ end
// Output registers // Output registers
always @(posedge pclk_out) begin always @(posedge pclk_out) begin
if (osd_enable) begin if (osd_enable) begin
if (osd_color == 2'h0) begin {HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= {{8{osd_color[2]}}, {8{osd_color[1]}}, {8{osd_color[0]}}};
{HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= 24'h000000;
end else if (osd_color == 2'h1) begin
{HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= 24'h0000ff;
end else if (osd_color == 2'h2) begin
{HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= 24'hffff00;
end else begin
{HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= 24'hffffff;
end
end else begin end else begin
{HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= {R_sc, G_sc, B_sc}; {HDMI_TX_RD, HDMI_TX_GD, HDMI_TX_BD} <= {R_sc, G_sc, B_sc};
end end
@ -385,7 +377,7 @@ sys sys_inst(
.reset_po_reset_n (po_reset_n), .reset_po_reset_n (po_reset_n),
.ibex_0_ndm_ndmreset_o (ndmreset_req), .ibex_0_ndm_ndmreset_o (ndmreset_req),
.ibex_0_ndm_ndmreset_ack_i (ndmreset_ack), .ibex_0_ndm_ndmreset_ack_i (ndmreset_ack),
.ibex_0_config_boot_addr_i (32'h02080000), .ibex_0_config_boot_addr_i (32'h02050000),
.ibex_0_config_core_sleep_o (), .ibex_0_config_core_sleep_o (),
.master_0_master_reset_reset (jtagm_reset_req), .master_0_master_reset_reset (jtagm_reset_req),
.i2c_opencores_0_export_scl_pad_io (scl), .i2c_opencores_0_export_scl_pad_io (scl),
@ -432,9 +424,9 @@ sys sys_inst(
.pll_reconfig_0_pll_reconfig_if_scandone (pll_scandone) .pll_reconfig_0_pll_reconfig_if_scandone (pll_scandone)
); );
// These do not work in current Quartus version (23.1) and a patch file (scripts/qsys.patch) must be used after Qsys generation instead // These do not work in current Quartus version (24.1) and a patch file (scripts/qsys.patch) must be used after Qsys generation instead
defparam defparam
sys_inst.master_0.fifo.USE_MEMORY_BLOCKS = 0; sys_inst.master_0.fifo.FIFO_DEPTH = 1024;
scanconverter #( scanconverter #(
.EMIF_ENABLE(0), .EMIF_ENABLE(0),

13
scripts/qsys.patch Normal file
View File

@ -0,0 +1,13 @@
--- sys/synthesis/submodules/sys_master_0.v 2025-07-25 10:15:46.708247405 +0300
+++ sys/synthesis/submodules/sys_master_0.v 2025-07-25 10:15:54.937804924 +0300
@@ -156,9 +156,9 @@
altera_avalon_sc_fifo #(
.SYMBOLS_PER_BEAT (1),
.BITS_PER_SYMBOL (8),
- .FIFO_DEPTH (64),
+ .FIFO_DEPTH (1024),
.CHANNEL_WIDTH (0),
.ERROR_WIDTH (0),
.USE_PACKETS (0),
.USE_FILL_LEVEL (0),

View File

@ -1,6 +1,6 @@
# flash details # flash details
set flash_base 0x02000000 set flash_base 0x02000000
set flash_imem_offset 0x00080000 set flash_imem_offset 0x00050000
set flash_imem_base [format 0x%.8x [expr $flash_base + $flash_imem_offset]] set flash_imem_base [format 0x%.8x [expr $flash_base + $flash_imem_offset]]
set flash_secsize 65536 set flash_secsize 65536
@ -64,21 +64,24 @@ for {set i 0} {$i<$num_sectors} {incr i} {
} }
puts "Writing flash" puts "Writing flash"
# writes garbage and occasionally hangs (bug in generic serial flash IF?) # JTAG to Avalon master does not support sink backpressure
#master_write_from_file $claim_path mem_init/flash.bin $flash_imem_base #master_write_from_file $claim_path mem_init/flash.bin $flash_imem_base
# work around the issue by writing into small chunks so that FIFO does not fill up # work around lack of backpressure support by writing chunks of master FIFO size
set chunks [llength [glob mem_init/chunks/*]] set chunks [llength [glob mem_init/chunks/*]]
puts "Programming $chunks chunks" puts "Programming $chunks chunks"
set addr $flash_imem_base set addr $flash_imem_base
for {set i 0} {$i<$chunks} {incr i} { for {set i 0} {$i<$chunks} {incr i} {
set file [format "flash.%04d" $i] set file [format "flash.%04d" $i]
master_write_from_file $claim_path mem_init/chunks/$file $addr master_write_from_file $claim_path mem_init/chunks/$file $addr
set addr [expr $addr + 64] set addr [expr $addr + 1024]
} }
#master_read_to_file $claim_path mem_init/flash_readback.bin $flash_imem_base $bin_size #master_read_to_file $claim_path mem_init/flash_readback.bin $flash_imem_base $bin_size
#master_read_to_file $claim_path mem_init/ram_readback.bin 0x010000 65536 #master_read_to_file $claim_path mem_init/ram_readback.bin 0x010000 65536
# flush flashctrl cmd fifo to ensure writes have finished
master_read_32 $claim_path $flash_base 1
puts "Resetting system" puts "Resetting system"
master_write_32 $claim_path 0x40 0x00000003 master_write_32 $claim_path 0x40 0x00000003
after 1 after 1
@ -86,4 +89,4 @@ master_write_32 $claim_path 0x40 0x00000001
master_write_32 $claim_path 0x40 0x00000000 master_write_32 $claim_path 0x40 0x00000000
close_service master $claim_path close_service master $claim_path
puts "Done" puts "Done"

View File

@ -208,7 +208,7 @@ APP_CFLAGS_UNDEFINED_SYMBOLS :=
APP_CFLAGS_OPTIMIZATION := -Os APP_CFLAGS_OPTIMIZATION := -Os
APP_CFLAGS_DEBUG_LEVEL := APP_CFLAGS_DEBUG_LEVEL :=
APP_CFLAGS_WARNINGS := -Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-function -Wno-packed-bitfield-compat APP_CFLAGS_WARNINGS := -Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-function -Wno-packed-bitfield-compat
APP_CFLAGS_USER_FLAGS := -fdata-sections -ffunction-sections -fshort-enums -fgnu89-inline -flto APP_CFLAGS_USER_FLAGS := -fdata-sections -ffunction-sections -fshort-enums -fgnu89-inline -flto -msmall-data-limit=0
APP_ASFLAGS_USER := APP_ASFLAGS_USER :=
APP_LDFLAGS_USER := -Wl,--gc-sections APP_LDFLAGS_USER := -Wl,--gc-sections
@ -1150,11 +1150,11 @@ src/userdata_sjis.c: src/userdata.c
iconv -f UTF-8 -t SHIFT-JIS src/userdata.c > src/userdata_sjis.c iconv -f UTF-8 -t SHIFT-JIS src/userdata.c > src/userdata_sjis.c
mem_init/flash.hex: sys_controller.elf mem_init/flash.hex: sys_controller.elf
$(RV_OBJCOPY) --change-addresses -0x02080000 -O binary --gap-fill 0 $< mem_init/flash.bin $(RV_OBJCOPY) --change-addresses -0x02050000 -O binary --gap-fill 0 $< mem_init/flash.bin
$(RV_OBJCOPY) --change-addresses -0x02080000 -O ihex --gap-fill 0 $< mem_init/flash.hex $(RV_OBJCOPY) --change-addresses -0x02050000 -O ihex --gap-fill 0 $< mem_init/flash.hex
mkdir -p mem_init/chunks mkdir -p mem_init/chunks
rm -f mem_init/chunks/* rm -f mem_init/chunks/*
split -d -b 64 -a 4 mem_init/flash.bin mem_init/chunks/flash. split -d -b 1024 -a 4 mem_init/flash.bin mem_init/chunks/flash.
.PHONY: mem_init_generate_new .PHONY: mem_init_generate_new
mem_init_generate_new: mem_init/flash.hex mem_init_generate_new: mem_init/flash.hex

View File

@ -65,18 +65,24 @@ extern alt_u16 rc_keymap_default[REMOTE_MAX_KEYS];
extern alt_u32 remote_code; extern alt_u32 remote_code;
extern alt_u32 btn_code, btn_code_prev; extern alt_u32 btn_code, btn_code_prev;
extern alt_u8 remote_rpt, remote_rpt_prev; extern alt_u8 remote_rpt, remote_rpt_prev;
extern avconfig_t tc, tc_default; extern avconfig_t tc;
extern alt_u8 vm_sel; extern alt_u8 vm_sel;
extern char target_profile_name[PROFILE_NAME_LEN+1]; extern char target_profile_name[USERDATA_NAME_LEN+1];
tvp_input_t target_tvp; tvp_input_t target_tvp;
tvp_sync_input_t target_tvp_sync; tvp_sync_input_t target_tvp_sync;
alt_u8 target_type; alt_u8 target_type;
alt_u8 update_cur_vm; alt_u8 update_cur_vm;
alt_u8 profile_sel, profile_sel_menu, input_profiles[AV_LAST], lt_sel, def_input, profile_link, lcd_bl_timeout; // Default settings
alt_u8 osd_enable=1, osd_status_timeout=1; const settings_t ts_default = {
alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr = 1, auto_av3_ypbpr; .osd_enable = 1,
.osd_status_timeout = 1,
.osd_highlight_color = 4,
.auto_av2_ypbpr = 1,
};
alt_u8 profile_sel, profile_sel_menu, sd_profile_sel_menu, input_profiles[AV_LAST], lt_sel;
char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
@ -97,6 +103,8 @@ alt_u32 read_it2(alt_u32 regaddr);
mode_data_t vmode_in, vmode_out; mode_data_t vmode_in, vmode_out;
vm_proc_config_t vm_conf; vm_proc_config_t vm_conf;
settings_t cs, ts;
// Manually (see cyiv-51005.pdf) or automatically (MIF/HEX from PLL megafunction) generated config may not // Manually (see cyiv-51005.pdf) or automatically (MIF/HEX from PLL megafunction) generated config may not
// provide fully correct scan chain data (e.g. mismatches in C3) and lead to incorrect PLL configuration. // provide fully correct scan chain data (e.g. mismatches in C3) and lead to incorrect PLL configuration.
// To get correct scan chain data, do the following: // To get correct scan chain data, do the following:
@ -140,9 +148,9 @@ int loaded_lc_palette = -1;
void ui_disp_menu(alt_u8 osd_mode) void ui_disp_menu(alt_u8 osd_mode)
{ {
alt_u8 menu_page; uint8_t menu_page;
if ((osd_mode == 1) || (osd_enable == 2)) { if ((osd_mode == 1) || (ts.osd_enable == 2)) {
strncpy((char*)osd->osd_array.data[0][0], menu_row1, OSD_CHAR_COLS); strncpy((char*)osd->osd_array.data[0][0], menu_row1, OSD_CHAR_COLS);
strncpy((char*)osd->osd_array.data[1][0], menu_row2, OSD_CHAR_COLS); strncpy((char*)osd->osd_array.data[1][0], menu_row2, OSD_CHAR_COLS);
osd->osd_row_color.mask = 0; osd->osd_row_color.mask = 0;
@ -763,7 +771,7 @@ int load_profile() {
target_input = tc.link_av; target_input = tc.link_av;
// Update profile link (also prevents the change of input from inducing a profile load). // Update profile link (also prevents the change of input from inducing a profile load).
input_profiles[profile_link ? target_input : AV_TESTPAT] = profile_sel; input_profiles[ts.profile_link ? target_input : AV_TESTPAT] = profile_sel;
write_userdata(INIT_CONFIG_SLOT); write_userdata(INIT_CONFIG_SLOT);
} }
@ -777,13 +785,18 @@ int save_profile() {
if (retval == 0) { if (retval == 0) {
profile_sel = profile_sel_menu; profile_sel = profile_sel_menu;
input_profiles[profile_link ? cm.avinput : AV_TESTPAT] = profile_sel; input_profiles[ts.profile_link ? cm.avinput : AV_TESTPAT] = profile_sel;
write_userdata(INIT_CONFIG_SLOT); write_userdata(INIT_CONFIG_SLOT);
} }
return retval; return retval;
} }
void set_default_settings() {
memcpy(&ts, &ts_default, sizeof(settings_t));
set_default_keymap();
}
void set_default_c_shmask() { void set_default_c_shmask() {
memset(&c_shmask, 0, sizeof(c_shmask)); memset(&c_shmask, 0, sizeof(c_shmask));
strncpy(c_shmask.name, "Custom: <none>", 20); strncpy(c_shmask.name, "Custom: <none>", 20);
@ -857,17 +870,19 @@ int init_hw()
}*/ }*/
// Set defaults // Set defaults
set_default_avconfig(); set_default_profile(1);
memcpy(&cm.cc, &tc_default, sizeof(avconfig_t));
set_default_c_shmask(); set_default_c_shmask();
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap)); set_default_settings();
// Init menu // Init menu
init_menu(); init_menu();
// Load initconfig and profile // Load initconfig and profile
//read_userdata(INIT_CONFIG_SLOT, 0); read_userdata(INIT_CONFIG_SLOT, 0);
//read_userdata(profile_sel, 0); profile_sel = input_profiles[AV_TESTPAT]; // Global profile
read_userdata(profile_sel, 0);
update_settings(1);
// Setup test pattern // Setup test pattern
get_vmode(VMODE_480p, &vmode_in, &vmode_out, &vm_conf); get_vmode(VMODE_480p, &vmode_in, &vmode_out, &vm_conf);
@ -977,6 +992,19 @@ int latency_test() {
return 0; return 0;
} }
void update_settings(int init_setup) {
if (init_setup || (ts.osd_enable != cs.osd_enable) || (ts.osd_status_timeout != cs.osd_status_timeout) || (ts.osd_highlight_color != cs.osd_highlight_color)) {
osd->osd_config.enable = !!ts.osd_enable;
osd->osd_config.status_timeout = ts.osd_status_timeout;
osd->osd_config.highlight_color = 2+ts.osd_highlight_color;
refresh_osd();
}
if (init_setup)
target_input = ts.def_input;
memcpy(&cs, &ts, sizeof(settings_t));
}
int main() int main()
{ {
ths_input_t target_ths = 0; ths_input_t target_ths = 0;
@ -1044,19 +1072,19 @@ int main()
} }
// Auto input switching // Auto input switching
if ((auto_input != AUTO_OFF) && (cm.avinput != AV_TESTPAT) && !cm.sync_active && !menu_active if ((cs.auto_input != AUTO_OFF) && (cm.avinput != AV_TESTPAT) && !cm.sync_active && !menu_active
&& (alt_timestamp() >= auto_input_timestamp + 300 * (alt_timestamp_freq() >> 10)) && (auto_input_ctr < AUTO_MAX_COUNT)) { && (alt_timestamp() >= auto_input_timestamp + 300 * (alt_timestamp_freq() >> 10)) && (auto_input_ctr < AUTO_MAX_COUNT)) {
// Keep switching on the same physical input when set to Current input or a short time after losing sync. // Keep switching on the same physical input when set to Current input or a short time after losing sync.
auto_input_keep_current = (auto_input == AUTO_CURRENT_INPUT || auto_input_current_ctr < AUTO_CURRENT_MAX_COUNT); auto_input_keep_current = (cs.auto_input == AUTO_CURRENT_INPUT || auto_input_current_ctr < AUTO_CURRENT_MAX_COUNT);
switch(cm.avinput) { switch(cm.avinput) {
case AV1_RGBs: case AV1_RGBs:
target_input = auto_av1_ypbpr ? AV1_YPBPR : AV1_RGsB; target_input = cs.auto_av1_ypbpr ? AV1_YPBPR : AV1_RGsB;
break; break;
case AV1_RGsB: case AV1_RGsB:
case AV1_YPBPR: case AV1_YPBPR:
target_input = auto_input_keep_current ? AV1_RGBs : (auto_av2_ypbpr ? AV2_YPBPR : AV2_RGsB); target_input = auto_input_keep_current ? AV1_RGBs : (cs.auto_av2_ypbpr ? AV2_YPBPR : AV2_RGsB);
break; break;
case AV2_YPBPR: case AV2_YPBPR:
case AV2_RGsB: case AV2_RGsB:
@ -1066,7 +1094,7 @@ int main()
target_input = AV3_RGBs; target_input = AV3_RGBs;
break; break;
case AV3_RGBs: case AV3_RGBs:
target_input = auto_av3_ypbpr ? AV3_YPBPR : AV3_RGsB; target_input = cs.auto_av3_ypbpr ? AV3_YPBPR : AV3_RGsB;
break; break;
case AV3_RGsB: case AV3_RGsB:
case AV3_YPBPR: case AV3_YPBPR:
@ -1097,7 +1125,7 @@ int main()
if ((target_input != cm.avinput && man_input_change) || (auto_input_changed && cm.sync_active)) { if ((target_input != cm.avinput && man_input_change) || (auto_input_changed && cm.sync_active)) {
// The input changed, so load the appropriate profile if // The input changed, so load the appropriate profile if
// input->profile link is enabled // input->profile link is enabled
if (profile_link && (profile_sel != input_profiles[target_input])) { if (cs.profile_link && (profile_sel != input_profiles[target_input])) {
profile_sel = input_profiles[target_input]; profile_sel = input_profiles[target_input];
read_userdata(profile_sel, 0); read_userdata(profile_sel, 0);
} }
@ -1182,7 +1210,7 @@ int main()
ui_disp_status(1); ui_disp_status(1);
if (man_input_change) { if (man_input_change) {
// record last input if it was selected manually // record last input if it was selected manually
if (def_input == AV_LAST) if (cs.def_input == AV_LAST)
write_userdata(INIT_CONFIG_SLOT); write_userdata(INIT_CONFIG_SLOT);
// Set auto_input_timestamp when input is manually changed // Set auto_input_timestamp when input is manually changed
auto_input_ctr = 0; auto_input_ctr = 0;
@ -1222,15 +1250,8 @@ int main()
printf("Changing AV3 RGB source\n"); printf("Changing AV3 RGB source\n");
cm.cc.av3_alt_rgb = tc.av3_alt_rgb; cm.cc.av3_alt_rgb = tc.av3_alt_rgb;
} }
if ((!!osd_enable != osd->osd_config.enable) || (osd_status_timeout != osd->osd_config.status_timeout)) {
osd->osd_config.enable = !!osd_enable; update_settings(0);
osd->osd_config.status_timeout = osd_status_timeout;
if (menu_active) {
remote_code = 0;
render_osd_page();
display_menu(1);
}
}
if (cm.avinput != AV_TESTPAT) { if (cm.avinput != AV_TESTPAT) {
status = get_status(target_tvp_sync); status = get_status(target_tvp_sync);

View File

@ -89,6 +89,20 @@ typedef struct {
avconfig_t cc; avconfig_t cc;
} avmode_t; } avmode_t;
typedef struct {
uint8_t profile_link;
avinput_t def_input;
uint8_t auto_input;
uint8_t auto_av1_ypbpr;
uint8_t auto_av2_ypbpr;
uint8_t auto_av3_ypbpr;
uint8_t lcd_bl_timeout;
uint8_t osd_enable;
uint8_t osd_status_timeout;
uint8_t osd_highlight_color;
uint8_t phase_hotkey_enable;
} settings_t;
typedef struct { typedef struct {
uint8_t iv_x; uint8_t iv_x;
uint8_t iv_y; uint8_t iv_y;
@ -117,10 +131,9 @@ void ui_disp_status(alt_u8 refresh_osd_timer);
void set_sampler_phase(uint8_t sampler_phase, uint8_t update_sc); void set_sampler_phase(uint8_t sampler_phase, uint8_t update_sc);
int load_profile();
int save_profile();
void print_vm_stats(); void print_vm_stats();
int latency_test(); int latency_test();
void update_settings(int init_setup);
#endif #endif

View File

@ -157,6 +157,11 @@ typedef struct {
avinput_t link_av; avinput_t link_av;
} __attribute__((packed)) avconfig_t; } __attribute__((packed)) avconfig_t;
int set_default_avconfig(); int set_default_profile(int update_cc);
int reset_profile();
int load_profile();
int save_profile();
int load_profile_sd();
int save_profile_sd();
#endif #endif

View File

@ -60,6 +60,7 @@ typedef enum {
#define REMOTE_MAX_KEYS (RC_PROF_HOTKEY-RC_BTN1+1) #define REMOTE_MAX_KEYS (RC_PROF_HOTKEY-RC_BTN1+1)
void setup_rc(); void setup_rc();
void set_default_keymap();
int parse_control(); int parse_control();
#endif #endif

View File

@ -21,26 +21,17 @@
#define FIRMWARE_H_ #define FIRMWARE_H_
#include <stdint.h> #include <stdint.h>
#include "alt_types.h"
#include "sysconfig.h" #include "sysconfig.h"
#define FW_VER_MAJOR 1 #define FW_VER_MAJOR 1
#define FW_VER_MINOR 20 #define FW_VER_MINOR 20
#define PROFILE_VER_MAJOR 1
#define PROFILE_VER_MINOR 12
#define INITCFG_VER_MAJOR 1
#define INITCFG_VER_MINOR 0
#ifdef OSDLANG_JP #ifdef OSDLANG_JP
#define FW_SUFFIX "j" #define FW_SUFFIX "j"
#else #else
#define FW_SUFFIX "" #define FW_SUFFIX ""
#endif #endif
#define FW_UPDATE_RETRIES 3
typedef struct { typedef struct {
char fw_key[4]; char fw_key[4];
uint8_t version_major; uint8_t version_major;

View File

@ -128,6 +128,7 @@ void render_osd_page();
void display_menu(alt_u8 forcedisp); void display_menu(alt_u8 forcedisp);
void sampler_phase_disp(alt_u8 v); void sampler_phase_disp(alt_u8 v);
void update_osd_size(mode_data_t *vm_out); void update_osd_size(mode_data_t *vm_out);
void refresh_osd();
static void vm_select(); static void vm_select();
static void vm_tweak(alt_u16 *v); static void vm_tweak(alt_u16 *v);

View File

@ -1,5 +1,5 @@
// //
// Copyright (C) 2015-2023 Markus Hiienkari <mhiienka@niksula.hut.fi> // Copyright (C) 2015-2025 Markus Hiienkari <mhiienka@niksula.hut.fi>
// //
// This file is part of Open Source Scan Converter project. // This file is part of Open Source Scan Converter project.
// //
@ -20,29 +20,17 @@
#ifndef USERDATA_H_ #ifndef USERDATA_H_
#define USERDATA_H_ #define USERDATA_H_
#include "alt_types.h" #include <stdint.h>
#include "sysconfig.h" #include "sysconfig.h"
#include "controls.h"
#include "av_controller.h"
#include "avconfig.h"
#include "video_modes.h"
#include "flash.h"
#define PROFILE_NAME_LEN 12 #define USERDATA_NAME_LEN 13
#define MAX_USERDATA_ENTRY 15
// EPCS16 pagesize is 256 bytes #define MAX_SD_USERDATA_ENTRY 100
// Flash is split 50-50 to FW and userdata, 1MB each
#define PAGESIZE 256
#define PAGES_PER_SECTOR 256 //EPCS "sector" corresponds to "block" on Spansion flash
#define SECTORSIZE (PAGESIZE*PAGES_PER_SECTOR)
#define USERDATA_OFFSET 0x100000
#define MAX_USERDATA_ENTRY 15 // 16 sectors for userdata
#define MAX_PROFILE (MAX_USERDATA_ENTRY-1) #define MAX_PROFILE (MAX_USERDATA_ENTRY-1)
#define MAX_SD_PROFILE (MAX_SD_USERDATA_ENTRY-1)
#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY #define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY
#define SD_INIT_CONFIG_SLOT MAX_SD_USERDATA_ENTRY
#define UDATA_IMPT_CANCELLED 104
#define UDATA_EXPT_CANCELLED 105
typedef enum { typedef enum {
UDE_INITCFG = 0, UDE_INITCFG = 0,
@ -51,40 +39,26 @@ typedef enum {
typedef struct { typedef struct {
char userdata_key[8]; char userdata_key[8];
alt_u8 version_major; char name[USERDATA_NAME_LEN+1];
alt_u8 version_minor;
ude_type type; ude_type type;
uint8_t num_items;
} __attribute__((packed, __may_alias__)) ude_hdr; } __attribute__((packed, __may_alias__)) ude_hdr;
typedef struct { typedef struct {
ude_hdr hdr; uint16_t id;
alt_u16 data_len; uint16_t version;
alt_u8 last_profile[AV_LAST]; uint16_t data_size;
alt_u8 profile_link; } __attribute__((packed, __may_alias__)) ude_item_hdr;
avinput_t last_input;
avinput_t def_input;
alt_u8 lcd_bl_timeout;
alt_u8 auto_input;
alt_u8 auto_av1_ypbpr;
alt_u8 auto_av2_ypbpr;
alt_u8 auto_av3_ypbpr;
alt_u8 osd_enable;
alt_u8 osd_status_timeout;
alt_u8 phase_hotkey_enable;
alt_u16 keys[REMOTE_MAX_KEYS];
} __attribute__((packed, __may_alias__)) ude_initcfg;
typedef struct { typedef struct {
ude_hdr hdr; ude_item_hdr hdr;
char name[PROFILE_NAME_LEN+1]; void *data;
alt_u16 avc_data_len; } ude_item_map;
alt_u16 vm_data_len;
avconfig_t avc;
//mode_data_t vm[VIDEO_MODES_CNT];
} __attribute__((packed, __may_alias__)) ude_profile;
int write_userdata(alt_u8 entry); int write_userdata(uint8_t entry);
int read_userdata(alt_u8 entry, int dry_run); int read_userdata(uint8_t entry, int dry_run);
int write_userdata_sd(uint8_t entry);
int read_userdata_sd(uint8_t entry, int dry_run);
int import_userdata(); int import_userdata();
int export_userdata(); int export_userdata();

View File

@ -1,14 +1,14 @@
SEARCH_DIR(.) SEARCH_DIR(.)
__DYNAMIC = 0; __DYNAMIC = 0;
/* First 16 flash sectors reserved for firmware image (1MB). /* First 16 flash sectors reserved for 2 firmware images (2x 0.5MB).
In typical configuration a firmware image consists of In typical configuration a firmware image consists of
* compressed bitstream (8 sectors / 0.5MB) * compressed bitstream (5 sectors / 0.3MB)
* flash_imem (8 sectors / 0.5MB) * flash_imem (3 sectors / 0.2MB)
Last 16 flash sectors reserved for userdata (16x 64KB). */ Last 16 flash sectors reserved for userdata (16x 64KB). */
MEMORY MEMORY
{ {
flash_imem : ORIGIN = 0x02080000, LENGTH = 524288 flash_imem : ORIGIN = 0x02050000, LENGTH = 196608
dataram : ORIGIN = 0x00010000, LENGTH = 16384 dataram : ORIGIN = 0x00010000, LENGTH = 16384
} }

View File

@ -21,12 +21,15 @@
#include "system.h" #include "system.h"
#include "avconfig.h" #include "avconfig.h"
#include "av_controller.h" #include "av_controller.h"
#include "userdata.h"
#include "altera_avalon_pio_regs.h" #include "altera_avalon_pio_regs.h"
#include "tvp7002.h" #include "tvp7002.h"
#define DEFAULT_ON 1 #define DEFAULT_ON 1
extern avmode_t cm;
extern alt_u8 update_cur_vm; extern alt_u8 update_cur_vm;
extern uint8_t sd_profile_sel_menu;
// Target configuration // Target configuration
avconfig_t tc; avconfig_t tc;
@ -65,14 +68,37 @@ const avconfig_t tc_default = {
.link_av = AV_LAST, .link_av = AV_LAST,
}; };
int set_default_avconfig() int set_default_profile(int update_cc)
{ {
memcpy(&tc, &tc_default, sizeof(avconfig_t)); memcpy(&tc, &tc_default, sizeof(avconfig_t));
tc.tx_mode = (IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & HDMITX_MODE_MASK) ? TX_DVI : TX_HDMI_RGB; tc.tx_mode = (IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & HDMITX_MODE_MASK) ? TX_DVI : TX_HDMI_RGB;
if (update_cc)
memcpy(&cm.cc, &tc, sizeof(avconfig_t));
set_default_vm_table(); set_default_vm_table();
update_cur_vm = 1; update_cur_vm = 1;
return 0; return 0;
} }
int reset_profile() {
set_default_profile(0);
return 0;
}
int load_profile_sd() {
return read_userdata_sd(sd_profile_sel_menu, 0);
}
int save_profile_sd() {
int retval;
retval = write_userdata_sd(sd_profile_sel_menu);
if (retval == 0)
write_userdata_sd(SD_INIT_CONFIG_SLOT);
return retval;
}

View File

@ -43,12 +43,12 @@ extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
extern mode_data_t video_modes_plm[]; extern mode_data_t video_modes_plm[];
extern avmode_t cm; extern avmode_t cm;
extern avconfig_t tc; extern avconfig_t tc;
extern settings_t ts;
extern avinput_t target_input; extern avinput_t target_input;
extern alt_u8 menu_active; extern alt_u8 menu_active;
extern alt_u32 sys_ctrl; extern alt_u32 sys_ctrl;
extern alt_u16 tc_sampler_phase; extern alt_u16 tc_sampler_phase;
extern alt_u8 profile_sel, profile_sel_menu; extern alt_u8 profile_sel, profile_sel_menu;
extern alt_u8 lcd_bl_timeout;
extern alt_u8 vm_edit; extern alt_u8 vm_edit;
extern volatile osd_regs *osd; extern volatile osd_regs *osd;
@ -94,7 +94,7 @@ void setup_rc()
if ((btn_code_prev == 0) && (btn_code == PB0_BIT)) { if ((btn_code_prev == 0) && (btn_code == PB0_BIT)) {
if (i == 0) { if (i == 0) {
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap)); set_default_keymap();
i=REMOTE_MAX_KEYS; i=REMOTE_MAX_KEYS;
} else { } else {
i-=2; i-=2;
@ -116,6 +116,10 @@ void setup_rc()
osd->osd_config.menu_active = 0; osd->osd_config.menu_active = 0;
} }
void set_default_keymap() {
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap));
}
int parse_control() int parse_control()
{ {
int i, prof_x10=0, ret=0, retval; int i, prof_x10=0, ret=0, retval;
@ -341,7 +345,7 @@ Button_Check:
sys_ctrl &= ~(3<<LCD_BL_TIMEOUT_OFFS); sys_ctrl &= ~(3<<LCD_BL_TIMEOUT_OFFS);
if (!menu_active) if (!menu_active)
sys_ctrl |= (lcd_bl_timeout << LCD_BL_TIMEOUT_OFFS); sys_ctrl |= (ts.lcd_bl_timeout << LCD_BL_TIMEOUT_OFFS);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl); IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);

View File

@ -54,10 +54,12 @@ int fw_update() {
uint8_t databuf[SD_BLK_SIZE]; // temp buffer for data uint8_t databuf[SD_BLK_SIZE]; // temp buffer for data
uint16_t fs_csize, fs_startsec, cl_iter, cl_soffs; uint16_t fs_csize, fs_startsec, cl_iter, cl_soffs;
retval = file_mount(); if (!sdcard_dev.mount) {
if (retval != 0) { retval = file_mount();
printf("SD card not detected %d\n", retval); if (retval != 0) {
return -1; printf("SD card not detected %d\n", retval);
return -1;
}
} }
//sniprintf(dirname_root, sizeof(dirname_root), "/%s", dirname); //sniprintf(dirname_root, sizeof(dirname_root), "/%s", dirname);

View File

@ -1,5 +1,5 @@
// //
// Copyright (C) 2015-2016 Markus Hiienkari <mhiienka@niksula.hut.fi> // Copyright (C) 2015-2025 Markus Hiienkari <mhiienka@niksula.hut.fi>
// //
// This file is part of Open Source Scan Converter project. // This file is part of Open Source Scan Converter project.
// //
@ -20,7 +20,16 @@
#include <unistd.h> #include <unistd.h>
#include "flash.h" #include "flash.h"
#define DEMUX_FINISH_DELAY 10000
void __attribute__((noinline, flatten, __section__(".text_bram"))) flash_write_protect(flash_ctrl_dev *dev, int enable) { void __attribute__((noinline, flatten, __section__(".text_bram"))) flash_write_protect(flash_ctrl_dev *dev, int enable) {
int i;
// add short delay to avoid mem/csr demux conflict (freeze) in intel_generic_serial_flash_interface
for(i = 0; i < DEMUX_FINISH_DELAY; i++){
asm volatile ("nop");
}
// Write enable // Write enable
dev->regs->flash_cmd_cfg = 0x00000006; dev->regs->flash_cmd_cfg = 0x00000006;
dev->regs->flash_cmd_ctrl = 1; dev->regs->flash_cmd_ctrl = 1;
@ -41,9 +50,21 @@ void __attribute__((noinline, flatten, __section__(".text_bram"))) flash_write_p
// Write disable // Write disable
dev->regs->flash_cmd_cfg = 0x00000004; dev->regs->flash_cmd_cfg = 0x00000004;
dev->regs->flash_cmd_ctrl = 1; dev->regs->flash_cmd_ctrl = 1;
// add short delay to avoid mem/csr demux conflict (freeze) in intel_generic_serial_flash_interface
for(i = 0; i < DEMUX_FINISH_DELAY; i++){
asm volatile ("nop");
}
} }
void __attribute__((noinline, flatten, __section__(".text_bram"))) flash_sector_erase(flash_ctrl_dev *dev, uint32_t addr) { void __attribute__((noinline, flatten, __section__(".text_bram"))) flash_sector_erase(flash_ctrl_dev *dev, uint32_t addr) {
int i;
// add short delay to avoid mem/csr demux conflict (freeze) in intel_generic_serial_flash_interface
for(i = 0; i < DEMUX_FINISH_DELAY; i++){
asm volatile ("nop");
}
// Write enable // Write enable
dev->regs->flash_cmd_cfg = 0x00000006; dev->regs->flash_cmd_cfg = 0x00000006;
dev->regs->flash_cmd_ctrl = 1; dev->regs->flash_cmd_ctrl = 1;
@ -60,4 +81,9 @@ void __attribute__((noinline, flatten, __section__(".text_bram"))) flash_sector_
if (!(dev->regs->flash_cmd_rddata[0] & (1<<0))) if (!(dev->regs->flash_cmd_rddata[0] & (1<<0)))
break; break;
} }
// add short delay to avoid mem/csr demux conflict (freeze) in intel_generic_serial_flash_interface
for(i = 0; i < DEMUX_FINISH_DELAY; i++){
asm volatile ("nop");
}
} }

View File

@ -33,15 +33,14 @@
extern char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; extern char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
extern avmode_t cm; extern avmode_t cm;
extern avconfig_t tc; extern avconfig_t tc;
extern settings_t ts;
extern mode_data_t video_modes_plm[]; extern mode_data_t video_modes_plm[];
extern alt_u32 remote_code; extern alt_u32 remote_code;
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS]; extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
extern alt_u8 vm_sel, profile_sel_menu, lt_sel, def_input, profile_link, lcd_bl_timeout; extern alt_u8 vm_sel, profile_sel_menu, sd_profile_sel_menu, lt_sel;
extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
extern alt_u8 update_cur_vm; extern alt_u8 update_cur_vm;
extern alt_u8 osd_enable, osd_status_timeout, phase_hotkey_enable;
extern uint8_t sl_def_iv_x, sl_def_iv_y; extern uint8_t sl_def_iv_x, sl_def_iv_y;
extern char target_profile_name[PROFILE_NAME_LEN+1]; extern char target_profile_name[USERDATA_NAME_LEN+1];
extern volatile osd_regs *osd; extern volatile osd_regs *osd;
extern const int num_video_modes_plm; extern const int num_video_modes_plm;
extern c_shmask_t c_shmask; extern c_shmask_t c_shmask;
@ -77,6 +76,7 @@ static const char* const lt_desc[] = { "Top-left", "Center", "Bottom-right" };
static const char* const lcd_bl_timeout_desc[] = { "Off", "3s", "10s", "30s" }; static const char* const lcd_bl_timeout_desc[] = { "Off", "3s", "10s", "30s" };
static const char* const osd_enable_desc[] = { "Off", "Full", "Simple" }; static const char* const osd_enable_desc[] = { "Off", "Full", "Simple" };
static const char* const osd_status_desc[] = { "2s", "5s", "10s", "Off" }; static const char* const osd_status_desc[] = { "2s", "5s", "10s", "Off" };
static const char* const osd_color_desc[] = { "Green", "Cyan", "Red", "Magenta", "Yellow" };
static const char* const rgsb_ypbpr_desc[] = { "RGsB", "YPbPr" }; static const char* const rgsb_ypbpr_desc[] = { "RGsB", "YPbPr" };
static const char* const auto_input_desc[] = { "Off", "Current input", "All inputs" }; static const char* const auto_input_desc[] = { "Off", "Current input", "All inputs" };
static const char* const mask_color_desc[] = { "Black", "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White" }; static const char* const mask_color_desc[] = { "Black", "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White" };
@ -103,7 +103,8 @@ static void lt_disp(alt_u8 v) { strncpy(menu_row2, lt_desc[v], LCD_ROW_LEN+1); }
static void aud_db_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d dB", ((alt_8)v-AUDIO_GAIN_0DB)); } static void aud_db_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d dB", ((alt_8)v-AUDIO_GAIN_0DB)); }
static void vm_display_name (alt_u8 v) { strncpy(menu_row2, video_modes_plm[v].name, LCD_ROW_LEN+1); } static void vm_display_name (alt_u8 v) { strncpy(menu_row2, video_modes_plm[v].name, LCD_ROW_LEN+1); }
static void link_av_desc (avinput_t v) { strncpy(menu_row2, v == AV_LAST ? "No link" : avinput_str[v], LCD_ROW_LEN+1); } static void link_av_desc (avinput_t v) { strncpy(menu_row2, v == AV_LAST ? "No link" : avinput_str[v], LCD_ROW_LEN+1); }
static void profile_disp(alt_u8 v) { read_userdata(v, 1); sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (target_profile_name[0] == 0) ? "<empty>" : target_profile_name); } static void profile_disp(uint8_t v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (read_userdata(v, 1) != 0) ? "<empty>" : target_profile_name); }
static void sd_profile_disp(uint8_t v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (read_userdata_sd(v, 1) != 0) ? "<empty>" : target_profile_name); }
static void alc_v_filter_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%u lines","%u ライン"), (1<<v)); } static void alc_v_filter_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%u lines","%u ライン"), (1<<v)); }
static void alc_h_filter_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%u pixels","%u ドット"), (1<<(v+1))); } static void alc_h_filter_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%u pixels","%u ドット"), (1<<(v+1))); }
void sampler_phase_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d deg", (v*11250)/1000); } void sampler_phase_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d deg", (v*11250)/1000); }
@ -111,6 +112,7 @@ void sampler_phase_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d deg"
static arg_info_t vm_arg_info = {&vm_sel, 0, vm_display_name}; static arg_info_t vm_arg_info = {&vm_sel, 0, vm_display_name};
static const arg_info_t profile_arg_info = {&profile_sel_menu, MAX_PROFILE, profile_disp}; static const arg_info_t profile_arg_info = {&profile_sel_menu, MAX_PROFILE, profile_disp};
static const arg_info_t sd_profile_arg_info = {&sd_profile_sel_menu, MAX_SD_PROFILE, sd_profile_disp};
static const arg_info_t lt_arg_info = {&lt_sel, (sizeof(lt_desc)/sizeof(char*))-1, lt_disp}; static const arg_info_t lt_arg_info = {&lt_sel, (sizeof(lt_desc)/sizeof(char*))-1, lt_disp};
@ -241,21 +243,24 @@ MENU(menu_audio, P99_PROTECT({ \
MENU(menu_settings, P99_PROTECT({ \ MENU(menu_settings, P99_PROTECT({ \
{ LNG("Link prof->input","Link prof->input"), OPT_AVCONFIG_NUMVALUE, { .num = { &tc.link_av, OPT_WRAP, AV1_RGBs, AV_LAST, link_av_desc } } }, { LNG("Link prof->input","Link prof->input"), OPT_AVCONFIG_NUMVALUE, { .num = { &tc.link_av, OPT_WRAP, AV1_RGBs, AV_LAST, link_av_desc } } },
{ LNG("Link input->prof","Link input->prof"), OPT_AVCONFIG_SELECTION, { .sel = { &profile_link, OPT_WRAP, SETTING_ITEM(off_on_desc) } } }, { LNG("Link input->prof","Link input->prof"), OPT_AVCONFIG_SELECTION, { .sel = { &ts.profile_link, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } }, { LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &ts.def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
{ "Autodetect input", OPT_AVCONFIG_SELECTION, { .sel = { &auto_input, OPT_WRAP, SETTING_ITEM(auto_input_desc) } } }, { "Autodetect input", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_input, OPT_WRAP, SETTING_ITEM(auto_input_desc) } } },
{ "Auto AV1 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av1_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } }, { "Auto AV1 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_av1_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
{ "Auto AV2 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av2_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } }, { "Auto AV2 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_av2_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
{ "Auto AV3 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av3_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } }, { "Auto AV3 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_av3_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
{ "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } }, { "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &ts.lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } },
{ "OSD", OPT_AVCONFIG_SELECTION, { .sel = { &osd_enable, OPT_WRAP, SETTING_ITEM(osd_enable_desc) } } }, { "OSD", OPT_AVCONFIG_SELECTION, { .sel = { &ts.osd_enable, OPT_WRAP, SETTING_ITEM(osd_enable_desc) } } },
{ "OSD status disp.", OPT_AVCONFIG_SELECTION, { .sel = { &osd_status_timeout, OPT_WRAP, SETTING_ITEM(osd_status_desc) } } }, { "OSD status disp.", OPT_AVCONFIG_SELECTION, { .sel = { &ts.osd_status_timeout, OPT_WRAP, SETTING_ITEM(osd_status_desc) } } },
{ "Phase hotkey", OPT_AVCONFIG_SELECTION, { .sel = { &phase_hotkey_enable, OPT_WRAP, SETTING_ITEM(off_on_desc) } } }, { "OSD cursor color", OPT_AVCONFIG_SELECTION, { .sel = { &ts.osd_highlight_color, OPT_WRAP, SETTING_ITEM(osd_color_desc) } } },
{ "Phase hotkey", OPT_AVCONFIG_SELECTION, { .sel = { &ts.phase_hotkey_enable, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
{ LNG("<Load profile >","<プロファイルロード >"), OPT_FUNC_CALL, { .fun = { load_profile, &profile_arg_info } } }, { LNG("<Load profile >","<プロファイルロード >"), OPT_FUNC_CALL, { .fun = { load_profile, &profile_arg_info } } },
{ LNG("<Save profile >","<プロファイルセーブ >"), OPT_FUNC_CALL, { .fun = { save_profile, &profile_arg_info } } }, { LNG("<Save profile >","<プロファイルセーブ >"), OPT_FUNC_CALL, { .fun = { save_profile, &profile_arg_info } } },
{ LNG("<Reset settings>","<セッテイヲショキカ >"), OPT_FUNC_CALL, { .fun = { set_default_avconfig, NULL } } }, { "<SD Load profile>" , OPT_FUNC_CALL, { .fun = { load_profile_sd, &sd_profile_arg_info } } },
{ LNG("<Import sett. >","<セッテイヨミコミ >"), OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } }, { "<SD Save profile>" , OPT_FUNC_CALL, { .fun = { save_profile_sd, &sd_profile_arg_info } } },
{ LNG("<Export sett. >","<セッテイカキコミ >"), OPT_FUNC_CALL, { .fun = { export_userdata, NULL } } }, { LNG("<Reset profile>","<セッテイヲショキカ >"), OPT_FUNC_CALL, { .fun = { reset_profile, NULL } } },
//{ LNG("<Import sett. >","<セッテイヨミコミ >"), OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
//{ LNG("<Export sett. >","<セッテイカキコミ >"), OPT_FUNC_CALL, { .fun = { export_userdata, NULL } } },
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } }, { LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
})) }))
@ -336,7 +341,7 @@ void render_osd_page() {
const menuitem_t *item; const menuitem_t *item;
uint32_t row_mask[2] = {0, 0}; uint32_t row_mask[2] = {0, 0};
if (!menu_active || (osd_enable != 1)) if (!menu_active || (ts.osd_enable != 1))
return; return;
for (i=0; i < navi[navlvl].m->num_items; i++) { for (i=0; i < navi[navlvl].m->num_items; i++) {
@ -500,6 +505,14 @@ void update_osd_size(mode_data_t *vm_out) {
osd->osd_config.y_size = osd_size; osd->osd_config.y_size = osd_size;
} }
void refresh_osd() {
if (menu_active) {
remote_code = 0;
render_osd_page();
display_menu(1);
}
}
static void vm_select() { static void vm_select() {
vm_edit = vm_sel; vm_edit = vm_sel;
tc_h_samplerate = video_modes_plm[vm_edit].timings.h_total; tc_h_samplerate = video_modes_plm[vm_edit].timings.h_total;

View File

@ -23,7 +23,6 @@
#include <stdio.h> #include <stdio.h>
#include "system.h" #include "system.h"
#include "userdata.h" #include "userdata.h"
#include "fat16_export.h"
#include "flash.h" #include "flash.h"
#include "sdcard.h" #include "sdcard.h"
#include "firmware.h" #include "firmware.h"
@ -31,508 +30,417 @@
#include "controls.h" #include "controls.h"
#include "av_controller.h" #include "av_controller.h"
#include "menu.h" #include "menu.h"
#include "utils.h" #include "ff.h"
#include "altera_avalon_pio_regs.h" #include "file.h"
#define UDE_ITEM(ID, VER, ITEM) {{ID, VER, sizeof(ITEM)}, &ITEM}
// include mode array definitions so that sizeof() can be used // include mode array definitions so that sizeof() can be used
#define VM_STATIC_INCLUDE #define VM_STATIC_INCLUDE
#include "video_modes_list.c" #include "video_modes_list.c"
#undef VM_STATIC_INCLUDE #undef VM_STATIC_INCLUDE
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS]; extern flash_ctrl_dev flashctrl_dev;
extern avmode_t cm; extern uint16_t rc_keymap[REMOTE_MAX_KEYS];
extern uint8_t input_profiles[AV_LAST];
extern avconfig_t tc; extern avconfig_t tc;
extern settings_t ts;
extern mode_data_t video_modes_plm[]; extern mode_data_t video_modes_plm[];
extern avinput_t target_input; extern uint8_t update_cur_vm;
extern alt_u8 update_cur_vm;
extern alt_u8 input_profiles[AV_LAST];
extern alt_u8 profile_sel;
extern alt_u8 def_input, profile_link;
extern alt_u8 lcd_bl_timeout;
extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
extern alt_u8 osd_enable, osd_status_timeout, phase_hotkey_enable;
extern SD_DEV sdcard_dev; extern SD_DEV sdcard_dev;
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; extern c_shmask_t c_shmask;
char target_profile_name[PROFILE_NAME_LEN+1]; char target_profile_name[USERDATA_NAME_LEN+1], cur_profile_name[USERDATA_NAME_LEN+1];
int write_userdata(alt_u8 entry) const ude_item_map ude_initcfg_items[] = {
{ UDE_ITEM(0, 120, rc_keymap),
alt_u8 databuf[PAGESIZE]; UDE_ITEM(1, 120, input_profiles),
alt_u16 vm_to_write; UDE_ITEM(2, 120, ts.profile_link),
alt_u16 pageoffset, srcoffset; UDE_ITEM(3, 120, ts.def_input),
alt_u8 pageno; UDE_ITEM(4, 120, ts.auto_input),
alt_u32 bytes_to_w; UDE_ITEM(5, 120, ts.auto_av1_ypbpr),
int retval, i; UDE_ITEM(6, 120, ts.auto_av2_ypbpr),
UDE_ITEM(7, 120, ts.auto_av3_ypbpr),
UDE_ITEM(8, 120, ts.lcd_bl_timeout),
UDE_ITEM(9, 120, ts.osd_enable),
UDE_ITEM(10, 120, ts.osd_status_timeout),
UDE_ITEM(11, 120, ts.osd_highlight_color),
UDE_ITEM(12, 120, ts.phase_hotkey_enable),
};
const ude_item_map ude_profile_items[] = {
{{0, 120, sizeof(video_modes_plm_default)}, video_modes_plm},
UDE_ITEM(1, 120, c_shmask),
// avconfig_t
UDE_ITEM(2, 120, tc.pm_240p),
UDE_ITEM(3, 120, tc.pm_384p),
UDE_ITEM(4, 120, tc.pm_480i),
UDE_ITEM(5, 120, tc.pm_480p),
UDE_ITEM(6, 120, tc.pm_1080i),
UDE_ITEM(7, 120, tc.pt_mode),
UDE_ITEM(8, 120, tc.l2_mode),
UDE_ITEM(9, 120, tc.l3_mode),
UDE_ITEM(10, 120, tc.l4_mode),
UDE_ITEM(11, 120, tc.l5_mode),
UDE_ITEM(12, 120, tc.l6_mode),
UDE_ITEM(13, 120, tc.l5_fmt),
UDE_ITEM(14, 120, tc.s480p_mode),
UDE_ITEM(15, 120, tc.s400p_mode),
UDE_ITEM(16, 120, tc.upsample2x),
UDE_ITEM(17, 120, tc.ar_256col),
UDE_ITEM(18, 120, tc.default_vic),
UDE_ITEM(19, 120, tc.clamp_offset),
UDE_ITEM(20, 120, tc.tvp_hpll2x),
UDE_ITEM(21, 120, tc.adc_pll_bw),
UDE_ITEM(22, 120, tc.fpga_pll_bw),
UDE_ITEM(23, 120, tc.sl_mode),
UDE_ITEM(24, 120, tc.sl_type),
UDE_ITEM(25, 120, tc.sl_hybr_str),
UDE_ITEM(26, 120, tc.sl_method),
UDE_ITEM(27, 120, tc.sl_altern),
UDE_ITEM(28, 120, tc.sl_str),
UDE_ITEM(29, 120, tc.sl_id),
UDE_ITEM(30, 120, tc.sl_cust_l_str),
UDE_ITEM(31, 120, tc.sl_cust_c_str),
UDE_ITEM(32, 120, tc.sl_cust_iv_x),
UDE_ITEM(33, 120, tc.sl_cust_iv_y),
UDE_ITEM(34, 120, tc.mask_br),
UDE_ITEM(35, 120, tc.mask_color),
UDE_ITEM(36, 120, tc.reverse_lpf),
UDE_ITEM(37, 120, tc.shmask_mode),
UDE_ITEM(38, 120, tc.shmask_str),
UDE_ITEM(39, 120, tc.lumacode_mode),
UDE_ITEM(40, 120, tc.lumacode_pal),
UDE_ITEM(41, 120, tc.sync_vth),
UDE_ITEM(42, 120, tc.linelen_tol),
UDE_ITEM(43, 120, tc.vsync_thold),
UDE_ITEM(44, 120, tc.pre_coast),
UDE_ITEM(45, 120, tc.post_coast),
UDE_ITEM(46, 120, tc.ypbpr_cs),
UDE_ITEM(47, 120, tc.video_lpf),
UDE_ITEM(48, 120, tc.sync_lpf),
UDE_ITEM(49, 120, tc.stc_lpf),
UDE_ITEM(50, 120, tc.alc_h_filter),
UDE_ITEM(51, 120, tc.alc_v_filter),
UDE_ITEM(52, 120, tc.col),
UDE_ITEM(53, 120, tc.full_vs_bypass),
UDE_ITEM(54, 120, tc.audio_dw_sampl),
UDE_ITEM(55, 120, tc.audio_swap_lr),
UDE_ITEM(56, 120, tc.audio_gain),
UDE_ITEM(57, 120, tc.audio_mono),
UDE_ITEM(58, 120, tc.tx_mode),
UDE_ITEM(59, 120, tc.hdmi_itc),
UDE_ITEM(60, 120, tc.hdmi_hdr),
UDE_ITEM(61, 120, tc.hdmi_vrr),
UDE_ITEM(62, 120, tc.full_tx_setup),
UDE_ITEM(63, 120, tc.av3_alt_rgb),
UDE_ITEM(64, 120, tc.link_av),
};
int write_userdata(uint8_t entry) {
ude_hdr hdr;
FIL name_file;
char p_filename[14];
const ude_item_map *target_map;
uint32_t flash_addr, bytes_written;
int i=0;
if (entry > MAX_USERDATA_ENTRY) { if (entry > MAX_USERDATA_ENTRY) {
printf("invalid entry\n"); printf("invalid entry\n");
return -1; return -1;
} }
strncpy(((ude_hdr*)databuf)->userdata_key, "USRDATA", 8); memset(&hdr, 0x00, sizeof(ude_hdr));
((ude_hdr*)databuf)->type = (entry > MAX_PROFILE) ? UDE_INITCFG : UDE_PROFILE; strlcpy(hdr.userdata_key, "USRDATA", 8);
hdr.type = (entry > MAX_PROFILE) ? UDE_INITCFG : UDE_PROFILE;
switch (((ude_hdr*)databuf)->type) { if (hdr.type == UDE_INITCFG) {
case UDE_INITCFG: target_map = ude_initcfg_items;
((ude_hdr*)databuf)->version_major = INITCFG_VER_MAJOR; hdr.num_items = sizeof(ude_initcfg_items)/sizeof(ude_item_map);
((ude_hdr*)databuf)->version_minor = INITCFG_VER_MINOR;
((ude_initcfg*)databuf)->data_len = sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile);
memcpy(((ude_initcfg*)databuf)->last_profile, input_profiles, sizeof(input_profiles));
((ude_initcfg*)databuf)->last_input = target_input;
((ude_initcfg*)databuf)->def_input = def_input;
((ude_initcfg*)databuf)->profile_link = profile_link;
((ude_initcfg*)databuf)->lcd_bl_timeout = lcd_bl_timeout;
((ude_initcfg*)databuf)->auto_input = auto_input;
((ude_initcfg*)databuf)->auto_av1_ypbpr = auto_av1_ypbpr;
((ude_initcfg*)databuf)->auto_av2_ypbpr = auto_av2_ypbpr;
((ude_initcfg*)databuf)->auto_av3_ypbpr = auto_av3_ypbpr;
((ude_initcfg*)databuf)->osd_enable = osd_enable;
((ude_initcfg*)databuf)->osd_status_timeout = osd_status_timeout;
((ude_initcfg*)databuf)->phase_hotkey_enable = phase_hotkey_enable;
memcpy(((ude_initcfg*)databuf)->keys, rc_keymap, sizeof(rc_keymap));
for (i=0; i<sizeof(ude_initcfg); i++)
databuf[i] = bitswap8(databuf[i]);
/*retval = alt_epcq_controller2_write(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), databuf, sizeof(ude_initcfg));
if (retval != 0)
return retval;*/
printf("Initconfig data written (%u bytes)\n", sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)); sniprintf(hdr.name, USERDATA_NAME_LEN+1, "INITCFG");
break; } else if (hdr.type == UDE_PROFILE) {
case UDE_PROFILE: target_map = ude_profile_items;
((ude_hdr*)databuf)->version_major = PROFILE_VER_MAJOR; hdr.num_items = sizeof(ude_profile_items)/sizeof(ude_item_map);
((ude_hdr*)databuf)->version_minor = PROFILE_VER_MINOR;
vm_to_write = sizeof(video_modes_plm_default);
((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t);
((ude_profile*)databuf)->vm_data_len = vm_to_write;
if (target_profile_name[0] == 0) // Check if name override file exists
sniprintf(target_profile_name, PROFILE_NAME_LEN+1, "<used>"); sniprintf(p_filename, sizeof(p_filename), "prof_n_i.txt");
if (!file_open(&name_file, p_filename)) {
strncpy(((ude_profile*)databuf)->name, target_profile_name, PROFILE_NAME_LEN+1); for (i=0; i<=entry; i++) {
if (file_get_string(&name_file, target_profile_name, sizeof(target_profile_name)) == NULL)
break;
}
pageoffset = offsetof(ude_profile, avc); file_close(&name_file);
// assume that sizeof(avconfig_t) << PAGESIZE
memcpy(databuf+pageoffset, &tc, sizeof(avconfig_t));
pageoffset += sizeof(avconfig_t);
// erase sector and write a full page first, assume sizeof(video_modes_plm) >> PAGESIZE
memcpy(databuf+pageoffset, (char*)video_modes_plm, PAGESIZE-pageoffset);
srcoffset = PAGESIZE-pageoffset;
vm_to_write -= PAGESIZE-pageoffset;
for (i=0; i<PAGESIZE; i++)
databuf[i] = bitswap8(databuf[i]);
/*retval = alt_epcq_controller2_write(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), databuf, PAGESIZE);
if (retval != 0)
return retval;*/
// then write the rest page by page
pageno = 1;
while (vm_to_write > 0) {
memcpy(databuf, (char*)video_modes_plm+srcoffset, (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write);
for (i=0; i<PAGESIZE; i++)
databuf[i] = bitswap8(databuf[i]);
/*retval = alt_epcq_controller2_write_block(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), (USERDATA_OFFSET+entry*SECTORSIZE+pageno*PAGESIZE), databuf, (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write);
if (retval != 0)
return retval;*/
srcoffset += PAGESIZE;
vm_to_write = (vm_to_write < PAGESIZE) ? 0 : (vm_to_write - PAGESIZE);
pageno++;
} }
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+sizeof(video_modes_plm_default)); if (i == entry+1) {
break; // strip CR / CRLF
default: target_profile_name[strcspn(target_profile_name, "\r\n")] = 0;
break;
strlcpy(hdr.name, target_profile_name, USERDATA_NAME_LEN+1);
} else if (cur_profile_name[0] == 0) {
sniprintf(hdr.name, USERDATA_NAME_LEN+1, "<used>");
} else {
strlcpy(hdr.name, cur_profile_name, USERDATA_NAME_LEN+1);
}
} }
flash_addr = flashctrl_dev.flash_size - (16-entry)*FLASH_SECTOR_SIZE;
// Disable flash write protect and erase sector
flash_write_protect(&flashctrl_dev, 0);
flash_sector_erase(&flashctrl_dev, flash_addr);
// Write data into erased sector
memcpy((uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr), &hdr, sizeof(ude_hdr));
bytes_written = sizeof(ude_hdr);
for (i=0; i<hdr.num_items; i++) {
memcpy((uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_written), &target_map[i].hdr, sizeof(ude_item_hdr));
bytes_written += sizeof(ude_item_hdr);
memcpy((uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_written), target_map[i].data, target_map[i].hdr.data_size);
bytes_written += target_map[i].hdr.data_size;
}
// Re-enable write protection
flash_write_protect(&flashctrl_dev, 1);
printf("%lu bytes written into userdata entry %u\n", bytes_written, entry);
return 0; return 0;
} }
int read_userdata(alt_u8 entry, int dry_run) int read_userdata(uint8_t entry, int dry_run) {
{ ude_hdr hdr;
int retval, i; ude_item_hdr item_hdr;
alt_u8 databuf[PAGESIZE]; const ude_item_map *target_map;
alt_u16 vm_to_read; uint32_t flash_addr, bytes_read;
alt_u16 pageoffset, dstoffset; int i, j, target_map_items;
alt_u8 pageno;
target_profile_name[0] = 0;
if (entry > MAX_USERDATA_ENTRY) { if (entry > MAX_USERDATA_ENTRY) {
printf("invalid entry\n"); printf("invalid entry\n");
return -1; return -1;
} }
//retval = alt_epcq_controller2_read(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), databuf, PAGESIZE); flash_addr = flashctrl_dev.flash_size - (16-entry)*FLASH_SECTOR_SIZE;
for (i=0; i<PAGESIZE; i++) memcpy(&hdr, (uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr), sizeof(ude_hdr));
databuf[i] = bitswap8(databuf[i]); bytes_read = sizeof(ude_hdr);
if (retval != 0)
return retval;
if (strncmp(((ude_hdr*)databuf)->userdata_key, "USRDATA", 8)) { if (strncmp(hdr.userdata_key, "USRDATA", 8)) {
printf("No userdata found on entry %u\n", entry); printf("No userdata found on entry %u\n", entry);
return 1; return 1;
} }
switch (((ude_hdr*)databuf)->type) { strlcpy(target_profile_name, hdr.name, USERDATA_NAME_LEN+1);
case UDE_INITCFG: if (dry_run)
if ((((ude_hdr*)databuf)->version_major != INITCFG_VER_MAJOR) || (((ude_hdr*)databuf)->version_minor != INITCFG_VER_MINOR)) { return 0;
printf("Initconfig version %u.%.2u does not match current one\n", ((ude_hdr*)databuf)->version_major, ((ude_hdr*)databuf)->version_minor);
return 2;
}
if (((ude_initcfg*)databuf)->data_len == sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)) {
if (dry_run)
return 0;
for (i = 0; i < sizeof(input_profiles)/sizeof(*input_profiles); ++i) target_map = (hdr.type == UDE_INITCFG) ? ude_initcfg_items : ude_profile_items;
if (((ude_initcfg*)databuf)->last_profile[i] <= MAX_PROFILE) target_map_items = (hdr.type == UDE_INITCFG) ? sizeof(ude_initcfg_items)/sizeof(ude_item_map) : sizeof(ude_profile_items)/sizeof(ude_item_map);
input_profiles[i] = ((ude_initcfg*)databuf)->last_profile[i];
def_input = ((ude_initcfg*)databuf)->def_input;
if (def_input < AV_LAST)
target_input = def_input;
else if (((ude_initcfg*)databuf)->last_input < AV_LAST)
target_input = ((ude_initcfg*)databuf)->last_input;
auto_input = ((ude_initcfg*)databuf)->auto_input;
auto_av1_ypbpr = ((ude_initcfg*)databuf)->auto_av1_ypbpr;
auto_av2_ypbpr = ((ude_initcfg*)databuf)->auto_av2_ypbpr;
auto_av3_ypbpr = ((ude_initcfg*)databuf)->auto_av3_ypbpr;
osd_enable = ((ude_initcfg*)databuf)->osd_enable;
osd_status_timeout = ((ude_initcfg*)databuf)->osd_status_timeout;
profile_link = ((ude_initcfg*)databuf)->profile_link;
profile_sel = input_profiles[AV_TESTPAT]; // Global profile
lcd_bl_timeout = ((ude_initcfg*)databuf)->lcd_bl_timeout;
phase_hotkey_enable = ((ude_initcfg*)databuf)->phase_hotkey_enable;
memcpy(rc_keymap, ((ude_initcfg*)databuf)->keys, sizeof(rc_keymap));
printf("RC data read (%u bytes)\n", sizeof(rc_keymap));
}
break;
case UDE_PROFILE:
if ((((ude_hdr*)databuf)->version_major != PROFILE_VER_MAJOR) || (((ude_hdr*)databuf)->version_minor != PROFILE_VER_MINOR)) {
printf("Profile version %u.%.2u does not match current one\n", ((ude_hdr*)databuf)->version_major, ((ude_hdr*)databuf)->version_minor);
return 2;
}
if ((((ude_profile*)databuf)->avc_data_len == sizeof(avconfig_t)) && (((ude_profile*)databuf)->vm_data_len == sizeof(video_modes_plm_default))) {
strncpy(target_profile_name, ((ude_profile*)databuf)->name, PROFILE_NAME_LEN+1);
if (dry_run)
return 0;
vm_to_read = ((ude_profile*)databuf)->vm_data_len; for (i=0; i<hdr.num_items; i++) {
memcpy(&item_hdr, (uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_read), sizeof(ude_item_hdr));
pageno = 0; bytes_read += sizeof(ude_item_hdr);
pageoffset = offsetof(ude_profile, avc); for (j=0; j<target_map_items; j++) {
if (!memcmp(&item_hdr, &target_map[j].hdr, sizeof(ude_item_hdr))) {
// assume that sizeof(avconfig_t) << PAGESIZE memcpy(target_map[j].data, (uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_read), item_hdr.data_size);
memcpy(&tc, databuf+pageoffset, sizeof(avconfig_t)); break;
pageoffset += sizeof(avconfig_t);
dstoffset = 0;
while (vm_to_read > 0) {
if (vm_to_read >= PAGESIZE-pageoffset) {
memcpy((char*)video_modes_plm+dstoffset, databuf+pageoffset, PAGESIZE-pageoffset);
dstoffset += PAGESIZE-pageoffset;
vm_to_read -= PAGESIZE-pageoffset;
pageoffset = 0;
pageno++;
// check
//retval = alt_epcq_controller2_read(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE+pageno*PAGESIZE), databuf, PAGESIZE);
for (i=0; i<PAGESIZE; i++)
databuf[i] = bitswap8(databuf[i]);
if (retval != 0)
return retval;
} else {
memcpy((char*)video_modes_plm+dstoffset, databuf+pageoffset, vm_to_read);
pageoffset += vm_to_read;
vm_to_read = 0;
}
} }
update_cur_vm = 1;
printf("Profile %u data read (%u bytes)\n", entry, sizeof(avconfig_t)+sizeof(video_modes_plm_default));
} }
break; bytes_read += item_hdr.data_size;
default:
printf("Unknown userdata entry\n"); if (bytes_read >= FLASH_SECTOR_SIZE) {
break; printf("userdata entry %u corrupted\n", entry);
return -1;
}
} }
if (hdr.type == UDE_PROFILE)
update_cur_vm = 1;
strlcpy(cur_profile_name, target_profile_name, USERDATA_NAME_LEN+1);
printf("%lu bytes read from userdata entry %u\n", bytes_read, entry);
return 0; return 0;
} }
int import_userdata() int write_userdata_sd(uint8_t entry) {
{ FIL p_file, name_file;
SDRESULTS res; ude_hdr hdr;
int retval; const ude_item_map *target_map;
int n, entries_imported=0; unsigned int bytes_written, bytes_written_tot;
char *errmsg; char p_filename[14];
alt_u8 databuf[SD_BLK_SIZE]; int i=0, retval=0;
ude_hdr header;
alt_u32 btn_vec;
retval = check_sdcard(databuf); if (entry == SD_INIT_CONFIG_SLOT)
SPI_CS_High(); sniprintf(p_filename, sizeof(p_filename), "settings.bin");
if (retval != 0) else
goto sd_disable; sniprintf(p_filename, sizeof(p_filename), "prof%.2u.bin", entry);
strncpy(menu_row2, "Import? 1=Y, 2=N", LCD_ROW_LEN+1); if (entry > MAX_SD_USERDATA_ENTRY) {
ui_disp_menu(2); printf("invalid entry\n");
return -1;
while (1) {
btn_vec = IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & RC_MASK;
if (btn_vec == rc_keymap[RC_BTN1]) {
break;
} else if (btn_vec == rc_keymap[RC_BTN2]) {
retval = UDATA_IMPT_CANCELLED;
strncpy(menu_row2, "Cancelled", LCD_ROW_LEN+1);
goto sd_disable;
}
usleep(WAITLOOP_SLEEP_US);
} }
strncpy(menu_row2, "Loading...", LCD_ROW_LEN+1); if (!sdcard_dev.mount) {
ui_disp_menu(2); retval = file_mount();
// Import the userdata
for (n=0; n<=MAX_USERDATA_ENTRY; ++n) {
res = SD_Read(&sdcard_dev, &header, (512+n*SECTORSIZE)/SD_BLK_SIZE, 0, sizeof(header));
if (res != SD_OK) {
printf("Failed to read SD card\n");
retval = -res;
goto sd_disable;
}
if (strncmp(header.userdata_key, "USRDATA", 8)) {
printf("Not an userdata entry at 0x%x\n", 512+n*SECTORSIZE);
continue;
}
if ((header.type == UDE_PROFILE) && ((header.version_major != PROFILE_VER_MAJOR) || (header.version_minor != PROFILE_VER_MINOR))) {
printf("Profile version %u.%.2u does not match current one\n", header.version_major, header.version_minor);
continue;
} else if ((header.type == UDE_INITCFG) && ((header.version_major != INITCFG_VER_MAJOR) || (header.version_minor != INITCFG_VER_MINOR))) {
printf("Initconfig version %u.%.2u does not match current one\n", header.version_major, header.version_minor);
continue;
} else if (header.type > UDE_PROFILE) {
printf("Unknown userdata entry type %u\n", header.type);
continue;
}
// Just blindly write the entry to flash
retval = copy_sd_to_flash((512+n*SECTORSIZE)/SD_BLK_SIZE, (n*PAGES_PER_SECTOR)+(USERDATA_OFFSET/PAGESIZE),
(header.type == UDE_PROFILE) ? (sizeof(ude_profile)+sizeof(video_modes_plm_default)) : sizeof(ude_initcfg), databuf);
if (retval != 0) { if (retval != 0) {
printf("Copy from SD to flash failed (error %d)\n", retval); printf("SD card not detected %d\n", retval);
goto sd_disable; return -2;
} }
entries_imported++;
} }
// flash read immediately after write might fail, add some delay if (f_open(&p_file, p_filename, FA_WRITE|FA_CREATE_ALWAYS) != F_OK) {
usleep(1000); return -3;
}
read_userdata(INIT_CONFIG_SLOT, 0); memset(&hdr, 0x00, sizeof(ude_hdr));
profile_sel = input_profiles[target_input]; strlcpy(hdr.userdata_key, "USRDATA", 8);
read_userdata(profile_sel, 0); hdr.type = (entry > MAX_SD_PROFILE) ? UDE_INITCFG : UDE_PROFILE;
sniprintf(menu_row2, LCD_ROW_LEN+1, "%d slots loaded", entries_imported); if (hdr.type == UDE_INITCFG) {
retval = 1; target_map = ude_initcfg_items;
hdr.num_items = sizeof(ude_initcfg_items)/sizeof(ude_item_map);
sd_disable: sniprintf(hdr.name, USERDATA_NAME_LEN+1, "INITCFG");
SPI_CS_High(); } else if (hdr.type == UDE_PROFILE) {
target_map = ude_profile_items;
hdr.num_items = sizeof(ude_profile_items)/sizeof(ude_item_map);
// Check if name override file exists
sniprintf(p_filename, sizeof(p_filename), "prof_n.txt");
if (!file_open(&name_file, p_filename)) {
for (i=0; i<=entry; i++) {
if (file_get_string(&name_file, target_profile_name, sizeof(target_profile_name)) == NULL)
break;
}
file_close(&name_file);
}
if (i == entry+1) {
// strip CR / CRLF
target_profile_name[strcspn(target_profile_name, "\r\n")] = 0;
strlcpy(hdr.name, target_profile_name, USERDATA_NAME_LEN+1);
} else if (cur_profile_name[0] == 0) {
sniprintf(hdr.name, USERDATA_NAME_LEN+1, "<used>");
} else {
strlcpy(hdr.name, cur_profile_name, USERDATA_NAME_LEN+1);
}
}
// Write header
if ((f_write(&p_file, &hdr, sizeof(ude_hdr), &bytes_written) != F_OK) || (bytes_written != sizeof(ude_hdr))) {
retval = -4;
goto close_file;
}
bytes_written_tot = bytes_written;
// Write data
for (i=0; i<hdr.num_items; i++) {
if ((f_write(&p_file, &target_map[i].hdr, sizeof(ude_item_hdr), &bytes_written) != F_OK) || (bytes_written != sizeof(ude_item_hdr))) {
retval = -5;
goto close_file;
}
bytes_written_tot += bytes_written;
if ((f_write(&p_file, target_map[i].data, target_map[i].hdr.data_size, &bytes_written) != F_OK) || (bytes_written != target_map[i].hdr.data_size)) {
retval = -6;
goto close_file;
}
bytes_written_tot += bytes_written;
}
printf("%u bytes written into userdata entry %u\n", bytes_written_tot, entry);
close_file:
file_close(&p_file);
return retval; return retval;
} }
static alt_u8 poll_yesno(const useconds_t useconds, alt_u32 *const btn_vec_out) int read_userdata_sd(uint8_t entry, int dry_run) {
{ FIL p_file;
alt_u32 btn_vec; ude_hdr hdr;
alt_u8 ret = 0U; ude_item_hdr item_hdr;
const ude_item_map *target_map;
unsigned int bytes_read, bytes_read_tot;
char p_filename[14];
int i, j, target_map_items, retval=0;
for (alt_u32 i = 0; i < (useconds/WAITLOOP_SLEEP_US); ++i) { if (entry == SD_INIT_CONFIG_SLOT)
btn_vec = IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & RC_MASK; sniprintf(p_filename, 14, "settings.bin");
else
sniprintf(p_filename, 14, "prof%.2u.bin", entry);
for (alt_u32 j = RC_BTN1; j < (REMOTE_MAX_KEYS - 1); ++j) { if (entry > MAX_SD_USERDATA_ENTRY) {
if (btn_vec == rc_keymap[j]) { printf("invalid entry\n");
ret = 1U; return -1;
}
if (!sdcard_dev.mount) {
retval = file_mount();
if (retval != 0) {
printf("SD card not detected %d\n", retval);
return -2;
}
}
if (file_open(&p_file, p_filename) != F_OK) {
return -3;
}
if ((f_read(&p_file, &hdr, sizeof(ude_hdr), &bytes_read) != F_OK) || (bytes_read != sizeof(ude_hdr))) {
printf("Hdr read error\n");
retval = -4;
goto close_file;
}
bytes_read_tot = bytes_read;
if (strncmp(hdr.userdata_key, "USRDATA", 8)) {
printf("No userdata found on file\n");
retval = -5;
goto close_file;
}
strlcpy(target_profile_name, hdr.name, USERDATA_NAME_LEN+1);
if (dry_run)
goto close_file;
target_map = (hdr.type == UDE_INITCFG) ? ude_initcfg_items : ude_profile_items;
target_map_items = (hdr.type == UDE_INITCFG) ? sizeof(ude_initcfg_items)/sizeof(ude_item_map) : sizeof(ude_profile_items)/sizeof(ude_item_map);
for (i=0; i<hdr.num_items; i++) {
if ((f_read(&p_file, &item_hdr, sizeof(ude_item_hdr), &bytes_read) != F_OK) || (bytes_read != sizeof(ude_item_hdr))) {
printf("Item header read fail\n");
retval = -6;
goto close_file;
}
bytes_read_tot += sizeof(ude_item_hdr);
for (j=0; j<target_map_items; j++) {
if (!memcmp(&item_hdr, &target_map[j].hdr, sizeof(ude_item_hdr))) {
if ((f_read(&p_file, target_map[j].data, item_hdr.data_size, &bytes_read) != F_OK) || (bytes_read != item_hdr.data_size)) {
printf("Item data read fail\n");
retval = -7;
goto close_file;
}
break; break;
} }
} }
bytes_read_tot += item_hdr.data_size;
if (ret) if (j == target_map_items)
break; f_lseek(&p_file, bytes_read_tot);
usleep(WAITLOOP_SLEEP_US);
} }
if (ret) if (hdr.type == UDE_PROFILE)
*btn_vec_out = btn_vec; update_cur_vm = 1;
return ret; strlcpy(cur_profile_name, target_profile_name, USERDATA_NAME_LEN+1);
} printf("%u bytes read from userdata entry %u\n", bytes_read_tot, entry);
int export_userdata() close_file:
{ file_close(&p_file);
int retval; return retval;
const char *msg;
alt_u8 databuf[SD_BLK_SIZE];
alt_u8 prompt_state = 0;
useconds_t prompt_delay;
const alt_u8 prompt_transitions[] = { 1, 2, 0, 0, };
const alt_u8 prompt_ofs[] = { 0, 16, 31, LNG(48, 47), };
const char *prompt_msgs =
LNG(
"SD CARD WILL BE" "\0" // [ 0..15]
"OVERWRITTEN!!!" "\0" // [16..30]
"Export? 1=Y, 2=N""\0" // [31..47]
"Press 1 or 2", // [48..60]
"SDカードヲウワガキシマス" "\0" // [ 0..15]
"ゴチュウイクダサイ!!!" "\0" // [16..30]
"1=ジッコウスル 2=ヤメル" "\0" // [31..46]
"ドチラカエランデクダサイ" // [47..60]
);
alt_u32 btn_vec, sd_block_offset;
_Static_assert(SD_BLK_SIZE == FAT16_SECTOR_SIZE, "Sector size mismatch");
retval = check_sdcard(databuf);
SPI_CS_High();
if (retval != 0) {
retval = -retval;
goto out;
}
usleep(100000U);
while (1) {
msg = &prompt_msgs[prompt_ofs[prompt_state]];
prompt_delay = (prompt_state == 2) ? 2000000U
: ((prompt_state == 3) ? 300000U : 1000000U);
prompt_state = prompt_transitions[prompt_state];
strncpy(menu_row2, msg, LCD_ROW_LEN+1);
ui_disp_menu(2);
if (poll_yesno(prompt_delay, &btn_vec))
goto eval_button;
continue;
eval_button:
if (btn_vec == rc_keymap[RC_BTN1]) {
break;
} else if (btn_vec == rc_keymap[RC_BTN2] ||
btn_vec == rc_keymap[RC_BACK])
{
retval = UDATA_EXPT_CANCELLED;
goto out;
}
prompt_state = 3;
}
usleep(100000U);
strncpy(menu_row1,"SD Format", LCD_ROW_LEN+1);
strncpy(menu_row2,"1=FAT16, 2=RAW", LCD_ROW_LEN+1);
ui_disp_menu(2);
if ((!poll_yesno(5000000U, &btn_vec)) || ((btn_vec != rc_keymap[RC_BTN1]) && (btn_vec != rc_keymap[RC_BTN2]))) {
retval = UDATA_EXPT_CANCELLED;
goto out;
}
sd_block_offset = (btn_vec == rc_keymap[RC_BTN1]) ? (PROF_16_DATA_OFS/SD_BLK_SIZE) : 0;
strncpy(menu_row2, LNG("Exporting...", "オマチクダサイ"), LCD_ROW_LEN+1);
ui_disp_menu(2);
// RAW copy
if (btn_vec == rc_keymap[RC_BTN2])
goto copy_start;
/* Zero out the boot sector, FATs and root directory. */
memset(databuf, 0, SD_BLK_SIZE);
for (alt_u32 sector = 0;
sector < (FAT16_ROOT_DIR_FIRST_SECTOR + FAT16_ROOT_DIR_SECTORS);
++sector)
{
retval = SD_Write(&sdcard_dev, databuf, sector);
if (retval)
goto out;
}
/* Generate and write the boot sector. */
generate_boot_sector_16(databuf);
retval = SD_Write(&sdcard_dev, databuf, 0);
if (retval)
goto out;
/* Generate and write the file allocation tables. */
for (alt_u16 clusters_written = 0, sd_blk_idx = 0;
clusters_written < (PROF_16_DATA_SIZE/FAT16_CLUSTER_SIZE);)
{
memset(databuf, 0, SD_BLK_SIZE);
clusters_written = generate_fat16(databuf, clusters_written);
retval = SD_Write(&sdcard_dev, databuf,
(FAT16_1_OFS/SD_BLK_SIZE) + sd_blk_idx);
if (retval)
goto out;
retval = SD_Write(&sdcard_dev, databuf,
(FAT16_2_OFS/SD_BLK_SIZE) + sd_blk_idx);
if (retval)
goto out;
++sd_blk_idx;
}
/* Write the directory entry of the settings file. */
memset(databuf, 0, SD_BLK_SIZE);
memcpy(databuf, prof_dirent_16, PROF_DIRENT_16_SIZE);
retval = SD_Write(&sdcard_dev, databuf, PROF_DIRENT_16_OFS/SD_BLK_SIZE);
if (retval)
goto out;
copy_start:
// Zero out first 512 bytes (1 SD block) of the file
memset(databuf, 0, SD_BLK_SIZE);
retval = SD_Write(&sdcard_dev, databuf, sd_block_offset++);
if (retval)
goto out;
/* This may wear the SD card a bit more than necessary... */
retval = copy_flash_to_sd(USERDATA_OFFSET/PAGESIZE,
sd_block_offset,
(MAX_USERDATA_ENTRY + 1) * SECTORSIZE,
databuf);
out:
SPI_CS_High();
switch (retval) {
case 0:
msg = LNG("Success", "カンリョウシマシタ"); // Alternative: "カンリョウイタシマシタ"
break;
case SD_NOINIT:
msg = LNG("No SD card det.", "SDカードガミツカリマセン");
break;
case -EINVAL:
msg = LNG("Invalid params.", "パラメータガムコウデス");
break;
case UDATA_EXPT_CANCELLED:
msg = LNG("Cancelled", "キャンセルサレマシタ"); // Alternative: "キャンセルサセテイタダキマス"
break;
default:
msg = LNG("SD/Flash error", "SDカFLASHノエラー"); // フラッシュ would be NG.
break;
}
strncpy(menu_row2, msg, LCD_ROW_LEN+1);
if (!retval) {
return 1;
} else {
/*
* We want the message above to remain on screen, so return a
* positive value which nevertheless stands out when debugging.
*/
return 0x0dead;
}
} }

View File

@ -136,7 +136,10 @@ BSP_CFLAGS_OPTIMIZATION = -Os
# C/C++ compiler warning level. "-Wall" is commonly used.This setting defines # C/C++ compiler warning level. "-Wall" is commonly used.This setting defines
# the value of BSP_CFLAGS_WARNINGS in Makefile. # the value of BSP_CFLAGS_WARNINGS in Makefile.
BSP_CFLAGS_WARNINGS = -Wall BSP_CFLAGS_WARNINGS = -Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-function
# Match APP flags
BSP_CFLAGS_USER_FLAGS := -fdata-sections -ffunction-sections -fshort-enums -fgnu89-inline -flto -msmall-data-limit=0
# C compiler command. # C compiler command.
CC = riscv64-unknown-elf-gcc -xc CC = riscv64-unknown-elf-gcc -xc

15640
sys.sopcinfo

File diff suppressed because one or more lines are too long