📄 device_new.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
};
//------------------------------------------------------------------------------
// high speed configuration descriptor
uint8 code g_hs_cfg_dscr[] =
{
k_usb_cfgdscrsz, // length of descriptor in bytes
k_usb_dscr_typ_config, // descriptor type: configuration
k_usb_cfgdscrsz +
k_usb_ifcdscrsz +
k_usb_ndpdscrsz +
k_usb_ndpdscrsz, // total length lo
0, // total length hi
1, // number of interfaces
0x01, // configuration value
0x00, // index of string descriptor
0xC0, // attributes: self powered, no remote wakeup
0x01, // _max power: 2ma
// 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
};
//------------------------------------------------------------------------------
// other speed configuration descriptor
//------------------------------------------------------------------------------
// full speed other speed configuration descriptor
uint8 code g_fs_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 +
k_usb_ndpdscrsz, // total length lo
0, // total length hi
1, // number of interfaces
0x01, // configuration value
0x00, // index of string descriptor
0xC0, // attributes: self powered, no remote wakeup
0x01, // _max power: 2ma
// 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
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
};
//------------------------------------------------------------------------------
// 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 +
k_usb_ndpdscrsz, // total length lo
0, // total length hi
1, // number of interfaces
0x01, // configuration value
0x00, // index of string descriptor
0xC0, // attributes: self powered, no remote wakeup
0x01, // _max power: 2ma
// 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
};
//------------------------------------------------------------------------------
// globals
uint8 g_ix_dev_thread;
#define g_ix_mscbot_thread g_ix_dev_thread
#define k_ix_ser 0
#define k_sz_ser 26
#define k_ix_vid_lo 26
#define k_ix_vid_hi 27
#define k_ix_pid_lo 28
#define k_ix_pid_hi 29
#define k_ix_lng 30
#define k_sz_lng 4
#define k_ix_mfr 34
#define k_sz_mfr 60
#define k_ix_prd 94
#define k_sz_prd 60
#define k_ix_attr_hi 154
#define k_ix_attr_lh 155
#define k_ix_attr_hl 156
#define k_ix_attr_lo 157
// 158<->251 reserved
// ata0 format signature
#define k_ix_ata0_sig_hi 252
#define k_ix_ata0_sig_lh 253
#define k_ix_ata0_sig_hl 254
#define k_ix_ata0_sig_lo 255
#define k_ata0_sig_hi 0x61 // 'a'
#define k_ata0_sig_lh 0x74 // 't'
#define k_ata0_sig_hl 0x61 // 'a'
#define k_ata0_sig_lo 0x30 // '0'
// locals
// static bit _source_eeprom_raw; // true to source as serial num, false to source as string dscr
static bit _nvram_data_valid;
static bit _nvram_insert_vidpid;
static xdata uint8 _nvram_ix;
static xdata uint16 _nvram_sz;
static bit _serial_number_valid;
//------------------------------------------------------------------------------
// 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:
// dev_exception
//
// Declaration:
// void dev_exception(void);
//
// Purpose:
// Hard error. Log message to trace fifo and halt.
//
// Arguments:
// None.
//
// Return:
// Does not return.No return value.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dev_exception(uint16 ec) reentrant
{
ec=ec; // keep compiler happy for release builds
trace0(0, stk, 0, "** fatal exception **");
trace1(0, stk, 0, " code: %04x", ec);
trace1(0, stk, 0, " thd: %d", g_tid);
thread_halt();
}
//------------------------------------------------------------------------------
// Declaration:
// uint8 dev_rd_most_recent_config(void);
//
// Purpose:
// Report the most recent value set by a "set_configuration" request.
//
// Arguments:
// None.
//
// Return:
// A uint8 representing the most recent usb configuration value.
//------------------------------------------------------------------------------
uint8 dev_rd_most_recent_config() reentrant
{
return _most_recent_config;
}
//------------------------------------------------------------------------------
// Declaration:
// void dev_wr_most_recent_config(uint8 cfg);
//
// Purpose:
// Allow interface managers to clear it before rebooting.
//
// Arguments:
// None.
//
// Return:
// A uint8 representing the most recent usb configuration value.
//------------------------------------------------------------------------------
void dev_wr_most_recent_config(uint8 cfg) reentrant
{
_most_recent_config = cfg;
}
//+-----------------------------------------------------------------------------
// Name:
// dev_initialize
//
// Declaration:
// void dev_initialize(void);
//
// Purpose:
// Called once on POR. initialize device hardware.
//
// Arguments:
// None.
//
// Return:
// None.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
static void dev_initialize(void) reentrant;
static void dev_initialize() reentrant
{
TRACE0(1, dev, 1, "dev_initialize()" );
#ifdef k_mcu_97201
// setup ATA control register. clr muxen to select ATA interface.
_mcu_register_set_bits(x_ata_ctl, kbm_ata_ctl_out_control);
_mcu_register_clr_bits(x_ata_ctl, kbm_ata_ctl_muxen);
// initialize test register so proper phy will be controlled
#ifdef k_rev_c_klsi_phy
XBYTE[0x3F10] = 0x01; // rev C klsi phy
#else
XBYTE[0x3F10] = 0x00; // rev A klsi phy
#endif
#endif
#ifdef k_mcu_97210
#ifdef k_pkg_100
TRACE0(2, dev, 0, "package: 100 pin");
_mcu_register_set_bits( x_fmc_mode_ctl, kbm_fmc_mode_ctl_mux_en );
#endif
#ifdef k_pkg_128
TRACE0(3, dev, 0, "package: 128 pin");
_mcu_register_clr_bits( x_fmc_mode_ctl, kbm_fmc_mode_ctl_mux_en );
#endif
#endif
}
//+-----------------------------------------------------------------------------
// Name:
// dev_power_up
//
// Declaration:
// void dev_power_up(void);
//
// Purpose:
// Called on set-config(1), and resume if configuration is non-zero.
// Power on the flash media sockets as appropriate.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -