Skip to content

Commit

Permalink
R3: Fix RTC problems
Browse files Browse the repository at this point in the history
This addresses issue #29
  • Loading branch information
MJoergen committed Jan 7, 2024
1 parent f0ef9da commit 42ac705
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
6 changes: 3 additions & 3 deletions M2M/vhdl/i2c/cpu_to_i2c_master.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ begin
end if;
start <= start(2 downto 0) & start(0);

if cpu_wr_en = '1' and cpu_addr_i = REG_I2C_CONFIG then
if cpu_wr_en = '1' and cpu_addr_i(11 downto 0) = REG_I2C_CONFIG(11 downto 0) then
i2c_addr_o <= cpu_wr_data_i( 7 downto 0);
num_bytes <= cpu_wr_data_i(11 downto 8);
i2c_bus_o <= to_integer(unsigned(cpu_wr_data_i(15 downto 13)));
start(0) <= '1';
end if;
if cpu_rd_en = '1' then
if cpu_addr_i = REG_I2C_CONFIG then
if cpu_addr_i(11 downto 0) = REG_I2C_CONFIG(11 downto 0) then
cpu_rd_data_o( 7 downto 0) <= i2c_addr_o;
cpu_rd_data_o(11 downto 8) <= num_bytes;
cpu_rd_data_o(15 downto 13) <= std_logic_vector(to_unsigned(i2c_bus_o, 3));
elsif cpu_addr_i = REG_I2C_STATUS then
elsif cpu_addr_i(11 downto 0) = REG_I2C_STATUS(11 downto 0) then
cpu_rd_data_o(3 downto 0) <= response_i(3) & nack & response_i(1 downto 0);
nack <= '0';
end if;
Expand Down
36 changes: 29 additions & 7 deletions M2M/vhdl/i2c/rtc_master.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,18 @@ architecture synthesis of rtc_master is

constant C_ACTION_LIST_WRITE_R3 : action_list_t := (
-- This writes to the RTC
0 => (WAIT_CMD, X"F1", X"0001"), -- Wait until I2C is idle
1 => (SHIFT_OUT_CMD, X"00", X"0005"), -- Prepare to write to RTC
2 => (WRITE_CMD, X"F0", X"08DE"), -- Send eight bytes from RTC
3 => (WAIT_CMD, X"F1", X"0000"), -- Wait until I2C command is accepted
4 => (WAIT_CMD, X"F1", X"0001"), -- Wait until I2C is idle
5 => (END_CMD, X"00", X"0000")
0 => (WAIT_CMD, X"F1", X"0001"), -- Wait until I2C is idle
1 => (WRITE_CMD, X"00", X"0841"), -- Prepare to write 0x41 to address 0x08
2 => (WRITE_CMD, X"F0", X"02DE"), -- Send two bytes to RTC
3 => (WAIT_CMD, X"F1", X"0000"), -- Wait until I2C command is accepted
4 => (WAIT_CMD, X"F1", X"0001"), -- Wait until I2C is idle
5 => (SHIFT_OUT_CMD, X"00", X"0005"), -- Prepare to write to RTC
6 => (WRITE_CMD, X"F0", X"08DE"), -- Send eight bytes to RTC
7 => (WAIT_CMD, X"F1", X"0000"), -- Wait until I2C command is accepted
8 => (WAIT_CMD, X"F1", X"0001"), -- Wait until I2C is idle
9 => (WRITE_CMD, X"00", X"0801"), -- Prepare to write 0x01 to address 0x08
10 => (WRITE_CMD, X"F0", X"02DE"), -- Send two bytes from RTC
11 => (END_CMD, X"00", X"0000")
);

-- For the R5 board:
Expand Down Expand Up @@ -157,7 +163,23 @@ architecture synthesis of rtc_master is
pure function post_read(board : string; arg : std_logic_vector) return std_logic_vector is
begin
if board = "MEGA65_R3" then
return arg(55 downto 0) & X"00";
if arg(23) = '1' then
-- 24 hour format
return (arg(55 downto 0) and X"FFFFFFFF7FFFFF") & X"00";
else
-- 12 hour format
if arg(21) = '1' then
-- PM
if arg(19 downto 16) < "1000" then
return ((arg(55 downto 0) and X"FFFFFFFFDFFFFF") + X"000000120000") & X"00";
else
return ((arg(55 downto 0) and X"FFFFFFFFDFFFFF") + X"000000080000") & X"00";
end if;
else
-- AM
return arg(55 downto 0) & X"00";
end if;
end if;
else
-- Valid for R4 and R5
return arg(39 downto 32) & arg(63 downto 40) & arg(31 downto 0);
Expand Down

0 comments on commit 42ac705

Please sign in to comment.