DOWNLOAD

CHANGES

SCREENSHOTS

DOCUMENTATION



module whatos.embedded

This Python module extends whatos.core with a set of tasks useful for embedding into a microprocessor target board. These include: serial port, serial line IP (SLIP), signal serialization, remote debugging and resource monitoring. Below is an image showing all the tasks this module creates and how they are designed to work together (C tasks are shown in gray). Additionally a new system object is provided, remote_system, which is designed to be programmed onto a standalone target board; it automatically adds communication support for simple Python interfacing using a serial port.

embedded.png

This module also serves as an example of how third-party WhatOS extensions for specific application domains can be provided. Note: some of the tasks use WhatOS undocumented internal features.

Contents

Extras

object packet (whatos.core.wostype)

A packet whatos.core.wostype for transporting arbitrary serial data. The size of a packet is statically defined and a packet of a certain size can carry data of any length up to that size.

Example

>>> a = packet.from_python([1, 2, 3])
>>> a
{'data': '\x01\x02\x03', 'len': 3}
>>> packet.to_list(a)
[1, 2, 3]
>>> packet.to_string(a)
'\x01\x02\x03'

attribute alloc = 1

A packet is an allocated data type.

attribute format = (('len', 'B'), ('data', '3s'))

Two fields: data and len. Data contains actual data, len contains the length of the data.

attribute size = 3

Number of bytes which a packet can contain.

method from_python (self, v)

Returns a new packet wosvalue from a string, tuple, or list.

method to_list (self, v)

Returns a list from a packet wosvalue.

method to_string (self, v)

Returns a string from a packet wosvalue.

object remote_system (whatos.core.system)

A whatos.core.system which automatically adds tasks cpacker, cunpacker, csliptx, csliprx, depending on a set of signals which this system is meant to receive and a set of signals which this system is meant to transmit over a serial connection. This task exists because it is a very common situation to make a system for putting into an embedded target which communicates over the serial port.

attribute exports = ()

A list/tuple of signals (their names) which this system will transmit over a serial connection. If empty, csliptx, cpacker will not be included.

attribute imports = ()

A list/tuple of signals (their names) which this system will receive over a serial connection. If empty, csliprx, cunpacker will not be included.

Tasks

object cdelay (whatos.core.ctask)

A simple multi-channel C timer task. It can be used to generate programmable time delays and to measure delay between discrete events.

inputs
  • delay_start_<channel>(wuint16)
  • tick()
outputs
  • delay_end_<channel>(wuint16)

<channel> is the name of a channel. The actual number of inputs/outputs are determined by the channels attribute. All channels behave identically and independently. The behavior:

  • Receive delay_start(number_of_ticks)
  • Start counting down from number_of_ticks. When counter gets to zero emit delay_end(0).
  • If we receive delay_start again before the counter has reached zero, we emit delay_end(number_of_ticks_remaining)

attribute channels = ()

A tuple/list containing names of the channels.

object cmonitor (whatos.core.ctask)

A C task which is typically included into an embedded system for debugging and monitoring purposes. It accesses operating system internals to provide information including cpu usage, memory usage, system response time, system signature, reading and writing arbitrary RAM locations.

Although you may send signals manually to a cmonitor it is more convenient to use a pymonitor on the host side.

inputs
  • wos_req_cpu_usage()
  • wos_req_periodic_statistics()
  • wos_req_allocator_statistics()
  • wos_req_lost_signals()
  • wos_req_signature()
  • wos_req_read_ram(packet)
  • wos_write_ram(packet)
outputs

I need to document the data format of the input requests and output responses. For now looking at the source code should be sufficient. Also, you do not have to deal with this if you let pymonitor to generate requests and interpret responses.

attribute num_types = 0

The number of allocated types in the system. This is needed to know how big the packet should be.

object cpacker (whatos.core.ctask)

Serializes input signals into packets which can be deserialized by a cunpacker or a pyunpacker.

inputs
  • None. Either clone and define inputs or clone and set cunpacker attribute to make inputs equal to the cunpacker outputs.
outputs

See pyunpacker for an example.

attribute cunpacker = None

Clone and set this to a cunpacker to make a new cpacker compatible with the cunpacker. Do not use this if defining inputs manually.

attribute serid = 0

An integer (0-255) which identifies this serializer. An unpacker will look for a matching serializer id in the input packet.

object csliprx (whatos.core.cautotask)

C SLIP receiver.

inputs
  • sub_rx_byte(wuint8)
outputs

object csliptx (whatos.core.cautotask)

C SLIP transmitter.

inputs
  • tx_packet(packet)
  • sub_tx_rdy() : Ready to send a new byte. Typically connected to a micro-controller UART tx_rdy interrupt event.
outputs
  • sub_tx_byte(wuint8)

object cunpacker (whatos.core.ctask)

Deserializes signals from a packet created by a cpacker or a pypacker.

inputs
outputs
  • None. Either clone and define outputs or clone and set cpacker attribute to make outputs equal to the cpacker inputs.

See pypacker for an example.

attribute cpacker = None

Clone and set this to a cpacker to make a new cunpacker compatible with the cpacker. Do not use this if defining outputs manually.

attribute serid = 0

An integer (0-255) which identifies this serializer. An unpacker will look for a matching serializer id in the input packet.

object monitor_viewer

A viewer used to view various pymonitor events. Clone and customize.

method cpu_usage (self, v)

Displays cpu usage information. Does nothing.

method log (self, s)

Displays text messages. Does nothing.

method status (self, s)

Displays target connection status (online/offline).

object pymonitor (whatos.core.pytask)

A host-side user-friendly interface to interract with an embedded target containing a cmonitor task.

attribute cmonitor = None

The cmonitor task which exists on the target. Note: the cmonitor must be part of a system.

attribute viewer = <obj 'monitor_printer'>

A monitor_viewer object used to display information.

method check_signature (self)

Verify that the system programmed onto the target is the same as the system which contains the cmonitor. If there is any discrepancy, communication behavior is undefined.

method read_ram (self, address, len)

Read an array of bytes from a certain target RAM location. The total number of bytes which may be read at once is limited to packet.size - 2.

method start (self)

Start polling for cpu usage every 0.5 s.

method stop (self)

Stop polling for cpu_usage.

method write_ram (self, address, values)

Write an array of bytes to a certain target RAM location. The total number of bytes which may be written at once is limited to packet.size - 4.

object pypacker (whatos.core.pytask)

Serializes input signals into packets which can be deserialized by a cunpacker.

inputs
  • None. Clone and set cunpacker attribute to make inputs equal to the cunpacker outputs.
outputs

An example is shown below. Note that cunpacker must be part of a system (i.e., all inputs/outputs must be completely defined signals, not ports).

from whatos.embedded import *

csystem = system(cunpacker = cunpacker(serid = 1,
                                       wuint8 = wuint8(),
                                       a = output('a', type = 'wuint8'),
                                       b = output('b'),
                                       ))

pysystem = system(pypacker = pypacker(cunpacker = csystem.cunpacker))

attribute cunpacker = None

Clone and set this to a cunpacker to make a new pypacker compatible with the cunpacker.

object pysliprx (whatos.core.pyautotask)

Python SLIP receiver.

inputs
  • sub_rx_byte(wuint8)
outputs

attribute compile_code = 1

object pysliptx (whatos.core.pytask)

Python SLIP transmitter.

inputs
outputs
  • sub_tx_byte(wuint8)

object pyunpacker (whatos.core.pytask)

Deserializes signals from a packet created by a cpacker.

inputs
outputs
  • None. Clone and set cpacker attribute to make outputs equal to the cpacker inputs.

An example is shown below. Note that cpacker must be part of a system (i.e., all inputs/outputs must be completely defined signals, not ports).

from whatos.embedded import *

csystem = system(cpacker = cpacker(serid = 1,
                                   wuint8 = wuint8(),
                                   a = input('a', type = 'wuint8'),
                                   b = input('b'),
                                   ))
pysystem = system(pyunpacker = pyunpacker(cpacker = csystem.cpacker))

attribute cpacker = None

Clone and set this to a cpacker to make a new pyunpacker compatible with the cpacker.

object uart (whatos.core.pytask)

Python threaded serial port communication.

inputs
  • rx_byte(wuint8)
outputs
  • tx_byte(wuint8)

This task uses thid-party software called pyserial (whatos_third_party/serial). The single class Serial is imported automatically in whatos.embedded. This document does not give the full documentation for class Serial, but a very common example is shown below:

class a_system(system):
    uart = uart(serial = Serial(port = '/dev/ttyUSB0', baudrate = 4800))
# uart is threaded so we need to start system thread
a_system.threadstart()

attribute enabled = 0

When set to 1 serial port TX and RX enabled.

attribute serial = None

A pyserial Serial instance (serial port connection).

object uartslip (whatos.core.pytask)

Provides functionality of pysliptx, pysliprx, and uart but is more efficient. Useful for high speed data streams.

inputs
outputs

attribute enabled = 0

When set to 1 serial port TX and RX enabled.

attribute serial = None

A pyserial Serial instance (serial port connection).
© Mircea Hossu () WhatOS 2.0.3  (2006 Feb 26)