at90can_private.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 /*
3  * Copyright (c) 2007 Fabian Greif, Roboterclub Aachen e.V.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $Id: at90can_private.h 6910 2008-11-30 21:13:14Z fabian $
28  */
29 // ----------------------------------------------------------------------------
30 
31 #ifndef AT90CAN_PRIVATE_H
32 #define AT90CAN_PRIVATE_H
33 
34 // ----------------------------------------------------------------------------
35 
36 #include <avr/io.h>
37 #include <avr/interrupt.h>
38 
39 #include <stdlib.h>
40 
41 #include "can_private.h"
42 #include "can.h"
43 #include "can_buffer.h"
44 #include "utils.h"
45 
46 // ----------------------------------------------------------------------------
47 
48 #if (defined (__AVR_AT90CAN32__) || \
49  defined (__AVR_AT90CAN64__) || \
50  defined (__AVR_AT90CAN128__)) && \
51  BUILD_FOR_AT90CAN == 1
52 
53 #if F_CPU != 16000000UL
54  #error only 16 MHz for F_CPU supported!
55 #endif
56 
57 #define SUPPORT_FOR_AT90CAN__ 1
58 
59 // ----------------------------------------------------------------------------
60 
61 #if CAN_RX_BUFFER_SIZE > 0
62 extern can_buffer_t can_rx_buffer;
63 #else
64 // Indicates the number of MObs which have currently one received
65 // message stored in them.
66 extern volatile uint8_t _messages_waiting;
67 #endif
68 
69 #if CAN_TX_BUFFER_SIZE > 0
70 extern can_buffer_t can_tx_buffer;
71 #else
72 extern volatile uint8_t _free_buffer;
73 #endif
74 
75 #if CAN_FORCE_TX_ORDER
76 extern volatile uint8_t _transmission_in_progress ;
77 #endif
78 
79 // ----------------------------------------------------------------------------
80 extern uint8_t _find_free_mob(void);
81 
82 // ----------------------------------------------------------------------------
83 extern void _disable_mob_interrupt(uint8_t mob);
84 
85 // ----------------------------------------------------------------------------
86 extern void _enable_mob_interrupt(uint8_t mob);
87 
88 
89 // ----------------------------------------------------------------------------
90 extern uint8_t at90can_send_message(const can_t *msg);
91 
92 // ----------------------------------------------------------------------------
93 extern uint8_t at90can_get_message(can_t *msg);
94 
95 // ----------------------------------------------------------------------------
101 extern void at90can_copy_message_to_mob(const can_t *msg);
102 
103 // ----------------------------------------------------------------------------
113 extern bool at90can_copy_mob_to_message(can_t *msg);
114 
115 // ----------------------------------------------------------------------------
116 // enter standby mode => messages are not transmitted nor received
117 
118 extern __attribute__ ((gnu_inline)) inline void _enter_standby_mode(void)
119 {
120  // request abort
121  CANGCON = (1 << ABRQ);
122 
123  // wait until receiver is not busy
124  while (CANGSTA & (1 << RXBSY))
125  ;
126 
127  // request standby mode
128  CANGCON = 0;
129 
130  // wait until the CAN Controller has entered standby mode
131  while (CANGSTA & (1 << ENFG))
132  ;
133 }
134 
135 // ----------------------------------------------------------------------------
136 // leave standby mode => CAN Controller is connected to CAN Bus
137 
138 extern __attribute__ ((gnu_inline)) inline void _leave_standby_mode(void)
139 {
140  // save CANPAGE register
141  uint8_t canpage = CANPAGE;
142 
143  // reenable all MObs
144  for (uint8_t i=0;i<15;i++) {
145  CANPAGE = i << 4;
146  CANCDMOB = CANCDMOB;
147  }
148 
149  // restore CANPAGE
150  CANPAGE = canpage;
151 
152  // request normal mode
153  CANGCON = (1 << ENASTB);
154 
155  // wait until the CAN Controller has left standby mode
156  while ((CANGSTA & (1 << ENFG)) == 0)
157  ;
158 }
159 
160 #endif
161 
162 // ----------------------------------------------------------------------------
163 
164 #endif // AT90CAN_PRIVATE_H
can_t
Datenstruktur zum Aufnehmen von CAN Nachrichten.
Definition: can.h:177
utils.h
can_buffer.h
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
can_private.h
can_buffer_t
Definition: can_buffer.h:39
__attribute__
__attribute__((gnu_inline)) inline void spi_start(uint8_t data)
Definition: spi.h:74


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02