summaryrefslogtreecommitdiffstats
path: root/src/occ_405/sensor/sensor_query_list.c
blob: 2cae2c712d6754129fe3eb5d517ab0e270e52e81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/sensor/sensor_query_list.c $                      */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2016                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

//*************************************************************************/
// Includes
//*************************************************************************/
#include <common_types.h>   // imageHdr_t declaration and image header macro
#include <occ_common.h>     // imageHdr_t declaration and image header macro
#include <errl.h>           // For error handle
#include "ssx_io.h"         // For sprintf
#include <trac.h>           // For traces
#include <sensor_service_codes.h> // sensor module ids
#include <occ_service_codes.h>    // sensor module ids
#include <sensor.h>               // For Sensor defines
#include <sensor_query_list.h>      // For args to command

//*************************************************************************/
// Externs
//*************************************************************************/

//*************************************************************************/
// Macros
//*************************************************************************/

//*************************************************************************/
// Defines/Enums
//*************************************************************************/

//*************************************************************************/
// Structures
//*************************************************************************/

//*************************************************************************/
// Globals
//*************************************************************************/

//*************************************************************************/
// Function Prototypes
//*************************************************************************/

//*************************************************************************/
// Functions
//*************************************************************************/

// Function Specification
//
//  Name: printSensorInfo
//
//  Description: Dump a sensor's info via printf
//
// End Function Specification
void printSensorInfo(uint16_t i_gsid)
{
// This prevents warnings of set but not used since without SNSR_DEBUG
// being set, the SNSR_DBG macros don't do anything.
#ifdef SNSR_DEBUG

    // Initialize variable j and k with NULL and then
    // point to sensor to avoid compilation error when SNSR_DEBUG is not
    // defined. j and k are only used with SNSR_DBG which is no-op statement
    // when SNSR_DEBUG is not defined.
    sensor_t * k = NULL;
    k = G_amec_sensor_list[i_gsid];
    uint16_t * j = NULL;
    j = G_amec_sensor_list[i_gsid]->mini_sensor;

    // Print Sensors Information from Sensor_info_t Table
    SNSR_DBG("Sensor [%d] = Name: %s, Units: %s, Type: 0x%04x, Loc: 0x%04x, Num: %d, Freq: 0x%08x, Scale: 0x%08x\n",
             i_gsid,
             G_sensor_info[i_gsid].name,
             G_sensor_info[i_gsid].sensor.units,
             G_sensor_info[i_gsid].sensor.type,
             G_sensor_info[i_gsid].sensor.location,
             G_sensor_info[i_gsid].sensor.number,
             G_sensor_info[i_gsid].sensor.freq,
             G_sensor_info[i_gsid].sensor.scalefactor
    );

    // Print Sensor Information from Sensor_t
    SNSR_DBG("SensorPtr=0x%08x, Sample=%d, Max=%d, Min=%d, Tag=%d, MiniSensorPtr=0x%08x, MiniSensorVal=0x%04x\n",
             (uint32_t) k,
             k->sample,
             k->sample_max,
             k->sample_min,
             k->update_tag,
             (uint32_t)k->mini_sensor,
             (NULL != j) ? *j : 0
    );

#endif
}

// Function Specification
//
//  Name: printAllSensors
//
//  Description: Dump all sensors via printf.
//
// End Function Specification
void printAllSensors(void)
{
    int i;

    // Loop through sensor table and printf all sensors
    for(i=0; i < NUMBER_OF_SENSORS_IN_LIST; i++)
    {
        printSensorInfo(i);
    }
}

/*****************************************************************************/
// Entry point function
/*****************************************************************************/

// Function Specification
//
//  Name: querySensorList
//
//  Description: Query sensor list
//
// End Function Specification
errlHndl_t querySensorList(const querySensorListArg_t * i_argPtr)
{
    errlHndl_t l_err = NULL;

    if (i_argPtr != NULL)
    {
        uint16_t            i_startGsid     = i_argPtr->i_startGsid;
        uint8_t             i_present       = i_argPtr->i_present;
        uint16_t            i_type          = i_argPtr->i_type;
        uint16_t            i_loc           = i_argPtr->i_loc;
        uint16_t *          io_numOfSensors = i_argPtr->io_numOfSensors;
        sensorQueryList_t * o_sensors       = i_argPtr->o_sensors;
        sensor_info_t     * o_sensorInfoPtrs= i_argPtr->o_sensorInfoPtrs;

        // Validate input parameters
        if( (i_startGsid >= NUMBER_OF_SENSORS_IN_LIST) ||
            ((o_sensors == NULL) && (o_sensorInfoPtrs ==NULL)) ||
            (io_numOfSensors == NULL))
        {
            TRAC_ERR("querySensorList: Invalid input pointers OR start GSID is out of range: "
                     "i_startGsid: 0x%x, G_amec_sensor_count: 0x%x",
                     i_startGsid,G_amec_sensor_count);

            /* @
             * @errortype
             * @moduleid    SENSOR_QUERY_LIST
             * @reasoncode  INTERNAL_INVALID_INPUT_DATA
             * @userdata1   i_startGsid -- passed in Global Sensor ID
             * @userdata2   G_amec_sensor_count -- number of OCC sensors
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     Firmware failure caused due to invalid GSID passed
             */

            /* @
             * @errortype
             * @moduleid    SENSOR_QUERY_LIST
             * @reasoncode  INTERNAL_FAILURE
             * @userdata1   i_startGsid -- passed in Global Sensor ID
             * @userdata2   G_amec_sensor_count -- number of OCC sensors
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     NULL pointer passed for querySensorList output args
             */
            l_err = createErrl(SENSOR_QUERY_LIST,                 //modId
                    ((i_startGsid >= NUMBER_OF_SENSORS_IN_LIST) ? INTERNAL_INVALID_INPUT_DATA : INTERNAL_FAILURE), //reasoncode
                    OCC_NO_EXTENDED_RC,                               //Extended reason code
                    ERRL_SEV_PREDICTIVE,                              //Severity
                    NULL,                                             //Trace Buf
                    0,                                                //Trace Size
                    i_startGsid,                                      //userdata1
                    G_amec_sensor_count                               //userdata2
            );
        }
        else
        {
            uint32_t l_cnt = i_startGsid;
            uint32_t l_num = *io_numOfSensors;
            *io_numOfSensors = 0;

            // Traverse through sensor list starting at i_startGsid to find
            // matching sensor. Return it in the output variable
            for (; (l_cnt < NUMBER_OF_SENSORS_IN_LIST && ((*io_numOfSensors) < l_num)); l_cnt++)
            {
                // If sample value is not zero then it means sensor is present.
                // This is currently only used by debug/mfg purpose
                // If user is looking for present sensors and sample is zero,
                // then don't include current sensor in the query list
                if ((i_present) && (G_amec_sensor_list[l_cnt]->sample == 0))
                {
                    continue;
                }

                // If user is NOT looking for any sensor type and input type,
                // does not match the current sensor type, then don't include
                // current sensor in the query list
                if ((i_type & G_sensor_info[l_cnt].sensor.type) == 0)
                {
                    continue;
                }

                // If user is NOT looking for any sensor location and input loc,
                // does not match the current sensor location, then don't include
                // current sensor in the query list
                if ((i_loc & G_sensor_info[l_cnt].sensor.location) == 0)
                {
                    continue;
                }

                if (o_sensors != NULL)
                {
                    // All conditions match. Include current sensor in the query list
                    // Copy gsid, name and sample
                    o_sensors->gsid = l_cnt;
                    strncpy(o_sensors->name, G_sensor_info[l_cnt].name, MAX_SENSOR_NAME_SZ);
                    o_sensors->sample = G_amec_sensor_list[l_cnt]->sample;
                    o_sensors++;
                }

                if (o_sensorInfoPtrs != NULL)
                {
                    memcpy(o_sensorInfoPtrs, &G_sensor_info[l_cnt], sizeof(sensor_info_t));
                    o_sensorInfoPtrs++;
                }

                (*io_numOfSensors)++;
            }
        }
    }
    else
    {
        TRAC_ERR("querySensorList: Invalid argument pointer = NULL");

        /* @
         * @errortype
         * @moduleid    SENSOR_QUERY_LIST
         * @reasoncode  INTERNAL_INVALID_INPUT_DATA
         * @userdata1   NULL
         * @userdata2   NULL
         * @userdata4   ERC_ARG_POINTER_FAILURE
         * @devdesc     NULL pointer passed to querySensorList applet
         */
        l_err = createErrl(
                SENSOR_QUERY_LIST,            // Module ID
                INTERNAL_INVALID_INPUT_DATA,  // Reason Code
                ERC_ARG_POINTER_FAILURE,      // Extended reason code
                ERRL_SEV_PREDICTIVE,          // Severity
                NULL,                         // Trace
                0,                            // Trace Size
                0,                            // UserData 1
                0                             // UserData 2
              );
    }

    return l_err;
}
OpenPOWER on IntegriCloud