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.
Dependencies: Queue mbed-rtos mbed
can_bus.cpp
00001 #include "mbed.h" 00002 #include "types.h" 00003 #include "rtos.h" 00004 00005 #if 0 00006 00007 CAN HSCAN(p30, p29); 00008 uint32 id; 00009 volatile uint32 available = 0; 00010 Thread canThread; 00011 00012 void can_init(void) 00013 { 00014 //thread.start(); 00015 } 00016 00017 void can_bus_rx_IRQ() 00018 { 00019 uint8 msg_raw[12]; 00020 CANMessage msg; 00021 if(HSCAN.read(msg)) 00022 { 00023 msg_raw[0] = (uint8)(msg.id >> 24); 00024 msg_raw[1] = (uint8)(msg.id >> 16); 00025 msg_raw[2] = (uint8)(msg.id >> 8); 00026 msg_raw[3] = (uint8)(msg.id >> 0); 00027 for(int i=0;i<8;i++) 00028 msg_raw[i+4] = msg.data[i]; 00029 } 00030 } 00031 00032 void can_bus_configure(uint32 txID,uint32 rxID,uint32 speed) 00033 { 00034 available = 0; 00035 HSCAN.reset(); 00036 wait(2); // wait for 2 seconds 00037 HSCAN.frequency(speed); 00038 HSCAN.filter(rxID,0xFFFFFF); 00039 HSCAN.attach(can_bus_rx_IRQ,CAN::RxIrq); 00040 id = txID; 00041 } 00042 00043 void can_bus_send(uint8 * message, uint8 dlc=8) 00044 { 00045 CANMessage msg; 00046 msg.id = id; 00047 msg.len = dlc; 00048 for(int i=0;i<dlc;i++) msg.data[i] = message[i]; 00049 HSCAN.write(msg); 00050 } 00051 00052 CANMessage can_bus_receive(void) 00053 { 00054 if(available) 00055 { 00056 00057 } 00058 } 00059 00060 uint32 can_bus_available(void) 00061 { 00062 return available; 00063 } 00064 00065 #endif
Generated on Thu Jul 14 2022 01:35:32 by
1.7.2