ISF  2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
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  **/
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 
127 {
128  int32 retval;
129  retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.Shutdown(pSensorAdapterHandle);
130  return retval;
131 }
132 
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 
int32 configure_sensor(isf_SensorHandle_t *pSensorAdapterHandle, isf_SubscriptionSettings_t *pRequiredSettings, isf_fifo_t *pfifo)
unsigned char uint8
Definition: isf_types.h:76
int32 shutdown_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
int32 stop_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
This defines the DSA sensor configuration structure defining each individual sensor adapter in the DS...
isf_dsa_status_t(* Configure)(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_dsa_status_t(* Shutdown)(isf_SensorHandle_t *pSensorHandle)
isf_dsa_ControlData_t controlData
const isf_dsa_Adapter_t * pAdapter
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
#define ERR_INVALID_PTR
isf_dsa_result_types_t resultFormat
The format of the data to be returned- 0=RAW, 1=FIXED, 2=FLOAT.
isf_dsa_ControlInterface_t control
#define ERR_INVALID_HANDLE
isf_dsa_status_t(* StartData)(isf_SensorHandle_t *pSensorHandle)
isf_dsa_status_t(* ValidateSettings)(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_dsa_data_converter_t * Convert
enum isf_dsa_result_enums isf_dsa_result_types_t
isf_dsa_result_types_t resultFormat
int32 convert_sensor_data(isf_SensorHandle_t *pSensorAdapterHandle, isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType, void *nativeSample, void *convertedSample)
isf_SensorDataTypes_t
const isf_SensorConfig_t * pSensorStaticConfig
isf_SensorHandle_t gSensorHandleList[]
This is the global DSA sensor driver list of the current sensor handles.
isf_SensorDataTypes_t resultType
The desired data type of the subscription.
isf_SensorDataTypes_t resultType
isf_dsa_AdapterStatus_t adapterStatus
signed long int int32
Definition: isf_types.h:74
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.
uint32 nSamplePeriod
Sample period in microseconds.
isf_dsa_status_t(* Initialize)(isf_SensorHandle_t *pSensorHandle)
This defines the DSA sensor configuration parameter structure configuring the sensor settings by a su...
isf_dsa_SensorSettings_t sensorSettings
const isf_SensorConfig_t gSensorList[]
This is the external declaration of the DSA sensor list array containing the sensor adapters and sens...
int32 start_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
unsigned long int uint32
Definition: isf_types.h:78
isf_dsa_status_t(* EndData)(isf_SensorHandle_t *pSensorHandle)