📄 fmcdev.c
字号:
eeprom_write(i++, k_serial_num_str_pfm[j]) ;
}
for(j=0;j<3;j++)
{
eeprom_write(i++, k_serial_num_str_evb[j]) ;
}
eeprom_write(i++, '#') ;
eeprom_write(i++, '#') ;
eeprom_write(i++, '0') ;
eeprom_write(i++, '#') ;
// stop writing
eeprom_write_disable() ;
mcu_end_critical_section();
trace0(0, eeprom, 0, "** dumping serial number **") ;
length = eeprom_read(0) ;
trace1(0, eeprom, 0, "** eeprom contains %d bytes **", length) ;
for(i=0;i<length;i++)
{
eetemp = eeprom_read(i+1) ;
TRACE2(415, ata, 0, "sn[%d]: '%c'", i, eetemp) ;
}
}
//------------------------------------------------------------------------------
// <<< DEVICE - MANAGER >>>
// Target MCU:
// FDC, 102, 200
// Declaration:
// uint8 dev_mngr(t_message *msgp);
// Purpose:
// This is the manager for all things related to the whole device.
// Arguments:
// None.
// Return:
// k_success
// K-error
// Note:
// Do NOT yield from this routine. It is NOT part of any thread. It does
// not execute in an any thread's context. Yielding from within this function
// will cause your firmware to crash.
//------------------------------------------------------------------------------
uint8 dev_mngr(t_message *msgp) reentrant
{
trace0(0, dev, 0, "dev_mngr()");
switch (message_rd_id(msgp))
{
case k_msg_initialize:
trace0(0, dev, 0, "k_msg_initialize");
// initialize gpios
// initialize the hardware
// x_gpioa_out = kbm_msk_gpioa_out_unconfigured;
// x_gpioa_dir = kbm_msk_gpioa_dir_unconfigured;
// create threads - no device specific threads required
// register endpoints - do nothing here, the interface managers will handle it
// register interfaces - do nothing here, the interface managers will handle it
// initialize the application specific interface managers
fmcapp_mngr(msgp);
// exit, stage left
return k_success;
case k_msg_kill:
trace0(0, dev, 0, "k_msg_kill");
// terminate this manager
//TBD
// propagate the message to the application specific interface managers
fmcapp_mngr(msgp);
// dfu_mngr(msgp);
return k_success;
case k_msg_usbrst:
trace0(0, dev, 0, "k_msg_usbrst");
// configured -> unconfigured (same as set config 0 in ctl_cpex.c)
// config the gpios
// x_gpioa_out = kbm_msk_gpioa_out_unconfigured;
// x_gpioa_dir = kbm_msk_gpioa_dir_unconfigured;
// propagate the message to the application specific interface managers
fmcapp_mngr(msgp);
// dfu_mngr(msgp);
return k_success;
case k_msg_resume:
TRACE0(416, fmcdev, 0, "k_msg_resume");
// process the usb resume notificaion
// config the gpios
// x_gpioa_out = kbm_msk_gpioa_out_resumed;
// x_gpioa_dir = kbm_msk_gpioa_dir_resumed;
// propagate the message to the application specific interface managers
fmcapp_mngr(msgp);
TRACE0(417, fmcdev, 0, "Device resumed") ;
return k_success;
case k_msg_suspend:
TRACE0(418, fmcdev, 0, "k_msg_suspend");
// process the usb suspend notificaion
// propagate the message to the application specific interface managers
fmcapp_mngr(msgp);
TRACE0(419, fmcdev, 0, "Device suspended") ;
return k_success;
default:
TRACE0(420, fmcdev, 0, "error: dev_mngr(unexpected message)");
// unexpected message
return k_error;
}
// unexpected message
return k_error;
}
//------------------------------------------------------------------------------
// <<< DEVICE - CONTROL PIPE EXTENSION >>>
// Target MCU:
// FDC, 102, 200
// Declaration:
// uint8 dev_cpex(t_message *msgp);
// Purpose:
// Handles requests targeted to the device: standard, class, vendor.
// Arguments:
// None.
// Return:
// k_success - Causes the protocol engine to complete the status stage successfully.
// k_error - Causes the protocol engine to stall the control pipe.
// k_in_progress - For k_msg_source_payload, causes the protocol engine to deliver
// another empty packet buffer to the cpex to be loaded for transmission.
// For k_msg_sink_payload, informs the protocol engine that the cpex expects at
// least one more payload buffer to be delivered to it by the protocol engine.
// k_finished - For k_msg_source_payload and k_msg_sink_payload, informs the
// protocol engine that the data phase is complete and no more data is expected
// in either direction.
// Note:
// Do NOT yield from this routine. It is part of the protocol engine's thread.
// It executes in the context of g_ix_ctl_thread. Yielding from within this
// function will cause the protocol engine's state machine to float belly up.
// And that will cause your firmware to shuffle off this mortal coil, post haste.
//------------------------------------------------------------------------------
uint8 dev_cpex(t_message *msgp) reentrant
{
uint8 pktsz;
uint8 pnr;
t_usb_rqst *rqstp;
trace1(0, dev, 0, "dev_cpex(msg:%04X)", message_rd_id(msgp));
rqstp = (t_usb_rqst *)(message_rd_arg(msgp));
switch (message_rd_id(msgp))
{
case k_dsd_usb_get_descriptor:
g_wtmp = rqstp->wLengthHi;
g_wtmp *= 256;
g_wtmp += (uint16)rqstp->wLengthLo;
trace3(0, dev, 0, "wLengthHi:%02X wLengthLo:%02X wtmp:%d", rqstp->wLengthHi, rqstp->wLengthLo, g_wtmp);
switch (rqstp->wValueHi)
{
case k_usb_dscr_typ_device:
trace0(0, dev, 0, "RQ_GET_DESCRIPTOR: device");
// tell the data pump where to find it and how much there is
#ifdef k_20x_family
#ifdef k_support_eeprom
trace0(0, dev, 0, "device reports a serial number, send correct descriptor") ;
trace1(0, dev, 0, "x_sie_conf:%02X",x_sie_conf);
if ((x_sie_conf & kbm_sie_conf_hspeed))
{
_payload_source(&g_hs_dev_dscr_w_ser, _min(g_hs_dev_dscr_w_ser[0], g_wtmp));
} else
{
_payload_source(&g_fs_dev_dscr_w_ser, _min(g_fs_dev_dscr_w_ser[0], g_wtmp));
}
#else // no eeprom support
trace0(0, dev, 0, "device did not report a serial number. non specified")
trace1(0, dev, 0, "x_sie_conf:%02X",x_sie_conf);
if ((x_sie_conf & kbm_sie_conf_hspeed))
{
_payload_source(&g_hs_dev_dscr, _min(g_hs_dev_dscr[0], g_wtmp));
} else
{
_payload_source(&g_fs_dev_dscr, _min(g_fs_dev_dscr[0], g_wtmp));
}
#endif // k_support_eeprom
#else
_payload_source(&g_fs_dev_dscr, _min(g_fs_dev_dscr[0], g_wtmp));
#endif
break;
case k_usb_dscr_typ_devqual:
trace0(0, dev, 0, "RQ_GET_DESCRIPTOR: devqual");
// tell the data pump where to find it and how much there is
#ifdef k_20x_family
trace1(0, dev, 0, "x_sie_conf:%02X",x_sie_conf);
if ((x_sie_conf & kbm_sie_conf_hspeed))
{
_payload_source(&g_fs_devqual_dscr, _min(g_fs_devqual_dscr[0], g_wtmp));
} else
{
_payload_source(&g_hs_devqual_dscr, _min(g_hs_devqual_dscr[0], g_wtmp));
}
#else
_payload_source(&g_fs_devqual_dscr, _min(g_fs_devqual_dscr[0], g_wtmp));
#endif
break;
case k_usb_dscr_typ_config:
trace0(0, dev, 0, "RQ_GET_DESCRIPTOR: configuration");
// make sure it is in the supported range
if (rqstp->wValueLo > k_dev_max_configuration)
return k_error;
// tell the data pump where to find it and how much there is
#ifdef k_20x_family
trace1(0, dev, 0, "x_sie_conf:%02X",x_sie_conf);
if ((x_sie_conf & kbm_sie_conf_hspeed))
{
_payload_source(&g_hs_cfg_dscr, _min(g_hs_cfg_dscr[2], g_wtmp));
} else
{
_payload_source(&g_fs_cfg_dscr, _min(g_fs_cfg_dscr[2], g_wtmp));
}
#else
_payload_source(&g_cfg_dscr, _min(g_cfg_dscr[2], g_wtmp));
#endif
break;
case k_usb_dscr_typ_osconfig:
trace0(0, dev, 0, "RQ_GET_DESCRIPTOR: other speed configuration");
// make sure it is in the supported range
if (rqstp->wValueLo > k_dev_max_configuration)
return k_error;
// tell the data pump where to find it and how much there is
#ifdef k_20x_family
trace1(0, dev, 0, "x_sie_conf:%02X",x_sie_conf);
if ((x_sie_conf & kbm_sie_conf_hspeed))
{
_payload_source(&g_fs_oscfg_dscr, _min(g_fs_oscfg_dscr[2], g_wtmp));
} else
{
_payload_source(&g_hs_oscfg_dscr, _min(g_hs_oscfg_dscr[2], g_wtmp));
}
#else
_payload_source(&g_cfg_osdscr, _min(g_oscfg_dscr[2], g_wtmp));
#endif
break;
case k_usb_dscr_typ_string:
trace0(0, dev, 0, "RQ_GET_DESCRIPTOR: string");
// make sure it is in the supported range
if (rqstp->wValueLo >= k_dev_max_string)
return k_error;
// check which string descriptor is requested
switch (rqstp->wValueLo)
{
case k_dev_idx_str_dscr_ser:
if (x_ata_dev_has_ser)
{
trace0(0, dev, 0, "sending custom serial num") ;
// build a serial descriptor and put it into the gp sram
_build_serial_dscr(&x_sram_buffer[0]) ;
// ship it
_payload_source(&x_sram_buffer[0], _min(x_sram_buffer[0], g_wtmp)) ;
break;
} else
{
trace0(0, dev, 0, "sending default serial num") ;
// send default.
_payload_source(g_str_dscr[rqstp->wValueLo], _min(*((uint8 *)g_str_dscr[rqstp->wValueLo]), g_wtmp));
}
break;
case k_dev_idx_str_dscr_prd:
trace0(0, dev, 0, "sending default product string descriptor") ;
_payload_source(g_str_dscr[rqstp->wValueLo], _min(*((uint8 *)g_str_dscr[rqstp->wValueLo]), g_wtmp));
break;
case k_dev_idx_str_dscr_mfg:
trace0(0, dev, 0, "sending default manufacturer string descriptor") ;
_payload_source(g_str_dscr[rqstp->wValueLo], _min(*((uint8 *)g_str_dscr[rqstp->wValueLo]), g_wtmp));
break;
case k_dev_idx_str_dscr_lng:
trace0(0, dev, 0, "sending default language string descriptor") ;
_payload_source(g_str_dscr[rqstp->wValueLo], _min(*((uint8 *)g_str_dscr[rqstp->wValueLo]), g_wtmp));
break;
default:
// tell the data pump where to find it and how much there is
trace1(0, dev, 0, "unknown value for string descriptor index:%d. Sending default", rqstp->wValueLo) ;
_payload_source(g_str_dscr[rqstp->wValueLo], _min(*((uint8 *)g_str_dscr[rqstp->wValueLo]), g_wtmp));
}
break;
default:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -