| ISF 2.2 rev 5 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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