Search code examples
cstructstubbit-fields

Stub a Special Function Register


I want to stub a special function register from a NEC microcontroller (Device is a 78K). I can't get any information how the sfr commands is coded.

The current main.c and Device.h looks like this:

// Device.h
sfr P1 = 0xFF01;     
sfr P2 = 0xFF02;
...

// main.c
#inlcude <Device.h>

void main(void) 
{ 
   P1.7 = 0; 
   P2.0 = 1;   
} 

afterwards is should look like this

// StubDevice.h
// typdef struct & volatile & bitfield = stubsfr
stubsfr P1
stubsfr P2 
...

// main.c
#include "StubDevice.h" 

void main(void) 
{ 
   P1.7 = 0; 
   P2.0 = 1;   
} 

It's a C-Project with a very old compiler. I dont wan't to change someting in the main function. I only want to add a new header file with the stubed special functions registers and use e.g. MinGW instead of the old compiler.

Is there a possiblity to use a typdef struct & volatile & bitfields to creat a variable stubsfr?

Thank you very much


Solution

  • This will be pretty hard to achieve without changing the implementation at least a little. This is because regular C will not allow you to name struct members with a number* so you will not be able to create a struct object that replaces the SFR registers.

    *C says that names must start with a letter or an underscore.