12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include <kernel.h>
- #include <sys/printk.h>
- #include <device.h>
- #include <init.h>
- #include <SEGGER_RTT.h>
- extern void __printk_hook_install(int (*fn)(int));
- extern void __stdout_hook_install(int (*fn)(int));
- static bool host_present;
- static void wait(void)
- {
- if (!IS_ENABLED(CONFIG_MULTITHREADING) || k_is_in_isr()) {
- if (IS_ENABLED(CONFIG_RTT_TX_RETRY_IN_INTERRUPT)) {
- k_busy_wait(1000*CONFIG_RTT_TX_RETRY_DELAY_MS);
- }
- } else {
- k_msleep(CONFIG_RTT_TX_RETRY_DELAY_MS);
- }
- }
- static int rtt_console_out(int character)
- {
- char c = (char)character;
- unsigned int cnt;
- int max_cnt = CONFIG_RTT_TX_RETRY_CNT;
- uint32_t key;
- do {
-
- key = irq_lock();
- cnt = SEGGER_RTT_WriteNoLock(0, &c, 1);
- irq_unlock(key);
-
- if (cnt) {
-
- host_present = true;
- } else if (host_present) {
- if (max_cnt) {
-
-
- max_cnt--;
- continue;
- } else {
- host_present = false;
- }
- }
- break;
- } while (1);
- return character;
- }
- static int rtt_console_init(const struct device *d)
- {
- ARG_UNUSED(d);
- __printk_hook_install(rtt_console_out);
- __stdout_hook_install(rtt_console_out);
- return 0;
- }
- SYS_INIT(rtt_console_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|