Q2. Please assume that you have to design a common driver, which can detect the device mounted to the host.
The mounted device could be developed by different vendors but they all follow the same header format.
For example, the device header could be like this:
| Vendor ID [16-Bit, Little Endian] | Device ID [16-Bit, Little Endian] | Capabilities [32-bit] |
Capabilites:
bit 0: 0'b-disabled, 1'b-enabled
bit 1-3: Speed mode
bit 4: 0'b-FIFO transfer, 1'b-DMA transfer
bit 5-15: Reserved.
bit 16: 0'b-interrupt mode, 1'b-polling mode
bit 17-31: Reserved
design requirements:
1. Create a device table [could be array or linkedlist] to contain information of all supported devices e.g.
DevA: vendor-id: 0x2C00, device-id:0x0x30C0, support_flag: 0x201
DevB: vendor-id: 0x2C00, device-id:0x0x45F0, support_flag: 0x301
DevC: vendor-id: 0x9C00, device-id:0x0x2000, support_flag: 0x401
2. Each probable device needs to register a callback function to do init task. The function prototype could be:
int device_init(int flag);
3. Assume that we have had a dev_read() to read a header from the bus/device. Please write a scan function
to go throuth the table and find the match one. Then call its init callback.
BUG-FREE is not required, just simply show your idea in C