📄 tm1if_pc.c
字号:
if (created_servers == NULL) { return TM1IF_Serving_Failed; } for (i=1; i <= NROF_SERVERS; i++) { HANDLE dummy; HANDLE new_thread; new_thread= CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE)serve, 0, 0, (LPDWORD)&dummy ); if (new_thread != NULL) { created_servers[nrof_created_servers++]= new_thread; } } if (nrof_created_servers > 0) { return TM1IF_Serving_Started; } else { return TM1IF_Serving_Failed; } }/* * Function : Initialise this module, and make the * I/O callback functions known to it. * Parameters : open .. exit (I) IO functions. * endian (I) node's endianness * Function Result : True iff initialisation succeeded */Bool TM1IF_init( RPCServ_OpenFunc open, RPCServ_OpenDllFunc open_dll, RPCServ_CloseFunc close, RPCServ_ReadFunc read, RPCServ_WriteFunc write, RPCServ_SeekFunc seek, RPCServ_IsattyFunc isatty, RPCServ_FstatFunc fstat, RPCServ_FcntlFunc fcntl, RPCServ_StatFunc stat, RPCServ_ExitFunc exit, Endian endian ){ static WSADATA WSAData; serving_stopped= False; same_endian = endian==LCURRENT_ENDIAN; WSAStartup(MAKEWORD(1, 1), &WSAData); return RPCServ_init( open, open_dll, close, read, write, seek, isatty, fstat, fcntl, stat, exit, endian );}/* * Function : Add information on new node * Parameters : node_number (I) Node number assigned to executable * via TMDownLoader interface. * argc, argv (I) Command line arguments * Stdin,Stdout,Stderr (I) file descriptors to be used as * standard file descriptors. * NB: these must be legal parameter * values for the IO functions * address_shift (I) the difference between the virtual * and physical address of the each location * in the node's SDRAM, as seen from the host * sdram_base (I) physical address of the node's SDRAM start * sdram_limit (I) physical address of the node's SDRAM limit * data (I) additional, monitor specific data * Function Result : True iff add succeeded. */static void terminate( NodeData data ){ tmMsgDestroy( data->hostcall_channel ); free(data);}Bool TM1IF_add_node_info( UInt32 node_number, UInt32 argc, String *argv, UInt32 Stdin, UInt32 Stdout, UInt32 Stderr, UInt32 address_shift, UInt32 sdram_base, UInt32 sdram_limit, Pointer data ){ TMMAN_MESSAGE_DESC MsgCreate; NodeData newdata; newdata= malloc(sizeof(*newdata)); if (newdata == Null) { return False; } newdata->dsp_number= (DWORD)data; MsgCreate.pvContext = NULL; MsgCreate.dwCallback = (DWORD)notify; MsgCreate.dwID = HostCall_CHANNEL; MsgCreate.dwMessageSlots = HostCall_CHANNEL_CAPACITY; if ( tmDSPOpen ( newdata->dsp_number, &newdata->dsp_handle ) != TMOK || tmMsgCreate ( newdata->dsp_handle, &MsgCreate, &newdata->hostcall_channel ) != TMOK ) { free(newdata); return False; } if ( RPCServ_add_node_info( node_number, argc, argv, Stdin, Stdout, Stderr, address_shift, sdram_base, sdram_limit, terminate, newdata )) { return True; } else { terminate(newdata); return False; }}/* * Function : Remove information on node, when present. * Parameters : node_number (I) Node number assigned to executable * via TMDownLoader interface. * Function Result : - */void TM1IF_remove_node_info( UInt32 node_number ){ RPCServ_remove_node_info(node_number);}/* * Function : Stops and deletes the previously started * TM-1 application serving task(s), and return * *after* they have been stopped (this makes sure * that the servers stopped writing into TM memory). * Additionally, cause all 'get_pending_request' * calls to unblock and return with either NULL or * a command. * Parameters : * Function Result : * Precondition : - * Postcondition : - * Sideeffects : */void TM1IF_term(){ Int32 i; serving_stopped= True; for (i=1; i<=nrof_created_servers; i++) { ReleaseSemaphore( overflow_detector, 1, NULL ); ReleaseSemaphore( element_counter, 1, NULL ); } WaitForMultipleObjects( nrof_created_servers, created_servers, TRUE, 2000 ); free( created_servers ); RPCServ_term(); WSACleanup();}/* * Function : Allocate a range of pagelocked memory, * and return scatter information. * Parameters : node_number (I) allocating node * size (I) size to allocate * address (O) returned virtual start address, * or Null when pagelocked allocation failed * scatter (O) an array of scatter block descriptors, * to contain the returned scatter desctiptor * size (IO) input: capacity of 'scatter', in nrof entries * output: number of scatter entries of result * Function Result : - */void TM1IF_malloc_pagelocked( UInt node_number, UInt size, Pointer *retval, HostCall_MemoryBlock *scatter, UInt *scatter_size ){ RPCServ_NodeInfo *ninfo= RPCServ_get_node_info( node_number ); NodeData data = ninfo->data; if ( *scatter_size >= 1 && tmShmemAllocate (data->dsp_handle,0,size,retval,&scatter->address) == TMOK ) { *scatter_size= 1; scatter->length = size; } else { *retval= Null; }}/* * Function : Free a range of pagelocked memory. * Parameters : node_number (I) freeing node * address (I) virtual start address of previously * allocated pagelocked memory * Function Result : - */void TM1IF_free_pagelocked( UInt node_number, Pointer address ){ RPCServ_NodeInfo *ninfo= RPCServ_get_node_info( node_number ); NodeData data = ninfo->data; tmShmemFree ( data->dsp_handle, address );}UInt32 TM1IF_endian_swap( UInt32 value ){ return (same_endian ? value : LIENDIAN_SWAP4(value)); }UInt32 TM1IF_endian_swap_short (UInt32 value){ return same_endian? value: LIENDIAN_SWAP2 (value);}Address TM1IF_tm2host( RPCServ_NodeInfo *ninfo, Address tm_address ){ return (tm_address == Null ? Null : (Address)(TM1IF_endian_swap((Int32)tm_address)+ninfo->address_shift)); }Address TM1IF_host2tm( RPCServ_NodeInfo *ninfo, Address host_address ){ return (host_address == Null ? Null : (Address)TM1IF_endian_swap(((Int32)host_address)-ninfo->address_shift));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -