<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/2144" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2009-01-21T22:40:34+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/2144</id>

		<entry>
		<author><name><![CDATA[epsilon_da]]></name></author>
		<updated>2009-01-21T22:40:34+02:00</updated>

		<published>2009-01-21T22:40:34+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2144&amp;p=7618#p7618</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2144&amp;p=7618#p7618"/>
		<title type="html"><![CDATA[Transfering more than 255 bytes.]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2144&amp;p=7618#p7618"><![CDATA[
Could it be caused by the differences between the return values of usbFunctionRead and usbFunctionWrite.<br /><br />The first returns the length of the buffer. And the second returns True or False.<br /><br />I can only suspect that for usbFunctionRead there is an &quot;uchar&quot; variable somewhere acumulating the return values of it, and then send to the computer the size of the transmitted buffer.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1412">epsilon_da</a> — Wed Jan 21, 2009 10:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[epsilon_da]]></name></author>
		<updated>2009-01-21T22:27:21+02:00</updated>

		<published>2009-01-21T22:27:21+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2144&amp;p=7617#p7617</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2144&amp;p=7617#p7617"/>
		<title type="html"><![CDATA[Transfering more than 255 bytes.]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2144&amp;p=7617#p7617"><![CDATA[
Hi i need to transfer a big buffer from an ATmega32 to the computer.<br />For that i have redefined &quot;bytesRemaining&quot; variable from uchar to usbWord_t and made some simple changes to usbFunctionWrite and Read.<br /><br />I test this writing 1800 bytes from the computer to the uC memory and reading it again.<br />The writing works perfectly because i turn on a led when the last value in the buffer is equal to what i send.<br />The reading doesnt work at more than 255 bytes.<br />When i try to transfer 1800 bytes (1800=0x708) it only transfers 8 bytes.<br />i think that it is being masked or stored in uchar somewhere in the driver, but the usbFunctionWrite is not.<br /><br />Here is my code:<br /><br /><br /><br /><br /><div class="codebox"><p>Code: </p><pre><code>uchar   usbFunctionWrite&#40;uchar *data, uchar len&#41;<br />&#123;<br />   if&#40;bytesRemaining.word == 0&#41;<br />      return 1;<br />        <br />    if&#40;len &gt; bytesRemaining.word&#41;<br />        len = bytesRemaining.byte&#91;0&#93;;<br /><br />   switch&#40;transferType&#41;&#123;<br />      case USB_HID_CUSTOM_RQ_ADC_BUFFER:<br />         memcpy&#40;nextTransferByte, data, len&#41;;<br />         nextTransferByte += len;<br />         break;<br />      case USB_HID_CUSTOM_RQ_EEPROM:<br />          eeprom_write_block&#40;data, &#40;uchar *&#41;0 + currentAddress, len&#41;;<br />          currentAddress += len;<br />         break;<br />   &#125;<br /><br />    bytesRemaining.word -= len;<br />    return &#40;bytesRemaining.word == 0&#41;; // return 1 if this was the last chunk <br />&#125;</code></pre></div><br /><br /><br /><br /><div class="codebox"><p>Code: </p><pre><code>uchar   usbFunctionRead&#40;uchar *data, uchar len&#41;<br />&#123;<br />   //uchar i;<br /><br />    if&#40;len &gt; bytesRemaining.word&#41;<br />        len = bytesRemaining.byte&#91;0&#93;;<br /><br />   switch&#40;transferType&#41;&#123;<br />      case USB_HID_CUSTOM_RQ_ADC_BUFFER:<br />         memcpy&#40; data , nextTransferByte , len &#41;;<br />         //for &#40;i=0 ; i &lt; len ; i++&#41;&#123;<br />         //   data&#91;i&#93; = nextTransferByte&#91;i&#93;;<br />         //&#125;<br />         nextTransferByte += len;<br />         break;<br />      case USB_HID_CUSTOM_RQ_EEPROM:<br />          eeprom_read_block&#40;data, &#40;uchar *&#41;0 + currentAddress, len&#41;;<br />          currentAddress += len;<br />         break;<br />   &#125;<br /><br />    bytesRemaining.word -= len;<br />    return len;<br />&#125;</code></pre></div><br /><br /><br /><br /><div class="codebox"><p>Code: </p><pre><code>typedef union word&#123;<br />    unsigned    word;<br />    uchar       byte&#91;2&#93;;<br />&#125;word_t;<br /><br />static word_t    bytesRemaining;<br />static uchar   transferType;<br />static uchar    *nextTransferByte;<br />static uchar adcBuffer&#91;ADC_BUFFER_SIZE&#93;;<br /></code></pre></div><br /><br /><br /><br /><br /><div class="codebox"><p>Code: </p><pre><code>usbMsgLen_t usbFunctionSetup&#40;uchar setupData&#91;8&#93;&#41;<br />&#123;<br />   usbRequest_t *rq = &#40;void *&#41;setupData;<br /><br />   switch&#40;rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK&#41;&#123;<br />      case USBRQ_TYPE_CLASS:<br />        // &quot;Class&quot; specific requests <br />         switch&#40;rq-&gt;bRequest&#41;&#123;<br />            case USBRQ_HID_GET_REPORT:<br />               // wValue: ReportType &#40;highbyte&#41;, ReportID &#40;lowbyte&#41; <br />               // we only have one report type, so don't look at wValue <br />               switch&#40;rq-&gt;wIndex.bytes&#91;0&#93;&#41;&#123;<br />                  case USB_HID_CUSTOM_RQ_ADC_BUFFER:<br />                     transferType = USB_HID_CUSTOM_RQ_ADC_BUFFER;<br />                     nextTransferByte = adcBuffer;<br />                     bytesRemaining.word = rq-&gt;wLength.word;<br />                     return USB_NO_MSG;  // use usbFunctionRead&#40;&#41; to send data to the host<br />               &#125;<br />                  // fallback and use usbFunctionRead&#40;&#41; to obtain data <br />            case USBRQ_HID_SET_REPORT:<br />               switch&#40;rq-&gt;wIndex.bytes&#91;0&#93;&#41;&#123;<br />                  case USB_HID_CUSTOM_RQ_ADC_BUFFER:<br />                     transferType = USB_HID_CUSTOM_RQ_ADC_BUFFER;<br />                     nextTransferByte = adcBuffer;<br />                     bytesRemaining.word = rq-&gt;wLength.word;<br />                     return USB_NO_MSG;  // use usbFunctionWrite&#40;&#41; to receive data from host<br /><br />                  case USB_HID_CUSTOM_RQ_START_CONVERTION:<br />                     switch &#40; rq-&gt;wLength.bytes&#91;0&#93; &#41;<br />                        &#123;<br />                        case 0:<br />                           ADCSRA = &#40; ADCSRA_CONFIG | ADC_PRESCALER_0 &#41;;<br />                           break;<br />                        default:<br />                        case 1:<br />                           ADCSRA = &#40; ADCSRA_CONFIG | ADC_PRESCALER_1 &#41;;<br />                           break;<br />                        case 2:<br />                           ADCSRA = &#40; ADCSRA_CONFIG | ADC_PRESCALER_2 &#41;;<br />                           break;<br />                        &#125;<br />                     ADMUX = ADMUX_CONFIG; // Reset ADMUX<br />                     SFIOR &amp;= 0x1F;<br />                     adcBuffer_intr_pointer = adcBuffer;<br />                     adcBuffer_index = 0;<br />                     SBI&#40; ADCSRA , ADEN &#41;;<br />                     SBI&#40; LEDPORT , LED1 &#41;;<br />                        return 0;<br />                  <br /><br />                  case USB_HID_CUSTOM_RQ_EEPROM:<br />                     transferType = USB_HID_CUSTOM_RQ_EEPROM;<br />                        bytesRemaining.byte&#91;0&#93; = rq-&gt;wLength.bytes&#91;0&#93;;<br />                     bytesRemaining.byte&#91;1&#93; = 0;<br />                        currentAddress = 0;<br />                     //currentAddress2 = 0;<br />                        return USB_NO_MSG;  // use usbFunctionWrite&#40;&#41; to receive data from host<br /><br />                  case USB_HID_CUSTOM_RQ_LED:<br />                     LEDPORT = &#40;&#40;rq-&gt;wValue.bytes&#91;0&#93;&lt;&lt;2&#41;&amp; LEDMASK&#41;;<br />                     return 0;<br />               &#125;<br />         &#125;<br />         break;<br />   &#125;<br />   return 0; // default for not implemented requests: return no data back to host <br />&#125;</code></pre></div><br /><br /><br />Is it possible for someone knowing better the driver to check wether only the usbFunctionRead() part is being masked?<br /><br />Or i am missing something in my function?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1412">epsilon_da</a> — Wed Jan 21, 2009 10:27 pm</p><hr />
]]></content>
	</entry>
	</feed>
