generated from Embedded_Projects/MPyATE_Template
71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
/* App */
|
|
#include "app_adc.h"
|
|
#include "app_dac.h"
|
|
#include "app_gpio.h"
|
|
#include "app_sys_utils.h"
|
|
#include "app_uart.h"
|
|
|
|
/* Private */
|
|
#include "app_reg_if.h"
|
|
|
|
#define MODULE_ID_SYS_UTILS 0
|
|
#define MODULE_ID_GPIO 1
|
|
#define MODULE_ID_ADC 2
|
|
#define MODULE_ID_DAC 3
|
|
#define MODULE_ID_UART 4
|
|
#define MODULE_ID_END 5
|
|
|
|
typedef uint16_t (*module_reg_read_t)(uint8_t offset);
|
|
typedef void (*module_reg_write_t)(uint8_t offset, uint16_t data);
|
|
|
|
typedef struct {
|
|
module_reg_read_t read;
|
|
module_reg_write_t write;
|
|
} module_reg_t;
|
|
|
|
static const module_reg_t s_module_regs[MODULE_ID_END] = {
|
|
[MODULE_ID_SYS_UTILS] =
|
|
{
|
|
.read = app_sys_utils_module_reg_read,
|
|
.write = app_sys_utils_module_reg_write,
|
|
},
|
|
[MODULE_ID_GPIO] =
|
|
{
|
|
.read = app_gpio_module_reg_read,
|
|
.write = app_gpio_module_reg_write,
|
|
},
|
|
[MODULE_ID_ADC] =
|
|
{
|
|
.read = app_adc_module_reg_read,
|
|
.write = app_adc_module_reg_write,
|
|
},
|
|
[MODULE_ID_DAC] =
|
|
{
|
|
.read = app_dac_module_reg_read,
|
|
.write = app_dac_module_reg_write,
|
|
},
|
|
[MODULE_ID_UART] =
|
|
{
|
|
.read = app_uart_module_reg_read,
|
|
.write = app_uart_module_reg_write,
|
|
},
|
|
};
|
|
|
|
uint16_t app_reg_if_read(uint8_t reg) {
|
|
uint8_t module_id = (reg >> 4U) & 0x0FU;
|
|
|
|
if (module_id < MODULE_ID_END) {
|
|
return s_module_regs[module_id].read(reg & 0x0FU);
|
|
}
|
|
|
|
return 0x5555;
|
|
}
|
|
|
|
void app_reg_if_write(uint8_t reg, uint16_t data) {
|
|
uint8_t module_id = (reg >> 4U) & 0x0FU;
|
|
|
|
if (module_id < MODULE_ID_END) {
|
|
s_module_regs[module_id].write((reg & 0x0FU), data);
|
|
}
|
|
}
|