-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChibiOSHardware.h
59 lines (48 loc) · 1009 Bytes
/
ChibiOSHardware.h
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
#ifndef ROS_CHIBIOS_HARDWARE_H
#define ROS_CHIBIOS_HARDWARE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "ch.h"
#include "hal.h"
#include "usbcfg.h"
class ChibiOSHardware
{
public:
ChibiOSHardware(BaseChannel* io)
{
iostream = io;
}
ChibiOSHardware()
: mLastSysTime(chVTGetSystemTimeX())
{
iostream = (BaseChannel*)&SDU1;
}
void init() {}
int read()
{
return chnGetTimeout(iostream, TIME_IMMEDIATE);
}
void write(uint8_t* data, int length)
{
chnWrite(iostream, data, length);
}
unsigned long time()
{
systime_t currentSysTime = chVTGetSystemTimeX();
mTimeDifference = chTimeDiffX(mLastSysTime, currentSysTime);
mTimeElapsed += TIME_I2MS(mTimeDifference);
mLastSysTime = currentSysTime;
return mTimeElapsed;
}
protected:
BaseChannel* iostream;
private:
uint32_t mTimeElapsed;
systime_t mLastSysTime;
systime_t mTimeDifference;
};
#ifdef __cplusplus
}
#endif
#endif /* ROS_CHIBIOS_HARDWARE_H */