Skip to content

Commit 001e99e

Browse files
Joao Victor Santosjoao-victor-s
authored andcommitted
Add MAX11609 voltage monitoring support to RTM Lamp
This commit adds voltage monitoring capability to the RTM Lamp by introducing the MODULE_MAX11609 module, which integrates with the max116xx driver. A new task, vTaskMAX11609, was created to iterate through the SDR table and measure sensor voltages for entries associated with the MAX11609. The task identifies relevant sensors by comparing their task_handle to its own and updates their readout_value field accordingly.
1 parent 4a1fe86 commit 001e99e

File tree

7 files changed

+556
-0
lines changed

7 files changed

+556
-0
lines changed

modules/sdr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ void sensor_init( void )
106106
#ifdef MODULE_MAX6642
107107
MAX6642_init();
108108
#endif
109+
#ifdef MODULE_MAX11609
110+
MAX11609_init();
111+
#endif
109112
#if defined(MODULE_INA220_CURRENT) || defined(MODULE_INA220_VOLTAGE)
110113
ina220_init();
111114
#endif

modules/sensors/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ if (";${TARGET_MODULES};" MATCHES ";INA3221_CURRENT;")
3838
set(MODULES_FLAGS "${MODULES_FLAGS} -DMODULE_INA3221_CURRENT")
3939
endif()
4040

41+
if (";${TARGET_MODULES};" MATCHES ";MAX116XX;")
42+
set(PROJ_SRCS ${PROJ_SRCS} ${SENSOR_PATH}/max11609.c)
43+
set(MODULES_FLAGS "${MODULES_FLAGS} -DMODULE_MAX11609")
44+
endif()
45+
4146
set(PROJ_SRCS ${PROJ_SRCS} ${SENSOR_PATH} PARENT_SCOPE)
4247
set(PROJ_HDRS ${PROJ_HDRS} ${SENSOR_PATH} PARENT_SCOPE)
4348
set(MODULES_FLAGS "${MODULES_FLAGS}" PARENT_SCOPE)

modules/sensors/max11609.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* FreeRTOS Includes */
2+
#include "FreeRTOS.h"
3+
#include "task.h"
4+
#include "port.h"
5+
6+
/* Project Includes */
7+
#include "sdr.h"
8+
#include "task_priorities.h"
9+
#include "i2c.h"
10+
#include "i2c_mapping.h"
11+
#include "max11609.h"
12+
#include "utils.h"
13+
#include "uart_debug.h"
14+
#include "max116xx.h"
15+
16+
TaskHandle_t vTask11609_Handle;
17+
18+
void vTaskMAX11609( void* Parameters )
19+
{
20+
max116xx_cfg max11609_cfg = {
21+
.ref_sel = MAX116XX_REF_INT_ON_OUT,
22+
.clk_sel = MAX116XX_CLK_INT,
23+
.pol_sel = MAX116XX_UNIPOLAR,
24+
.scan_mode = MAX116XX_SCAN_OFF_SINGLE_CONV,
25+
.diff_mode = MAX116XX_SINGLE_ENDED,
26+
.channel_sel = 0
27+
};
28+
const TickType_t update_period = pdMS_TO_TICKS(MAX11609_UPDATE_PERIOD);
29+
30+
sensor_t * voltage_sensor;
31+
int16_t data_voltage[1];
32+
mmc_err err;
33+
34+
for ( ;; ) {
35+
/* Iterate through the SDR Table to find all the MAX11609 entries */
36+
for ( voltage_sensor = sdr_head; voltage_sensor != NULL; voltage_sensor = voltage_sensor->next) {
37+
if ( voltage_sensor->task_handle == NULL ) {
38+
continue;
39+
}
40+
/* Check if this task should update the selected SDR */
41+
if ( *(voltage_sensor->task_handle) != xTaskGetCurrentTaskHandle() ) {
42+
continue;
43+
}
44+
45+
max11609_cfg.channel_sel = ((SDR_type_01h_t*)voltage_sensor->sdr)->OEM;
46+
err = max116xx_set_config(voltage_sensor->chipid, &max11609_cfg);
47+
if(err != MMC_OK) continue;
48+
49+
err = max116xx_read_uni(voltage_sensor->chipid, data_voltage, 1);
50+
if (err == MMC_OK)
51+
{
52+
voltage_sensor->readout_value = (uint16_t)(data_voltage[0] >> 2);
53+
}
54+
55+
sensor_state_check(voltage_sensor);
56+
check_sensor_event(voltage_sensor);
57+
}
58+
vTaskDelay(update_period);
59+
}
60+
}
61+
62+
void MAX11609_init()
63+
{
64+
xTaskCreate(vTaskMAX11609, "MAX11609", 256, (void *) NULL, tskMAX11609SENSOR_PRIORITY, &vTask11609_Handle);
65+
}

modules/sensors/max11609.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef MAX11609_
2+
#define MAX11609_
3+
4+
/**
5+
* @brief Rate at which the MAX11609 sensors are read (in ms)
6+
*/
7+
#define MAX11609_UPDATE_PERIOD 200
8+
9+
#define MAX11609_CHANNEL_0 0
10+
#define MAX11609_CHANNEL_1 1
11+
#define MAX11609_CHANNEL_2 2
12+
#define MAX11609_CHANNEL_3 3
13+
#define MAX11609_CHANNEL_4 4
14+
#define MAX11609_CHANNEL_5 5
15+
#define MAX11609_CHANNEL_6 6
16+
#define MAX11609_CHANNEL_7 7
17+
18+
extern TaskHandle_t vTask11609_Handle;
19+
20+
extern const SDR_type_01h_t SDR_MAX11609_12V_HP;
21+
22+
void MAX11609_init( void );
23+
24+
/**
25+
* @brief Monitoring task for MAX11609 sensor
26+
*
27+
* This task unblocks after every #MAX11609_UPDATE_PERIOD ms and updates the read from all the MAX11609 sensors listed in this module's SDR table
28+
*
29+
* @param Parameters Pointer to parameter list passed to task upon initialization (not used here)
30+
*/
31+
void vTaskMAX11609( void* Parameters );
32+
33+
#endif

modules/sensors/sensors.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@
5858
#include "max6642.h"
5959
#endif
6060

61+
#ifdef MODULE_MAX11609
62+
#include "max11609.h"
63+
#endif
64+
6165
#endif

modules/task_priorities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define tskMAX6642SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
4040
#define tskINA220SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
4141
#define tskINA3221SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
42+
#define tskMAX11609SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
4243

4344
#define tskIPMI_HANDLERS_PRIORITY (tskIDLE_PRIORITY+4)
4445
#define tskIPMI_PRIORITY (tskIDLE_PRIORITY+4)

0 commit comments

Comments
 (0)