program which tests the CAR project (concerning the CAN bus)

Dependencies:   mbed

net.hpp

Committer:
mariob
Date:
2015-08-02
Revision:
0:8097eeede645
Child:
1:8446a0d14877

File content as of revision 0:8097eeede645:

#ifndef __NET_H__
#define __NET_H__

#include "common_types.h"

#define CAN_FLAG_EMPTY          0x00
#define CAN_FLAG_RECEIVED       0x01
#define CAN_FLAG_SEND           0x02


/**************************************************
 * 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_1s               10
#define PERIOD_500ms            5

#define CAN_STS_BODY_PERIOD     PERIOD_500ms

/**************************************************
 * 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_driver_time_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
 **************************************************/
void init_can(CAN *device);

#endif //__NET_H__