summaryrefslogtreecommitdiff
path: root/cesar/hal/arch/io.h
blob: be06d65647ff8017cbe4f5c22b3fe759fb3fbd31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef hal_arch_io_h
#define hal_arch_io_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/arch/io.h
 * \brief   Architecture dependent basic input output services.
 * \ingroup hal_arch
 *
 * The services in this file offer the added value that they should depend of
 * almost nothing in order to work, enabling use from debugger or fatal error
 * state.
 */

/**
 * Basic output, output a single char.
 * \param  c  the char to output
 *
 * \note Actually implemented as macro.
 */
void
arch_io_write_char (char c);

/**
 * Basic output, output a null terminated string.
 * \param  s  the string to output
 *
 * \note Actually implemented as macro.
 */
void
arch_io_write_string (const char *s);

/**
 * Basic output, output a text buffer.
 * \param  text  text buffer start address
 * \param  text_size  number of characters to output
 *
 * \note Actually implemented as macro.
 */
void
arch_io_write (const char *text, uint text_size);

#if defined (ECOS) && ECOS

#  include <cyg/infra/diag.h>

#  define arch_io_write_char diag_write_char

#  define arch_io_write_string diag_write_string

#  define arch_io_write(text, text_size) do { \
    const char *iter_ = (text); \
    const char *end_ = iter_ + (text_size); \
    for (; iter_ != end_; iter_++) \
    { \
        arch_io_write_char (*iter_); \
    } \
} while (0)

#else /* !(defined (ECOS) && ECOS) */

#  include <unistd.h>
#  include <string.h>

#  define arch_io_write_char(c) do { \
    char c_ = (c); \
    arch_io_write (&c_, 1); \
} while (0)

#  define arch_io_write_string(s) do { \
    const char *s_ = (s); \
    uint size_ = strlen (s_); \
    arch_io_write (s_, size_); \
} while (0)

#  define arch_io_write(text, text_size) do { \
    if (text_size) \
        write (1, (text), (text_size)); \
} while (0)

#endif /* !(defined (ECOS) && ECOS) */

#endif /* hal_arch_io_h */