Skip to content

Commit 3f0a3a5

Browse files
committed
Update to Mbed 6.7
And a whole lot of other stuff
1 parent 7b3bf3d commit 3f0a3a5

19 files changed

+335
-119
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "bms/deps/optional"]
2+
path = bms/deps/optional
3+
url = https://github.com/TartanLlama/optional.git
File renamed without changes.

bms/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
mbed-os
2-
optional
1+
.mbedbuild
2+
cmake_build/

bms/.mbed

Lines changed: 0 additions & 3 deletions
This file was deleted.

bms/.mbedignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

bms/CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.19.0)
5+
6+
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
7+
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
8+
set(APP_TARGET bms)
9+
10+
set(CMAKE_CXX_STANDARD 17)
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
12+
13+
include(${MBED_PATH}/tools/cmake/app.cmake)
14+
15+
add_subdirectory(${MBED_PATH})
16+
17+
# Libraries
18+
#add_library(optional INTERFACE deps/optional)
19+
20+
add_executable(${APP_TARGET}
21+
src/Main.cpp
22+
src/BmsThread.cpp
23+
src/EnergusTempSensor.cpp
24+
src/LTC6811Bus.cpp
25+
src/LTC6811.cpp
26+
)
27+
28+
mbed_configure_app_target(${APP_TARGET})
29+
30+
project(${APP_TARGET})
31+
32+
target_link_libraries(${APP_TARGET} mbed-os)
33+
34+
mbed_set_post_build(${APP_TARGET})
35+
36+
option(VERBOSE_BUILD "Have a verbose build process")
37+
if(VERBOSE_BUILD)
38+
set(CMAKE_VERBOSE_MAKEFILE ON)
39+
endif()

bms/mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#b6370b4c37f3d4665ed1cdcb1afea85396bba1b3
1+
https://github.com/ARMmbed/mbed-os#master

bms/optional.lib

Lines changed: 0 additions & 1 deletion
This file was deleted.

bms/src/BmsConfig.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
#include "mbed.h"
44

5-
6-
// Global pointer to serial object
7-
//
8-
// This allows for all files to access the serial output
9-
extern Serial* serial;
10-
115
// Global pointer to can bus object
126
//
137
// This allows for all files to access the can bus output

bms/src/BmsThread.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include "BmsThread.h"
2+
3+
BMSThread::BMSThread(LTC6811Bus* bus, unsigned int frequency, std::vector<Queue<BmsEvent, mailboxSize>*> mailboxes) : m_bus(bus), mailboxes(mailboxes) {
4+
m_delay = 1000 / frequency;
5+
for (int i = 0; i < BMS_BANK_COUNT; i++) {
6+
m_chips.push_back(LTC6811(*bus, i));
7+
}
8+
for (int i = 0; i < BMS_BANK_COUNT; i++) {
9+
//m_chips[i].getConfig().gpio5 = LTC6811::GPIOOutputState::kLow;
10+
//m_chips[i].getConfig().gpio4 = LTC6811::GPIOOutputState::kPassive;
11+
12+
m_chips[i].updateConfig();
13+
}
14+
}
15+
16+
void BMSThread::threadWorker() {
17+
std::array<uint16_t, BMS_BANK_COUNT * BMS_BANK_CELL_COUNT> allVoltages;
18+
std::array<std::optional<int8_t>, BMS_BANK_COUNT * BMS_BANK_TEMP_COUNT> allTemps;
19+
20+
while (true) {
21+
// Measure from all BMS banks
22+
for (int i = 0; i < BMS_BANK_COUNT; i++) {
23+
LTC6811::Configuration& conf = m_chips[i].getConfig();
24+
25+
// Turn on status LED
26+
conf.gpio5 = LTC6811::GPIOOutputState::kLow;
27+
m_chips[i].updateConfig();
28+
29+
uint16_t* voltages = m_chips[i].getVoltages();
30+
31+
// Measure all temperature sensors on the current bank
32+
uint16_t temperatures[BMS_BANK_TEMP_COUNT];
33+
for (unsigned int j = 0; j < BMS_BANK_TEMP_COUNT; j++) {
34+
conf.gpio1 = (j & 0x01) ? LTC6811::GPIOOutputState::kHigh
35+
: LTC6811::GPIOOutputState::kLow;
36+
conf.gpio2 = (j & 0x02) ? LTC6811::GPIOOutputState::kHigh
37+
: LTC6811::GPIOOutputState::kLow;
38+
conf.gpio3 = (j & 0x04) ? LTC6811::GPIOOutputState::kHigh
39+
: LTC6811::GPIOOutputState::kLow;
40+
conf.gpio4 = LTC6811::GPIOOutputState::kPassive;
41+
m_chips[i].updateConfig();
42+
43+
// Wait for config changes to take effect
44+
ThisThread::sleep_for(3);
45+
46+
uint16_t* temps = m_chips[i].getGpioPin(GpioSelection::k4);
47+
temperatures[j] = temps[j] / 10;
48+
49+
delete temps;
50+
}
51+
52+
// Turn off status LED
53+
conf.gpio5 = LTC6811::GPIOOutputState::kHigh;
54+
m_chips[i].updateConfig();
55+
56+
//
57+
// Process values
58+
//
59+
for (int j = 0; j < 12; j++) {
60+
uint16_t voltage = voltages[j] / 10;
61+
62+
int index = BMS_CELL_MAP[j];
63+
if (index != -1) {
64+
allVoltages[(BMS_BANK_CELL_COUNT * i) + index] = voltage;
65+
}
66+
}
67+
68+
for (unsigned int j = 0; j < BMS_BANK_TEMP_COUNT; j++) {
69+
auto temp = convertTemp(temperatures[j]);
70+
allTemps[(BMS_BANK_TEMP_COUNT * i) + j] = temp;
71+
}
72+
73+
delete voltages;
74+
}
75+
76+
for(auto mailbox : mailboxes) {
77+
if(!mailbox->full()) {
78+
{
79+
auto msg = new VoltageMeasurement();
80+
msg->voltageValues = allVoltages;
81+
mailbox->put((BmsEvent*) msg);
82+
}
83+
{
84+
auto msg = new TemperatureMeasurement();
85+
msg->temperatureValues = allTemps;
86+
mailbox->put((BmsEvent*) msg);
87+
}
88+
}
89+
}
90+
}
91+
}
92+
93+
void BMSThread::throwBmsFault() {
94+
m_discharging = false;
95+
//palClearLine(LINE_BMS_FLT);
96+
//palSetLine(LINE_CHARGER_CONTROL);
97+
}

0 commit comments

Comments
 (0)