ISSDK  1.7
IoT Sensing Software Development Kit
control.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*! \file control.h
36  \brief Defines control sub-system
37 
38  Each sensor fusion application will probably have its own set of functions
39  to control the fusion process and report results. This file defines the
40  programming interface that should be followed in order for the fusion functions
41  to operate correctly out of the box. The actual command interpreter is
42  defined separately in DecodeCommandBytes.c. The output streaming function
43  is defined in output_stream.c. Via these three files, the NXP Sensor Fusion
44  Library provides a default set of functions which are compatible with the
45  Sensor Fusion Toolbox. Use of the toolbox is highly recommended at least
46  during initial development, as it provides many useful debug features.
47  The NXP development team will typically require use of the toolbox as a
48  pre-requisite for providing software support.
49 */
50 
51 // Requires sensor_fusion.h to occur first in the #include stackup
52 #ifndef SENSOR_FUSION_CONTROL_H_
53 #define SENSOR_FUSION_CONTROL_H_
54 
55 /// @name Control Port Function Type Definitions
56 /// The "write" and "stream" commands provide two control functions visible at the main()
57 /// level. These typedefs define the structure of those two calls.
58 ///@{
59 typedef int8_t (writePort_t) (struct ControlSubsystem *pComm, uint8_t buffer[], uint16_t nbytes);
61 ///@}
62 
63 /// \brief he ControlSubsystem encapsulates command and data streaming functions.
64 ///
65 /// The ControlSubsystem encapsulates command and data streaming functions
66 /// for the library. A C++-like typedef structure which includes executable methods
67 /// for the subsystem is defined here.
68 typedef struct ControlSubsystem {
69  quaternion_type DefaultQuaternionPacketType; ///< default quaternion transmitted at power on
70  volatile quaternion_type QuaternionPacketType; ///< quaternion type transmitted over UART
71  volatile uint8_t AngularVelocityPacketOn; ///< flag to enable angular velocity packet
72  volatile uint8_t DebugPacketOn; ///< flag to enable debug packet
73  volatile uint8_t RPCPacketOn; ///< flag to enable roll, pitch, compass packet
74  volatile uint8_t AltPacketOn; ///< flag to enable altitude packet
75  volatile int8_t AccelCalPacketOn; ///< variable used to coordinate accelerometer calibration
76  writePort_t *write; ///< low level function to write a char buffer to the serial stream
77  streamData_t *stream; ///< function to create packets for serial stream
79 
80 int8_t initializeControlPort(ControlSubsystem *pComm); ///< Call this once to initialize structures, ports, etc.
81 
82 // Located in output_stream.c:
83 /// Called once per fusion cycle to stream information required by the NXP Sensor Fusion Toolbox.
84 /// Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
86 
87 // Located in DecodeCommandBytes.c:
88 /// This function is responsible for decoding commands sent by the NXP Sensor Fusion Toolbox and setting
89 /// the appropriate flags in the ControlSubsystem data structure.
90 /// Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
91 void DecodeCommandBytes(SensorFusionGlobals *sfg, char iCommandBuffer[], uint8 sUART_InputBuffer[], uint16 nbytes);
92 
93 /// Used to initialize the Blue Radios Bluetooth module found on the
94 /// FRDM-FXS-MULT2-B sensor shield from NXP.
95 void BlueRadios_Init(void);
96 
97 /// Utility function used to place data in output buffer about to be transmitted via UART
98 void sBufAppendItem(uint8_t *pDest, uint16_t *pIndex, uint8_t *pSource, uint16_t iBytesToCopy);
99 
100 // externals
101 extern uint8_t sUARTOutputBuffer[256]; ///< main output buffer defined in control.c
102 
103 #endif /* SENSOR_FUSION_CONTROL_H_ */
enum quaternion quaternion_type
the quaternion type to be transmitted
volatile quaternion_type QuaternionPacketType
quaternion type transmitted over UART
Definition: control.h:70
int8_t() writePort_t(struct ControlSubsystem *pComm, uint8_t buffer[], uint16_t nbytes)
Definition: control.h:59
void BlueRadios_Init(void)
Definition: control.c:136
SensorFusionGlobals sfg
writePort_t * write
low level function to write a char buffer to the serial stream
Definition: control.h:76
volatile uint8_t AltPacketOn
flag to enable altitude packet
Definition: control.h:74
uint8_t uint8
Definition: sensor_fusion.h:68
he ControlSubsystem encapsulates command and data streaming functions.
Definition: control.h:68
volatile uint8_t AngularVelocityPacketOn
flag to enable angular velocity packet
Definition: control.h:71
The top level fusion structure.
quaternion_type DefaultQuaternionPacketType
default quaternion transmitted at power on
Definition: control.h:69
int8_t initializeControlPort(ControlSubsystem *pComm)
Call this once to initialize structures, ports, etc.
Definition: control.c:186
void sBufAppendItem(uint8_t *pDest, uint16_t *pIndex, uint8_t *pSource, uint16_t iBytesToCopy)
Utility function used to place data in output buffer about to be transmitted via UART.
Definition: output_stream.c:63
void CreateAndSendPackets(SensorFusionGlobals *sfg, uint8_t *sUARTOutputBuffer)
volatile uint8_t RPCPacketOn
flag to enable roll, pitch, compass packet
Definition: control.h:73
void() streamData_t(SensorFusionGlobals *sfg, uint8_t *sUARTOutputBuffer)
Definition: control.h:60
struct ControlSubsystem ControlSubsystem
he ControlSubsystem encapsulates command and data streaming functions.
streamData_t * stream
function to create packets for serial stream
Definition: control.h:77
void DecodeCommandBytes(SensorFusionGlobals *sfg, char iCommandBuffer[], uint8 sUART_InputBuffer[], uint16 nbytes)
uint16_t uint16
Definition: sensor_fusion.h:69
volatile int8_t AccelCalPacketOn
variable used to coordinate accelerometer calibration
Definition: control.h:75
uint8_t sUARTOutputBuffer[256]
main output buffer defined in control.c
Definition: control.c:63
volatile uint8_t DebugPacketOn
flag to enable debug packet
Definition: control.h:72