add CAN, not tested yet

This commit is contained in:
Edward Emelianov
2026-02-18 22:54:20 +03:00
parent 68028f42a3
commit 80c894517e
16 changed files with 1028 additions and 7 deletions

View File

@@ -16,10 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "can.h"
#include "canproto.h"
#include "Debug.h"
#include "flash.h"
#include "hardware.h"
#include "proto.h"
#include "strfunc.h"
#include "usart.h"
#include "usb_dev.h"
@@ -44,6 +47,7 @@ int main(void){
hw_setup();
USBPU_OFF();
USB_setup();
CAN_setup(the_conf.CANspeed);
//uint32_t ctr = Tms;
//usb_LineCoding lc = {9600, 0, 0, 8};
//for(int i = 0; i < 5; ++i) usart_config(i, &lc); // configure all U[S]ARTs for default data
@@ -51,6 +55,7 @@ int main(void){
while(1){
// Put here code working WITOUT USB connected
if(!usbON) continue;
// and here is code what should run when USB connected
usarts_process();
DBGpri();
/*for(int i = 0; i < 6; ++i){ // just echo for first time
@@ -58,7 +63,32 @@ int main(void){
int l = USB_receive(i, (uint8_t*)inbuff, MAXSTRLEN);
if(l) USB_send(i, (uint8_t*)inbuff, l);
}*/
// and here is code what should run when USB connected
if(CDCready[ICAN]){
CAN_proc();
if(CAN_get_status() == CAN_FIFO_OVERRUN){
USB_sendstr(ICAN, "CAN bus fifo overrun occured!\n");
}
CAN_message *can_mesg;
while((can_mesg = CAN_messagebuf_pop())){
if(can_mesg && CANsoftFilter(can_mesg->ID)){
if(CANShowMsgs){ // display message content
IWDG->KR = IWDG_REFRESH;
uint8_t len = can_mesg->length;
USB_sendstr(ICAN, u2str(Tms));
USB_sendstr(ICAN, " #");
USB_sendstr(ICAN, u2str(can_mesg->ID));
for(uint8_t i = 0; i < len; ++i){
USB_putbyte(ICAN, ' ');
USB_sendstr(ICAN, u2str(can_mesg->data[i]));
}
newline(ICAN);
}
}
}
int l = USB_receivestr(ICAN, inbuff, MAXSTRLEN);
if(l < 0) USB_sendstr(ICAN, "ERROR: USB buffer overflow or string was too long\n");
else if(l) CANcmd_parser(inbuff);
}
if(Config_mode && CDCready[ICFG]){
/*if(Tms - ctr > 4999){
ctr = Tms;