Instantiate Fifo; Initialize Fifo - Freescale Semiconductor MMA9559L Software Reference Manual

Intelligent, motion-sensing platform
Table of Contents

Advertisement

that the scheduler may be "losing" events because one or more FIFO samples were not stored on the FIFO,
although user code may make some accommodation for this. The
by the Freescale firmware and may be used as a diagnostic to identify problems with the chosen FIFO size.
FIFOs are used with the following steps:
1. Instantiate the FIFO variable to reserve the space for the FIFO structure.
2. Initialize the FIFO at run time to configure it before it is used.
3. Push data onto the FIFO, as it becomes available.
4. Pop data off the FIFO in the tasks that process the data.
5. Reset the FIFO to discard the current contents of the FIFO and restore it to its empty state.
FIFOs are normally created as global variables so that they are always permanently allocated and are never
de-allocated. They may also be created as local variables within functions, in which case they are allocated
on the user stack. If they are on the user stack, the user must ensure that they are not referenced after they
have gone out of scope and been removed from the stack.
2.5.1

Instantiate FIFO

The data buffer and control variables for each FIFO are held in a single data structure. The data structure
can either be created on a per-instance basis or by creating a data type that enables multiple instances of
the same FIFO to be created.
A FIFO instance can be created with the FIFO_STRUCT macro, as in the following code that creates the
FIFO test_fifo. That FIFO can hold up to FIFO_MAX_ENTRIES entries, where each entry is the size of
the
mma9559_afe_data_t
FIFO_STRUCT(FIFO_MAX_ENTRIES, sizeof(mma9559_afe_data_t)) test_fifo;
An alternate method of creating a FIFO is to create a data type for the required FIFO configuration and
instantiate one or more FIFO variables from the data type with the same configuration. In the following
example, the fifo_20_t data type is created and used to create fifo_1 and fifo_2 variables:
typedef FIFO_STRUCT(10, 2) fifo_20_t;
fifo_20_t fifo1, fifo2;
2.5.2

Initialize FIFO

Once the FIFO data structure has been created through the definition of a FIFO variable, the space for the
FIFO structure has been reserved, but the contents of the FIFO structure must be initialized before it is
used. Initialization of a FIFO occurs at runtime and performs the following steps:
Sets the events that are associated with the FIFO, and reserves them in the
events_fifos
because the FIFO is now empty and contains no data.
Sets the maximum number of data entries that the FIFO can hold and the size of each data entry.
MMA9559L Intelligent, Motion-Sensing Platform Software Reference Manual, Rev. 0.1
Freescale Semiconductor, Inc.
data type.
Example 2-9.
field. It also clears the associated events, in case any events were already signaled
field is never cleared
events_missed
mma9559_vars
25

Advertisement

Table of Contents
loading

Table of Contents