Help porting code

  • Jonny Bergdahl

    Jonny Bergdahl - 2005-01-25

    I am in the process of porting some code to be able to compile a project with sdcc. I have a problem compiling the following existing code:

    --- from the .h file
    #define SERIAL_ADDRESS 0x027FFE  // AT89C55 EPROM address used for serial number
    bool i2c_write(u_short address, void *buffer, byte length, bool card);

    --- from the .c file
          i2c_write (SM_TEMPSTART+sizeof(t_result)+(u_short)(&((t_stat*)0)->serialno),
              (u_short*)SERIAL_ADDRESS, 2, FALSE);  // Write counters serial number into data structure

    sdcc gives me this output:
    cassina.c:150: error: illegal cast of LITERAL value to 'generic' pointer
    from type 'literal-long-int'
    to type 'unsigned-int generic* '

    As far as I can tell by the code, it needs to pass a pointer to the data at memory address 0x027FFE, where the device serial number is stored.
    What is the proper sdcc way of getting the pointer needed?

    • Maarten Brock

      Maarten Brock - 2005-01-26


      SDCC is a compiler for Small Devices. This mostly comes down to 8 bit mcu's with 16 bit addresses. Therefor a pointer is usually a 16 bit value. 0x027FFE is at least 18 bits large and SDCC makes it a 32 bit "long int".

      Which small device did you choose to port to and what makes you think there will be a serial number at memory address 0x027FFE in your device?

      Hope this helps,

      • Jonny Bergdahl

        Jonny Bergdahl - 2005-01-26

        I am not porting the project to a new device (we are using 89C51RC2), I am just porting the code to be used with the sdcc compiler. The code compiles as written with the commercial compiler the original author used.

        The serial number is displayed on the LCD screen when the device is started using this (existing) code:
          lcdout(VERSION_STR " SNr", CUR_POS(0,1));
          ltoa( (signed long)(*(u_short *)SERIAL_ADDRESS), buf);
          lcdout(buf, CUR_POS(0,11));

        I see your point about 18 bits... Looking at the typecast above I guess it should work like this:
        (u_short*)0x027FFE would translate to 0x7FFE, so I guess the "2" part is a way to tell the original compiler to access the code segment. Does this make more sense?


    • Maarten Brock

      Maarten Brock - 2005-01-27

      I guess it does. Try using this:
      #define SERIAL_ADDRESS 0x7FFE
      (code u_short*)SERIAL_ADDRESS


Log in to post a comment.