diff --git a/.vscode/settings.json b/.vscode/settings.json index 1846aa58..a0e17d56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,7 @@ "editor.trimAutoWhitespace": true, "editor.autoClosingQuotes": "always", "editor.autoClosingBrackets": "always", - "editor.wordBasedSuggestions": true, + "editor.wordBasedSuggestions": "matchingDocuments", "editor.insertSpaces": false, "editor.autoIndent": "advanced", "editor.detectIndentation": true, @@ -28,7 +28,6 @@ "editor.columnSelection": false, "editor.colorDecorators": true, "editor.cursorBlinking": "blink", - "editor.lightbulb.enabled": true, "editor.lineNumbers": "on", "editor.suggest.showFunctions": true, "diffEditor.codeLens": true, diff --git a/projects/demo_avr_cpp/gpio.cpp b/projects/demo_avr_cpp/gpio.cpp index af6af35f..848c220d 100644 --- a/projects/demo_avr_cpp/gpio.cpp +++ b/projects/demo_avr_cpp/gpio.cpp @@ -16,18 +16,31 @@ extern "C" #include "gpio.h" -/* Outside declaration of the member function of class onBoardLed */ +/* Outside declaration of the member function of class onBoardLed: Utilized by the specific register allocation for the onboard LED */ onBoardLed::onBoardLed() { gpio_pin_alloc(&led13, PORTB, 5); } +/** + * @brief the setting up of the onboard-LED + * + * This function configures the specific GPIO pin for the onboard-LED as an output + * This function also sets the LED state to low (off) + */ + void onBoardLed::setup() { gpio_pin_mode(&led13, out); gpio_pin_clear(&led13); } +/** + * @brief The toggling of the onboard LED + * + * This function toggles the state of the onboard LED on and off + */ + void onBoardLed::toggle() { gpio_pin_toggle(&led13); diff --git a/projects/demo_avr_cpp/gpio.h b/projects/demo_avr_cpp/gpio.h index 5f968c52..40e9963a 100644 --- a/projects/demo_avr_cpp/gpio.h +++ b/projects/demo_avr_cpp/gpio.h @@ -10,6 +10,13 @@ #pragma once +/** + * @brief Class representing an on-board LED controlled via GPIO. + * + * This class provides methods to initialize the LED, set it up as an output, + * and toggle its state. + */ + class onBoardLed { private: diff --git a/projects/demo_avr_cpp/project.cpp b/projects/demo_avr_cpp/project.cpp index 93294c06..05edd261 100644 --- a/projects/demo_avr_cpp/project.cpp +++ b/projects/demo_avr_cpp/project.cpp @@ -21,15 +21,15 @@ extern "C" #include } -#include "gpio.h" +#include "gpio.h" // This has custom GPIO header functions -class onBoardLed led; +class onBoardLed led; /* Use EXPORT_C macro for calling cpp function in c file */ EXPORT_C(void plug()) { - bootstrap(); + bootstrap(); // calls the system initial bootstrap driver_setup_all(); /* call the constructor and setup member of led object */ @@ -47,13 +47,13 @@ void delay(unsigned long d) { unsigned long c; for(c = 0; c < d; c++) - asm volatile("nop"); + asm volatile("nop"); // provides the assembly instructions to create a general delay } static unsigned char i = 0; -EXPORT_C(void play()) +EXPORT_C(void play()) // the calling of the continues function check { - wdog_guard(WDT_64MS, true, NULL); + wdog_guard(WDT_64MS, true, NULL); // safety feature if the core hangs or creates interruptions /* call the toggle member of led object */ led.toggle(); diff --git a/src/driver/onboardled/onboardled.c b/src/driver/onboardled/onboardled.c index a0966ad7..774d31aa 100644 --- a/src/driver/onboardled/onboardled.c +++ b/src/driver/onboardled/onboardled.c @@ -23,6 +23,15 @@ static gpio_port_t *obledPort; static swdev_t *obled_sp; static lock_t obledlock; +/** + * @brief Toggle the state of the onboard LED. + * + * This function toggles the state of the onboard LED by each GPIO pin + * It also works accordinlg with locks to protect the state + * + * @return status_t: Status of the operation + */ + status_t onboardled_toggle(void) { status_t ret = success; @@ -39,6 +48,14 @@ status_t onboardled_toggle(void) return ret; } +/** + * @brief Turning on the onboard LED + * + * This function turns on the onboard LED by setting each of the GPIO pin to high + * + * @return status_t: Status of the operation + */ + status_t onboardled_on(void) { status_t ret = success; @@ -55,6 +72,14 @@ status_t onboardled_on(void) return ret; } +/** + * @brief Turning off the onboard LED + * + * This function turns on the onboard LED by setting each of the GPIO pin to low (clearing) + * + * @return status_t: Status of the operation + */ + status_t onboardled_off(void) { status_t ret = success; @@ -71,6 +96,14 @@ status_t onboardled_off(void) return ret; } +/** + * @brief Initializes the onboard LED driver + * + * This function initializes the onboard LED driver by allocating GPIO ports for the LED. + * + * @return status_t: Status of the initialization + */ + static status_t onboardled_setup(void) { vret_t vres; @@ -107,6 +140,15 @@ static status_t onboardled_setup(void) return ret; } +/** + * @brief Cleanup and exit the onboard LED driver. + * + * This function frees allocated GPIO ports and resources associated with the + * onboard LED driver. + * + * @return status_t: Status of the cleanup and exit + */ + static status_t onboardled_exit(void) { status_t ret = success; @@ -125,4 +167,4 @@ static status_t onboardled_exit(void) return ret; } -INCLUDE_DRIVER(OBrdLED, onboardled_setup, onboardled_exit, 0, 255, 255); +INCLUDE_DRIVER(OBrdLED, onboardled_setup, onboardled_exit, 0, 255, 255); \ No newline at end of file diff --git a/src/platform/mega_avr/README.md b/src/platform/mega_avr/README.md new file mode 100644 index 00000000..ed63def6 --- /dev/null +++ b/src/platform/mega_avr/README.md @@ -0,0 +1,27 @@ +# MegaAVR Family +This folder contains platform specific programs for MegaAVR family of controllers. + +## Some differences between the two AVR microcontrollers: + +| Controller | CPU | Memory (SRAM) | Flash | EEPROM | GPIO | +|---|---|---|---|---|---| +| AtMega328P | AVR5-8b | 2KB | 32KB | 1KB | 23 | +| AtMega2560 | AVR6-8b | 8KB | 256KB | 4KB | 86 | + +## Directories Overview +| Folder | Description | +| --------------------- | ------------------------------------------------------------- | +| [common](common) | Holds common code shared between platforms.| +| [atmega328p](atmega328p) | Houses platform-specific programs for Atmega328p. Contains: Architecture Specifics, Platform Includes, Platform Clock, and Resources| +| [atmega2560](atmega2560) | Houses platform-specific programs for Atmega2560. Contains: Architecture Specifics, Platform Includes, Platform Clock, and Resources| + +### [common](common) + +Contains code shared between Atmega328p and Atmega2560. + +| Subfolder | Description | +| --------------- | ------------------------------------------------------- | +| [arch](common/arch) | CPU architecture related src| +| [hal](common/hal) | Hardware abstraction layer src| +| [include](common/include) | Includes for platform header| +| [platform](common/platform) | Platform specific src| diff --git a/src/platform/mega_avr/common/hal/adc/adc.c b/src/platform/mega_avr/common/hal/adc/adc.c index f6763e41..e710e907 100644 --- a/src/platform/mega_avr/common/hal/adc/adc.c +++ b/src/platform/mega_avr/common/hal/adc/adc.c @@ -21,16 +21,42 @@ #include #include "adc_private.h" +/** + * _adc_enable - Enables ADC + * + * @brief Enables the ADC peripheral + * + * @param[in] port: Pointer to the ADC port structure + */ + static inline void _adc_enable(adc_port_t *port) { MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADEN); } +/** + * _adc_disable - Disables ADC + * + * @brief Disables the ADC peripheral + * + * @param[in] port: Pointer to the ADC port structure + */ + static inline void _adc_disable(adc_port_t *port) { MMIO8(port->baddr + ADCSRA_OFFSET) &= ~(1 << ADEN); } +/** + * _adc_set_prescaler - Sets ADC prescaler + * + * @brief Sets the ADC prescaler value based on the clock frequency specific in the port + * + * @param[in] port: Pointer to the ADC port structure + * + * @return status: Status of prescaler setup operation + */ + static inline status_t _adc_set_prescaler(adc_port_t *port) { uint8_t pscale_value = 0; @@ -65,11 +91,30 @@ static inline status_t _adc_set_prescaler(adc_port_t *port) return ret; } +/** + * _adc_start_conv - Starts ADC conversion + * + * @brief Initiates ADC conversion process + * + * @param[in] port: Pointer to the ADC port structure + */ + static inline void _adc_start_conv(adc_port_t *port) { MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADSC); } +/** + * _adc_config_trigger - Configures ADC trigger mode + * + * @brief Configures the ADC trigger mode for conversion + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] trigger: ADC trigger mode + * + * @return status: Status of trigger configuration operation + */ + static inline status_t _adc_config_trigger(adc_port_t *port, adc_trig_t trigger) { status_t ret = success; @@ -81,6 +126,17 @@ static inline status_t _adc_config_trigger(adc_port_t *port, adc_trig_t trigger) return ret; } +/** + * _adc_config_resolution - Configures ADC resolution + * + * @brief Configures the ADC resolution (8-bit | 10-bit) + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] resolution: ADC resolution wanted + * + * @return status: Status of resolution configuration operation + */ + static inline status_t _adc_config_resolution(adc_port_t *port, uint8_t resolution) { status_t ret = success; @@ -91,6 +147,17 @@ static inline status_t _adc_config_resolution(adc_port_t *port, uint8_t resoluti return ret; } +/** + * _adc_config_vref - Configures ADC voltage reference + * + * @brief Configures the ADC voltage reference source based on specific reference source + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] vref: ADC voltage reference source + * + * @return status: Status of voltage reference configuration operation + */ + static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref) { status_t ret = success; @@ -114,6 +181,16 @@ static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref) return ret; } +/** + * adc_setup - Setups ADC + * + * @brief Initializes and configures the ADC peripheral + * + * @param[out] port: Pointer to the ADC port structure + * + * @return status: Status of setup operation + */ + status_t adc_setup(adc_port_t *port) { status_t ret = success; @@ -129,6 +206,16 @@ status_t adc_setup(adc_port_t *port) return ret; } +/** + * adc_shutdown - Shutdown ADC + * + * @brief Disables and shuts down the ADC peripheral + * + * @param[out] port: Pointer to the ADC port structure + * + * @return status: Status of shutdown operation + */ + status_t adc_shutdown(adc_port_t *port) { status_t ret = success; @@ -139,6 +226,16 @@ status_t adc_shutdown(adc_port_t *port) return ret; } +/** + * adc_busy - Checks ADC busy state + * + * @brief Checks if the ADC is currently busy + * + * @param[in] port: Pointer to the ADC port structure + * + * @return state: State of ADC busy status + */ + bool adc_busy(adc_port_t *port) { bool ret; @@ -147,6 +244,16 @@ bool adc_busy(adc_port_t *port) return ret; } +/** + * adc_int_en - Enables ADC interrupts + * + * @brief Enables ADC interrupts for the specified ADC port + * + * @param[in] port: Pointer to the ADC port structure + * + * @return status: Status of interrupt enable operation + */ + status_t adc_int_en(adc_port_t *port) { STATUS_CHECK_POINTER(port); @@ -154,6 +261,16 @@ status_t adc_int_en(adc_port_t *port) return success; } +/** + * adc_int_dis - Disables ADC interrupts + * + * @brief Disables ADC interrupts for the specified ADC port + * + * @param[in] port: Pointer to the ADC port structure + * + * @return status: Status of interrupt disable operation + */ + status_t adc_int_dis(adc_port_t *port) { STATUS_CHECK_POINTER(port); @@ -161,6 +278,20 @@ status_t adc_int_dis(adc_port_t *port) return success; } +/** + * adc_config_pin - Configures ADC pin parameters + * + * @brief Configures ADC pin settings for conversion + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] pin: ADC pin to configure + * @param[in] trigger: ADC trigger mode + * @param[in] resolution: ADC resolution (8 or 10 bits) + * @param[in] vref: ADC voltage reference source + * + * @return status: Status of pin configuration operation + */ + status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8_t resolution, adc_ref_t vref) { status_t ret = success; @@ -175,6 +306,17 @@ status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8 return ret; } +/** + * adc_read - Reads ADC conversion result + * + * @brief Reads the ADC conversion result from the specified ADC port + * + * @param[in] port: Pointer to the ADC port structure + * @param[out] adc_val: Pointer to store the ADC conversion value + * + * @return status: Status of read operation + */ + status_t adc_read(adc_port_t *port, uint16_t *adc_val) { status_t ret = success; @@ -195,6 +337,17 @@ status_t adc_read(adc_port_t *port, uint16_t *adc_val) return ret; } +/** + * adc_temperature_convert - Converts ADC raw value to temperature + * + * @brief Converts the raw ADC value to temperature in Celsius + * + * @param[in] raw_adc: Raw ADC value + * @param[out] temperature: Pointer to store the temperature value + * + * @return status: Status of temperature conversion operation + */ + status_t adc_temperature_convert(uint16_t raw_adc, float *temperature) { status_t ret = success; diff --git a/src/platform/mega_avr/common/hal/gpio/gpio.c b/src/platform/mega_avr/common/hal/gpio/gpio.c index 1d543770..e87f0dae 100644 --- a/src/platform/mega_avr/common/hal/gpio/gpio.c +++ b/src/platform/mega_avr/common/hal/gpio/gpio.c @@ -22,6 +22,18 @@ #include #include "gpio_private.h" +/** + * gpio_pin_alloc - Allocates the needed GPIO pin + * + * @brief Allocates the GPIO pin and looks for availability + * + * @param[out] port: Pointer to the GPIO port structure + * @param[in] portID: Port ID of the GPIO pin + * @param[in] pinID: Pin ID of the GPIO pin + * + * @return status: Status of allocation operation + */ + status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) { vret_t vres; @@ -59,6 +71,17 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) return success; } +/** + * gpio_pin_mode - Sets GPIO pin mode + * + * @brief Sets the mode of a GPIO pin (ex: Input, Output) + * + * @param[in] port: Pointer to the GPIO port structure + * @param[in] mode: Specified GPIO setting + * + * @return status: Status of mode setting operation + */ + status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; @@ -82,6 +105,16 @@ status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) return success; } +/** + * gpio_pin_free - Frees specific GPIO pin + * + * @brief Frees a previously allocated GPIO pin + * + * @param[out] port: Pointer to the GPIO port structure + * + * @return status: Status of freeing operation + */ + status_t gpio_pin_free(gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -95,6 +128,16 @@ status_t gpio_pin_free(gpio_port_t *port) return success; } +/** + * gpio_pin_set - Sets a GPIO pin high + * + * @brief Sets a GPIO pin to high logic level by setting appropriate bit in the control register + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return status: Status of setting operation + */ + status_t gpio_pin_set(const gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -102,6 +145,16 @@ status_t gpio_pin_set(const gpio_port_t *port) return success; } +/** + * gpio_pin_clear - Sets a GPIO pin low + * + * @brief Sets a GPIO pin to low logic level by setting appropriate bit in the control register + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return status: Status of clearing operation + */ + status_t gpio_pin_clear(const gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -109,6 +162,16 @@ status_t gpio_pin_clear(const gpio_port_t *port) return success; } +/** + * gpio_pin_toggle - Toggles a GPIO pin state + * + * @brief Toggles the state of a GPIO pin (high to low) + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return status: Status of toggling operation + */ + status_t gpio_pin_toggle(const gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -116,12 +179,33 @@ status_t gpio_pin_toggle(const gpio_port_t *port) return success; } +/** + * gpio_pin_read - Reads a GPIO pin state + * + * @brief Reads the state of a GPIO pin (high or low) + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return state: State of the GPIO pin depending on high, low for true, false + */ + bool gpio_pin_read(const gpio_port_t *port) { assert(port); return (MMIO8(port->pbaddr + PIN_OFFSET) & (1 << port->pin)) ? true : false; } +/** + * gpio_port_alloc - Allocates a GPIO port + * + * @brief Allocates a GPIO port and checks for availability different from needing pinID + * + * @param[out] port: Pointer to the GPIO port structure + * @param[in] portID: Port ID of the GPIO port + * + * @return status: Status of allocation operation + */ + status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) { vret_t vres; @@ -157,6 +241,17 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) return success; } +/** + * gpio_port_mode - Sets GPIO port mode + * + * @brief Sets the mode of a GPIO port (ex: input, output, pull_up) + * + * @param[in] port: Pointer to the GPIO port structure + * @param[in] mode: GPIO mode to set + * + * @return status: Status of mode setting operation + */ + status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; @@ -180,6 +275,16 @@ status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) return success; } +/** + * gpio_port_free - Frees a GPIO port + * + * @brief Frees a previously allocated GPIO port different from freeing pin + * + * @param[out] port: Pointer to the GPIO port structure + * + * @return status: Status of freeing operation + */ + status_t gpio_port_free(gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -193,6 +298,17 @@ status_t gpio_port_free(gpio_port_t *port) return success; } +/** + * gpio_port_write - Writes to a GPIO port + * + * @brief Writes data to a GPIO port + * + * @param[in] port: Pointer to the GPIO port structure + * @param[in] val: Data to write to the port + * + * @return status: Status of writing operation + */ + status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) { STATUS_CHECK_POINTER(port); @@ -201,6 +317,17 @@ status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) return success; } +/** + * gpio_port_read - Reads from a GPIO port + * + * @brief Reads data from a GPIO port + * + * @param[in] port: Pointer to the GPIO port structure + * @param[out] val: Variable to store the read data + * + * @return status: Status of reading operation + */ + status_t gpio_port_read(const gpio_port_t *port, gpio_parallel_t *val) { STATUS_CHECK_POINTER(port); diff --git a/src/platform/mega_avr/common/hal/pwm/pwm.c b/src/platform/mega_avr/common/hal/pwm/pwm.c index 11f18c66..17b3ba5c 100644 --- a/src/platform/mega_avr/common/hal/pwm/pwm.c +++ b/src/platform/mega_avr/common/hal/pwm/pwm.c @@ -19,6 +19,15 @@ #include #include +/** + * pwm_to_timer - Convert PWM port to Timer port + * + * @brief Converts PWM port structure to Timer port structure + * + * @param[in] p: Pointer to the PWM port structure + * @param[out] t: Pointer to the Timer port structure + */ + static void pwm_to_timer(const pwm_port_t *p, timer_port_t *t) { t->port_id = p->port_id; @@ -29,6 +38,17 @@ static void pwm_to_timer(const pwm_port_t *p, timer_port_t *t) t->tmr_handler = p->pwm_handler; } +/** + * pwm_get_properties - Get PWM properties + * + * @brief Retrieves PWM properties and maps them to the PWM port structure. + * + * @param[out] port: Pointer to the PWM port structure + * @param[in] dev: Software device ID + * + * @return status: Status of PWM properties retrieval operation + */ + status_t pwm_get_properties(pwm_port_t *port, sw_devid_t dev) { vret_t vres; @@ -62,6 +82,17 @@ status_t pwm_get_properties(pwm_port_t *port, sw_devid_t dev) return success; } +/** + * pwm_setup - Configure PWM settings + * + * @brief Configures PWM settings using the associated Timer port + * + * @param[in] port: Pointer to the PWM port structure + * @param[in] mode: PWM mode (e.g., PWM, timer) + * + * @return status: Status of PWM setup operation + */ + status_t pwm_setup(const pwm_port_t *port, unsigned int mode) { status_t ret; @@ -81,6 +112,18 @@ status_t pwm_setup(const pwm_port_t *port, unsigned int mode) return ret; } +/** + * pwm_set - Set PWM value + * + * @brief Sets the PWM value using the associated Timer port + * + * @param[in] port: Pointer to the PWM port structure + * @param[in] value: PWM value to set + * @param[in] invert: Invert PWM signal if true + * + * @return status: Status of PWM set operation + */ + status_t pwm_set(const pwm_port_t *port, size_t value, bool invert) { status_t ret; diff --git a/src/platform/mega_avr/common/hal/spi/spi.c b/src/platform/mega_avr/common/hal/spi/spi.c index 65328d08..6209d361 100644 --- a/src/platform/mega_avr/common/hal/spi/spi.c +++ b/src/platform/mega_avr/common/hal/spi/spi.c @@ -20,6 +20,18 @@ #include #include "spi_private.h" +/** + * spi_master_setup - Setups SPI master mode + * + * @brief Initializes SPI in master mode with specified settings + * + * @param[out] port: Pointer to the SPI port structure + * @param[in] df_format: Data frame format + * @param[in] cpol: Clock polarity + * @param[in] cpha: Clock phase + * + * @return status: Status of master setup operation + */ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol_t cpol, clk_ph_t cpha) { @@ -64,6 +76,19 @@ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_po return ret; } +/** + * spi_slave_setup - Setups SPI slave mode + * + * @brief Initializes SPI in slave mode with specified settings + * + * @param[out] port: Pointer to the SPI port structure + * @param[in] df_format: Data frame format + * @param[in] cpol: Clock polarity + * @param[in] cpha: Clock phase + * + * @return status: Status of slave setup operation + */ + status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol_t cpol, clk_ph_t cpha) { status_t ret = success; @@ -107,18 +132,48 @@ status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol return ret; } +/** + * spi_wcol_error - Checks SPI write collision error + * + * @brief Checks if a write collision error occurred during SPI communication + * + * @param[in] port: Pointer to the SPI port structure + * + * @return state: State of the write collision error (true = error, false = no error) + */ + bool spi_wcol_error(spi_port_t *port) { assert(port); return (MMIO8(port->baddr + SPSR_OFFSET) & (1 << WCOL)) ? true : false; } +/** + * spi_trx_done - Checks SPI transaction completion + * + * @brief Checks if an SPI transaction is completed + * + * @param[in] port: Pointer to the SPI port structure + * + * @return state: State of the transaction completion (true = completed, false = not completed) + */ + bool spi_trx_done(spi_port_t *port) { assert(port); return (MMIO8(port->baddr + SPSR_OFFSET) & (1 << SPIF)) ? true : false; } +/** + * spi_int_en - Enables SPI interrupts + * + * @brief Enables SPI interrupts for the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * + * @return status: Status of interrupt enable operation + */ + status_t spi_int_en(spi_port_t *port) { STATUS_CHECK_POINTER(port); @@ -126,6 +181,16 @@ status_t spi_int_en(spi_port_t *port) return success; } +/** + * spi_int_dis - Disables SPI interrupts + * + * @brief Disables SPI interrupts for the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * + * @return status: Status of interrupt disable operation + */ + status_t spi_int_dis(spi_port_t * port) { STATUS_CHECK_POINTER(port); @@ -133,6 +198,17 @@ status_t spi_int_dis(spi_port_t * port) return success; } +/** + * spi_tx - Transmits data via SPI + * + * @brief Transmits data via SPI using the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * @param[in] data: Data to be transmitted + * + * @return status: Status of data transmission operation + */ + status_t spi_tx(spi_port_t *port, char data) { STATUS_CHECK_POINTER(port); @@ -140,6 +216,17 @@ status_t spi_tx(spi_port_t *port, char data) return success; } +/** + * spi_rx - Receives data via SPI + * + * @brief Receives data via SPI using the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * @param[out] data: Pointer to store the received data + * + * @return status: Status of data reception operation + */ + status_t spi_rx(spi_port_t *port, char *data) { STATUS_CHECK_POINTER(port); diff --git a/src/platform/mega_avr/common/hal/timer/timer.c b/src/platform/mega_avr/common/hal/timer/timer.c index 801e49fd..adedfbb7 100644 --- a/src/platform/mega_avr/common/hal/timer/timer.c +++ b/src/platform/mega_avr/common/hal/timer/timer.c @@ -23,6 +23,18 @@ #include "timer8.h" #include "timer16.h" +/** + * timer_setup - Configure timer settings + * + * @brief Configures timer settings including mode and prescaler + * + * @param[in] port: Pointer to the timer port structure + * @param[in] mode: Timer mode (e.g., PWM, timer) + * @param[in] ps: Timer prescaler value + * + * @return status: Status of timer setup operation + */ + status_t timer_setup(const timer_port_t *port, unsigned int mode, unsigned int ps) { status_t ret; @@ -55,6 +67,16 @@ status_t timer_setup(const timer_port_t *port, unsigned int mode, unsigned int p return ret; } +/** + * timer_shutdown - Shutdown timer + * + * @brief Disables timer and associated interrupts + * + * @param[in] port: Pointer to the timer port structure + * + * @return status: Status of timer shutdown operation + */ + status_t timer_shutdown(const timer_port_t *port) { status_t ret = success; @@ -78,6 +100,17 @@ status_t timer_shutdown(const timer_port_t *port) return ret; } +/** + * timer_read - Read timer value + * + * @brief Reads the current value of the timer. + * + * @param[in] port: Pointer to the timer port structure + * @param[out] value: Pointer to store the timer value + * + * @return status: Status of timer read operation + */ + status_t timer_read(const timer_port_t *port, size_t *value) { unsigned id; @@ -90,6 +123,17 @@ status_t timer_read(const timer_port_t *port, size_t *value) return success; } +/** + * timer_pwm_set - Set PWM value + * + * @brief Sets the PWM value and configuration + * + * @param[in] port: Pointer to the timer port structure + * @param[in] invert: Invert PWM signal if true + * @param[in] value: PWM value to set + * + * @return status: Status of PWM set operation + */ status_t timer_pwm_set(const timer_port_t *port, bool invert, size_t value) { @@ -109,4 +153,3 @@ status_t timer_pwm_set(const timer_port_t *port, bool invert, size_t value) } return ret; } - diff --git a/src/platform/mega_avr/common/hal/uart/uart.c b/src/platform/mega_avr/common/hal/uart/uart.c index 0243875f..3db3afc9 100644 --- a/src/platform/mega_avr/common/hal/uart/uart.c +++ b/src/platform/mega_avr/common/hal/uart/uart.c @@ -24,6 +24,19 @@ #include #include "uart_private.h" +/** + * uart_setup - Configure UART port settings + * + * @brief Configures UART port settings including direction, parity, baud rate, + * interrupt handling, and frame configuration. + * + * @param[in] port: Pointer to the UART port structure + * @param[in] d: Direction of UART communication (trx, rx, tx) + * @param[in] p: Parity setting for UART communication + * + * @return status: Status of UART setup operation + */ + status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) { status_t ret = success; @@ -91,6 +104,16 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) return ret; } +/** + * uart_shutdown - Shutdown UART port + * + * @brief Disables UART port and associated interrupts + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART shutdown operation + */ + status_t uart_shutdown(uart_port_t *port) { status_t ret = success; @@ -109,12 +132,30 @@ status_t uart_shutdown(uart_port_t *port) return ret; } +/** + * uart_buffer_available - Check if UART buffer is free for transmission + * + * @brief Checks if UART buffer is available for data transmission. + * + * @param[in] port: Pointer to the UART port structure + * + * @return bool: True if UART buffer is available, false otherwise + */ + bool uart_buffer_available(const uart_port_t *port) { assert(port); return (bool)((MMIO8(port->baddr + UCSRA_OFFSET) >> UDRE) & 0x01); } +/** + * uart_tx_wait_till_done - Wait until UART transmission is done + * + * @brief Waits until UART transmission is complete + * + * @param[in] port: Pointer to the UART port structure + */ + void uart_tx_wait_till_done(const uart_port_t *port) { assert(port); @@ -123,12 +164,32 @@ void uart_tx_wait_till_done(const uart_port_t *port) MMIO8(port->baddr + UCSRA_OFFSET) |= (1 << TXC); } +/** + * uart_rx_done - Check if UART reception is complete + * + * @brief Checks if UART reception is complete. + * + * @param[in] port: Pointer to the UART port structure + * + * @return bool: True if UART reception is complete, false otherwise + */ + bool uart_rx_done(const uart_port_t *port) { assert(port); return (bool)((MMIO8(port->baddr + UCSRA_OFFSET) >> RXC) & 0x01); } +/** + * uart_frame_error - Check if UART frame error occurred + * + * @brief Checks if UART frame error occurred + * + * @param[in] port: Pointer to the UART port structure + * + * @return bool: True if UART frame error occurred, false otherwise + */ + bool uart_frame_error(const uart_port_t *port) { bool ret = false; @@ -138,6 +199,17 @@ bool uart_frame_error(const uart_port_t *port) return ret; } +/** + * uart_tx - Transmit data over UART + * + * @brief Function transmits the data over on UART + * + * @param[in] port: Pointer to the UART port structure + * @param[in] data: Data to be transmitted + * + * @return status: Status of UART transmission operation + */ + status_t uart_tx(const uart_port_t *port, const char data) { STATUS_CHECK_POINTER(port); @@ -147,6 +219,17 @@ status_t uart_tx(const uart_port_t *port, const char data) return success; } +/** + * uart_rx - Receive data over UART + * + * @brief Receives data over UART. + * + * @param[in] port: Pointer to the UART port structure + * @param[out] data: Pointer to store received data + * + * @return status: Status of UART reception operation + */ + status_t uart_rx(const uart_port_t *port, char *data) { STATUS_CHECK_POINTER(port); @@ -156,6 +239,16 @@ status_t uart_rx(const uart_port_t *port, char *data) return success; } +/** + * uart_tx_int_en - Enable UART transmission interrupt + * + * @brief Enables UART transmission interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART transmission interrupt enable operation + */ + status_t uart_tx_int_en(const uart_port_t *port) { STATUS_CHECK_POINTER(port); @@ -163,6 +256,16 @@ status_t uart_tx_int_en(const uart_port_t *port) return success; } +/** + * uart_tx_int_dis - Disable UART transmission interrupt + * + * @brief Disables UART transmission interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART transmission interrupt disable operation + */ + status_t uart_tx_int_dis(const uart_port_t *port) { STATUS_CHECK_POINTER(port); @@ -170,6 +273,16 @@ status_t uart_tx_int_dis(const uart_port_t *port) return success; } +/** + * uart_rx_int_en - Enable UART reception interrupt + * + * @brief Enables UART reception interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART reception interrupt enable operation + */ + status_t uart_rx_int_en(const uart_port_t *port) { STATUS_CHECK_POINTER(port); @@ -177,6 +290,16 @@ status_t uart_rx_int_en(const uart_port_t *port) return success; } +/** + * uart_rx_int_dis - Disable UART reception interrupt + * + * @brief Disables UART reception interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART reception interrupt disable operation + */ + status_t uart_rx_int_dis(const uart_port_t *port) { STATUS_CHECK_POINTER(port);