/*! \brief Main loop. * * Most of the action is interrupt driven. This loop only detects USB suspension. * * @return Never exits */ void main(void) { init(); for(;;){ wait100us(); suspend_timer++; if (suspend_timer>=SUSPEND_TIME) { /* host is not sending keepalive signals, time to suspend all operation */ /* BDM is in idle mode when not communicating, so nothing to do there */ U16 i; /* Acknowledge any pending interrupt and disable KBD interrupts; */ /* This will prevent RESET activity waking us up out of stop */ KBSCR = KBSCR_IMASKK_MASK | KBSCR_ACKK_MASK; led_state=LED_OFF; /* switch the LED off */ GREEN_LED_OFF(); /* do it now, the interrupt which would do it normally is not going to come */ UIR0_SUSPND=1; /* suspend USB */ while (suspend_timer) asm(STOP); /* go to sleep, wait for USB resume or reset */ for (i=0;i<RESUME_RECOVERY;i++) wait100us(); /* wait for host to recover */ led_state=LED_ON; /* Switch the LED back on */ (void)bdm_init(); /* Reinitialise the BDM after wake-up as the device might */ /* have been disconected in the meantime; assume nothing */ } }
int _start(int argc, char* argv[]) { printf("Block Device Manager (BDM) v%d.%d\n", MAJOR_VER, MINOR_VER); if (RegisterLibraryEntries(&_exp_bdm) != 0) { M_PRINTF("ERROR: Already registered!\n"); return MODULE_NO_RESIDENT_END; } // initialize the block device manager if (bdm_init() < 0) { M_PRINTF("ERROR: BDM init failed!\n"); return MODULE_NO_RESIDENT_END; } // initialize the partition driver part_init(); // return resident return MODULE_RESIDENT_END; }
/*! \brief Initialise the system. * * Initialisation of the following: * \li Watchdog (off), * \li Stack, * \li BDM interface, * \li USB interface. */ void init(void) { /* disable part reset on USB reset, enable STOP instruction & disable COP */ CONFIG = CONFIG_URSTD_MASK | CONFIG_STOP_MASK | CONFIG_COPD_MASK; // Turn off important things VPP_OFF(); VDD_OFF(); FLASH12V_OFF(); clearStack(); // Make unused pins 'safe' (not floating) // These settings may be overridden later POCR = POCR_PAP_MASK|POCR_PCP_MASK|POCR_PTE20P_MASK; /* acknowledge IRQ interrupt and disable it */ ISCR = ISCR_ACK_MASK | ISCR_IMASK_MASK; (void)bdm_init(); // Do early as possible usb_init(); EnableInterrupts; }
/*! \brief Initialise the system. * * Initialisation of the following: * \li Default port values * \li Watchdog (off), * \li Stack, * \li BDM interface, * \li USB interface. * \li Configure Clock for 48MHz operation */ static void init(void) { // Default ports to inputs PTADD = 0x00; PTBDD = 0x00; #if (CPU==JMxx) PTCDD = 0x00; PTDDD = 0x00; PTEDD = 0x00; PTFDD = 0x00; PTGDD = 0x00; #endif // Turn off important things #if ((HW_CAPABILITY & CAP_FLASH) != 0) (void)bdmSetVpp(BDM_TARGET_VPP_OFF); #endif VDD_OFF(); // Default to Ports have PUPs // Note - this doesn't affect outputs PTAPE = 0xFF; PTBPE = 0xFF; #if (CPU==JMxx) PTCPE = 0xFF; PTDPE = 0xFF; PTEPE = 0xFF; PTFPE = 0xFF; PTGPE = 0xFF; #endif EnableInterrupts; #ifndef SOPT1_BKGDPE_MASK #define SOPT1_BKGDPE_MASK (0) #endif SOPT1 = SOPT1_STOPE_MASK|SOPT1_BKGDPE_MASK; // Disable COP, enable STOP instr. & BKGD pin #if (HW_CAPABILITY&CAP_VDDSENSE) SPMSC1_BGBE = 1; // Enable Bandgap Reference #endif LED_INIT(); clearStack(); initUSB(); // Assumes clock already done (void)bdm_init(); (void)bdm_off(); #ifdef VDD_ON_INITIALLY // For compatibility with original board s/w // The board is powered when initially plugged in #if (VDD_ON_INITIALLY == 3) bdm_option.targetVdd = BDM_TARGET_VDD_3V3; #elif (VDD_ON_INITIALLY == 5) bdm_option.targetVdd = BDM_TARGET_VDD_5; #else #error "Illegal VDD_ON_INITIALLY value" #endif (void)bdm_interfaceOff(); (void)bdm_setTargetVdd(); #endif #if (DEBUG&SCI_DEBUG) != 0) debugSCIInit(); #endif }
int main( int ArgC, char *ArgV[] ) { int BDMHandle; unsigned int Base; unsigned int Chips; unsigned int Bytes; char *Operation; FlashError_t Error; if (ArgC < 6) Usage( ArgV[0] ); if((BDMHandle = bdm_init(ArgV[1]))<0) { fprintf( stderr, "Problem opening bdm device %s, error code %d.\n", ArgV[1], BDMHandle ); return (EXIT_FAILURE); } Base = (unsigned int) strtoul( ArgV[2], NULL, 0 ); Chips = (unsigned int) strtoul( ArgV[3], NULL, 0 ); Bytes = (unsigned int) strtoul( ArgV[4], NULL, 0 ); Operation = ArgV[5]; Error = BDMFlashConfigSet( BDMHandle, Base, Chips, Bytes ); if (Error != FlashErrorOkay_c) { fprintf( stderr, "Problem configuring flash; error code = %d '%s'.\n", (int) Error, FlashErrorDescriptionEnglish[Error] ); } if (strcasecmp( Operation, "erase" ) == 0) { Erase( ArgC, ArgV ); } else if (strcasecmp( Operation, "SectorErase" ) == 0) { SectorErase( ArgC, ArgV ); } else if (strcasecmp( Operation, "BlockErase" ) == 0) { BlockErase( ArgC, ArgV ); } else if (strcasecmp( Operation, "write" ) == 0) { Write( ArgC, ArgV ); } else if (strcasecmp( Operation, "read" ) == 0) { Read( BDMHandle, ArgC, ArgV ); } else if (strcasecmp( Operation, "probe" ) == 0) { Probe( ArgC, ArgV ); } else if (strcasecmp( Operation, "detect" ) == 0) { Detect( ArgC, ArgV ); } else Usage( ArgV[0] ); bdm_release( BDMHandle ); return (EXIT_SUCCESS); }