小弟今天写了一段关于SPI的驱动代码。板子上是通过SPI对一块FLASH操作的。MPC作为master,FLASH作为slave。
下面是我的代码,主要就是一些寄存器的初始化,这是我第一次操刀写BSP,希望各位达人帮我看看有没有问题,大家相互交流一下!谢谢!
我把参数ram,rxBD和txBD,还有rxBuffer,txBuffer都放在dual_ram中,其中参数ram放在bank#11中,BD和BUFFER放在bank#2中。
在这段代码执行之前,我执行sysSerialHwInit(),在其中将Port D的16,17,18,19,20脚设置好,这段代码如下:
* M8260_IOP_PDDIR(immrVal) &= 0xFFFF07FC; /* clear first */
* M8260_IOP_PDDIR(immrVal) |= 0x00000002; /* TXD pin 30| RXD pin 31 */
* M8260_IOP_PDDIR(immrVal) |= 0x00000010; /* set bit 27 for SCC2 */
* M8260_IOP_PDDIR(immrVal) &= ~0x00000008; /* clear bit 28 for SCC2 */
* M8260_IOP_PDPAR(immrVal) |= 0x00000003; /* TXD pin 30| RXD pin 31 */
* M8260_IOP_PDPAR(immrVal) |= 0x00000018; /* set bits 27, 28 for SCC2*/
* M8260_IOP_PDPAR(immrVal) |= 0x00000004; /* set bit 29 for SCC2*/
* M8260_IOP_PDPAR(immrVal) |= 0x00000020; /* set bit 26 for SCC2*/
* M8260_IOP_PDPAR(immrVal) |= 0x0000F000; /* set bit 16,17,18,19 for SPI*/
* M8260_IOP_PDSO(immrVal) &= 0xFFFFFFF8; /* clear first */
* M8260_IOP_PDSO(immrVal) |= 0x00000002; /* TXD pin 30 and RXD pin 31 */
* M8260_IOP_PDSO(immrVal) &= ~0x00000018; /* clear bits 27, 28 for SCC2 */
* M8260_IOP_PDSO(immrVal) &= ~0x00000020; /* clear bit 26 for SCC2 */
* M8260_IOP_PDSO(immrVal) |= 0x0000F000; /* set bit 16,17,18,19 for SCC2 */
* M8260_IOP_PDODR(immrVal) &= 0xFFFF08ED;
* M8260_IOP_PDDAT(immrVal) = 0x00000000;
/*
DESCRIPTION
This library contains routines for M8280 SPI BSP serial device
initialization
*/
#include "vxWorks.h"
#include "iv.h"
#include "intLib.h"
#include "config.h"
#include "sysLib.h"
#include "drv/parallel/m8260IOPort.h"
#include "drv/sio/m8260Cp.h"
IMPORT UINT32 vxImmrGet (void);
#define M8260_SPMODE(base) ((VINT32 *)((base) + 0x11AA0))
#define M8260_SPIE(base) ((VINT32 *)((base) + 0x11AA6))
#define M8260_SPIM(base) ((VINT32 *)((base) + 0x11AAA))
#define M8260_SPCOM(base) ((VINT32 *)((base) + 0x11AAD))
#define M8260_SPI_BASE(base) ((VINT32 *)((base) + 0x89FC))
#define M8260_SPI_PARARAM_OFFSET 0x9000
#define M8260_SPI_RARARAM(base) ((VINT32 *)((base) + M8260_SPI_PARARAM_OFFSET))
#define M8260_SPI_RXBD_OFFSET 0x0800
#define M8260_SPI_RXBD(base) ((VINT32 *)((base) + M8260_SPI_RXBD_OFFSET))
#define M8260_SPI_TXBD_OFFSET 0x0808