Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint.h is not working, VSCode shows error on every SDCC keyword #45

Open
marshfolx opened this issue Jun 17, 2022 · 2 comments
Open

lint.h is not working, VSCode shows error on every SDCC keyword #45

marshfolx opened this issue Jun 17, 2022 · 2 comments

Comments

@marshfolx
Copy link

marshfolx commented Jun 17, 2022

图片

SDCC related defines, like __SDCC and __SDCC_mcs51, were added somewhere which causes lint.h is useless.

A simple workaround is undef __SDCC_mcs51 before including lint.h, then re-define it, like:

#undef __SDCC_mcs51
#include <lint.h>
#define __SDCC_mcs51

but this way all the SDCC keyword below will disapear.

@IOsetting
Copy link

I get the same problem.

My workaround is add a new macro before SDCC

#if defined (__SDCC_SYNTAX_FIX)
    #include <stdbool.h>
    #include <lint.h>
    # warning unrecognized compiler
    #define __BIT   bool
    #define __IDATA
    #define __PDATA 
    #define __XDATA 
    #define __CODE 
    #define __REENTRANT  
    #define SBIT(name, addr, bit)    volatile bool           name
    #define SFR(name, addr)          volatile unsigned char  name
    #define SFRX(addr)               (*(unsigned char volatile *)(addr))
    #define SFR16X(addr)             (*(unsigned char volatile *)(addr))
    #define INTERRUPT(name, vector)  void name (void) 
    #define INTERRUPT_USING(name, vector, regnum) void name (void)
    #define NOP() 

#elif defined (SDCC) || defined (__SDCC)
    #define __BIT   __bit
    #define __IDATA __idata
    #define __PDATA __pdata
    #define __XDATA __xdata
    #define __CODE  __code
    #define __REENTRANT  __reentrant
    #define SBIT(name, addr, bit)  __sbit  __at(addr+bit)                    name
    #define SFR(name, addr)        __sfr   __at(addr)                        name
    #define SFRX(addr)              (*(unsigned char volatile __xdata *)(addr))
    #define SFR16X(addr)            (*(unsigned int  volatile __xdata *)(addr))

    #define INTERRUPT(name, vector) void name (void) __interrupt (vector)
    #define INTERRUPT_USING(name, vector, regnum) void name (void) __interrupt (vector) __using (regnum)
    #define NOP() __asm NOP __endasm

//...

#endif

Then create a separate env for code editing

build_flags =
    -D__SDCC_SYNTAX_FIX
    -D__CONF_FOSC=36864000UL
    -D__CONF_MCU_MODEL=MCU_MODEL_STC8H3K32S2
    ...

and build/upload with another env.

@a3510377
Copy link

a3510377 commented Sep 28, 2024

A simple demonstration:

#include <stdbool.h>
#undef __SDCC_mcs51
#include <lint.h>
#define __SDCC_mcs
#include <8052.h>

#define MAIN_Fosc 16000000uL
#define led P1_0

void delay_ms(unsigned int ms);

void main() {
  while (1) {
    led = true;
    delay_ms(500);
    led = false;
    delay_ms(500);
  }
}

void delay_ms(unsigned int ms) {
  unsigned int i;
  do {
    i = MAIN_Fosc / 13000;
    while (--i);
  } while (--ms);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants