car chassis

Dependencies:   Servo mbed-rtos mbed

Committer:
mariob
Date:
Sun Aug 02 12:55:33 2015 +0000
Revision:
0:ce6055872f4e
first commit: new car ECU

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariob 0:ce6055872f4e 1 #ifndef __NET_H__
mariob 0:ce6055872f4e 2 #define __NET_H__
mariob 0:ce6055872f4e 3
mariob 0:ce6055872f4e 4 #include "common_types.h"
mariob 0:ce6055872f4e 5
mariob 0:ce6055872f4e 6 #define CAN_FLAG_EMPTY 0x00
mariob 0:ce6055872f4e 7 #define CAN_FLAG_RECEIVED 0x01
mariob 0:ce6055872f4e 8 #define CAN_FLAG_SEND 0x02
mariob 0:ce6055872f4e 9
mariob 0:ce6055872f4e 10 #define CAN_THREAD_PERIOD 100 //ms
mariob 0:ce6055872f4e 11
mariob 0:ce6055872f4e 12 /**************************************************
mariob 0:ce6055872f4e 13 * GLOBAL DEFINES
mariob 0:ce6055872f4e 14 **************************************************/
mariob 0:ce6055872f4e 15 #define CAN_CMD_BODY_ID 0xAA
mariob 0:ce6055872f4e 16 #define CAN_STS_BODY_ID 0xAB
mariob 0:ce6055872f4e 17 #define CAN_CMD_ENGINE_ID 0x0A
mariob 0:ce6055872f4e 18 #define CAN_CMD_TIME_ID 0xBB
mariob 0:ce6055872f4e 19 #define CAN_CMD_DRIVER_ID 0x11
mariob 0:ce6055872f4e 20 #define CAN_STS_DRIVER_ID 0x10
mariob 0:ce6055872f4e 21
mariob 0:ce6055872f4e 22 #define PERIOD_3s (3000/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 23 #define PERIOD_1s (1000/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 24 #define PERIOD_500ms (500/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 25 #define PERIOD_400ms (400/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 26 #define PERIOD_300ms (300/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 27 #define PERIOD_200ms (200/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 28 #define PERIOD_100ms (100/CAN_THREAD_PERIOD)
mariob 0:ce6055872f4e 29
mariob 0:ce6055872f4e 30 #define CAN_STS_BODY_PERIOD PERIOD_1s
mariob 0:ce6055872f4e 31
mariob 0:ce6055872f4e 32
mariob 0:ce6055872f4e 33
mariob 0:ce6055872f4e 34 #define CAN_MISSING_DETECTION PERIOD_3s
mariob 0:ce6055872f4e 35
mariob 0:ce6055872f4e 36 #define CAN_MISSING_BODY_ID 0
mariob 0:ce6055872f4e 37 #define CAN_MISSING_ENGINE_ID 1
mariob 0:ce6055872f4e 38 #define CAN_MISSING_TIME_ID 2
mariob 0:ce6055872f4e 39
mariob 0:ce6055872f4e 40 #define CAN_RX_PERIODIC_MSG 3
mariob 0:ce6055872f4e 41
mariob 0:ce6055872f4e 42 /**************************************************
mariob 0:ce6055872f4e 43 * GLOBAL TYPES
mariob 0:ce6055872f4e 44 **************************************************/
mariob 0:ce6055872f4e 45 #define CAN_CMD_PAYLOAD_BODY 4
mariob 0:ce6055872f4e 46 #define CAN_STS_PAYLOAD_BODY 8
mariob 0:ce6055872f4e 47 #define CAN_CMD_PAYLOAD_ENGINE 4
mariob 0:ce6055872f4e 48 #define CAN_CMD_PAYLOAD_TIME 4
mariob 0:ce6055872f4e 49 #define CAN_CMD_PAYLOAD_DRIVER 8
mariob 0:ce6055872f4e 50 #define CAN_STS_PAYLOAD_DRIVER 4
mariob 0:ce6055872f4e 51
mariob 0:ce6055872f4e 52 typedef union can_cmd_body_payload_s {
mariob 0:ce6055872f4e 53 uint8 buf[CAN_CMD_PAYLOAD_BODY];
mariob 0:ce6055872f4e 54 struct {
mariob 0:ce6055872f4e 55 uint32 light_r:1;
mariob 0:ce6055872f4e 56 uint32 light_c:1;
mariob 0:ce6055872f4e 57 uint32 light_l:1;
mariob 0:ce6055872f4e 58 uint32 unused:29;
mariob 0:ce6055872f4e 59 } msg;
mariob 0:ce6055872f4e 60 } can_cmd_body_payload_t;
mariob 0:ce6055872f4e 61 typedef struct can_cmd_body_s {
mariob 0:ce6055872f4e 62 can_cmd_body_payload_t payload;
mariob 0:ce6055872f4e 63 uint8 flag;
mariob 0:ce6055872f4e 64 } can_cmd_body_t;
mariob 0:ce6055872f4e 65
mariob 0:ce6055872f4e 66 typedef union can_sts_body_payload_s {
mariob 0:ce6055872f4e 67 uint8 buf[CAN_STS_PAYLOAD_BODY];
mariob 0:ce6055872f4e 68 struct {
mariob 0:ce6055872f4e 69 uint32 hit_front:1;
mariob 0:ce6055872f4e 70 uint32 hit_rear:1;
mariob 0:ce6055872f4e 71 uint32 hit_left:1;
mariob 0:ce6055872f4e 72 uint32 hit_right:1;
mariob 0:ce6055872f4e 73 uint32 light_sens:1;
mariob 0:ce6055872f4e 74 uint32 unused:3;
mariob 0:ce6055872f4e 75 uint32 eye_back_l:8;
mariob 0:ce6055872f4e 76 uint32 eye_back_r:8;
mariob 0:ce6055872f4e 77 uint32 eye_front:16;
mariob 0:ce6055872f4e 78 } msg;
mariob 0:ce6055872f4e 79 } can_sts_body_payload_t;
mariob 0:ce6055872f4e 80 typedef struct can_sts_body_s {
mariob 0:ce6055872f4e 81 can_sts_body_payload_t payload;
mariob 0:ce6055872f4e 82 uint8 flag;
mariob 0:ce6055872f4e 83 } can_sts_body_t;
mariob 0:ce6055872f4e 84
mariob 0:ce6055872f4e 85 typedef union can_cmd_engine_payload_s {
mariob 0:ce6055872f4e 86 uint8 buf[CAN_CMD_PAYLOAD_BODY];
mariob 0:ce6055872f4e 87 struct {
mariob 0:ce6055872f4e 88 uint32 steering:8;
mariob 0:ce6055872f4e 89 uint32 power:8;
mariob 0:ce6055872f4e 90 uint32 direction:1;
mariob 0:ce6055872f4e 91 uint32 breaking:1;
mariob 0:ce6055872f4e 92 uint32 unused:14;
mariob 0:ce6055872f4e 93 } msg;
mariob 0:ce6055872f4e 94 } can_cmd_engine_payload_t;
mariob 0:ce6055872f4e 95 typedef struct can_cmd_engine_s {
mariob 0:ce6055872f4e 96 can_cmd_engine_payload_t payload;
mariob 0:ce6055872f4e 97 uint8 flag;
mariob 0:ce6055872f4e 98 } can_cmd_engine_t;
mariob 0:ce6055872f4e 99
mariob 0:ce6055872f4e 100 typedef union can_cmd_time_payload_s {
mariob 0:ce6055872f4e 101 uint8 buf[CAN_CMD_PAYLOAD_TIME];
mariob 0:ce6055872f4e 102 struct {
mariob 0:ce6055872f4e 103 uint32 time;
mariob 0:ce6055872f4e 104 } msg;
mariob 0:ce6055872f4e 105 } can_cmd_time_payload_t;
mariob 0:ce6055872f4e 106 typedef struct can_cmd_time_s {
mariob 0:ce6055872f4e 107 can_cmd_time_payload_t payload;
mariob 0:ce6055872f4e 108 uint8 flag;
mariob 0:ce6055872f4e 109 } can_cmd_time_t;
mariob 0:ce6055872f4e 110
mariob 0:ce6055872f4e 111 typedef union can_cmd_driver_payload_s {
mariob 0:ce6055872f4e 112 uint8 buf[CAN_CMD_PAYLOAD_DRIVER];
mariob 0:ce6055872f4e 113 struct {
mariob 0:ce6055872f4e 114 uint32 cmd:16;
mariob 0:ce6055872f4e 115 uint32 opt:16;
mariob 0:ce6055872f4e 116 uint32 data;
mariob 0:ce6055872f4e 117 } msg;
mariob 0:ce6055872f4e 118 } can_cmd_driver_payload_t;
mariob 0:ce6055872f4e 119 typedef struct can_driver_time_s {
mariob 0:ce6055872f4e 120 can_cmd_driver_payload_t payload;
mariob 0:ce6055872f4e 121 uint8 flag;
mariob 0:ce6055872f4e 122 } can_cmd_driver_t;
mariob 0:ce6055872f4e 123
mariob 0:ce6055872f4e 124 typedef union can_sts_driver_payload_s {
mariob 0:ce6055872f4e 125 uint8 buf[CAN_STS_PAYLOAD_DRIVER];
mariob 0:ce6055872f4e 126 struct {
mariob 0:ce6055872f4e 127 uint32 data;
mariob 0:ce6055872f4e 128 } msg;
mariob 0:ce6055872f4e 129 } can_sts_driver_payload_t;
mariob 0:ce6055872f4e 130 typedef struct can_sts_driver_time_s {
mariob 0:ce6055872f4e 131 can_sts_driver_payload_t payload;
mariob 0:ce6055872f4e 132 uint8 flag;
mariob 0:ce6055872f4e 133 } can_sts_driver_t;
mariob 0:ce6055872f4e 134
mariob 0:ce6055872f4e 135 /**************************************************
mariob 0:ce6055872f4e 136 * DATA STRUCTURES
mariob 0:ce6055872f4e 137 **************************************************/
mariob 0:ce6055872f4e 138 void init_can();
mariob 0:ce6055872f4e 139
mariob 0:ce6055872f4e 140 bool can_msg_is_missing(uint8 msg_id);
mariob 0:ce6055872f4e 141
mariob 0:ce6055872f4e 142 #endif //__NET_H__