XINU
spicontrol.c
Go to the documentation of this file.
1 /* spicontrol.c - spicontrol */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * spicontrol - Control function for SPI device
7  *------------------------------------------------------------------------
8  */
10  struct dentry *devptr, /* Entry in device switch table */
11  int32 func, /* Control function */
12  int32 arg1, /* Argument 1, if needed */
13  int32 arg2 /* Argument 2, if needed */
14  )
15 {
16  struct spi_csreg *csrptr; /* SPI control and status regs */
17  struct spi_transfer *msg; /* Message pointer */
18  int i; /* For loop index */
19 
20  /* Get the pointer to the SPI CSRs */
21 
22  csrptr = (struct spi_csreg *)devptr->dvcsr;
23 
24  /* Get the pointer to the message */
25 
26  msg = (struct spi_transfer *)arg1;
27 
28  switch(func) {
29 
30  /* This is a SPI transfer */
31 
32  case SPI_CTRL_TRANSFER:
33 
34  for(i = 0; i < msg->length; i++) {
35 
36  /* Wait while the transmit register is not empty */
37 
38  while((csrptr->ch[0].chstat & SPI_CHSTAT_TXS) == 0);
39 
40  /* Send a byte */
41 
42  csrptr->ch[0].chtx = msg->txbuf[i];
43 
44  /* Wait until there is a byte in the receive register */
45 
46  while((csrptr->ch[0].chstat & SPI_CHSTAT_RXS) == 0);
47 
48  /* Read the byte from the receive register */
49 
50  msg->rxbuf[i] = csrptr->ch[0].chrx;
51  }
52 
53  /* End the transfer by changing CS level */
54 
55  csrptr->ch[0].chconf &= ~SPI_CHCONF_FORCE;
56  csrptr->ch[0].chconf |= SPI_CHCONF_FORCE;
57 
58  break;
59  }
60 
61  return OK;
62 }
struct spi_csreg::@14 ch[3]
devcall spicontrol(struct dentry *devptr, int32 func, int32 arg1, int32 arg2)
Definition: spicontrol.c:9
byte * txbuf
Definition: spi.h:74
#define SPI_CHSTAT_TXS
Definition: spi.h:71
全てのシステムヘッダファイルをインクルードする。
#define OK
処理が成功した場合
Definition: kernel.h:77
volatile uint32 chrx
Definition: spi.h:18
Definition: conf.h:6
#define SPI_CHCONF_FORCE
Definition: spi.h:60
Definition: spi.h:3
#define SPI_CTRL_TRANSFER
Definition: spi.h:79
byte * rxbuf
Definition: spi.h:75
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
volatile uint32 chtx
Definition: spi.h:17
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
void * dvcsr
Definition: conf.h:19
volatile uint32 chconf
Definition: spi.h:14
int32 length
Definition: spi.h:76
#define SPI_CHSTAT_RXS
Definition: spi.h:70
volatile uint32 chstat
Definition: spi.h:15