1
0
Fork 0
forked from len0rd/rockbox
foxbox/firmware/drivers/serial.c
Vencislav Atanasov 8e293b4948 serial: Add serial_tx_raw() function for sending raw bytes to the serial port
serial_tx() can only be used for NULL-terminated strings, and also adds CR before every LF.

Change-Id: I8c3eafa5bc152bb54abf4629ee76396dc1cb9b8c
2025-01-20 08:17:48 -05:00

62 lines
No EOL
1.7 KiB
C

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr & Nick Robinson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "serial.h"
void dprintf(const char * str, ... )
{
char dprintfbuff[256];
char * ptr;
va_list ap;
va_start(ap, str);
ptr = dprintfbuff;
vsnprintf(ptr,sizeof(dprintfbuff),str,ap);
va_end(ap);
serial_tx((unsigned char *)ptr);
}
void serial_tx(const unsigned char * buf)
{
/*Tx*/
for(;;) {
if(tx_rdy()) {
if(*buf == '\0')
return;
if(*buf == '\n')
tx_writec('\r');
tx_writec(*buf);
buf++;
}
}
}
void serial_tx_raw(const unsigned char * buf, int len)
{
for (int i = 0; i < len; i++) {
while (!tx_rdy());
tx_writec(buf[i]);
}
}