|
| 1 | +/*------------------------------------------------------------- |
| 2 | +
|
| 3 | +sys_report.c -- Support for printing to Dolphin debug UART |
| 4 | +
|
| 5 | +Copyright (C) 2023 |
| 6 | +Dave Murphy (WinterMute) <[email protected]> |
| 7 | +
|
| 8 | +This software is provided 'as-is', without any express or implied |
| 9 | +warranty. In no event will the authors be held liable for any |
| 10 | +damages arising from the use of this software. |
| 11 | +
|
| 12 | +Permission is granted to anyone to use this software for any |
| 13 | +purpose, including commercial applications, and to alter it and |
| 14 | +redistribute it freely, subject to the following restrictions: |
| 15 | +
|
| 16 | +1. The origin of this software must not be misrepresented; you |
| 17 | +must not claim that you wrote the original software. If you use |
| 18 | +this software in a product, an acknowledgment in the product |
| 19 | +documentation would be appreciated but is not required. |
| 20 | +
|
| 21 | +2. Altered source versions must be plainly marked as such, and |
| 22 | +must not be misrepresented as being the original software. |
| 23 | +
|
| 24 | +3. This notice may not be removed or altered from any source |
| 25 | +distribution. |
| 26 | +
|
| 27 | +-------------------------------------------------------------*/ |
| 28 | + |
| 29 | +#include <sys/iosupport.h> |
| 30 | +#include <stdio.h> |
| 31 | +#include <stdarg.h> |
| 32 | + |
| 33 | +#include "exi.h" |
| 34 | + |
| 35 | +static ssize_t __uart_write(const char *buffer,size_t len) |
| 36 | +{ |
| 37 | + u32 cmd,ret; |
| 38 | + |
| 39 | + if(EXI_Lock(EXI_CHANNEL_0,EXI_DEVICE_1,NULL)==0) return 0; |
| 40 | + if(EXI_Select(EXI_CHANNEL_0,EXI_DEVICE_1,EXI_SPEED8MHZ)==0) { |
| 41 | + EXI_Unlock(EXI_CHANNEL_0); |
| 42 | + return len; |
| 43 | + } |
| 44 | + |
| 45 | + ret = 0; |
| 46 | + cmd = 0xa0010000; |
| 47 | + if(EXI_Imm(EXI_CHANNEL_0,&cmd,4,EXI_WRITE,NULL)==0) ret |= 0x01; |
| 48 | + if(EXI_Sync(EXI_CHANNEL_0)==0) ret |= 0x02; |
| 49 | + if(EXI_ImmEx(EXI_CHANNEL_0,(void *)buffer,len,EXI_WRITE)==0) ret |= 0x04; |
| 50 | + if(EXI_Deselect(EXI_CHANNEL_0)==0) ret |= 0x08; |
| 51 | + if(EXI_Unlock(EXI_CHANNEL_0)==0) ret |= 0x10; |
| 52 | + |
| 53 | + return len; |
| 54 | +} |
| 55 | + |
| 56 | +static ssize_t __uart_stdio_write(struct _reent *r, void *fd, const char *ptr, size_t len) |
| 57 | +{ |
| 58 | + __uart_write(ptr,len); |
| 59 | + return len; |
| 60 | +} |
| 61 | +static const devoptab_t dotab_uart = { |
| 62 | + .name = "uart", |
| 63 | + .write_r = __uart_stdio_write, |
| 64 | +}; |
| 65 | + |
| 66 | +void SYS_STDIO_Report(bool use_stdout) |
| 67 | +{ |
| 68 | + fflush(stderr); |
| 69 | + devoptab_list[STD_ERR] = &dotab_uart; |
| 70 | + setvbuf(stderr, NULL, _IONBF, 0); |
| 71 | + if(use_stdout) |
| 72 | + { |
| 73 | + fflush(stdout); |
| 74 | + devoptab_list[STD_OUT] = &dotab_uart; |
| 75 | + setvbuf(stdout, NULL, _IONBF, 0); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +static char __outstr[256]; |
| 80 | + |
| 81 | +void SYS_Report (char const *const fmt_, ...) |
| 82 | +{ |
| 83 | + |
| 84 | + int len; |
| 85 | + |
| 86 | + va_list args; |
| 87 | + |
| 88 | + va_start(args, fmt_); |
| 89 | + len=vsnprintf(__outstr,256,fmt_,args); |
| 90 | + va_end(args); |
| 91 | + |
| 92 | + __uart_write(__outstr, len); |
| 93 | + |
| 94 | +} |
| 95 | + |
0 commit comments