1 // Implementation of cprintf console output for user processes,
2 // based on printfmt() and the sys_cputs() system call.
4 // cprintf is a debugging statement, not a generic output statement.
5 // It is very important that it always go to the console, especially when
6 // debugging file descriptor code!
8 #include <ros/common.h>
12 // Collect up to BUF_SIZE characters into a buffer
13 // and perform ONE system call to print all of them,
14 // in order to make the lines output to the console atomic
15 // and prevent interrupts from causing context switches
16 // in the middle of a console output line and such.
18 typedef struct debugbuf {
19 size_t idx; // current buffer index
20 size_t cnt; // total bytes printed so far
21 uint8_t buf[BUF_SIZE];
25 static void putch(int ch, debugbuf_t **b)
27 (*b)->buf[(*b)->idx++] = ch;
28 if ((*b)->idx == BUF_SIZE) {
29 sys_cputs((*b)->buf, (*b)->idx);
35 int ros_vdebug(const char *fmt, va_list ap)
38 debugbuf_t *COUNT(1) bp = &b;
42 ros_vdebugfmt((void*)putch, (void*)&bp, fmt, ap);
43 sys_cputs(b.buf, b.idx);
48 int ros_debug(const char *fmt, ...)
54 cnt = ros_vdebug(fmt, ap);