This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

eZ430-chronos developing questions

When I try to read the "main.c" file and "project.h" file of the firmware for the sports-watch project. There is a unit defined in "project.h" as:

typedef union
{
  struct
  {
    u16 prepare    : 1; // 1 = Wait for clock tick, then set display.flag.show_message flag
    u16 show    : 1; // 1 = Display message now
    u16 erase    : 1; // 1 = Erase message
    u16 type_locked   : 1; // 1 = Show "buttons are locked" in Line2
    u16 type_unlocked  : 1; // 1 = Show "buttons are unlocked" in Line2
    u16 type_lobatt   : 1; // 1 = Show "lobatt" text in Line2
    u16 type_alarm_on  : 1; // 1 = Show "  on" text in Line1
    u16 type_alarm_off  : 1; // 1 = Show " off" text in Line1
 } flag;
  u16 all_flags;            // Shortcut to all message flags (for reset)
} s_message_flags;

Here, the u16 type is not defined in this headfile and I can't easily find its definition in any other headfiles.

So, how is this typed defined?

 

  • U16 means unsigned 16 bit int. This type (often uint16, u_int_16 or similar) is defined since int and even short int have different meaning on different plattforms. I tmakes no sense on the MSP, since all MSPs have a 16 bit (short) int and the code is not portable anyway, so unsigned or unsigned int would do fine.

    Anyway, you should also include a file msp430xxx.h or similar, which holds all the register definitions and should also load compiler specific defines and target/arch specific defines. Inlcuding any aliases for unsigned int.

    Usually, these defines are found in types.h or inttypes.h

     

  • But where it is defined in the Chronos software. I was also looking many times. Spend couple of hours searching without success.

    When I create new project then u8 or u16 is not supported. So again: we know what that means. Show as where it is defined.

  • Grzegorz Latocha said:
    But where it is defined in the Chronos software. I was also looking many times. Spend couple of hours searching without success.

    It took me less than ten minutes (including download and installation of the sources) to locate it in the bm.h file in the bluerobin folder. project.h includes bm.h and bm.h defines these types.

    But I'm not surprised you didn't find it if you used the windows explorer search function.

    By default, this function searches for file content only if there is a content filter installed for a certain file type. All other files (including .c, .h and most others) are just skipped by the search.

    The search filter allows windows search (and the indexer) to find words which are scrambled e.g. inside word or pdf, but it just ignores everything that's not connected with a filter. And only a few file types are.

    There is a registry key to force the windows search to search into unknown (to the search/indexer) file types too:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex]
    "FilterFilesWithUnknownExtensions"=dword:00000001

  • I would never find it. So big thanks. Maybe I am not new to C language. But the complex preprocessor functions are sometimes new to me. Big thanks for posting it.

    I was searching using Unreal Commander (free Total Commander alternative). But I was looking for casting something like

    typedef unsigned char u8

    and similars. Now I can see that something totaly new for me is used there.

     

    One more time - big thanks

  • Grzegorz Latocha said:
    the complex preprocessor functions are sometimes new to me.

    The preprocessor functions are pretty much standardized. Yet it isn't easy to find a good documentation, since a google search will find a million times more sites where they are used rather than explained.

    Problem is that some compilers have additional features which are supported by the preprocessor. #pragma has different possible uses on different compilers, VisualC++ supports #message (something I really miss on GCC), others have their own extensions.

    What's causing most trouble is that only AFTER a preprocessor run, a normal human can see what's been really done. This includes the current search path (which include file was actually included? I have created an SPI.H, but the preprocessor included a supplementary (non-standard) SPI.H from the mspgcc branch instead etc.
    And then there are the multi-stage text replacements. For this, I also often have to look into the preprocessor docs. String concatenation, subtoken replacement etc. A real pain, but sometimes useful if you want things done at compiletime and not at runtime.

    In your case, the header contained

    typedef unsigned _CPU_8BIT_INT_ u8 ;

    where _CPU_8BIT_INT_ is simply replaced with char.

    Reason for this is modularity. Depending on the target system, an int may be 16 or 32 bit, maybe there are no 8 bit instructions and therefore no real 8 bit types at all etc.

    But I still do not understand why this has been done at all, since all notmal compiler distributions already address this by defining types like uint8_t and such. I wonder why they used their own definitions.
    It makes sense if you want type safety, so the compiler warns you if you mix types, even if they both resolve to a char. If the compiler does at all in this case :)

  • I can see you are familiar with the preprocessor. I will ask one more question which I couldn't find in any C documentation.

    How C preprocessor is using const values. If I declare

    #define MAX 15

    #define MIN 10

    and than i declare

    #define AV ((MAX+MIN)/2)

    will this math equation be calculated during preprocessing or simply inserted to the files and calculated in runtime?

     

    regards

**Attention** This is a public forum