Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Servo mbed-rtos mbed
Diff: can.hpp
- Revision:
- 2:7dfc8dd6aab3
- Parent:
- 1:79b1ee0f97ef
--- a/can.hpp Mon Aug 31 22:25:57 2015 +0000
+++ b/can.hpp Thu Oct 08 13:36:17 2015 +0000
@@ -1,148 +1,16 @@
-#ifndef __NET_H__
-#define __NET_H__
+#ifndef __CAN_H__
+#define __CAN_H__
#include "common_types.h"
-#define CAN_FLAG_EMPTY 0x00
-#define CAN_FLAG_RECEIVED 0x01
-#define CAN_FLAG_SEND 0x02
-
-#define CAN_THREAD_PERIOD 100 //ms
-
-
-
-#define CMD_ECHO 0x0A0A
-
-/**************************************************
- * GLOBAL DEFINES
- **************************************************/
-#define CAN_CMD_BODY_ID 0xAA
-#define CAN_STS_BODY_ID 0xAB
-#define CAN_CMD_ENGINE_ID 0x0A
-#define CAN_CMD_TIME_ID 0xBB
-#define CAN_CMD_DRIVER_ID 0x11
-#define CAN_STS_DRIVER_ID 0x10
-
-#define PERIOD_3s (3000/CAN_THREAD_PERIOD)
-#define PERIOD_1s (1000/CAN_THREAD_PERIOD)
-#define PERIOD_500ms (500/CAN_THREAD_PERIOD)
-#define PERIOD_400ms (400/CAN_THREAD_PERIOD)
-#define PERIOD_300ms (300/CAN_THREAD_PERIOD)
-#define PERIOD_200ms (200/CAN_THREAD_PERIOD)
-#define PERIOD_100ms (100/CAN_THREAD_PERIOD)
-
-#define CAN_STS_BODY_PERIOD PERIOD_1s
-
-
-#define CAN_MISSING_DETECTION PERIOD_3s
-
-#define CAN_MISSING_BODY_ID 0
-#define CAN_MISSING_ENGINE_ID 1
-#define CAN_MISSING_TIME_ID 2
-
-#define CAN_RX_PERIODIC_MSG 3
-
-/**************************************************
- * GLOBAL TYPES
- **************************************************/
-#define CAN_CMD_PAYLOAD_BODY 4
-#define CAN_STS_PAYLOAD_BODY 8
-#define CAN_CMD_PAYLOAD_ENGINE 4
-#define CAN_CMD_PAYLOAD_TIME 4
-#define CAN_CMD_PAYLOAD_DRIVER 8
-#define CAN_STS_PAYLOAD_DRIVER 4
-
-typedef union can_cmd_body_payload_s {
- uint8 buf[CAN_CMD_PAYLOAD_BODY];
- struct {
- uint32 light_r:1;
- uint32 light_c:1;
- uint32 light_l:1;
- uint32 unused:29;
- } msg;
-} can_cmd_body_payload_t;
-typedef struct can_cmd_body_s {
- can_cmd_body_payload_t payload;
- uint8 flag;
-} can_cmd_body_t;
-
-typedef union can_sts_body_payload_s {
- uint8 buf[CAN_STS_PAYLOAD_BODY];
- struct {
- uint32 hit_front:1;
- uint32 hit_rear:1;
- uint32 hit_left:1;
- uint32 hit_right:1;
- uint32 light_sens:1;
- uint32 unused:3;
- uint32 eye_back_l:8;
- uint32 eye_back_r:8;
- uint32 eye_front:16;
- } msg;
-} can_sts_body_payload_t;
-typedef struct can_sts_body_s {
- can_sts_body_payload_t payload;
- uint8 flag;
-} can_sts_body_t;
-
-typedef union can_cmd_engine_payload_s {
- uint8 buf[CAN_CMD_PAYLOAD_BODY];
- struct {
- uint32 steering:8;
- uint32 power:8;
- uint32 direction:1;
- uint32 breaking:1;
- uint32 unused:14;
- } msg;
-} can_cmd_engine_payload_t;
-typedef struct can_cmd_engine_s {
- can_cmd_engine_payload_t payload;
- uint8 flag;
-} can_cmd_engine_t;
-
-typedef union can_cmd_time_payload_s {
- uint8 buf[CAN_CMD_PAYLOAD_TIME];
- struct {
- uint32 time;
- } msg;
-} can_cmd_time_payload_t;
-typedef struct can_cmd_time_s {
- can_cmd_time_payload_t payload;
- uint8 flag;
-} can_cmd_time_t;
-
-typedef union can_cmd_driver_payload_s {
- uint8 buf[CAN_CMD_PAYLOAD_DRIVER];
- struct {
- uint32 cmd:16;
- uint32 opt:16;
- uint32 data;
- } msg;
-} can_cmd_driver_payload_t;
-typedef struct can_cmd_driver_s {
- can_cmd_driver_payload_t payload;
- uint8 flag;
-} can_cmd_driver_t;
-
-typedef union can_sts_driver_payload_s {
- uint8 buf[CAN_STS_PAYLOAD_DRIVER];
- struct {
- uint32 data;
- } msg;
-} can_sts_driver_payload_t;
-typedef struct can_sts_driver_time_s {
- can_sts_driver_payload_t payload;
- uint8 flag;
-} can_sts_driver_t;
-
-/**************************************************
- * DATA STRUCTURES
- **************************************************/
-
+//CAN driver initialization
void init_can();
+//thread of the CAN driver which receives and transmits messages periodically
void thread_can(void const *args);
+//return if a message hasn't been received for longer than
+//CAN_MISSING_DETECTION
bool can_msg_is_missing(uint8 msg_id);
-#endif //__NET_H__
+#endif //__CAN_H__