Files CCore/src/sys/SysCon.cpp
This part defines default console object. This object may be connected to the board serial port or another input/output device to be used for the console communication.
Two functions are implemented in this module: GetPlanInitNode_SysCon() and ConBase::GetObject(). The first is a PlanInit node function. The second gives access to the console object through the abstract base ConBase.
Here is a pattern to implement SysCon:
/* SysCon.cpp */ #include <CCore/inc/sys/SysCon.h> #include <CCore/inc/dev/DevPlanInit.h> namespace CCore { namespace Sys { /* GetPlanInitNode_...() */ namespace Private_SysCon { /* class ImpCon */ class ImpCon : public ConBase { private: virtual void attachDefaultInput(ConInputFunction input_any) { Used(input_any); // TODO } virtual void detachDefaultInput() { // TODO } virtual void defaultOutput(NanoPacket<char> packet) { if( !packet ) return; // TODO packet.free(); } virtual void enablePacket() { // TODO } virtual void disablePacket() { // TODO } virtual void showStat() { // TODO } public: ImpCon(TextLabel name,void *mem,ulen max_data_len,ulen count) : ConBase(name,mem,max_data_len,count) { } ~ImpCon() { } }; /* class DefaultCon */ class DefaultCon : NoCopy { static const ulen MaxDataLen = 512 ; static const ulen Count = 100 ; static const ulen MemLen = ConBase::MemLen(MaxDataLen,Count) ; private: InitStorage<MemLen> storage; ImpCon dev; public: DefaultCon() : dev("!SysCon",storage.getMem(),MaxDataLen,Count) {} ~DefaultCon() {} ConBase * getBase() { return &dev; } static const char * GetTag() { return "SysCon"; } }; PlanInitObject<DefaultCon,PlanInitReq<Dev::GetPlanInitNode_Dev> ,PlanInitReq<GetPlanInitNode_TaskCore> > Object CCORE_INITPRI_1 ; } // namespace Private_SysCon using namespace Private_SysCon; PlanInitNode * GetPlanInitNode_SysCon() { return &Object; } /* class ConBase */ ConBase * ConBase::GetObject() { return Object->getBase(); } } // namespace Sys } // namespace CCore
The private class ImpCon is responsible for the actual console implementation. The following virtual functions must be implemented to do the real job:
attachDefaultInput() attaches the given input processing function to handle console from the user.
detachDefaultInput() detaches the input processing function.
defaultOutput() must send given data to the output target. If the packet mode is enabled, the implementation may use full power of the XCore, for example, it may store incoming packets in some queue and drive output by an interrupt. If the packet mode is not enabled, implementation must not relay on interrupts and task features and perform output directly, using polling, if required.
enablePacket() is called by XCore when core is fully initialized to enable packet mode output processing.
disablePacket() is called by XCore right before core is going to be uninitialized to disable packet mode output processing.
showStat() may print internal statistic counters (or may do nothing). Provided to debug implementation.