Skip to content

Commit

Permalink
bootloader: fix status change from remote
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1nb0w committed Jul 19, 2020
1 parent 072473c commit 49cbff1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 19 deletions.
41 changes: 30 additions & 11 deletions bootloader/Bootloader.v
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,19 @@ reg start_addr_ready = 1'b0;
// slot value
wire [1:0] slot_num;
reg [1:0] slot_num_ext = 2'd1;
// flag to alert when the value changed from remote
reg slot_changed_ext = 1'b0;
// high when we receive a valid slot from MCU
wire slot_ready;
// high if we have changed slot, power amplifier or audio amplifier
reg status_changed = 1'b0;
// status of the power amplifier
wire pa_enabled;
reg pa_enabled_ext = 1'b0;
// status of the audio amplifier
wire aa_enabled;
reg aa_enabled_ext = 1'b0;
// flags to alert when the value changed from remote
reg pa_changed_ext = 1'b0;
reg aa_changed_ext = 1'b0;
// crc error during radio firmware loading
wire fw_crc_error;
// option that manage the auto power on functionality
Expand All @@ -438,11 +441,27 @@ reg [3:0] stage = 4'h01;
reg stage_changed = 1'b0;

mcu #(.fw_version(fw_version), .fw_type(fw_type)) mcu_uart (
.clk(INA_CLK), .mcu_uart_rx(MCU_UART_RX), .mcu_uart_tx(MCU_UART_TX), .ip(local_IP), .eeprom_read_ready(ip_ready),
.stage(stage), .stage_changed(stage_changed), .slot_ext(slot_num_ext), .slot(slot_num), .slot_ready(slot_ready),
.power_amplifier(pa_enabled), .power_amplifier_ext(pa_enabled_ext), .audio_amplifier(aa_enabled), .audio_amplifier_ext(aa_enabled_ext),
.poweron_ext(auto_poweron_ext), .poweron_changed_ext(auto_poweron_changed_ext), .poweron(auto_poweron),
.status_changed_ext(status_changed), .ip_changed(write_ip)
.clk(INA_CLK),
.mcu_uart_rx(MCU_UART_RX),
.mcu_uart_tx(MCU_UART_TX),
.ip(local_IP),
.eeprom_read_ready(ip_ready),
.stage(stage),
.stage_changed(stage_changed),
.slot_ext(slot_num_ext),
.slot_changed_ext(slot_changed_ext),
.slot(slot_num),
.slot_ready(slot_ready),
.power_amplifier(pa_enabled),
.power_amplifier_ext(pa_enabled_ext),
.power_amplifier_changed_ext(pa_changed_ext),
.audio_amplifier(aa_enabled),
.audio_amplifier_ext(aa_enabled_ext),
.audio_amplifier_changed_ext(aa_changed_ext),
.poweron_ext(auto_poweron_ext),
.poweron_changed_ext(auto_poweron_changed_ext),
.poweron(auto_poweron),
.ip_changed(write_ip)
);

// add 10 seconds delay before deciding if boot radio or stay in the bootloader
Expand Down Expand Up @@ -770,7 +789,7 @@ begin
// by flash module. Since the latter works at 12.5MHz should
// be enought
slot_num_ext <= ip_data_buffer[1:0];
status_changed <= ~status_changed;
slot_changed_ext <= ~slot_changed_ext;
erase_req <= ~erase_req;
pkt_rx_state <= 1'd0;
end
Expand Down Expand Up @@ -811,7 +830,7 @@ begin
// get the new status of the audio amplifier
aa_enabled_ext <= ip_data_buffer[0:0];
// notify that the status is changed
status_changed <= ~status_changed;
aa_changed_ext <= ~aa_changed_ext;
// reply with the same package
udp_buffer[(32-0)*8-1 : 0] <= {"EAA", 224'b0, 7'b0, ip_data_buffer[0:0] };
udp_length <= 8'd8 + 8'd32;
Expand All @@ -826,7 +845,7 @@ begin
// get the new status of the audio amplifier
pa_enabled_ext <= ip_data_buffer[0:0];
// notify that the status is changed
status_changed <= ~status_changed;
pa_changed_ext <= ~pa_changed_ext;
// reply with the same package
udp_buffer[(32-0)*8-1 : 0] <= {"EPA", 224'b0, 7'b0, ip_data_buffer[0:0] };
udp_length <= 8'd8 + 8'd32;
Expand Down Expand Up @@ -884,7 +903,7 @@ begin
begin
slot_num_ext <= ip_data_buffer[1:0];
// notify that the status is changed
status_changed <= ~status_changed;
slot_changed_ext <= ~slot_changed_ext;
// reply with the same package
udp_buffer[(32-0)*8-1 : 0] <= {"SLC", 224'b0, 6'b0, ip_data_buffer[1:0] };
udp_length <= 8'd8 + 8'd32;
Expand Down
6 changes: 6 additions & 0 deletions bootloader/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Fainitski N7DDC:
- asynchronous communication with MCU
- fully remote controllable (also bootloader access)

** Notes

- the booting is soo long because it waits a stop signal from the
remote programmer; this is used to enter in the bootloader from
remote.

** TO DO

- IPv4 subnet
Expand Down
56 changes: 48 additions & 8 deletions bootloader/mcu.v
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module mcu
// alert Reconfigure when we have received the slot
output reg slot_ready = 1'b0,

// the remote slot is changed
input slot_changed_ext,

// bit with the amplifiers status
input power_amplifier_ext,
input audio_amplifier_ext,
Expand All @@ -53,9 +56,10 @@ module mcu
output reg [1:0] slot = 2'b0,
output reg power_amplifier = 1'b0,
output reg audio_amplifier = 1'b0,

// different from before if amplifier/slot status changed
input status_changed_ext,

// flag to alert when a value changed
input power_amplifier_changed_ext,
input audio_amplifier_changed_ext,

// variable for the auto power on functionality
input poweron_ext,
Expand Down Expand Up @@ -140,14 +144,21 @@ reg power_amplifier_int = 1'b0;
reg audio_amplifier_int = 1'b0;
reg status_changed_int = 1'b0;
reg status_changed_int_old = 1'b0;
reg status_changed_ext_old = 1'b0;

// manage the auto power on option
reg poweron_int = 1'b0;
reg poweron_changed_int = 1'b0;
reg poweron_changed_int_old = 1'b0;
reg poweron_changed_ext_old = 1'b0;

// flags from remote status change
reg slot_changed_ext_old = 1'b0;
reg power_amplifier_changed_ext_old = 1'b0;
reg audio_amplifier_changed_ext_old = 1'b0;

reg send_status = 1'b0;
reg send_status_old = 1'b0;

// manage the status changes from network programmer
// and from mcu keys
// NOTE: must exist a simplier solution!
Expand All @@ -162,14 +173,28 @@ begin
power_amplifier <= power_amplifier_int;
audio_amplifier <= audio_amplifier_int;
end
else if (status_changed_ext != status_changed_ext_old)
// check the status
else if (slot_changed_ext != slot_changed_ext_old)
begin
status_changed_ext_old <= status_changed_ext;
slot_changed_ext_old <= slot_changed_ext;
slot <= slot_ext;
if (send_status == send_status_old)
send_status = ~send_status;
end
else if (power_amplifier_changed_ext != power_amplifier_changed_ext_old)
begin
power_amplifier_changed_ext_old <= power_amplifier_changed_ext;
power_amplifier <= power_amplifier_ext;
if (send_status == send_status_old)
send_status = ~send_status;
end
else if (audio_amplifier_changed_ext != audio_amplifier_changed_ext_old)
begin
audio_amplifier_changed_ext_old <= audio_amplifier_changed_ext;
audio_amplifier <= audio_amplifier_ext;
if (send_status == send_status_old)
send_status = ~send_status;
end

// check if the power on option is changed
if (poweron_changed_int != poweron_changed_int_old)
begin
Expand Down Expand Up @@ -205,8 +230,23 @@ begin
end
// check if we are programming the bootloader
// therefore we don't need to send the status change
else if ((status_changed_ext != status_changed_ext_old) & (slot_ext != 2'b0))
/*
else if ((slot_changed_ext != slot_changed_ext_old) & (slot_ext != 2'b0))
begin
state_tx <= STATE_SEND_STATUS;
end
else if (power_amplifier_changed_ext != power_amplifier_changed_ext_old)
begin
state_tx <= STATE_SEND_STATUS;
end
else if (audio_amplifier_changed_ext != audio_amplifier_changed_ext_old)
begin
state_tx <= STATE_SEND_STATUS;
end
*/
else if ((send_status != send_status_old) & (slot_ext != 2'b0))
begin
send_status_old <= send_status;
state_tx <= STATE_SEND_STATUS;
end
else if (stage_changed != stage_changed_old)
Expand Down

0 comments on commit 49cbff1

Please sign in to comment.