OSDN Git Service

(none)
[hos/hos-v4a.git] / aplfw / driver / ether / lan9000 / lan9000hal_setup.c
1 /**
2  *  Hyper Operating System  Application Framework
3  *
4  * @file  lan9000hal.h
5  * @brief %jp{LAN9000シリーズ用ハードウェアアクセス層}
6  *
7  * Copyright (C) 2006-2007 by Project HOS
8  * http://sourceforge.jp/projects/hos/
9  */
10
11
12 #include "system/sysapi/sysapi.h"
13 #include "lan9000hal_local.h"
14
15
16
17 /** 初期化 */
18 int Lan9000Hal_Setup(C_LAN9000HAL *self)
19 {
20         int iTimeOut;
21         
22         /* リセット処理 */
23         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 0);
24         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B0_RCR, 0x8000);
25
26         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 1);
27         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B1_CONFIG, LAN9000HAL_REG_READ(self, LAN9000HAL_B1_CONFIG) | 0x8000);
28         SysTim_Wait(50);
29
30         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 0);
31         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B0_RCR,  0x0000);
32         SysTim_Wait(50);
33
34         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 2);
35         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B2_MMU_COMMAND,  0x0040);
36         
37         
38         /* ANEG処理 */
39         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 0);
40         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B0_RPCR, 0x0800);
41         SysTim_Wait(100);
42         
43         Lan9000Hal_PhyRegWrite(self, 0, 0, 0x8000);
44         SysTim_Wait(50);
45
46         Lan9000Hal_PhyRegWrite(self, 0, 0, 0x3000);
47         SysTim_Wait(1500);
48         
49         iTimeOut = 0;
50         while ( !(Lan9000Hal_PhyRegRead(self, 0, 1) & 0x0020) )
51         {
52                 if ( iTimeOut++ > 200 )
53                 {
54                         return (-1);
55                 }
56                 SysTim_Wait(10);
57         }
58         
59         /* Configure the Transmit and Receive registers to allow external loopback */
60         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 0);
61         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B0_RPCR, 0x0800);
62         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B0_TCR, 0x0881);
63         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B0_RCR, 0x0302);
64         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 1);
65         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B1_CONFIG, LAN9000HAL_REG_READ(self, LAN9000HAL_B1_CONFIG) | 0x8000);
66         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B1_CONTROL,  0x5a10);     
67         SysTim_Wait(1);
68         
69         /* 送信バッファ割り当て要求 */
70         LAN9000HAL_REG_WRITE(self, LAN9000HAL_BANK, 2);
71         LAN9000HAL_REG_WRITE(self, LAN9000HAL_B2_MMU_COMMAND, 0x0020);
72         
73         return 0;
74 }
75
76
77
78 /* endof file */