eritronio Posted July 27, 2015 Report Share Posted July 27, 2015 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 Quote Link to comment Share on other sites More sharing options...
kaiserhaz Posted July 28, 2015 Report Share Posted July 28, 2015 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. Quote Link to comment Share on other sites More sharing options...
dakupoto Posted July 29, 2015 Report Share Posted July 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
kaiserhaz Posted July 29, 2015 Report Share Posted July 29, 2015 Shoot, I knew something felt wrong It's supposed to be sc_bv<32> instead of sc_bit<32>. My bad. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.