81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
#include "LightWeightCPU.h"
|
|
#include "SfTypeDefine.h"
|
|
#include "Log.h"
|
|
#include <thread>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
#define MSYS_IOCTL_MAGIC 'S'
|
|
#define IOCTL_MSYS_GET_SY_RTOS_DATA _IO(MSYS_IOCTL_MAGIC, 0x97)
|
|
#define IOCTL_MSYS_SET_RTOS_CMD _IO(MSYS_IOCTL_MAGIC, 0x98)
|
|
typedef struct ONLY_FOR_GET_DATA
|
|
{
|
|
// unsigned int test1;
|
|
// unsigned int test2;
|
|
// unsigned int test3;
|
|
// unsigned int IsNight;
|
|
// unsigned int BatPer;
|
|
// unsigned int Fctemp;
|
|
// unsigned short McuVer;
|
|
// unsigned char McuSubVer;
|
|
// unsigned int rtosBootTime;
|
|
unsigned int test1;
|
|
unsigned int test2;
|
|
unsigned int test3;
|
|
unsigned int IsNight;
|
|
unsigned int BatPer;
|
|
unsigned int LiveBatPer;
|
|
unsigned int currentBatvalue;
|
|
unsigned int recorddone;
|
|
unsigned int Fctemp;
|
|
unsigned short McuVer;
|
|
unsigned char McuSubVer;
|
|
unsigned int rtosBootTime;
|
|
} ONLY_FOR_GET_DATA;
|
|
bool LightWeightCPU::Read(char *readBuf, const unsigned int length)
|
|
{
|
|
SINT32 nMsysFd = SF_FAILURE;
|
|
ONLY_FOR_GET_DATA info = {0};
|
|
for (SINT32 cnt = 0; cnt < 100; cnt++)
|
|
{
|
|
if (0 > (nMsysFd = open("/dev/msys", O_RDONLY | O_SYNC)))
|
|
{
|
|
LogError("open /dev/msys failed!!\n");
|
|
usleep(20000);
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
ioctl(nMsysFd, IOCTL_MSYS_GET_SY_RTOS_DATA, &info);
|
|
memcpy(readBuf, &info, sizeof(ONLY_FOR_GET_DATA));
|
|
close(nMsysFd);
|
|
return true;
|
|
}
|
|
}
|
|
LogError("LightWeightCPU::Read failed.\n");
|
|
return false;
|
|
}
|
|
bool LightWeightCPU::Write(const char *writeBuf, const unsigned length)
|
|
{
|
|
SINT32 nMsysFd = -1;
|
|
SINT32 ret = -1;
|
|
for (SINT32 cnt = 0; cnt < 10; cnt++)
|
|
{
|
|
if (0 > (nMsysFd = open("/dev/msys", O_RDONLY | O_SYNC)))
|
|
{
|
|
LogError("%s open /dev/msys failed!!\n", __FUNCTION__);
|
|
// usleep(20000);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
ret = ioctl(nMsysFd, IOCTL_MSYS_SET_RTOS_CMD, &writeBuf);
|
|
close(nMsysFd);
|
|
return ret;
|
|
}
|
|
}
|
|
return false;
|
|
} |