ISSDK  1.8
IoT Sensing Software Development Kit
control.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /*! \file control.h
10  \brief Defines control sub-system
11 
12  Each sensor fusion application will probably have its own set of functions
13  to control the fusion process and report results. This file defines the
14  programming interface that should be followed in order for the fusion functions
15  to operate correctly out of the box. The actual command interpreter is
16  defined separately in DecodeCommandBytes.c. The output streaming function
17  is defined in output_stream.c. Via these three files, the NXP Sensor Fusion
18  Library provides a default set of functions which are compatible with the
19  Sensor Fusion Toolbox. Use of the toolbox is highly recommended at least
20  during initial development, as it provides many useful debug features.
21  The NXP development team will typically require use of the toolbox as a
22  pre-requisite for providing software support.
23 */
24 
25 // Requires sensor_fusion.h to occur first in the #include stackup
26 #ifndef SENSOR_FUSION_CONTROL_H_
27 #define SENSOR_FUSION_CONTROL_H_
28 
29 /// @name Control Port Function Type Definitions
30 /// The "write" and "stream" commands provide two control functions visible at the main()
31 /// level. These typedefs define the structure of those two calls.
32 ///@{
33 typedef int8_t (writePort_t) (struct ControlSubsystem *pComm, uint8_t buffer[], uint16_t nbytes);
35 ///@}
36 
37 /// \brief he ControlSubsystem encapsulates command and data streaming functions.
38 ///
39 /// The ControlSubsystem encapsulates command and data streaming functions
40 /// for the library. A C++-like typedef structure which includes executable methods
41 /// for the subsystem is defined here.
42 typedef struct ControlSubsystem {
43  quaternion_type DefaultQuaternionPacketType; ///< default quaternion transmitted at power on
44  volatile quaternion_type QuaternionPacketType; ///< quaternion type transmitted over UART
45  volatile uint8_t AngularVelocityPacketOn; ///< flag to enable angular velocity packet
46  volatile uint8_t DebugPacketOn; ///< flag to enable debug packet
47  volatile uint8_t RPCPacketOn; ///< flag to enable roll, pitch, compass packet
48  volatile uint8_t AltPacketOn; ///< flag to enable altitude packet
49  volatile int8_t AccelCalPacketOn; ///< variable used to coordinate accelerometer calibration
50  writePort_t *write; ///< low level function to write a char buffer to the serial stream
51  streamData_t *stream; ///< function to create packets for serial stream
53 
54 int8_t initializeControlPort(ControlSubsystem *pComm); ///< Call this once to initialize structures, ports, etc.
55 
56 // Located in output_stream.c:
57 /// Called once per fusion cycle to stream information required by the NXP Sensor Fusion Toolbox.
58 /// Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
60 
61 // Located in DecodeCommandBytes.c:
62 /// This function is responsible for decoding commands sent by the NXP Sensor Fusion Toolbox and setting
63 /// the appropriate flags in the ControlSubsystem data structure.
64 /// Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
65 void DecodeCommandBytes(SensorFusionGlobals *sfg, char iCommandBuffer[], uint8 sUART_InputBuffer[], uint16 nbytes);
66 
67 /// Used to initialize the Blue Radios Bluetooth module found on the
68 /// FRDM-FXS-MULT2-B sensor shield from NXP.
69 void BlueRadios_Init(void);
70 
71 /// Utility function used to place data in output buffer about to be transmitted via UART
72 void sBufAppendItem(uint8_t *pDest, uint16_t *pIndex, uint8_t *pSource, uint16_t iBytesToCopy);
73 
74 // externals
75 extern uint8_t sUARTOutputBuffer[256]; ///< main output buffer defined in control.c
76 
77 #endif /* SENSOR_FUSION_CONTROL_H_ */
quaternion_type DefaultQuaternionPacketType
default quaternion transmitted at power on
Definition: control.h:43
void CreateAndSendPackets(SensorFusionGlobals *sfg, uint8_t *sUARTOutputBuffer)
volatile uint8_t RPCPacketOn
flag to enable roll, pitch, compass packet
Definition: control.h:47
enum quaternion quaternion_type
the quaternion type to be transmitted
void BlueRadios_Init(void)
Definition: control.c:110
volatile uint8_t AngularVelocityPacketOn
flag to enable angular velocity packet
Definition: control.h:45
writePort_t * write
low level function to write a char buffer to the serial stream
Definition: control.h:50
struct ControlSubsystem ControlSubsystem
he ControlSubsystem encapsulates command and data streaming functions.
The top level fusion structure.
volatile uint8_t DebugPacketOn
flag to enable debug packet
Definition: control.h:46
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:37
volatile quaternion_type QuaternionPacketType
quaternion type transmitted over UART
Definition: control.h:44
he ControlSubsystem encapsulates command and data streaming functions.
Definition: control.h:42
void() streamData_t(SensorFusionGlobals *sfg, uint8_t *sUARTOutputBuffer)
Definition: control.h:34
int8_t initializeControlPort(ControlSubsystem *pComm)
Call this once to initialize structures, ports, etc.
Definition: control.c:160
volatile uint8_t AltPacketOn
flag to enable altitude packet
Definition: control.h:48
SensorFusionGlobals sfg
void DecodeCommandBytes(SensorFusionGlobals *sfg, char iCommandBuffer[], uint8 sUART_InputBuffer[], uint16 nbytes)
uint8_t sUARTOutputBuffer[256]
main output buffer defined in control.c
Definition: control.c:37
uint8_t uint8
Definition: sensor_fusion.h:42
uint16_t uint16
Definition: sensor_fusion.h:43
int8_t() writePort_t(struct ControlSubsystem *pComm, uint8_t buffer[], uint16_t nbytes)
Definition: control.h:33
streamData_t * stream
function to create packets for serial stream
Definition: control.h:51
volatile int8_t AccelCalPacketOn
variable used to coordinate accelerometer calibration
Definition: control.h:49