Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into 49-cangen-sim
Browse files Browse the repository at this point in the history
tszwinglitw committed Oct 20, 2024
2 parents eac7335 + fe86adc commit 5cb9db1
Showing 10 changed files with 246 additions and 234 deletions.
12 changes: 6 additions & 6 deletions ftdi_flash.cfg
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
adapter driver ftdi
ftdi vid_pid 0x0403 0x6010
ftdi_vid_pid 0x0403 0x6010

# Initial state: Assuming 0x0008 doesn't interfere with your setup
# and 0x000b sets the required initial states for your other signals.
ftdi layout_init 0x0008 0x000b
ftdi_layout_init 0x0008 0x000b

ftdi layout_signal LED_Tx -data 0x00F0 -oe 0x00F0
ftdi layout_signal LED_Rx -data 0x00F0 -oe 0x00F0
ftdi_layout_signal LED_Tx -data 0x00F0 -oe 0x00F0
ftdi_layout_signal LED_Rx -data 0x00F0 -oe 0x00F0

# Configure GPIOL0 (ADBUS4) as nSRST, assuming active low reset
# Setting `-data` for active low, `-oe` to enable output.
# If tri-state isn't supported, this configures the pin as push-pull.
ftdi layout_signal nSRST -data 0x0010 -oe 0x0010
ftdi_layout_signal nSRST -data 0x0010 -oe 0x0010

transport select jtag
transport select jtag
19 changes: 13 additions & 6 deletions general/include/LTC4015.h
Original file line number Diff line number Diff line change
@@ -39,12 +39,19 @@
//Enable Coulomb Counter Low Alert.(0xOD Bit 13)
//Enable Coulomb Counter High Alert.(0xOD Bit 12)

typedef int (*Read_Ptr)(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);

typedef int (*Write_Ptr)(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);

typedef struct {
I2C_HandleTypeDef *i2cHandle;
uint16_t chargeFaults; //Stores error faults from CHGSTATE register
uint16_t qcount;
uint16_t limitAlerts;

Read_Ptr read;
Write_Ptr write;
} LTC4015_T;

/**
@@ -54,7 +61,7 @@ typedef struct {
* @param hi2c
* @return HAL_StatusTypeDef
*/
HAL_StatusTypeDef LTC4015_Init(LTC4015_T *dev, I2C_HandleTypeDef *i2cHandle);
int LTC4015_Init(LTC4015_T *dev, Read_Ptr read, Write_Ptr write);

/**
* @brief Reads from the LTC4015EUHF#PBF load switch
@@ -63,7 +70,7 @@ HAL_StatusTypeDef LTC4015_Init(LTC4015_T *dev, I2C_HandleTypeDef *i2cHandle);
* @param dev
* @param i2c_handle
*/
HAL_StatusTypeDef LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data);
int LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data);

/**
* @brief Writes to the LTC4015EUHF#PBF load switch
@@ -73,7 +80,7 @@ HAL_StatusTypeDef LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data);
* @param i2c_handle
* @return HAL_StatusTypeDef
*/
HAL_StatusTypeDef LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data);
int LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data);

/**
* @brief Checks coulombs of charger to see if within a given range, more info on page 38-40
@@ -85,8 +92,8 @@ HAL_StatusTypeDef LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data);
* @param lowAlert
* @return HAL_StatusTypeDef, QCOUNT, Faulted
*/
HAL_StatusTypeDef LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler,
uint16_t highAlert, uint16_t lowAlert);
int LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler, uint16_t highAlert,
uint16_t lowAlert);

#ifndef MAX_NUM_LTC4015_INSTANCES
#define MAX_NUM_LTC4015_INSTANCES 1
56 changes: 27 additions & 29 deletions general/src/LTC4015.c
Original file line number Diff line number Diff line change
@@ -8,64 +8,62 @@

#include "LTC4015.h"

HAL_StatusTypeDef LTC4015_Init(LTC4015_T *dev, I2C_HandleTypeDef *i2cHandle)
int LTC4015_Init(LTC4015_T *dev, Read_Ptr read, Write_Ptr write)
{
dev->i2cHandle = i2cHandle;
dev->read = read;
dev->write = write;

// Gets the value from the Charging state register
LtC4015_read(dev, LTC4015_CHGSTATE, dev->CHGdata);
//Gets the value from the Charging state register
LtC4015_read(dev, LTC4015_CHGSTATE, &dev->chargeFaults);
}

HAL_StatusTypeDef LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data){
return HAL_I2C_Mem_Read(dev -> i2c_handle, LTC4015_ADDR_68, reg,
I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY)

int LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data)
{
return dev->read(LTC4015_ADDR_68, reg, 0x00000001U, data, 1);
}

HAL_StatusTypeDef LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data){
return HAL_I2C_Mem_Write(dev->i2c_handle, LTC4015_ADDR_68, reg,
I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY)
int LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data)
{
return dev->write(LTC4015_ADDR_68, reg, 0x00000001U, data, 1);
}

HAL_StatusTypeDef LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler,
uint16_t highAlert, uint16_t lowAlert)
int LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler, uint16_t highAlert,
uint16_t lowAlert)
{
// Increases integration time, at which QCOUNT is updated
//Increases integration time, at which QCOUNT is updated
LTC4015_write(dev, QCOUNT_PRESCALE_FACTOR, prescaler);

// Sets the High amount for the QCOUNT before error is flagged
//Sets the High amount for the QCOUNT before error is flagged
LTC4015_write(dev, QCOUNT_HI_ALERT_LIMIT, highAlert);
LTC4015_write(dev, EN_LIMIT_ALERTS,
0x1000); // Enable bit is in 12th bit postion
0x1000); //Enable bit is in 12th bit postion

// Sets the low amount for the QCOUNT before error is flagged
//Sets the low amount for the QCOUNT before error is flagged
LTC4015_write(dev, QCOUNT_LO_ALERT_LIMIT, lowAlert);
LTC4015_write(dev, EN_LIMIT_ALERTS,
0x2000); // Enable bit is in 13th bit postion
0x2000); //Enable bit is in 13th bit postion

LTC4015_write(dev, CONFIG_BITS,
0x0008); // enable QCOUNT, in bit postion 2
0x0008); //enable QCOUNT, in bit postion 2
LTC4015_read(dev, LIMIT_ALERTS, dev->limitAlerts);
LTC4015_read(dev, QCOUNT, dev->qcount);

// This all could be put into a while loop if you want to continually check
// for errors
//This all could be put into a while loop if you want to continually check for errors
LTC4015_write(dev, CONFIG_BITS,
(CONFIG_BITS ^
0x1000)); // should re-enable charging if was disabled
// Sees if the alerts are being flagged, and then will return the QCOUNT
0x1000)); //should re-enable charging if was disabled
//Sees if the alerts are being flagged, and then will return the QCOUNT
if (LIMIT_ALERTS | 0x1000 == 0x1000) {
LTC4015_write(
dev, EN_LIMIT_ALERTS,
(EN_LIMIT_ALERTS ^
0x1000)); // Should just reset the enable but touch nothing else
LTC4015_write(dev, CONFIG_BITS, 0x1000); // suspends charger
0x1000)); //Should just reset the enable but touch nothing else
LTC4015_write(dev, CONFIG_BITS, 0x1000); //suspends charger
return (QCOUNT,
highAlert) // Need away to tell its being flagged, but not
// really sure what to return
highAlert); //Need away to tell its being flagged, but not really sure what to return
} else if (LIMIT_ALERTS | 0x2000 == 0x2000) {
LTC4015_write(dev, EN_LIMIT_ALERTS, EN_LIMIT_ALERTS ^ 0x2000);
LTC4015_write(dev, CONFIG_BITS, 0x1000); // suspends charger
return (QCOUNT, lowAlert) // sames issue as above
LTC4015_write(dev, CONFIG_BITS, 0x1000); //suspends charger
return (QCOUNT, lowAlert); //sames issue as above
}
}
2 changes: 1 addition & 1 deletion ner_environment/build_system/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

from .build_system import main
from .build_system import app
from . import miniterm
Loading

0 comments on commit 5cb9db1

Please sign in to comment.