Mio Class Reference

Base class for interfacing the MIO board. More...

#include <Mio.h>

Inheritance diagram for Mio:

MioWin32

List of all members.

Classes

struct  PWMInSubchannelConfig
 PWM input subchannel configuration. More...
struct  PWMOutSubchannelConfig
 PWM output subchannel configuration. More...
struct  PWMOutSubchannelConfig2
 PWM output subchannel configuration 2. More...

Public Member Functions

 Mio ()
 Default constructor.
virtual ~Mio ()
 Destructor.
void SetReceiveTimeout (unsigned timeout_ms)
 Set receive timeout in ms (milli-seconds).
unsigned GetReceiveTimeout () const
 Get receive timeout in ms (milli-seconds).
void SetDrainTime (unsigned drain_time_ms)
 Set drain time in ms (milli-seconds).
unsigned GetDrainTime () const
 Get drain time in ms (milli-seconds).
virtual const char * ResultCodeToText (Mio_Rc rc) const
 Convert MIO API result code to text string.
Mio_Rc Reset ()
 Reset MIO board.
Mio_Rc Loopback (void *out_data, int &out_data_len, const void *in_data, int in_data_len)
 Loopback test.
Mio_Rc SetMioPortsModes (const Mio_PortMode *modes, const unsigned char *params, const Mio_Port *ports, int num_ports)
 Set Mio_PortMode for 1...40 Mio_Port's.
Mio_Rc SetMioPortMode (Mio_PortMode mode, unsigned char param, Mio_Port port)
 Set Mio_PortMode for a single Mio_Port.
Mio_Rc GetMioPortsModes (Mio_PortMode *modes, unsigned char *params, const Mio_Port *ports, int num_ports)
 Get Mio_PortModes and params for 1...40 Mio_Ports at a time.
Mio_Rc GetMioPortMode (Mio_PortMode &mode, unsigned char &param, Mio_Port port)
 Get Mio_PortMode and param for a single Mio_Port.
Mio_Rc SetDigitalOutputValue (unsigned char value, Mio_Port port)
 Set digital output value (0 or 1) for a Mio_Port.
Mio_Rc GetDigitalInputValue (unsigned char &value, Mio_Port port)
 Get digital input value (0 or 1) from a single Mio_Port.
Mio_Rc SetDigitalOutputsValues (const unsigned char *values, const Mio_Port *ports, int num_ports)
 Set digital output value (0 or 1) for 1...39 Mio_Ports.
Mio_Rc GetDigitalInputsValues (unsigned char *values, const Mio_Port *ports, int num_ports)
 Get digital input value (0 or 1) for 1...40 Mio_Ports.
Mio_Rc GetAnalogInputsValues (int *values, const Mio_Port *ports, int num_ports)
 Get analog input value from 1...8 Mio_Ports.
Mio_Rc GetAnalogInputValue (int &value, Mio_Port port)
 Get analog input value from a single Mio_Port.
Mio_Rc StartDS18x20Task (int task_id, Mio_Port mio_port, Mio_DS18x20Type sensor_type, unsigned conversion_time_x100ms)
 Start a DS18x20 temperature sensor measurement task.
Mio_Rc GetDS18x20TaskTemperature (int &temperature, unsigned char &sn, Mio_DS18x20Error &error, int task_id)
 Get DS18x20 temperature.
Mio_Rc StopTask (int task_id)
 Stop a task.
Mio_Rc StartPWMOut (int pwm_clock_channel, Mio_PWMClockSpeed pwm_clock_speed, int pwm_period, const PWMOutSubchannelConfig subchannels[3])
 Start PWM output (generation) on 1...3 PWM subchannels.
Mio_Rc StartPWMOut (int pwm_clock_channel, float pwm_frequency, const PWMOutSubchannelConfig2 subchannels[3])
 Start PWM output (generation) on 1...3 PWM subchannels.
Mio_Rc AdjustPWMOut (int pwm_clock_channel, Mio_PWMClockSpeed pwm_clock_speed, int pwm_period, const PWMOutSubchannelConfig subchannels[3])
 Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.
Mio_Rc AdjustPWMOut (int pwm_clock_channel, float pwm_frequency, const PWMOutSubchannelConfig2 subchannels[3])
 Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.
Mio_Rc StartPWMIn (int pwm_clock_channel, const PWMInSubchannelConfig subchannels[4])
 Start PWM input (measurement) on 1...4 PWM subchannels.
Mio_Rc SetPWMInMode (int pwm_clock_channel, int pwm_subchannel, Mio_PWMInMode mode)
 Set mode for a PWM input subchannel.
Mio_Rc GetPWMInResult (unsigned &total_halfperiod_time, unsigned &total_period_time, int &edges_captured, int pwm_clock_channel, int pwm_subchannel)
 Get measurement result from a PWM input subchannel.
Mio_Rc StopPWM (int pwm_clock_channel)
 Stop all PWM input/output on the selected PWM clock channel.

Static Public Member Functions

static Mio_Rc ConvertPWMOutValues (Mio_PWMClockSpeed &pwm_clock_speed, int &pwm_period, PWMOutSubchannelConfig dst_subchannels[3], float pwm_frequency, const PWMOutSubchannelConfig2 src_subchannels[3])
 Convert from frequency/duty cycle PWM values to PWM clock tick values.

Protected Member Functions

virtual Mio_Rc ResetCommunicationPort ()=0
 Reset communication port to MIO board.
virtual Mio_Rc SendRawDataToMio (const void *data, int data_len)=0
 Send an array of raw data bytes to the MIO board.
virtual Mio_Rc ReceiveRawDataFromMio (void *data, int data_len, int &data_bytes_received, unsigned timeout_ms)=0
 Receive an array of raw data bytes from the MIO board.
virtual unsigned GetCurrentTimeMs ()=0
 Get the current time in milli-seconds.
virtual unsigned GetElapsedTimeMs (unsigned start_time)=0
 Get the elapsed time in milli-seconds.
virtual void DispatchOutOfBandMessage (Mio_MioMsgId msg_id, int payload_len, const void *payload)
 "Call-back" for out-of-band messages received from MIO.


Detailed Description

Base class for interfacing the MIO board.

The functionality in the MIO board is exposed through an API which is implemented in this class. Related constants and enums are declared in MioComm.h.

The base class translates the API function calls into messages that are sent/received to/from the MIO board. The base class implements only the API and message communication layer, not the low level OS specific communication functions. The OS specific functions must be implemented in a derived class, e.g. as the class MioWin32 for Win32 systems.

Porting the MIO API to a new OS is straightforward. Derive from the Mio class and implement the protected virtual functions; ResetCommunicationPort(), SendRawDataToMio(), ReceiveRawDataFromMio(), GetCurrentTimeMs(), GetElapsedTimeMs(). Some means of opening and closing the communication port is also needed.


Constructor & Destructor Documentation

Mio::Mio (  ) 

Default constructor.

virtual Mio::~Mio (  )  [virtual]

Destructor.


Member Function Documentation

void Mio::SetReceiveTimeout ( unsigned  timeout_ms  )  [inline]

Set receive timeout in ms (milli-seconds).

The receive timeout specifies how long the API will wait for a response message from MIO, after a request message has been sent to it. If no response message is received within the specified timeout, the correspodning API function will return with the the error code Mio_Rc_OS_DeviceReadTimeout.

The default value (of about 1000 ms) should be good in most cases. Increase the timeout if the host OS is VERY busy with other tasks.

Parameters:
timeout_ms Receive timeout in ms

unsigned Mio::GetReceiveTimeout (  )  const [inline]

Get receive timeout in ms (milli-seconds).

See documentation for SetReceiveTimeout().

Returns:
Current receive timeout in ms

void Mio::SetDrainTime ( unsigned  drain_time_ms  )  [inline]

Set drain time in ms (milli-seconds).

The drain time specifies how long the communication channel should be cleared from possibly bad data after a communication error has been detected.

The default value (of about 200 ms) should be good in most cases.

Parameters:
drain_time_ms Drain time in ms

unsigned Mio::GetDrainTime (  )  const [inline]

Get drain time in ms (milli-seconds).

See documentation for SetDrainTime().

Returns:
Current drain time time in ms

virtual const char* Mio::ResultCodeToText ( Mio_Rc  rc  )  const [virtual]

Convert MIO API result code to text string.

Returns:
static text string corresponding to rc
Parameters:
rc Result code to convert

Mio_Rc Mio::Reset (  ) 

Reset MIO board.

The function resets MIO to the same state as when power was switched on to the board.

Returns:
Mio_Rc_OK if success, else some error code

Mio_Rc Mio::Loopback ( void *  out_data,
int &  out_data_len,
const void *  in_data,
int  in_data_len 
)

Loopback test.

Loop the given data through the MIO board and back to the host. This function can be used as a basic communication test.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
out_data Ptr to output buffer (must be at least Mio_MessageMaxPayloadSize bytes long)
out_data_len Length of output data is stored here
in_data Ptr to input data
in_data_len Length of input data (max Mio_MessageMaxPayloadSize bytes long)

Mio_Rc Mio::SetMioPortsModes ( const Mio_PortMode modes,
const unsigned char *  params,
const Mio_Port ports,
int  num_ports 
)

Set Mio_PortMode for 1...40 Mio_Port's.

The operating mode (Mio_PortMode) for a port (Mio_Port) must be set before the port can be used. The following modes can be set:

 Mio_PortMode_DigIn      // Digital input (default at MIO startup)
 Mio_PortMode_DigInOut   // Digital input and output
 Mio_PortMode_Vref       // Vref input for ADC
 Mio_PortMode_AnaIn      // Analog input

See definition of Mio_PortMode in MioComm.h for more info.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
modes Ptr to 1...40 Mio_PortModes
params Ptr to 1...40 extra paramerers for the Mio_PortModes. Set to NULL to apply default (0) for all ports
ports Ptr to 1...40 Ports
num_ports Number of ports to configure (1...40)

Mio_Rc Mio::SetMioPortMode ( Mio_PortMode  mode,
unsigned char  param,
Mio_Port  port 
) [inline]

Set Mio_PortMode for a single Mio_Port.

Same as SetMioPortsModes() but for a single Mio_Port.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
mode Mio_PortMode
param Extra parameter for the Mio_PortMode. Set to 0 if not applicable
port Mio_Port

Mio_Rc Mio::GetMioPortsModes ( Mio_PortMode modes,
unsigned char *  params,
const Mio_Port ports,
int  num_ports 
)

Get Mio_PortModes and params for 1...40 Mio_Ports at a time.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
modes Ptr to buffer where 1...40 Mio_PortModes are stored
params Ptr to buffer where 1...40 extra params for the Mio_PortModes are stored
ports Ptr to 1...40 Mio_Ports
num_ports Number of ports

Mio_Rc Mio::GetMioPortMode ( Mio_PortMode mode,
unsigned char &  param,
Mio_Port  port 
) [inline]

Get Mio_PortMode and param for a single Mio_Port.

Same as GetMioPortsModes() but for a single Mio_Port.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
mode Mio_PortMode
param Extra param related to Mio_PortMode
port Mio_Port

Mio_Rc Mio::SetDigitalOutputValue ( unsigned char  value,
Mio_Port  port 
)

Set digital output value (0 or 1) for a Mio_Port.

The Mio_Port must be configured as Mio_PortMode_DigInOut. If the port currently is in input mode, it is automatically switched to output mode.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
value Output value (0 or 1) to be set
port Mio_Port

Mio_Rc Mio::GetDigitalInputValue ( unsigned char &  value,
Mio_Port  port 
)

Get digital input value (0 or 1) from a single Mio_Port.

The Mio_Port must be configured as Mio_PortMode_DigInOut or Mio_PortMode_DigIn. If the port is Mio_PortMode_DigInOut and currently in output mode, it is automatically switched to input mode.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
value Input value (0 or 1) is stored here
port Mio_Port

Mio_Rc Mio::SetDigitalOutputsValues ( const unsigned char *  values,
const Mio_Port ports,
int  num_ports 
)

Set digital output value (0 or 1) for 1...39 Mio_Ports.

The ports must be configured as Mio_PortMode_DigInOut. This is an optimized version that sets the output values with minimum latency between the CPU I/O register writes. All Mio_Ports residing on the same 8 bit CPU I/O register are guaranteed to be updated simultaneously. The maximum update latency between any two Mio_Ports residing on different CPU I/O registers is ~5 us. Please check the MIO specifications for the exact latency.

Note:
Due to the optimized nature of this function; if a Mio_PortMode_DigInOut port currently is in input mode, the port will remain in input mode and the output value will not be set for that port. The function will not report this as an error.
Returns:
Mio_Rc_OK if success, else some error code
Parameters:
values Ptr to 1...39 output values (0 or 1) corresponding to the Mio_Ports
ports Ptr to 1...39 Mio_Ports
num_ports Number of ports

Mio_Rc Mio::GetDigitalInputsValues ( unsigned char *  values,
const Mio_Port ports,
int  num_ports 
)

Get digital input value (0 or 1) for 1...40 Mio_Ports.

The ports must be configured as Mio_PortMode_DigIn or Mio_PortMode_DigInOut. This is an optimized version that gets the input values with minimum latency between the CPU input register reads. All Mio_Ports residing on the same 8 bit CPU input register are guaranteed to be read simultaneously. The maximum read latency between any two Mio_Ports residing on different CPU input registers is ~3 us. Please check the MIO specifications for the exact latency.

Note:
Due to the optimized nature of this function; if a Mio_PortMode_DigInOut port currently is in output mode, the port will remain in output mode and the input value will not be read. The function will not report this as an error.
Returns:
Mio_Rc_OK if success, else some error code
Parameters:
values Ptr to 1...40 input values (0 or 1) corresponding to the Mio_Ports
ports Ptr to 1...40 Mio_Ports
num_ports Number of ports

Mio_Rc Mio::GetAnalogInputsValues ( int *  values,
const Mio_Port ports,
int  num_ports 
)

Get analog input value from 1...8 Mio_Ports.

The ports must be configured as Mio_PortMode_AnaIn (only Mio_Port_P11 ... Mio_Port_P18 can be configured in this mode). The ports are sampled sequentially in the same order as specified in the 'ports' array. One sample takes ~6 us. When sampling more than one port, the samples are taken ~15 us apart giving a total of ~120 us for sampling all 8 analog input ports.

Note:
Mio_Port_P10 must be configured as Mio_PortMode_Vref and a Vref voltage supplied to Mio_Port_P10, othervice this function will not return meaningful values.
Returns:
Mio_Rc_OK if success, else some error code
Parameters:
values Ptr to array where analog input values are stored; 1...8 items
ports Ptr to analog input ports; 1...8 ports (Mio_Port_P11 ... Mio_Port_P18)
num_ports Number of ports in array; 1...8

Mio_Rc Mio::GetAnalogInputValue ( int &  value,
Mio_Port  port 
) [inline]

Get analog input value from a single Mio_Port.

Same as GetAnalogInputsValues() but for a single Mio_Port.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
value Analog input values is stored here
port Analog input port (Mio_Port_P11 ... Mio_Port_P18)

Mio_Rc Mio::StartDS18x20Task ( int  task_id,
Mio_Port  mio_port,
Mio_DS18x20Type  sensor_type,
unsigned  conversion_time_x100ms 
)

Start a DS18x20 temperature sensor measurement task.

The function will internally configure the selected Mio_Port for temperature measurement. The temperature is measured periodically by a task. The measurement interval time is specified with 'conversion_time_x100ms' which can be from 0,1 - 25,5 seconds.

Note:
The DS18x20 sensor typically needs a temperature conversion time of 200 ms and in worst case up to 750 ms. Set 'conversion_time_x100ms' accordingly!

The DS18x20 sensor needs an external 4k7 pull-up resistor on the 1-wire data line. When only using the weak internal pull-ups of the MIO board, MIO will detect the sensor, but reading the temperature will give wrong results.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
task_id Task id: 0 ... Mio_TaskMaxTaskId
mio_port Mio_Port to be used as 1-wire data interface to the sensor
sensor_type DS18x20 sensor type
conversion_time_x100ms Temperature conversion interval [1...255] in multiples of 100 ms

Mio_Rc Mio::GetDS18x20TaskTemperature ( int &  temperature,
unsigned char &  sn,
Mio_DS18x20Error error,
int  task_id 
)

Get DS18x20 temperature.

Get the latest temperature measurement result from the DS18x20 task that was started with StartDS18x20Task().

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
temperature Temperature in deci-Celsius
sn Measurement sequence number. 0 = no measurement ready yet, after that sn is 1...255,1...255,1...
error Sensor error
task_id Id of DS18x20 task

Mio_Rc Mio::StopTask ( int  task_id  ) 

Stop a task.

The function stops the specified task that has been started with any of the StartXXXTask() functions.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
task_id Task id: 0 ... Mio_TaskMaxTaskId

static Mio_Rc Mio::ConvertPWMOutValues ( Mio_PWMClockSpeed pwm_clock_speed,
int &  pwm_period,
PWMOutSubchannelConfig  dst_subchannels[3],
float  pwm_frequency,
const PWMOutSubchannelConfig2  src_subchannels[3] 
) [static]

Convert from frequency/duty cycle PWM values to PWM clock tick values.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_speed OUT: Calculated PWM clock speed is stored here
pwm_period OUT: Calculated PWM period width (in PWM clock ticks): 1 ... 65536 is stored here
dst_subchannels OUT: Calculated PWM subchannel config info is stored here
pwm_frequency IN: PWM frequency (in Hz): ~10.0 ... ~400000.0
src_subchannels PWM subchannel config info to convert

Mio_Rc Mio::StartPWMOut ( int  pwm_clock_channel,
Mio_PWMClockSpeed  pwm_clock_speed,
int  pwm_period,
const PWMOutSubchannelConfig  subchannels[3] 
)

Start PWM output (generation) on 1...3 PWM subchannels.

Configure a PWM clock channel in PWM output mode, with one of the following clock speeds; 20MHz, 10MHz, 5MHz, 2.5MHz or 625 kHz. A PWM clock channel in output mode has 3 independent 16-bit PWM subchannels which can output PWM signals. The 3 subchannels are syncronised, i.e. their PWM periods start on the same PWM clock tick.

The subchannels are mapped onto the physical Mio_Ports as follows:

   PWM clock channel 0:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio_Port_P29
     subchannel 2   Mio_Port_P28
     subchannel 3   Mio_Port_P27

   PWM clock channel 1:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio_Port_P25
     subchannel 2   Mio_Port_P24
     subchannel 3   Mio_Port_P23

This function configures and starts 1..3 PWM subchannels on 1 PWM clock channel. The shape of the PWM signals are specified as number of PWM clock ticks.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1
pwm_clock_speed PWM clock speed
pwm_period PWM period width (in PWM clock ticks): 1 ... 65536
subchannels PWM subchannel config for subchannels 1, 2, 3

Mio_Rc Mio::StartPWMOut ( int  pwm_clock_channel,
float  pwm_frequency,
const PWMOutSubchannelConfig2  subchannels[3] 
)

Start PWM output (generation) on 1...3 PWM subchannels.

Configure a PWM clock channel in PWM output mode, with one of the following clock speeds; 20MHz, 10MHz, 5MHz, 2.5MHz or 625 kHz. A PWM clock channel in output mode has 3 independent 16-bit PWM subchannels which can output PWM signals. The 3 subchannels are syncronised, i.e. their PWM periods start on the same PWM clock tick.

The subchannels are mapped onto the physical Mio_Ports as follows:

   PWM clock channel 0:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio_Port_P29
     subchannel 2   Mio_Port_P28
     subchannel 3   Mio_Port_P27

   PWM clock channel 1:
     subchannel 0   /* not available for PWM output */
     subchannel 1   Mio_Port_P25
     subchannel 2   Mio_Port_P24
     subchannel 3   Mio_Port_P23

This function configures and starts 1..3 PWM subchannels on 1 PWM clock channel. The shape of the PWM signals are specified with PWM frequency and duty cyckle.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1
pwm_frequency PWM frequency (in Hz): ~10.0 ... ~400000.0
subchannels PWM subchannel config for subchannels 1, 2, 3

Mio_Rc Mio::AdjustPWMOut ( int  pwm_clock_channel,
Mio_PWMClockSpeed  pwm_clock_speed,
int  pwm_period,
const PWMOutSubchannelConfig  subchannels[3] 
)

Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.

Adjust ongoing PWM genration period width and shape on 1...3 PWM subchannels. The adjustment is made after the current PWM period has ended and before the next PWM period starts, to minimize glitches in the generated signals.

Note:
'config' is ignored in the subchannel config.
Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1
pwm_clock_speed PWM clock speed
pwm_period PWM period width (in PWM clock ticks): 1 ... 65536
subchannels PWM subchannel config for subchannels 1, 2, 3

Mio_Rc Mio::AdjustPWMOut ( int  pwm_clock_channel,
float  pwm_frequency,
const PWMOutSubchannelConfig2  subchannels[3] 
)

Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.

Adjust ongoing PWM genration frequency and duty cycle on 1...3 PWM subchannels. The adjustment is made after the current PWM period has ended and before the next PWM period starts, to minimize glitches in the generated signals.

Note:
'config' is ignored in the subchannel config.
Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1
pwm_frequency PWM frequency (in Hz): ~10.0 ... ~400000.0
subchannels PWM subchannel config for subchannels 1, 2, 3

Mio_Rc Mio::StartPWMIn ( int  pwm_clock_channel,
const PWMInSubchannelConfig  subchannels[4] 
)

Start PWM input (measurement) on 1...4 PWM subchannels.

Configure a PWM clock channel in PWM input mode with 20MHz clock speed. A PWM clock channel in input mode has 4 independent subchannels which can measure PWM signals.

The subchannels are mapped onto the physical Mio_Ports as follows:

   PWM clock channel 0:
     subchannel 0   Mio_Port_P30
     subchannel 1   Mio_Port_P29
     subchannel 2   Mio_Port_P28
     subchannel 3   Mio_Port_P27

   PWM clock channel 1:
     subchannel 0   Mio_Port_P26
     subchannel 1   Mio_Port_P25
     subchannel 2   Mio_Port_P24
     subchannel 3   Mio_Port_P23

When a measurement on a subchannel becomes active (using the 'config' bits in this function or using SetPWMInMode()), it will start to capture the edges of the PWM signal, up to the number of edges specified in 'edges'. When the specified number of edges has been captured, the subchannel enters idle mode. The number of edges captured so far, and the total halfperiod and period times can be polled with GetPWMInResult(). A new measurement on the subchannel can be started with SetPWMInMode().

The PWM input implementation in MIO is software assisted meaning that a software interrupt is generated in the MIO board for each edge that is captured. For reliable measurements, it's important not to overflow MIO with interrupts. MIO can reliably capture signals up to 10 kHz (minimum halfperiod pulse width is 50 us) on one subchannel. If two subchannels are used simultaneously, the maximum signal is 5 kHz, tree subchannels is 2.5 kHz, etc. If several high-frequency signals needs to be measured, the measurements should be done sequentially on one subchannel at a time. I.e. only one subchannel should be active at a time, and the other in idle mode. Sequential measurement can be acheived using SetPWMInMode().

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1
subchannels PWM subchannel config for subchannels 0, 1, 2, 3

Mio_Rc Mio::SetPWMInMode ( int  pwm_clock_channel,
int  pwm_subchannel,
Mio_PWMInMode  mode 
)

Set mode for a PWM input subchannel.

Set the PWM input subchannel mode to one of the following:

   Mio_PWMInMode_Idle            // Set subchannel in idle mode
   Mio_PWMInMode_Active          // Set subchannel in active mode (force start of a new measurement)
   Mio_PWMInMode_ActivateIfIdle  // Set subchannel in active mode only if currently in idle mode

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1
pwm_subchannel PWM subchannel: 0, 1, 2 or 3
mode PWM mode for this subchannel

Mio_Rc Mio::GetPWMInResult ( unsigned &  total_halfperiod_time,
unsigned &  total_period_time,
int &  edges_captured,
int  pwm_clock_channel,
int  pwm_subchannel 
)

Get measurement result from a PWM input subchannel.

GetPWMInResult() is used to check (poll) the current measurement result for a specific PWM input subchannel. The function returns the number of PWM edges captured so far, along with the total (accumulated) PWM halfperiod and period time in 50 ns ticks. The number of edges a measurement will capture was specified in StartPWMIn().

Initial edge captured if: edges_captured >= 1
Measurement completed if: edges_captured >= subchannels[n].edges
Number of periods captured: (edges_captured - 1) / 2

The following can be calculated when at least 1 period (3 edges) has been captured:
Duty cycle in percent: (100.0 * total_halfperiod_time) / total_period_time
Frequency in Hz: ((edges_captured - 1) / 2) / (total_period_time * 50.0E-9)
Period time in ms: total_period_time * 50.0E-6 / ((edges_captured - 1) / 2)

PWM input mode can be used to measure the width of single pulses. Number of edges should then be set to 2, and pulse polarity accordingly (Mio_PWM_POL_0 or Mio_PWM_POL_1) using StartPWMIn(). In this case, when 2 edges has been captured, total_halfperiod_time will contain the pulse width (in 50 ns ticks) and total_period_time will be zero. Please note that this is a special measurement case, as normally, when more than 2 edges are captured, total_halfperiod_time and total_period_time will only be updated at the end of each captured PWM period.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
total_halfperiod_time Total halfperiod time (in 50 ns ticks) of all halfperiods captured
total_period_time Total period time (in 50 ns ticks) of all halfperiods captured
edges_captured Number of edges in the PWM signal that has been captured
pwm_clock_channel PWM clock channel: 0 or 1
pwm_subchannel PWM subchannel: 0, 1, 2 or 3

Mio_Rc Mio::StopPWM ( int  pwm_clock_channel  ) 

Stop all PWM input/output on the selected PWM clock channel.

Stop all PWM input/output on the slected PWM clock channel and release the Mio_Ports.

Returns:
Mio_Rc_OK if success, else some error code
Parameters:
pwm_clock_channel PWM clock channel: 0 or 1

virtual Mio_Rc Mio::ResetCommunicationPort (  )  [protected, pure virtual]

Reset communication port to MIO board.

This function resets the communication port by clearing any error conditions and deleting any data currently pending in the tx and rx buffers. This function must be implemented in the derived class using the appropriate OS specific functions.

Returns:
Mio_Rc_OK if success, else some OS level error code

Implemented in MioWin32.

virtual Mio_Rc Mio::SendRawDataToMio ( const void *  data,
int  data_len 
) [protected, pure virtual]

Send an array of raw data bytes to the MIO board.

This function must be implemented in the derived class using the appropriate OS specific functions.

Returns:
Mio_Rc_OK if success, else some OS level error code
Parameters:
data Ptr to raw data
data_len Length of raw data in bytes

Implemented in MioWin32.

virtual Mio_Rc Mio::ReceiveRawDataFromMio ( void *  data,
int  data_len,
int &  data_bytes_received,
unsigned  timeout_ms 
) [protected, pure virtual]

Receive an array of raw data bytes from the MIO board.

The function is non-blocking if timeout_ms is 0, and blocking if timeout_ms is not 0.

In non-blocking mode, the function will return immediately and return as many bytes as was immediately available for reading. If number of bytes received is less than data_len; Mio_Rc_OS_DeviceReadTimeout is returned.

In blocking mode, the function does not return until data_len bytes has been received, or the timeout has elapsed in which case Mio_Rc_OS_DeviceReadTimeout is returned. When timeout occure, the returned data length is less than the requested data_len.

In both non-blocking and blocking modes, the function may return prematurely with an OS-level error.

This function must be implemented in the derived class using the appropriate OS specific functions.

Returns:
Mio_Rc_OK if success, else Mio_Rc_OS_DeviceReadTimeout or some OS level error code
Parameters:
data Ptr to buffer where received data is stored
data_len Length of data buffer (number of bytes we want to receive)
data_bytes_received Number of received data bytes is stored here (useful when timeout_ms = 0)
timeout_ms Max number of milli-seconds we want to wait for data

Implemented in MioWin32.

virtual unsigned Mio::GetCurrentTimeMs (  )  [protected, pure virtual]

Get the current time in milli-seconds.

This function must be implemented in the derived class using the appropriate OS specific functions.

Returns:
time in milli-seconds

Implemented in MioWin32.

virtual unsigned Mio::GetElapsedTimeMs ( unsigned  start_time  )  [protected, pure virtual]

Get the elapsed time in milli-seconds.

The elapsed time is calculated from start_time which was sampled with GetCurrentTimeMs(). The function must take wrapping of the sampled time into account.

This function must be implemented in the derived class using the appropriate OS specific functions.

Returns:
elapsed time in milli-seconds
Parameters:
start_time Start time to calculate elapsed time from

Implemented in MioWin32.

virtual void Mio::DispatchOutOfBandMessage ( Mio_MioMsgId  msg_id,
int  payload_len,
const void *  payload 
) [inline, protected, virtual]

"Call-back" for out-of-band messages received from MIO.

This is a call-back for out-of-band messages received from MIO. Out-of-band messages are sent on MIO's own initiative and can be received by the host at any time. Implement this function in the derived class to handle the messages.

Parameters:
msg_id Message id
payload_len Payload length
payload Ptr to payload


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

USB-MIO v1.0 C++ API     Copyright (C) 2009 by Mats Byggmastar Consulting Ab