/* * Scan devices in bus 0 */ void pci_init() { uint8_t bus = 0; uint8_t slot; uint8_t func; uint i; /* Initialize PCI table */ memset(pci_devices, 0, sizeof(pci_devices)); /* Scan bus 0 devices */ pci_count = 0; for(slot=0; slot<32; slot++) { for(func=0; func<8; func++) { uint i; uint32_t* p; uint32_t pci_dev_addr = (uint32_t) (((ul_t)bus<<16) | ((ul_t)slot<<11) | ((ul_t)func<<8)); uint16_t vendor_id = pci_read_config(pci_dev_addr, 0)&0xFFFF; /* Discard unused */ if(vendor_id == 0xFFFF) { continue; } /* Read device */ p = (uint32_t *)&pci_devices[pci_count]; for(i=0; i<sizeof(struct PCI_DEVICE); i+=4) { *p++ = pci_read_config(pci_dev_addr, i); } pci_count++; if(pci_count >= MAX_PCI_DEVICE) { debugstr("There are unlisted PCI devices\n\r"); return; } } } /* Print debug info */ debugstr("PCI initialized\n\r"); for(i=0; i<pci_count; i++) { debugstr("vendor:%x device:%x\n", pci_devices[i].vendor_id, pci_devices[i].device_id); } }
//! Handle a command. void handle(uint8_t const app, uint8_t const verb, uint32_t const len){ int i; //debugstr("GoodFET"); //led_off(); // find the app and call the handle fn for(i = 0; i < num_apps; i++){ if(apps[i]->app == app){ // call the app's handle fn (*(apps[i]->handle))(app, verb, len); // exit early return; } } // if we get here, then the desired app is not compiled into // this firmware debugstr("App missing."); debughex(app); txdata(app, NOK, 0); }
// send debug messages over USB-serial link encapsulated in the goodfet protocol void dputc(char c) { char two[2]; two[0]=c; two[1]=0; debugstr(two); }
void debughex(u16 v) { char buffer[5]; buffer[0] = nibbletohex(v >> 12); buffer[1] = nibbletohex(v >> 8); buffer[2] = nibbletohex(v >> 4); buffer[3] = nibbletohex(v); buffer[4] = 0; debugstr(buffer); }
//! Delay for specified number of clock ticks (16 MHz clock implies 62.5 ns per tick). void delay_ticks( unsigned int num_ticks ) { #ifdef MSP430 TBCTL |= 0x20; // Start timer while (TBR < num_ticks) asm( "nop" ); TBCTL = 0x0204; // Reset Timer B, till next time #else debugstr("delay_ticks unimplemented"); #endif }
//! Delay for specified number of microseconds (given 16 MHz clock) void delay_us( unsigned int us ) { #ifdef MSP430 // 16 ticks = 1 us TBCTL |= 0x20; // Start timer! while (us--) { while (TBR < 16) asm( "nop" ); TBCTL = 0x0224; } TBCTL = 0x0204; // Reset Timer B, till next time #else debugstr("delay_us unimplemented"); #endif }
//! Shift 20 bits of the DR. uint32_t jtag430_dr_shift_20(uint32_t in) { if (!in_run_test_idle()) { debugstr("Not in run-test-idle state"); return 0; } // get intot the right state jtag_capture_dr(); jtag_shift_register(); // shift DR, then idle return jtag_trans_n(in, 20, MSB); }
//! Main loop. int main(void){ volatile unsigned int i; unsigned char app, verb; unsigned long len; // MSP reboot count for reset input & reboot function located at 0xFFFE volatile unsigned int reset_count = 0; silent=0; //Don't trust globals. #if (platform == tilaunchpad) int ret=0; //ret = setjmp(warmstart);// needs to be here since context from init() would be gone warmstart: if (ret == 0) { coldstart(); // basic hardware setup, clock to TUSB3410, and enable } else if (ret == 2) { dputs("\nalmost BSL only one RTS change\n"); } else if (ret > 2) { // reset released after more than two tst transisitions // We could write a BSL, a nice exercise for a Sunday afternoon. dputs("\nBSL\n"); //call_BSL(); // once you are done uncomment ;-) } else { // we come here after DTR high (release reset) dputs("\nWarmstart\n"); } #endif #if (platform == donbfet) extern void donbfet_reboot(void); void (*reboot_function)(void) = donbfet_reboot; #elif (platform == zigduino) extern void zigduino_reboot(void); void (*reboot_function)(void) = zigduino_reboot; #else void (*reboot_function)(void) = (void *) 0xFFFE; #endif init(); txstring(MONITOR,OK,"http://goodfet.sf.net/"); //txstring(0xab,0xcd,"http://goodfet.sf.net/"); //Command loop. There's no end! while(1){ //Magic 3 app = serial_rx(); // If the app is the reset byte (0x80) increment and loop if (app == RESET){ reset_count++; if (reset_count > 4){ // We could trigger the WDT with either: // WDTCTL = 0; // or // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00; // but instead we'll jump to our reboot function pointer (*reboot_function)(); debugstr("Rebooting not supported on this platform."); } continue; }else { reset_count = 0; } verb = serial_rx(); len = rxword(); //Read data, looking for buffer overflow. if(len <= CMDDATALEN){ for(i = 0; i < len; i++) cmddata[i] = serial_rx(); handle(app,verb,len); }else { //Listen to the blaberring. for(i = 0; i < len; i++) serial_rx(); //Reply with an error. debugstr("Buffer length exceeded."); txdata(MONITOR,NOK,0); } } }
//! Handles MSP430X2 JTAG commands. Forwards others to JTAG. void jtag430x2_handle_fn( uint8_t const app, uint8_t const verb, uint32_t const len) { unsigned int i,val; unsigned long at, l; //jtag430_resettap(); if(verb!=START && jtag430mode==MSP430MODE){ (*(jtag430_app.handle))(app,verb,len); return; } switch(verb){ case START: //Enter JTAG mode. //do cmddata[0]=jtag430x2_start(); //while(cmddata[0]==00 || cmddata[0]==0xFF); //MSP430 or MSP430X if(jtagid==MSP430JTAGID){ //debugstr("ERROR, using JTAG430X2 instead of JTAG430!"); jtag430mode=MSP430MODE; /* So the way this works is that a width of 20 does some backward-compatibility finagling, causing the correct value to be exchanged for addresses on 16-bit chips as well as the new MSP430X chips. (This has only been verified on the MSP430F2xx family. TODO verify for others.) */ drwidth=20; //Perform a reset and disable watchdog. jtag430_por(); jtag430_writemem(0x120,0x5a80);//disable watchdog jtag430_haltcpu(); jtag430_resettap(); txdata(app,verb,1); return; }else if(jtagid==MSP430X2JTAGID){ jtag430mode=MSP430X2MODE; drwidth=20; }else{ debugstr("JTAG version unknown."); txdata(app,NOK,1); return; } jtag430x2_fusecheck(); jtag430x2_syncpor(); jtag430_resettap(); txdata(app,verb,1); break; case JTAG430_READMEM: case PEEK: at=cmddatalong[0]; //Fetch large blocks for bulk fetches, //small blocks for individual peeks. if(len>5) l=(cmddataword[2]);//always even. else l=2; l&=~1;//clear lsbit if(l<2) l=2; txhead(app,verb,l); for(i=0;i<l;i+=2){ //jtag430_resettap(); //delay(10); val=jtag430x2_readmem(at); at+=2; serial_tx(val&0xFF); serial_tx((val&0xFF00)>>8); } break; case JTAG430_COREIP_ID: cmddataword[0]=jtag430_coreid(); txdata(app,verb,2); break; case JTAG430_DEVICE_ID: cmddatalong[0]=jtag430_deviceid(); txdata(app,verb,4); break; case JTAG430_WRITEFLASH: case JTAG430_WRITEMEM: case POKE: jtag430x2_writemem(cmddatalong[0], cmddataword[2]); cmddataword[0]=jtag430x2_readmem(cmddatalong[0]); txdata(app,verb,2); break; //unimplemented functions case JTAG430_HALTCPU: //jtag430x2_haltcpu(); debugstr("Warning, not trying to halt for lack of code."); txdata(app,verb,0); break; case JTAG430_RELEASECPU: case JTAG430_SETINSTRFETCH: case JTAG430_ERASEFLASH: case JTAG430_SETPC: debugstr("This function is not yet implemented for MSP430X2."); debughex(verb); txdata(app,NOK,0); break; default: (*(jtag_app.handle))(app,verb,len); } jtag430_resettap(); }
void dputs(char *str) { debugstr(str); }
OSErr NetDDPOpenSocket( short *socketNumber, packetHandlerProcPtr packetHandler) { OSErr error; Handle socket_listener_resource; ProcPtr initialize_socket_listener, socket_listener; MPPPBPtr myMPPPBPtr= (MPPPBPtr) NewPtrClear(sizeof(MPPParamBlock)); static ProcPtr initialize_upp = NULL; static UniversalProcPtr packet_handler_upp = NULL; assert(packetHandler); /* canÕt have NULL packet handlers */ assert(!ddpPacketBuffer); /* canÕt have more than one socket listener installed */ socket_listener_resource = GetResource(SOCKET_LISTENER_RESOURCE_TYPE, SOCKET_LISTENER_ID); assert(socket_listener_resource); HLock(socket_listener_resource); HNoPurge(socket_listener_resource); initialize_socket_listener = (ProcPtr) StripAddress(*socket_listener_resource); ddpPacketBuffer= (DDPPacketBufferPtr) NewPtrClear(sizeof(DDPPacketBuffer)); error= MemError(); if (error==noErr) { if (packet_handler_upp == NULL) { packet_handler_upp = (UniversalProcPtr) NewRoutineDescriptor((ProcPtr) packetHandler, uppPacketHandlerProcInfo, GetCurrentISA()); } assert(packet_handler_upp); if (initialize_upp == NULL) { initialize_upp = (ProcPtr) NewRoutineDescriptor((ProcPtr) initialize_socket_listener, uppInitializeListenerProcInfo, kM68kISA); // it's in a 68k code resource } assert(initialize_upp); #ifdef env68k // it seems that we don't have CallUniversalProc() in the library. strange... #ifndef VULCAN socket_listener = (ProcPtr) initialize_socket_listener(packet_handler_upp, ddpPacketBuffer, 1); #else debugstr("Hey, socket listener was never initialized"); #endif #else socket_listener = (ProcPtr) CallUniversalProc((UniversalProcPtr) initialize_upp, uppInitializeListenerProcInfo, packet_handler_upp, ddpPacketBuffer, 1); #endif listenerUPP = (DDPSocketListenerUPP) NewRoutineDescriptor((ProcPtr) socket_listener, uppDDPSocketListenerProcInfo, kM68kISA); // have to force it to realize that it's a 68K resource assert(listenerUPP); myMPPPBPtr->DDP.socket= 0; myMPPPBPtr->DDP.u.listener= listenerUPP; error= POpenSkt(myMPPPBPtr, FALSE); if (error==noErr) { *socketNumber= myMPPPBPtr->DDP.socket; } DisposePtr((Ptr)myMPPPBPtr); } return error; }