# Firmware, did anyone verify hook\_fgv?

**URL:** <https://www.ruby-forum.com/t/firmware-did-anyone-verify-hook-fgv/121369>\
**Category:** GNU Radio\
**Created:** [November 27, 2007, 10:33am UTC](https://www.ruby-forum.com/t/firmware-did-anyone-verify-hook-fgv/121369 "2007-11-27T10:33:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michele\_Bavaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Michele\_Bavaro](https://www.ruby-forum.com/u/Michele_Bavaro)\
**Post date:** [November 27, 2007, 10:33am UTC](https://www.ruby-forum.com/t/firmware-did-anyone-verify-hook-fgv/121369/1 "2007-11-27T10:33:40Z")

</div>

Dear all,  
I modified a little the firmware of a usrp-based device.  
I wanted to check the buffer overrun event on the BULK IN EP2 FIFO, but  
the  
interrupt autovectoring mechanism doesn’t work.  
The following code

static void  
isr\_EP2FULLFLAG (void) interrupt  
{  
clear\_fifo\_gpif\_irq ();

IOD ^= 0x01;

\_usb\_rx\_overrun++;  
}

void install\_handlers (void)  
{  
setup\_descriptors (); // ensure that they’re set before use

hook\_uv (UV\_SUDAV, (WORD) isr\_SUDAV);  
hook\_uv (UV\_USBRESET, (WORD) isr\_USBRESET);  
hook\_uv (UV\_HIGHSPEED, (WORD) isr\_HIGHSPEED);

hook\_fgv (FGV\_EP2FF, (WORD) isr\_EP2FULLFLAG);

SYNCDELAY; EP2FIFOIE = 0x01; /\* The FF on the EP2, which is BULK IN \*/  
SYNCDELAY;  
USBIE = bmSUDAV | bmURES | bmHSGRANT;  
}

I don’t see any changes in the port D bit 0 or \_usb\_rx\_overrun variable,  
even in case of the EP2 overrun, which I can less efficiently verify  
with  
EP2468STAT or EP24FIFOFLGS (and maybe EP2CS as well).  
Any clue? Did someone ever try hook\_fgv?

Regards,  
Mic

---

<div class="post-metadata">

**Author:** ![Michele\_Bavaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Michele\_Bavaro](https://www.ruby-forum.com/u/Michele_Bavaro)\
**Post date:** [December 3, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/firmware-did-anyone-verify-hook-fgv/121369/2 "2007-12-03T17:34:52Z")

</div>

Solved.  
It was my fault, but the source in my opinion is a little misleading.  
Since the USB interrupt autovector had been separated by the GPIF/FIFO  
one  
(likely as a memory optimization during changeset 2452), it is not  
allowed  
to use in hook\_fgv the same vector\_number as in hook\_uv.  
In fact FGV\_MIN, defined as 0x80 in isr.h, is sequential in the unified  
table USB+GPIF/FIFO to the last USB resource interrupt, but should be  
0x0  
when used to indicize the new \_fifo\_gpif\_autovector at address 0x0080.  
Maybe a little update to the firmware should be done, either updating  
FGV\_xxxx values in isr.h, or modifying the hook\_fgv as follows:

/\* begin \*/  
void  
hook\_fgv (unsigned char vector\_number, unsigned short addr)  
{  
bit t;  
BYTE vector\_idx;  
// sanity checks

if (vector\_number \< FGV\_MIN || vector\_number \> FGV\_MAX)  
return;

if ((vector\_number & 0x3) != 0)  
return;

vector\_idx = vector\_number - FGV\_MIN;

t = EA;  
EA = 0;  
\_fifo\_gpif\_autovector[vector\_idx] = LJMP\_OPCODE;  
\_fifo\_gpif\_autovector[vector\_idx + 1] = addr \>\> 8;  
\_fifo\_gpif\_autovector[vector\_idx + 2] = addr & 0xff;  
EA = t;  
}  
/\* end \*/

Comments?

Michele

---

<div class="post-metadata">

**Author:** ![Michele\_Bavaro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Michele\_Bavaro](https://www.ruby-forum.com/u/Michele_Bavaro)\
**Post date:** [December 3, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/firmware-did-anyone-verify-hook-fgv/121369/3 "2007-12-03T18:49:31Z")

</div>

On Mon, Dec 03, 2007 at 05:34:02PM +0100, Michele Bavaro wrote:

> Solved.  
> It was my fault, but the source in my opinion is a little misleading.  
> Since the USB interrupt autovector had been separated by the GPIF/FIFO one  
> (likely as a memory optimization during changeset 2452), it is not allowed  
> to use in hook\_fgv the same vector\_number as in hook\_uv.  
> In fact FGV\_MIN, defined as 0x80 in isr.h, is sequential in the unified  
> table USB+GPIF/FIFO to the last USB resource interrupt, but should be 0x0  
> when used to indicize the new \_fifo\_gpif\_autovector at address 0x0080.  
> Maybe a little update to the firmware should be done, either updating  
> FGV\_xxxx values in isr.h, or modifying the hook\_fgv as follows:

Thanks for finding this problem and suggesting the fixes.

I’ve fixed it in the trunk (r7060) by renumbering FGV\_\* from 0x00.

Eric
