summaryrefslogtreecommitdiff
path: root/firmware/can.h
blob: 1bab0ba4094fdade31a75c92fbf4d4ee1f023829 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright (c) 2007 Marco Glietsch (http://www.mikrocontroller.net/topic/98697)
 * Original author: Marco Glietsch
 * Modified for octopus by Michael Hartmann <ich@speicherleck.de>
 * All rights reserved.
 *
 * Short descripton of file:
 *
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials provided 
 *     with the distribution.
 *   * Neither the name of the FH Augsburg nor the names of its 
 *     contributors may be used to endorse or promote products derived 
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES{} LOSS OF USE, 
 * DATA, OR PROFITS{} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef CAN_H
#define CAN_H

#include <inttypes.h>

#define setbit(ADR,BIT)   (ADR |= (1<<BIT))
#define clearbit(ADR,BIT) (ADR &=~(1<<BIT))
#define getbit(ADR, BIT)  (ADR &  (1<<BIT))

/* CAN Objekte */
#define NO_MOBS 15   // Anzahl der Message Objects festlegen
#define NOMOB   0xff // Definition für ungültigen Objektindex

// baudrate
enum { CAN_BAUDRATE_100K, CAN_BAUDRATE_125K, CAN_BAUDRATE_200K,
       CAN_BAUDRATE_250K, CAN_BAUDRATE_500K, CAN_BAUDRATE_1000K };

// Betriebsmodi
enum { CAN_MODE_DISABLED, CAN_MODE_TRANSMIT_DATA, CAN_MODE_TRANSMIT_REMOTE,
       CAN_MODE_RECEIVE_DATA, CAN_MODE_AUTO_REPLY };

// Interrupt-Modi
enum { CAN_INTERRUPTS_NONE, CAN_INTERRUPTS_TX, CAN_INTERRUPTS_RX,
       CAN_INTERRUPTS_TXRX };

void can_parser(uint8_t *buf);

int can_init(uint8_t baudrate, uint8_t intmode, uint8_t eid);
void can_init_usb(uint8_t baudrate, uint8_t eid);

int can_deinit(void);
void can_deinit_usb(void);

int can_enable_mob(uint8_t mob, uint8_t mode, uint32_t id, uint32_t idm);
void can_enable_mob_usb(uint8_t mob, uint8_t mode, uint32_t id, uint32_t idm);

int can_disable_mob(uint8_t mob);
void can_disable_mob_usb(uint8_t mob);

int can_send_data(uint8_t mob, uint8_t length, uint8_t * data);
void can_send_data_usb(uint8_t mob, uint8_t length, uint8_t *data);

int can_send_remote(uint8_t mob);
void can_send_remote_usb(uint8_t mob);

void can_receive_data_usb(int mob);

void can_set_autoreply(uint8_t mob, uint8_t length, uint8_t *buf);
void can_set_autoreply_usb(uint8_t mob, uint8_t length, uint8_t *buf);

// sonsitge hilfsfunktionen
int can_set_baudrate(uint8_t baudrate);
int can_set_interrupt(uint8_t mode);
void can_get_mob(uint8_t mob);
uint32_t can_get_id(void);
void can_set_id_mask(uint32_t idm);
void can_set_id(uint32_t id);
int can_set_mode(uint8_t mode);
uint8_t can_get_mode(void);
void can_set_data(uint8_t length, uint8_t * data);
void can_get_data(int8_t *msg);
void can_set_mob_interrupt(uint8_t object);
void can_clear_mob_interrupt(uint8_t mob);
uint8_t can_get_mob_interrupt(void);

#endif /* CAN_H */