1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: nwmeth.h
4
5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 21218 $
14 *---------------------------------------------------------------------------*/
15
16
17 #ifndef NN_NETWORK_NWMETH_H
18 #define NN_NETWORK_NWMETH_H
19
20 #include <nnet.h>
21 #include <nnet/nnet_ext.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /*---------------------------------------------------------------------------*
28 * Definitions
29 *---------------------------------------------------------------------------*/
30 #define NWMETH_DEVICE_1 0 /* このドライバで扱えるI/Fは1つだけ */
31
32 #define NWMETH_USE_MBUF 1
33
34 #define NWMETH_VENDOR_NINTENDO 0x0000
35 #define NWMETH_COMMON_CONF_VERSION 0x1100
36 #define NWMETH_INS_CONF_VERSION 0x2100
37
38 /**
39 * エラーコード
40 */
41 #define NWMETH_ERROR_BASE 0xffff9000
42 #define NWMETH_ERROR_CODE(code) ((s32)(NWMETH_ERROR_BASE | (code)))
43 enum
44 {
45 NWMETH_ERR_PARAM = NWMETH_ERROR_CODE(1), /* パラメータエラー */
46 NWMETH_ERR_INIT = NWMETH_ERROR_CODE(2), /* 初期状態のため実行不可 */
47 NWMETH_ERR_FINISH = NWMETH_ERROR_CODE(3), /* 終了状態のため実行不可 */
48 NWMETH_ERR_CONFVER = NWMETH_ERROR_CODE(4), /* 設定のバージョンエラー */
49 NWMETH_ERR_STATE = NWMETH_ERROR_CODE(5), /* ステートエラー */
50 NWMETH_ERR_EXIST = NWMETH_ERROR_CODE(6), /* 既に作成済み */
51 NWMETH_ERR_NOMEM = NWMETH_ERROR_CODE(7), /* メモリ不足 */
52 NWMETH_ERR_TIMEOUT = NWMETH_ERROR_CODE(8), /* タイムアウト */
53 NWMETH_ERR_IO = NWMETH_ERROR_CODE(9),
54 NWMETH_ERR_NONE = 0 /* 正常終了 */
55 };
56
57 /**
58 * メモリ
59 */
60 #define NWMETH_MEM_BASE 0x00050000
61 #define NWMETH_MEM_NAME(name) ((s32)(NWMETH_MEM_BASE | (name)))
62 enum
63 {
64 NWMETH_MEM_INSTANCE = NWMETH_MEM_NAME(1)
65 };
66
67 /**
68 * ステート
69 */
70 enum
71 {
72 NWMETH_STATE_INIT = 0, /* 初期状態 */
73 NWMETH_STATE_ACTIVE, /* 接続完了状態 */
74 NWMETH_STATE_DESTROY,
75 NWMETH_STATE_ABORT /* 接続完了状態 */
76 };
77
78 /*---------------------------------------------------------------------------*
79 * Types/Declarations
80 *---------------------------------------------------------------------------*/
81
82 /**
83 * インスタンス
84 */
85 #define NWMETH_UPPER_NUM 2 /* 上位のレイヤ数 */
86 #define NWMETH_RXFRAME_BUFFUR_COUNT 16 /* 上位へ渡すキューのサイズ */
87 #define NWMETH_STACK_SIZE 4096
88
89 #define NWMETH_PROTOCOL_ENTRY_MAX 16
90
91 typedef struct NWMETHQueuePair
92 {
93 NOSMessageQueue mq; /* 上位用の受信キュー */
94 NOSMessage msg[NWMETH_RXFRAME_BUFFUR_COUNT]; /* 上位用の受信キュー実体 */
95 } NWMETHQueuePair;
96
97 typedef struct NWMETHInstance
98 {
99 NNETInstance netIns; /* 全レイヤ共通に持っているインスタンス情報 */
100 NNETProtocolList protocolList;
101
102 NWMETHQueuePair upper_mq[NWMETH_UPPER_NUM]; /* 上位用の受信キュー */
103 s32 upper_ins_count;
104
105 s32 state;
106
107 u8 macaddr[NNET_ETH_ALEN]; /* 自MACアドレス */
108 u16 pad;
109
110 u8 sendBuf[NNET_MAX_SEND_LEN]; /* 送信バッファ */
111 u8 recvBuf[NNET_MAX_RECV_LEN];
112 NOSThread thread;
113 NOSThreadId threadId;
114 u8 stack[NWMETH_STACK_SIZE];
115
116 } NWMETHInstance;
117
118 /*
119 WCMのインスタンスからNNETInstanceを取得する
120 */
NWMETH_GetNNETInstance(NWMETHInstance * pNwmIns)121 static inline NNETInstance* NWMETH_GetNNETInstance(NWMETHInstance* pNwmIns)
122 {
123 return &pNwmIns->netIns;
124 }
125
126 /*
127 NNETInstanceからWCMのインスタンスを取得する
128 */
NWMETH_GetNWMETHInstance(NNETInstance * pNetIns)129 static inline NWMETHInstance* NWMETH_GetNWMETHInstance(NNETInstance* pNetIns)
130 {
131 return (NWMETHInstance*)pNetIns;
132 }
133
134 /*---------------------------------------------------------------------------*
135 * Function Prototypes
136 *---------------------------------------------------------------------------*/
137 /* nwmeth_Main.cpp */
138 void* NWMETHi_Alloc(u32 name, u32 size, u32 align);
139 void NWMETHi_Free(u32 name, void* ptr);
140
141 s32 NWMETH_Init(const NNETAllocator* allocator);
142 s32 NWMETH_Finish(void);
143 s32 NWMETH_GetMacAddr(NNETInstance* ins, u8* macaddr);
144
145 void NWMETHi_HandleFrame(NWMETHInstance* pNwmIns, NOSMessageBuf* mbuf);
146 void NWMETHi_HandleFrameRaw(NWMETHInstance* pNwmIns, const u8* pFrame, int len);
147
148 /* nwmeth_Direct.cpp */
149 s32 NWMETH_CreateInsDirect(NWMETHInstance** pNwmEth);
150 s32 NWMETH_DestroyInsDirect(NWMETHInstance* pNwmEth);
151 s32 NWMETH_GetUpperDirectAPI(NNETEthernetAPI* pEtherAPI, NWMETHInstance* pNwmEth);
152
153 /* nwmeth_Ipc.cpp */
154 s32 NWMETH_CreateIns(NWMETHInstance** pNwmEth);
155 s32 NWMETH_DestroyIns(NWMETHInstance* pNwmEth);
156 s32 NWMETH_GetUpperAPI(NNETEthernetAPI* pEtherAPI, NWMETHInstance* pNwmEth);
157
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 /* NN_NETWORK_NWMETH_H */
164 #endif
165