BoostC Forum Extracts 2007

From OpenCircuits
Jump to navigation Jump to search

Almost Ready For Reading

A macro like MAKESHORT can initialize a variable but the compiler does not know that and generates a warning. Is there a way to solve this without initializing the variable explicitly?


    u16_t timestamp;

    t1con.TMR1ON = 0; // stop timer
    MAKESHORT(timestamp, tmr1l, tmr1h);

    en_of_pulse = timestamp; <<==== causes warning

It's not the macro that's the problem, but the inline assembly it uses. The compiler doesn't notice if you set a variable with inline assembly statements and warns that it's possibly uninitialized. Declaring the variable as 'volatile' gets rid of the warning, but isn't a great solution as you might miss a true 'uninitialized' case.

I am not an expert, but I think I have seen compilers that have pragma's that give hints to compiler about these things.


Problem initializing struct. Whah, this doesn't work!

typedef struct {
    char foo[11];
    bar_enum bar;
} baz_list;

baz_list baz[] = { "0123456789", quux,
                   "0123456789", quuux,
                   "0123456789", quuuux
                 };


I can create a two dimensional array of strings and initialize them or a array of enums and initialize them but not an array of structs.

A more premitive question to ask would be why:

CODE
struct thing {
  char ch_1;
  char ch_2;
};
 
struct thing thingy = {2,2};

doesn't work.

I can't find the thread I'm thinking of but I believe you're going to have to assign the values yourself. I'd say use an inline function or something to make it look neater:

struct thing {
  char ch_1;
  char ch_2;
};

inline void set_thing( struct thing &i_thing, 
                       unsigned char ch_1, 
                       unsigned char ch_2 ) {
  i_thing.ch_1 = ch_1;
  i_thing.ch_2 = ch_2;
}

void main( void ){
  struct thing i_thing[3];
  set_thing( i_thing[0], 2, 3 );
  set_thing( i_thing[1], 5, 3 );
  set_thing( i_thing[2], 1, 9 );

Found the thread - http://forum.sourceboost.com/index.php?showtopic=3404


break this into 3

    • Question 1:

Function prototypes, It looks like they are allowed, but not required nor enforced?

Prototypes are required if you do a forward reference to a function. If you are in the habit of using them, then always use them. I do.

    • Question 2:

If I call

 delay_ms(1000 ); 

I get no warnings.

Is there a way to make it more strict?

If you go to Settings - Options and enable All warnings the compiler will warn you if you exceed 255 for a delay.

    • Question 3:

Interrupts; If I don't put the interrupt function in my code, is there a default handler?

There is no default interrupt handler that I can see. Keep GIE = 0 if you don't want you program to go into the woods.



    • Question 4:

Global variables vs volatile; If I declare a variable in a header file, and wish to use it in both a main thread function and an interrupt handler, do I really need to declare it volatile?

If I was sharing a variable with main and interrupt, I would probably make it volatile. It all depends on how your main code is written and how many times the variable is used in main. The compiler may retain the variable value between uses and the interrupt may change its value between uses. You could always devise a semaphore type system.




I had some code that suddenly got bigger and slower and all I'd done was change the size of an array, though no variables ended up placed anywhere but bank 0. ...

read the post for some info an location of variables in memory, bank switching ..... size and speed.


Boostc gives me the warning Caution: Delay inaccurrate: 'delay_us', Delay overhead:0.01ms, Unit delay:0.001ms

How do I interpret the overhead and unit delay....?

delay_us( 1 ) gives 0.01ms + (1 * 0.001ms) = 11us delay_us(12) gives 0.01ms + (12 * 0.001ms) = 22us delay_us(13) gives 0.01ms + (13 * 0.001ms) = 23us

delay_us(0) results in 0.01ms + (255 * 0.001ms) = 265us



notes that I am not able to summarize about structs union and access of sub-components.






Best Method For Accumulated Timer -- go read it



http://forum.sourceboost.com/index.php?showtopic=3408&pid=12790&mode=threaded&start=#entry12790

go read it

may be useful for lcd read and other ? Here is my basic template when working with the 684 chip.


more

It may be of some help to you......

 LCD_684.txt ( 4.03K ) Number of downloads: 41