git subrepo clone https://github.com/libopencm3/libopencm3.git
subrepo: subdir: "libopencm3" merged: "88e91c9a7cce" upstream: origin: "https://github.com/libopencm3/libopencm3.git" branch: "master" commit: "88e91c9a7cce" git-subrepo: version: "0.4.3" origin: "???" commit: "???"
This commit is contained in:
57
libopencm3/tests/shared/trace.c
Normal file
57
libopencm3/tests/shared/trace.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdint.h>
|
||||
#include <libopencm3/cm3/common.h>
|
||||
#include <libopencm3/cm3/memorymap.h>
|
||||
#include <libopencm3/cm3/itm.h>
|
||||
#include "trace.h"
|
||||
|
||||
void trace_send_blocking8(int stimulus_port, char c)
|
||||
{
|
||||
if (!(ITM_TER[0] & (1<<stimulus_port))) {
|
||||
return;
|
||||
}
|
||||
while (!(ITM_STIM8(stimulus_port) & ITM_STIM_FIFOREADY));
|
||||
ITM_STIM8(stimulus_port) = c;
|
||||
}
|
||||
|
||||
void trace_send8(int stimulus_port, char val)
|
||||
{
|
||||
if (!(ITM_TER[0] & (1<<stimulus_port))) {
|
||||
return;
|
||||
}
|
||||
ITM_STIM8(stimulus_port) = val;
|
||||
}
|
||||
|
||||
void trace_send_blocking16(int stimulus_port, uint16_t val)
|
||||
{
|
||||
if (!(ITM_TER[0] & (1<<stimulus_port))) {
|
||||
return;
|
||||
}
|
||||
while (!(ITM_STIM16(stimulus_port) & ITM_STIM_FIFOREADY));
|
||||
ITM_STIM16(stimulus_port) = val;
|
||||
}
|
||||
|
||||
void trace_send16(int stimulus_port, uint16_t val)
|
||||
{
|
||||
if (!(ITM_TER[0] & (1<<stimulus_port))) {
|
||||
return;
|
||||
}
|
||||
ITM_STIM16(stimulus_port) = val;
|
||||
}
|
||||
|
||||
|
||||
void trace_send_blocking32(int stimulus_port, uint32_t val)
|
||||
{
|
||||
if (!(ITM_TER[0] & (1<<stimulus_port))) {
|
||||
return;
|
||||
}
|
||||
while (!(ITM_STIM32(stimulus_port) & ITM_STIM_FIFOREADY));
|
||||
ITM_STIM32(stimulus_port) = val;
|
||||
}
|
||||
|
||||
void trace_send32(int stimulus_port, uint32_t val)
|
||||
{
|
||||
if (!(ITM_TER[0] & (1<<stimulus_port))) {
|
||||
return;
|
||||
}
|
||||
ITM_STIM32(stimulus_port) = val;
|
||||
}
|
||||
32
libopencm3/tests/shared/trace.h
Normal file
32
libopencm3/tests/shared/trace.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* File: trace.h
|
||||
* Author: karlp
|
||||
*
|
||||
* Created on November 21, 2013, 4:35 PM
|
||||
*/
|
||||
|
||||
#ifndef TRACE_H
|
||||
#define TRACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void trace_send_blocking8(int stimulus_port, char c);
|
||||
void trace_send8(int stimulus_port, char c);
|
||||
|
||||
void trace_send_blocking16(int stimulus_port, uint16_t val);
|
||||
void trace_send16(int stimulus_port, uint16_t val);
|
||||
|
||||
void trace_send_blocking32(int stimulus_port, uint32_t val);
|
||||
void trace_send32(int stimulus_port, uint32_t val);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TRACE_H */
|
||||
|
||||
34
libopencm3/tests/shared/trace_stdio.c
Normal file
34
libopencm3/tests/shared/trace_stdio.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* support for stdio output to a trace port
|
||||
* Karl Palsson, 2014 <karlp@remake.is>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
#ifndef STIMULUS_STDIO
|
||||
#define STIMULUS_STDIO 0
|
||||
#endif
|
||||
|
||||
int _write(int file, char *ptr, int len);
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (ptr[i] == '\n') {
|
||||
trace_send_blocking8(STIMULUS_STDIO, '\r');
|
||||
}
|
||||
trace_send_blocking8(STIMULUS_STDIO, ptr[i]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user