Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/sdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ void sensor_init( void )
#ifdef MODULE_MAX6642
MAX6642_init();
#endif
#ifdef MODULE_MAX11609
MAX11609_init();
#endif
#if defined(MODULE_INA220_CURRENT) || defined(MODULE_INA220_VOLTAGE)
ina220_init();
#endif
Expand Down
5 changes: 5 additions & 0 deletions modules/sensors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ if (";${TARGET_MODULES};" MATCHES ";INA3221_CURRENT;")
set(MODULES_FLAGS "${MODULES_FLAGS} -DMODULE_INA3221_CURRENT")
endif()

if (";${TARGET_MODULES};" MATCHES ";MAX116XX;")
set(PROJ_SRCS ${PROJ_SRCS} ${SENSOR_PATH}/max11609.c)
set(MODULES_FLAGS "${MODULES_FLAGS} -DMODULE_MAX11609")
endif()

set(PROJ_SRCS ${PROJ_SRCS} ${SENSOR_PATH} PARENT_SCOPE)
set(PROJ_HDRS ${PROJ_HDRS} ${SENSOR_PATH} PARENT_SCOPE)
set(MODULES_FLAGS "${MODULES_FLAGS}" PARENT_SCOPE)
65 changes: 65 additions & 0 deletions modules/sensors/max11609.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* FreeRTOS Includes */
#include "FreeRTOS.h"
#include "task.h"
#include "port.h"

/* Project Includes */
#include "sdr.h"
#include "task_priorities.h"
#include "i2c.h"
#include "i2c_mapping.h"
#include "max11609.h"
#include "utils.h"
#include "uart_debug.h"
#include "max116xx.h"

TaskHandle_t vTask11609_Handle;

void vTaskMAX11609( void* Parameters )
{
max116xx_cfg max11609_cfg = {
.ref_sel = MAX116XX_REF_INT_ON_OUT,
.clk_sel = MAX116XX_CLK_INT,
.pol_sel = MAX116XX_UNIPOLAR,
.scan_mode = MAX116XX_SCAN_OFF_SINGLE_CONV,
.diff_mode = MAX116XX_SINGLE_ENDED,
.channel_sel = 0
};
const TickType_t update_period = pdMS_TO_TICKS(MAX11609_UPDATE_PERIOD);

sensor_t * voltage_sensor;
int16_t data_voltage[1];
mmc_err err;

for ( ;; ) {
/* Iterate through the SDR Table to find all the MAX11609 entries */
for ( voltage_sensor = sdr_head; voltage_sensor != NULL; voltage_sensor = voltage_sensor->next) {
if ( voltage_sensor->task_handle == NULL ) {
continue;
}
/* Check if this task should update the selected SDR */
if ( *(voltage_sensor->task_handle) != xTaskGetCurrentTaskHandle() ) {
continue;
}

max11609_cfg.channel_sel = ((SDR_type_01h_t*)voltage_sensor->sdr)->OEM;
err = max116xx_set_config(voltage_sensor->chipid, &max11609_cfg);
if(err != MMC_OK) continue;

err = max116xx_read_uni(voltage_sensor->chipid, data_voltage, 1);
if (err == MMC_OK)
{
voltage_sensor->readout_value = (uint16_t)(data_voltage[0] >> 2);
}

sensor_state_check(voltage_sensor);
check_sensor_event(voltage_sensor);
}
vTaskDelay(update_period);
}
}

void MAX11609_init()
{
xTaskCreate(vTaskMAX11609, "MAX11609", 256, (void *) NULL, tskMAX11609SENSOR_PRIORITY, &vTask11609_Handle);
}
33 changes: 33 additions & 0 deletions modules/sensors/max11609.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef MAX11609_
#define MAX11609_

/**
* @brief Rate at which the MAX11609 sensors are read (in ms)
*/
#define MAX11609_UPDATE_PERIOD 200

#define MAX11609_CHANNEL_0 0
#define MAX11609_CHANNEL_1 1
#define MAX11609_CHANNEL_2 2
#define MAX11609_CHANNEL_3 3
#define MAX11609_CHANNEL_4 4
#define MAX11609_CHANNEL_5 5
#define MAX11609_CHANNEL_6 6
#define MAX11609_CHANNEL_7 7

extern TaskHandle_t vTask11609_Handle;

extern const SDR_type_01h_t SDR_MAX11609_12V_HP;

void MAX11609_init( void );

/**
* @brief Monitoring task for MAX11609 sensor
*
* 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
*
* @param Parameters Pointer to parameter list passed to task upon initialization (not used here)
*/
void vTaskMAX11609( void* Parameters );

#endif
4 changes: 4 additions & 0 deletions modules/sensors/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@
#include "max6642.h"
#endif

#ifdef MODULE_MAX11609
#include "max11609.h"
#endif

#endif
1 change: 1 addition & 0 deletions modules/task_priorities.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define tskMAX6642SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
#define tskINA220SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
#define tskINA3221SENSOR_PRIORITY (tskIDLE_PRIORITY+3)
#define tskMAX11609SENSOR_PRIORITY (tskIDLE_PRIORITY+3)

#define tskIPMI_HANDLERS_PRIORITY (tskIDLE_PRIORITY+4)
#define tskIPMI_PRIORITY (tskIDLE_PRIORITY+4)
Expand Down
Loading