Jump to content

Recommended Posts

Posted

Hi, I have an assignment in which I should model an adc. This adc has some 32 bit registers that must be accessed from a header file in order to write or read data from the adc. I have tried doing this by using a pointer, but I get a segmentation fault when accessing it in my program. I know that it is not possible to have custom address in c++ that you can write to. In this case, how it is possible to model such register in systemC?

 

for example in registers.h I have the following

#define control_register 0x40038000

 

 

and I try to write in some function of a systemc module

*((int *) control_register) = 2;

 

So, obviously I get the segmentation fault

 

Posted

Hello,

As far as I know, in SystemC one would model a register (or memory) as a an array, be it unidimensional or multidimensional.

It's not worth the effort of actually using 'real hardware' registers and memory-mapped addresses (correct me if I'm wrong). The whole point of using SystemC to model systems is to be able to describe functionality and not worry about implementation too much.

In your case, the control register could be represented as an sc_bit<32> or sc_lv<32>, as do other registers:

/** registers.h **/

sc_bit<32> control_register // ADC control reg

sc_bit<32> status_register // ADC status reg

// Other registers below

/*EOF*/

In this case, writing to reg would be as such:

control_register = 2 // Not sure if you need to cast the 2, I think you do need to

Alternatively, you could use an array of sc_bit, and define the address for specific registers as follows:

/** registers.h **/

#define ADC_CTRL_REG 0

#define ADC_STAT_REG 1

// Other reg addresses

sc_bit<32> adc_reg_file[/*size of regfile, or number of regs you want to have in ADC*/]

/*EOF*/

In this case writing to a register would be as such:

adc_reg_file[ADC_CTRL_REG] = 2 // Again I'm sure you'd have to cast it

Instead of arrays, you can also use sc_vector.

Technically, you could also still use the memory-mapped addresses. In this case, you could employ any of the methods above, but you'll need a translation method to convert that address to a simpler index (i.e. 0x40038000 -> /*Some int index, like 0 for example*/).

Hope that helps.

Posted

Hi, I have an assignment in which I should model an adc. This adc has some 32 bit registers that must be accessed from a header file in order to write or read data from the adc. I have tried doing this by using a pointer, but I get a segmentation fault when accessing it in my program. I know that it is not possible to have custom address in c++ that you can write to. In this case, how it is possible to model such register in systemC?

 

for example in registers.h I have the following

#define control_register 0x40038000

 

 

and I try to write in some function of a systemc module

*((int *) control_register) = 2;

 

So, obviously I get the segmentation fault

 

Hello Sir,

Just use bit vectors.

Hope that helps.

  • 7 years later...
Posted

@Akash_2675 is this a question or an assertion?

@kaiserhaz SystemC is about creating models of designs. You can model any address you want, but you certainly do not use real pointers to do this. You are probably best off using TLM2 as a transport. If you are not picky about the protocol and timing specifics, then you would probably model this as loosely-timed. A question you must answer is: What is the model being used for (architectural feasibility, early virtual prototyping, or hardware verification)? That will drive you towards the modeling style needed.

To amplify and clarify what I said about modeling... let's pretend I am modeling a 64-bit system (aka the target system), but I am running the model on a 32-bit processor as the simulator. Let's also say the modeled system has 32GB of RAM and devices memory mapped into another 1MB of addresses, but my simulator only has 16GB of memory, which also accommodates the OS. Obviously, I cannot represent the full memory space of the target system in my smallish simulator, but that does not prevent me from modeling it. I have a number of possibilities:

  1. Model the 32GB RAM as a sparse array using std::map<uint64_t,uint32_t>. I model the data as 32-bits for efficiency.
  2. The I/O devices would have addresses that are outside that model.
  3. Alternately, only model a few small segments of the 32GB memory. Perhaps I only need to model four separate areas of a few 100MB, then I could create four 100MB std::vector<uint32_t> and resize as needed.

When modeling, time is also modeled/simulated. So you need to be careful to keep that concept separate as well. SystemC has the notion of sc_time_stamp(), which is distinct from localtime or C++ chrono libraries.

If you don't understand any of what I said, then you need to take a course on SystemC or spend a lot of time learning about SystemC itself. But don't even think about any of this if you are not already a solid C++ programmer.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...