ME405: Mechatronics
Project Documentation and Portfolio by Neil Patel
task_share.Share Class Reference

This class implements a shared data item which can be protected against data corruption by pre-emptive multithreading. More...

Public Member Functions

def __init__ (self, type_code, thread_protect=True, name=None)
 Allocate memory in which the shared data will be buffered. 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)
 This method 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.
 

Detailed Description

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 a Real-Time Operating System (RTOS).

Constructor & Destructor Documentation

◆ __init__()

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

Allocate memory in which the shared data will be buffered.

The data type code is given as for the Python 'array' type, which can be any of

  • b (signed char), B (unsigned char)
  • h (signed short), H (unsigned short)
  • i (signed int), I (unsigned int)
  • l (signed long), L (unsigned long)
  • q (signed long long), Q (unsigned long long)
  • f (float), or 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

Member Function Documentation

◆ get()

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

Read an item of data from the share.

Interrupts are disabled as the data is 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.

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: