VT100 Terminal App
Circle VT100 module documentation
Loading...
Searching...
No Matches
TUART.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Module: CTUART
3// Description: Provides buffered UART handling as a Circle task abstraction.
4// Author: R. Zuehlsdorff, ralf.zuehlsdorff@t-online.de
5// Created: 2026-01-27
6// License: MIT License (https://opensource.org/license/mit/)
7//------------------------------------------------------------------------------
8// Change Log:
9// 2026-01-27 R. Zuehlsdorff Initial creation
10//------------------------------------------------------------------------------
11
12#pragma once
13
14#include <circle/sched/task.h>
15#include <circle/spinlock.h>
16#include <circle/serial.h>
17
33class CTUART : public CTask
34{
35public:
37 static CTUART *Get(void);
38
42 CTUART();
43
47 ~CTUART();
48
55 typedef void (*ReceiveHandler)(const char*, size_t);
56 bool Initialize(CInterruptSystem *pInterruptSystem, ReceiveHandler recvFunc);
57
61 bool EnsureStarted();
62
66 void SuspendTask();
67
73 void Send(const char* buf, size_t len);
74
75
79 void Run() override;
80
87 int DrainSerialInput(char *dest, size_t maxLen);
88
89private:
90 class CSerialDeviceWithAccess : public CSerialDevice
91 {
92 public:
93 using CSerialDevice::CSerialDevice;
94 unsigned RxAvailable() { return AvailableForRead(); }
95 };
96
97 CSerialDeviceWithAccess *m_pSerial = nullptr;
98 CInterruptSystem *m_pInterruptSystem = nullptr;
99 bool m_bTaskRunning = false;
100 bool m_bEverStarted = false;
101 bool m_bSoftwareFlowControl = false;
102 bool m_bFlowStopped = false;
103 unsigned m_FlowHighThreshold = 0;
104 unsigned m_FlowLowThreshold = 0;
105
106 // Static receive handler pointer
107 static ReceiveHandler g_ReceiveHandler;
108};
Task responsible for UART initialization and data retrieval.
Definition TUART.h:34
void Send(const char *buf, size_t len)
Send a message through the serial interface.
Definition TUART.cpp:152
void(* ReceiveHandler)(const char *, size_t)
Initialize the serial port.
Definition TUART.h:55
CTUART()
Construct a CTUART task object.
Definition TUART.cpp:35
void Run() override
Main task loop for UART (currently idle, extend for polling/interrupt).
Definition TUART.cpp:158
int DrainSerialInput(char *dest, size_t maxLen)
Drain available serial input from the ring buffer into a destination buffer.
Definition TUART.cpp:167
static CTUART * Get(void)
Access the singleton UART task instance.
Definition TUART.cpp:25
~CTUART()
Destructor for CUART.
Definition TUART.cpp:51
void SuspendTask()
Suspend the UART task so host input is buffered only.
Definition TUART.cpp:140
bool EnsureStarted()
Ensure the UART task is running; safe to call multiple times.
Definition TUART.cpp:111