Miosix  2.01
miosix Namespace Reference

c++11 More...

Classes

class  BufferQueue
 
class  Callback
 
class  CallbackBase
 
class  ConditionVariable
 
class  DefaultConsole
 
class  Device
 
class  DirectoryBase
 
class  DynUnsyncQueue
 
class  EventQueue
 
class  FastInterruptDisableLock
 
class  FastInterruptEnableLock
 
class  FastMutex
 
class  Fat32Fs
 
class  FileBase
 
class  FileDescriptorTable
 
class  FilesystemBase
 
class  FilesystemManager
 
class  FixedEventQueue
 
class  FixedEventQueueBase
 
class  InterruptDisableLock
 
class  InterruptEnableLock
 
class  Intrusive
 
class  intrusive_ref_ptr
 
class  IntrusiveRefCounted
 
class  IntrusiveRefCountedSharedFromThis
 
class  Lcd44780
 
class  Lock
 
class  LowerPriority
 
class  MemoryProfiling
 
class  MountpointFs
 
class  Mutex
 
class  PauseKernelLock
 
class  Queue
 
class  ResolvedPath
 
class  RestartKernelLock
 
class  SoftwareI2C
 
class  SoftwareSPI
 
class  TerminalDevice
 
class  Thread
 
class  TimeConversion
 
class  TimeConversionFactor
 
class  Timer
 
class  Unicode
 
class  Unlock
 

Enumerations

enum  Error {
  INVALID_PARAMETERS, OUT_OF_MEMORY, STACK_OVERFLOW, UNEXPECTED,
  PAUSE_KERNEL_NESTING, DISABLE_INTERRUPTS_NESTING, MUTEX_DEADLOCK, MUTEX_UNLOCK_NOT_OWNER,
  NESTING_OVERFLOW, PROPAGATED_EXCEPTION, INTERRUPTS_ENABLED_AT_BOOT
}
 

Functions

void basicFilesystemSetup (intrusive_ref_ptr< Device > dev)
 
FileDescriptorTablegetFileDescriptorTable ()
 
int atomicSwap (volatile int *p, int v)
 
void atomicAdd (volatile int *p, int incr)
 
int atomicAddExchange (volatile int *p, int incr)
 
int atomicCompareAndSwap (volatile int *p, int prev, int next)
 
void * atomicFetchAndIncrement (void *const volatile *p, int offset, int incr)
 
void shutdown ()
 
void reboot ()
 
void delayMs (unsigned int mseconds)
 
void delayUs (unsigned int useconds)
 
void errorHandler (Error e)
 
template<typename T , typename U >
bool operator== (const intrusive_ref_ptr< T > &a, const intrusive_ref_ptr< U > &b)
 
template<typename T , typename U >
bool operator!= (const intrusive_ref_ptr< T > &a, const intrusive_ref_ptr< U > &b)
 
template<typename T , typename U >
bool operator< (const intrusive_ref_ptr< T > &a, const intrusive_ref_ptr< U > &b)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const intrusive_ref_ptr< T > &p)
 
template<typename T , typename U >
intrusive_ref_ptr< T > static_pointer_cast (const intrusive_ref_ptr< U > &r)
 
template<typename T , typename U >
intrusive_ref_ptr< T > dynamic_pointer_cast (const intrusive_ref_ptr< U > &r)
 
template<typename T , typename U >
intrusive_ref_ptr< T > const_pointer_cast (const intrusive_ref_ptr< U > &r)
 
template<typename T >
intrusive_ref_ptr< T > atomic_load (const intrusive_ref_ptr< T > *p)
 
template<typename T >
void atomic_store (intrusive_ref_ptr< T > *p, intrusive_ref_ptr< T > r)
 
template<typename T >
intrusive_ref_ptr< T > atomic_exchange (intrusive_ref_ptr< T > *p, intrusive_ref_ptr< T > r)
 
void disableInterrupts ()
 
void enableInterrupts ()
 
void pauseKernel ()
 
void restartKernel ()
 
bool areInterruptsEnabled ()
 
bool isKernelRunning ()
 
long long getTick ()
 
void fastDisableInterrupts ()
 
void fastEnableInterrupts ()
 
void * mainLoader (void *argv)
 
long long mul64x32d32 (long long a, unsigned int bi, unsigned int bf)
 
unsigned short crc16 (const void *message, unsigned int length)
 
void memDump (const void *start, int len)
 
const char * getMiosixVersion ()
 

Variables

const unsigned int SERIAL_PORT_SPEED =115200
 Serial port baudrate.
 
const unsigned int AUX_SERIAL_SPEED =9600
 Aux serial port baudrate. More...
 
const unsigned int MAIN_STACK_SIZE =4*1024
 Size of stack for main(). More...
 
const unsigned int TICK_FREQ =200
 
const unsigned int defaultSerial =0
 Serial port.
 
const unsigned char MAX_OPEN_FILES =8
 
const unsigned int STACK_MIN =256
 Minimum stack size (MUST be divisible by 4)
 
const unsigned int STACK_DEFAULT_FOR_PTHREAD =2048
 
const unsigned int MAX_PROCESS_IMAGE_SIZE =64*1024
 
const unsigned int MIN_PROCESS_STACK_SIZE =STACK_MIN
 
const unsigned int SYSTEM_MODE_PROCESS_STACK_SIZE =2*1024
 
const short int PRIORITY_MAX =4
 
const unsigned char MAIN_PRIORITY =1
 
const float kpi =0.5
 
const int multFactor =static_cast<int>(1.0f/kpi)
 

Detailed Description

c++11

All user available kernel functions, classes are inside this namespace.

Enumeration Type Documentation

This enum will be passed as argument to the error handler.
If the error is marked UNRECOVERABLE, then the error handler will not return.

Enumerator
INVALID_PARAMETERS 

A function/method was called with invalid parameters.
Error is recoverable.

OUT_OF_MEMORY 

The heap is full, malloc/new returned NULL.
Whether error is recoverable is architecture specific.

STACK_OVERFLOW 

The stack of a thread overflowed.
Error is UNRECOVERABLE.

UNEXPECTED 

Unexpected error occurred.
Error is UNRECOVERABLE.

PAUSE_KERNEL_NESTING 

A call to restartKernel that does not match a previous call to pauseKernel
Error is UNRECOVERABLE

DISABLE_INTERRUPTS_NESTING 

A call to enableInterrupts that does not match a previous call to disableInterrupts
Error is UNRECOVERABLE

MUTEX_DEADLOCK 

An attempt to lock twice a non recursive mutex happened.
Error is UNRECOVERABLE

MUTEX_UNLOCK_NOT_OWNER 

An attempt to call unlock() on a mutex without first calling lock has been detected.

NESTING_OVERFLOW 

The calls to pauseKernel or disableInterrupts were nested too much. Error is UNRECOVERABLE

PROPAGATED_EXCEPTION 

An uncaught exception propagated throug a thread's entry point. Error is recoverable.

INTERRUPTS_ENABLED_AT_BOOT 

Interrupts are wrongly enabled during boot Error is unrecoverable

Function Documentation

template<typename T >
intrusive_ref_ptr<T> miosix::atomic_exchange ( intrusive_ref_ptr< T > *  p,
intrusive_ref_ptr< T >  r 
)

Allows concurrent access to an instance of intrusive_ref_ptr. Multiple threads can cooncurrently perform atomic_load(), atomic_store() and atomic_exchange() on the same intrusive_ref_ptr. Any other concurent access not protected by explicit locking (such as threads calling reset(), or using the copy constructor, or deleting the intrusive_ref_ptr) yields undefined behaviour.

Parameters
ppointer to an intrusive_ref_ptr shared among threads
rvalue to be stored in *p
Returns
the previous value of *p
template<typename T >
intrusive_ref_ptr<T> miosix::atomic_load ( const intrusive_ref_ptr< T > *  p)

Allows concurrent access to an instance of intrusive_ref_ptr. Multiple threads can cooncurrently perform atomic_load(), atomic_store() and atomic_exchange() on the same intrusive_ref_ptr. Any other concurent access not protected by explicit locking (such as threads calling reset(), or using the copy constructor, or deleting the intrusive_ref_ptr) yields undefined behaviour.

Parameters
ppointer to an intrusive_ref_ptr shared among threads
Returns
*p, atomically fetching the pointer and incrementing the reference count
template<typename T >
void miosix::atomic_store ( intrusive_ref_ptr< T > *  p,
intrusive_ref_ptr< T >  r 
)

Allows concurrent access to an instance of intrusive_ref_ptr. Multiple threads can cooncurrently perform atomic_load(), atomic_store() and atomic_exchange() on the same intrusive_ref_ptr. Any other concurent access not protected by explicit locking (such as threads calling reset(), or using the copy constructor, or deleting the intrusive_ref_ptr) yields undefined behaviour.

Parameters
ppointer to an intrusive_ref_ptr shared among threads
rintrusive_ref_ptr that will be stored in *p
void miosix::atomicAdd ( volatile int *  p,
int  incr 
)
inline

Atomically read the content of a memory location, add a number to the loaded value, and store the result. Performs atomically the following operation:

inline void atomicAdd(volatile int *p, int incr)
{
*p+=incr;
}
Parameters
ppointer to memory location where the atomic add will take place
incrvalue to be added to *p
int miosix::atomicAddExchange ( volatile int *  p,
int  incr 
)
inline

Atomically read the content of a memory location, add a number to the loaded value, store the result and return the previous value stored. Performs atomically the following operation:

inline int atomicAddExchange(volatile int *p, int incr)
{
int result=*p;
*p+=incr;
return result;
}
Parameters
pointerto memory location where the atomic add will take place
incrvalue to be added to *p
Returns
the previous value of *p
int miosix::atomicCompareAndSwap ( volatile int *  p,
int  prev,
int  next 
)
inline

Atomically read the value of a memory location, and store a new value in it if it matches a given value. Also, return the previously stored value. Performs atomically the following operation:

inline int atomicCompareAndSwap(volatile int *p, int prev, int next)
{
int result=*p;
if(*p==prev) *p=next;
return result;
}
Parameters
ppointer to the memory location to compare and swap
prevvalue to be compared against the content of *p
nextvalue to be stored in *p if *p==prev
Returns
the value actually read from *p
void* miosix::atomicFetchAndIncrement ( void *const volatile *  p,
int  offset,
int  incr 
)
inline

An implementation of atomicFetchAndIncrement, as described in http://www.drdobbs.com/atomic-reference-counting-pointers/184401888 Atomically read a pointer stored in one memory loaction, and add a constant to a memory loaction placed at a given offset from the pointer. Performs atomically the following operation:

void *atomicFetchAndIncrement(void * const volatile *p, int offset, int incr)
{
int *result=*p;
if(result==0) return 0;
*(result+offset)+=incr;
return result;
}
Parameters
ppointer to a const volatile pointer to object. While p is not subject to thread contention, *p is.
offsetthe memory location to increment is **p+offset*sizeof(int)
incrvalue to be added to **p+offset*sizeof(int)
Returns
*p
int miosix::atomicSwap ( volatile int *  p,
int  v 
)
inline

Store a value in one memory location, and atomically read back the previously stored value. Performs atomically the following operation:

inline int atomicSwap(volatile int *p, int v)
{
int result=*p;
*p=v;
return result;
}
Parameters
ppointer to memory location where the atomic swap will take place
vnew value to be stored in *p
Returns
the previous value of *p
void miosix::basicFilesystemSetup ( intrusive_ref_ptr< Device dev)

This is a simplified function to mount the root and /dev filesystems, meant to be called from bspInit2(). It mounts a MountpointFs as root, then creates a /dev directory, and mounts /dev there. It also takes the passed device and if it is not null it adds the device di DevFs as /dev/sda. Last, it attempts to mount /dev/sda at /sd as a Fat32 filesystem. In case the bsp needs another filesystem setup, such as having a fat32 filesystem as /, this function can't be used, but instead the bsp needs to mount the filesystems manually.

Parameters
devdisk device that will be added as /dev/sda and mounted on /sd
Returns
a pointer to the DevFs, so as to be able to add other device files, but only if WITH_DEVFS is defined
template<typename T , typename U >
intrusive_ref_ptr<T> miosix::const_pointer_cast ( const intrusive_ref_ptr< U > &  r)

Performs const_cast between intrusive_ref_ptr

Parameters
rintrusive_ref_ptr of source type
Returns
intrusive_ref_ptr of destination type
unsigned short miosix::crc16 ( const void *  message,
unsigned int  length 
)

Calculate the ccitt crc16 on a string of bytes

Parameters
messagestring of bytes
lengthmessage length
Returns
the crc16
template<typename T , typename U >
intrusive_ref_ptr<T> miosix::dynamic_pointer_cast ( const intrusive_ref_ptr< U > &  r)

Performs dynamic_cast between intrusive_ref_ptr

Parameters
rintrusive_ref_ptr of source type
Returns
intrusive_ref_ptr of destination type
void miosix::errorHandler ( Error  e)

Handles errors generated by kernel. Prints an error message on the Console (only if WITH_ERRLOG is defined in miosix_config.h). For information about possible errors, see the enum Error Can be called with the kernel not started, started, paused, with interrupts disabled and within an interrupt routine.

FileDescriptorTable & miosix::getFileDescriptorTable ( )
Returns
a pointer to the file descriptor table associated with the current process.

< The only file table

void * miosix::mainLoader ( void *  argv)

This function will perform the part of system initialization that must be done after the kernel is started. At the end, it will call main()

Parameters
argvignored parameter
long long miosix::mul64x32d32 ( long long  a,
unsigned int  bi,
unsigned int  bf 
)

Multiplication between a 64 bit integer and a 32.32 fixed point number,

The caller must guarantee that the 64 bit number is positive and that the result of the multiplication fits in 64 bits. Otherwise the behaviour is unspecified.

Parameters
athe 64 bit integer number.
bithe 32 bit integer part of the fixed point number
bfthe 32 bit fractional part of the fixed point number
Returns
the result of the multiplication. The fractional part is discarded.
template<typename T , typename U >
bool miosix::operator!= ( const intrusive_ref_ptr< T > &  a,
const intrusive_ref_ptr< U > &  b 
)

Operator!=

Parameters
afirst pointer
bsecond pointer
Returns
true if they point to different objects
template<typename T , typename U >
bool miosix::operator< ( const intrusive_ref_ptr< T > &  a,
const intrusive_ref_ptr< U > &  b 
)

Operator<, allows to create containers of objects

Parameters
afirst pointer
bsecond pointer
Returns
true if a.get() < b.get()
template<typename T >
std::ostream& miosix::operator<< ( std::ostream &  os,
const intrusive_ref_ptr< T > &  p 
)

Operator<<, allows printing of the pointer value on an ostream

Parameters
osostream where to print the pointer value
pintrusive_ref_ptr to print
Returns
os
template<typename T , typename U >
bool miosix::operator== ( const intrusive_ref_ptr< T > &  a,
const intrusive_ref_ptr< U > &  b 
)

Operator==

Parameters
afirst pointer
bsecond pointer
Returns
true if they point to the same object
template<typename T , typename U >
intrusive_ref_ptr<T> miosix::static_pointer_cast ( const intrusive_ref_ptr< U > &  r)

Performs static_cast between intrusive_ref_ptr

Parameters
rintrusive_ref_ptr of source type
Returns
intrusive_ref_ptr of destination type

Variable Documentation

const float miosix::kpi =0.5

Run the scheduler using fixed point math only. Faster but less precise. Note that the inner integral regulators are always fixed point, this affects round partitioning and the external PI regulator. Also note this imposes a number of limits:

  • the number of threads has a maximum of 64 (this constrain is enforced in PKaddThread()
  • the max "priority" is limited to 63 (this constraint is enforced by priority valdation, as usual)
  • both krr and zrr must be less than 1.99f (this constraint is not enforced, if a wrong value is set strange things may happen)
  • the maximum average burst must be less than 8192. Individual bursts may exceed this, but the su of all bursts in the Tr variable can't exceed 64 (max # threads) * 8191 = ~524287 (this constraint is enforced by clamping Tr to that value)
const int miosix::multFactor =static_cast<int>(1.0f/kpi)

Implementation detail resulting from a fixed point implementation of the inner integral regulators. Never change this, change kpi instead.