ME 405 Romi
Loading...
Searching...
No Matches
task_share.Share Class Reference

An item which holds data to be shared between tasks. More...

Inheritance diagram for task_share.Share:
Collaboration diagram for task_share.Share:

Public Member Functions

 __init__ (self, type_code, thread_protect=True, name=None)
 Create a shared data item used to transfer data between tasks.
 put (self, data, in_ISR=False)
 Write an item of data into the share.
 get (self, in_ISR=False)
 Read an item of data from the share.
 __repr__ (self)
 Puts diagnostic information about the share into a string.

Static Public Attributes

int ser_num = 0
 A counter used to give serial numbers to shares for diagnostic use.

Protected Attributes

 _buffer = array.array (type_code, [0])
str _name

Detailed Description

An item which holds data to be shared between tasks.

This class implements a shared data item which can be protected against data corruption by pre-emptive multithreading. Multithreading which can corrupt shared data includes the use of ordinary interrupts as well as the use of pre-emptive multithreading such as by a Real-Time Operating System (RTOS).

An example of the creation and use of a share is as follows:

import task_share
# This share holds a signed short (16-bit) integer
my_share = task_share.Queue ('h', name="My Share")
# Somewhere in one task, put data into the share
my_share.put (some_data)
# In another task, read data from the share
something = my_share.get ()
A queue which is used to transfer data from one task to another.
Definition task_share.py:90

Definition at line 324 of file task_share.py.

Constructor & Destructor Documentation

◆ __init__()

task_share.Share.__init__ ( self,
type_code,
thread_protect = True,
name = None )

Create a shared data item used to transfer data between tasks.

This method allocates memory in which the shared data will be buffered.

Each share can only carry data of one particular type which must be chosen from the following list. The data type is specified by a one-letter type code which is given as for the Python array.array type, which can be any of the following:

b (signed char) B (unsigned char) 8 bit integers
h (signed short) H (unsigned short) 16 bit integers
i (signed int) I (unsigned int) 32 bit integers (probably)
l (signed long) L (unsigned long) 32 bit integers
q (signed long long) Q (unsigned long long) 64 bit integers
f (float) d (double-precision float)
Parameters
type_codeThe type of data items which the share can hold
thread_protectTrue if mutual exclusion protection is used
nameA short name for the share, default ShareN where N is a serial number for the share

Definition at line 351 of file task_share.py.

Member Function Documentation

◆ __repr__()

task_share.Share.__repr__ ( self)

Puts diagnostic information about the share into a string.

Shares are pretty simple, so we just put the name and type.

Definition at line 408 of file task_share.py.

◆ get()

task_share.Share.get ( self,
in_ISR = False )

Read an item of data from the share.

If thread protection is enabled, interrupts are disabled during the time that the data is being read so as to prevent data corruption by changes in the data as it is being read.

Parameters
in_ISRSet this to True if calling from within an ISR

Definition at line 391 of file task_share.py.

◆ put()

task_share.Share.put ( self,
data,
in_ISR = False )

Write an item of data into the share.

This method puts data into the share; any old data is overwritten. This code disables interrupts during the writing so as to prevent data corrupting by an interrupt service routine which might access the same data.

Parameters
dataThe data to be put into this share
in_ISRSet this to True if calling from within an ISR

Definition at line 371 of file task_share.py.

Member Data Documentation

◆ _buffer

task_share.Share._buffer = array.array (type_code, [0])
protected

Definition at line 355 of file task_share.py.

◆ _name

task_share.Share._name
protected
Initial value:
= None \
else 'Share' + str (Share.ser_num)

Definition at line 357 of file task_share.py.

◆ ser_num

int task_share.Share.ser_num = 0
static

A counter used to give serial numbers to shares for diagnostic use.

Definition at line 327 of file task_share.py.


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