Hello Josh,
I found a number of minor problems with the code that prevented proper compilation.
- The macro for clearing the COP timer is usually specified as __RESET_WATCHDOG() rather than __RESET_WATCHDOG.
- The macro definitions within the header file, for constants N1 and N2, have errors - some brace characters {} had crept in, in place of the required parenthesis (). With some fonts, these are difficult to distinguish from each other.
- One of the functions was missing a closing parenthesis for the return statement.
Once these problems were fixed, I had no difficulty in compiling the code.
Lundin:
I presume that you are referring to the function:
void delay( int val)
{
for ( ; val; val--);
}
This function did not actually appear within the attached file, so was not the source of the compiling problem.
With respect to your intimation that the CodeWarrior complier may be free to ignore the programmer's wish to create a simple function, I find very hard to believe. In fact, we know this is not the case for the function in question. The reference guide "HCS08 Unleashed", by Fabio Pereira, does make use to this function in many of the tested examples, and I have never had a problem with CW generating the appropriate code.
I do not know what you specifically mean bt a "side effect", but might have thought that the used of the parameter within a for loop, empty or otherwise, would represent use of the parameter, certainly sufficient to prevent a compiler warning message about an unused parameter.
In terms of the need to declare a function parameter as "volatile", this is not a topic that I have ever seen covered by a general C text reference. Perhaps you may be able to enlighten. Maybe it is a C++ thing.
Juls,
I think that creating a timer interrupt at 1us or 10us intervals would be a bad idea. With a maximum bus frequency of 10MHz, the number of bus cycles between interrupts would be 10 or 100 cycles maximum. Since the minimum overhead for an ISR entry and exit will be about 25 cycles (not including the ISR code), this will give insufficient time to process the ISR, and do any other useful work. I would suggest that the periodic tick interval should be 100us absolute minimum - >= 1ms would be better.
Regards,
Mac