00001 /* 00002 * Copyright (C) 2004 by Ole Reinhardt <ole.reinhardt@kernelconcepts.de>, 00003 * Kernelconcepts http://www.kernelconcepts.de 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. Neither the name of the copyright holders nor the names of 00015 * contributors may be used to endorse or promote products derived 00016 * from this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS 00019 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00021 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE 00022 * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00024 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00025 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00028 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00029 * SUCH DAMAGE. 00030 * 00031 * For additional information see http://www.ethernut.de/ 00032 * 00033 */ 00034 00043 /* 00044 * $Log$ 00045 * Revision 1.7 2008/08/11 06:59:41 haraldkipp 00046 * BSD types replaced by stdint types (feature request #1282721). 00047 * 00048 * Revision 1.6 2007/09/08 03:01:11 hwmaier 00049 * Changes to support RX time-out, CAN_SetRxTimeout() added. 00050 * 00051 * Revision 1.5 2005/10/07 21:38:44 hwmaier 00052 * CAN_SetSpeed function added. 00053 * 00054 * Revision 1.4 2004/08/25 15:45:18 olereinhardt 00055 * Added function to set acceptance filter 00056 * 00057 * Revision 1.3 2004/08/02 09:56:13 olereinhardt 00058 * changed typing of CAN_TryRxFrame 00059 * 00060 * Revision 1.2 2004/06/23 10:17:04 olereinhardt 00061 * Added buffer monitoring functions (free / avail) 00062 * 00063 * Revision 1.1 2004/06/07 15:15:28 olereinhardt 00064 * Initial checkin 00065 * 00066 */ 00067 00072 00073 00074 /* Not ported. */ 00075 #ifdef __GNUC__ 00076 00077 #include <stdio.h> 00078 #include <sys/timer.h> 00079 #include <sys/device.h> 00080 #include <dev/can_dev.h> 00081 00082 00083 uint8_t CAN_SetSpeed(NUTDEVICE *dev, uint32_t baudrate) 00084 { 00085 return (((IFCAN *)(dev->dev_icb))->can_set_baud)(dev, baudrate); 00086 } 00087 00088 void CAN_SetFilter(NUTDEVICE *dev, uint8_t *ac, uint8_t *am) 00089 { 00090 (((IFCAN *)(dev->dev_icb))->can_set_ac)(dev, ac); 00091 (((IFCAN *)(dev->dev_icb))->can_set_am)(dev, am); 00092 } 00093 00094 void CAN_TxFrame(NUTDEVICE *dev, CANFRAME *frame) 00095 { 00096 (((IFCAN *)(dev->dev_icb))->can_send)(dev, frame); 00097 } 00098 00099 uint8_t CAN_TryTxFrame(NUTDEVICE *dev, CANFRAME *frame) 00100 { 00101 if (((IFCAN *)(dev->dev_icb))->can_txfree(dev)) { 00102 (((IFCAN *)(dev->dev_icb))->can_send)(dev, frame); 00103 return 0; 00104 } 00105 return 1; 00106 } 00107 00108 uint8_t CAN_TxFree(NUTDEVICE *dev) 00109 { 00110 return ((IFCAN *)(dev->dev_icb))->can_txfree(dev); 00111 } 00112 00113 uint8_t CAN_RxFrame(NUTDEVICE *dev, CANFRAME *frame) 00114 { 00115 return (((IFCAN *)(dev->dev_icb))->can_recv)(dev, frame); 00116 } 00117 00118 uint8_t CAN_TryRxFrame(NUTDEVICE *dev, CANFRAME *frame) 00119 { 00120 if (((IFCAN *)(dev->dev_icb))->can_rxavail(dev)) { 00121 (((IFCAN *)(dev->dev_icb))->can_recv)(dev, frame); 00122 return 0; 00123 } 00124 return 1; 00125 } 00126 00127 uint8_t CAN_RxAvail(NUTDEVICE *dev) 00128 { 00129 return ((IFCAN *)(dev->dev_icb))->can_rxavail(dev); 00130 } 00131 00142 void CAN_SetRxTimeout(NUTDEVICE *dev, uint32_t timeout) 00143 { 00144 ((IFCAN *)(dev->dev_icb))->can_rtimeout = timeout; 00145 } 00146 00147 00148 #else 00149 00150 void keep_icc_happy(void) 00151 { 00152 } 00153 00154 #endif 00155