
This module details the usage of writing verification test software in C
1. Representation of hardware registers in C
2. Symbol file providing module base address
3. Accessing the module register in a test-case
Question 1 : How do you represent hardware registers in "C"?
In C modules are represented using structures, since it is simply an amalgamation of logically unified registers. The registers themselves are of either byte, word or double word, or double double word.
The representation is as follows :
unsigned char byte : BYTE : 8 bit
unsigned short int : WORD : 16 bit
unsigned long int : DOUBLE_WORD : 32 bit
unsigned long long : DOUBLE_DOUBLE_WORD : 64 bit
It all depends on the size of the register you are accessing. I haven’t seen any granularity other than this, that’s how processors work; they work on bytes or multiples thereof.
Now typically during your verification you would come across data which are represented as uint16 or uint32, they are no different from their definitions above:
typedef unsigned char uint8
typedef unsigned short int uint16
typedef unsigned long int uint32
typedef unsigned long long uint64
If you want them signed simply substitude unsigned with signed above,
typedef signed char int8
….
As an example lets say you have a module called GPD [General purpose device] and it has a SW register map as follows

You could create a structure as follows:
typedef struct{
volatile uint32 REV_NO; /*REV NO*/
volatile uint32 CLOCK_CONTROL; /*Clock control */
volatile uint16 INT_STATUS; /* Interrupt Status */
volatile uint16 INT_MASK; /* Interrupt Mask */
volatile uint32 CONFIG_SETTING; /* Configuration Setting */
} ASIC_GPD_STR
What does the volatile data type do for you ?
Simply put volatile tells the compiler to not make any assumptions about the value of the variable defined. It can change anytime, and it probably will, because not all registers are in total control of the processor, and especially HW status registers. This tells the compiler to go load the value from the register directly each and every time it needs it instead of treating it like a value in the processor register. Also it might require the MPU settings of your processor to make sure that such registers are not cached for any reason, and they will not be pushed on to stack like other variables.
You can put this structure into the sw_module_name/module_name_hardware.h header file
We are only done with defining our module. We need to breathe some life in to it, in order to allow for the processor to access it.
For this we need to do two things:
1. Tell the processor what the actual structure maps to
2. Make an allocation of memory of this structure
Question 2 : How do you map the base address of a module to the pointer to the structure just defined?
The actual structure’s base address is what you need to indicate to the compiler. This is usually done in a symbol file : The actually base address of all modules is defined out here, for both design and test-bench data structures:
0xA000_0000 asicGPD // This tells the compiler, and the processor where to access the module in the test-case
0xB000_0000 asicInterrupt_Controller
0xC000_0000 asicTB_Slave_1
Question 3 : And finally, how does the processor actually access the hardware register?
In actual Verification Test Software you can access the registers as follows:
#include "asicGPD_hardware_structure.h"
.....
integer module_access_test()
{
volatile ASIC_GPD_STR *asicGPD; /* This creates a pointer to the structure*/
uint16 mask_value;
uint32 config_setting;
integer errors = 0;
config_setting = 0x11112222;
mask_value = busread_register(asicGPD->Interrupt_Mask);
if(mask_value != interrupt_mask_register_default) {errors = errors++;}
buswrite_register(asicGPD->Config_Setting, config_setting);
return errors;
}
No comments:
Post a Comment