⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cam_example_util.uc

📁 网络处理器例子程序
💻 UC
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------------
//                                                                      
//                   I N T E L   P R O P R I E T A R Y                   
//                                                                       
//      COPYRIGHT (c)  2001 BY  INTEL  CORPORATION.  ALL RIGHTS          
//      RESERVED.   NO  PART  OF THIS PROGRAM  OR  PUBLICATION  MAY      
//      BE  REPRODUCED,   TRANSMITTED,   TRANSCRIBED,   STORED  IN  A    
//      RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER    
//      LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,    
//      MAGNETIC,  OPTICAL,  CHEMICAL, MANUAL, OR OTHERWISE,  WITHOUT    
//      THE PRIOR WRITTEN PERMISSION OF :                                
//                                                                       
//                         INTEL  CORPORATION                            
//                                                                      
//                      2200 MISSION COLLEGE BLVD                        
//                                                                       
//                SANTA  CLARA,  CALIFORNIA  95052-8119                  
//                                                                       
//------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//
//
//      File Name: cam_example_util.uc
//
//      Purpose: 
//
//      History:
//
//
//      Date            Comment                         By
//      ---------------------------------------------------------------------
//
//      10/23/2001      Created                         David Meng
//      01/21/2002      Modified the code to avoid a    Ameya Varde
//                      asembler warning.
//
/////////////////////////////////////////////////////////////////////////////

//File :cam_example_util.uc
//Description:  This file is the utility file for the CAM example project.

#include "stdmac.uc"
#include "cam_example.h"

.sig  sram_wait_op_done, dram_sleep_sig

// cam_init_from_dram
//	 	Description: Initialize the CAM 16 entries from preset values from DRAM 
//
//	 	Outputs:
//			The CAM entry are initialize. Each entry tag is from DRAM and state is
//          from input state
// 
//		Inputs:
//			init_state: The state will be written to the all CAM entry state field

#macro cam_init_from_dram[init_state]
cam_init_from_dram_begin#:
 .local $$xfer_0, $$xfer_1, count, dram_base, cam_entry
 .xfer_order $$xfer_0, $$xfer_1

//Set iterate value
//Set DRAM base 
//Set start CAM entry number
//Add DRAM offset to DRAM base for this ME
//Set init data area address in DRAM
  move[count, 0x08] 
  move[dram_base, _DRAM_BASE] 
  immed[cam_entry, 0]         
  add[dram_base,dram_base, _DRAM_OFFSET]  //defined in asebler settings
  add[dram_base, dram_base, _CAM_DRAM_INIT_AREA_OFFSET] 
loop_begin#:

//Read two tags from DRAM
//Context swap and waite the read done
//Write one CAM entry
//Write another CAM entry 
  dram[read, $$xfer_0, dram_base, 0, 1],sig_done[dram_sleep_sig]
  ctx_arb[dram_sleep_sig] 
  cam_write[cam_entry, $$xfer_0, init_state] 
  alu[cam_entry, cam_entry, +, 1]            
  cam_write[cam_entry, $$xfer_1, init_state] 

//Increment CAM entry number
//Update DRAM address
//Decrement iterate value
//If not done, continue
  alu[cam_entry, cam_entry, +, 1]
  alu[dram_base, dram_base, +, 8]
  alu[count, count, - ,1]        
  BNE[loop_begin#]               
loop_end#:
  .endlocal
//For debug purpose use some nops
#ifdef DEBUG_CAM
  nop 
  nop
#endif
cam_init_from_dram_end#:
#endm  

// cam_entry_to_dram
//	 	Description: Read tags from all CAM entries and send it to the display area in DRAM 
//
//	 	Outputs:
//			The CAM entries are stored in DRAM, one can check the entry using dump_dram
//          command line command 
// 
//		Inputs:
//			None
#macro cam_entry_to_dram[]
cam_cam_entry_to_dram_begin#:
 .local $$xfer_0, $$xfer_1, count, dram_base, cam_entry
 .xfer_order $$xfer_0, $$xfer_1

//Set iterate value
//Set DRAM base 
//Set start CAM entry number
//Add DRAM offset to DRAM base for this ME
//Set init data area address in DRAM
  move[count, 0x08]            //Set iterate value
  move[dram_base, _DRAM_BASE]  //Set DRAM base address
  immed[cam_entry, 0]          //Set start CAM entry number
  add[dram_base,dram_base, _DRAM_OFFSET]  //Add DRAM offset to DRAM base for this ME
  add[dram_base, dram_base, _CAM_DRAM_DISPLAY_AREA_OFFSET]  //Add the dispaly offset to DRAM base
loop_begin#:

//Read two tags from CAM entris
//Write one DRAM 
  cam_read_tag[$$xfer_0,cam_entry]  //Read tag from the CAM entry
  alu[cam_entry, cam_entry, +, 1]   //CAM entry number increment 
  cam_read_tag[$$xfer_1, cam_entry] //Read another tag form the CAM entry
  alu[cam_entry, cam_entry, +, 1]   //CAM entry number increment 
  dram[write, $$xfer_0, dram_base, 0, 1],sig_done[dram_sleep_sig] //Write to the DRAM
  ctx_arb[dram_sleep_sig] //Waite write finish

//Update DRAM address
//Decrement iterate value
//If not done, continue
  alu[dram_base, dram_base, +, 8] //DRAM address update
  alu[count, count, - ,1]         //Iterate value update
  BNE[loop_begin#]                //If not done, do it again
loop_end#:
  .endlocal
#ifdef DEBUG_CAM
  nop //For debug purpose
  nop
#endif
cam_entry_to_dram_end#:
#endm 


// cam_init_from_sram
//	 	Description: Initialize the CAM 16 entries from preset values from SRAM 
//
//	 	Outputs:
//			The CAM entries are initialized. Each entry tag is from SRAM and state is
//          from input state
// 
//		Inputs:
//			init_state: The state will be written to the all CAM entry state field
#macro cam_init_from_sram[init_state]
cam_init_from_sram_begin#:
 .local $xfer_sram, count, sram_base, cam_entry //Start init

//Set iterate value
//Set SRAM  base
//Add SRAM offset to base address for this ME
//Set SRAM address  to init data area
  move[count, 0x10]          
  move[sram_base, _SRAM_BASE]
  immed[cam_entry, 0]        
  add[sram_base,sram_base, _SRAM_OFFSET]
  add[sram_base,sram_base, _CAM_SRAM_INIT_AREA_OFFSET] 

//Start loop
//Read one entry tag from SRAM
//Write the tag to CAM entry tag field
//Update SRAM base
//Decrement iterate value
//If not done, repeat
loop_begin#:
  sram[read, $xfer_sram, sram_base, 0, 1],ctx_swap[sram_wait_op_done]
  cam_write[cam_entry, $xfer_sram, init_state]
  alu[cam_entry, cam_entry, +, 1]
  alu[sram_base, sram_base, +, 4]
  alu[count, count, - ,1]        
  bne[loop_begin#]
loop_end#:
  .endlocal //End init
#ifdef DEBUG_CAM
  nop //For debug purpose
  nop
#endif
cam_init_from_sram_end#:
#endm 

// cam_entry_to_sram
//	 	Description: Read tags from all CAM entries and send it to the display area in SRAM 
//
//	 	Outputs:
//			The CAM entries are stored in SRAM, one can check the entry using dump_sram
//          command line command 
// 
//		Inputs:
//			None 
#macro cam_entry_to_sram[]
cam_entry_to_sram_begin#:
 .local $xfer_sram, count, sram_base, cam_entry  //Start cam_entry_to_sram

// Set iterate value
//Set SRAM base
//Set start CAM entry number
//Add offset to the SRAM base for this ME
//Set SRAM address to display area
  move[count, 0x10]   
  move[sram_base, _SRAM_BASE]
  immed[cam_entry, 0]        
  add[sram_base,sram_base, _SRAM_OFFSET] 
  add[sram_base,sram_base, _CAM_SRAM_DISPLAY_AREA_OFFSET]

loop_begin#:
//Read one tag from CAM entry 
//Write to the sram and wait write finished
//Update CAM entry number
//Update SRAM adress
//Iterate value decrement 
//If not done, repeat
  cam_read_tag[$xfer_sram, cam_entry] 
  sram[write, $xfer_sram, sram_base, 0, 1],ctx_swap[sram_wait_op_done]
  alu[cam_entry, cam_entry, +, 1]
  alu[sram_base, sram_base, +, 4]
  alu[count, count, - ,1] 
  BNE[loop_begin#]
loop_end#:
//End cam_entry_to_sram
  .endlocal
#ifdef DEBUG_CAM
  nop //For debug purpose
  nop
#endif
cam_entry_to_sram_end#:
#endm 

// get_cam_lookup_result
//	 	Description: Do a CAM look up and parse the result.
//
//	 	Outputs:
//			state: The return state from the CAM look up				 	
//			status: 1 if hit
//					0 if miss
//			entry:	enrty number from the CAM lookup
// 
//		Inputs:
//			in_data	 Tag to be used in look up	
//		

#macro get_cam_lookup_result[stat, status, entry, in_data]
 .local result //Start get_cam_lookup_result

//Use in_data to do a lookup
//Get the enrty from the result
//Get the state from the result     
//Get the status from the result         
get_cam_lookup_result_begin#:
  cam_lookup[result, in_data] 
  and_shf_right[entry, 0xF, result, 3]
  and_shf_right[stat, 0xF, result, 8]
  and_shf_right[status, 0x1, result, 7]

get_cam_lookup_result_end#:
 .endlocal //End get_cam_lookup_result
#endm



// miss_hit_count_update
//	 	Description: Update miss and hit count value
//
//	 	Outputs:
//			miss_count:	  If miss, this value will increment 							 	
//			hit_count:	  If hit, this value will incerement
// 
//		Inputs:
//			miss_count:	  Original miss count value 							 	
//			hit_count:	  Original hit count value
//			in_status:	register holds the hit/miss status	
//		
//		Size: Maximum 3 instructions
//	

#macro miss_hit_count_update[miss_count, hit_count, in_status]
//Test the hit/miss status
//If miss, update miss count
//Jump to the end
    br_bset[in_status, 7, hit_update#]
	  alu[miss_count, miss_count, +, 1]
      br[miss_hit_count_update_end#]
hit_update#: 
//Hit, update hit count
	  alu[hit_count, hit_count, +, 1]
miss_hit_count_update_end#:          
#endm	        	   


//Macro cam_lookup_test
//	 	Description: This macro test the CAM look up based on the initilzation
//
//	 	Outputs: The macro will store the hit and miss in SDRAM and SRAM hit/miss
//               ccount respectively 
// 
//		Inputs:  None
//
//      Others: For SRAM init, the sram hit count is 16 and miss count is 0
//                             the dram hit count is 0 and miss count is 16
//  
//              For DRAM init, the sram hit count is 0 and miss count is 16
//                             the dram hit count is 16 and miss count is 0 
#macro cam_lookup_test[]
cam_lookup_test_begin#:
.local hit_count_1, miss_count_1, hit_count_2, miss_count_2 //Start cam_lookup_test
 
 //Clear  hit_count_1  (using SRAM initialization) 
 //Clear  miss_count_1  (using SRAM initialization) 
 //Clear  hit_count_2  (using DRAM initialization)
 //Clear  miss_count_2  (using DRAM initialization) 
  immed[hit_count_1, 0x0]  
  immed[miss_count_1, 0x0]
  immed[hit_count_2, 0x0] 
  immed[miss_count_2, 0x0]
//Folllowing code uses sram initial data as look up data do a
//CAM lookup. If the code is initilized using sram data, this is
//a hit test. If the code is initilized using dram data, this is
//a miss test 
  .local $xfer_sram, count, sram_base, sram_base_1, status 
//Start cam lookup 1
//Set loop up iterated value 16
//Set SRAM base
//Set SRAM offset for this ME
//Set SRAM display area base
    move[count, 0x10]  
    move[sram_base, _SRAM_BASE]
    add[sram_base_1,sram_base, _SRAM_OFFSET]
    add[sram_base,sram_base_1, _CAM_SRAM_DISPLAY_AREA_OFFSET]
loop_begin#:
//Write to the sram and wait write finished
//CAM look up
//Update miss and hit count value	        	   
//SRAM base increase 4
//Count decrement
//If not done, do next look up
    sram[read, $xfer_sram, sram_base, 0, 1],ctx_swap[sram_wait_op_done] 
    cam_lookup[status, $xfer_sram]
    miss_hit_count_update[miss_count_1, hit_count_1, status] 
    alu[sram_base, sram_base, +, 4]
    alu[count, count, - ,1]        
    bne[loop_begin#]               

loop_end#:
//move hit count to $xfer_sram register
//Get SRAM hit count base
//Write to the SRAM and wait write finished
//Move miss count to $xfer_sram
//Get SRAM miss count base
//Write to the SRAM and wait write finished
    move[$xfer_sram, hit_count_1]
    add[sram_base,sram_base_1, _CAM_SRAM_HITCOUNT_OFFSET]
    sram[write, $xfer_sram, sram_base, 0, 1],ctx_swap[sram_wait_op_done]
	move[$xfer_sram, miss_count_1]    
    add[sram_base,sram_base_1, _CAM_SRAM_MISSCOUNT_OFFSET]
    sram[write, $xfer_sram, sram_base, 0, 1],ctx_swap[sram_wait_op_done] 
//Finish cam lookup 1
  .endlocal

#ifdef DEBUG_CAM
//For debug purpose, one can set break point here
  nop
#endif

//Folllowing code uses dram initial data as look up data do a
//CAM lookup. If the code is initilized using dram data, this is
//a hit test. If the code is initilized using sram data, this is
//a miss test 
  .local $$xfer_0, $$xfer_1, count_2, dram_base, dram_base_2, status_2 
//Start cam look up 2
  .xfer_order $$xfer_0, $$xfer_1

//Set iterate value
//Set DRAM base
//Add DRAM base offset for this ME
//Set DRAM display area offset
    move[count_2, 0x08]
    move[dram_base, _DRAM_BASE]
    add[dram_base_2,dram_base, _DRAM_OFFSET]
    add[dram_base, dram_base_2, _CAM_DRAM_DISPLAY_AREA_OFFSET]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -