summaryrefslogtreecommitdiff
path: root/roms/SLOF/slof/fs/usb/usb-storage-support.fs
blob: aa620a412e34bd129d7fde6645ea41283a8ef14d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

s" entered usb-storage-support.fs" usb-debug-print

\ ---------------------------------------------------------------------------
\ Parent methods
\ ---------------------------------------------------------------------------

: rw-endpoint
   ( pt ed-type toggle buffer length mps address -- toggle TRUE | toggle FALSE )
   s" rw-endpoint" $call-parent
   ( toggle TRUE | toggle FALSE )
;

: controlxfer ( dir addr dlen setup-packet MPS ep-fun --- TRUE|FALSE )
   s" controlxfer" $call-parent
   ( TRUE | FALSE )
;

: control-std-get-configuration-descriptor
   ( data-buffer data-len MPS FuncAddr -- TRUE | FALSE )
   s" control-std-get-configuration-descriptor" $call-parent
   ( TRUE | FALSE )
;

: control-std-set-configuration ( configvalue FuncAddr -- TRUE | FALSE )
   s" control-std-set-configuration" $call-parent   ( TRUE | FALSE )
;

: bulk-reset-recovery-procedure ( bulk-out-endp bulk-in-endp usb-addr -- )
  s" bulk-reset-recovery-procedure" $call-parent
;


\ ---------------------------------------------------------------------------
\ Bulk support package methods
\ ---------------------------------------------------------------------------

: build-cbw ( address tag transfer-len direction lun command-len -- )
   s" build-cbw" ihandle-bulk @ $call-method
;

: analyze-csw ( address -- residue tag TRUE | reason FALSE )
   s" analyze-csw" ihandle-bulk @ $call-method
   ( residue tag TRUE | reason FALSE )
;


\ =======================================================
\ NATIVE METHODS USED EITHER AT PROBE TIME OR TIME
\ WHEN INSTANCE IS CREATED
\ =======================================================


\ --------------------------------------------------------
\ COLON DEFINITION: the method is a probe-time method
\ used to:
\ 1. decode the properties and store in variables
\ 2. allocat buffers required for the device and
\ 3. set the right configuration after extracting the
\ configuration descriptor
\ --------------------------------------------------------

: device-init ( -- )
   s" Starting to initialize usb-storage device" usb-debug-print
   s" USB-ADDRESS" get-my-property         ( TRUE | propaddr proplen FALSE )
   IF
      s" not possible" usb-debug-print
   ELSE
      decode-int nip nip to my-usb-address
   THEN
   s" MPS-BULKOUT" get-my-property         ( TRUE | propaddr proplen FALSE )
   IF
      s" not possible"   usb-debug-print
   ELSE
      decode-int nip nip to mps-bulk-out
   THEN
   s" MPS-BULKIN" get-my-property          ( TRUE | propaddr proplen FALSE )
   IF
      s" not possible" usb-debug-print
   ELSE
      decode-int nip nip to mps-bulk-in
   THEN
   s" BULK-IN-EP-ADDR" get-my-property     ( TRUE | propaddr proplen FALSE )
   IF
      s" not possible" usb-debug-print
   ELSE
      decode-int nip nip to bulk-in-ep
   THEN
   s" BULK-OUT-EP-ADDR" get-my-property    ( TRUE | propaddr proplen FALSE )
   IF
      s" not possible"  usb-debug-print
   ELSE
      decode-int nip nip to bulk-out-ep
   THEN
   s" MPS-DCP" get-my-property             ( TRUE | propaddr proplen FALSE )
   IF
      s" Not possible" usb-debug-print
   ELSE
      decode-int nip nip to mps-dcp
   THEN
   s" LUN" get-my-property                 ( TRUE | propaddr proplen FALSE )
   IF
      s" NOT Possible to extract LUN" usb-debug-print
   ELSE
      decode-int nip nip to lun
   THEN
   s" Extracted properties inherited from parent."  usb-debug-print

   dma-buf >cfg-buffer 8 mps-dcp my-usb-address   ( buffer len mps fun-addr )
   control-std-get-configuration-descriptor       ( TRUE | FALSE )
   drop
   s" Configuration descriptor extracted." usb-debug-print
   dma-buf >cfg-buffer 5 + c@ my-usb-address      ( configvalue fun-addr )
   control-std-set-configuration                  ( TRUE | FALSE )
   s" usb-storage: Set config returned: " rot usb-debug-print-val
;


\ ----------------------------------------------------
\ Internal methods
\ ----------------------------------------------------


: (open-package)  ( ihandle-var name-str name-len -- )
   find-package IF                 ( ihandle-var phandle )
      0 0 rot open-package         ( ihandle-var ihandle )
      swap !
   ELSE
      s" Support package not found"  usb-debug-print
   THEN
;

: (close-package)  ( ihandle-var -- )
   dup @ close-package
   0 swap !
;

s" leaving usb-storage-support.fs" usb-debug-print