| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
isf_dsa_direct.c
Go to the documentation of this file.
1 /*
2 * isf_dsa_direct.c
3 *
4 * Created on: Jul 10, 2014
5 * Author: B37804
6 */
7 #include "isf_dsa_direct.h"
8
9
10 /*!
11 * @brief This is the external declaration of the DSA sensor list array containing
12 * the sensor adapters and sensor hardware mapping information.
13 */
14 extern const isf_SensorConfig_t gSensorList[];
15
16
17 extern isf_SensorHandle_t gSensorHandleList[]; // Array that holds the dynamic/runtime sensor data for each sensor.
18
19 /*!
20 * @brief This function initializes the sensor adapters in the absence of the Sensor Manager
21 *
22 * @param [in] nSensorID The index of the sensor in the gSensorList array to initialize
23 * @param [in] pSensorAdapterHandle The handled to the Sensor Adapter.
24 * @param [in] pEventGroup Event Group for Sensor Adapter to signal on new data available
25 * @param [in] nEventFieldIndex Event Flag for Sensor Adapter to signal on new data available
26 *
27 * @return init_sensors() returns a pointer to a sensor handle
28 *
29 * @retval non-NULL The initialization succeeded and the return value is a valid sensor handle
30 *
31 * @retval NULL The initialization failed
32 *
33 * @Constraints Must only be called once for a given sensor index.
34 *
35 * @Reentrant No.
36 **/
37 int32 init_sensor
38 (
39 uint8 nSensorID,
40 isf_SensorHandle_t *pSensorAdapterHandle,
41 LWEVENT_STRUCT *pEventGroup,
42 uint32 nEventFieldIndex
43 )
44 {
45 int32 retval;
46
47 // Check for memory allocation error here.
48 if (pSensorAdapterHandle == NULL)
49 {
50 return ERR_INVALID_HANDLE;
51 }
52 //
53 // Initialize the SensorAdapterHandle
54 //
55
56 if (pEventGroup == NULL)
57 {
58 return ERR_INVALID_PTR;
59 }
60
61 // Establish the handle's link to the static sensor configuration data
62 pSensorAdapterHandle->pSensorStaticConfig = &gSensorList[nSensorID];
63 pSensorAdapterHandle->adapterStatus = DSA_STATE_NOT_INITIALIZED; // This is currently checked in the DSAs prior to performing initialization- need to remove this
64
65 pSensorAdapterHandle->controlData.pEventGroup = pEventGroup; // Event Group for Sensor Adapter to signal after depositing next sample in pDataBuf
66 pSensorAdapterHandle->controlData.nEventFieldIndex = nEventFieldIndex; // Event flag for Sensor Adapter to signal after depositing next sample in pDataBuf
67
68 // Initialize the Device Descriptor pointer to NULL prior to calling the adapter's Initialize routine
69 // The Initialize() routine will allocate and assign the pointer.
70 pSensorAdapterHandle->pDeviceDescriptor = NULL;
71
72 // Call the adapter's Initialize function
73 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.Initialize(pSensorAdapterHandle);
74 if (retval != ISF_SUCCESS)
75 {
76 return retval;
77 }
78
79 // Mark the sensor as initialized
80 pSensorAdapterHandle->adapterStatus = DSA_STATE_INITIALIZED;
81
82 return ISF_SUCCESS;
83 }
84
85 int32 configure_sensor(isf_SensorHandle_t *pSensorAdapterHandle, isf_SubscriptionSettings_t *pRequiredSettings, isf_fifo_t *pfifo)
86 {
87 int32 retval;
88 isf_dsa_SensorSettings_t *pSensorSettings = &(pSensorAdapterHandle->controlData.sensorSettings);
89
90 pSensorSettings->pSampleBufferInfo = pfifo;
91 pSensorSettings->nSamplePeriod = pRequiredSettings->nSamplePeriod;
92 pSensorSettings->resultType = pRequiredSettings->resultType;
93 pSensorSettings->resultFormat = pRequiredSettings->resultFormat;
94
95 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.ValidateSettings(pSensorAdapterHandle, pSensorSettings );
96 if ( retval == ISF_SUCCESS )
97 {
98 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.Configure(pSensorAdapterHandle, pSensorSettings );
99 }
100 else
101 {
102 pRequiredSettings->nSamplePeriod = pSensorSettings->nSamplePeriod;
103 pRequiredSettings->resultType = pSensorSettings->resultType;
104 pRequiredSettings->resultFormat = pSensorSettings->resultFormat;
105 }
106 return retval;
107 }
108
109 int32 start_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
110 {
111 int32 retval;
112 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.StartData(pSensorAdapterHandle);
113 return retval;
114 }
115
116 int32 stop_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
117 {
118 int32 retval;
119 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.EndData(pSensorAdapterHandle);
120 return retval;
121 }
122
123 int32 shutdown_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
124 {
125 int32 retval;
126 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.Shutdown(pSensorAdapterHandle);
127 return retval;
128 }
129
130 int32 convert_sensor_data(
131 isf_SensorHandle_t *pSensorAdapterHandle,
132 isf_SensorDataTypes_t convertToType,
133 isf_dsa_result_types_t resultType,
134 void *nativeSample, void *convertedSample)
135 {
136 int32 retval;
137 int32 numBytes;
138
139 retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.Convert(pSensorAdapterHandle, convertToType, resultType, nativeSample, convertedSample,&numBytes);
140 return retval;
141 }
142
143
144
145
146
147
148
isf_SensorHandle_st::pDeviceDescriptor
void * pDeviceDescriptor
Definition: isf_dsa_adapter.h:111
configure_sensor
int32 configure_sensor(isf_SensorHandle_t *pSensorAdapterHandle, isf_SubscriptionSettings_t *pRequiredSettings, isf_fifo_t *pfifo)
Definition: isf_dsa_direct.c:85
uint8
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
shutdown_sensor
int32 shutdown_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
Definition: isf_dsa_direct.c:123
stop_sensor
int32 stop_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
Definition: isf_dsa_direct.c:116
SensorConfig_st
This defines the DSA sensor configuration structure defining each individual sensor adapter in the DS...
Definition: isf_dsa_adapter.h:154
isf_dsa_ControlInterface_st::StartData
isf_dsa_status_t(* StartData)(isf_SensorHandle_t *pSensorHandle)
Definition: isf_dsa_adapter.h:132
isf_dsa_ControlInterface_st::EndData
isf_dsa_status_t(* EndData)(isf_SensorHandle_t *pSensorHandle)
Definition: isf_dsa_adapter.h:133
ISF_SUCCESS
Definition: isf.h:33
isf_SensorHandle_st::controlData
isf_dsa_ControlData_t controlData
Definition: isf_dsa_adapter.h:113
SensorConfig_st::pAdapter
const isf_dsa_Adapter_t * pAdapter
Definition: isf_dsa_adapter.h:156
isf_SensorHandle_st
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
Definition: isf_dsa_adapter.h:109
ERR_INVALID_PTR
#define ERR_INVALID_PTR
Definition: isf_dsa_direct_types.h:19
isf_SubscriptionSettings_t::resultFormat
isf_dsa_result_types_t resultFormat
The format of the data to be returned- 0=RAW, 1=FIXED, 2=FLOAT.
Definition: isf_dsa_direct_types.h:26
isf_dsa_SensorSettings_st::nSamplePeriod
uint32 nSamplePeriod
Definition: isf_dsa_adapter.h:84
isf_dsa_Adapter_st::control
isf_dsa_ControlInterface_t control
Definition: isf_dsa_adapter.h:147
init_sensor
int32 init_sensor(uint8 nSensorID, isf_SensorHandle_t *pSensorAdapterHandle, LWEVENT_STRUCT *pEventGroup, uint32 nEventFieldIndex)
This function initializes the sensor adapters in the absence of the Sensor Manager.
Definition: isf_dsa_direct.c:38
isf_dsa_ControlInterface_st::ValidateSettings
isf_dsa_status_t(* ValidateSettings)(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
Definition: isf_dsa_adapter.h:130
uint32
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
ERR_INVALID_HANDLE
#define ERR_INVALID_HANDLE
Definition: isf_dsa_direct_types.h:18
isf_dsa_direct.h
isf_dsa_ControlInterface_st::Convert
isf_dsa_data_converter_t * Convert
Definition: isf_dsa_adapter.h:136
DSA_STATE_INITIALIZED
Definition: isf_dsa_adapter.h:60
isf_dsa_ControlInterface_st::Configure
isf_dsa_status_t(* Configure)(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
Definition: isf_dsa_adapter.h:131
isf_dsa_result_types_t
enum isf_dsa_result_enums isf_dsa_result_types_t
isf_dsa_SensorSettings_st::resultFormat
isf_dsa_result_types_t resultFormat
Definition: isf_dsa_adapter.h:86
convert_sensor_data
int32 convert_sensor_data(isf_SensorHandle_t *pSensorAdapterHandle, isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType, void *nativeSample, void *convertedSample)
Definition: isf_dsa_direct.c:130
isf_SensorDataTypes_t
isf_SensorDataTypes_t
Definition: isf_sensor_types.h:61
isf_fifo_t
Definition: isf_fifo.h:18
isf_SensorHandle_st::pSensorStaticConfig
const isf_SensorConfig_t * pSensorStaticConfig
Definition: isf_dsa_adapter.h:112
int32
long int32
This defines int32 as long.
Definition: isf_types.h:32
gSensorHandleList
isf_SensorHandle_t gSensorHandleList[]
This is the global DSA sensor driver list of the current sensor handles.
Definition: isf_sensor_configuration.c:47
isf_SubscriptionSettings_t::resultType
isf_SensorDataTypes_t resultType
The desired data type of the subscription.
Definition: isf_dsa_direct_types.h:25
isf_dsa_SensorSettings_st::resultType
isf_SensorDataTypes_t resultType
Definition: isf_dsa_adapter.h:85
isf_dsa_ControlData_st::pEventGroup
LWEVENT_STRUCT * pEventGroup
Definition: isf_dsa_adapter.h:94
isf_SensorHandle_st::adapterStatus
isf_dsa_AdapterStatus_t adapterStatus
Definition: isf_dsa_adapter.h:114
isf_dsa_ControlInterface_st::Shutdown
isf_dsa_status_t(* Shutdown)(isf_SensorHandle_t *pSensorHandle)
Definition: isf_dsa_adapter.h:135
isf_SubscriptionSettings_t::nSamplePeriod
uint32 nSamplePeriod
Sample period in microseconds.
Definition: isf_dsa_direct_types.h:27
isf_SubscriptionSettings_t
Definition: isf_dsa_direct_types.h:23
isf_dsa_ControlData_st::nEventFieldIndex
uint32 nEventFieldIndex
Definition: isf_dsa_adapter.h:95
isf_dsa_SensorSettings_st::pSampleBufferInfo
isf_fifo_t * pSampleBufferInfo
Definition: isf_dsa_adapter.h:83
DSA_STATE_NOT_INITIALIZED
Definition: isf_dsa_adapter.h:59
isf_dsa_SensorSettings_st
This defines the DSA sensor configuration parameter structure configuring the sensor settings by a su...
Definition: isf_dsa_adapter.h:81
isf_dsa_ControlData_st::sensorSettings
isf_dsa_SensorSettings_t sensorSettings
Definition: isf_dsa_adapter.h:96
gSensorList
const isf_SensorConfig_t gSensorList[]
This is the external declaration of the DSA sensor list array containing the sensor adapters and sens...
Definition: isf_sensor_configuration.c:26
start_sensor
int32 start_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
Definition: isf_dsa_direct.c:109
isf_dsa_ControlInterface_st::Initialize
isf_dsa_status_t(* Initialize)(isf_SensorHandle_t *pSensorHandle)
Definition: isf_dsa_adapter.h:129
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.