Hi all,

We used the sdcc 2.7.0 in our project.

There is one problem when we used the "unsigned short" pointers in 
our programs.

If we call the macro defined INW(), the program worked, but when we
called the function defined INW(), the program corrupted.
In addition, the function defined and macro defined INB() both work
normally.
Why does this happen, could anyone explain?

There is the code attached below.
Thanks for your explanation.


/* code is here **************************************************/
/* Table 9-8: device descriptor data structure */
struct usb_device_desc {
        uint8_t  bLength;
        uint8_t  bDescriptorType;
        uint16_t bcdUSB;
        uint8_t  bDeviceClass;
#define USB_CLASS_DEVICE_DEFAULT        0x00
#define USB_CLASS_INTERFACE_HID         0x03
#define USB_CLASS_INTERFACE_CCID        0x04
        uint8_t  bDeviceSubClass;
#define USB_SUBCLASS_DEVICE_DEFAULT     0x00
        uint8_t  bDeviceProtocol;
#define USB_PROTO_DEVICE_DEFAULT        0x00
        uint8_t  bMaxPacketSize0;
        uint16_t idVendor;
        uint16_t idProduct;
        uint16_t bcdDevice;
        uint8_t  iManufacture;
        uint8_t  iProduct;
        uint8_t  iSerialNumber;
        uint8_t  bNumConfigurations;
};

pdata struct usb_device_desc usb_device = {
        sizeof (struct usb_device_desc),        /* bLength */
        USB_DESC_DEVICE,                        /* bDescriptorType */
        USB_VERSION_DEFAULT,                    /* bcdUSB */
        USB_CLASS_DEVICE_DEFAULT,               /* bDeviceClass */
        USB_SUBCLASS_DEVICE_DEFAULT,            /* bDeviceSubClass */
        USB_PROTO_DEVICE_DEFAULT,               /* bDeviceProtocol */
        USB_HW_CTRL_SIZE,                       /* bMaxPacketSize0 */
        USB_VENDOR_ID,                          /* idVendor */
        USB_PRODUCT_ID,                         /* idProduct */
        USB_DEVICE_ID,                          /* bcdDevice */
        USB_STRING_UNSUPPORTED,                 /* iManufacture */
        USB_STRING_UNSUPPORTED,                 /* iProduct */
        USB_STRING_UNSUPPORTED,                 /* iSerialNumber */
        NR_USB_CONFS,                           /* bNumConfigurations */
};

/* This function corrupt when called the function defined USB_INW()
 * But it is worked with the macro defined USB_INW()
 */
static uint16_t usb_test(usb_eid_t eid, uint16_t offset, uint16_t size)
{
        uint16_t count = 0;
        USB_INB(usb_device.bLength);
        USB_INB(usb_device.bDescriptorType);
        USB_INW(usb_device.bcdUSB);
        USB_INB(usb_device.bDeviceClass);
        USB_INB(usb_device.bDeviceSubClass);
        USB_INB(usb_device.bDeviceProtocol);
        USB_INB(usb_device.bMaxPacketSize0);
        USB_INW(usb_device.idVendor);
        USB_INW(usb_device.idProduct);
        USB_INW(usb_device.bcdDevice);
        USB_INB(usb_device.iManufacture);
        USB_INB(usb_device.iProduct);
        USB_INB(usb_device.iSerialNumber);
        USB_INB(usb_device.bNumConfigurations);
        return count;
}

/* defined as macro **************************************************/
#define usb_inb(eid, byte, offset, size, count)         \
        do {                                            \
                if (size >= 1 && count == offset) {     \
                        usb_hw_write_byte(eid, byte);   \
                        uart_putc(byte);                \
                        offset += 1;                    \
                        size -= 1;                      \
                }                                       \
                count += 1;                             \
        } while (0)

#define usb_inw(eid, word, offset, size, count)         \
        do {                                            \
                if (count == offset)                    \
                        usb_inb(eid, LOBYTE(word),      \
                                offset, size, count);   \
                usb_inb(eid, HIBYTE(word),              \
                        offset, size, count);           \
        } while (0)

#define USB_INB(b) usb_inb(eid, b, offset, size, count)
#define USB_INW(w) usb_inw(eid, w, offset, size, count)

/* defined as function ***********************************************/
void usb_inb(usb_eid_t eid, uint8_t byte,
             uint16_t *offset, uint16_t *size, uint16_t *count)
{
        if ((*size) >= 1 && (*count) == (*offset)) {
                usb_hw_write_byte(eid, byte);
                uart_putc(byte);
                (*offset)++;
                (*size)--;
        }
        (*count)++;
}

void usb_inw(usb_eid_t eid, uint16_t word,
             uint16_t *offset, uint16_t *size, uint16_t *count)
{
        if ((*count) == (*offset))
                usb_inb(eid, LOBYTE(word), offset, size, count);
        usb_inb(eid, HIBYTE(word), offset, size, count);
}

#define USB_INB(b) usb_inb(eid, b, offset, size, count)
#define USB_INW(w) usb_inw(eid, w, offset, size, count)

USB_INW(usb_device.bcdUSB);


Best regards.

Li Xiaojun
*******************************************************
Soliton Network Systems (Shanghai)Co.,Ltd.
TEL:021-63183300-5407
FAX:021-63183300-5555
EMAIL: [email protected]
WEBSITE: http://www.soliton.com.cn
*******************************************************

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to