stdcomm.h

来自「基于4个mips核的noc设计」· C头文件 代码 · 共 201 行

H
201
字号
/**************************************************************** *  TU Eindhoven, Eindhoven, The Netherlands, November 2003 *  Author      :   Mathijs Visser *                  (Mathijs.Visser@student.tue.nl) *  Discription :   Interface definition of the (non-)blocking send *                  and receive primitives for sending one multi-byte *                  packet over a network of minimips processors. *                  If CC_I386 is defined, this code will compile *                  on a i386 with gcc. *                  See the NoF documentation for details. ****************************************************************/#ifndef STDCOMM_H_#define STDCOMM_H_#define SC_CONTROLWORD          (*(int*)0x80000004)/* Dereferenced address location of the control word * of the network interface (NI).*/ #define SC_DATAWORD             (*(int*)0x80000000)/* Dereferenced address location of the data word * of the network interface (NI).*//* Bitmask to extract the address from the contolword. */#define SC_BITMASK_ADDRESS      0x0000FFFF/* Control word bits related to sending packets:*/#define SC_BIT_SEND_READY       0x00040000/* Name: send_ready     Position: bit 18    Access: READ only * 1 :  Transmitter is ready to accept data. * 0 :  Transmitter not ready. *      If data is written to location SC_DATAWORD in this state, *      it will be undefined what data is actually sent (new, old, *      corrupted or nothing at all). */#define SC_BIT_SEND             0x00020000                     /* Name: send           Position: bit 17    Access: WRITE only * The user needs to write SC_BIT_SEND to the NI controlword before * writing any value to the NI dataword. This value should also be * OR-ed with the destination address of the packet before the first * write to the data word and with SC_BIT_SEND_EOP before the last. */#define SC_BIT_SEND_EOP         0x00100000/* Name: send_eop       Position: bit 20    Access: WRITE only * The bit send_eop of the control word is set to one only if the * next write to the data word completes the current packet. *//* Control word bits related to receiving packets:*/#define SC_BIT_DATA_READY       0x00010000/* Name: data_ready     Position: bit 16    Access: READ only * A value of 1 indicates that the receiver has data waiting that * can be read. Do not read from the receiver if it the * data_ready is not 1. */#define SC_BIT_RCV_EOP          0x00080000/* Name: rcv_eop        Position: bit 19    Access: READ only * The current value of the data word is that of the last part * of the current packet. *//* ERROR/STATUS values returned by the communication functions: */#define SC_COMMERR_SUCCESS          0/* All network operations completed successfully.*/#define SC_COMMERR_FAILURE          1/* There was some undefined error.*/#define SC_COULD_NOT_SEND           2/* SC_BIT_SEND_READY was 0 so no transmission was done.*/#define SC_NO_DATA_WAITING          3/* SC_BIT_DATA_READY was 0 so there either is no data waiting to * be read, or there is an error in the network interface.*/#define SC_RCV_EOP_BIT_ZERO         4/* The SC_BIT_RCV_EOP of the last 32-bit value received was not set * to 1. This means that we have read an incomplete packet. * This could indicate that there were more (or less) packets * than expected. */extern int sc_my_address;/* The address of the node on which this library runs. This variable is * not used in the stdcomm library yet and is reserved for future use. * Setting this value is good practice (as it may be used in the future). */extern int try_count_sc_send;/* Default try_count used by sc_send() for each call to sc_send_word() * A value of 0 or less will result in infinite retries. */extern int try_count_sc_receive;/* Default try_count used by sc_receive() for each call to sc_receive_word() * A value of 0 or less will result in infinite retries. */int sc_send(const int address, const void *data, const int size_in_bytes);/***************************************************************** DESCRIPTION: Tries to send a block of the given number of bytes.*   Uses sc_send_word() to send each 4 byte word in data. The max.*   retry_count for each call to sc_send_word() is given by*   try_count_sc_send.* PARAMETERS:*   address:    Relative address of (or distance to) the destination*               node.*   data:       Pointer to where the source data starts.*               May be any address (not necessarily divideable by 4).*   size_in_bytes:  Number of bytes to send.* RETURN VALUE:*   Returns the number of bytes that were successfully sent.****************************************************************/int sc_send_word(const int *ctrlword, const int *data, int try_count);/***************************************************************** DESCRIPTION: Tries to send a 32 bit word.*   Checks if the transmitter is ready and sends the 32 bit word "data"*   if that is the case. Retries a maximum of try_count-1 times before*   it returns.* PARAMETERS:*   ctrlword:   Pointer to the control word value to write to the NI.*   data:       Pointer to the data word value to write to the NI.*               On the mMIPS this address needs to be on an address*               divideable by 4. Only the first 32 bits are copied.*   try_count:  Number of times to check the control word to see if the*               transmitter is ready to send data. A negative value*               results in a blocking send (infinite number of retries).* RETURN VALUE:*   One of the predefined SC_COMMERR_ error values or SC_COMMERR_SUCCESS*   if the operation completed successfully.****************************************************************/int sc_receive(void *data, const int size_in_bytes);/***************************************************************** DESCRIPTION: Tries to receive a block of the given number of bytes.*   Uses sc_receive_word() to receive each 4 byte word in data. The max.*   retry_count for each call to sc_receive_word() is given by*   try_count_sc_receive.* PARAMETERS:*   address:    Relative address of (or distance to) the destination*               node.*   data:       Pointer to the loctation where the received data is*               to be stored.*               May be any address (not necessarily divideable by 4).*   size_in_bytes:  Number of bytes to send.* RETURN VALUE:*   Returns the number of bytes that were successfully sent or minus*   size_in_bytes if the rcv_eop bit of the last read of the data word*   wasn't 1 (which could indicate an error).****************************************************************/int sc_receive_word(int *ctrlword, int *data, int try_count);/***************************************************************** DESCRIPTION: Tries to receive a 32 bit word.*   Checks if the receiver is ready and reads the 32 bit word in "data"*   if that is the case. Retries a maximum of try_count-1 times before*   it returns.* PARAMETERS:*   ctrlword:   Pointer to the control word value to read from the NI.*   data:       Pointer to the data word value to read from the NI.*               On the mMIPS this address needs to be on an address*               divideable by 4.*   try_count:  Number of times to check the control word to see if the*               receiver has data waiting to be sent. A negative value*               results in a blocking receive (infinite number of retries).* RETURN VALUE:*   One of the predefined SC_COMMERR_ error values or SC_COMMERR_SUCCESS*   if the operation completed successfully.****************************************************************/#ifdef CC_I386#ifdef DEBUG2FILEint sc_send_wordf(const int *ctrlword, const int *data);/***************************************************************** DESCRIPTION: Saves the ctrlword and *data (in that order) to the file*   output_to_0xZZ.bin, where bin is the destination node address*   (= *ctrlword & 0xFF). Always successful.* PARAMETERS:*   ctrlword:   Pointer to the control word value that is saved first.*   data:       Pointer to the data word value that is saved next.* RETURN VALUE:*   Always returns SC_COMMERR_SUCCESS.****************************************************************/int sc_receive_wordf(int *ctrlword, int *data);/***************************************************************** DESCRIPTION: Tries to receive a 32 bit word.*   Reads *ctrlword and *data from the file input.bin (in that order).*   The file pointer fi_pos is thereafter increased by 8.* PARAMETERS:*   ctrlword:   Pointer to the control word value to read first.*   data:       Pointer to the data word value to read next.* RETURN VALUE:*   Returns SC_COMMERR_SUCCESS if there was data in input.bin at the*   current fi_pos, SC_COMMERR_FAILURE otherwise.****************************************************************/#endif#endif#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?