Download MMA9559L Intelligent, Motion-Sensing Platform Software Reference

Transcript
Chapter 3 User Code Example
The functionality of the device is determined by the user firmware. This section shows sample code that
can be used as a template for creating that firmware.
The following code usually would be contained in a single file. The code is split into four sections:
• Header
• User exception handler
• User trap handler
• User main
Each of the sections is required, except the user trap handler, which is optional and usually not needed.
3.1
Header
The user code should include the mma9559.h header file, instantiate the key global variables, assign event
bits, and set the FOPT value that is loaded from address 0x3FFE.
Example 3-1.
#include "derivative.h"
#include "mma9559.h"
// include peripheral declarations
// include mma9559 firmware functions
// User assignment of event bits (0 to 31)
#define EVENT_AFE_DATA
(0) // AFE conversion is complete
#define EVENT_SLAVE_PORT (1) // write to the slave port mailboxes completes
// Set Flash Options to enable boot from Flash
word flash_opt @0x3FFE = 0x0337;
// //FOPT_BF_MASK
|
// This bit is inverted so leave
//
// blank for boot from flash.
// FOPT_CHECKB_MASK |
// Do not perform Flash CRC
// FOPT_PW_MASK
|
// PROTB writable
// FOPT_PROTB_MASK |
// Flash Array NOT protected
// FOPT_SSW_MASK
|
// Security State Writable
// FOPT_SSC_MASK;
// Security State = Unsecured
// Instantiate global variables
// Use a pointer to access the MMA9559 firmware variables
mma9559_vars_t *mma9559_vars_ptr;
MMA9559L Intelligent, Motion-Sensing Platform Software Reference Manual, Rev. 0.1
Freescale Semiconductor, Inc.
31