Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would use a combination of structs to rappresent the register and a pair of functions to handle them.</p> <p>In a <code>fpga_register.h</code> you would have something like</p> <pre><code>#define FPGA_READ = 1; #define FPGA_WRITE = 2; typedef struct register_t { char permissions; } FPGARegister; FPGARegister* fpga_init(void* address, char permissions); int fpga_write(FPGARegister* register, void* value); int fpga_read(FPGARegister* register, void* value); </code></pre> <p>with READ and WRITE in xor to express permissions.</p> <p>Than in the <code>fpga_register.c</code> you would define a new struct</p> <pre><code>typedef struct register_t2 { char permissions; void * address; } FPGARegisterReal; </code></pre> <p>so that you returns a pointer to it instead of a pointer to <code>FPGARegister</code> on <code>fpga_init</code>.</p> <p>Then, on <code>fpga_read</code> and <code>fpga_write</code> you check the permissions and </p> <ul> <li>if the operetion is allowed, cast back the <code>FPGARegister</code> from the argument to a <code>FPGARegisterReal</code>, execute the desired action (set or read the value) and return a success code</li> <li>if the operation is not allowed, just return an error code</li> </ul> <p>This way, no one including the header file will be able to access the <code>FPGARegisterReal</code> structure, and thus it will not have direct access to the register address. Obviously, one could hack it, but I'm quite sure that such intentional hacks are not your actual concerns.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload