-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hal/imxrt: Support RTT as a HAL console
UART is enabled by default (current behavior), but can be turned off by defining UART_CONSOLE_KERNEL with an empty value. RTT is enabled by defining RTT_ENABLED with a truthy value and (optionally) selecting a channel to use by RTT_CONSOLE_KERNEL (0-based). UART and RTT may be used at the same time. RTT driver reuses the control block configured by plo, which must also create a map named via RTT_SYSPAGE_MAP_NAME (default: "rtt"). Channel configuration is not altered at all, so RTT will work even when user-mode driver takes control - exception dumps will still be printed. JIRA: RTOS-754
- Loading branch information
Showing
6 changed files
with
319 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* SEGGER's Real Time Transfer - simplified driver | ||
* | ||
* Copyright 2023-2024 Phoenix Systems | ||
* Author: Gerard Swiderski, Daniel Sawka | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#include "include/errno.h" | ||
#include "syspage.h" | ||
#include "hal/arm/barriers.h" | ||
|
||
#include <board_config.h> | ||
#include "rtt.h" | ||
|
||
#ifndef RTT_SYSPAGE_MAP_NAME | ||
#define RTT_SYSPAGE_MAP_NAME "rtt" | ||
#endif | ||
|
||
#ifndef RTT_CB_SIZE | ||
#define RTT_CB_SIZE 256 | ||
#endif | ||
|
||
|
||
struct rtt_pipe { | ||
const char *name; | ||
volatile unsigned char *ptr; | ||
unsigned int sz; | ||
volatile unsigned int wr; | ||
volatile unsigned int rd; | ||
unsigned int flags; | ||
}; | ||
|
||
|
||
struct rtt_desc { | ||
char tag[16]; | ||
unsigned int txChannels; | ||
unsigned int rxChannels; | ||
struct rtt_pipe channels[]; | ||
}; | ||
|
||
|
||
static struct { | ||
volatile struct rtt_desc *rtt; | ||
} common; | ||
|
||
|
||
static int rtt_check(unsigned int chan, rtt_dir_t dir) | ||
{ | ||
if ((dir == rtt_dir_up) && (chan >= common.rtt->txChannels)) { | ||
return -ENODEV; | ||
} | ||
|
||
if ((dir == rtt_dir_down) && (chan >= common.rtt->rxChannels)) { | ||
return -ENODEV; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int _hal_rttWrite(unsigned int chan, const void *buf, unsigned int count) | ||
{ | ||
unsigned int sz; | ||
unsigned int rd; | ||
unsigned int wr; | ||
unsigned int todo; | ||
volatile unsigned char *dstBuf; | ||
|
||
if (rtt_check(chan, rtt_dir_up) < 0) { | ||
return -ENODEV; | ||
} | ||
|
||
hal_cpuDataMemoryBarrier(); | ||
dstBuf = common.rtt->channels[chan].ptr; | ||
sz = common.rtt->channels[chan].sz - 1; | ||
rd = (common.rtt->channels[chan].rd + sz) & sz; | ||
wr = common.rtt->channels[chan].wr & sz; | ||
todo = count; | ||
|
||
/* TODO: Support all buffer modes (currently only trim is used, regardless of flags) */ | ||
while ((todo != 0) && (rd != wr)) { | ||
dstBuf[wr] = *(unsigned char *)buf++; | ||
wr = (wr + 1) & sz; | ||
todo--; | ||
} | ||
|
||
hal_cpuDataMemoryBarrier(); | ||
common.rtt->channels[chan].wr = wr; | ||
|
||
return count - todo; | ||
} | ||
|
||
|
||
int _hal_rttTxAvail(unsigned int chan) | ||
{ | ||
unsigned int sz; | ||
unsigned int rd; | ||
unsigned int wr; | ||
|
||
if (rtt_check(chan, rtt_dir_up) < 0) { | ||
return -ENODEV; | ||
} | ||
|
||
hal_cpuDataMemoryBarrier(); | ||
sz = common.rtt->channels[chan].sz - 1; | ||
rd = (common.rtt->channels[chan].rd + sz) & sz; | ||
wr = common.rtt->channels[chan].wr & sz; | ||
|
||
if (wr > rd) { | ||
return sz + 1 - (wr - rd); | ||
} | ||
else { | ||
return rd - wr; | ||
} | ||
} | ||
|
||
|
||
int _hal_rttReset(unsigned int chan, rtt_dir_t dir) | ||
{ | ||
if (rtt_check(chan, dir) < 0) { | ||
return -ENODEV; | ||
} | ||
|
||
hal_cpuDataMemoryBarrier(); | ||
if (dir == rtt_dir_up) { | ||
common.rtt->channels[chan].wr = common.rtt->channels[chan].rd; | ||
} | ||
else { | ||
chan = common.rtt->txChannels + chan; | ||
common.rtt->channels[chan].rd = common.rtt->channels[chan].wr; | ||
} | ||
hal_cpuDataMemoryBarrier(); | ||
return 0; | ||
} | ||
|
||
|
||
int _hal_rttInit(void) | ||
{ | ||
const syspage_map_t *map = syspage_mapNameResolve(RTT_SYSPAGE_MAP_NAME); | ||
|
||
if (map == NULL) { | ||
return -ENOENT; | ||
} | ||
|
||
/* TODO: Place CB always at the start of the map? */ | ||
common.rtt = (void *)(map->end - RTT_CB_SIZE); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* SEGGER's Real Time Transfer - simplified driver | ||
* | ||
* Copyright 2023-2024 Phoenix Systems | ||
* Author: Gerard Swiderski, Daniel Sawka | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#ifndef HAL_ARM_RTT_H_ | ||
#define HAL_ARM_RTT_H_ | ||
|
||
|
||
typedef enum { | ||
rtt_dir_up, /* tx: target -> host */ | ||
rtt_dir_down, /* rx: host -> target */ | ||
} rtt_dir_t; | ||
|
||
|
||
typedef enum { | ||
rtt_mode_skip = 0, /* write if the whole message can be written at once; discard the message otherwise */ | ||
rtt_mode_trim = 1, /* write anything if possible; discard the remaining unwritten data otherwise */ | ||
rtt_mode_blocking = 2, /* wait until writable */ | ||
} rtt_mode_t; | ||
|
||
|
||
/* Initialize rtt internal structures */ | ||
int _hal_rttInit(void); | ||
|
||
|
||
/* Non-blocking write to channel */ | ||
int _hal_rttWrite(unsigned int chan, const void *buf, unsigned int count); | ||
|
||
|
||
/* Check for available space in tx */ | ||
int _hal_rttTxAvail(unsigned int chan); | ||
|
||
|
||
/* Reset fifo pointers */ | ||
int _hal_rttReset(unsigned int chan, rtt_dir_t dir); | ||
|
||
|
||
#endif /* end of HAL_ARM_RTT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.