📄 device.c
字号:
0, // alternate interface
2, // number of endpoints
0x08, // usb interface class: mass storage
0x06, // usb interface subclass: scsi
0x50, // interface protocol: BOT (bulk only transport)
0x00, // interface string index
// endpoint descriptor: bulk out
k_usb_ndpdscrsz, // length of descriptor in bytes
0x05, // descriptor type: endpoint
0x02, // endpoint 2, out
0x02, // bulk
k_fs_maxpktsz, // max packet size lo
0x00, // max packet size hi
0x01, // polling interval
// endpoint descriptor: bulk in
k_usb_ndpdscrsz, // length of descriptor in bytes
0x05, // descriptor type: endpoint
0x82, // endpoint 2, in
0x02, // bulk
k_fs_maxpktsz, // max packet size lo
0x00, // max packet size hi
0x00, // polling interval
// dfu functional descriptor
k_dfu_funcdscrsz, // length of descriptor in bytes
k_dfu_dscr_typ_functional, // dfu functional descriptor type
0x07, // manifest, upload, dnload tolerant
_l(k_dfu_detach_timeout), // detach timeout lo
_h(k_dfu_detach_timeout), // detach timeout hi
_l(k_dfu_max_xfer_sz), // max transfer size lo
_h(k_dfu_max_xfer_sz) // max transfer size hi
};
//------------------------------------------------------------------------------
// high speed other speed configuration descriptor
uint8 code g_hs_oscfg_dscr[] =
{
k_usb_cfgdscrsz, // length of descriptor in bytes
k_usb_dscr_typ_osconfig, // descriptor type: other speed configuration
k_usb_cfgdscrsz +
k_usb_ifcdscrsz +
k_usb_ndpdscrsz +
#ifdef k_append_dfu_dscr
k_usb_ndpdscrsz +
k_dfu_funcdscrsz, // total length lo
#else
k_usb_ndpdscrsz, // total length lo
#endif
0, // total length hi
1, // number of interfaces
0x01, // configuration value
0x00, // index of string descriptor
0x80, // attributes: bus powered, no remote wakeup
// 0xFA, // max power: 500ma
0x31, // max power: 98ma
// interface descriptor: BOT mass storage
k_usb_ifcdscrsz, // length of descriptor in bytes
k_usb_dscr_typ_interface, // descriptor type: interface
0, // interface number
0, // alternate interface
2, // number of endpoints
0x08, // usb interface class: mass storage
0x06, // usb interface subclass: scsi
0x50, // interface protocol: BOT (bulk only transport)
0x00, // interface string index
// endpoint descriptor: bulk out
k_usb_ndpdscrsz, // length of descriptor in bytes
0x05, // descriptor type: endpoint
0x02, // endpoint 2, out
0x02, // bulk
_l(k_hs_maxpktsz), // max packet size lo
_h(k_hs_maxpktsz), // max packet size hi
0x01, // polling interval
// endpoint descriptor: bulk in
k_usb_ndpdscrsz, // length of descriptor in bytes
0x05, // descriptor type: endpoint
0x82, // endpoint 2, in
0x02, // bulk
_l(k_hs_maxpktsz), // max packet size lo
_h(k_hs_maxpktsz), // max packet size hi
0x00, // polling interval
// dfu functional descriptor
k_dfu_funcdscrsz, // length of descriptor in bytes
k_dfu_dscr_typ_functional, // dfu functional descriptor type
0x07, // manifest, upload, dnload tolerant
_l(k_dfu_detach_timeout), // detach timeout lo
_h(k_dfu_detach_timeout), // detach timeout hi
_l(k_dfu_max_xfer_sz), // max transfer size lo
_h(k_dfu_max_xfer_sz) // max transfer size hi
};
//------------------------------------------------------------------------------
// globals
uint8 g_ix_dev_thread;
#define g_ix_mscbot_thread g_ix_dev_thread
#define k_counts_per_sec 100
//------------------------------------------------------------------------------
// nvstore ghost values
xdata uint8 g_inq_vid[k_sz_inq_vid];
xdata uint8 g_inq_pid_hdr[k_sz_inq_pid_hdr];
//variables to store these custom values
uint8 g_blink_interval;
static uint8 _blink_counter;
//just a temp storage so that we will remember the value
xdata uint8 g_nvstore_post_access_blink_secs;
uint8 g_post_access_blink_secs; //in seconds
bit g_activity_led_idle_bright = k_true;
static uint8 _seconds_counter;
// attribute & global attribute flags
uint8 xdata g_dev_attr_lo;
// uint8 xdata g_dev_attr_hl;
// uint8 xdata g_dev_attr_lh;
// uint8 xdata g_dev_attr_hi;
// locals
static bit _nvstore_data_valid;
static bit _nvstore_insert_vidpid;
static bit _nvstore_insert_bmattrib_and_maxpwr;
static bit _serial_number_valid;
// cannot be located in k_ram_base to k_ram_base+k_flash_sector_sz range.
static xdata uint8 _nvstore_ix _at_ 0x4000;
static xdata uint16 _nvstore_sz _at_ 0x4001;
static void dev_sd_poller(void) reentrant;
#define k_sd_poll_interval 65000
static xdata uint16 _sd_poll_counter = k_sd_poll_interval;
//------------------------------------------------------------------------------
// must store a copy of config so it can be checked after the usbrst arrives
// since on the 20x family the configuration is cleared by hardware.
static uint8 _most_recent_config = 0;
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
// None.
//
// Notes:
// It is safe to call this function from interrupt handlers.
//
// Since:
// fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_indicate_bus_speed() reentrant
{
// be sure to validate the nvstore before calling this
if (g_dev_attr_lo & kbm_attr_lo_gpio5_as_sd_insert)
{
gpio_bit_is_input(5);
return;
}
gpio_bit_is_output(5);
if (sie_is_high_speed())
gpio_setbit(5);
else
gpio_clrbit(5);
}
// these functions must be callable from interupt service routines
#pragma NOAREGS
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
// None.
//
// Notes:
// It is safe to call this function from interrupt handlers.
// Call during initialization so the direction bits will be correct.
//
// Since:
// fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_turn_off_activity_indicator() reentrant
{
#ifdef k_mcu_97210
gpio_bit_is_output(0);
#endif
#ifdef k_mcu_97211
gpio_bit_is_output(0);
gpio_bit_is_output(1);
#endif
#ifdef k_mcu_97223
gpio_bit_is_output(1);
#endif
#ifdef k_mcu_97242
gpio_bit_is_output(1);
#endif
// no activity, return the led to its idle state as defined in the nvstore
if (g_activity_led_idle_bright)
{
// turn on the led
#ifdef k_mcu_97210
gpio_setbit(0);
#endif
#ifdef k_mcu_97211
gpio_setbit(0);
gpio_setbit(1);
#endif
#ifdef k_mcu_97223
gpio_setbit(1);
#endif
#ifdef k_mcu_97242
gpio_setbit(1);
#endif
}
else // idle dim
{
// turn off the led
#ifdef k_mcu_97210
gpio_clrbit(0);
#endif
#ifdef k_mcu_97211
gpio_clrbit(0);
gpio_clrbit(1);
#endif
#ifdef k_mcu_97223
gpio_clrbit(1);
#endif
#ifdef k_mcu_97242
gpio_clrbit(1);
#endif
}
}
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
// None.
//
// Notes:
// It is safe to call this function from interrupt handlers.
//
// Since:
// fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_toggle_activity_indicator() reentrant
{
#ifdef k_mcu_97210
gpio_togglebit(0);
#endif
#ifdef k_mcu_97211
gpio_togglebit(0);
gpio_togglebit(1);
#endif
#ifdef k_mcu_97223
gpio_togglebit(1);
#endif
#ifdef k_mcu_97242
gpio_togglebit(1);
#endif
}
#pragma AREGS
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
// None.
//
// Notes:
//
// Since:
// fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_gpio_power_down() reentrant
{
// turn off all power to cards, indicator leds, etc
if (g_dev_attr_lo & kbm_attr_lo_activity_led_gpio_hi_on_spd)
{
trace0(0, dev, 0, "setting the activity led gpio");
//drive the gpio high
#ifdef k_mcu_97210
gpio_setbit(0);
#endif
#ifdef k_mcu_97211
gpio_setbit(0);
gpio_setbit(1);
#endif
#ifdef k_mcu_97223
gpio_setbit(1);
#endif
#ifdef k_mcu_97242
gpio_setbit(1);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -