-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
73 lines (63 loc) · 2.1 KB
/
Copy pathmain.c
File metadata and controls
73 lines (63 loc) · 2.1 KB
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
/*
* main.c
*
* Created on: 02 gen 2019
* Author: andrea
*/
#include <stdint.h>
#include <syslog.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <pru_mylinuxdrone.h>
#define MPU6050_DEVICE_NAME "/dev/iio:device1"
#define MPU6050_BUFF_SIZE 12
unsigned char mpu6050Data[sizeof(PrbMessageType)] = {0};
PrbMessageType* mpu6050DataStruct = (PrbMessageType*)mpu6050Data;
struct timeval now; // wall clock times
struct timeval later;
uint32_t usec;
FILE *fd;
unsigned char readBuff[MPU6050_BUFF_SIZE] = {0};
void openMpu6050()
{
syslog(LOG_INFO, "open device mpu6050 ...");
/* Open the rpmsg_pru character device file */
fd = fopen(MPU6050_DEVICE_NAME, "r");
if (fd == NULL)
{
syslog(LOG_ERR, "Failed to open [%s] ",
MPU6050_DEVICE_NAME);
}
}
void closeMpu6050() {
fclose(fd);
}
void readMpu6050() {
fread(mpu6050Data, sizeof(PrbMessageType), 1, fd);
}
int main(void)
{
syslog(LOG_INFO, "PrbMessageType size=[%d]", sizeof(PrbMessageType));
gettimeofday(&now, NULL); // wall clock time when CPU time first read
gettimeofday(&later, NULL); // wall clock time when CPU time has ticked
openMpu6050();
for(int i = 0; i < 100000; i++) {
readMpu6050();
gettimeofday(&later, NULL); // wall clock time when CPU time has ticked
usec = (((unsigned long long)later.tv_sec) * 1000000ULL + later.tv_usec) - (((unsigned long long)now.tv_sec) * 1000000ULL + now.tv_usec);
if(usec > 1200) {
syslog(LOG_INFO, "usec[%d], a[%d,%d,%d], g[%d,%d,%d]", usec,
mpu6050DataStruct->mpu_accel_gyro.ax,
mpu6050DataStruct->mpu_accel_gyro.ay,
mpu6050DataStruct->mpu_accel_gyro.az,
mpu6050DataStruct->mpu_accel_gyro.gx,
mpu6050DataStruct->mpu_accel_gyro.gy,
mpu6050DataStruct->mpu_accel_gyro.gz
);
}
gettimeofday(&now, NULL); // wall clock time when CPU time first read
}
closeMpu6050();
}