Rev 88 | Rev 100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 88 | Rev 92 | ||
---|---|---|---|
Line 72... | Line 72... | ||
72 | { |
72 | { |
73 | if (WUSB_udev) xxusb_device_close(WUSB_udev); |
73 | if (WUSB_udev) xxusb_device_close(WUSB_udev); |
74 | } |
74 | } |
75 | 75 | ||
76 | 76 | ||
77 |
|
77 | uint32_t fStack[MAXSTACKSIZE]; |
78 | - | ||
- | 78 | uint32_t fStackSize; |
|
79 | 79 | ||
80 | int WIENER_VMUSB_StackInit(){ |
80 | int WIENER_VMUSB_StackInit(){ |
81 | fStack[0]=1; |
81 | fStack[0]=1; |
82 |
|
82 | fStackSize=1; |
83 | return fStack[0]; |
83 | return fStack[0]; |
84 | } |
84 | } |
85 | 85 | ||
86 | void WIENER_VMUSB_StackClear(){ |
86 | void WIENER_VMUSB_StackClear(){ |
87 | WIENER_VMUSB_StackInit(); |
87 | WIENER_VMUSB_StackInit(); |
88 | } |
88 | } |
89 | 89 | ||
90 | int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack){ |
90 | int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack){ |
91 | int i; |
91 | int i; |
- | 92 | uint16_t * u16Stack = (uint16_t *) fStack; |
|
92 | for (i=0;i< |
93 | for (i=0;i< fStackSize*2;i++){ |
93 | if (i<maxn) stack[i]= |
94 | if (i<maxn) stack[i]=u16Stack[i]; else return -1; |
94 | } |
95 | } |
95 | return |
96 | return fStackSize*2; |
96 | } |
97 | } |
97 | 98 | ||
98 | int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack){ |
99 | int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack){ |
99 | int i; |
100 | int i; |
- | 101 | uint16_t * u16Stack = (uint16_t *) fStack; |
|
100 | for (i=0;i< |
102 | for (i=0;i< fStackSize*2;i++){ |
101 | if (i<maxn) stack[i]= |
103 | if (i<maxn) stack[i]=u16Stack[i]; else return -1; |
102 | } |
104 | } |
103 | return |
105 | return fStackSize*2; |
104 | } |
106 | } |
105 | 107 | ||
106 | 108 | ||
107 | int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ){ |
109 | int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ){ |
108 | int i= fStack[0]+1; |
- | |
109 | if ( |
110 | if (fStackSize+2 >= MAXSTACKSIZE) { |
110 | fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", |
111 | fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", fStackSize+2); |
111 | return -1; |
112 | return -1; |
112 | } |
113 | } |
113 | fStack[i] = (cmd & 0xFFFF); |
- | |
114 | fStack[ |
114 | fStack[fStackSize ++] = cmd; |
115 | fStack[ |
115 | fStack[fStackSize ++] = addr; |
116 | fStack[i+3] = (addr >> 16)& 0xFFFF; |
- | |
117 | fStack[0]+=4; |
116 | fStack[0]+=4; |
118 | return fStack[0]; |
117 | return fStack[0]; |
119 | } |
118 | } |
120 | 119 | ||
121 | int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data){ |
120 | int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data){ |
122 |
|
121 | |
123 | WIENER_VMUSB_StackAppend( cmd, addr ); |
122 | WIENER_VMUSB_StackAppend( cmd, addr ); |
124 |
|
123 | |
125 | if ( |
124 | if (fStackSize+1 >= MAXSTACKSIZE) { |
126 | fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", |
125 | fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", fStackSize+1); |
127 | return -1; |
126 | return -1; |
128 | } |
127 | } |
129 | fStack[ |
128 | fStack[fStackSize++] = data; |
130 | fStack[i+1] = (data >> 16)&0xFFFF; |
- | |
131 | fStack[0]+=2; |
129 | fStack[0]+=2; |
132 | return fStack[0]; |
130 | return fStack[0]; |
133 | } |
131 | } |
134 | 132 | ||
135 | void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask){ |
133 | void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask){ |
Line 145... | Line 143... | ||
145 | int i; |
143 | int i; |
146 | for (i=0;i<n;i++) WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data); |
144 | for (i=0;i<n;i++) WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data); |
147 | } |
145 | } |
148 | 146 | ||
149 | void WIENER_VMUSB_StackPrint(){ |
147 | void WIENER_VMUSB_StackPrint(){ |
- | 148 | uint16_t * u16Stack = (uint16_t *) fStack; |
|
150 | uint32_t i; |
149 | uint32_t i; |
151 | for (i=0; i < |
150 | for (i=0; i < fStackSize*2;i++) printf("0x%04x\n",u16Stack[i]); |
152 | printf("size of stack %d __________________________________\n", |
151 | printf("size of stack %d __________________________________\n",fStackSize*2-1); |
153 | } |
152 | } |
154 | 153 | ||
155 | 154 | ||
156 | char wusbcc_stack[MAXSTACKSIZE*4]; |
155 | char wusbcc_stack[MAXSTACKSIZE*4]; |
157 | 156 | ||
158 | 157 | ||
159 | int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack){ |
158 | int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack){ |
160 | int i, nb=0; |
159 | int i, nb=0; |
- | 160 | if (!dev) { |
|
- | 161 | printf("WUSBXX_stack_execute device not open\n"); |
|
161 |
|
162 | return -1; |
- | 163 | } |
|
162 | uint16_t * exstack = (uint16_t *) wusbcc_stack; |
164 | uint16_t * exstack = (uint16_t *) wusbcc_stack; |
163 | exstack[0]=0; |
165 | exstack[0]=0; |
164 | nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] ); |
166 | nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] ); |
165 | //printf("WUSBXX_stack_execute stack size |
167 | //printf("WUSBXX_stack_execute stack size %d\n", nb); |
166 | //WIENER_VMUSB_StackPrint(); |
168 | //WIENER_VMUSB_StackPrint(); |
167 | nb = xxusb_longstack_execute (dev, exstack, nb, 1000); |
169 | nb = xxusb_longstack_execute (dev, exstack, nb, 1000); |
168 | - | ||
169 | - | ||
- | 170 | //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0 |
|
- | 171 | //printf("WUSBXX_stack_execute return size %d\n", nb); |
|
170 | if (nb<0 ) printf("%s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
172 | if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
171 | if (stack!=NULL) for ( i=0;i<nb;i++) stack[i]=wusbcc_stack[i]; |
173 | if (stack!=NULL) for ( i=0;i<nb;i++) stack[i]=wusbcc_stack[i]; |
172 | return nb/sizeof(uint32_t); |
174 | return nb/sizeof(uint32_t); |
173 | } |
175 | } |
174 | 176 | ||
175 | 177 | ||
Line 222... | Line 224... | ||
222 | short __stdcall WIENER_VMUSB_VME_MWRST( void ){ |
224 | short __stdcall WIENER_VMUSB_VME_MWRST( void ){ |
223 | WIENER_VMUSB_StackInit(); |
225 | WIENER_VMUSB_StackInit(); |
224 | return 0; |
226 | return 0; |
225 | } |
227 | } |
226 | short __stdcall WIENER_VMUSB_VME_MWEXEC( void ){ |
228 | short __stdcall WIENER_VMUSB_VME_MWEXEC( void ){ |
227 | WUSBXX_stack_execute (WUSB_udev, NULL); |
229 | return WUSBXX_stack_execute (WUSB_udev, NULL); |
228 | return 0; |
- | |
229 | } |
230 | } |
230 | 231 | ||
231 | short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){ |
232 | short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){ |
232 | switch (DW){ |
233 | switch (DW){ |
233 | case VME_D16: return (short) |
234 | case VME_D16: return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 ); |
234 | case VME_D32: return (short) |
235 | case VME_D32: return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 ); |
235 | default: return 0; |
236 | default: return 0; |
236 | } |
237 | } |
237 | return 0; |
238 | return 0; |
238 | } |
239 | } |
239 | short __stdcall WIENER_VMUSB_VME_MRRST( void ){ |
240 | short __stdcall WIENER_VMUSB_VME_MRRST( void ){ |
240 | WIENER_VMUSB_StackInit(); |
241 | WIENER_VMUSB_StackInit(); |
241 | return 0; |
242 | return 0; |
242 | } |
243 | } |
243 | short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ){ |
244 | short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ){ |
244 | WUSBXX_stack_execute (WUSB_udev,(char *) Data); |
245 | return WUSBXX_stack_execute (WUSB_udev,(char *) Data); |
245 | return 0; |
- | |
246 | } |
246 | } |