Skip to content

Commit 4f5f62f

Browse files
committed
Add ISR print functions PrintFromISR() and VPrintFromISR()
The functions PrintFromISR() and VPrintFromISR() perform formatted output from ISRs. Don't use them outside of an ISR. The functions do not synchronize with the output of the regular print functions of any task.
1 parent 762a5b7 commit 4f5f62f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/FormattedIO.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,47 @@ VPrint(const char* fmt, va_list ap)
6464
}
6565
return PrintIPC(res, buf);
6666
}
67+
68+
int
69+
_Print(const char* fmt, ...)
70+
{
71+
va_list ap;
72+
73+
va_start(ap, fmt);
74+
int res = _VPrint(fmt, ap);
75+
va_end(ap);
76+
77+
return res;
78+
}
79+
80+
int
81+
_VPrint(const char* fmt, va_list ap)
82+
{
83+
char buf[128];
84+
int res = vsnprintf(buf, sizeof(buf), fmt, ap);
85+
if (res < 0) {
86+
return -1;
87+
}
88+
SerialPutString(res, buf);
89+
return res;
90+
}
91+
92+
int
93+
PrintFromISR(const char* fmt, ...)
94+
{
95+
va_list ap;
96+
97+
va_start(ap, fmt);
98+
int res = VPrintFromISR(fmt, ap);
99+
va_end(ap);
100+
101+
return res;
102+
}
103+
104+
int
105+
VPrintFromISR(const char* fmt, va_list ap)
106+
{
107+
/* TODO: ISRs might be limited on stack memory. Output each
108+
* character individually; instead of a string buffer. */
109+
return _VPrint(fmt, ap);
110+
}

src/FormattedIO.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ Print(const char* fmt, ...);
1111

1212
int
1313
VPrint(const char* fmt, va_list ap);
14+
15+
int
16+
PrintFromISR(const char* fmt, ...);
17+
18+
int
19+
VPrintFromISR(const char* fmt, va_list ap);
20+
21+
/* Internal functions for debugging; don't use in production code. */
22+
23+
int
24+
_Print(const char* fmt, ...);
25+
26+
int
27+
_VPrint(const char* fmt, va_list ap);

0 commit comments

Comments
 (0)