/*-------------------------------------------------------------------------
  CPU Startup Code

   Written By - Dipl.-Ing. (FH) Michael Schmitt
   Update & Bug-Fix March 21 2000
    michael.schmitt@t-online.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!
-------------------------------------------------------------------------*/

// Note :
// The Makefile is not working properly with the make that comes along with
// cygwin
// If somebody finds out why and how to solve this. mail me and make us all happy

/*-------------------------------------------------------------------------

The idea behind this was to stop creating the body of a source project
every time i start a new software project.

i got bored of the same problem everytime with timmer settings for different
cpu speeds. so i started to set down a basic set of functions that are called
and handled the same way everytime i include them.

So the first thing that has to be defined is the type of the cpu.
With this Information, some functions may ba able to handle things different
depending of the target cpu
#define CPUTYPE AT89C55

After including the CPU specific definitions, i set the cpu-clock frequency
#define CPUCLKHZ                11059200
It is important that the value has a unit of Hz

With this value and the next define
#define BAUDRATE                9600

the necessary values for the baudrate timer are calculated. So, if you change 
the crystal you do not need to go through your code and replace all hardwired
settings. otherwise if you want a different baudrate just change the value and
re-compile it. That all. no more need to handle with timer reload values.

Now we define how we want to handle the serial port, there are two basic versons.
One is the polling method, the other one is interupt driven. (Thanks to Josef Wolf
for his interupt driven code, i have adapted it into this source). So the are two
defines, you have to choose one from.
#define SERIAL_VIA_INTERRUPT
#define SERIAL_VIA_POLLING
do not define both at the same time, i do not handle this at the moment

if you want to have an interupt driven serial port, we need two buffer. one for TX
and one for RX, both sizes can be set with the following defines
#define SERIAL_VIA_INTERRUPT_XBUFLEN 19
#define SERIAL_VIA_INTERRUPT_RBUFLEN 23
!! Important the buffers must be smaler than 128bytes !!!
!! This is a bit confusing me, in some cases it works with buffers up to 180 ??
!! This is a problem with SDCC V219Ga and V220 (21.March2000)
both buffers are located in the XRAM area

The next (and last define in the main module) enables the internal timer to give us
a 1msec interupt. this interupt increments a system variable that is use for a delay
function. during the delay, the cpu is set into IDLE mode to save power (Battery). it
is waked up every 1msec. if the desired times is not over, the cpu is put into
IDLE mode again.

And again, if you change the cpu speed, you do not need to modify any hardwired values,
as they are calculated from the defines.

inside the second file CPU_TOOLS.C and it's header file CPU_TOOLS.H, there are some more
defines. I have tried to cross check them, whenever i though about that.

One empty function is WatchDog(), that can be filled with live if needed. I call this 
function in source, even if there is no Watchdog in my system. Bus this keeps me
free for future projects, where i might use a watchdog. so do not come into the miss
that i am searching for the "bug" where the watchdog is not retriggert.

The functions init_hardware() looks a little bit strange with all those #ifdef's but 
i have tried to init the hardware in the right order and init those parts with the 
correct values. Also this looks a little bit more modular for me.

-------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------

So that is the first version of this code, feel free to use it and/or modify it
I will try to keep this up-to-date. Any comments are welcome, especialy improvements

-------------------------------------------------------------------------*/








