Contiki 3.x
Retarget.c
1 /**
2  * Copyright (c) 2014, Analog Devices, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted (subject to the limitations in the
6  * disclaimer below) provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - 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
14  * distribution.
15  *
16  * - Neither the name of Analog Devices, Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
21  * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 /**
35  Module : retarget.c
36  Description :
37  Date : December 2012
38  Version : v2.00
39  Changelog : v1.00 Initial
40  v2.00 use of UrtLib functions
41 */
42 
43 #include <stdio.h>
44 #include <rt_misc.h>
45 #include <include.h>
46 
47 #pragma import(__use_no_semihosting_swi)
48 
49  #define CR 0x0D
50 struct __FILE { int handle; /* Add whatever you need here */ };
51 FILE __stdout;
52 FILE __stdin;
53 
54 
55 // Re-targetting the Realview library functions
56 /*
57  * writes the character specified by c (converted to an unsigned char) to
58  * the output stream pointed to by stream, at the position indicated by the
59  * asociated file position indicator (if defined), and advances the
60  * indicator appropriately. If the file position indicator is not defined,
61  * the character is appended to the output stream.
62  * Returns: the character written. If a write error occurs, the error
63  * indicator is set and fputc returns EOF.
64  */
65 int fputc(int ch, FILE * stream )
66 {
67  if(ch == '\n')
68  while(!(COMLSR_THRE==(UrtLinSta(0) & COMLSR_THRE)));
69  UrtTx(0, CR); /* output CR */
70  while(!(COMLSR_THRE==(UrtLinSta(0) & COMLSR_THRE)));
71  UrtTx(0, ch);
72  return(ch);
73 }
74 
75 int __backspace(FILE *stream)
76 {
77  return 0x0;
78 
79 }
80 /*
81  * obtains the next character (if present) as an unsigned char converted to
82  * an int, from the input stream pointed to by stream, and advances the
83  * associated file position indicator (if defined).
84  * Returns: the next character from the input stream pointed to by stream.
85  * If the stream is at end-of-file, the end-of-file indicator is
86  * set and fgetc returns EOF. If a read error occurs, the error
87  * indicator is set and fgetc returns EOF.
88  */
89 int fgetc(FILE * stream)
90 {
91  return (UrtRx(0));
92 }
93 
94 
95 int ferror(FILE *f) {
96  /* Your implementation of ferror */
97  return EOF;
98 }
99 
100 
101 void _ttywrch(int ch) { UrtTx(0, ch); }
102 
103 
104 void _sys_exit(int return_code) {
105 label: goto label; /* endless loop */
106 }