1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - MI - include
3 File: device.h
4
5 Copyright 2007-2008 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 $Date:: 2008-09-17#$
14 $Rev: 8556 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17 #ifndef NITRO_MI_DEVICE_H_
18 #define NITRO_MI_DEVICE_H_
19
20
21 #include <nitro/misc.h>
22 #include <nitro/types.h>
23 #include <nitro/platform.h>
24
25
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30
31
32 /*---------------------------------------------------------------------------*/
33 /* Declarations */
34
35 /* Device Access Function Prototypes */
36 typedef int (*MIDeviceReadFunction)(void *userdata, void *buffer, u32 offset, u32 length);
37 typedef int (*MIDeviceWriteFunction)(void *userdata, const void *buffer, u32 offset, u32 length);
38
39 /* Device Access Structures */
40 typedef struct MIDevice
41 {
42 void *userdata;
43 MIDeviceReadFunction Read;
44 MIDeviceWriteFunction Write;
45 }
46 MIDevice;
47
48
49 /*---------------------------------------------------------------------------*/
50 /* Functions */
51
52 /*---------------------------------------------------------------------------*
53 Name: MI_InitDevice
54
55 Description: Initializes the device.
56
57 Arguments: device The MIDevice structure to be initialized.
58 userdata Arbitrary user-defined argument.
59 read Pointer to device read function.
60 write Pointer to device write function.
61
62 Returns: None.
63 *---------------------------------------------------------------------------*/
64 PLATFORM_ATTRIBUTE_INLINE
MI_InitDevice(MIDevice * device,void * userdata,MIDeviceReadFunction read,MIDeviceWriteFunction write)65 void MI_InitDevice(MIDevice *device, void *userdata,
66 MIDeviceReadFunction read,
67 MIDeviceWriteFunction write)
68 {
69 device->userdata = userdata;
70 device->Read = read;
71 device->Write = write;
72 }
73
74 /*---------------------------------------------------------------------------*
75 Name: MI_ReadDevice
76
77 Description: Reads from the device.
78
79 Arguments: device The MIDevice structure.
80 buffer The transfer target memory.
81 offset The transfer source offset.
82 length The transfer size.
83
84 Returns: Returns a value of 0 or higher if successful; a negative number otherwise.
85 *---------------------------------------------------------------------------*/
86 PLATFORM_ATTRIBUTE_INLINE
MI_ReadDevice(MIDevice * device,void * buffer,u32 offset,u32 length)87 int MI_ReadDevice(MIDevice *device, void *buffer, u32 offset, u32 length)
88 {
89 return device->Read(device->userdata, buffer, offset, length);
90 }
91
92 /*---------------------------------------------------------------------------*
93 Name: MI_WriteDevice
94
95 Description: Writes to the device.
96
97 Arguments: device The MIDevice structure.
98 buffer The transfer source memory.
99 offset The transfer target offset.
100 length The transfer size.
101
102 Returns: Returns a value of 0 or higher if successful; a negative number otherwise.
103 *---------------------------------------------------------------------------*/
104 PLATFORM_ATTRIBUTE_INLINE
MI_WriteDevice(MIDevice * device,const void * buffer,u32 offset,u32 length)105 int MI_WriteDevice(MIDevice *device, const void *buffer, u32 offset, u32 length)
106 {
107 return device->Write(device->userdata, buffer, offset, length);
108 }
109
110
111 /*---------------------------------------------------------------------------*/
112
113
114 #ifdef __cplusplus
115 } /* extern "C" */
116 #endif
117
118
119 #endif /* NITRO_MI_DEVICE_H_ */
120