drv_hwtimer.c文件中的 timer_init函数如下
static void timer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
它的参数timer是 rt_hwtimer_device指针类型,
但是在这个函数里, 有一句
tim_device = (struct stm32_hwtimer *)timer;
又把它强转成stm32_hwtimer指针类型,
关于这两个类型分别是:
typedef struct rt_hwtimer_device
{
struct rt_device parent;
const struct rt_hwtimer_ops *ops;
const struct rt_hwtimer_info *info;
rt_int32_t freq; /* counting frequency set by the user */
rt_int32_t overflow; /* timer overflows */
float period_sec;
rt_int32_t cycles; /* how many times will generate a timeout event after overflow */
rt_int32_t reload; /* reload cycles(using in period mode) */
rt_hwtimer_mode_t mode; /* timing mode(oneshot/period) */
} rt_hwtimer_t;
和
struct stm32_hwtimer
{
rt_hwtimer_t time_device;
TIM_HandleTypeDef tim_handle;
IRQn_Type tim_irqn;
char *name;
};
我想问一个指针是怎么同时指向这两个类型的, 我觉得我C语言不过关了.
哦哦, 是的, 这两个的首地址是相同的. 感谢提醒.