ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 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  **/
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 
124 {
125  int32 retval;
126  retval = pSensorAdapterHandle->pSensorStaticConfig->pAdapter->control.Shutdown(pSensorAdapterHandle);
127  return retval;
128 }
129 
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 
int32 configure_sensor(isf_SensorHandle_t *pSensorAdapterHandle, isf_SubscriptionSettings_t *pRequiredSettings, isf_fifo_t *pfifo)
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
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(* StartData)(isf_SensorHandle_t *pSensorHandle)
isf_dsa_status_t(* EndData)(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
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.
isf_dsa_status_t(* ValidateSettings)(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
#define ERR_INVALID_HANDLE
isf_dsa_data_converter_t * Convert
isf_dsa_status_t(* Configure)(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
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
long int32
This defines int32 as long.
Definition: isf_types.h:32
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
LWEVENT_STRUCT * pEventGroup
isf_dsa_AdapterStatus_t adapterStatus
isf_dsa_status_t(* Shutdown)(isf_SensorHandle_t *pSensorHandle)
uint32 nSamplePeriod
Sample period in microseconds.
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)
isf_dsa_status_t(* Initialize)(isf_SensorHandle_t *pSensorHandle)