Atmel's Flash_api for Keil to SDCC

Help
Zappa
2005-03-13
2013-03-12
  • Zappa

    Zappa - 2005-03-13

    In Atmel's flash api there is following line:
    #define __API_FLASH_ENTRY_POINT (*((const void(code*)(void)) 0xFFC0 ))
    When I try to compile that file with SDCC I get  "error 27: Pointer required".
    Can anybody tell how to change that line to get it compile right?
    Does this following line do the job?
    #define __API_FLASH_ENTRY_POINT() _asm lcall 0xFFC0 _endasm;

     
    • Zappa

      Zappa - 2005-03-14

      Addition to previous post.
      Call is like this:
      __API_FLASH_ENTRY_POINT();

       
    • Maarten Brock

      Maarten Brock - 2005-03-14

      Your code does not work. This would be my solution:
      typedef void (*fp)(void); //define function pointer type
      code fp at 0xFFC0 api; //declare fp api and store it in code memory at FFC0
      api(); //and finally use it

      Greets,
      Maarten

       
    • Brian Cherdak

      Brian Cherdak - 2005-03-14

      hey,

      I had similar issues with my Cygnal/Silabs code.  I ended up rewriting the keil2sdcc converter in perl.  I can send you a copy if you'ld like.

      bc

       
    • Brian Cherdak

      Brian Cherdak - 2005-03-14

      sorry,

      Wrong problem.  mine was the keil sbit declaration.  oops.

      brian

       
    • Zappa

      Zappa - 2005-03-14

      I tried to declare function pointer as Maarten Brock suggested, but it didn't compile. This is what I get:

      SDCC -c --model-small -DSDCC main.c
      Internal error: validateLink failed in SPEC_ABSA(yyvsp[-2].lnk) @ SDCC.y:591: ex
      pected SPECIFIER, got DECLARATOR
      make: *** [main.rel] Error -1

      Don't know what went wrong.
      But is it possible in SDCC to declare a function pointer and then make it point to absolute address in code memory?

      I'm not very familiar with this kind of things, but as far as I understand __API_FLASH_ENTRY_POINT is void Fun(void) function in absolute 0xFFC0 address and somehow I should get my program to call that function?

       
    • Zappa

      Zappa - 2005-03-15

      I compiled this declaration with Keil demo compiler:

      #define __API_FLASH_ENTRY_POINT (*((const void(code*)(void))0xFFC0 ))

      void main (void)
      {
          __API_FLASH_ENTRY_POINT();
      }

      ...and I get this kind assembler output:

      NAME    TEST

      ?PR?main?TEST        SEGMENT CODE
          EXTRN    CODE (?C_STARTUP)
          PUBLIC    main
          RSEG  ?PR?main?TEST
      main:
          USING    0
      ;     __API_FLASH_ENTRY_POINT();
          LCALL    0FFC0H
      ?C0001:
          RET     
          END

      So for me it seems that I could use LCALL, but apparently I don't understand this well.

       
    • Maarten Brock

      Maarten Brock - 2005-03-15

      Ok, So i misread the braces I guess. And as you found out, this does not work either. Next thing I did check before sending, so this should work, although it's not ideal:

      typedef void (*fp)(void);    //define function pointer type

      void test(void)
      {
          const fp api = (fp)0xFFC0;
          api(); //and finally use it
      }

       
    • Zappa

      Zappa - 2005-03-15

      Yes, It compiles now right and it works fine on 89c51cc03 chip too. Thank you Maarten very much!

       
    • Frieder Ferlemann

      Isn't Zappa's original code valid c?

      Removing the (non ANSI) keyword "code", gcc would compile the following code without any hiccup:

      #define __API_FLASH_ENTRY_POINT (*((const void(*)(void)) 0xFFC0 ))

      int main()
      {
          __API_FLASH_ENTRY_POINT();
          return 0;
      }

       
    • Zappa

      Zappa - 2005-03-18

      Without "code" keyword sdcc still complains about call line:
      "error 27: Pointer required"

       
    • Maarten Brock

      Maarten Brock - 2005-03-20

      I'm afraid SDCC is not yet as compatible with the C-standard as gcc is. In this case I don't think that's such a big problem as the code was unreadable to begin with. Using function pointers clears things up. But it's too bad the generated code is not optimized at all.

       

Log in to post a comment.