XINU
Functions
spicontrol.c File Reference
#include <xinu.h>
Include dependency graph for spicontrol.c:

Go to the source code of this file.

Functions

devcall spicontrol (struct dentry *devptr, int32 func, int32 arg1, int32 arg2)
 

Function Documentation

◆ spicontrol()

devcall spicontrol ( struct dentry devptr,
int32  func,
int32  arg1,
int32  arg2 
)

Definition at line 9 of file spicontrol.c.

References spi_csreg::ch, spi_csreg::chconf, spi_csreg::chrx, spi_csreg::chstat, spi_csreg::chtx, dentry::dvcsr, spi_transfer::length, OK, spi_transfer::rxbuf, SPI_CHCONF_FORCE, SPI_CHSTAT_RXS, SPI_CHSTAT_TXS, SPI_CTRL_TRANSFER, and spi_transfer::txbuf.

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]
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
#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
volatile uint32 chtx
Definition: spi.h:17
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