例如,请参阅改编自 BlueZ 的 BCM43xx 蓝牙驱动程序的代码:
int bcm43xx_init(int fd, int def_speed, int speed, struct termios *ti,
const char *bdaddr)
{
char chip_name[20];
char fw_path[PATH_MAX];
printf("bcm43xx_init\n");
if (bcm43xx_reset(fd))
return -1;
if (bcm43xx_read_local_name(fd, chip_name, sizeof(chip_name)))
return -1;
if (bcm43xx_locate_patch(FIRMWARE_DIR, chip_name, fw_path)) {
fprintf(stderr, "Patch not found, continue anyway\n");
} else {
if (bcm43xx_set_speed(fd, ti, speed))
return -1;
if (bcm43xx_load_firmware(fd, fw_path))
return -1;
/* Controller speed has been reset to def speed */
if (set_speed(fd, ti, def_speed) < 0) {
perror("Can't set host baud rate");
return -1;
}
if (bcm43xx_reset(fd))
return -1;
}
if (bdaddr)
bcm43xx_set_bdaddr(fd, bdaddr);
if (bcm43xx_set_speed(fd, ti, speed))
return -1;
return 0;
}
在这个函数的中间,它会在文件系统上查找一个文件,并通过调用 bcm43xx_load_firmware 将其加载到芯片中。为什么每次都需要这样做?
提前致谢。