home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
SIMTEL
/
HITECH-C
/
MOTOROLA.EXE
/
FEAT68K.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-21
|
4KB
|
143 lines
#include <intrpt.h>
/*
* This source file demonstrates some of the special features
* of the HI-TECH 68000 C Cross Compiler. This program should be
* compiled with 68000 code generation selected.
*
* To generate the best possible code for this program, select
* "68000 Code" from the options menu and "Full Optimization" from
* the optimization menu.
*
* HI-TECH C has a number of features designed to make programming
* embedded processors simpler and more efficient, these include:
*
* interrupt functions: interrupt handlers may be written entirely
* in C (no messy assembler code required).
*
* absolute variables: variables of any type (even complex
* structures and arrays) can be placed at
* any absolute address in memory - great
* for handling memory mapped devices.
*
* in-line assembler: assembler code can be place in line. This
* is useful for accessing special instructions.
*/
#ifndef m68k
#error This code should be compiled with 68000 code generation selected.
#endif
volatile unsigned char PIA_STATUS @ 0xC0000000; /* mem mapped PIA */
volatile unsigned char PIA_BUFFER @ 0xC0000001; /* at C0000000 */
unsigned char rxbuf[256]; /* 256 byte circular buffer */
near unsigned char ri_ptr, ro_ptr; /* head, tail pointers */
volatile struct {
unsigned char baud; /* baud rate register */
unsigned char sccr1; /* control reg 1 */
unsigned char sccr2; /* control reg 2 */
unsigned char scsr; /* status register */
unsigned char scdr; /* data register */
} SCC @ 0xC0000100;
/*
* rx_intr handles receive interrupts from the on board serial port
*
* Note the efficiency of the code generated for this function. With
* HI-TECH C there is no need to revert to assembly language coding
* for interrupt handlers.
*/
interrupt void
rx_intr(void)
{
rxbuf[ri_ptr++] = SCC.scdr;
if (ro_ptr == ri_ptr) /* buffer overflow ? */
--ri_ptr;
}
/*
* serial_char_avail: returns 1 if a char is available, 0 otherwise
*/
unsigned char
serial_char_avail(void)
{
return (ri_ptr != ro_ptr);
}
/*
* serial_get_char: returns one char from the tail of the circular
* buffer. Assumes that a char is available.
*/
unsigned char
serial_get_char(void)
{
unsigned char ch;
di();
ch = rxbuf[ro_ptr++];
ei();
return ch;
}
/*
* Transmit a character via the memory mapped PIA
* bit 0 of STATUS register indicates it is ready to accept data
*/
void
pia_send(unsigned char ch)
{
while (!(PIA_STATUS & 1))
continue;
PIA_BUFFER = ch;
}
/*
* Initialize the serial port and PIA
*
* Notes on code generated:
*
* 1. Note the quality of the I/O port manipulation code
* generated by the compiler for the serial port
* and PIA initialization sequence below.
*
* 2. The serial port initialization code below is "real"
* and was taken from the source code for the 68HC11
* "Lucifer" monitor.
*/
#define BAUD_VAL 0x30
void
device_inits(void)
{
unsigned char i;
di();
/* setup interrupt vector here */
SCC.baud = BAUD_VAL;
SCC.sccr1 = 0;
SCC.sccr2 = 0x0C; /* rx and tx enable */
i = SCC.scsr; /* read status register */
i = SCC.scdr; /* read data register */
PIA_STATUS = 0x80; /* reset PIA */
PIA_STATUS = 0x40; /* mode 2: bidirectional, ints off */
ri_ptr = ro_ptr = 0;
ei();
}
main()
{
device_inits();
for (;;) {
if (serial_char_avail())
pia_send(serial_get_char());
/* other processing */
}
}