ME405 Library  Version 0.38
Python library in support of ME405 class
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

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

Static Public Attributes

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

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

Constructor & Destructor Documentation

◆ __init__()

def 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

Reimplemented from task_share.BaseShare.

Member Function Documentation

◆ __repr__()

def 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.

◆ get()

def 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

◆ put()

def 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

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