source: trunk/libs/newlib/src/libgloss/rl78/write.c @ 555

Last change on this file since 555 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.9 KB
RevLine 
[444]1/*
2
3Copyright (c) 2010 Red Hat Incorporated.
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9    Redistributions of source code must retain the above copyright
10    notice, this list of conditions and the following disclaimer.
11
12    Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15
16    The name of Red Hat Incorporated may not be used to endorse
17    or promote products derived from this software without specific
18    prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31*/
32
33/* These definitions are for the RL78/G13, which the simulator
34   simulates.  */
35
36typedef unsigned char UQI __attribute__((mode(QI)));
37typedef unsigned int UHI __attribute__((mode(HI)));
38
39#define s8(x)   (*(volatile UQI *)(x))
40#define s16(x)  (*(volatile UHI *)(x))
41
42#define P(x)    s8(0xfff00+(x))
43#define PM(x)   s8(0xfff20+(x))
44
45#define PER0    s8(0xf00f0)
46
47#define SSR00   s16(0xf0100)
48#define SMR00   s16(0xf0110)
49#define SCR00   s16(0xf0118)
50#define SS0     s16(0xf0122)
51#define SPS0    s16(0xf0126)
52#define SO0     s16(0xf0128)
53#define SOE0    s16(0xf012a)
54#define SOL0    s16(0xf0134)
55
56#define SDR00   s16(0xfff10)
57
58static int initted = 0;
59
60static void
61init_uart0 ()
62{
63  initted = 1;
64
65  PER0 = 0xff;
66  SPS0 = 0x0011; /* 16 MHz */
67  SMR00 = 0x0022; /* uart mode */
68  SCR00 = 0x8097; /* 8-N-1 */
69  SDR00 = 0x8a00; /* baud in MSB - 115200 */
70  SOL0 = 0x0000; /* not inverted */
71  SO0 = 0x000f; /* initial value */
72  SOE0 = 0x0001; /* enable TxD0 */
73  P(1)  |= 0b00000100;
74  PM(1) &= 0b11111011;
75  SS0 = 0x0001;
76}
77
78static void
79tputc (char c)
80{
81  /* Wait for transmit buffer to be empty.  */
82  while (SSR00 & 0x0020)
83    asm("");
84  /* Transmit that byte.  */
85  SDR00 = c;
86}
87
88/* defaults to 0 unless open() is linked in */
89int _open_present;
90
91int
92_write(int fd, char *ptr, int len)
93{
94  int rv = len;
95
96  if (_open_present && fd > 2)
97    return _SYS_write (fd, ptr, len);
98
99  if (!initted)
100    init_uart0 ();
101
102  while (len != 0)
103    {
104      tputc (*ptr);
105      ptr ++;
106      len --;
107    }
108  return rv;
109}
110
111char * write (int) __attribute__((weak, alias ("_write")));
Note: See TracBrowser for help on using the repository browser.