Plot Something - ME 405 Term Project
|
An item which holds data to be shared between tasks. More...
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. | |
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:
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) |
type_code | The type of data items which the share can hold |
thread_protect | True if mutual exclusion protection is used |
name | A short name for the share, default ShareN where N is a serial number for the share |
Reimplemented from task_share.BaseShare.
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.
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.
in_ISR | Set this to True if calling from within an ISR |
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.
data | The data to be put into this share |
in_ISR | Set this to True if calling from within an ISR |