[long] IR mouse problem

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

[long] IR mouse problem

Post by ksz » Mon Jan 29, 2007 8:55 pm

Hi

I'm trying to build an IR remote controlled mouse (as HID of course)..
For test I've build buttons controlled mouse, it works fine..
On the same hardware (of course with IR receiver connected), and only
makeReport fuction changed in firmware it's not working.

It is programmed with two interrupts to receive IR data:
input capture and output compare.. Input capture interrupt saves times between
edges changes for later decode, and output compare is timeot of avery ir packet
transmition (it is similar to the Usbtiny's IR example project)..
In output compare interrupt the makeReport() is called..

In makeReport(), after decode the ir data, when code:

Code: Select all

   if ( usbInterruptIsReady() ) {
      usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
      DBG1 (0x02, (void*)&reportBuffer, sizeof(reportBuffer));
   }

is used, only one report is debugged (but corsor don't moves)..
It's not ready any more after first report..

In makeReport() the reportBuffer is build as for standard mouse with no wheel:

Code: Select all

/* 0xXX 0xXX 0xXX 0xXX
 *   ^    ^    ^    ^
 *   |    |    |    |
 *   |    |    |    +-- Fourth byte, for mouse's wheel (not used)
 *   |    |    |        0x01 - wheel UP
 *   |    |    |        0xFF - wheel DOWN
 *   |    |    |       
 *   |    |    +------- Y axis (values depends on mouse's speed)
 *   |    |             0x81 .. 0x00 : -127 ..   0 : UP
 *   |    |             0x00 .. 0x7f :    0 .. 127 : DOWN
 *   |    |             
 *   |    +------------ X axis (values depends on mouse's speed)
 *   |                  0x81 .. 0x00 : -127 ..   0 : LEFT
 *   |                  0x00 .. 0x7f :    0 .. 127 : RIGHT
 *   |                 
 *   +----------------- mouse buttons states
 *                      r r r r r W R L, where:
 *                      r - reserved (depends on device type?)
 *                      W - wheel pressed (my mouse's wheel is a button too)
 *                      R - right button
 *                      L - left button
 */

so it's size is three.


Additional info:
I) I'm using three leds to show what is done:
1 - power
2 - IR data receiving
3 - IR code matching, making report
II) As in usbtiny's ir, there is some protection for no conflicts:
1 - when USB transferring, IR data isn't changed in IR interrupts
III) I'm using constant value for cursor's move, by default it's three..


==============================================
==============================================

Debug (makeReport()'s prefix is 0x02):

-------------------------------------------
Buttons controlled device's output:

Code: Select all

(cut device's identification...)
02: 00 fd 00                                                                                                                                               
21: 4b 00 fd 00 ce af                                                                                                                                       
02: 00 fd 00                                                                                                                                               
02: 00 fd 00                                                                                                                                               
21: c3 00 fd 00 ce af                                                                                                                                       
02: 00 fd 00                                                                                                                                               
02: 00 fd 00                                                                                                                                               
21: 4b 00 fd 00 ce af                                                                                                                                       
02: 00 fd 00                                                                                                                                               
02: 00 fd 00                                                                                                                                               
21: c3 00 fd 00 ce af                                                                                                                                       
02: 00 fd 00                                                                                                                                               
02: 00 fd 00                                                                                                                                               
21: 4b 00 fd 00 ce af                                                                                                                                       
02: 00 fd 00                                                                                                                                               
02: 00 fd 00                                                                                                                                               
21: c3 00 fd 00 ce af       
...


The corsor is moving, left/right MB works, everything is OK.

-------------------------------------------
IR control, with no usb functions (no usb functions calls, just debug of reportBuffer):

Code: Select all

(cut device's identification...)
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
ff:
02: 00 00 fd
02: 00 00 fd
ff:
02: 00 00 fd
02: 00 00 fd
02: 00 00 fd
ff:
ff:
10: 69 00 10 01 00 00 40 00
20: 4b 00 00
10: 10 06 00 01 00 00 00 00
20: 4b 12 01 01 01 00 00 00 08 12 36
20: c3 42 42 31 e1 40 00 01 02 75 bf
20: 4b 00 01 3f 8f                                                                                                                                         
ff:                                                                                                                                                         
10: 69 00 10 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 10 05 6d 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 69 6d 70 01 00 00 08 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 70 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 69 6d 70 01 00 00 08 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 70 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 69 6d 70 01 00 00 08 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 70 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 69 00 10 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 10 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 12 01 01 01 00 00 00 08 12 36                                                                                                                       
20: c3 42 42 31 e1 40 00 01 02 75 bf                                                                                                                       
20: 4b 00 01 3f 8f                                                                                                                                         
ff:                                                                                                                                                         
10: 69 00 10 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 10 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 12 01 01 01 00 00 00 08 12 36                                                                                                                       
20: c3 42 42 31 e1 40 00 01 02 75 bf                                                                                                                       
20: 4b 00 01 3f 8f                                                                                                                                         
ff:                                                                                                                                                         
10: 69 00 10 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 10 05 70 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 69 70 20 01 00 00 08 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 20 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 69 70 20 01 00 00 08 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 20 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 69 70 20 01 00 00 08 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 20 06 00 01 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 69 00 10 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
02: 00 00 fd                                                                                                                                               
02: 00 00 fd                                                                                                                                               
02: 00 00 fd                                                                                                                                               
02: 00 00 fd
...


Here it receive's few codes, makes some communication with host, and
disapears from system (e.g not present in usbview).. But codes receiving still
works after that (both ir receive and code match leds blinking)..

Dmesg's output:

Code: Select all

[17198963.364000] ppdev0: registered pardevice
[17198966.564000] ppdev0: unregistered pardevice
[17198966.860000] usb 1-1.1: new low speed USB device using uhci_hcd and address 99
[17198967.468000] usb 1-1.1: configuration #1 chosen from 1 choice
[17198967.680000] input: Krzysiek Szczuka ksz's USB IR Mouse as /class/input/input10
[17198967.680000] input: USB HID v1.01 Mouse [Krzysiek Szczuka ksz's USB IR Mouse] on usb-0000:00:07.2-1.1
[17198970.828000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 99
[17198971.100000] usb 1-1.1: device descriptor read/64, error -71
[17198971.476000] usb 1-1.1: device descriptor read/64, error -71
[17198971.840000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 99
[17198972.164000] usb 1-1.1: device descriptor read/64, error -71
[17198972.588000] usb 1-1.1: device descriptor read/64, error -71
[17198972.952000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 99
[17198972.984000] usb 1-1.1: device descriptor read/8, error -71
[17198973.104000] usb 1-1.1: device descriptor read/8, error -71
[17198973.468000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 99
[17198973.500000] usb 1-1.1: device descriptor read/8, error -71
[17198973.624000] usb 1-1.1: device descriptor read/8, error -71
[17198973.732000] usb 1-1.1: USB disconnect, address 99
[17198973.804000] usb 1-1.1: new low speed USB device using uhci_hcd and address 100
[17198973.940000] usb 1-1.1: device descriptor read/64, error -71
[17198974.176000] usb 1-1.1: device descriptor read/64, error -71
[17198974.352000] usb 1-1.1: new low speed USB device using uhci_hcd and address 101
[17198974.488000] usb 1-1.1: device descriptor read/64, error -71
[17198974.724000] usb 1-1.1: device descriptor read/64, error -71
[17198974.900000] usb 1-1.1: new low speed USB device using uhci_hcd and address 102
[17198974.932000] usb 1-1.1: device descriptor read/8, error -71
[17198975.052000] usb 1-1.1: device descriptor read/8, error -71
[17198975.228000] usb 1-1.1: new low speed USB device using uhci_hcd and address 103
[17198975.260000] usb 1-1.1: device descriptor read/8, error -71
[17198975.380000] usb 1-1.1: device descriptor read/8, error -71



-------------------------------------------
Debug with usb fuctions called:

Code: Select all

(cut device's identification...)
02: 00 00 fd
21: c3 00 00 fd 4f be
ff:
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
ff:
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
ff:
ff:
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
10: 00 10 00 01 00 00 40 00
20: 4b 00 00
10: 00 10 00 01 00 00 40 00
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
ff:                                                                                                                                                         
ff:                                                                                                                                                         
ff:                                                                                                                                                         
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
ff:                                                                                                                                                         
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
10: 00 10 00 01 00 00 40 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
ff:                                                                                                                                                         
10: 00 10 75 00 00 00 00 00                                                                                                                                 
20: 4b 00 00                                                                                                                                               
ff:                                                                                                                                                         
10: 00 10 76 00 00 00 00 00                                                                                                                                 
20: 4b 00 00   


Here it reports one time to host, after that like before: some comunication
with host, disapear from usbview and no ir decode any more (code match
LED not blinking)..

Dmesg's output:

Code: Select all

[17200845.124000] ppdev0: registered pardevice
[17200848.500000] ppdev0: unregistered pardevice
[17200848.804000] usb 1-1.1: new low speed USB device using uhci_hcd and address 119
[17200849.412000] usb 1-1.1: configuration #1 chosen from 1 choice
[17200849.624000] input: Krzysiek Szczuka ksz's USB IR Mouse as /class/input/input24
[17200849.624000] input: USB HID v1.01 Mouse [Krzysiek Szczuka ksz's USB IR Mouse] on usb-0000:00:07.2-1.1
[17200862.484000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 119
[17200862.808000] usb 1-1.1: device descriptor read/64, error -71
[17200863.232000] usb 1-1.1: device descriptor read/64, error -71
[17200863.596000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 119
[17200863.920000] usb 1-1.1: device descriptor read/64, error -71
[17200864.344000] usb 1-1.1: device descriptor read/64, error -71
[17200864.708000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 119
[17200864.740000] usb 1-1.1: device descriptor read/8, error -71
[17200864.860000] usb 1-1.1: device descriptor read/8, error -71
[17200865.224000] usb 1-1.1: reset low speed USB device using uhci_hcd and address 119
[17200865.256000] usb 1-1.1: device descriptor read/8, error -71
[17200865.376000] usb 1-1.1: device descriptor read/8, error -71
[17200865.480000] usb 1-1.1: USB disconnect, address 119
[17200865.556000] usb 1-1.1: new low speed USB device using uhci_hcd and address 120
[17200865.688000] usb 1-1.1: device descriptor read/64, error -71
[17200865.924000] usb 1-1.1: device descriptor read/64, error -71
[17200866.100000] usb 1-1.1: new low speed USB device using uhci_hcd and address 121
[17200866.232000] usb 1-1.1: device descriptor read/64, error -71
[17200866.468000] usb 1-1.1: device descriptor read/64, error -71
[17200866.644000] usb 1-1.1: new low speed USB device using uhci_hcd and address 122
[17200866.676000] usb 1-1.1: device descriptor read/8, error -71
[17200866.796000] usb 1-1.1: device descriptor read/8, error -71
[17200866.972000] usb 1-1.1: new low speed USB device using uhci_hcd and address 123
[17200867.004000] usb 1-1.1: device descriptor read/8, error -71
[17200867.124000] usb 1-1.1: device descriptor read/8, error -71

==============================================
==============================================

Is it possible, that there are no uC's resources for usb's int0, and ir's
interrupts? Is this a source of my problems? Or what?


Please, if any one could help, I'm 'fighting' with it two days, and have
no ideas now...

PS. Sorry for my english (-;

EDIT: and even with code:

Code: Select all

if ( usbInterruptIsReady() ) {
   DBG1 (0x02, (void*)&reportBuffer, sizeof(reportBuffer));
   //usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
}

(usb send commented out) it's not working.. After first packet receive/decode problem is the same:
Debug output OK, but after some communication to host device disapears from usbview with the same dmesg's output..[/b]
Last edited by ksz on Thu Oct 04, 2007 6:04 pm, edited 2 times in total.

ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

additional info

Post by ksz » Wed Jan 31, 2007 1:27 am

After turn debug off and comment out all usb functions usage and even
makeReport function call (there are only IR interrupts working), the problem
still exists.. After few packets from remote, device 'disapears' from usbview,
still IR receive LED blinks..
Is there any time limit for device to response to host?
Device is connected to self powered USB hub, could it be a problem? Hub
'disapears' from usbview for a while too :/ (my standard mouse is connected
to this hub too, and stops for a while too :/ )
Here's dmesg's output:

Code: Select all

...
[17231921.896000] usb 1-1.1: device descriptor read/64, error -71
[17231922.084000] usb 1-1.1: device descriptor read/64, error -71
[17231922.260000] usb 1-1.1: new low speed USB device using uhci_hcd and address 49
[17231922.672000] usb 1-1.1: device not accepting address 49, error -71
[17231922.672000] hub 1-1:1.0: cannot disable port 1 (err = -71)
[17231922.672000] hub 1-1:1.0: cannot reset port 1 (err = -71)
[17231922.672000] hub 1-1:1.0: cannot reset port 1 (err = -71)
[17231922.672000] hub 1-1:1.0: cannot reset port 1 (err = -71)
[17231922.676000] hub 1-1:1.0: cannot reset port 1 (err = -71)
[17231922.676000] hub 1-1:1.0: cannot reset port 1 (err = -71)
[17231922.676000] hub 1-1:1.0: Cannot enable port 1.  Maybe the USB cable is bad?
[17231922.676000] hub 1-1:1.0: cannot disable port 1 (err = -71)
[17231922.676000] hub 1-1:1.0: cannot disable port 1 (err = -71)
[17231922.680000] hub 1-1:1.0: hub_port_status failed (err = -71)
[17231922.680000] hub 1-1:1.0: hub_port_status failed (err = -71)
[17231922.680000] hub 1-1:1.0: hub_port_status failed (err = -71)
[17231922.680000] hub 1-1:1.0: hub_port_status failed (err = -71)
[17231922.680000] hub 1-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
[17231922.680000] usb 1-1: USB disconnect, address 46
[17231922.796000] usb 1-1: new full speed USB device using uhci_hcd and address 51
[17231922.956000] usb 1-1: configuration #1 chosen from 1 choice
[17231922.960000] hub 1-1:1.0: USB hub found
[17231922.960000] hub 1-1:1.0: 4 ports detected
[17231923.276000] usb 1-1.1: new low speed USB device using uhci_hcd and address 52
[17231923.360000] usb 1-1.1: device descriptor read/64, error -71
[17231923.548000] usb 1-1.1: device descriptor read/64, error -71
[17231923.724000] usb 1-1.1: new low speed USB device using uhci_hcd and address 53
[17231923.808000] usb 1-1.1: device descriptor read/64, error -71
[17231923.996000] usb 1-1.1: device descriptor read/64, error -71
[17231924.172000] usb 1-1.1: new low speed USB device using uhci_hcd and address 54
[17231924.584000] usb 1-1.1: device not accepting address 54, error -71
[17231924.656000] usb 1-1.1: new low speed USB device using uhci_hcd and address 55
[17231925.068000] usb 1-1.1: device not accepting address 55, error -71
[17231925.272000] usb 1-1.3: new low speed USB device using uhci_hcd and address 56
[17231925.412000] usb 1-1.3: configuration #1 chosen from 1 choice
...


Here are my IR interrupts:

Code: Select all

// ----------------------------------------------------------------------
// Handler for timer1 input capture interrupt: edge on IR input
ISR(TIMER1_CAPT_vect)
{
   static   uint_t   prev;
   uint_t      stamp;
   byte_t      delta;

   stamp = ICR1;         // get time stamp
   TIMSK = 0;            // disable both IR interrupts
   TCCR1B ^= _BV(ICES1);   // toggle edge detector
   LED_IR_ON;            // switch IR LED on
   
   delta = calcIRTime(stamp - prev);
   asm volatile("" : : "r"(delta) );   // calculate delta (gcc-4.1.0)

   prev  = stamp;
   OCR1A = stamp + 12L * TIMEOUT / 8;   // update timeout value
   if   ( edges != 0xff )      // packet should not be ignored?
   {
      if   ( inpos == 0xff )   // update ir only when USB idle
      {
         ir.length = 0;      // discard previous packet
         if   ( edges > 0 )
         {
            ir.data[edges - 1] = delta;
         }
      }
      ++edges;
   }

   TIMSK = _BV(OCIE1A) | _BV(TICIE1);   // reenable IR interrupts
}

// ----------------------------------------------------------------------
// Handler for timer1 output compare A interrupt: IR transmission timeout
// ----------------------------------------------------------------------
ISR(TIMER1_COMPA_vect)
{
   TIMSK = 0;            // disable both IR interrupts
   LED_IR_OFF;            // switch LED off
   if   (  edges >= 40      //
      && edges != 0xff   // packet should not be ignored
      && inpos == 0xff   // update ir only when USB idle
      )
   {
      ir.count++;
      ir.length = edges - 1;      // new packet is complete
   }
   edges = 0;
   TCCR1B &= ~_BV(ICES1);         // reset to negative edge
   TIMSK = _BV(OCIE1A) | _BV(TICIE1);   // reenable IR interrupts
}

Help, please!
Last edited by ksz on Thu Oct 04, 2007 6:05 pm, edited 1 time in total.

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Post by Grendel » Wed Jan 31, 2007 2:01 am

Skimming over your posts, how high are your IR interrupt frequencies ? It looks like your IRQ handler blocks further interrupts -- AVR-USB is very sensitive to IRQ latency, keep in mind there's a SOF packet sent by the host every 1ms (!):

usbdrv.h wrote:Interrupt latency:
The application must ensure that the USB interrupt is not disabled for more than 20 cycles. This implies that all interrupt routines must either be eclared as "INTERRUPT" instead of "SIGNAL" (see "avr/signal.h") or that hey are written in assembler with "sei" as the first instruction.

Maximum interrupt duration / CPU cycle consumption:
The driver handles all USB communication during the interrupt service routine. The routine will not return before an entire USB message is received and the reply is sent. This may be up to ca. 1200 cycles = 100us if the host conforms to the standard. The driver will consume CPU cycles for all USB messages, even if they address another (low-speed) device on the same bus.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Wed Jan 31, 2007 4:36 pm

You must make sure that your interrupt service routines can be interrupted by the USB interrupt. Timing is VERY critical for AVR-USB, the interrupt handler must be called with only a couple of cycles latency.

ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

Post by ksz » Thu Feb 08, 2007 5:24 pm

christian wrote:You must make sure that your interrupt service routines can be interrupted by the USB interrupt. Timing is VERY critical for AVR-USB, the interrupt handler must be called with only a couple of cycles latency.


First of all, sorry for delayed response, couldn't do it earlier..
How can it be done? by sei() in my interrupt routines?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Feb 09, 2007 7:40 pm

Putting a sei() into your ISR is too late. You must use

__attribute__ ((interrupt))

instead of

__attribute__ ((signal))

for your ISR. Don't know how the appropriate macro has been renamed in recent versions of AVR-Libc.

Please note that this may cause problems if the interrupt-pending flag must be cleared by software. That would cause an infinite interrupt loop. You'd have to go down to assembler to handle this case correctly, I'm afraid.

ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

Post by ksz » Sat Feb 10, 2007 4:01 am

christian wrote:Putting a sei() into your ISR is too late. You must use

__attribute__ ((interrupt))

instead of

__attribute__ ((signal))

for your ISR. Don't know how the appropriate macro has been renamed in recent versions of AVR-Libc.


it is __attribute__ ((interrupt))..
This (instead of ISR() ) don't change anything after recompile/reprogram:

Code: Select all

__attribute__((interrupt))
extern   void   SIG_OUTPUT_COMPARE1A ( void )
{...


christian wrote:Please note that this may cause problems if the interrupt-pending flag must be cleared by software. That would cause an infinite interrupt loop. You'd have to go down to assembler to handle this case correctly, I'm afraid.


So should I rewrite my interrupt routines to ASM with sei as first instruction? Will it work then?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Sun Feb 11, 2007 1:18 pm

If "__attribute__ ((interrupt))" does not change anything, I'd be suspicious. Try to compile the module with the "-S" option to gcc. this will print the assembler source code. Then look at the code where the sei() instruction is. If it's among the first instructions of the ISR, it's OK and the problem must be somewhere else.

ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

Post by ksz » Sun Feb 11, 2007 11:07 pm

christian wrote:If "__attribute__ ((interrupt))" does not change anything, I'd be suspicious. Try to compile the module with the "-S" option to gcc. this will print the assembler source code. Then look at the code where the sei() instruction is. If it's among the first instructions of the ISR, it's OK and the problem must be somewhere else.


sei is first :|

Code: Select all

__vector_5:
/* prologue: frame size=0 */
/* prologue: naked */
/* prologue end (size=0) */
/* #APP */
   sei
/* #NOAPP */
   ...

Code: Select all

__vector_6:
/* prologue: frame size=0 */
   sei
   ...


So where is the problem..? My code..? What else can I do to find it?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Sun Feb 11, 2007 11:49 pm

I'm not sure the code for vector 5 is OK. The SEI as a first instruction is inserted manually ("#APP" and "#NOAPP" framing) and the compiler comments that the function is "naked". That would indicate that no PUSH instructions have been emitted as it would be appropriate for an ISR.

Vector 6, on the other hand, is probably OK. You did not include the PUSH instructions, but since everything was compiler-generated, the pushes should be OK.

ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

Post by ksz » Mon Feb 12, 2007 1:41 am

christian wrote:I'm not sure the code for vector 5 is OK. The SEI as a first instruction is inserted manually ("#APP" and "#NOAPP" framing) and the compiler comments that the function is "naked". That would indicate that no PUSH instructions have been emitted as it would be appropriate for an ISR.

Vector 6, on the other hand, is probably OK. You did not include the PUSH instructions, but since everything was compiler-generated, the pushes should be OK.


My mistake, sorry..
Now no manually added sei() in ISR's and no naked interrupts..
Here are compiler generated vectors:

Code: Select all

   .global   __vector_5
   .type   __vector_5, @function
__vector_5:
/* prologue: frame size=0 */
   sei
   push __zero_reg__
   push __tmp_reg__
   in __tmp_reg__,__SREG__
   push __tmp_reg__
   clr __zero_reg__
   push r18
   push r19
   ...
   
   .global   __vector_6
   .type   __vector_6, @function
__vector_6:
/* prologue: frame size=0 */
   sei
   push __zero_reg__
   push __tmp_reg__
   in __tmp_reg__,__SREG__
   push __tmp_reg__
   clr __zero_reg__
   push r18
   ...

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Mon Feb 12, 2007 11:21 am

And... does it change anything?

ksz
Rank 1
Rank 1
Posts: 26
Joined: Tue Jan 09, 2007 9:10 pm
Location: Poland

Post by ksz » Mon Feb 12, 2007 2:25 pm

no..
Still after few packets from remote the device 'disapears' from usbview, here's some of debug now (as you can see, there are some strange otputs, eg.:
10: 00 002: 01 00 00, this 002: is my 02: prefix..)

Code: Select all

...
5 27 00 04 0d 00 09 f6
10: 00 002: 01 00 00
5 27 00 04 0d 00 09 f6
10: 00 002: 01 00 00
5 27 00 04 0d 00 09 f6
ff:
10: 00 002: 01 00 00
5 27 00 04 0d 00 09 f6
10: 00 002: 01 00 00
5 28 00 05 0d 00 0a 76 0d
10: 00 002: 01 00 00
5 28 00 04 0d 00 09 76
10: 00 002: 01 00 00
5 28 00 04 0d 00 09 76
ff:
10: 80 06 00 00 06 0d 00 0b 6e ca fd
20: 4b 00 00
ff:
ff:
10: 00 05 2c 00 06 0d 00 0b 76 0d 00
20: 4b 00 00
ff:
10: 00 002: 00 00 fd
5 2c 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 2c 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 2c 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 2c 00 04 0d 00 09 a0
ff:
10: 00 05 31 00 06 0d 00 0b f7 0d 00
20: 4b 00 00
10: 05 302: 00 00 fd
1 00 05 0e 00 09 a0 0e
10: 00 002: 00 00 fd
5 31 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 31 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 31 00 05 0d 00 0a a0 0d
ff:
10: 00 002: 00 00 fd
5 31 00 05 0d 00 0a a0 0d
10: 00 002: 00 00 fd
5 31 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 31 00 04 0d 00 09 a0
ff:
10: 00 05 36 00 06 0d 00 0b 77 0d 00
20: 4b 00 00
10: 00 05 36 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 36 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 36 00 04 0d 00 09 a0
10: 05 302: 00 00 fd
6 00 05 0e 00 09 a0 0e
ff:
10: 00 002: 00 00 fd
5 36 00 04 0d 00 09 a0
10: 00 002: 00 00 fd
5 36 00 04 0d 00 09 a0
...


And here with no IR transmition:

Code: Select all

...
ff:
10: 00 05 3b 00 06 0d 00 0b f7 0d 00
20: 4b 00 00
ff:
ff:
10: 00 05 40 00 06 0d 00 0b 72 0d 00
20: 4b 00 00
ff:
ff:
10: 00 05 45 00 06 0d 00 0b f2 0d 00
20: 4b 00 00
ff:
ff:
10: 00 05 4a 00 06 0d 00 0b 72 0d 00
20: 4b 00 00
ff:


And again my USB HUB hangs (mouse stops:), after disconnect of my 'IRmouse' hub works normally, mouse is usable..
(Sometimes hub hangs for good, only disconnect of my device helps, somatimes hangs for a while, turning IRmouse off and works fine.. This debug output is for long hang of whole hub..)

Arghhh..!
I think I'll make it on two attinys: one for IR, one for USB..
Or, Christian, are there some other solutions..?

Any way, thanks a lot for patience and help!

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Mon Feb 12, 2007 8:15 pm

The debug logs look as if you would do logging from the IR interrupt handler (one line of log is inserted into the middle of another line). You should NEVER do time consuming things like debug logging from an ISR. That causes all kinds of problems.

You must do something in your ISR or main code which confuses the USB driver. The most likely thing is that you disable interrupts for too long, maybe implicitly by calling a library routine.

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Post by Grendel » Tue Feb 13, 2007 11:42 pm

.bss segment crossing a 256b page boundary maybe ?

Post Reply