1 | /* |
---|
2 | * Copyright (c) 2015 University of York. |
---|
3 | * Hesham ALMatary <hmka501@york.ac.uk> |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
8 | * 1. Redistributions of source code must retain the above copyright |
---|
9 | * notice, this list of conditions and the following disclaimer. |
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer in the |
---|
12 | * documentation and/or other materials provided with the distribution. |
---|
13 | * |
---|
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
24 | * SUCH DAMAGE. |
---|
25 | */ |
---|
26 | |
---|
27 | #include <bsp.h> |
---|
28 | #include <bsp/console-polled.h> |
---|
29 | #include <rtems/libio.h> |
---|
30 | #include <stdlib.h> |
---|
31 | #include <assert.h> |
---|
32 | #include <stdio.h> |
---|
33 | |
---|
34 | static void outbyte_console( char ); |
---|
35 | static char inbyte_console( void ); |
---|
36 | |
---|
37 | void console_initialize_hardware(void) |
---|
38 | { |
---|
39 | /* Do nothing */ |
---|
40 | } |
---|
41 | |
---|
42 | /* Epiphany simulator would handle this system call */ |
---|
43 | static void outbyte_console(char c) |
---|
44 | { |
---|
45 | register int chan asm("r0") = STDOUT_FILENO; |
---|
46 | register void* addr asm("r1") = &c; |
---|
47 | register int len asm("r2") = 1; |
---|
48 | |
---|
49 | /* Invoke write system call to be handled by Epiphany simulator */ |
---|
50 | __asm__ __volatile__ ("trap 0" : : "r" (chan), "r" (addr), "r" (len)); |
---|
51 | } |
---|
52 | |
---|
53 | static char inbyte_console(void) |
---|
54 | { |
---|
55 | char c; |
---|
56 | register int chan asm("r0") = STDIN_FILENO; |
---|
57 | register void* addr asm("r1") = &c; |
---|
58 | register int len asm("r2") = 1; |
---|
59 | |
---|
60 | /* Invoke read system call to be handled by Epiphany simulator */ |
---|
61 | asm ("trap 1" :: "r" (chan), "r" (addr), "r" (len)); |
---|
62 | return c; |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * console_outbyte_polled |
---|
67 | * |
---|
68 | * This routine transmits a character using polling. |
---|
69 | */ |
---|
70 | void console_outbyte_polled( |
---|
71 | int port, |
---|
72 | char ch |
---|
73 | ) |
---|
74 | { |
---|
75 | outbyte_console( ch ); |
---|
76 | } |
---|
77 | |
---|
78 | /* |
---|
79 | * console_inbyte_nonblocking |
---|
80 | * |
---|
81 | * This routine polls for a character. |
---|
82 | */ |
---|
83 | |
---|
84 | int console_inbyte_nonblocking(int port) |
---|
85 | { |
---|
86 | char c; |
---|
87 | |
---|
88 | c = inbyte_console(); |
---|
89 | if (!c) |
---|
90 | return -1; |
---|
91 | return (int) c; |
---|
92 | } |
---|
93 | |
---|
94 | /* |
---|
95 | * To support printk |
---|
96 | */ |
---|
97 | |
---|
98 | #include <rtems/bspIo.h> |
---|
99 | |
---|
100 | static void Epiphany_output_char(char c) { console_outbyte_polled( 0, c ); } |
---|
101 | |
---|
102 | BSP_output_char_function_type BSP_output_char = Epiphany_output_char; |
---|
103 | BSP_polling_getchar_function_type BSP_poll_char = |
---|
104 | (void *)console_inbyte_nonblocking; |
---|