XINU
ethread.c
Go to the documentation of this file.
1 /* ethread.c - ethread */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * ethread - read an incoming packet on TI AM335X Ethernet
7  *------------------------------------------------------------------------
8  */
10  struct dentry *devptr,
11  void *buf,
12  uint32 count
13  )
14 {
15  struct ethcblk *ethptr; /* Ethernet ctl blk ptr */
16  struct eth_a_csreg *csrptr; /* Ethernet CSR pointer */
17  struct eth_a_rx_desc *rdescptr;/* Rx Desc. pointer */
18  struct eth_a_rx_desc *prev; /* Prev Rx desc pointer */
19  uint32 retval; /* Num of bytes returned*/
20 
21  ethptr = &ethertab[devptr->dvminor];
22 
23  /* Get the pointer to Ethernet CSR */
24  csrptr = (struct eth_a_csreg *)ethptr->csr;
25 
26  /* Wait for a packet */
27  wait(ethptr->isem);
28 
29  /* Get pointer to the descriptor */
30  rdescptr = (struct eth_a_rx_desc *)ethptr->rxRing +
31  ethptr->rxHead;
32 
33  /* Read the packet length */
34  retval = rdescptr->packlen;
35  if(retval > count) {
36  retval = count;
37  }
38 
39  /* Copy the packet into user provided buffer */
40  memcpy((char *)buf, (char *)rdescptr->buffer, retval);
41 
42  /* Initialize the descriptor for next packet */
43  rdescptr->stat = ETH_AM335X_RDS_OWN;
44  rdescptr->bufoff = 0;
45  rdescptr->buflen = ETH_BUF_SIZE;
46  rdescptr->packlen = 0;
47  rdescptr->next = NULL;
48 
49  /* Insert the descriptor into Rx queue */
50  prev = (struct eth_a_rx_desc *)csrptr->stateram->rx_hdp[0];
51  if(prev == NULL) {
52  kprintf("hdp 0, adding %x\n", rdescptr);
53  csrptr->stateram->rx_hdp[0] = (uint32)rdescptr;
54  }
55  else {
56  while(prev->next != NULL) {
57  prev = prev->next;
58  }
59  prev->next = rdescptr;
60  }
61 
62  /* Increment the head index of rx ring */
63  ethptr->rxHead++;
64  if(ethptr->rxHead >= ethptr->rxRingSize) {
65  ethptr->rxHead = 0;
66  }
67 
68  return retval;
69 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
uint16 packlen
DMAパケットの長さ
Definition: am335x_eth.h:330
void * rxRing
Definition: ether.h:82
uint32 rx_hdp[8]
RX(受信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:128
#define ETH_AM335X_RDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:340
int32 dvminor
Definition: conf.h:8
全てのシステムヘッダファイルをインクルードする。
Ethernet subsystemレジスタ構造体
Definition: am335x_eth.h:297
Definition: ether.h:68
uint32 rxHead
Definition: ether.h:84
#define ETH_BUF_SIZE
Definition: ether.h:34
DMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:319
uint16 bufoff
DMAバッファのオフセット
Definition: am335x_eth.h:328
Definition: conf.h:6
struct eth_a_rx_desc * next
次のDMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:322
struct ethcblk ethertab[]
Definition: ethinit.c:7
uint16 stat
DMA状態
Definition: am335x_eth.h:332
volatile struct eth_a_stateram * stateram
CPSW_STATERANレジスタ
Definition: am335x_eth.h:304
uint16 buflen
DMAバッファの長さ
Definition: am335x_eth.h:326
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 ethread(struct dentry *devptr, void *buf, uint32 count)
Definition: ethread.c:9
uint32 buffer
DMAバッファ
Definition: am335x_eth.h:324
syscall wait(sid32)
Definition: wait.c:9
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * csr
Definition: ether.h:76
uint32 rxRingSize
Definition: ether.h:86
sid32 isem
Definition: ether.h:102
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13