spi_cmd.c
资源名称:driver.rar [点击查看]
上传用户:plenty2008
上传日期:2022-08-02
资源大小:11k
文件大小:2k
源码类别:
驱动编程
开发平台:
Unix_Linux
- /*
- Module Name: SPI_CMD.C
- Abstract: Function definition for the CAN's spi command interface
- Notes: Presently, only the SPI Channel 0 is supported.
- Environment: MCP2515
- Date: 2004/01/28
- By: Li zhongmin
- */
- #include <asm-arm/arch-s3c2410/S3C2410.h>
- #include "spi.h"
- #include "spi_cmd.h"
- unsigned char CAN_SPI_CMD( unsigned char cmd, unsigned long addr, unsigned char arg1, unsigned char arg2 )
- {
- unsigned char ret=0;
- unsigned char data=0;
- // Empty the spi's transfer and receive buffer
- // SPI_TXFlush( CAN_SPI_MODULE );
- // SPI_RXFlush( CAN_SPI_MODULE );
- //StartSPIClock();
- *(unsigned int *)rGPGDAT = (*(unsigned int *)rGPGDAT) & CHIP_SELECT_nSS0;
- switch( cmd ){
- case SPI_CMD_READ:
- // printk("SPI_CMD_READn");
- ret = SPI_SendByte(SPI_CMD_READ, &data);
- ret = SPI_SendByte(addr, &data);
- ret = SPI_SendByte(0xff, &data);
- break;
- case SPI_CMD_WRITE:
- // printk("SPI_CMD_WRITEn");
- ret = SPI_SendByte(SPI_CMD_WRITE, &data);
- // printk("send byte return value = %dn",ret);
- ret = SPI_SendByte(addr, &data);
- ret = SPI_SendByte(arg1, &data);
- break;
- case SPI_CMD_RTS:
- ret = SPI_SendByte(SPI_CMD_RTS, &data);
- break;
- case SPI_CMD_READSTA:
- ret = SPI_SendByte(SPI_CMD_READSTA, &data);
- ret = SPI_SendByte(0xff, &data);
- break;
- case SPI_CMD_BITMOD:
- // printk("SPI_CMD_BITMODn");
- ret = SPI_SendByte(SPI_CMD_BITMOD, &data);
- // printk("send byte 1 return value = %dn",ret);
- ret = SPI_SendByte(addr, &data);
- // printk("send byte 2 return value = %dn",ret);
- ret = SPI_SendByte(arg1, &data);
- // printk("send byte 3 return value = %dn",ret);
- ret = SPI_SendByte(arg2, &data);
- // printk("send byte 4 return value = %dn",ret);
- break;
- case SPI_CMD_RESET:
- // printk("SPI_CMD_RESETn");
- ret = SPI_SendByte(SPI_CMD_RESET, &data);
- break;
- default:
- ret = 0x30; // any value is ok
- }
- *(unsigned int *)rGPGDAT = (*(unsigned int *)rGPGDAT)|CHIP_DESELECT_nSS0;
- //StopSPIClock();
- //SPI_RXFlush( CAN_SPI_MODULE );
- return data;
- }