Skip to content

Commit

Permalink
Change from EV-CAN to Chademo
Browse files Browse the repository at this point in the history
  • Loading branch information
dalathegreat committed Sep 26, 2023
2 parents beeb4bb + 73cd2cd commit e1dfd11
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 120 deletions.
19 changes: 15 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ This document describe how to build firmware and burn on MUXSAN can bridge

## On Linux

### Install AVR compiler and dependencies
sudo apt-get install gcc-avr binutils-avr avr-libc
### Build

#> cd <clone repo>/leaf-can-bridge-3-port-CCS/Debug
#> make -f Makefile.multiOS all
#> cd <clone repo>/leaf-can-bridge-3-port-CCS/Debug

clean all win pre complied files to avoid issue like
the following one
https://github.com/dalathegreat/Nissan-LEAF-CCS/pull/2#issuecomment-1046327328

#> make -f Makefile.multiOS clean

build

#> make -f Makefile.multiOS all

### Burn

#> avrdude -c avrispmkII -p ATMega32c4 -P usb -e -U flash:w:<your hex file>
#> avrdude -c avrispmkII -p ATMega32c4 -P usb -e -U flash:w:<your hex file>

NOTE: You should use the correct -c option depending on avr flasher
NOTE: You should use the correct **-c** option depending on avr flasher

## On OSX
Not tested, please refer to Build on Linux guide
Expand Down
2 changes: 0 additions & 2 deletions leaf-can-bridge-3-port-CCS/can-bridge-ccs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
CCS ADD-ON FIRMWARE
When fitted between the LIM Powertrain CAN and QC-CAN, this firmware allows for CCS charging.
Expand Down Expand Up @@ -1092,4 +1091,3 @@ void check_can3(void){
}
}
}
}
193 changes: 79 additions & 114 deletions leaf-can-bridge-3-port-CCS/can-bridge-ccs.h
Original file line number Diff line number Diff line change
@@ -1,114 +1,79 @@
#include <avr/wdt.h>
#include <avr/power.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stddef.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include <avr/eeprom.h>
#include "Descriptors.h"
#include "LUFA/Platform/Platform.h"
#include "LUFA/Drivers/USB/USB.h"
#include "sp_driver.h"
#include "mcp25xx.h"
#include "helper_functions.h"

//function prototypes
void hw_init(void);
void print(char * str, uint8_t len);
void uint32_to_str(char * str, uint32_t num);
void SID_to_str(char * str, uint32_t num);
//void blink(void);
void canframe_to_str(char * str, can_frame_t frame);
void send_can(uint8_t can_bus, can_frame_t frame);
void send_can1(can_frame_t frame);
void send_can2(can_frame_t frame);
void send_can3(can_frame_t frame);
void can_handler(uint8_t can_bus);
void ProcessCDCCommand(void);
void check_can1(void);
void check_can2(void);
void check_can3(void);


//defines
#define TC0_CLKSEL_DIV1_gc 0b0001
#define TC0_CLKSEL_DIV256_gc 0b0110
#define TC0_CLKSEL_DIV1024_gc 0b0111
#define TC0_OVFINTLVL_HI_gc 0b11
#define TC0_OVFINTLVL_LO_gc 0b01
#define TC0_CCAINTLVL_HI_gc 0x03
#define TC0_CCBINTLVL_HI_gc 0x0C
#define TC0_CCCINTLVL_HI_gc 0x30
#define TC0_WGMODE_SINGLESLOPE_bm 0x03

#define OUTBUF_SIZE 2048
#define CURVOL_AVERAGES 100

#define SHIFT_P 0x00
#define SHIFT_D 0x40 //Modified, no longer following mux standard
#define SHIFT_N 0x30
#define SHIFT_R 0x20

#define TXBUFFER_SIZE 16

USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = {
.Config = {
.ControlInterfaceNumber = 0,
.DataINEndpoint = {
.Address = CDC_TX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint = {
.Address = CDC_RX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.NotificationEndpoint = {
.Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1,
},
},
};


typedef struct {
int Batt_Wh:16;
int CHG_Status:4;
int CHG_Req:4;
int CHG_Power_LSB:4;
int DCFC_I_Diff:2;
int CHG_Readiness:2;
int CHG_Power_MSB:8;
int FC_Current_Command_LSB:8;
int Contactor_Con:4;
int DCFC_V_Diff:2;
int FC_Current_Command_MSB:2;
int EOC_Time:8;
} VCU_3E9;

typedef struct {
int CHG_V_Limit_LSB:8;
int BLANK:2;
int CHG_V_Limit_MSB:6;
int CHG_I_Lim:8;
int Time_to_SOC:16;
int Time_to_FC_SOC:16;
int FC_SOC:8;
} VCU_2F1;

typedef struct {
int Time2Go:16;
int Target_CHG_Ph:4;
int Chg_End:2;
int FC_End:2;
int Target_Volts_LSB:8;
int BLANK:2;
int Target_Volts_MSB:6;
int BLANK2:16;
int BLANK3:8;
} VCU_2FA;
#include <avr/wdt.h>
#include <avr/power.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stddef.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include <avr/eeprom.h>
#include "Descriptors.h"
#include "LUFA/Platform/Platform.h"
#include "LUFA/Drivers/USB/USB.h"
#include "sp_driver.h"
#include "mcp25xx.h"
#include "helper_functions.h"

//function prototypes
void hw_init(void);
void print(char * str, uint8_t len);
void uint32_to_str(char * str, uint32_t num);
void SID_to_str(char * str, uint32_t num);
//void blink(void);
void canframe_to_str(char * str, can_frame_t frame);
void send_can(uint8_t can_bus, can_frame_t frame);
void send_can1(can_frame_t frame);
void send_can2(can_frame_t frame);
void send_can3(can_frame_t frame);
void can_handler(uint8_t can_bus);
void ProcessCDCCommand(void);
void check_can1(void);
void check_can2(void);
void check_can3(void);
void CCS_Pwr_Con(void);
void Chg_Timers(void);
void ControlCharge(void);


//defines
#define TC0_CLKSEL_DIV1_gc 0b0001
#define TC0_CLKSEL_DIV256_gc 0b0110
#define TC0_CLKSEL_DIV1024_gc 0b0111
#define TC0_OVFINTLVL_HI_gc 0b11
#define TC0_OVFINTLVL_LO_gc 0b01
#define TC0_CCAINTLVL_HI_gc 0x03
#define TC0_CCBINTLVL_HI_gc 0x0C
#define TC0_CCCINTLVL_HI_gc 0x30
#define TC0_WGMODE_SINGLESLOPE_bm 0x03

#define OUTBUF_SIZE 2048
#define CURVOL_AVERAGES 100

#define SHIFT_P 0x00
#define SHIFT_D 0x40
#define SHIFT_N 0x30
#define SHIFT_R 0x20

#define TXBUFFER_SIZE 16

USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = {
.Config = {
.ControlInterfaceNumber = 0,
.DataINEndpoint = {
.Address = CDC_TX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint = {
.Address = CDC_RX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.NotificationEndpoint = {
.Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1,
},
},
};

0 comments on commit e1dfd11

Please sign in to comment.