/* * * * binary.h * * * */ /* * * * * * * * * * * * */ /* hostspec.h This file contains host-specific definitions for DSP initialization and communication. Modified 15-May-1995 */ /* 32-bit compilers */ typedef int int32; /* int32 is a signed 32-bit integer */ typedef unsigned int u_int32; /* uint32 is an unsigned 32-bit integer */ /********************** time-related definitions ***********************/ /* choose one of the following #if blocks or add your own */ /* if standard C library time functions are available */ #include /* function that returns clock ticks since t == t0 */ #define CLOCK() clock() /* number of clock ticks before timeout, set to ~2 seconds */ #define TIMEOUT_PERIOD (200000) /* number of clock ticks to wait while DSP's reset, set to > 750 ms */ #define DSP_RES_PERIOD (100000) /* if no time functions are available */ /* simple clock: one tick per call */ /*#define CLOCK() simp_clock() */ /* number of clock ticks before timeout, set to ~2 seconds */ /*#define TIMEOUT_PERIOD (200000) */ /* assumes 10 usec per CLOCK() call */ /* number of clock ticks to wait while DSP's reset, set to > 750 ms */ /*#define DSP_RES_PERIOD (100000) */ /* assumes 10 usec per CLOCK() call */ /***************** end of time-related definitions *********************/ /* Error logging functions: log_err() and log_boot() use printf() to print out error messages. Other functions may be subsituted for log_err() and log_boot(). To access some global variables, functions may be included in hos_init.c */ /* max number of errors to log; subsequent errors are counted but not logged */ #define MAX_ERR_LOG (50) /* parm1 = int error code, parm2 = char* error message */ /* note that a host-specific offset may be added to parm1 here */ #define LOG_ERR(parm1, parm2) log_err((1000+parm1), parm2) /* log error */ /* parm1 = dsp_no */ #define LOG_BOOT(parm1) log_boot(parm1) /* log contents of boot structure */ /**************************/ /* sys_pub.h */ /* public communication constants and function prototypes */ /* public == for use by the host system code and/or by the DSP system code */ /* private == for use by the developers of the communication system only */ /* This file has three parts: I, II, III. See below. */ /* I. Items here are for use by software running in the host or in the DSP. */ /* message system error codes */ #define SUCCESS 0 #define ENOSIG 1 #define EABORT 2 #define ENOMESS 3 #define ECONFLICT 4 #define EEBUSY 5 #define ETOOBIG 6 #define EMESSINVAL 7 #define ETIMEOUT 8 #define NUM_FLAGS 64 #define NUM_CHAN 7 #define DPRAM_SIZE 0x800 #ifdef I_AM_HOST /* II. Items here are for use by software running in the host. */ /* constants */ /* status codes returned in dsp_status by download system */ #define DOWN_DONE ( 0) /* download done without errors */ #define DOWN_INCOMPLETE (0xA00) /* no DSP errors, but download is not done */ #define DOWN_TIMEOUT (0xA01) /* DSP timed out */ #define DOWN_ERROR (0xA02) /* Some error besides timeout */ /* function prototypes */ /* reset and initialize DSP's, then download system */ int init_dsps( int dsp_min, int dsp_max, char* path ); int* dsp_base( int dsp_no ); /* return pointer to base of DSP's DPRAM */ void dsp_led( int, int ); /* turn the host's red LED on or off */ void interrupt_dsp( int ); /* cause a DSP interrupt */ int send_mess( int * ); int get_mess( int ); int get_flag( int, int ); int set_flag( int, int, int ); int message_status( void ); int check_mess( int ); #endif #ifdef I_AM_DSP /* III. Items here are for use by software running in the DSP. */ /* constants */ /* function prototypes */ int export_mess(int *); int import_message( void ); int m_wait(int); int accept( void ); int com_abort( void ); void clear_signals( int ); int get_flag(int); int set_flag(int, int); int import_code( void ); int message_status( void ); int check_mess( void ); #endif /*******************************/ /* sys_priv.h */ /* private communication constants and function prototypes */ /* public == for use by the host system code and/or by the DSP system code */ /* private == for use by the developers of the communication system only */ /* This file has three parts: I, II, III. See below. */ /* I. Items here are for use by software running in the host or in the DSP. */ #define IMPORT 0 #define EXPORT 1 #define DAV 2 #define ACK 3 #define EOM 4 #define ABORT 5 #define MTU 1024 #define LOOKUPS 3 typedef struct { int id; int timestamp; int return_add; int size; } t_head; typedef struct { t_head header; int message[MTU]; } transport; typedef struct { u_int32 boot[16]; /* reserved for DSP's system download code */ volatile int signals; transport packet ; volatile int flags[NUM_FLAGS]; } dpr; #ifdef I_AM_HOST /* II. Items here are for use by software running in the host. */ /* constants */ dpr *io_base[NUM_CHAN]; #define MESS_TIMEOUT (2000000) #define PORT_OFFSET DPRAM_SIZE #define TMESSID(x) io_base[x]->packet.header.id #define TTIME(x) io_base[x]->packet.header.timestamp #define TRETURN(x) io_base[x]->packet.header.return_add #define TSIZE(x) io_base[x]->packet.header.size #define FLAG(x,y) io_base[x]->flags[y] #define DO_T_HEAD(x) io_base[x]->packet.header.id = mess_id; \ io_base[x]->packet.header.timestamp = time; \ io_base[x]->packet.header.return_add = iam; \ io_base[x]->packet.header.size = remain #define MCIW(x) x->ciw #define MSIZE(x) x->len #define MDEST(x) x->dsp /* function prototypes */ int get_port( int ); void set_port( int, int ); int sys_set(int, int); int sys_clear(int, int); int sys_wait(int, int); int sys_nwait(int, int); /* int copy_header( void ); FIXME -- Is this needed? */ void copy( int *, int *, int ); void zero( int *, int ); int look( int, int ); /* void com_aborted( int ); FIXME -- Is this needed? */ int __check_mess( int ); #endif #ifdef I_AM_DSP /* III. Items here are for use by software running in the DSP. */ /* constants */ dpr *io_base = (dpr *) HL_BASE; /* function prototypes */ #define TMESSID(x) io_base->packet.header.id #define TTIME(x) io_base->packet.header.timestamp #define TRETURN(x) io_base->packet.header.return_add #define TSIZE(x) io_base->packet.header.size #define FLAG(y) io_base->flags[y] #define DO_T_HEAD(x) io_base->packet.header.id = mess_id; \ io_base->packet.header.timestamp = time; \ io_base->packet.header.return_add = iam; \ io_base->packet.header.size = remain #define MCIW(x) x->ciw #define MSIZE(x) x->len int sys_set(int); int sys_clear(int); int sys_wait(int); int sys_nwait(int); int copy_header( void ); void copy( int *, int *, int ); void zero( int *, int ); int look( int ); void com_aborted( int ); int __check_mess( void ); #endif /*******************************/ /**********************************************************************/ /* sys_gen.h */ /* sys_mem.h definitons of memory blocks */ /* sys_generic.h definition of generic message, header, */ /* message length, header length */ /* sys_mess.h definitions of VME -> DSP messages */ /* sys_action_id.h definitions of action_id */ /* sys_flags.h definitions of flags */ /* sys_error_codes.h definitions of error_codes */ /* sys_response_codes.h definition of response codes */ /**********************************************************************/ /*********************************************************************/ /* MEMORY BLOCKS */ /*********************************************************************/ #define EXT0_SIZE 0x40000 #define EXT1_SIZE 0x40000 #define CODE_BLOCKSIZE 0x2800 /* size of RAM block allocated for code */ /* 0x800: boot code, 0x2000 code */ #define MESS_BLOCKSIZE 0x2000 /* size of message buffer in RAM */ #define TRIG_BLOCKSIZE 0x2000 /* size of block where trigger info is stored */ #define DATA_BLOCKSIZE (EXT0_SIZE - CODE_BLOCKSIZE - MESS_BLOCKSIZE \ - TRIG_BLOCKSIZE) /* size of block in RAM where data is stored: */ /* add EXT1_SIZE if expansion RAM card available*/ /**********************************************************************/ /* MESSAGES: */ /**********************************************************************/ /**********************************************************************/ /* sys_generic.h: */ /* sys_messhead.h message header definition */ /* sys_gener_mess.h structure definitions of generic message */ /**********************************************************************/ /* sys_messhead.h */ /* MESSAGE HEADER */ /**********************************************************************/ #define HEADER u_int32 ciw; \ u_int32 len; \ u_int32 dsp; \ u_int32 dsp_dipsw; \ u_int32 channel; \ u_int32 host_ciw; \ u_int32 spare[5];/* message header */ /* ciw: command identifier word*/ /* ciw: flag | action_id */ /* len: message length */ /* dsp: dsp # */ /* dsp_dipsw: dsp dip switch */ /* setting */ /* channel: unit/channel # */ /* serviced by dsp dsp*/ /* spare: spare */ /**********************************************************************/ /* sys_gener_mess.h */ /* GENERIC MESSAGE: STRUCTURE DEFINITION */ /* HEADLEN, MESSLEN definitions */ /**********************************************************************/ /**********************************************************************/ /* generic message */ /**********************************************************************/ struct m_generic { HEADER }; typedef struct m_generic m_generic; /**********************************************************************/ #define HEADLEN sizeof(m_generic)/sizeof(int32) /* header length DSP: 1 byte = 1 word (32 bits) for testing on other machines: divide by 4 */ #define MESSLEN MESS_BLOCKSIZE /* maximum message length in */ /* SRAM message buffer */ /* xxx + HEADLEN */ #define MAX_MESS_ARRAY (MESS_BLOCKSIZE - HEADLEN) /**********************************************************************/ /**********************************************************************/ /* sys_mess.h */ /* GENERAL MESSAGES: STRUCTURE DEFINITIONS */ /**********************************************************************/ /**********************************************************************/ /* messages from VME to DSP */ /**********************************************************************/ /**********************************************************************/ /* ECHO */ /**********************************************************************/ struct m_echo { HEADER int32 data[MAX_MESS_ARRAY]; }; typedef struct m_echo m_echo; /**********************************************************************/ /* MESSAGE_TEST */ /**********************************************************************/ struct m_message_test { HEADER int32 tmess_size; int32 startval; int32 delta; }; typedef struct m_message_test m_message_test; /**********************************************************************/ /* INITIALIZE */ /* # of parameters: 1 run_mode: 0: data transmission at end of burst upon request 1: data transmission for each event (real time) */ /**********************************************************************/ struct m_init { HEADER }; typedef struct m_init m_init; /**********************************************************************/ /* DISABLE_READOUT */ /* # of parameters: 0 */ /**********************************************************************/ struct m_disable_read { HEADER }; typedef struct m_disable_read m_disable_read; /**********************************************************************/ /* ENABLE_READOUT */ /* # of parameters: 0 */ /**********************************************************************/ struct m_enable_read { HEADER }; typedef struct m_enable_read m_enable_read; /**********************************************************************/ /* SELECT_RUN_MODE */ /* # of parameters: 1 */ /**********************************************************************/ struct m_sel_run { HEADER int32 runmode ; /* run mode: 0: data transmission at end of burst 1: data transmission event by event in real time */ }; typedef struct m_sel_run m_sel_run; /**********************************************************************/ /* SELECT_TRIGGER_MODE */ /* # of parameters: 4 */ /**********************************************************************/ struct m_sel_trig { HEADER int32 trignum[4]; /* # of trigger accepts per trigger from source 0-3 */ }; typedef struct m_sel_trig m_sel_trig; /**********************************************************************/ /* SELECT_ALIGN_DELAY */ /* # of parameters: 2 */ /**********************************************************************/ struct m_align_delay { HEADER int32 delay1; /* delay for trigger alignment fifo 1 */ int32 delay2; /* delay for trigger alignment fifo 2 */ }; typedef struct m_align_delay m_align_delay; /**********************************************************************/ /* SELECT_TIME_PARAM */ /* # of parameters: 3 */ /**********************************************************************/ struct m_sel_time { HEADER int32 tr_time ; /* time interval to read trigger counter and fifo */ int32 rt_rtout; /* timeout for readout routine (RT_TRANSFER mode) */ int32 t_addoff; /* offset for 13 bit graycode address (trigger fifo)*/ }; typedef struct m_sel_time m_sel_time; /**********************************************************************/ /* SET_DAC */ /* # of parameters: 2 */ /**********************************************************************/ struct m_set_dac { HEADER int32 dac; /* DAC: (DSP card: 0-3) */ int32 voltage; /* voltage: (0-4095) */ }; typedef struct m_set_dac m_set_dac; /**********************************************************************/ /* LOAD_GRAYCODE_PATTERN */ /* # of parameters: 256 */ /**********************************************************************/ struct m_load_gray { HEADER int32 graycode[256]; /* data */ }; typedef struct m_load_gray m_load_gray; /**********************************************************************/ /* CALIBRATE */ /* # of parameters: 3 */ /* 1) # of triggers to generate for calibration run */ /* 2) take_data (0 or 1) */ /* 3) user parameter */ /**********************************************************************/ struct m_calib { HEADER int32 acqui_events; int32 take_data; int32 user_par; }; typedef struct m_calib m_calib; /**********************************************************************/ /* LOAD_DATA */ /* # of parameters: MAX_MESS_ARRAY */ /**********************************************************************/ struct m_load_data { HEADER int32 data_format; /* data format: */ int32 data_word[MAX_MESS_ARRAY]; /* data */ }; typedef struct m_load_data m_load_data; /**********************************************************************/ /* TRANSFER_DATA */ /* # of parameters: 1 */ /**********************************************************************/ struct m_transfer_data { HEADER int32 data_format; }; typedef struct m_transfer_data m_transfer_data; /**********************************************************************/ /* VALIDATE_DATA */ /* # of parameters: 0 */ /**********************************************************************/ /**********************************************************************/ /* GET_DSP_STATUS */ /* # of parameters: 0 */ /**********************************************************************/ /*********************************************************************/ /* MESSAGES FROM DSP TO VME */ /*********************************************************************/ /**********************************************************************/ /* DSP_STATUS */ /* # of parameters: 14 */ /**********************************************************************/ struct m_dsp_status { HEADER int32 dac_setting[4]; int32 al_delay_setting[2]; int32 runmode; int32 ro_enabled; int32 tcc_connected; int32 tr_time; int32 rt_rtout; int32 t_addoff; int32 trig_timer_val; int32 clock_timer_val; }; typedef struct m_dsp_status m_dsp_status; /**********************************************************************/ /* DATA_SUMMARY */ /* # of parameters: 3 */ /**********************************************************************/ struct m_data_summary { HEADER int32 flag; /* = 0 : # triggers = # data blocks = 1 : error = -1 : no trigger information */ int32 numtrig; /* # triggers */ int32 numdat; /* # data blocks */ }; typedef struct m_data_summary m_data_summary; /**********************************************************************/ /* RESET_DONE */ /* # of parameters: 1: boot code version */ /**********************************************************************/ struct m_reset_done { HEADER int32 bootver; }; /**********************************************************************/ /* CODE_LOADED */ /* # of parameters: 2: code version */ /* parameter 1: system code version */ /* parameter 2: system communication and user code versions */ /**********************************************************************/ struct m_code_loaded { HEADER int32 codever_sys; int32 codever_scom_us; }; typedef struct m_code_loaded m_code_loaded; /**********************************************************************/ /* RESPONSE */ /* # of parameters: 1 */ /**********************************************************************/ struct m_response { HEADER int32 response_code; }; typedef struct m_response m_response; /**********************************************************************/ /* FATAL_ERROR */ /* # of parameters: 1 */ /**********************************************************************/ struct m_fatal_error { HEADER int32 error_code; }; typedef struct m_fatal_error m_fatal_error; /**********************************************************************/ /* ERROR_REPORT */ /* # of parameters: 1 */ /**********************************************************************/ struct m_error_report { HEADER int32 error_code; }; typedef struct m_error_report m_error_report; /**********************************************************************/ /* ACTION_ID: */ /**********************************************************************/ /**********************************************************************/ /* sys_action_id.h */ /* GENERAL MESSAGES: DEFINITIONS OF action_id */ /**********************************************************************/ /* system: action_id 1-99 */ /* messages VME->DSP: 1-49 */ /* messages DSP->VME: 50-79 */ /* error messages DSP->VME: 80-99 */ /* pixels: action_id 100-199 */ /* strips: action_id 200-299 */ /**********************************************************************/ /* Messages/Action initiated by VME CPU */ /**********************************************************************/ #define INITIALIZE 1 #define DISABLE_READOUT 3 #define ENABLE_READOUT 4 #define SELECT_TRIGGER_MODE 5 #define TRANSFER_DATA 6 #define SET_DAC 9 #define SELECT_ALIGN_DELAY 11 #define LOAD_GRAYCODE_PATTERN 12 #define LOAD_CODE 14 #define LOAD_DATA 15 #define CALIBRATE 16 #define SELECT_RUN_MODE 17 #define SELECT_TIME_PARAM 18 #define ECHO 19 #define MESSAGE_TEST 20 #define GET_DSP_STATUS 21 #define VALIDATE_DATA 22 /**********************************************************************/ /* Messages sent from DSP to VME */ /**********************************************************************/ #define DATA_TRANSFER 50 #define DATA_SUMMARY 51 #define RESET_DONE 52 #define RESPONSE 53 #define CODE_LOADED 54 #define ECHO_REPLY 55 #define TEST_MESSAGE 56 #define DSP_STATUS 57 /**********************************************************************/ /* Error messages sent from DSP to VME */ /**********************************************************************/ #define FATAL_ERROR 80 #define ERROR_REPORT 81 /**********************************************************************/ /* sys_error_codes.h */ /* ERROR CODE DEFINITIONS */ /**********************************************************************/ /* fatal errors: reported by message fatal_error */ #define NO_LL 1 /* low level card not present */ #define NO_HL 2 /* high level card not present */ #define RO_ERROR 3 /* readout error */ #define MEM_OVERFLOW 4 /* memory overflow */ #define INVALID_RUNMODE 5 #define INVALID_AL_DELAY 6 #define GRAYCODE_TOO_LONG 7 #define INVALID_LINK 8 #define COMMAND_UNKNOWN 9 #define FORMAT_UNKNOWN 10 #define MESSAGE_TOO_LONG 11 /* other errors: reported by message error_report */ #define INVALID_DAC_VALUE 50 #define INVALID_DESTINATION_DAC 51 #define TRIG_ERROR 52 /* error reading trigger info */ #define NO_DET_DATA 53 #define NO_TRIG_DATA 54 #define NO_DATA 55 /**********************************************************************/ /* sys_com_error_codes.h */ /* communication error codes */ /**********************************************************************/ /* these error codes moved into file sys_pub.h */ /**********************************************************************/ /* sys_response_codes.h */ /* RESPONSE CODE DEFINITIONS */ /**********************************************************************/ #define DONE 0 #define ACCEPTED 1 #define REFUSED 2 /**********************************************************************/ /* sys_flags.h */ /* DEFINITIONS OF FLAGS */ /**********************************************************************/ #define SOB_SIG_FLAG 0 #define EOB_SIG_FLAG 1 #define TRIGGER_FLAG 2 #define DSP_DATA_READY_FLAG 3 #define DSP_STATE 4 #define ABORT_FLAG 5 #define VERBOSE_FLAG 6 #define BOOT_CODE_VERSION 7 #define HOST_STATE 8 #define CODEVER_SYS 9 #define CODEVER_SCOM_US 10 /**********************************************************************/ /* DEFINITIONS OF DSP_STATE FLAG VALUES */ /* */ /* RESET_COMPLETE = 4: reset done, boot code running, */ /* dsp is waiting for message load_code */ /* DOWNLOAD_COMPLETE = 5: code loaded and running */ /* IDLE = 1: dsp is waiting for */ /* start of burst signal or messages */ /* EXECUTING = 2: dsp is executing action initiated by message */ /* BURST_LOOP = 3: dsp is in burst-loop */ /* (reading data, waiting for end of burst signal)*/ /* */ /* values 20 - 60: states reserved for strips code */ /* values 61 - 100: states reserved for pixel code */ /**********************************************************************/ #define IDLE 1 #define EXECUTING 2 #define BURST_LOOP 3 #define RESET_COMPLETE 4 #define DOWNLOAD_COMPLETE 5 /**********************************************************************/ /* DEFINITIONS OF HOST_STATE FLAG VALUES */ /**********************************************************************/ #define HS_RESETTING_DSP 0xfadedbad #define HS_READY 0x0 /**********************************************************************/ /* RUN_MODE DEFINITIONS */ /**********************************************************************/ #define EOB_TRANSFER 0 #define RT_TRANSFER 1 #define CALIBRUN 2 /**********************************************************************/ /* OTHER DEFINITIONS */ /**********************************************************************/ #define MAX_AL_DELAY 255 #define MAX_GRAYCODE 256 #define MAX_DATA_FORMAT 10 #define DSP_LED_G 2 /* output port bit numbers */ #define DSP_LED_Y 1 #define DSP_LED_R 0 #define DSP_LED_ON 0 #define DSP_LED_OFF 1 /***************************/ /* Do not modify this file. Report bugs or desired changes to: Steve Pier University of California, Irvine pier@nucleus.ps.uci.edu 714-824-3162 */ /* eboot.h include file common to eboot.c and dsp_init.c */ /*** DO NOT CHANGE THIS FILE. *** *** Boot code in the DSP's EEPROM uses this file. ***/ /* 16 words at the beginning of the DPRAM are reserved for the boot ROM's use. */ /* DSP boot states (written by DSP) */ #define DBS_RESETTING (0) /* DSP has not finished resetting; DBS_RESETTING must be 0 */ #define DBS_INITIALIZING (1) /* DSP is initializing boot structure */ #define DBS_READY (2) /* ready to start download */ #define DBS_DOWNLOADING (3) /* download has begun */ #define DBS_DOWNLOAD_OK (4) /* the downloaded code is running */ #define ERR_FIRST_WORD (0xA0) /* these error codes may appear in dsp_bstate */ #define ERR_PAGE_FAILED (0xA1) #define ERR_BLK_SIZE (0xA2) #define ERR_BLK_DEST (0xA3) /* host boot states (written by host) */ #define HBS_RESETTING (0xf00ba123) /* forces delay of start of boot */ #define HBS_IDLE (0) /* HBS_IDLE must be 0 */ #define HBS_READY (0x0ad00dad) /* causes DSP to proceed with boot */ #define PAGE_SIZE (512) /* number of u_int32's in a page */ #define HAND_HI (0xff) /* legal handshake values for req and ack */ #define HAND_LO (0) /* This structure is in the VME card's dual-port RAM. Members of this structure are written by the DSP unless noted otherwise. ! The first member of boot_dpr must be host_bstate ! ! The second member of boot_dpr must be boots ! */ struct boot_dpr { u_int32 host_bstate; /* host boot state, written by host */ u_int32 boots; /* number of boots (set to 0 by host) */ u_int32 rom_rev; /* boot ROM revision number */ u_int32 dip_switches; /* ddddvvvvvvvv, d = DSP's dip switch, v = VME card's dip switch */ u_int32 dsp_bstate; /* DSP boot state */ u_int32 req, ack; /* handshake flags, ack is written by host */ u_int32 lo_mem, hi_mem; /* external ram available during boot */ u_int32 words_read; /* words of system downloaded so far */ u_int32 ram_loops, ram_errors; /* memory test information */ u_int32 dummy [ 4 ]; /* fill in unused words to make 16 total */ u_int32 zero[ 8 ]; /* zeroes (used by messaging system) */ u_int32 page[ PAGE_SIZE ]; /* block through which system code is transferred */ }; /* The meaning of some words used in this and related files: The word 'host' refers to the CPU that is in communication with the DSP. This CPU may be a VME card, a MacIntosh, or other computer that has access to the VMEbus. The word 'page' refers to the units into which the system file is divided as it is sent to the DSP. The system file is too big to be sent through the DSP's dual-port RAM all at once, so it is divided into pages. (The system file is converted to binary before being divided into pages and sent through the DPRAM.) The word 'block' refers to the data blocks described in "Format of System File" below. These are the blocks recognized by the 320C31's boot loader as well as the system loader coded in eboot.c. The word 'download' refers to the process of loading the DSP's operating system into the DSP's memory. The operating system is stored in an ASCII file on the host's file system. The function init_dsps() (in dsp_init.c) reads in this file, converts it to binary, and sends it to the DSP. The DSP loads it into RAM in the same way the the 320C31's built-in bootloader loads code from ROM. In fact, the system file, once converted to binary, is in the format used by the built-in bootloader. */ /* The boot process as seen by the VME host: The VME host sets host_bstate to HBS_RESETTING. The VME host resets the DSP. The VME host zeroes all of the DPRAM except host_bstate. The VME host sets dsp_bstate to DBS_RESETTING. The VME host sets host_bstate to HBS_IDLE, allowing DSP RAM tests to proceed. The VME host waits until dsp_bstate is DBS_READY. The VME host sets host_bstate to HBS_READY. When dsp_bstate is DBS_DOWNLOADING, downloading begins. The boot process as seen by the DSP: The DSP is reset (by the host or on power-up). The DSP waits if host_bstate is HBS_RESETTING (unlikely at power-up). The DSP sets dsp_bstate to DBS_INITIALIZING. The DSP initializes its hardware and the boot structure. The DSP sets dsp_bstate to DBS_READY. The DSP starts the download if host_bstate is HBS_READY. If host_bstate is not HBS_READY, the DSP runs one loop of a RAM test. If host_bstate is HBS_READY, downloading begins. The download process as seen by the VME host: If req is true, the host reads one page of code into the DPRAM. It then sets ack true and waits for req to go false. It then sets ack false. The host checks for a variety of errors. The download process as seen by the DSP: The DSP sets dsp_bstate to DBS_DOWNLOADING. The DSP calls get_word() repeatedly until all code is loaded. get_word() calls get_page() as necessary. get_page() handshakes with the host as necessary. If the DSP detect errors, it reports them in dsp_bstate and halts. If there are no errors, the DSP sets dsp_bstate to DBS_DOWNLOAD_OK. The DSP turns on all DSP LED's and transfers control to the downloaded code. The req/ack handshake: req is controlled by the DSP ack is controlled by the host req: ________~~~~~~~~~~~~~~~~~~~~~~~~_________________~~~~~~~~~~~ ack: _____________________________~~~~~__________________________ - host -|--- host copies ---| |-- DSP loads --|- next --> waits page to DPRAM page into RAM handshake for req */ /* Format of System File: The system is stored in an ASCII file. This file is the output of the hex30 program (by Texas Instruments). The hex30 program is instructed to output an ascii (-a option) file of bootable code. The resulting file starts with a ctrl-B (02h), continues with hex data bytes separated by white space, and ends with a ctrl-C (03h): ^B XX XX XX XX XX XX ... XX ^C XX represents a hex byte. A group of four hex bytes represents a 32-bit word, with the MSB first: 33 22 11 00 represents the 32-bit hex number 0x33221100. The 32-bit numbers are in exactly the 32-bit format used by the 320C31's built-in boot loader (not to be confused with the code in the file eboot.h). The format is detailed in the TMS320C3x User's Guide. A brief description: word value comments ---- ---------- ---------------------------------------------------- 0 0x00000020 memory width (always = 32) 1 -- ignored by eboot.c 2 size1 size of first data block 3 dest1 destination (address in memory) for first data block . data data words (total of size1) . data . ... . size2 size of second data block . dest2 destination for second data block . data data words (total of size2) . data . ... . sizeN size of last data block . destN destination for last data block . data data words (total of sizeN) . data . ... . 0x00000000 size == 0 indicates no more data blocks Execution will begin at dest1 (the beginning of the first data block). The DSP is passed only the binary version of this data. I.e., the host reads the ASCII file and sends the binary equivalent to the DSP during the system download process. */ /***********************/ /**********************************************************************/ /* strips.h, ucsc.h */ /**********************************************************************/ /* this part is only included if: #define I_AM_DSP */ /* us_LL_ports.h initialization of LL ports */ /* us_var_point.h static variables, */ /* constant pointer definitions */ /**********************************************************************/ /* this part is always included */ /* us_mess.h structure definitions of user messages */ /* us_action_id.h definitions of action_id */ /* us_error_codes.h definitions of error codes */ /* us_response_codes.h definitions of response codes */ /**********************************************************************/ /* this part is only included if: #define I_AM_DSP */ /* us_defaults.h default values */ /* us_sys.h prototype definitions */ /* us.h prototype definitions */ /**********************************************************************/ #ifdef I_AM_DSP #define CODE_VER_UH 0x200 /**********************************************************************/ /* SLL PORTS */ /**********************************************************************/ #define SLL_IN_INFLAG (LL_BASE + 0x0) #define SLL_IN_OUTFLAG (LL_BASE + 0x80) #define SLL_IN_FIFO0 (LL_BASE + 0x200) #define SLL_IN_FIFO1 (LL_BASE + 0x280) #define SLL_IN_FIFO2 (LL_BASE + 0x300) #define SLL_IN_FIFO3 (LL_BASE + 0x380) #define SLL_OUT_DACMISC (LL_BASE + 0x0) #define SLL_OUT_COUNT (LL_BASE + 0x80) #define SLL_OUT_DELAY (LL_BASE + 0x100) #define SLL_OUT_FIFO (LL_BASE + 0x180) #define SLL_OUT_NEXT0 (LL_BASE + 0x200) #define SLL_OUT_NEXT1 (LL_BASE + 0x280) #define SLL_OUT_NEXT2 (LL_BASE + 0x300) #define SLL_OUT_NEXT3 (LL_BASE + 0x380) /*******************************************************************/ /* BIT DEFINITIONS FOR SLL PORTS: */ /*******************************************************************/ #define SLL_OUTFLAG0 0 /* output fifo flags */ #define SLL_OUTFLAG1 1 #define SLL_OFIFO_RESET 0 #define SLL_OFIFO_GO 1 /**********************************************************************/ /* DEFINITION OF PORTS */ /**********************************************************************/ #define SLL_DATIN0 0 #define SLL_DATIN1 1 #define SLL_DATIN2 2 #define SLL_DATIN3 3 #define SLL_INFLAG 4 #define SLL_OUTFLAG 5 #define SLL_DACMISC 6 #define SLL_COUNTER 7 #define SLL_DELAY 8 #define SLL_DATOUT 9 #define SLL_NEXT0 10 #define SLL_NEXT1 11 #define SLL_NEXT2 12 #define SLL_NEXT3 13 #define A_SLL_INFLAG (int *) SLL_IN_INFLAG #define A_SLL_OUTFLAG (int *) SLL_IN_OUTFLAG #define A_SLL_DATIN0 (int *) SLL_IN_FIFO0 #define A_SLL_DATIN1 (int *) SLL_IN_FIFO1 #define A_SLL_DATIN2 (int *) SLL_IN_FIFO2 #define A_SLL_DATIN3 (int *) SLL_IN_FIFO3 #define A_SLL_DACMISC (int *) SLL_OUT_DACMISC #define A_SLL_COUNTER (int *) SLL_OUT_COUNT #define A_SLL_DELAY (int *) SLL_OUT_DELAY #define A_SLL_DATOUT (int *) SLL_OUT_FIFO #define A_SLL_NEXT0 (int *) SLL_OUT_NEXT0 #define A_SLL_NEXT1 (int *) SLL_OUT_NEXT1 #define A_SLL_NEXT2 (int *) SLL_OUT_NEXT2 #define A_SLL_NEXT3 (int *) SLL_OUT_NEXT3 /**********************************************************************/ /* INPUT PORT MASKS */ /**********************************************************************/ #define M_SLL 0xff /**********************************************************************/ /* INITIALIZATION OF PORTS */ /**********************************************************************/ struct LL_ports LL_port[LL_MAXPORTS] = { {A_SLL_DATIN0, 0}, {A_SLL_DATIN1, 0}, {A_SLL_DATIN2, 0}, {A_SLL_DATIN3, 0}, {A_SLL_INFLAG, 0}, {A_SLL_OUTFLAG, 0}, {A_SLL_DACMISC, 0xc3}, {A_SLL_COUNTER, 0}, {A_SLL_DELAY, 0}, {A_SLL_DATOUT, 0}, {A_SLL_NEXT0, 0x1}, {A_SLL_NEXT1, 0x1}, {A_SLL_NEXT2, 0x1}, {A_SLL_NEXT3, 0x1}}; volatile int *LL_port_add[LL_MAXPORTS] = { {A_SLL_DATIN0}, {A_SLL_DATIN1}, {A_SLL_DATIN2}, {A_SLL_DATIN3}, {A_SLL_INFLAG}, {A_SLL_OUTFLAG}, {A_SLL_DACMISC}, {A_SLL_COUNTER}, {A_SLL_DELAY}, {A_SLL_DATOUT}, {A_SLL_NEXT0}, {A_SLL_NEXT1}, {A_SLL_NEXT2}, {A_SLL_NEXT3}}; volatile int LL_port_cval[LL_MAXPORTS] = { {0}, {0}, {0}, {0}, {0}, {0}, {0xc3}, {0}, {0}, {0}, {0x1}, {0x1}, {0x1}, {0x1}}; /**********************************************************************/ /**********************************************************************/ /* POINTER DEFINITIONS */ /**********************************************************************/ /* p_indata[NUMLINKS]: points to input data block from links */ /* p_ctrout_block[4]: points to output control blocks */ /* (to be loaded into output fifo) */ /* inflag_mask[NUMLINKS]: masks input fifo flag bits for link i */ /* inflag2_mask[NUMLINKS]: masks input fifo flag F2 bit for link i */ /* mask_inflag2: masks input fifo flag F2 bits */ /**********************************************************************/ #define INDATA_BASE (DATA_BASE + HEADLEN + 1) #define NUMLINKS 4 /* number of links connected to DSP */ #define CTROUT_BLOCKSIZE (2048 +1) /* size of control block buffer in RAM */ #define INDATA_BLOCKSIZE (DATA_BLOCKSIZE/NUMLINKS \ - (HEADLEN + 1) \ - 4*CTROUT_BLOCKSIZE) const int *p_indata[NUMLINKS] = { (int *) INDATA_BASE, (int *) (INDATA_BASE + HEADLEN + 1 + INDATA_BLOCKSIZE), (int *) (INDATA_BASE + 2*(HEADLEN + 1) + 2*INDATA_BLOCKSIZE), (int *) (INDATA_BASE + 3*(HEADLEN + 1) + 3*INDATA_BLOCKSIZE)}; #define CTROUT_BASE \ (INDATA_BASE + 4*(HEADLEN + 1 + INDATA_BLOCKSIZE) + 0x0) const int *p_ctrout_block[4] = { (int *) CTROUT_BASE, (int *) (CTROUT_BASE + CTROUT_BLOCKSIZE), (int *) (CTROUT_BASE + 2*CTROUT_BLOCKSIZE), (int *) (CTROUT_BASE + 3*CTROUT_BLOCKSIZE)}; const int def_inflag_mask[NUMLINKS] = {0x3,0xc,0x30,0xc0}; const int def_inflag2_mask[NUMLINKS] = {2,8,32,128}; int inflag_mask[NUMLINKS] = {0x3,0xc,0x30,0xc0}; int inflag2_mask[NUMLINKS] = {2,8,32,128}; int mask_inflag2 = 0xaa; int mask_inflag = M_SLL; /**********************************************************************/ /* VARIABLES */ /**********************************************************************/ /* LL_dac_val[4] values LL DAC's are set to */ /* calib_block RAM control block to execute during calibration run */ /* packet_bytes number of bytes per data packet (counterval + 1) */ /* packets_expected number of packets expected after execution of ctr.*/ /* read_det_numcalls gets incremented whenever read_det is called */ /* out_of_phase set as soon as it was not possible to read 4 bytes */ /* det_read_timeout timeout for reading packets */ /* byte_count[NUMLINKS] number of bytes read from link */ /* indata_words[NUMLINKS]: 32-bit words read and stored in memory */ /* indata_blocks[NUMLINKS]: number of data blocks stored in memory */ /* data for 1 trigger accept = 1 data block */ /* indata_wordnum[NUMLINKS] 32-bit word to add byte read */ /**********************************************************************/ int LL_dac_val[4]; int LL_strobe_delay; int LL_counterval; int LL_link_enabled[4]; int calib_block; int packet_bytes; int packets_expected; int det_read_timeout; int gen_timeout; int out_of_phase; int read_det_numcalls; unsigned int byte_count[NUMLINKS]; int indata_words[NUMLINKS]; int indata_blocks[NUMLINKS]; int indata_wordnum[NUMLINKS]; #endif /**********************************************************************/ /* MESSAGES: */ /**********************************************************************/ /**********************************************************************/ /* us_mess.h */ /* USER MESSAGES: STRUCTURE DEFINITIONS */ /**********************************************************************/ /**********************************************************************/ /* LOAD_CONTROL_BLOCK */ /* parameters: 1+ 2048 MAX */ /**********************************************************************/ struct m_load_control { HEADER int32 blocknum; /* block will be loaded into RAM buffer blocknum */ int32 blockdata[2048]; /* control block to load */ }; typedef struct m_load_control m_load_control; /**********************************************************************/ /* EXECUTE_CONTROL_BLOCK */ /* parameters: 2 */ /**********************************************************************/ struct m_exe_control { HEADER int32 blocknum; /* RAM buffer block to execute */ int32 numexe; /* number of times to execute control block blocknum */ }; typedef struct m_exe_control m_exe_control; /**********************************************************************/ /* LOAD_EXE_CTR_BLK */ /**********************************************************************/ struct m_load_exe_ctr_blk { HEADER int32 take_data; int32 data_format; int32 numpackets; int32 blockdata[2048]; }; typedef struct m_load_exe_ctr_blk m_load_exe_ctr_blk; /**********************************************************************/ /* GET_DET_STATUS */ /* parameters: 2048 max */ /**********************************************************************/ struct m_get_det_status { HEADER int32 blockdata[2048]; /* control block to execute */ }; typedef struct m_get_det_status m_get_det_status; /**********************************************************************/ /* DET_STATUS Response message from DSP to GET_DET_STATUS */ /* parameters: 2048 max */ /**********************************************************************/ struct m_det_status { HEADER int32 data[2048]; /* status block from detector */ }; typedef struct m_det_status m_det_status; /**********************************************************************/ /* LL_STATUS */ /* parameters: 12 */ /**********************************************************************/ struct m_LL_status { HEADER int32 LL_dac_setting[4]; int32 LL_strobe_setting; int32 LL_counter_setting; int32 LL_timeout_setting[2]; int32 LL_link_enabling[4]; }; typedef struct m_LL_status m_LL_status; /**********************************************************************/ /* SET_LL_DAC */ /* # of parameters: 2 */ /**********************************************************************/ struct m_set_LL_dac { HEADER int32 dac; /* DAC: (LL card: 0-3) */ int32 voltage; /* voltage: (0-4095) */ }; typedef struct m_set_LL_dac m_set_LL_dac; /**********************************************************************/ /* SET_STROBE_DELAY */ /* parameters: 1 */ /**********************************************************************/ struct m_set_strobe_delay { HEADER int32 strobe_delay; /* strobe delay value */ }; typedef struct m_set_strobe_delay m_set_strobe; /**********************************************************************/ /* SET_COUNTER_VAL */ /* parameters: 1 */ /**********************************************************************/ struct m_set_counter_val { HEADER int32 count_val; /* input control counter value */ }; typedef struct m_set_counter_val m_set_counter; /**********************************************************************/ /* SET_TIMEOUT */ /* parameters: 2 */ /**********************************************************************/ struct m_set_timeout { HEADER int32 det_rd_timeout; int32 gen_timeout; }; typedef struct m_set_timeout m_set_timeout; /**********************************************************************/ /* DIS_ENABLE_LINK */ /* parameters: 1 */ /* = 0: disable link, = 1; enable link */ /**********************************************************************/ struct m_dis_enable_link { HEADER int32 link_enable; }; typedef struct m_dis_enable_link m_dis_enable_link; /**********************************************************************/ /* ACTION_ID: */ /**********************************************************************/ /**********************************************************************/ /* us_action_id.h */ /* USER MESSAGES: DEFINITIONS OF action_id */ /* strips: action_id 200-299 */ /* pixels: action_id 100-199 */ /**********************************************************************/ #define LOAD_CONTROL_BLOCK 200 #define EXECUTE_CONTROL_BLOCK 201 #define GET_DET_STATUS 202 #define DET_STATUS 203 #define SET_STROBE_DELAY 204 #define SET_COUNTER_VAL 205 #define SET_LL_DAC 206 #define GET_LL_STATUS 207 #define LL_STATUS 208 #define LOAD_EXE_CTR_BLK 209 #define SET_TIMEOUT 210 #define RESET_FIFOS 211 #define DIS_ENABLE_LINK 212 /**********************************************************************/ /* strips_error_codes.h */ /* ERROR CODE DEFINITIONS */ /**********************************************************************/ /* fatal errors: reported by message fatal_error */ /* other errors: reported by message error_report */ #define BLOCK_TOO_LONG 200 /* control block too long */ #define INVALID_BLOCK_NUMBER 201 /* valid blocks: 0-3 */ #define INVALID_COUNTER_VALUE 210 #define INVALID_DELAY_VALUE 211 #define TIMEOUT 212 #define TOO_FEW_PACKETS 213 /* read_packets did not receive */ /* expected number of packets */ /* within time limit given by */ /* det_read_timeout */ #ifdef I_AM_DSP /**********************************************************************/ /* us_defaults.h */ /* DEFAULTS */ /**********************************************************************/ #define RUN_MODE EOB_TRANSFER /* run-mode */ #define TRIG_PULSES 1 /* trigger accepts/external trigger */ #define TRIG_DELAY1 80 /* delay for trigger alignment fifo 1*/ #define TRIG_DELAY2 80 /* delay for trigger alignment fifo 2*/ #define VOLTAGE 0 /* DSP-DAC voltage */ /**********************************************************************/ /* add other default values to be set in set_defaults() */ /**********************************************************************/ #define STROBE_DELAY 0 /* strobe delay */ #define COUNTER_VAL 99 /* input fifo control counter value */ #define LL_VOLTAGE 0 /* LL-DAC voltage */ #define DET_READ_TIMEOUT 1000 /* timeout for reading packets */ #define GEN_TIMEOUT 0 /* general timeout, not used yet */ /**********************************************************************/ /* us_sys.h */ /* PROTOTYPE DEFINITIONS */ /**********************************************************************/ /* functions invoked by system functions: coding mandatory */ /* also defined in sys.h */ /**********************************************************************/ int get_user_code_ver(void); int load_data_block(int, int *); int dispatch_specific(int); int report_data(int); int get_data_summary(int, int *, int *); int set_defaults(void); int det_init(void); int burst_det_init(void); int init_user_var(void); int read_det(void); int data_ready(void); int data_ready_f2(void); int calib_init(int); int exec_calib(void); /**********************************************************************/ /* us.h */ /* PROTOTYPE DEFINITIONS */ /**********************************************************************/ /* user functions */ /* only definded in user.h */ /**********************************************************************/ /* functions invoked by user messages: */ /* action_id defined */ /**********************************************************************/ int load_control_block(void); int execute_control_block(void); int load_exe_ctr_blk(void); int get_det_status(void); int get_LL_status(void); int set_strobe_delay(void); int set_counter_val(void); int set_LL_dac(void); int set_timeout(void); int dis_enable_link(void); /*******************************************************************/ int enable_link(int, int); int set_strobe(int); int set_counter(int); int set_LL_voltage(int,int); int exe_control(int,int); int exe_control_packed(int,int); int load_ctr_block(int *,int, int *); int read_packets(int); int read_det_slow(void); int read_byte(int, int *); int reset_io_fifo(void); int clear_indata_buf(void); int clear_indata(void); int validate_data(int, int *); #endif /* You may modify this file as desired. UCI contact: Steve Pier University of California, Irvine pier@nucleus.ps.uci.edu 714-824-3162 */ /* hos_init.c: host-specific functions for use with dsp_init.c Include any host-specific functions in this file. E.g., log_err() and log_boot() can be replaced with host-specific functions with different names. Then change the LOG_ERR() and LOG_BOOT() macros in hostspec.h to call the host-specific functions. See init_dsp.c for global variables available to host-specific functions in this file. */ /* simple clock: one tick per call unsigned long simp_clock() { static unsigned long clock_tick = 0; return( clock_tick ++ ); } */ /*****************************/ /* * dsp.h * */ #define DSP_BASE0 0x08000000 #define DSP_BASE1 0x20000000 #define DSP_BASE2 0x40000000 #define DSP_BASE3 0x0 #define DSP_BASE4 0x0 #define DSP_AM 0x09 #define DSP_SIZE 0x8000 /*****************************/ #define NUMLINKS 4 #define RESET_DETECTORS 213