docs: Add Doxygen comments to library files
Added Doxygen-style comments to all C source and header files in the and directories. This improves code documentation and enables VSCode tooltip help. Additionally, short inline comments were added to all global variables for better clarity.
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/**
|
||||
* @file modbus_server.c
|
||||
* @brief Modbus RTU server implementation for the irrigation system slave node.
|
||||
*
|
||||
* This file implements the Modbus server logic, including register callbacks,
|
||||
* watchdog handling, and dynamic reconfiguration. It interfaces with other
|
||||
* libraries like valve control, ADC sensors, and firmware updates.
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/device.h>
|
||||
@@ -25,12 +34,27 @@ static struct modbus_iface_param server_param = {
|
||||
static uint16_t watchdog_timeout_s = 0;
|
||||
static struct k_timer watchdog_timer;
|
||||
|
||||
/**
|
||||
* @brief Timer handler for the Modbus watchdog.
|
||||
*
|
||||
* This function is called when the watchdog timer expires, indicating a loss
|
||||
* of communication with the Modbus master. It triggers a fail-safe action,
|
||||
* which is to close the valve.
|
||||
*
|
||||
* @param timer_id Pointer to the timer instance.
|
||||
*/
|
||||
static void watchdog_timer_handler(struct k_timer *timer_id)
|
||||
{
|
||||
LOG_WRN("Modbus watchdog expired! Closing valve as a fail-safe.");
|
||||
valve_close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resets the Modbus watchdog timer.
|
||||
*
|
||||
* This function should be called upon receiving any valid Modbus request
|
||||
* to prevent the watchdog from expiring.
|
||||
*/
|
||||
static inline void reset_watchdog(void)
|
||||
{
|
||||
if (watchdog_timeout_s > 0)
|
||||
@@ -39,6 +63,13 @@ static inline void reset_watchdog(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback for reading Modbus holding registers.
|
||||
*
|
||||
* @param addr Register address.
|
||||
* @param reg Pointer to store the read value.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
static int holding_reg_rd(uint16_t addr, uint16_t *reg)
|
||||
{
|
||||
reset_watchdog();
|
||||
@@ -60,6 +91,13 @@ static int holding_reg_rd(uint16_t addr, uint16_t *reg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback for writing Modbus holding registers.
|
||||
*
|
||||
* @param addr Register address.
|
||||
* @param reg Value to write.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
static int holding_reg_wr(uint16_t addr, uint16_t reg)
|
||||
{
|
||||
reset_watchdog();
|
||||
@@ -112,6 +150,13 @@ static int holding_reg_wr(uint16_t addr, uint16_t reg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback for reading Modbus input registers.
|
||||
*
|
||||
* @param addr Register address.
|
||||
* @param reg Pointer to store the read value.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
static int input_reg_rd(uint16_t addr, uint16_t *reg)
|
||||
{
|
||||
reset_watchdog();
|
||||
@@ -149,7 +194,7 @@ static int input_reg_rd(uint16_t addr, uint16_t *reg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct modbus_user_callbacks mbs_cbs = {
|
||||
static struct modbus_user_callbacks mbs_cbs = { // Modbus server callback functions
|
||||
.holding_reg_rd = holding_reg_rd,
|
||||
.holding_reg_wr = holding_reg_wr,
|
||||
.input_reg_rd = input_reg_rd,
|
||||
|
||||
Reference in New Issue
Block a user