📄 device.c
字号:
else
{
trace0(0, dev, 0, "clearing the activity led gpio");
//drive the gpio low
#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
}
gpio_clrbit(5);
_mcu_register_set_bits(x_gpiob_out, kbm_gpio8 |kbm_gpio9 |kbm_gpio10 |kbm_gpio11 |kbm_gpio12 |kbm_gpio13 |kbm_gpio14 |kbm_gpio15);
#ifdef k_pfm_led
// turn off the activity/inserted LEDs
_mcu_register_clr_bits(x_gpiob_out, kbm_gpio12 |kbm_gpio13 |kbm_gpio14 |kbm_gpio15);
#endif
}
//+-----------------------------------------------------------------------------
// 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(0, 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);
#endif
#ifdef k_20x_family
// 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_flash_family
#ifdef k_pkg_100
trace0(0, 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(0, 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.
//
// Arguments:
// None.
//
// Return:
// None.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
static void dev_power_up(void) reentrant;
static void dev_power_up() reentrant
{
uint8 ps;
trace0(0, dev, 1, "dev_power_up()");
dev_indicate_bus_speed();
// temporary - disable card status change irq's on power down, enable on power up
irq_control(k_irq_crd_sts_chg, kbm_irqctl_clear |kbm_irqctl_unmask);
ps = _mcu_register_rd(x_crd_ps);
// compact flash
#if (k_log_lun_cf < k_max_log_lun)
if (ps & kbm_crd_ps_cf)
{
trace0(0, dev, 0, "_cf_pwr_on()");
_cf_pwr_on();
_inserted(k_lun_cf);
#ifdef k_pfm_led
_mcu_register_clr_bits(x_gpiob_out, kbm_gpio13);
#endif
}
#endif
// memory stick
#if (k_log_lun_ms < k_max_log_lun)
if (ps & kbm_crd_ps_ms)
{
_ms_pwr_on();
_inserted(k_lun_ms);
#ifdef k_pfm_led
_mcu_register_clr_bits(x_gpiob_out, kbm_gpio12);
#endif
}
#endif
// smart media
#if (k_log_lun_sm < k_max_log_lun)
if (ps & kbm_crd_ps_sm)
{
_sm_pwr_on();
_inserted(k_lun_sm);
#ifdef k_pfm_led
_mcu_register_clr_bits(x_gpiob_out, kbm_gpio14);
#endif
}
#endif
// secure digital / multi media card
#if (k_log_lun_sd < k_max_log_lun)
_sd_pwr_off();
#ifdef k_pfm_led
_mcu_register_clr_bits(x_gpiob_out, kbm_gpio15);
#endif
_sd_inserted_ejected();
_lun_map_log2phy(k_log_lun_sd, k_lun_sd);
#endif
// nand drive
#if (k_log_lun_nand < k_max_log_lun)
_nand_pwr_on();
// $$$ cds - this doesn't really make sense for a fixed drive.
// Will have to figure something out... like moving this to a lun-specific
// location
_inserted(k_lun_nand);
#ifdef k_pfm_led
_mcu_register_clr_bits(x_gpiob_out, kbm_gpio14);
#endif
#ifdef k_interleave_demo
gpio_bit_is_input(2);
gpio_bit_is_input(4);
gpio_bit_is_input(5);
gpio_bit_is_input(7);
#endif
#endif
//all the bits are output for 211 and 242, as they are chip selects
#if defined(k_mcu_97242) || defined(k_mcu_97211)
_mcu_register_set_bits(x_gpiob_dir, 0xff);
#endif
dev_turn_off_activity_indicator();
}
//+-----------------------------------------------------------------------------
// Name:
// dev_power_dn
//
// Declaration:
// void dev_power_dn(void);
//
// Purpose:
// Called on set-config(0), and suspend if configuration is non-zero.
// Power off the flash media sockets and mark the media as ejected.
//
// Arguments:
// None.
//
// Return:
// None.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
static void dev_power_dn(void) reentrant;
static void dev_power_dn() reentrant
{
trace0(0, dev, 1, "dev_power_dn()");
// temporary - disable card status change irq's on power down, enable on power up
irq_control(k_irq_crd_sts_chg, kbm_irqctl_mask);
//mask the timer1 interrupt, because the interrupt fires after we process dev_power_dn and brings
//the led to the wrong state
irq_control(k_irq_cpu_t1, kbm_irqctl_mask);
// simulate eject on all cards
_ejected(k_lun_cf);
_ejected(k_lun_ms);
_ejected(k_lun_sm);
//_sd_inserted_ejected();
// turn off all power to cards, indicator leds, etc
dev_gpio_power_down();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint8 nvstore_read(uint8 addr) reentrant
{
#ifdef k_opt_eeprom
return(eeprom_read(addr));
#elif defined (k_opt_otprom)
return(otprom_read(addr));
#elif defined (k_opt_nand)
return(nand_boot_read(addr));
#else
return(uint8) 0xff;
#endif
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void nvstore_write(uint8 addr, uint8 value) reentrant
{
// do nothing. only passworded drives call this, and they require nand, not otprom
#ifdef k_opt_eeprom
eeprom_write(addr, value);
//#elif defined (k_opt_otprom)
// otprom_write(addr, value));
#elif defined (k_opt_nand)
// #ifdef k_opt_nand
nand_boot_write(addr, value);
#else
// avoid "unused parameter" warning
addr = value;
#endif
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void nvstore_write_enable() reentrant
{
#ifdef k_opt_eeprom
eeprom_write_enable();
//#elif defined (k_opt_otprom)
//do nothing
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -