aboutsummaryrefslogtreecommitdiffstats
path: root/tests/asicworld/code_hdl_models_cam.v
blob: 0cebc07ccb3c0a4b2c7913ebff4d47d9fddef66b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//-----------------------------------------------------
// Design Name : cam
// File Name   : cam.v
// Function    : CAM
// Coder       : Deepak Kumar Tala
//-----------------------------------------------------
module cam (
clk         , // Cam clock
cam_enable  , // Cam enable
cam_data_in , // Cam data to match
cam_hit_out , // Cam match has happened
cam_addr_out  // Cam output address 
);

parameter ADDR_WIDTH  = 8;
parameter DEPTH       = 1 << ADDR_WIDTH;
//------------Input Ports--------------
input                    clk;      
input                    cam_enable;   
input  [DEPTH-1:0]       cam_data_in;  
//----------Output Ports--------------
output                   cam_hit_out;  
output [ADDR_WIDTH-1:0]  cam_addr_out;  
//------------Internal Variables--------
reg [ADDR_WIDTH-1:0]  cam_addr_out;
reg                   cam_hit_out;
reg [ADDR_WIDTH-1:0]  cam_addr_combo;
reg                   cam_hit_combo;
reg                   found_match;
integer               i;
//-------------Code Starts Here-------
always @(cam_data_in) begin
  cam_addr_combo   = {ADDR_WIDTH{1'b0}};
  found_match      = 1'b0;
  cam_hit_combo    = 1'b0;
  for (i=0; i<DEPTH; i=i+1) begin
    if (cam_data_in[i] && !found_match) begin
      found_match     = 1'b1;
      cam_hit_combo   = 1'b1;
      cam_addr_combo  = i;
    end else begin
      found_match     = found_match;
      cam_hit_combo   = cam_hit_combo;
      cam_addr_combo  = cam_addr_combo;
    end
  end
end

// Register the outputs 
always @(posedge clk) begin
  if (cam_enable) begin
    cam_hit_out  <=  cam_hit_combo;
    cam_addr_out <=  cam_addr_combo;
  end else begin
    cam_hit_out  <=  1'b0;
    cam_addr_out <=  {ADDR_WIDTH{1'b0}};
  end
end

endmodule 
ank = false, .DataOUTEndpointNumber = CDC_RX_EPNUM, .DataOUTEndpointSize = CDC_TXRX_EPSIZE, .DataOUTEndpointDoubleBank = false, .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, .NotificationEndpointDoubleBank = false, }, }; /** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be * used like any regular character stream in the C APIs */ static FILE USBSerialStream; /** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { SetupHardware(); /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */ CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); sei(); for (;;) { CheckJoystickMovement(); /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } } /** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ Joystick_Init(); LEDs_Init(); USB_Init(); } /** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */ void CheckJoystickMovement(void) { uint8_t JoyStatus_LCL = Joystick_GetStatus(); char* ReportString = NULL; static bool ActionSent = false; if (JoyStatus_LCL & JOY_UP) ReportString = "Joystick Up\r\n"; else if (JoyStatus_LCL & JOY_DOWN) ReportString = "Joystick Down\r\n"; else if (JoyStatus_LCL & JOY_LEFT) ReportString = "Joystick Left\r\n"; else if (JoyStatus_LCL & JOY_RIGHT) ReportString = "Joystick Right\r\n"; else if (JoyStatus_LCL & JOY_PRESS) ReportString = "Joystick Pressed\r\n"; else ActionSent = false; if ((ReportString != NULL) && (ActionSent == false)) { ActionSent = true; /* Write the string to the virtual COM port via the created character stream */ fputs(ReportString, &USBSerialStream); /* Alternatively, without the stream: */ // CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString)); } } /** Event handler for the library USB Connection event. */ void EVENT_USB_Device_Connect(void) { LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); } /** Event handler for the library USB Disconnection event. */ void EVENT_USB_Device_Disconnect(void) { LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); } /** Event handler for the library USB Configuration Changed event. */ void EVENT_USB_Device_ConfigurationChanged(void) { bool ConfigSuccess = true; ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface); LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); } /** Event handler for the library USB Control Request reception event. */ void EVENT_USB_Device_ControlRequest(void) { CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); }