Skip to content

Commit 063a250

Browse files
implemented power service
1 parent 4150493 commit 063a250

23 files changed

+861
-35
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
5757
src/status_led.h
5858
src/services/imu_service/imu_service.cpp
5959
src/services/imu_service/imu_service.hpp
60+
src/services/power_service/power_service.cpp
61+
src/services/power_service/power_service.hpp
62+
src/services/power_service/bq_2576/bq_2576.cpp
63+
src/services/power_service/bq_2576/bq_2576.hpp
64+
6065
)
6166

6267
# Add include paths
@@ -78,6 +83,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
7883
)
7984

8085
target_add_service(${CMAKE_PROJECT_NAME} ImuService ${CMAKE_CURRENT_SOURCE_DIR}/services/imu_service.json)
86+
target_add_service(${CMAKE_PROJECT_NAME} PowerService ${CMAKE_CURRENT_SOURCE_DIR}/services/power_service.json)
8187

8288
set_target_properties(${CMAKE_PROJECT_NAME}
8389
PROPERTIES SUFFIX ".elf")

boards/XCORE/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,7 @@ bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
264264
*/
265265
void boardInit(void) {
266266

267+
268+
initBoardPeriphs();
269+
267270
}

boards/XCORE/board_ex.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Created by clemens on 05.11.24.
3+
//
4+
#include "board_ex.h"
5+
6+
#include "ch.h"
7+
#include "hal.h"
8+
9+
static I2CConfig i2c1Config = {0};
10+
static I2CConfig i2c2Config = {0};
11+
static I2CConfig i2c4Config = {0};
12+
13+
void initBoardPeriphs(void) {
14+
/**
15+
* Init I2C1
16+
*/
17+
i2cAcquireBus(&I2CD1);
18+
19+
// Calculated depending on clock source, check reference manual
20+
i2c1Config.timingr = 0xE14;
21+
22+
if (i2cStart(&I2CD1, &i2c1Config) != HAL_RET_SUCCESS) {
23+
while (1)
24+
;
25+
}
26+
i2cReleaseBus(&I2CD1);
27+
/**
28+
* Init I2C4 with 100kHz
29+
*/
30+
i2cAcquireBus(&I2CD2);
31+
32+
// Calculated depending on clock source, check reference manual
33+
i2c2Config.timingr = 0xE14;
34+
35+
if (i2cStart(&I2CD2, &i2c2Config) != HAL_RET_SUCCESS) {
36+
while (1)
37+
;
38+
}
39+
i2cReleaseBus(&I2CD2);
40+
/**
41+
* Init I2C4 with 100kHz
42+
*/
43+
i2cAcquireBus(&I2CD4);
44+
45+
// Calculated depending on clock source, check reference manual
46+
i2c4Config.timingr = 0xE14;
47+
48+
if (i2cStart(&I2CD4, &i2c4Config) != HAL_RET_SUCCESS) {
49+
while (1)
50+
;
51+
}
52+
i2cReleaseBus(&I2CD4);
53+
}

boards/XCORE/board_ex.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@
6767
#define PROGRAM_FLASH_SIZE_BYTES (FLASH_PAGE_COUNT * FLASH_PAGE_SIZE_BYTES)
6868

6969
#define SPID_IMU SPID3
70-
70+
#ifndef __ASSEMBLER__
71+
void initBoardPeriphs(void);
72+
#endif
7173
#endif

boards/XCORE/cfg/board.chcfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
</configuration_settings>
1212
<board_name>xcore</board_name>
1313
<board_id>XCORE</board_id>
14-
<board_functions></board_functions>
14+
<board_functions>
15+
<boardInit>
16+
initBoardPeriphs();
17+
</boardInit>
18+
</board_functions>
1519
<headers>
1620
<header>board_ex.h</header>
1721
</headers>

boards/XCORE/mcuconf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@
270270
/*
271271
* I2C driver system settings.
272272
*/
273-
#define STM32_I2C_USE_I2C1 FALSE
274-
#define STM32_I2C_USE_I2C2 FALSE
273+
#define STM32_I2C_USE_I2C1 TRUE
274+
#define STM32_I2C_USE_I2C2 TRUE
275275
#define STM32_I2C_USE_I2C3 FALSE
276276
#define STM32_I2C_USE_I2C4 TRUE
277277
#define STM32_I2C_BUSY_TIMEOUT 50

cfg/chconf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ extern volatile uint32_t last_idle_tick;
258258
* @note Requires @p CH_CFG_USE_MUTEXES.
259259
*/
260260
#if !defined(CH_CFG_USE_MUTEXES_RECURSIVE)
261-
#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
261+
#define CH_CFG_USE_MUTEXES_RECURSIVE TRUE
262262
#endif
263263

264264
/**

ext/ChibiOS_21.11.3/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ add_library(
9999
os/oslib/src/chfactory.c
100100
# board
101101
${BOARD_DIR}/board.c
102+
${BOARD_DIR}/board_ex.c
102103
# LwIP
103104
os/various/lwip_bindings/lwipthread.c
104105
os/various/lwip_bindings/arch/sys_arch.c

main.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#include <xbot-service/portable/system.hpp>
1818

1919
#include "services/imu_service/imu_service.hpp"
20+
#include "services/power_service/power_service.hpp"
2021
ImuService imu_service{4};
21-
22+
PowerService power_service{5};
2223
/*
2324
* Application entry point.
2425
*/
@@ -47,7 +48,6 @@ int main(void) {
4748
#ifdef USE_SEGGER_SYSTEMVIEW
4849
SYSVIEW_ChibiOS_Start(STM32_SYS_CK, STM32_SYS_CK, "I#15=SysTick");
4950
#endif
50-
ID_EEPROM_Init();
5151

5252
/*
5353
* InitGlobals() sets up global variables shared by threads. (e.g. mutex)
@@ -81,16 +81,6 @@ int main(void) {
8181
xbot::service::system::initSystem();
8282
xbot::service::Io::start();
8383
imu_service.start();
84-
85-
int i = 0;
86-
while (1) {
87-
chThdSleep(TIME_MS2I(100));
88-
const auto idle_thread = chSysGetIdleThreadX();
89-
const auto first_thread = chRegFirstThread();
90-
for (thread_t* t = first_thread; t; t = chRegNextThread(t)) {
91-
chprintf((BaseSequentialStream*)&RTTD0, "chprintf: %s\t %llu\n", t->name,
92-
t->stats.cumulative);
93-
}
94-
}
84+
power_service.start();
9585
chThdSleep(TIME_INFINITE);
9686
}

services/diff_drive_service.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"inputs": [
3+
{
4+
"id": 0,
5+
"name": "Control Twist",
6+
"type": "double[6]"
7+
}
8+
],
9+
"outputs": [
10+
{
11+
"id": 0,
12+
"name": "Actual Twist",
13+
"type": "double[6]"
14+
},
15+
{
16+
"id": 1,
17+
"name": "Left ESC Temperature",
18+
"type": "float"
19+
},
20+
{
21+
"id": 2,
22+
"name": "Left ESC Current",
23+
"type": "float"
24+
},
25+
{
26+
"id": 3,
27+
"name": "Right ESC Temperature",
28+
"type": "float"
29+
},
30+
{
31+
"id": 4,
32+
"name": "Right ESC Current",
33+
"type": "float"
34+
},
35+
{
36+
"id": 5,
37+
"name": "Wheel Ticks",
38+
"type": "uint32_t[2]"
39+
}
40+
],
41+
"registers": [
42+
{
43+
"id": 0,
44+
"name": "Wheel Ticks Per Meter",
45+
"type": "double"
46+
},
47+
{
48+
"id": 1,
49+
"name": "Wheel Distance",
50+
"type": "double"
51+
}
52+
],
53+
"type": "DiffDriveService",
54+
"version": 1
55+
}

0 commit comments

Comments
 (0)