ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
retarget_stdio.c
Go to the documentation of this file.
1/*
2 * retarget_stdio.c
3 *
4 * Created on: Jan 23, 2026
5 * Author: Souham Biswas
6 * GitHub: https://github.com/ironhide23586/icarus-os-core
7 */
8
9
10#include "icarus/kernel.h"
11#include "icarus/scheduler.h"
12
13#include "usbd_cdc_if.h"
14#include "usbd_def.h"
15#include "cmsis_gcc.h"
16
17/* Function prototype */
18int __io_putchar(int ch);
19
20//int __io_putchar(int ch) {
21// enqueue_print_buffer(ch);
22// return ch;
23//}
24
25//
26// Change your __io_putchar implementation
27int __io_putchar(int ch) {
28 /* Static variables must be in RAM_D1, not DTCM, for unprivileged access */
29#ifndef HOST_TEST
30 static uint8_t buf[64] __attribute__((section(".ram_d1")));
31 static uint8_t i __attribute__((section(".ram_d1"))) = 0;
32#else
33 static uint8_t buf[64];
34 static uint8_t i = 0;
35#endif
36
37 buf[i++] = (uint8_t)ch;
38
39 // Flush on newline or when buffer is full
40 {
41 const uint8_t buf_size = (uint8_t)sizeof(buf);
42 if ((ch == (int)'\n') || (i >= buf_size)) {
43
44 uint8_t result = CDC_Transmit_FS(buf, i);
45 uint16_t retry_count = 0u;
46
47 while ((retry_count < 1000u) && (result == USBD_BUSY)) {
48 result = CDC_Transmit_FS(buf, i);
49 (void)task_blocking_sleep(1);
50 retry_count++;
51 }
52 i = 0;
53 }
54 }
55
56 return ch;
57}
ICARUS Kernel Core - State and Initialization.
int __io_putchar(int ch)
ICARUS Scheduler - Task Scheduling and Timing.
uint32_t task_blocking_sleep(uint32_t ticks)
Sleep with scheduler disabled (blocking)
Definition svc.c:542
uint8_t CDC_Transmit_FS(uint8_t *buf, uint16_t len)
Transmit data over USB CDC.