at90can_send_buf_message.c
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_send_buf_message.c 6837 2008-11-16 19:05:15Z fabian $
28  */
29 // -----------------------------------------------------------------------------
30 
31 #include "at90can_private.h"
32 #if defined(SUPPORT_FOR_AT90CAN__) && CAN_TX_BUFFER_SIZE > 0
33 
34 #include <string.h>
35 
36 // -----------------------------------------------------------------------------
37 uint8_t at90can_send_buffered_message(const can_t *msg)
38 {
39  // check if there is any free buffer left
40 #if CAN_FORCE_TX_ORDER
41  if (_transmission_in_progress)
42 #else
43  if (_find_free_mob() == 0xff)
44 #endif
45  {
46  can_t *buf = can_buffer_get_enqueue_ptr(&can_tx_buffer);
47 
48  if (buf == NULL)
49  return 0; // buffer full
50 
51  // copy message to the buffer
52  memcpy( buf, msg, sizeof(can_t) );
53 
54  // In the interrupt it is checked if there are any waiting messages
55  // in the queue, otherwise the interrupt will be disabled.
56  // So, if the transmission finished while we are in this routine the
57  // message will be queued but not send.
58  // Therefore interrupts have to disabled while putting the message
59  // to the queue.
60  bool enqueued = false;
61 
62 #if CAN_FORCE_TX_ORDER
64  if (_transmission_in_progress)
65  {
66  can_buffer_enqueue(&can_tx_buffer);
67  enqueued = true;
68  }
70 #endif
71 
72  if (enqueued) {
73  return 1;
74  }
75  else {
76  // buffer gets free while we where preparing the message
77  // => send message directly
78  return at90can_send_message( msg );
79  }
80  }
81  else
82  {
83  return at90can_send_message( msg );
84  }
85 }
86 
87 #endif // SUPPORT_FOR_AT90CAN__
ENTER_CRITICAL_SECTION
#define ENTER_CRITICAL_SECTION
Definition: utils.h:126
can_t
Datenstruktur zum Aufnehmen von CAN Nachrichten.
Definition: can.h:177
can_buffer_get_enqueue_ptr
can_t * can_buffer_get_enqueue_ptr(can_buffer_t *buf)
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
at90can_private.h
can_buffer_enqueue
void can_buffer_enqueue(can_buffer_t *buf)
NULL
#define NULL
Nullzeiger.
Definition: utils.h:64
LEAVE_CRITICAL_SECTION
#define LEAVE_CRITICAL_SECTION
Definition: utils.h:127


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