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