Contiki 2.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cpu
mc1322x
tests
printf.c
1
/*
2
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
3
* to the MC1322x project (http://mc1322x.devl.org)
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of the Institute nor the names of its contributors
15
* may be used to endorse or promote products derived from this software
16
* without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
22
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
* SUCH DAMAGE.
29
*
30
* This file is part of libmc1322x: see http://mc1322x.devl.org
31
* for details.
32
*
33
*
34
*/
35
36
#include <mc1322x.h>
37
#include <
board.h
>
38
39
#include <stdio.h>
40
#include <math.h>
41
42
#include "tests.h"
43
#include "config.h"
44
45
#define print_size(x) do { \
46
printf("sizeof("); \
47
printf(#x); \
48
printf("): %d\n", sizeof(x)); \
49
} while(0)
50
51
#if (__linux__)
52
FILE *stderr;
53
54
void
__assert_fail(
void
) {
55
return
;
56
}
57
58
int
fputs(
const
char
*s, FILE *stream) {
59
return
0;
60
}
61
62
size_t
fwrite(
const
void
*ptr,
size_t
size,
size_t
nmemb,
63
FILE *stream) {
64
return
0;
65
}
66
#endif
67
68
int
main
(
void
)
69
{
70
char
*ptr =
"Hello world!"
;
71
char
*np = 0;
72
int
i = 5;
73
unsigned
int
bs =
sizeof
(int)*8;
74
int
mi;
75
// char buf[80];
76
77
uart_init(INC, MOD, SAMP);
78
79
print_size(int8_t);
80
print_size(uint8_t);
81
print_size(int16_t);
82
print_size(uint16_t);
83
print_size(int32_t);
84
print_size(uint32_t);
85
print_size(int64_t);
86
print_size(uint64_t);
87
88
mi = (1 << (bs-1)) + 1;
89
printf(
"%s\n"
, ptr);
90
printf(
"printf test\n"
);
91
printf(
"%s is null pointer\n"
, np);
92
printf(
"%d = 5\n"
, i);
93
printf(
"%d = - max int\n"
, mi);
94
printf(
"char %c = 'a'\n"
,
'a'
);
95
printf(
"hex %x = ff\n"
, 0xff);
96
printf(
"hex %02x = 00\n"
, 0);
97
printf(
"signed %d = unsigned %u = hex %x\n"
, -3, -3, -3);
98
printf(
"%d %s(s)"
, 0,
"message"
);
99
printf(
"\n"
);
100
printf(
"%d %s(s) with %%\n"
, 0,
"message"
);
101
102
printf(
"sqrt(5) * 100 = %d\n"
, (
int
) (sqrt(5)*100));
103
104
// sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
105
// sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
106
// sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
107
// sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
108
// sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
109
// sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
110
// sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
111
// sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
112
113
while
(1) {
continue
; }
114
}
115
116
/*
117
* this should display (on 32bit int machine) :
118
*
119
* Hello world!
120
* printf test
121
* (null) is null pointer
122
* 5 = 5
123
* -2147483647 = - max int
124
* char a = 'a'
125
* hex ff = ff
126
* hex 00 = 00
127
* signed -3 = unsigned 4294967293 = hex fffffffd
128
* 0 message(s)
129
* 0 message(s) with %
130
* justif: "left "
131
* justif: " right"
132
* 3: 0003 zero padded
133
* 3: 3 left justif.
134
* 3: 3 right justif.
135
* -3: -003 zero padded
136
* -3: -3 left justif.
137
* -3: -3 right justif.
138
*/
Generated on Fri Aug 30 2013 12:34:09 for Contiki 2.5 by
1.8.3.1