Skip to content

Commit f0c7e4b

Browse files
committed
make RTM path not fixed
Signed-off-by: Reyhaneh Yazdani <reyhane.y84@gmail.com>
1 parent 2495f8e commit f0c7e4b

File tree

4 files changed

+88
-12
lines changed

4 files changed

+88
-12
lines changed

include/EApiDmo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
#define HWMON_PATH "/sys/class/hwmon/"
1919
#define HWMON_NAME "nct7802"
2020

21+
#define RTM_PATH "/sys/bus/platform/drivers/dmec-rtm/"
22+
23+
2124
extern int eeprom_bus;
2225
extern uint8_t *eeprom_userSpaceBuf;
2326

2427
extern int board_type;
2528

2629
extern char *hwname;
30+
extern char *rtmname;
2731

2832
extern char err[256];
2933

lib/EApiEmulBoardInfo.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,22 @@ EApiBoardGetValueEmul(
249249
switch (Id)
250250
{
251251
case EAPI_ID_BOARD_BOOT_COUNTER_VAL:
252-
snprintf(path,sizeof(BOOT_COUNTER_PATH),BOOT_COUNTER_PATH);
252+
EAPI_LIB_RETURN_ERROR_IF(
253+
EApiBoardGetValueEmul,
254+
(rtmname==NULL),
255+
EAPI_STATUS_ERROR,
256+
"Error finding RTM"
257+
);
258+
snprintf(path,sizeof(RTM_PATH)+sizeof(rtmname)+sizeof("/rtm_boot_count")+1,RTM_PATH"%s/rtm_boot_count",rtmname);
253259
break;
254260
case EAPI_ID_BOARD_RUNNING_TIME_METER_VAL:
255-
snprintf(path,sizeof(RUNTIME_PATH),RUNTIME_PATH);
261+
EAPI_LIB_RETURN_ERROR_IF(
262+
EApiBoardGetValueEmul,
263+
(rtmname==NULL),
264+
EAPI_STATUS_ERROR,
265+
"Error finding RTM"
266+
);
267+
snprintf(path,sizeof(RTM_PATH)+sizeof(rtmname)+sizeof("/rtm_time")+1,RTM_PATH"%s/rtm_time",rtmname);
256268
break;
257269
case EAPI_ID_BOARD_PNPID_VAL:
258270
*pValue=EAPI_PNPID_DM;
@@ -283,9 +295,9 @@ EApiBoardGetValueEmul(
283295
"Error finding HWMON"
284296
);
285297
if (board_type == BBW6)
286-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/temp5_input"),HWMON_PATH"%s/temp5_input",hwname);
298+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/temp5_input")+1,HWMON_PATH"%s/temp5_input",hwname);
287299
else if (board_type == CBS6)
288-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/temp1_input"),HWMON_PATH"%s/temp1_input",hwname);
300+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/temp1_input")+1,HWMON_PATH"%s/temp1_input",hwname);
289301
else
290302
EAPI_LIB_RETURN_ERROR(
291303
EApiBoardGetValueEmul,
@@ -307,7 +319,7 @@ EApiBoardGetValueEmul(
307319
EAPI_STATUS_ERROR,
308320
"Error finding HWMON"
309321
);
310-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/temp4_input"),HWMON_PATH"%s/temp4_input",hwname);
322+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/temp4_input")+1,HWMON_PATH"%s/temp4_input",hwname);
311323
break;
312324
case EAPI_ID_HWMON_FAN_CPU:
313325
EAPI_LIB_RETURN_ERROR_IF(
@@ -316,7 +328,7 @@ EApiBoardGetValueEmul(
316328
EAPI_STATUS_ERROR,
317329
"Error finding HWMON"
318330
);
319-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/fan2_input"),HWMON_PATH"%s/fan2_input",hwname);
331+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/fan2_input")+1,HWMON_PATH"%s/fan2_input",hwname);
320332
break;
321333
case EAPI_ID_HWMON_FAN_SYSTEM:
322334
EAPI_LIB_RETURN_ERROR(
@@ -345,7 +357,7 @@ EApiBoardGetValueEmul(
345357
EAPI_STATUS_ERROR,
346358
"Error finding HWMON"
347359
);
348-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in0_input"),HWMON_PATH"%s/in0_input",hwname);
360+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in0_input")+1,HWMON_PATH"%s/in0_input",hwname);
349361
break;
350362
case EAPI_ID_HWMON_VOLTAGE_VBAT:
351363
EAPI_LIB_RETURN_ERROR_IF(
@@ -354,7 +366,7 @@ EApiBoardGetValueEmul(
354366
EAPI_STATUS_ERROR,
355367
"Error finding HWMON"
356368
);
357-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in1_input"),HWMON_PATH"%s/in1_input",hwname);
369+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in1_input")+1,HWMON_PATH"%s/in1_input",hwname);
358370
break;
359371
case EAPI_ID_HWMON_VOLTAGE_5V:
360372
*pValue=0xffffff;
@@ -370,7 +382,7 @@ EApiBoardGetValueEmul(
370382
EAPI_STATUS_ERROR,
371383
"Error finding HWMON"
372384
);
373-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in3_input"),HWMON_PATH"%s/in3_input",hwname);
385+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in3_input")+1,HWMON_PATH"%s/in3_input",hwname);
374386
break;
375387
case EAPI_ID_HWMON_VOLTAGE_12V:
376388
EAPI_LIB_RETURN_ERROR_IF(
@@ -379,7 +391,7 @@ EApiBoardGetValueEmul(
379391
EAPI_STATUS_ERROR,
380392
"Error finding HWMON"
381393
);
382-
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in4_input"),HWMON_PATH"%s/in4_input",hwname);
394+
snprintf(path,sizeof(HWMON_PATH)+sizeof(hwname)+sizeof("/in4_input")+1,HWMON_PATH"%s/in4_input",hwname);
383395
break;
384396
default:
385397
EAPI_LIB_RETURN_ERROR(

lib/EApiInitLib.c

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int eeprom_bus = -1;
4848
uint8_t *eeprom_userSpaceBuf = NULL;
4949
int board_type;
5050
char *hwname;
51+
char *rtmname;
5152
char err[256];
5253

5354
struct gpiohandle_request *req = NULL;
@@ -199,6 +200,57 @@ EApiStatus_t find_hwmon()
199200
return StatusCode;
200201
}
201202

203+
EApiStatus_t find_rtm()
204+
{
205+
struct dirent *de;
206+
DIR *dir;
207+
EApiStatus_t StatusCode=EAPI_STATUS_SUCCESS;
208+
209+
char sysfs[NAME_MAX];
210+
snprintf(sysfs,sizeof(RTM_PATH),RTM_PATH);
211+
212+
if(!(dir = opendir(sysfs)))
213+
{
214+
rtmname = NULL;
215+
216+
snprintf(err,sizeof(err),"%s",strerror(errno));
217+
EAPI_LIB_RETURN_ERROR(
218+
find_rtm,
219+
EAPI_STATUS_UNSUPPORTED,
220+
err);
221+
}
222+
/* go through the rtm*/
223+
rtmname = NULL;
224+
StatusCode = EAPI_STATUS_UNSUPPORTED;
225+
while ((de = readdir(dir)) != NULL) {
226+
227+
if (strstr(de->d_name, "dmec") != NULL)
228+
{
229+
rtmname = (char*)malloc(sizeof(de->d_name)*sizeof(char));
230+
if (!rtmname)
231+
{
232+
EAPI_LIB_RETURN_ERROR(
233+
find_rtm,
234+
EAPI_STATUS_ALLOC_ERROR,
235+
"Error in Allocating Memory");
236+
}
237+
strncpy(rtmname, de->d_name,sizeof(de->d_name));
238+
StatusCode = EAPI_STATUS_SUCCESS;
239+
break;
240+
}
241+
else
242+
continue;
243+
}
244+
closedir(dir);
245+
if (StatusCode == EAPI_STATUS_UNSUPPORTED )
246+
EAPI_LIB_RETURN_ERROR(
247+
find_rtm,
248+
EAPI_STATUS_UNSUPPORTED,
249+
"Info: No RTM is found.");
250+
EAPI_LIB_ASSERT_EXIT
251+
return StatusCode;
252+
}
253+
202254
EApiStatus_t list_gpio_device()
203255
{
204256
EApiStatus_t StatusCode=EAPI_STATUS_SUCCESS;
@@ -399,9 +451,9 @@ eeprom_userSpaceBuf = eeprom_userSpace();
399451
}
400452
else
401453
{
402-
if(!strncmp(line,"eDM-COMC-BS6",12))
454+
if (strstr(line, "COMC") != NULL)
403455
board_type = CBS6;
404-
else if(!strncmp(line,"eDM-COMB-BW6",12))
456+
else if (strstr(line, "COMB") != NULL)
405457
board_type = BBW6;
406458
}
407459
}
@@ -419,6 +471,10 @@ eeprom_userSpaceBuf = eeprom_userSpace();
419471
hwname = NULL;
420472
find_hwmon();
421473

474+
/* ******************** RTM ************************** */
475+
rtmname = NULL;
476+
find_rtm();
477+
422478
/* ******************** GPIO ************************** */
423479
gpioName = NULL;
424480
StatusCode = list_gpio_device();
@@ -461,6 +517,9 @@ EApiUninitLib(){
461517
if(hwname != NULL)
462518
free(hwname);
463519

520+
if(rtmname != NULL)
521+
free(rtmname);
522+
464523
if(gpioName != NULL)
465524
free(gpioName);
466525

lib/include/EApiInitLib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ EApiInitLib();
5959
uint32_t
6060
EApiUninitLib();
6161
EApiStatus_t find_hwmon();
62+
EApiStatus_t find_rtm();
6263
EApiStatus_t list_gpio_device();
6364
EApiStatus_t gpio_dev_open(const char *device_name);
6465

0 commit comments

Comments
 (0)