int CommandMemmap(char *szCom,target_context_t **tc) { int ret; /* open a connection to the target */ *tc = target_open(szCom, NULL); if(*tc == NULL) { MessageBox(hDlg_Main, "can't open connection to target", "hermit", 0); return FALSE; } //set_serial_timeout(((target_context_t *)*tc)->portfd, TIMEOUT_NORMAL); ret = target_connect(*tc); if(ret != 0) { MessageBox(NULL, "can't connect to target", "hermit", 0); target_close(*tc); return FALSE; } target_write_command(*tc, "memmap"); mem_map_read(*tc); return TRUE; }
static void romloader_openocd_close_instance(void *pvHandle) { command_context_t *cmd_ctx; target_t *target; int iResult; wxString strMsg; /* cast the handle to the command context */ cmd_ctx = (command_context_t*)pvHandle; strMsg.Printf(wxT("closing romloader openocd at %p"), cmd_ctx); wxLogMessage(strMsg); /* NOTE: this seems to work with ftd2xx, but not with libftdi */ if( jtag!=NULL && jtag->quit!=NULL ) { jtag->quit(); } /* close all subsystems */ iResult = jtag_close(cmd_ctx); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to close jtag interface: %d"), iResult); wxLogWarning(strMsg); } iResult = target_close(cmd_ctx); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to close target interface: %d"), iResult); wxLogWarning(strMsg); } // free commandline interface command_done(cmd_ctx); }
target_context_t *target_open(const char *port, const char *netif) { target_context_t *tc; assert(port); tc = zmalloc(sizeof (target_context_t)); #ifndef WIN32 tc->portfd = -1; #else tc->portfd = INVALID_HANDLE_VALUE; #endif tc->sockfd = -1; tc->medium = TM_SERIAL; tc->mtu = SERIAL_MTU; tc->write = target_write_serial; tc->portfd = open_port(port); if(tc->portfd < 0) goto failure; #if defined(WIN32) if(tc->portfd == INVALID_HANDLE_VALUE) goto failure; #endif #ifndef WIN32 if (netif && (eth_open(tc, netif) < 0)) goto failure; #endif return tc; failure: target_close(tc); return NULL; }
int CommandFinish(target_context_t **tc) { restore_interactive(*tc); target_close(*tc); return TRUE; }