`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
//	Tony Kim
//	6.111 Lab2
//
// Module name: TimeParameters
// Description: A four-location memory that holds 4-bit values. 
//
//////////////////////////////////////////////////////////////////////////////////

module TimeParameters(clk, timeSelector, timeValue, reprogram, interval, value, selected_value);
    input clk;
	 input [1:0] timeSelector;
    input [3:0] timeValue;
    input reprogram;
    input [1:0] interval;
    output [3:0] value;
	 output [3:0] selected_value;
	 
	parameter T_ARM_DELAY       = 2'b00;
	parameter T_DRIVER_DELAY    = 2'b01;
	parameter T_PASSENGER_DELAY = 2'b10;
	parameter T_ALARM_ON        = 2'b11; 

	parameter T_ARM_DELAY_DEFAULT       = 4'd6;
	parameter T_DRIVER_DELAY_DEFAULT    = 4'd8;
	parameter T_PASSENGER_DELAY_DEFAULT = 4'd15;
	parameter T_ALARM_ON_DEFAULT        = 4'd10;
	
	reg [3:0] t_arm_delay       = T_ARM_DELAY_DEFAULT;
	reg [3:0] t_driver_delay    = T_DRIVER_DELAY_DEFAULT;
	reg [3:0] t_passenger_delay = T_PASSENGER_DELAY_DEFAULT; 
	reg [3:0] t_alarm_on        = T_ALARM_ON_DEFAULT;
	reg [3:0] value;
	reg [3:0] selected_value;
	
	always @ (posedge clk)
	begin
		if(reprogram)
			case(timeSelector)
				T_ARM_DELAY:       t_arm_delay       <= timeValue;
				T_DRIVER_DELAY:	 t_driver_delay    <= timeValue; 
				T_PASSENGER_DELAY: t_passenger_delay <= timeValue;
				T_ALARM_ON:        t_alarm_on        <= timeValue;
			endcase
		
		case(interval)
			T_ARM_DELAY:       value <= t_arm_delay;
			T_DRIVER_DELAY:    value <= t_driver_delay;
			T_PASSENGER_DELAY: value <= t_passenger_delay;
			T_ALARM_ON:        value <= t_alarm_on;
		endcase
		
		//----------------------------------------------------------------------
		// This functionality is to print the appropriate parameter to 
		// the hex displays.
		//----------------------------------------------------------------------
		case(timeSelector)
			T_ARM_DELAY:       selected_value <= t_arm_delay;
			T_DRIVER_DELAY:    selected_value <= t_driver_delay;
			T_PASSENGER_DELAY: selected_value <= t_passenger_delay;
			T_ALARM_ON:        selected_value <= t_alarm_on;		
		endcase
	end
	
	

endmodule
