Skip to content

Openofdm rx.c

Function reg_read(u32 reg)

reg_read: The function of reg_read is to read a 32-bit value from a specified hardware register.

parameters: The parameters of this Function. · parameter1: u32 reg - This parameter represents the offset of the register from which the value is to be read.

Code Description: The reg_read function is defined as a static inline function, which means it is intended to be used only within the file it is defined in and may be optimized by the compiler for performance. The function takes a single parameter, reg, which is an unsigned 32-bit integer representing the offset of the register to be accessed.

Inside the function, the ioread32 function is called with the argument (base_addr + reg). Here, base_addr is a predefined pointer that points to the base address of the device's memory-mapped I/O region. The addition of reg to base_addr calculates the exact address of the desired register. The ioread32 function then reads the 32-bit value from that address and returns it. This operation is typically used in low-level hardware programming, where direct access to hardware registers is necessary for device control and status monitoring.

Note: It is important to ensure that the base_addr is correctly initialized to point to the appropriate memory-mapped I/O region before calling this function. Additionally, the value of reg should be within the valid range of the device's registers to avoid undefined behavior.

Output Example: If the base_addr is set to 0x1000 and reg is 0x04, the function call reg_read(0x04) would read the 32-bit value from the memory address 0x1004. If the value at that address is 0xDEADBEEF, the function would return 0xDEADBEEF.

flowchart TD
    A[Start reg_read function] --> B[Receive register address]
    B --> C[Calculate effective address by adding base address]
    C --> D[Read value from calculated address using ioread32]
    D --> E[Return read value]
    E --> F[End reg_read function]

Function reg_write(u32 reg, u32 value)

reg_write: The function of reg_write is to write a specified value to a given hardware register.

parameters: The parameters of this Function. · parameter1: u32 reg - This parameter represents the offset of the register to which the value will be written. It is typically defined as a 32-bit unsigned integer. · parameter2: u32 value - This parameter is the value that will be written to the specified register. It is also defined as a 32-bit unsigned integer.

Code Description: The reg_write function is defined as a static inline function, which means it is intended to be used only within the file it is defined in and may be optimized by the compiler for performance. The function takes two parameters: 'reg' and 'value'. The 'reg' parameter specifies the offset of the hardware register, while the 'value' parameter is the data to be written to that register.

Inside the function, the iowrite32 function is called, which is responsible for writing a 32-bit value to a specific memory-mapped I/O address. The address is calculated by adding the base address (base_addr) to the register offset (reg). This operation effectively targets the correct register in the hardware device for writing the specified value.

The use of iowrite32 is crucial in embedded systems and device drivers, where direct interaction with hardware registers is necessary for controlling hardware behavior. The inline nature of the function suggests that it is optimized for speed, reducing the overhead of function calls in performance-critical code paths.

Note: When using the reg_write function, it is important to ensure that the base_addr is correctly initialized to point to the appropriate memory-mapped I/O region of the hardware device. Additionally, care should be taken to write valid values to the registers, as incorrect values may lead to undefined behavior or hardware malfunctions.

graph TD
    A[Start reg_write function] --> B[Receive register address reg]
    A --> C[Receive value to write]
    B --> D[Calculate effective address by adding base_addr and reg]
    C --> D
    D --> E[Write value to calculated address using iowrite32]
    E --> F[End reg_write function]

Function OPENOFDM_RX_REG_STATE_HISTORY_read(void)

OPENOFDM_RX_REG_STATE_HISTORY_read: The function of OPENOFDM_RX_REG_STATE_HISTORY_read is to read the value from the OPENOFDM_RX_REG_STATE_HISTORY register.

parameters: The parameters of this Function. · There are no parameters for this function.

Code Description: The OPENOFDM_RX_REG_STATE_HISTORY_read function is defined as a static inline function that returns a 32-bit unsigned integer (u32). The function performs a read operation from a specific hardware register identified by the address OPENOFDM_RX_REG_STATE_HISTORY_ADDR. The function utilizes the reg_read function to access the register's value. This operation is typically used in embedded systems or driver development where direct interaction with hardware registers is necessary to retrieve the current state or configuration of a device. The inline nature of the function suggests that it is intended for performance optimization, allowing the compiler to insert the function's code directly at the point of call, thereby reducing function call overhead.

Note: It is important to ensure that the OPENOFDM_RX_REG_STATE_HISTORY_ADDR is correctly defined and accessible within the context of the driver to avoid any runtime errors. Additionally, this function should be used in a context where the register is expected to be read, and the system's state is stable to ensure accurate data retrieval.

Output Example: A possible return value of the function could be a 32-bit integer such as 0x00000001, which represents the current state of the OPENOFDM_RX_REG_STATE_HISTORY register.

graph TD
    A[Start] --> B[Call OPENOFDM_RX_REG_STATE_HISTORY_read]
    B --> C[Execute reg_read function]
    C --> D[Read value from OPENOFDM_RX_REG_STATE_HISTORY_ADDR]
    D --> E[Return value]
    E --> F[End]

Function OPENOFDM_RX_REG_MULTI_RST_write(u32 Data)

OPENOFDM_RX_REG_MULTI_RST_write: The function of OPENOFDM_RX_REG_MULTI_RST_write is to write a specified value to the OPENOFDM_RX_REG_MULTI_RST register.

parameters: The parameters of this Function. · Data: A 32-bit unsigned integer that represents the value to be written to the register.

Code Description: The OPENOFDM_RX_REG_MULTI_RST_write function is defined as a static inline function, which means it is intended for use only within the file it is defined in and may be optimized by the compiler for performance. The function takes a single parameter, Data, which is a 32-bit unsigned integer. Inside the function, the reg_write function is called with two arguments: the address of the OPENOFDM_RX_REG_MULTI_RST register (OPENOFDM_RX_REG_MULTI_RST_ADDR) and the Data value. This operation effectively writes the provided Data value to the specified register address, allowing for the configuration or control of the OPENOFDM_RX hardware component.

Note: It is important to ensure that the Data value being written is valid and appropriate for the specific use case of the OPENOFDM_RX_REG_MULTI_RST register. Improper values may lead to undefined behavior or malfunction of the hardware. Additionally, since this function is marked as static inline, it is recommended to include this function in performance-critical code sections where register writes are frequent.

graph TD
    A[Start] --> B[Receive Data]
    B --> C[Call reg_write function]
    C --> D[Write Data to OPENOFDM_RX_REG_MULTI_RST_ADDR]
    D --> E[End]

Function OPENOFDM_RX_REG_ENABLE_write(u32 Data)

OPENOFDM_RX_REG_ENABLE_write: The function of OPENOFDM_RX_REG_ENABLE_write is to write a specified value to the OPENOFDM_RX_REG_ENABLE register.

parameters: The parameters of this Function. · Data: A 32-bit unsigned integer (u32) that represents the value to be written to the register.

Code Description: The OPENOFDM_RX_REG_ENABLE_write function is defined as a static inline function, which means it is intended to be used only within the file it is defined in and may be optimized by the compiler for performance. The function takes a single parameter, Data, which is a 32-bit unsigned integer. This parameter is used to specify the value that will be written to the OPENOFDM_RX_REG_ENABLE register.

The function body consists of a single call to the reg_write function, which is responsible for performing the actual write operation to the hardware register. The reg_write function takes two arguments: the address of the register to write to (OPENOFDM_RX_REG_ENABLE_ADDR) and the value to be written (Data). By calling reg_write with these parameters, the function effectively updates the register with the provided value, enabling or configuring the corresponding functionality of the OPENOFDM receiver.

Note: It is important to ensure that the value passed to the OPENOFDM_RX_REG_ENABLE_write function is valid and appropriate for the intended operation, as writing incorrect values to hardware registers can lead to undefined behavior or malfunction of the device. Additionally, since this function is defined as inline, it may be inlined by the compiler, which can improve performance but may also increase the size of the compiled code if used extensively.

graph TD
    A[Start] --> B[Receive Data]
    B --> C[Call reg_write function]
    C --> D[Write Data to OPENOFDM_RX_REG_ENABLE_ADDR]
    D --> E[End]

Function OPENOFDM_RX_REG_POWER_THRES_write(u32 Data)

OPENOFDM_RX_REG_POWER_THRES_write: The function of OPENOFDM_RX_REG_POWER_THRES_write is to write a specified value to the OPENOFDM_RX_REG_POWER_THRES register.

parameters: The parameters of this Function. · Data: A 32-bit unsigned integer (u32) that represents the value to be written to the register.

Code Description: The OPENOFDM_RX_REG_POWER_THRES_write function is defined as a static inline function, which means it is intended for use only within the file it is defined in and may be optimized by the compiler for performance. The function takes a single parameter, Data, which is a 32-bit unsigned integer. This value is written to a specific hardware register identified by the constant OPENOFDM_RX_REG_POWER_THRES_ADDR. The actual writing to the register is performed by the reg_write function, which is assumed to handle the low-level details of writing to the hardware register.

The function effectively allows the user to set the power threshold for the OPENOFDM receiver by writing the desired threshold value directly to the corresponding register. This is crucial for configuring the receiver's sensitivity and performance characteristics in a communication system.

Note: It is important to ensure that the value passed to this function is within the acceptable range for the OPENOFDM_RX_REG_POWER_THRES register to avoid undefined behavior or hardware malfunctions. Additionally, this function should be called in a context where the hardware is properly initialized and ready to accept register writes.

graph TD
    A[Start] --> B[Receive Data]
    B --> C[Call reg_write function]
    C --> D[Write Data to OPENOFDM_RX_REG_POWER_THRES_ADDR]
    D --> E[End]

Function OPENOFDM_RX_REG_MIN_PLATEAU_write(u32 Data)

OPENOFDM_RX_REG_MIN_PLATEAU_write: The function of OPENOFDM_RX_REG_MIN_PLATEAU_write is to write a specified value to the OPENOFDM_RX_REG_MIN_PLATEAU register.

parameters: The parameters of this Function. · Data: This parameter is of type u32 and represents the value to be written to the register.

Code Description: The OPENOFDM_RX_REG_MIN_PLATEAU_write function is defined as a static inline function, which means it is intended for use only within the file it is defined in and may be optimized by the compiler for performance. The function takes a single parameter, Data, which is a 32-bit unsigned integer (u32). Inside the function, the reg_write function is called with two arguments: OPENOFDM_RX_REG_MIN_PLATEAU_ADDR and Data.

OPENOFDM_RX_REG_MIN_PLATEAU_ADDR is a predefined constant that specifies the memory address of the OPENOFDM_RX_REG_MIN_PLATEAU register. The reg_write function is responsible for writing the value of Data to this register address. This operation is typically used in hardware programming to configure or control the behavior of a device by setting specific register values.

Note: It is important to ensure that the value passed to the Data parameter is valid for the specific register being written to, as incorrect values may lead to undefined behavior or malfunction of the hardware. Additionally, since this function is static inline, it may be inlined by the compiler, which can improve performance but may also increase the size of the binary if used excessively.

graph TD
    A[Start] --> B[Receive Data]
    B --> C[Call reg_write function]
    C --> D[Write Data to OPENOFDM_RX_REG_MIN_PLATEAU_ADDR]
    D --> E[End]

Function OPENOFDM_RX_REG_SOFT_DECODING_write(u32 Data)

OPENOFDM_RX_REG_SOFT_DECODING_write: The function of OPENOFDM_RX_REG_SOFT_DECODING_write is to write a specified value to the OPENOFDM_RX_REG_SOFT_DECODING register.

parameters: The parameters of this Function. · Data: This parameter is of type u32 and represents the value to be written to the register.

Code Description: The OPENOFDM_RX_REG_SOFT_DECODING_write function is defined as a static inline function, which means it is intended for use only within the file it is defined in and may be optimized by the compiler for performance. The function takes a single parameter, Data, which is a 32-bit unsigned integer (u32). Inside the function, the reg_write function is called with two arguments: the address of the OPENOFDM_RX_REG_SOFT_DECODING register and the Data value. The reg_write function is responsible for performing the actual write operation to the specified register address. This function is crucial for configuring or updating the state of the OPENOFDM_RX hardware component by writing the appropriate data to its control register.

Note: It is important to ensure that the value passed to the Data parameter is valid and appropriate for the specific register being written to, as incorrect values may lead to undefined behavior or malfunction of the hardware. Additionally, since this function is defined as inline, it is recommended to use it in performance-critical sections of code where register writes are frequent.

graph TD
    A[Start] --> B[Receive Data]
    B --> C[Call reg_write function]
    C --> D[Write Data to OPENOFDM_RX_REG_SOFT_DECODING_ADDR]
    D --> E[End]

Function OPENOFDM_RX_REG_FFT_WIN_SHIFT_write(u32 Data)

OPENOFDM_RX_REG_FFT_WIN_SHIFT_write: The function of OPENOFDM_RX_REG_FFT_WIN_SHIFT_write is to write a specified value to the FFT window shift register of the OPENOFDM receiver.

parameters: The parameters of this Function. · Data: A 32-bit unsigned integer (u32) that represents the value to be written to the FFT window shift register.

Code Description: The OPENOFDM_RX_REG_FFT_WIN_SHIFT_write function is defined as a static inline function, which means it is intended to be used only within the file it is defined in and can be optimized by the compiler for performance. The function takes a single parameter, Data, which is a 32-bit unsigned integer.

Inside the function, the reg_write function is called with two arguments: OPENOFDM_RX_REG_FFT_WIN_SHIFT_ADDR and Data. OPENOFDM_RX_REG_FFT_WIN_SHIFT_ADDR is a predefined constant that specifies the memory address of the FFT window shift register in the OPENOFDM receiver hardware. The reg_write function is responsible for writing the value of Data to the specified address. This operation is essential for configuring the FFT window shift settings in the receiver, which can affect the performance and behavior of the signal processing.

Note: It is important to ensure that the value passed to the Data parameter is within the acceptable range for the FFT window shift register to avoid undefined behavior or hardware malfunctions. Additionally, this function should be called in the appropriate context where the receiver is properly initialized and ready to accept configuration changes.

graph TD
    A[Start] --> B[Receive Data]
    B --> C[Call reg_write function]
    C --> D[Write Data to OPENOFDM_RX_REG_FFT_WIN_SHIFT_ADDR]
    D --> E[End]

Function hw_init(enum openofdm_rx_mode mode)

hw_init: The function of hw_init is to initialize hardware settings for the OpenOFDM receiver based on the specified mode.

parameters: The parameters of this Function. · mode: An enumeration value of type openofdm_rx_mode that specifies the operational mode of the receiver. It can be either OPENOFDM_RX_TEST or OPENOFDM_RX_NORMAL.

Code Description: The hw_init function begins by logging the initialization mode using the printk function, which outputs messages to the kernel log. It checks the provided mode against predefined operational modes. If the mode is OPENOFDM_RX_TEST, it logs that the test mode is selected. If the mode is OPENOFDM_RX_NORMAL, it logs that the normal mode is selected. If the mode does not match either of these, it logs an error message indicating that the mode is incorrect and sets an error flag.

Following the mode check, the function logs the initial configuration values for power threshold, DC running sum threshold, and minimum plateau. It then proceeds to configure various hardware registers using the openofdm_rx_api interface. The configuration includes setting the power threshold, minimum plateau, soft decoding parameters, and FFT window shift.

The function also performs a reset operation on the hardware by writing to the MULTI_RST register multiple times to ensure that the hardware is properly reset. It writes a value of 0, followed by a value of 0xFFFFFFFF, and then writes 0 again to complete the reset sequence.

Finally, the function logs any error encountered during the initialization process and returns the error code. A return value of 0 indicates success, while a return value of 1 indicates an error due to an invalid mode.

Note: It is important to ensure that the mode parameter is correctly set to either OPENOFDM_RX_TEST or OPENOFDM_RX_NORMAL before calling this function to avoid initialization errors. Additionally, proper handling of the return value is essential for determining the success of the hardware initialization.

Output Example: If the function is called with OPENOFDM_RX_TEST as the mode, the expected return value would be 0, indicating successful initialization. If an invalid mode is passed, the function would return 1, indicating an error.

graph TD
    A[Start hw_init function] --> B[Print hw_init mode]
    B --> C{Check mode}
    C -->|OPENOFDM_RX_TEST| D[Print hw_init mode OPENOFDM_RX_TEST]
    C -->|OPENOFDM_RX_NORMAL| E[Print hw_init mode OPENOFDM_RX_NORMAL]
    C -->|Default| F[Print hw_init mode is wrong]
    F --> G[Set err to 1]
    D --> H[Print input parameters]
    E --> H
    H --> I[Configure power threshold and reset]
    I --> J[Write to OPENOFDM_RX_REG_POWER_THRES]
    J --> K[Write to OPENOFDM_RX_REG_MIN_PLATEAU]
    K --> L[Write to OPENOFDM_RX_REG_SOFT_DECODING]
    L --> M[Write to OPENOFDM_RX_REG_FFT_WIN_SHIFT]
    M --> N[Reset multi_rst register]
    N --> O[Loop 8 times to write 0]
    O --> P[Loop 32 times to write 0xFFFFFFFF]
    P --> Q[Loop 8 times to write 0]
    Q --> R[Print hw_init err]
    R --> S[Return err]
    S --> T[End hw_init function]

Function dev_probe(struct platform_device *pdev)

dev_probe: The function of dev_probe is to initialize the device driver for the OpenOFDM receiver.

parameters: The parameters of this Function. · parameter1: struct platform_device *pdev - A pointer to the platform device structure that represents the device being probed.

Code Description: The dev_probe function is responsible for initializing the OpenOFDM receiver device when it is detected by the system. It begins by retrieving the device node associated with the platform device from the provided parameter pdev. The function then checks if the device node is valid. If valid, it attempts to match the device node with a predefined list of compatible device identifiers using the of_match_node function. If a match is found, a success message is printed, and the error code is set to zero.

If no match is found, the function returns an error code, indicating that the device is not supported. Upon successful matching, the function proceeds to set up the OpenOFDM receiver API by assigning various function pointers for hardware initialization and register read/write operations. These assignments allow the driver to interact with the hardware effectively.

Next, the function requests and maps the I/O memory resources associated with the device using platform_get_resource and devm_ioremap_resource. If the memory mapping fails, the function returns an error code indicating the failure.

The function then prints detailed information about the I/O memory, including its start and end addresses, name, flags, and description. It also logs the base address of the mapped I/O memory and the addresses of the driver API instance and the OpenOFDM receiver API structure.

Finally, the function calls the hardware initialization function hw_init with a specific mode (OPENOFDM_RX_NORMAL) and returns the result of this initialization process. This ensures that the device is properly set up for operation.

Note: It is important to ensure that the device node is correctly defined in the device tree and that the necessary resources are available for the device to function properly. The function should only be called during the device initialization phase.

Output Example: A successful execution of the function may return 0, indicating that the device has been initialized correctly. If there is an error during the process, it may return a negative error code, such as -ENOMEM for memory allocation failures or -EINVAL for invalid parameters.

graph TD
    A[Start dev_probe function] --> B[Get device node from platform device]
    B --> C{Is device node valid?}
    C -->|Yes| D[Match device node with device IDs]
    C -->|No| E[Return error 1]
    D --> F{Is match found?}
    F -->|Yes| G[Print match message]
    F -->|No| H[Return error 1]
    G --> I[Set hardware initialization and register functions]
    I --> J[Request and map I/O memory]
    J --> K[Get I/O resource from platform device]
    K --> L[Map resource to base address]
    L --> M{Is mapping successful?}
    M -->|Yes| N[Print I/O and base address information]
    M -->|No| O[Return error from mapping]
    N --> P[Print driver API instance information]
    P --> Q[Print API pointer information]
    Q --> R[Print success message]
    R --> S[Call hardware initialization function]
    S --> T[Return error from hw_init]
    E --> T
    O --> T
    T --> U[End dev_probe function]

Function dev_remove(struct platform_device *pdev)

dev_remove: The function of dev_remove is to handle the removal of a device from the platform.

parameters: The parameters of this Function. · parameter1: struct platform_device *pdev - A pointer to the platform device structure that represents the device being removed.

Code Description: The dev_remove function is defined as a static function that takes a single parameter, a pointer to a platform_device structure. This function is responsible for performing cleanup operations when a device is removed from the platform.

Upon invocation, the function first prints a newline character to the console for formatting purposes. It then logs several messages that include the base address of the device and the addresses of the openofdm_rx_driver_api_inst and openofdm_rx_api instances. These messages are formatted to include the string defined by openofdm_rx_compatible_str, which likely identifies the compatible device or driver. Each address is cast to a 32-bit unsigned integer (u32) for proper formatting in the log output.

Finally, the function prints a success message indicating that the removal process has completed successfully. The function concludes by returning 0, which typically signifies that the operation was successful without errors.

Note: It is important to ensure that any resources allocated to the device are properly released before this function is called to prevent memory leaks or resource contention.

Output Example: The output of the function might look like the following in the console:

<newline>
<compatible_string> dev_remove base_addr 0x12345678
<compatible_string> dev_remove openofdm_rx_driver_api_inst 0x87654321
<compatible_string> dev_remove             openofdm_rx_api 0xabcdef00
<compatible_string> dev_remove succeed!
Here, <compatible_string> would be replaced by the actual value of openofdm_rx_compatible_str, and the hexadecimal addresses would reflect the actual memory addresses used by the device.

graph TD
    A[Start dev_remove function] --> B[Print newline]
    B --> C[Print base_addr value]
    C --> D[Print openofdm_rx_driver_api_inst address]
    D --> E[Print openofdm_rx_api address]
    E --> F[Print success message]
    F --> G[Return 0]
    G --> H[End dev_remove function]