spidemo.c
来自「一个嵌入式linux的驱动程序例子」· C语言 代码 · 共 50 行
C
50 行
#include <linux/types.h>#include <linux/stat.h>#include <linux/fcntl.h>#include <stdio.h>#include "spi.h"int dev_handle,boot_handle,PacketNum,DotNum;unsigned char bootdata[60*1024],*p;unsigned int filelen;unsigned long temp;int boot(){ boot_handle=open("bootload.bin",O_RDONLY); if(boot_handle==-1) { printf("Boot file not found,reset dsp fauler!\n"); close(dev_handle); return -1; } filelen=lseek(boot_handle,0,SEEK_END); lseek(boot_handle,0,SEEK_SET); read(boot_handle,bootdata,filelen); close(boot_handle); ioctl(dev_handle,SPI_SET_BOOTLEN,filelen); return ioctl(dev_handle,SPI_SEND_BOOTDATA,bootdata);} int main(){ dev_handle=open("/dev/spi_drv",O_RDWR); if(dev_handle==-1) { printf("Device not exist,check system!\n"); return -1; } boot(); /* for(temp=0;temp<0x1ffffff;temp++){}; ioctl(dev_handle,SPI_BLIGHT_ON,NULL); */ ioctl(dev_handle,SPI_MODEM_RESET,NULL); close(dev_handle); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?