CORE2 v1.0.0
hFramework::hSystem Class Reference

RTOS (Real-Time operating system) interface. More...

#include <hSystem.h>

Public Types

enum  SortMode { None, Name, Ticks }
 

Public Member Functions

 __attribute__ ((deprecated)) static hTask &taskCreate(const UserDataFunc &handler
 
 __attribute__ ((deprecated)) static hTimer &addTimer(uint32_t timeout
 
 __attribute__ ((deprecated)) static hTimer &addTimeout(uint32_t timeout
 
 __attribute__ ((deprecated)) static hTimer &addInterval(uint32_t interval
 

Static Public Member Functions

static hTasktaskCreate (const std::function< void()> &handler, uint8_t priority=2, uint32_t stack=DEFAULT_STACK_SIZE, const char *desc=0)
 Create new task with parameter list. More...
 
static uint32_t getUsTimVal ()
 Get timestamp from all time working timer with 1us resolution. More...
 
static void delay (uint32_t delayMs)
 Delay the current task. More...
 
static void delayUs (uint32_t delay)
 Delay the current task. More...
 
static void delaySync (uint64_t &refTime, uint32_t delay)
 Delay the current task. More...
 
static void delaySync (uint32_t &refTime, uint32_t delay)
 
static uint64_t getRefTime ()
 Get system time. More...
 
static uint32_t getRandNr ()
 Get the random number generated by hardware random number generator. More...
 
static float getSupplyVoltage ()
 Get power supply voltage. More...
 
static uint32_t getSupplyVoltageMV ()
 Get power supply voltage in millivolts. More...
 
static void startCritical ()
 Start critical section. More...
 
static void endCritical ()
 End critical section. More...
 
static char * getTaskList (char *taskList)
 Get list of tasks that are currently registered in the system. More...
 
static void * getThisTaskHandle ()
 Return handle of current task. More...
 
static char * getStats (char *stats)
 Get statistics of all tasks. More...
 
static void printStats (SortMode sortMode=SortMode::Name, hPrintfDev *dev=0)
 
static void * malloc (uint32_t size)
 Dynamicaly allocate memory on the heap. More...
 
static void free (void *ptr)
 Free allocated memory. More...
 
static void getUid (uint8_t *id)
 Get unique device 6-octet length ID. More...
 
static void getRobocoreKey (uint8_t *key)
 
static void reset ()
 Perform microcontroller software reset.
 
static void enableUsbCharging ()
 Enable USB port ability to charge connected devices. More...
 
static void disableUsbCharging ()
 Disable USB port ability to charge connected devices. More...
 
static void enable5V ()
 Enable 5V rail. More...
 
static void disable5V ()
 Disable 5V rail. More...
 
static void disableAutoWatchdog ()
 
static void enableAutoWatchdog ()
 
static void enableSyslog ()
 
static void disableSyslog ()
 
static void setLogDev (hPrintfDev *dev)
 Set default log device. More...
 
static void setSysLogDev (hPrintfDev *dev)
 Set default log device for hFramework internal events. More...
 
static int log (const char *format,...)
 Log formatted string. More...
 
static int vlog (const char *format, va_list arg)
 Log formatted string. More...
 
static int syslog (const char *format,...)
 
static int vsyslog (const char *format, va_list arg)
 
static hStoragegetStorage ()
 Return local persistent storage. More...
 
static int fail_log (const char *format,...)
 
static int fail_vlog (const char *format, va_list arg)
 
static void fault_log (const char *msg)
 
static void idleTask ()
 
static void tickHook ()
 
static void fault_handler ()
 
static hSensorgetSensor (int num)
 
static hMotorgetMotor (int num)
 

Public Attributes

void * param = 0
 
void uint8_t priority = 2
 
void uint8_t uint32_t stack = DEFAULT_STACK_SIZE
 
void uint8_t uint32_t const char * desc
 
TimerMode mode
 
TimerMode TimerRun startMode
 
TimerMode TimerRun const UserDataFunc & handler
 
TimerMode TimerRun const UserDataFunc void * userdata
 
const UserDataFunc & handler
 
const UserDataFunc void * userdata
 

Friends

class hMotor
 
void hFramework::hMainInit ()
 

Detailed Description

RTOS (Real-Time operating system) interface.

Member Function Documentation

static void hFramework::hSystem::delay ( uint32_t  delayMs)
static

Delay the current task.

Parameters
delaymilliseconds to delay
static void hFramework::hSystem::delaySync ( uint64_t &  refTime,
uint32_t  delay 
)
static

Delay the current task.

Parameters
delaymilliseconds to delay
#include "hFramework.h"
void hMain() {
uint32_t t = sys.getRefTime();
while(1) {
sys.delaySync(t,1000);
// ... do something that no one knows whether it takes 100ms, 95ms, 87ms or something.
//delayMsSync() generates respectively 900ms, 905ms, 913ms
//so this piece of code is executed exacly every 1s.
}
}
static void hFramework::hSystem::delayUs ( uint32_t  delay)
static

Delay the current task.

Parameters
delaymicroseconds to delay (must be multiply of 500)
static void hFramework::hSystem::disable5V ( )
static

Disable 5V rail.

Switches 5V off.

static void hFramework::hSystem::disableUsbCharging ( )
static

Disable USB port ability to charge connected devices.

Switches USB port to Standard Downstream Port (SDP) mode.

static void hFramework::hSystem::enable5V ( )
static

Enable 5V rail.

Switches 5V on.

static void hFramework::hSystem::enableUsbCharging ( )
static

Enable USB port ability to charge connected devices.

Switches USB port to Charging Downstream Port (CDP) mode.

static void hFramework::hSystem::endCritical ( )
static

End critical section.

Enable tasks swithing.

static void hFramework::hSystem::free ( void *  ptr)
static

Free allocated memory.

Parameters
ptrpointer to dynamically allocated memory
static uint32_t hFramework::hSystem::getRandNr ( )
static

Get the random number generated by hardware random number generator.

Returns
generated random number
static uint64_t hFramework::hSystem::getRefTime ( )
static

Get system time.

Returns
system time in ms
static char* hFramework::hSystem::getStats ( char *  stats)
static

Get statistics of all tasks.

Parameters
statspointer to table in which Stats will be stored
Returns
pointer to stats in the following format: [ Task_name Abs_Time _Time ]
static hStorage& hFramework::hSystem::getStorage ( )
static

Return local persistent storage.

Returns
storage object
static float hFramework::hSystem::getSupplyVoltage ( )
static

Get power supply voltage.

Returns
power supply voltage
static uint32_t hFramework::hSystem::getSupplyVoltageMV ( )
static

Get power supply voltage in millivolts.

Returns
power supply voltage in millivolts.
static char* hFramework::hSystem::getTaskList ( char *  taskList)
static

Get list of tasks that are currently registered in the system.

Parameters
taskListpointer to table in which TaskList will be stored
Returns
pointer to taskList in the following format: [ Task_name Task_state(Ready/Running/Blocked/Suspended/Deleted) Priority Stack Num ]
static void* hFramework::hSystem::getThisTaskHandle ( )
static

Return handle of current task.

Returns
current task handle
static void hFramework::hSystem::getUid ( uint8_t *  id)
static

Get unique device 6-octet length ID.

Parameters
idpointer to buffer to store unique id
static uint32_t hFramework::hSystem::getUsTimVal ( )
static

Get timestamp from all time working timer with 1us resolution.

Returns
timer counter value is [us]
static int hFramework::hSystem::log ( const char *  format,
  ... 
)
static

Log formatted string.

To set default log device use setLogDev.

Parameters
strpointer to null terminated format string
...- optional arguments
Returns
number of written characters
static void* hFramework::hSystem::malloc ( uint32_t  size)
static

Dynamicaly allocate memory on the heap.

Parameters
sizenumber of bytes to be dynamically allocated
Returns
pointer to dynamically allocated memory
static void hFramework::hSystem::setLogDev ( hPrintfDev dev)
static

Set default log device.

Device set by this method will be used by printf and sys.log. Example:

sys.setLogDev(&platform);
sys.setLogDev(&devNull);
Parameters
devdevice
static void hFramework::hSystem::setSysLogDev ( hPrintfDev dev)
static

Set default log device for hFramework internal events.

Parameters
devdevice
static void hFramework::hSystem::startCritical ( )
static

Start critical section.

Prevent task switching. Critical section should be as short as possible.

static hTask& hFramework::hSystem::taskCreate ( const std::function< void()> &  handler,
uint8_t  priority = 2,
uint32_t  stack = DEFAULT_STACK_SIZE,
const char *  desc = 0 
)
static

Create new task with parameter list.

Parameters
taskProcan TaskProcUserData argument
parama void pointer to the object with parameters
prioritya priority of the task (the higher the number, the higher priority)
stacka size of table dynamically allocated as stack for current task (single element of this table is uint32_t)
desca C-string with task description used in debugging
Returns
the created task handle
static int hFramework::hSystem::vlog ( const char *  format,
va_list  arg 
)
static

Log formatted string.

To set default log device use setLogDev.

Parameters
strpointer to null terminated format string
argarguments as a va_list
Returns
number of written characters

Member Data Documentation

void uint8_t uint32_t const char* hFramework::hSystem::desc
Initial value:
= 0)
{
return taskCreate(std::bind(handler, param), priority, stack, desc);
}
static hTimer& addTimer(uint32_t timeout, TimerMode mode, TimerRun startMode, const std::function<void()>& handler)
const UserDataFunc void * hFramework::hSystem::userdata
Initial value:
{
return addTimer(timeout, mode, startMode, std::bind(handler, userdata))
const UserDataFunc void* hFramework::hSystem::userdata
Initial value:
{
return addTimer(timeout, TimerMode::OneShot, TimerRun::Immediately, std::bind(handler, userdata))

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