Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
can_mbed.cpp
00001 /* 00002 This file is part of CanFestival, a library implementing CanOpen Stack. 00003 00004 Copyright (C): Edouard TISSERANT and Francis DUPIN 00005 mbed Port: sgrove 00006 00007 See COPYING file for copyrights details. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 //#define DEBUG_WAR_CONSOLE_ON 00025 //#define DEBUG_ERR_CONSOLE_ON 00026 00027 #include "can_mbed.h" 00028 #include "canfestival.h" 00029 00030 volatile unsigned char msg_received = 0; 00031 // initialize the CAN object from the mbed api 00032 CAN CANopen(p9, p10); 00033 00034 unsigned char canInit(unsigned int bitrate) 00035 /****************************************************************************** 00036 Initialize the hardware to send and receive CAN messages 00037 INPUT bitrate bitrate in kilobit 00038 OUTPUT 1 if successful 00039 ******************************************************************************/ 00040 { 00041 // make sure the requested baudrate is supported 00042 if (CANopen.frequency(bitrate*1000) == 0){ 00043 return 0; 00044 } 00045 // desired baud was set 00046 return 1; 00047 } 00048 00049 unsigned char canSend(CAN_PORT notused, Message *m) 00050 /****************************************************************************** 00051 The driver send a CAN message passed from the CANopen stack 00052 INPUT CAN_PORT is not used (only 1 avaiable) 00053 Message *m pointer to message to send 00054 OUTPUT 1 if hardware -> CAN frame 00055 ******************************************************************************/ 00056 { 00057 // convert the message from a CANopen object to a mbed object 00058 CANMessage msg(m->cob_id, (char*)m->data, m->len, static_cast<CANType>(m->rtr), CANStandard); 00059 // make sure the message was sent 00060 if (CANopen.write(msg) == 0){ 00061 return 0; 00062 } 00063 // message was sent 00064 return 1; 00065 } 00066 00067 unsigned char canReceive(Message *m) 00068 /****************************************************************************** 00069 The driver pass a received CAN message to the stack 00070 INPUT Message *m pointer to received CAN message 00071 OUTPUT 1 if a message received 00072 ******************************************************************************/ 00073 { 00074 // object to store the last message 00075 CANMessage msg; 00076 // look if something has been rec'd 00077 if (CANopen.read(msg) == 0){ 00078 return 0; 00079 } 00080 // conver the CANMessage object to a Message object 00081 m->cob_id = msg.id; 00082 m->len = msg.len; 00083 m->rtr = static_cast<UNS8>(msg.type); 00084 // clear erroneous data from the stack 00085 for (int i=0; i<=7; i++){ 00086 if ((msg.len-1) >= i) 00087 m->data[i] = msg.data[i]; 00088 else 00089 m->data[i] = 0; 00090 } 00091 return 1; 00092 } 00093 00094 /***************************************************************************/ 00095 unsigned char canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) 00096 { 00097 // not sure how baud is passed as a char* yet 00098 return 0; 00099 } 00100
Generated on Tue Jul 12 2022 17:11:51 by
1.7.2