Contiki 3.x
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
69
70
int
main
(
void
)
71
{
72
char
*ptr =
"Hello world!"
;
73
char
*np = 0;
74
int
i = 5;
75
unsigned
int
bs =
sizeof
(int)*8;
76
int
mi;
77
// char buf[80];
78
79
uart_init
(
UART1
, 115200);
80
81
print_size(int8_t);
82
print_size(uint8_t);
83
print_size(int16_t);
84
print_size(uint16_t);
85
print_size(int32_t);
86
print_size(uint32_t);
87
print_size(int64_t);
88
print_size(uint64_t);
89
90
mi = (1 << (bs-1)) + 1;
91
printf(
"%s\n"
, ptr);
92
printf(
"printf test\n"
);
93
printf(
"%s is null pointer\n"
, np);
94
printf(
"%d = 5\n"
, i);
95
printf(
"%d = - max int\n"
, mi);
96
printf(
"char %c = 'a'\n"
,
'a'
);
97
printf(
"hex %x = ff\n"
, 0xff);
98
printf(
"hex %02x = 00\n"
, 0);
99
printf(
"signed %d = unsigned %u = hex %x\n"
, -3, -3, -3);
100
printf(
"%d %s(s)"
, 0,
"message"
);
101
printf(
"\n"
);
102
printf(
"%d %s(s) with %%\n"
, 0,
"message"
);
103
104
printf(
"sqrt(5) * 100 = %d\n"
, (
int
) (sqrt(5)*100));
105
106
// sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
107
// sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
108
// sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
109
// sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
110
// sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
111
// sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
112
// sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
113
// sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
114
115
while
(1) {
continue
; }
116
}
117
118
/*
119
* this should display (on 32bit int machine) :
120
*
121
* Hello world!
122
* printf test
123
* (null) is null pointer
124
* 5 = 5
125
* -2147483647 = - max int
126
* char a = 'a'
127
* hex ff = ff
128
* hex 00 = 00
129
* signed -3 = unsigned 4294967293 = hex fffffffd
130
* 0 message(s)
131
* 0 message(s) with %
132
* justif: "left "
133
* justif: " right"
134
* 3: 0003 zero padded
135
* 3: 3 left justif.
136
* 3: 3 right justif.
137
* -3: -003 zero padded
138
* -3: -3 left justif.
139
* -3: -3 right justif.
140
*/
uart_init
void uart_init(const unsigned int uart_num, uint32_t module_clk_hz, const uint32_t baud)
Initialize UART.
Definition:
uart.c:154
main
int main(void)
This is main...
Definition:
ethconfig.c:49
UART1
#define UART1
Peripheral UART1 base pointer.
Definition:
MK60D10.h:8667
Generated on Sun Nov 30 2014 09:58:58 for Contiki 3.x by
1.8.5