Make rtio_log() accept variable number of arguments.

This commit is contained in:
whitequark 2016-02-14 23:12:39 +00:00
parent cd7f12e4b1
commit b9448c069a
3 changed files with 24 additions and 9 deletions

View File

@ -103,6 +103,7 @@ static const struct symbol runtime_exports[] = {
{"watchdog_clear", &watchdog_clear}, {"watchdog_clear", &watchdog_clear},
{"core_log", &core_log}, {"core_log", &core_log},
{"rtio_log", &rtio_log},
{"send_rpc", &send_rpc}, {"send_rpc", &send_rpc},
{"recv_rpc", &recv_rpc}, {"recv_rpc", &recv_rpc},

View File

@ -39,25 +39,28 @@ void rtio_process_exceptional_status(int status, long long int timestamp, int ch
} }
} }
void rtio_log(long long int timestamp, char *message) void rtio_log_va(long long int timestamp, const char *fmt, va_list args)
{ {
unsigned int word; // This executes on the kernel CPU's stack, which is specifically designed
int i; // for allocation of this kind of massive buffers.
int len = vsnprintf(NULL, 0, fmt, args);
char *buf = __builtin_alloca(len + 1);
vsnprintf(buf, len + 1, fmt, args);
rtio_chan_sel_write(CONFIG_RTIO_LOG_CHANNEL); rtio_chan_sel_write(CONFIG_RTIO_LOG_CHANNEL);
rtio_o_timestamp_write(timestamp); rtio_o_timestamp_write(timestamp);
i = 0; int i = 0;
word = 0; unsigned int word = 0;
while(1) { while(1) {
word <<= 8; word <<= 8;
word |= *message & 0xff; word |= *buf & 0xff;
if(*message == 0) { if(*buf == 0) {
rtio_o_data_write(word); rtio_o_data_write(word);
rtio_o_we_write(1); rtio_o_we_write(1);
break; break;
} }
message++; buf++;
i++; i++;
if(i == 4) { if(i == 4) {
rtio_o_data_write(word); rtio_o_data_write(word);
@ -67,3 +70,12 @@ void rtio_log(long long int timestamp, char *message)
} }
} }
} }
void rtio_log(long long int timestamp, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
rtio_log_va(timestamp, fmt, args);
va_end(args);
}

View File

@ -1,6 +1,7 @@
#ifndef __RTIO_H #ifndef __RTIO_H
#define __RTIO_H #define __RTIO_H
#include <stdarg.h>
#include <generated/csr.h> #include <generated/csr.h>
#include "artiq_personality.h" #include "artiq_personality.h"
@ -14,7 +15,8 @@
void rtio_init(void); void rtio_init(void);
long long int rtio_get_counter(void); long long int rtio_get_counter(void);
void rtio_process_exceptional_status(int status, long long int timestamp, int channel); void rtio_process_exceptional_status(int status, long long int timestamp, int channel);
void rtio_log(long long int timestamp, char *message); void rtio_log(long long int timestamp, const char *format, ...);
void rtio_log_va(long long int timestamp, const char *format, va_list args);
static inline void rtio_write_and_process_status(long long int timestamp, int channel) static inline void rtio_write_and_process_status(long long int timestamp, int channel)
{ {