`include "../fsm/Fsm.sv"
`include "../Bus_if/Bus_if.sv"
`include "../timer_port/timer_top.sv"
`include "../spi_interface_radiant/spi_interface.sv"

module Top(
    input wire clk,
    input wire rst,
    input wire endOfConv,
    output wire LEDg,
    output wire LEDr,
    output wire AlarmAmpel,
    output wire Alarm_R
);
    // Bus (Interface)
    Bus_if bus(.clk(clk));
    // SPI Interface
    spi_interface_ports spi_bus(.clk(clk));

    // FSM
    Fsm fsm(
        .clk(clk),
        .inAlarmAmpel(bus.AlarmAmpel),
        .inDataValid(bus.DataValid),
        .inTasteAktiv(bus.TasteAktiv),
        .outAlarm_R(bus.Alarm_R),
        .outSendData(bus.SendData),
        .outTimerEN(bus.TimerEN)
    );
    // Parallelport
    parallelport parallelport1 (
        .inClk(clk),
        .inTimerMeas(bus.TimerMeas),
        .inEndOfConv(endOfConv),
        .inData(bus.Data),
        .outDataValid(bus.DataValid),
        .outData(bus.Data)
    );
    // FRAM-Controller
    // Timer
    timer timer1 (
        .inClk(clk),
        .inTaste(bus.Taste),
        .inEN(bus.TimerEN),
        .outReadTemp(bus.ReadTemp),
        .outTasteAktiv(bus.TasteAktiv)
    );
    // Ampelsteuerung
    led_top ampelsteuerung (
        .clk12M(clk),
        .rst(rst),
        .data_input(bus.Data),
        .data_valid(bus.DataValid),
        .RED(LEDr),
        .GRN(LEDg),
        .alarm(bus.AlarmAmpel)
    );

    assign AlarmAmpel = bus.AlarmAmpel;
    assign Alarm_R = bus.Alarm_R;

    assign bus.sbclk = spi_bus.sb_clk_i;
    assign bus.sbstb = spi_bus.sb_stb_i;
    assign bus.sbrw = spi_bus.sb_wr_i;
    assign bus.sbadr = spi_bus.sb_adr_i;
    assign bus.sbdat_r = spi_bus.sb_dat_i;
    assign bus.sbdat_w = spi_bus.sb_dat_o;
    assign bus.sback = spi_bus.sb_ack_o;
endmodule