1 /*
2 * Copyright (C) 2022 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
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 * 3. Neither the name of the copyright holders nor the names of
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
21 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32 /*
33 * retarget_chibios.c
34 *
35 * retarget printf and friends for ChibiOS/HAL
36 */
37
38 #define BTSTACK_FILE__ "hal_uart_dma_chibios.c"
39
40 #include "btstack_config.h"
41 #include "btstack_debug.h"
42 #include "btstack_util.h"
43
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <errno.h>
47
48 // retarget printf and friends
49
50 #ifndef ENABLE_SEGGER_RTT
51
52 #include "hal.h"
53
54 /**
55 * Use USART_CONSOLE as a console.
56 * This is a syscall for newlib
57 * @param file
58 * @param ptr
59 * @param len
60 * @return
61 */
62
63 int _write(int file, char *ptr, int len);
_write(int file,char * ptr,int len)64 int _write(int file, char *ptr, int len){
65 UNUSED(file);
66 #ifdef HAL_DEBUG_SERIAL
67 sdWrite(&HAL_DEBUG_SERIAL, (const uint8_t *) ptr, len);
68 #endif
69 errno = EIO;
70 return -1;
71 }
72 #endif
73
_read(int file,char * ptr,int len)74 int _read(int file, char * ptr, int len){
75 UNUSED(file);
76 UNUSED(ptr);
77 UNUSED(len);
78 return -1;
79 }
80
_lseek(int file)81 int _lseek(int file){
82 UNUSED(file);
83 return -1;
84 }
85
_close(int file)86 int _close(int file){
87 UNUSED(file);
88 return -1;
89 }
90
_isatty(int file)91 int _isatty(int file){
92 UNUSED(file);
93 return -1;
94 }
95
_fstat(int file)96 int _fstat(int file){
97 UNUSED(file);
98 return -1;
99 }
100
_exit(int err)101 void _exit(int err){
102 UNUSED(err);
103 while(1);
104 }
105
_kill(int pid)106 int _kill(int pid){
107 UNUSED(pid);
108 return -1;
109 }
110
_getpid(void)111 int _getpid(void){
112 return -1;
113 }
114
_sbrk(intptr_t increment)115 void * _sbrk(intptr_t increment){
116 UNUSED(increment);
117 // btstack_assert(false);
118 return (void*) -1;
119 }
120