![]()
This module contains a number of useful macro definitions and declarations.
These functions are not actually part of the ucore library, they are in fact located with the startup code in ctr0.s. The functions allow control of the uCore timer tick mechanism.
Enable the timer tick mechanism. Following a call to start_tick(), the user supplied function tick() will be called automatically by an interrupt service routine 32 times every second (ie every 31.25 mSec).
Disable the timer tick mechanism.
The following macros are specific to the µCore, they allow the use of the standard C printf notation to send data to a µTerm located at the default address. If you do not find this appropriate, simply undefine printf and redefine it to whatever best meets your requirements.
#define UT 0x04 // the default uterm address
#define printf(format,...) ut_printf(UT,format,##__VA_ARGS__)
|
Example: print "Hello World" on the default µTerm #include |
The specification of the scope of variables and functions in C is not as intuitive as it might be. To alleviate some of the difficult that this may cause you can use the above definitions of LOCAL and GLOBAL.
|
Appropriate use would be as follows: // to declare a globally accessible variable GLOBAL BYTE x; // to declare a variable only accessible from the current source file LOCAL BYTE y; // to declare a globally accessible function myfun GLOBAL void myfun(void); // to declare a function only accessible from the current source file LOCAL void myfun1(void); |
It is considered good programming practice to split your program up into a number of modules with only those parts necessary declared as global. Many programmers take this to the extreme by completely outlawing global data, forcing access through a small number of global functions.
Unfortunately C has quite a loose specification for the exact implementation of its standard data types. This can cause problems when porting code from one processor to another. Using the following definitions can help:
#define BYTE unsigned char // unsigned 8 bit value #define WORD unsigned int // unsigned 16 bit value #define LONG unsigned long // unsigned 32 bit value |
Note that some programmers do not like the use of macros to hide weaknesses in a programming language, we have found the above definitions useful, use them if you wish.
Home | Products | Technical Info | How to Order | Contact Us | Links