COSA
An Object-Oriented Platform for Arduino Programming
Nucleo::Actor Class Reference

#include <Actor.hh>

Inheritance diagram for Nucleo::Actor:
Inheritance graph
Collaboration diagram for Nucleo::Actor:
Collaboration graph

Public Member Functions

 Actor ()
 
int send (uint8_t port, const void *buf=NULL, size_t size=0)
 
int recv (Actor *&sender, uint8_t &port, void *buf=NULL, size_t size=0)
 
virtual void run ()
 
void resume (Thread *thread)
 
void yield ()
 
void delay (uint32_t ms)
 
void enqueue (Head *queue, Thread *thread=NULL)
 
void dequeue (Head *queue, bool flag=true)
 
void detach ()
 
Linkagesucc () const
 
Linkagepred () const
 
void attach (Linkage *pred)
 
virtual void on_event (uint8_t type, uint16_t value)
 

Static Public Member Functions

static Threadrunning ()
 
static void begin (Thread *thread=NULL, size_t size=0)
 
static void service ()
 

Protected Member Functions

void init (void *stack)
 

Protected Attributes

volatile bool m_receiving
 
Head m_sending
 
uint8_t m_port
 
size_t m_size
 
const void * m_buf
 
jmp_buf m_context
 
uint32_t m_expires
 
Linkagem_succ
 
Linkagem_pred
 

Static Protected Attributes

static const size_t MAIN_STACK_MAX = 64
 
static Head s_delayed
 
static Thread s_main
 
static Threads_running = &s_main
 
static size_t s_top = MAIN_STACK_MAX
 

Detailed Description

The Cosa Nucleo Actor; message passing supported thread.

Definition at line 31 of file Actor.hh.

Constructor & Destructor Documentation

Nucleo::Actor::Actor ( )
inline

Construct actor and initiate internals.

Definition at line 36 of file Actor.hh.

Member Function Documentation

void Linkage::attach ( Linkage pred)
inlineinherited

Attach given linkage as predecessor. Will check and detach if already attached.

Parameters
[in]predlinkage to attach.
Note
atomic

Definition at line 71 of file Linkage.hh.

void Thread::begin ( Thread thread = NULL,
size_t  size = 0 
)
staticinherited

Schedule static thread with given stack size. Using the default parameters will start the main thread.

Parameters
[in]threadto initiate and schedule.
[in]sizeof stack.

Definition at line 57 of file Thread.cpp.

void Thread::delay ( uint32_t  ms)
inherited

Delay at least the given time period in milli-seconds. The resolution is determined by the Watchdog clock and has a resolution of 16 milli-seconds (per tick). The actual delay also depends on how other threads yield.

Parameters
[in]msminimum delay time period in milli-seconds.

Definition at line 121 of file Thread.cpp.

void Thread::dequeue ( Head queue,
bool  flag = true 
)
inherited

If given queue is not empty dequeue first thread and resume direct if flag is true otherwise enqueue first in run queue.

Parameters
[in]queueto transfer from.
[in]flagresume direct otherwise on yield (Default true).

Definition at line 107 of file Thread.cpp.

void Link::detach ( )
inlineinherited

Detach this link. Unlink from any list.

Definition at line 125 of file Linkage.hh.

void Thread::enqueue ( Head queue,
Thread thread = NULL 
)
inherited

Enqueue running thread to given queue and yield.

Parameters
[in]queueto transfer to.
[in]threadto resume (Default yield).

Definition at line 98 of file Thread.cpp.

void Thread::init ( void *  stack)
protectedinherited

Initiate thread and prepare for initial call to virtual member function run(). Stack frame is allocated by begin().

Parameters
[in]stacktop pointer.

Definition at line 49 of file Thread.cpp.

virtual void Event::Handler::on_event ( uint8_t  type,
uint16_t  value 
)
inlinevirtualinherited

Default null event handler. Should be redefined by sub-classes. Called by Event::dispatch().

Parameters
[in]typethe event type.
[in]valuethe event value.

Reimplemented in Menu::RotaryController, Rotary::Dial< T >, AnalogPin, Job, TWI::Slave, ProtoThread, AnalogPins, and Periodic.

Definition at line 107 of file Event.hh.

Linkage* Linkage::pred ( ) const
inlineinherited

Return predecessor in sequence.

Returns
predecessor linkage.

Definition at line 60 of file Linkage.hh.

int Actor::recv ( Actor *&  sender,
uint8_t &  port,
void *  buf = NULL,
size_t  size = 0 
)

Receive message to given buffer and with given max size to actor. Returns sender, port and size or negative error code. Sending actor is rescheduled.

Parameters
[in,out]senderactor.
[in,out]portor message identity.
[in]bufpointer to buffer (default NULL).
[in]sizeof message (default 0)
Returns
size or negative error code.

Definition at line 45 of file Actor.cpp.

void Thread::resume ( Thread thread)
inherited

Yield control to the given thread. Preserve stack and machine state and later continue.

Parameters
[in]threadto resume.

Definition at line 90 of file Thread.cpp.

void Thread::run ( )
virtualinherited

The thread main function. The function is called when the thread is scheduled and becomes running. Normally the function is an end-less loop. Returning from the function will result in that the function is called again. The default implementation is the main thread. It is responsible for power down when there are no other active threads. Other threads must override this member function.

Definition at line 72 of file Thread.cpp.

static Thread* Nucleo::Thread::running ( )
inlinestaticinherited

Return running thread.

Returns
thread.

Definition at line 39 of file Thread.hh.

int Actor::send ( uint8_t  port,
const void *  buf = NULL,
size_t  size = 0 
)

Send message in given buffer and with given size to actor. Given port may be used as message identity. Returns size or negative error code. Receiving actor is resumed.

Parameters
[in]portor message identity.
[in]bufpointer to buffer (default NULL).
[in]sizeof message (default 0).
Returns
size or negative error code.

Definition at line 26 of file Actor.cpp.

void Thread::service ( )
staticinherited

Service the nucleos main thread. Should be called in the loop() function.

Definition at line 133 of file Thread.cpp.

Linkage* Linkage::succ ( ) const
inlineinherited

Return successor in sequence.

Returns
successor linkage.

Definition at line 51 of file Linkage.hh.

void Nucleo::Thread::yield ( )
inlineinherited

Yield control to the next thread in the thread queue. Preserve stack and machine state and later continue.

Definition at line 75 of file Thread.hh.

Member Data Documentation

const void* Nucleo::Actor::m_buf
protected

Definition at line 73 of file Actor.hh.

jmp_buf Nucleo::Thread::m_context
protectedinherited

Thread context.

Definition at line 130 of file Thread.hh.

uint32_t Nucleo::Thread::m_expires
protectedinherited

Delay time expires; should not run for more than 2**32 seconds.

Definition at line 133 of file Thread.hh.

uint8_t Nucleo::Actor::m_port
protected

Definition at line 71 of file Actor.hh.

Linkage* Linkage::m_pred
protectedinherited

Definition at line 94 of file Linkage.hh.

volatile bool Nucleo::Actor::m_receiving
protected

Definition at line 69 of file Actor.hh.

Head Nucleo::Actor::m_sending
protected

Definition at line 70 of file Actor.hh.

size_t Nucleo::Actor::m_size
protected

Definition at line 72 of file Actor.hh.

Linkage* Linkage::m_succ
protectedinherited

Double linked list pointers.

Definition at line 93 of file Linkage.hh.

const size_t Nucleo::Thread::MAIN_STACK_MAX = 64
staticprotectedinherited

Size of main thread stack.

Definition at line 115 of file Thread.hh.

Head Thread::s_delayed
staticprotectedinherited

Queue for delayed threads.

Definition at line 118 of file Thread.hh.

Thread Thread::s_main
staticprotectedinherited

Main thread and thread queue head.

Definition at line 121 of file Thread.hh.

Thread * Thread::s_running = &s_main
staticprotectedinherited

Running thread.

Definition at line 124 of file Thread.hh.

size_t Thread::s_top = MAIN_STACK_MAX
staticprotectedinherited

Top of stack allocation.

Definition at line 127 of file Thread.hh.


The documentation for this class was generated from the following files: