c27837b63eed3c446571321bd9e694be1e99f509
[fw/sdcc] / device / include / tinibios.h
1 #ifndef TINIBIOS_H
2
3 #define TINIBIOS_H
4
5 #include <ds80c390.h>
6 #include <time.h>
7
8 #define Serial0GetChar getchar
9 #define Serial0PutChar putchar
10
11 void Serial0Init (unsigned long baud, unsigned char buffered);
12 char Serial0GetChar(void);
13 void Serial0PutChar(char);
14 char Serial0CharArrived(void);
15 void Serial0Baud(unsigned long baud);
16 void Serial0SendBreak(void);
17 void Serial0Flush(void);
18
19 void Serial0SwitchToBuffered(void); // ds400 only.
20
21 void Serial1Init (unsigned long baud, unsigned char buffered);
22 char Serial1GetChar(void);
23 void Serial1PutChar(char);
24 char Serial1CharArrived(void);
25 void Serial1Baud(unsigned long baud);
26 void Serial1SendBreak(void);
27 void Serial1Flush(void);
28
29 unsigned long ClockTicks();
30 void ClockMilliSecondsDelay(unsigned long ms);
31 void ClockMicroSecondsDelay(unsigned int us);
32
33 #define SERIAL_0_BAUD 115200L
34 #define SERIAL_1_BAUD 9600L
35
36 // these need to be binary numbers
37 #define SERIAL_0_RECEIVE_BUFFER_SIZE 1024
38 #define SERIAL_1_RECEIVE_BUFFER_SIZE 64
39
40 // I know someone is fooling with the crystals
41 #if defined(SDCC_ds400)
42 # define OSCILLATOR 14745600L
43 #else
44 # define OSCILLATOR 18432000L
45 #endif
46
47 /* Set the cpu speed in clocks per machine cycle, valid values are:
48    1024: Divide-by-1024 (power management) mode (screws ALL timers and serial)
49       4: Standard 8051 divide-by-4 mode
50       2: Use 2x xtal multiplier 
51       1: Use 4x xtal multiplier (Don't do this with a TINI at 18.432MHz)
52 */
53 #define CPU_SPEED 2
54 void CpuSpeed(unsigned int speed);
55
56 // The MOVX stretch cycles, see datasheet
57 #define CPU_MOVX_STRETCH 0x01
58
59 // from rtc390.c
60 #define HAVE_RTC
61 unsigned char RtcRead(struct tm *rtcDate);
62 void RtcWrite(struct tm *rtcDate);
63
64 // from lcd390.c
65 extern void LcdInit(void);
66 extern void LcdOn(void);
67 extern void LcdOff(void);
68 extern void LcdClear(void);
69 extern void LcdHome(void);
70 extern void LcdGoto(unsigned int collumnRow);
71 extern void LcdPutChar(char c);
72 extern void LcdPutString(char *string);
73 extern void LcdLPutString(unsigned int collumnRow, char *string);
74 extern void LcdPrintf(const char *format, ...) reentrant;
75 extern void LcdLPrintf(unsigned int collumnRow, const char *format, ...) reentrant;
76
77 // from i2c390.c
78 #define I2C_BUFSIZE 128
79 extern char I2CReset(void);
80 extern char I2CStart(void);
81 extern char I2CStop(void);
82 extern char I2CSendStop(char addr, char count, 
83                         char send_stop);
84 extern char I2CReceive(char addr, char count);
85 extern char I2CSendReceive(char addr, char tx_count, 
86                            char rx_count);
87 //extern char I2CByteOut(char);
88 //extern void I2CDumpError(char);
89
90 /* global transfer buffers */
91 extern char i2cTransmitBuffer[I2C_BUFSIZE];
92 extern char i2cReceiveBuffer[I2C_BUFSIZE];
93
94 // Macro for normal send transfer ending with a stop condition
95 #define I2CSend(addr, count)   I2CSendStop(addr, count, 1)
96
97
98 // internal functions used by tinibios.c
99 unsigned char _sdcc_external_startup(void);
100 void Serial0IrqHandler (void) interrupt 4;
101 void Serial1IrqHandler (void) interrupt 7;
102
103 #if !defined(SDCC_ds400)
104 void ClockInit();
105 void ClockIrqHandler (void) interrupt 1 _naked;
106 #endif
107
108 #if defined(SDCC_ds400)
109 // functions for dealing with the ds400 ROM firmware.
110
111 // A wrapper which calls rom_init allocating all available RAM in CE0
112 // to the heap, sets the serial port to SERIAL_0_BAUD, sets up the 
113 // millisecond timer, and diddles the clock multiplier.
114
115 // Values for the romInit "speed" parameter.
116 #define SPEED_1X        0 /* no clock multiplier, normal speed. */
117 #define SPEED_2X        1 /* 2x clock multiplier. */
118 #define SPEED_4X        2 /* 4x clock, DOESN'T WORK ON TINIm400! */
119
120 unsigned char romInit(unsigned char noisy,
121                       char speed);
122
123 // Install an interrupt handler.
124 void installInterrupt(void (*isrPtr)(void), unsigned char offset);
125 #endif
126
127
128 #endif /* TINIBIOS_H */