2023-06-21 18:00:56 +08:00
|
|
|
|
#ifndef board_h__
|
|
|
|
|
#define board_h__
|
|
|
|
|
|
|
|
|
|
#include "stdint.h"
|
|
|
|
|
#include "rtthread.h"
|
|
|
|
|
#include <rthw.h>
|
|
|
|
|
#include "string.h"
|
2023-06-25 15:30:36 +08:00
|
|
|
|
#include "stm32mp1xx.h"
|
2023-06-21 18:00:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct dev_struct{
|
|
|
|
|
const char *name;
|
|
|
|
|
void *dev;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct __uart_def{
|
|
|
|
|
const char *name;
|
|
|
|
|
int (*init)(struct __uart_def *u);
|
|
|
|
|
int (*deinit)(struct __uart_def *u);
|
|
|
|
|
int (*set_irq)(struct __uart_def *u,void (*irq)(void *t,uint8_t d),void *t);
|
|
|
|
|
int (*set_end_irq)(struct __uart_def *u,uint8_t *rx_buff,int rx_buff_size,
|
|
|
|
|
void (*irq)(void *t,uint32_t len),void *t);
|
|
|
|
|
int (*read)(struct __uart_def *u,uint8_t *b,int len);
|
|
|
|
|
int (*write)(struct __uart_def *u,const uint8_t *b,int len);
|
|
|
|
|
void *private_data;
|
|
|
|
|
}uart_def;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct __pwm_def{
|
|
|
|
|
const char *name;
|
|
|
|
|
int (*init)(struct __pwm_def *u);
|
|
|
|
|
int (*deinit)(struct __pwm_def *u);
|
|
|
|
|
int (*start)(struct __pwm_def *u,int step_count);
|
|
|
|
|
int (*stop)(struct __pwm_def *u);
|
|
|
|
|
int (*set_fre)(struct __pwm_def *u,int fre);
|
|
|
|
|
int (*set_irq_fun)(struct __pwm_def *p,void (*fun)(void *t),void *t);
|
|
|
|
|
void *private_data;
|
|
|
|
|
}pwm_def;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_DO(s,to) if(s) {to(s);}
|
|
|
|
|
|
|
|
|
|
#define LENGTH(s) (sizeof(s)/sizeof(s[0]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define uart_init_export(name_,init_,deinit_,set_irq_,set_end_irq_,read_,write_,priv_) \
|
|
|
|
|
const static char __dev_##name_##_name[] SECTION(".rodata.devstr") = #name_; \
|
|
|
|
|
RT_USED static uart_def _uart_##name_={\
|
|
|
|
|
.name=__dev_##name_##_name,\
|
|
|
|
|
.init=init_,\
|
|
|
|
|
.deinit=deinit_,\
|
|
|
|
|
.set_irq=set_irq_,\
|
|
|
|
|
.set_end_irq=set_end_irq_,\
|
|
|
|
|
.read=read_,\
|
|
|
|
|
.write=write_,\
|
|
|
|
|
.private_data=priv_,\
|
|
|
|
|
};\
|
|
|
|
|
RT_USED static const struct dev_struct __dev_##name_ SECTION("devstruct")= \
|
|
|
|
|
{ \
|
|
|
|
|
__dev_##name_##_name, \
|
|
|
|
|
&_uart_##name_, \
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define pwm_init_export(name_,init_,deinit_,start_,stop_,set_fre_,set_end_irq_,priv_) \
|
|
|
|
|
const static char __dev_##name_##_name[] SECTION(".rodata.devstr") = #name_; \
|
|
|
|
|
RT_USED static pwm_def _pwm_##name_={\
|
|
|
|
|
.name=__dev_##name_##_name,\
|
|
|
|
|
.init=init_,\
|
|
|
|
|
.deinit=deinit_,\
|
|
|
|
|
.start=start_,\
|
|
|
|
|
.stop=stop_,\
|
|
|
|
|
.set_fre=set_fre_,\
|
|
|
|
|
.set_irq_fun=set_end_irq_,\
|
|
|
|
|
.private_data=priv_,\
|
|
|
|
|
};\
|
|
|
|
|
RT_USED static const struct dev_struct __dev_##name_ SECTION("devstruct")= \
|
|
|
|
|
{ \
|
|
|
|
|
__dev_##name_##_name, \
|
|
|
|
|
&_pwm_##name_, \
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct init_struct{
|
|
|
|
|
int (*init_fun)(void);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define app_init_export(fun_)\
|
|
|
|
|
RT_USED static const struct init_struct __init_##fun_ SECTION("initstruct")= \
|
|
|
|
|
{\
|
|
|
|
|
.init_fun=fun_,\
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define def_find_fun(type_,g_data_)\
|
|
|
|
|
static const type_ *find(const char *name,int *index)\
|
|
|
|
|
{\
|
|
|
|
|
const type_ *r=0;\
|
|
|
|
|
for(int i=0;i<LENGTH(g_data_);i++)\
|
|
|
|
|
{\
|
|
|
|
|
r=&g_data_[i];\
|
|
|
|
|
if(strcmp(r->name,name)==0){\
|
|
|
|
|
if(index) *index=i;\
|
|
|
|
|
return r;\
|
|
|
|
|
}\
|
|
|
|
|
}\
|
|
|
|
|
return r;\
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void app_init(void);
|
|
|
|
|
void *app_variable(const char *name,void *p,void (*del)(void *t));
|
|
|
|
|
void app_valid_call(const char *name,void (*fun)(void *t),void *t);
|
|
|
|
|
|
|
|
|
|
void param_err_handle(const char *param,const char *file,const char *fun,int line);
|
|
|
|
|
|
|
|
|
|
void cpy4byte(uint32_t *dst,uint32_t *src,int num_4byte);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>s==0,<2C><><EFBFBD>ӡ
|
|
|
|
|
#define param_check(s) \
|
|
|
|
|
if((s)==0){\
|
|
|
|
|
param_err_handle(#s,__FILE__,__func__,__LINE__);}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef RT_THREAD
|
|
|
|
|
|
|
|
|
|
#define irq_disable()\
|
|
|
|
|
register rt_base_t __level;\
|
|
|
|
|
__level = rt_hw_interrupt_disable()
|
|
|
|
|
|
|
|
|
|
#define irq_enable()\
|
|
|
|
|
rt_hw_interrupt_enable(__level)
|
|
|
|
|
|
|
|
|
|
void *dev_get(const char *name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
uint32_t __interrupt_disable(void);
|
|
|
|
|
void __interrupt_enable(uint32_t level);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define irq_disable()\
|
|
|
|
|
register uint32_t __level;\
|
|
|
|
|
__level = __interrupt_disable()
|
|
|
|
|
|
|
|
|
|
#define irq_enable()\
|
|
|
|
|
__interrupt_enable(__level)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
|
|
|
|
|
#define MEM_ADDR(addr) *((volatile uint32_t *)(addr))
|
|
|
|
|
#define BIT_ADDR(addr, bitnum) (MEM_ADDR(BITBAND(addr, bitnum)))
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַs=A~I
|
|
|
|
|
#define GPIOx_ODR_ADDR(s) (GPIO##s##_BASE+20)
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַs=A~I
|
|
|
|
|
#define GPIOx_IDR_ADDR(s) (GPIO##s##_BASE+16)
|
|
|
|
|
|
|
|
|
|
// gpio<69><6F><EFBFBD><EFBFBD><EFBFBD>s=A~I,n=0~15
|
|
|
|
|
#define PINOUT(s,n) BIT_ADDR(GPIOx_ODR_ADDR(s),n)
|
|
|
|
|
#define PININ(s,n) BIT_ADDR(GPIOx_IDR_ADDR(s),n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|