Pond Electronics - Home of the µFlash876 & µFlash876B embedded controllers, µStack & µConnect Bus.

ucdefs Module

This module contains a number of useful macro definitions and declarations.

Declaration of startup functions

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.

void start_tick(void);

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).

void stop_tick(void);

Disable the timer tick mechanism.

µCore printf macros

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 

void main(void)
    {
    printf("Hello World\n");                         
    }

Macros for specification of C scope

#define LOCAL static
#define GLOBAL

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.

Macros for specification of C data types

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