1 /*---------------------------------------------------------------------------* 2 Project: MP Data Sharing library 3 File: mpds.h 4 5 Copyright 2006 Nintendo. 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 $Log: mpds.h,v $ 14 Revision 1.6 2007/11/29 03:18:20 seiki_masashi 15 Added the const modifier. 16 17 Revision 1.5 2007/10/24 13:46:41 seiki_masashi 18 Changed so that OSThreadQueue is used during synchronization. 19 20 Revision 1.4 2007/10/22 09:41:57 seiki_masashi 21 Made the MPDSStep function into a synchronous function, and added the new function MPDSTryStep 22 23 Revision 1.3 2007/10/17 12:47:21 seiki_masashi 24 Changed the constants for debug output 25 26 Revision 1.2 2007/10/17 09:37:34 seiki_masashi 27 Added constants for debug output 28 29 Revision 1.1 2007/10/10 08:38:07 seiki_masashi 30 Added the MPDS library 31 32 $NoKeywords: $ 33 *---------------------------------------------------------------------------*/ 34 35 #ifndef REVOLUTION_MPDS_H__ 36 #define REVOLUTION_MPDS_H__ 37 38 #include <revolution/types.h> 39 #include <revolution/mp.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 /*===========================================================================*/ 45 /* Constants */ 46 47 #define MPDS_HEADER_SIZE 4 48 49 #define MPDS_DATA_SIZE 508 // Maximum data size of one WMDataSet (512-4) 50 // MPDS_DATA_SIZE+MPDS_HEADER_SIZE must be a multiple of 32 51 52 #define MPDS_DATASET_NUM 4 // How many MPDSDataSet elements to be kept in MPDSDataSetBuf (fixed value) 53 #define MPDS_CONTEXT_SIZE (sizeof(MPDSContext)) // Buffer size for DataSharing 54 55 typedef enum 56 { 57 MPDS_DEBUG_LEVEL_NONE = 0, 58 MPDS_DEBUG_LEVEL_TRACE = 1, 59 MPDS_DEBUG_LEVEL_REPORT = 2, 60 MPDS_DEBUG_LEVEL_WARNING = 4, 61 MPDS_DEBUG_LEVEL_ERROR = 8, 62 MPDS_DEBUG_LEVEL_DETAIL_AIDBITS = 16 63 } MPDSDebugLevel; 64 65 #define MPDS_DEBUG_LEVEL_DEFAULT (MPDS_DEBUG_LEVEL_WARNING|MPDS_DEBUG_LEVEL_ERROR) 66 67 /*===========================================================================*/ 68 /* Declarations */ 69 70 typedef struct MPDSConfig 71 { 72 u32 dataLength; 73 74 u32 port; 75 u32 priority; 76 77 BOOL isParent; 78 u32 aidBits; 79 BOOL isDoubleMode; 80 81 BOOL isAutoStart; 82 MPPortCallback mpdsCallback; 83 } 84 MPDSConfig; 85 86 typedef struct MPDSDataSet 87 { 88 u16 aidBits; 89 u16 receivedBits; // Receive status 90 u16 data[MPDS_DATA_SIZE / sizeof(u16)]; // Shared data 91 } 92 MPDSDataSet ATTRIBUTE_ALIGN(2); 93 94 typedef struct MPDSContext 95 { 96 MPDSConfig config; 97 98 MPDSDataSet ds[MPDS_DATASET_NUM]; 99 u16 seqNum[MPDS_DATASET_NUM]; // Sequential Number 100 101 u16 writeIndex; // Next Index to write 102 u16 sendIndex; // Index currently being sent 103 u16 readIndex; // Next Index to read 104 105 u16 stationNumber; // Number of devices sharing data (number of bits set to 1 in aidBits) 106 u16 dataSetLength; // dataLength * stationNumber 107 u16 currentSeqNum; // SeqNum of the DataSet read most recently 108 u16 state; // Current DataSharing state (MPDSState) 109 110 u8 padding[2]; 111 112 OSThreadQueue readThreadQueue; // ThreadQueue for controlling synchronous reads 113 MPPortCallbackInfo tmpCallbackInfo;// Work buffer for callbacks 114 115 } 116 MPDSContext; 117 118 119 /*===========================================================================*/ 120 /* Functions */ 121 122 /*---------------------------------------------------------------------------* 123 Name : MPDSInit 124 Description : Configure the initial settings for data sharing 125 Arguments : context - The data sharing context structure 126 config - Data sharing settings 127 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed. 128 *---------------------------------------------------------------------------*/ 129 s32 130 MPDSInit( MPDSContext* context, const MPDSConfig* config ); 131 132 /*---------------------------------------------------------------------------* 133 Name : MPDSSetupPortConfig 134 Description : Configure MP communications for data sharing 135 Arguments : context - The data sharing context structure 136 mpconfig - MP communication settings 137 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed. 138 *---------------------------------------------------------------------------*/ 139 s32 140 MPDSSetupPortConfig( const MPDSContext* context, MPConfig* mpconfig ); 141 142 /*---------------------------------------------------------------------------* 143 Name : MPDSStep 144 Description : Perform data sharing 145 Arguments : context - The data sharing context structure 146 sendData - The data that the local host wants to share next 147 recvDataSet - The data that was shared 148 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed. 149 *---------------------------------------------------------------------------*/ 150 s32 151 MPDSStep( MPDSContext* context, const void* sendData, MPDSDataSet* recvDataSet ); 152 153 /*---------------------------------------------------------------------------* 154 Name : MPDSTryStep 155 Description : Perform data sharing 156 Arguments : context - The data sharing context structure 157 sendData - The data that the local host wants to share next 158 recvDataSet - The data that was shared 159 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed. 160 *---------------------------------------------------------------------------*/ 161 s32 162 MPDSTryStep( MPDSContext* context, const void* sendData, MPDSDataSet* recvDataSet ); 163 164 /*---------------------------------------------------------------------------* 165 Name : MPDSGetData 166 Description : Gets the data that was shared 167 Arguments : context - The data sharing context structure 168 dataSet - a shared data structure 169 aid - the aid of the data to be obtained 170 Returns : u8* - a pointer to the shared data 171 *---------------------------------------------------------------------------*/ 172 const u8* MPDSGetData( const MPDSContext* context, const MPDSDataSet* dataSet, u32 aid ); 173 174 #ifndef NDEBUG 175 /*---------------------------------------------------------------------------* 176 Name : MPDSSetDebugLevel 177 Description : Change the level of debug output. 178 Arguments : level - Debug output type bit to be output 179 Returns : None. 180 *---------------------------------------------------------------------------*/ 181 void MPDSSetDebugLevel( u32 level ); 182 #else 183 #define MPDSSetDebugLevel( level ) ( (void)0 ) 184 #endif 185 186 187 /*===========================================================================*/ 188 #ifdef __cplusplus 189 } 190 #endif 191 #endif /* REVOLUTION_MP_H__ */ 192 193 /*---------------------------------------------------------------------------* 194 End of file 195 *---------------------------------------------------------------------------*/ 196