#1505 PIC error: pointer on SFR-variables

open
nobody
PIC16
5
2014-01-02
2009-02-15
No

I wrote a program for CAN-interface with PIC-IC P18f258. The SDCC compiler
is my choice. The program works, but I must unfortunately in the C-source changes
to do. SDCC has problems with the pointer on SFR-variable.
For example:

#if WITH_POINTER
if ( (flags & CAN_TX_FRAME_BIT) == CAN_TX_STD_FRAME )
CANIDToRegs((BYTE*)&RXB0SIDH, id, CAN_CONFIG_STD_MSG);
else
CANIDToRegs((BYTE*)&RXB0SIDH, id, flags);
#else
if ( (flags & CAN_TX_FRAME_BIT) == CAN_TX_STD_FRAME )
CANIDToRegsD(id, CAN_CONFIG_STD_MSG);
else
CANIDToRegsD(id, flags);
#endif

RXB0DLC = DataLen;

if ( !(flags & CAN_TX_RTR_BIT) )
RXB0DLC |= 0b01000000;

// Populate data values.
#if WITH_POINTER
ptr = (BYTE*)(&(RXB0D0));
for ( i = 0; i < DataLen; i++ )
ptr[i] = Data[i];
#else

RXB0D0 = Data[0];
RXB0D1 = Data[1];
RXB0D2 = Data[2];
RXB0D3 = Data[3];
RXB0D4 = Data[4];
RXB0D5 = Data[5];
RXB0D6 = Data[6];
RXB0D7 = Data[7];
#endif

When WITH_POINTER == 1 the program not works. The same program compiled
with Microchip C18 works without problem.

Discussion

  • Raphael Neider

    Raphael Neider - 2009-02-15
    • labels: --> pic16 target
     
  • Raphael Neider

    Raphael Neider - 2009-02-15

    The compiler incorrectly assumes that the SFRs reside in __code memory (generic pointer tag 0x00) instead of __data space (generic pointer tag 0x80). As a workaround, you can change all casts (BYTE*)some_sfr to (__data BYTE*)some_sfr to get it work.

    Best regards,
    Raphael

     
  • Maarten Brock

    Maarten Brock - 2014-01-02
    • Category: --> PIC16
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks