1 / 38

RTDL Driver Design Review

RTDL Driver Design Review. Johnny Tang (BNL) SNS Global Controls. Outline. RTDL Driver Design Requirements RTDL Board VME Memory Map and Register Bit Assignments RTDL Driver Design Block Diagram RTDL Driver - rtdlDrv Initialization Default Mode Device Names IOCTL Functions

xantha-buck
Download Presentation

RTDL Driver Design Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RTDL Driver Design Review Johnny Tang (BNL) SNS Global Controls

  2. Outline • RTDL Driver Design Requirements • RTDL Board VME Memory Map and Register Bit Assignments • RTDL Driver Design Block Diagram • RTDL Driver - rtdlDrv • Initialization • Default Mode • Device Names • IOCTL Functions • Concurrency Control • Interrupt Handling • Read/Write Functions • Parameter ID Table • RTDL EPICS Interface • New Customized Record vs. Record Template • EPICS Device Support • RTDL Documentations • Summary – Current Status

  3. RTDL Driver Design Requirements • Compatible with SNS ADE • Provide Board Configuration & Status Access Routines • Support RTDL Board Functionalities • Compliant with Wind River Coding Conventions • VxWorks naming conventions (routines, variables, constants, macros, types, structure and error status codes) • Unique status codes assigned for each error • Subroutines must be preceded by a comment block containing the purpose of the subroutine • Parameterize base address, interrupt number & vector

  4. RTDL VME Memory Map and Bit Assignments • SNS RTDL Master has one Encoder module (v105s) and and many (up to 128) RTDL dual channel input modules (v106s) or up to 32 eight channel input modules (v206) • SNS RTDL driver was developed against v105 and v106 while v206 and Utility modules were not available at the time

  5. V105 Registers AddressDescription Base Addr + 64 (40H) Command Register (R/W) Base Addr + 66 (42H) Status Register (R) Base Addr + 68 (44H) Interrupt Vector Register (7-0) (R/W)

  6. V105 Register Bit Assignments Command Register: bit 0 ===> Reset bit 1 ===> External Trigger On/Off bit 2 ===> Go ; Init Done/not done bit 3 ===> Interrupt Enable/Disable bit 4 ===> Undefined bit 5-7===> INTCD(1..3) interrupt level bit8-15===> Undefined  Status Register: bit 0 ===> NO Reply Error bit 1 ===> INITDONE/ERROR bit 4 ===> RTDLACT Transmitter Active bit 8-15 ===> IDCODE(0..7) (only important if NoReply Error) Interrupt Vector Register: bit 7-0 ===> Vector #

  7. V105 Parameter ID Codes SRAM AddressContents Base Addr + 256 (100H) Parameter ID Code #1 Base Addr + 257 (101H) Parameter ID Code #2 Base Addr + 258 (102H) Parameter ID Code #3 . . Base Addr + (256 + n) Parameter ID Code #n Base Addr + (256 + n + 1) 00H . . Base Addr + 511 (1FFH) End of RAM Space

  8. V106 Registers AddressDescription Base Addr + 64 (40H) Command Register CH1 Base Addr + 66 (42H) Command Register CH2 Base Addr + 68 (44H) VME Data Register CH1 (15-0) Base Addr + 70 (46H) VME Data Register CH1 (23-16) Base Addr + 72 (48H) VME Data Register CH2 (15-0) Base Addr + 74 (4AH) VME Data Register CH2 (23-16) Base Addr + 76 (4CH) Device Data Register CH1 (15-0) Base Addr + 78 (4EH) Device Data Register CH1 (23-16) Base Addr + 80 (50H) Device Data Register CH2 (15-0) Base Addr + 82 (52H) Device Data Register CH2 (23-16) Base Addr + 84 (54H) Interrupt Vector Register (7-0) Base Addr + 86 (56H) Status/Interrupt Status Register CH1 (15-0) Base Addr + 88 (58H) Status/Interrupt Status Register CH2 (15-0)

  9. V106 Register Bit Assignments Command Register: bit 0 ===> Reset bit 1 ===> Mode (VME/Device) bit 2 ===> Halt/Load (VME Data) bit 3 ===> Interrupt Enable bit 4 ===> Go bit 5-7 ===> INTerrupt CoDe (1..3) Interrupt level bit 8-15 ===> Undefined Status register: bit 0 ===> Link Status bit 1 ===> CRC Error Status bit 2 ===> Frame Error Status bit 3 ===> Link Interrupt Status bit 4 ===> CRC Interrupt Status bit 5 ===> Frame Interrupt Status bit 6-7 ===> Undefined bit 8-15 ===> Parameter ID  Interrupt Vector Register: bit 7-0 ===> Vector #

  10. RTDL Driver Design Block Diagram Application RTDL IOC Startup Script EPICS Support Layer write() close() read() ioctl() open() ioLib iosDrvInstall() iosLib iosDevAddl() rtdlDrv() rtdlWrite() rtdlClose() rtdlRead() rtdlIoctl() rtdlDevCreate() rtdlOpen() rtdlDrv RTDL P2 Bus

  11. RTDL Driver – rtdlDrv.c - Initialization • Initialization rtdlDrv() must be called to install the driver in the VxWorks I/O system. rtdlDevCreate() must then be called to initialize and install each device (v105 or v106) After installing the driver and creating the devices the following functions are available: open(),close(),ioctl(),read(),write() through the VxWorks I/O system. These routines may be called from an IOC startup script before EPICS software is loaded # Install RTDL driver int rtdlDrv(void) # Create each RTDL input/encoder device int rtdlDevCreate(deviceName, baseAddress, moduleType, intNumber, intLevel) char *deviceName # Name of RTDL device int baseAddress # Base address of board on VME bus unsigned int moduleType # Type of module (0 = v106 module, 1 = v105 module) unsigned char intNumber # interrupt number for board unsigned char intLevel # interrupt level for board

  12. RTDL Driver – rtdlDrv.c – Default Mode • Default Mode When new input channel devices are installed, the driver will not affect the state of the input channels. Ioctl functions are provided which can be used to determine the current state. When new encoder devices are installed, the driver reads an indication on the encoder board to see if initialization is necessary. If the board had been previously initialized, the driver does not affect the state of the board. If initialization is necessary, the encoder module will be configured as follows: • Interrupts are enabled. • Encoder GO bit is set.

  13. RTDL Driver – rtdlDrv.c – Device Names • Device Names A device can be defined as either an encoder module or an input module. Each module within the system will have a unique device name. The driver supports arbitrary names. However, it is recommended that, for ease of use, device names reflect the function or position of the device in the system. For example, rtdlDevCreate “/dev/rtdlE”, 0x200, 1, 0x1a, 3 # Create a device for v105 RTDL Encoder rtdlDevCreate “/dev/rtdlIA”, 0xfe00, 0, 0x1b, 3 # Create a device for 1st RTDL Input rtdlDevCreate “/dev/rtdlIB”, 0xfe00, 0, 0x1c, 3 # Create a device for 2nd RTDL Input Extended naming will be used when using open() to access a specific channel on an input module. E.g. if the name of the input device is "/dev/rtdlB", the name of channel 1 is "/dev/rtdlB/1", and the name of channel 2 is "/dev/rtdlB/2". E.g. the C command : fd = fopen("/dev/rtdlA/1"); will open a device for Real Time Data Link input module A which is used to read channel 1.

  14. RTDL Driver – rtdlDrv.c – IOCTL Function List • Supported IOCTL Functions RTDL_INPUT_SET_MODERTDL_INPUT_GET_MODERTDL_INPUT_SET_VME_DATARTDL_INPUT_GET_VME_DATARTDL_INPUT_GET_DEVICE_DATARTDL_ENCODER_GET_STATUSRTDL_ENCODER_SET_TRIGGERRTDL_ENCODER_GET_TRIGGERRTDL_ENCODER_NO_REPLY_ERROR_COUNTRTDL_ENCODER_NO_REPLY_ERROR_IDRTDL_ENCODER_NO_CARRIER_ERROR_COUNTRTDL_INPUT_NO_LINK_ERROR_COUNTRTDL_INPUT_FRAME_ERROR_COUNTRTDL_INPUT_CRC_ERROR_COUNTRTDL_ENCODER_ADD_CODERTDL_ENCODER_DELETE_CODERTDL_INPUT_GET_PARAMETER_IDRTDL_SET_RESETRTDL_GET_RESETRTDL_GET_BASE_ADDRESSRTDL_ENCODER_VERIFY_CODE

  15. RTDL_INPUT_GET_MODE RTDL_INPUT_SET_MODE Description:  Description:  Returns data mode of input channel (not valid for encoder module). Sets data mode of input channel (not valid for encoder module). Arg Usage:  Arg Usage:  N/A 1 for VME mode, 0 for device mode. Return Value:  Return Value:  1 for VME data mode, 0 for device data mode. OK if success ERROR if unsuccessful. RTDL Driver – rtdlDrv.c – IOCTL Functions

  16. RTDL_INPUT_SET_VME_DATA Description:  Write to VME data register for input channel  (not valid for encoder module). Arg Usage:  Desired VME data. Return Value:  OK if success ERROR if unsuccessful. RTDL_INPUT_GET_VME_DATA Description:  Returns the current VME data register for input channel (not valid for encoder module). Arg Usage:  N/A Return Value:  Current VME data register RTDL Driver – rtdlDrv.c – IOCTL Functions

  17. RTDL_INPUT_GET_DEVICE_DATA Description:  Returns the current DEVICE data register for input channel (not valid for encoder module). Arg Usage:  N/A Return Value:  Current DEVICE data register for input channel RTDL_ENCODER_GET_STATUS Description:  Returns the current value of the encoder status register. Arg Usage:  N/A Return Value:  Current value of encoder status register RTDL Driver – rtdlDrv.c – IOCTL Functions

  18. RTDL_ENCODER_SET_TRIGGER RTDL_ENCODER_GET_TRIGGER Description:  Description:  Enable or disable external trigger on the encoder module (not valid for input channels). Returns the state of external trigger bit on encoder module (not valid for input channels). Arg Usage:  Arg Usage:  1 for enable, 0 for disable. N/A Return Value:  Return Value:  OK if success ERROR if unsuccessful. 1 for external trigger enabled, 0 for disabled. RTDL Driver – rtdlDrv.c – IOCTL Functions

  19. RTDL_ENCODER_NO_REPLY_ERROR_COUNT  Description:  Returns the count NO REPLY errors for input channel. (not valid for input channels). Arg Usage:  N/A Return Value:  count NO REPLY errors for input channel RTDL_ENCODER_NO_REPLY_ERROR_ID Description:  Returns the parameter ID of channel with NO REPLY error. (not valid for input channels). Arg Usage:  N/A Return Value:  parameter ID of channel with NO REPLY error RTDL Driver – rtdlDrv.c – IOCTL Functions

  20. RTDL_ENCODER_NO_CARRIER_ERROR_COUNT Description:  Returns the count of event line CARRIER NOT DETECTED errors. (not valid for input channels). Arg Usage:  N/A Return Value:  count of event line CARRIER NOT DETECTED errors RTDL_INPUT_NO_LINK_ERROR_COUNT Description:  Returns the count of local serial LINK NOT DETECTED errors. (not valid for encoder module). Arg Usage:  N/A Return Value:  count of local serial LINK NOT DETECTED errors RTDL Driver – rtdlDrv.c – IOCTL Functions

  21. RTDL_INPUT_FRAME_ERROR_COUNT Description:  Returns the count of FRAME errors for input channel. (not valid for encoder module). Arg Usage:  N/A Return Value:  count of FRAME errors for input channel RTDL_INPUT_CRC_ERROR_COUNT Description:  Returns the count of CRC errors for input channel (not valid for encoder module). Arg Usage:  N/A Return Value:  count of CRC errors for input channel. RTDL Driver – rtdlDrv.c – IOCTL Functions

  22. RTDL_ENCODER_ADD_CODE RTDL_INPUT_GET_PARAMETER_ID Description:  Description:  Add a parameter ID to the current end of the parameter ID list. (not valid for input module). Get the parameter ID for an input channel. Arg Usage:  N/A Arg Usage:  Parameter ID to add Return Value:  Returns the jumper selected parameter ID for input channel used by this open device. Return Value:  OK if success ERROR if unsuccessful. RTDL_ENCODER_DELETE_CODE  Description:  Delete last occurrence of a code in parameter ID list. (not valid for input module) Arg Usage:  Parameter ID to delete Return Value:  Remaining number of occurrences in list. RTDL Driver – rtdlDrv.c – IOCTL Functions

  23. RTDL_SET_RESET Description:  Set or clear the reset bit for the module or channel used by this open device. (valid for either encoder or input module). Arg Usage:  1 for set, 0 for clear Return Value:  OK if success ERROR if unsuccessful. RTDL_GET_RESET Description:  Get the current status of the reset bit for the module or channel used by this open device. Description:  Verify that the given parameter ID has been loaded into the table on the encoder module. (valid for either encoder or input module). Arg Usage:  N/A Return Value:  Returns 1 for set, 0 for clear. RTDL Driver – rtdlDrv.c – IOCTL Functions

  24. RTDL_GET_BASE_ADDRESS Description:  Get the base address of the module used by this open device. (valid for either encoder or input module). Arg Usage:  N/A Return Value:  Returns local base address of module. RTDL_ENCODER_VERIFY_CODE Description:  Verify that the given parameter ID has been loaded into the table on the encoder module. (not valid for input module) Arg Usage:  Parameter ID to verify Return Value:  Count of occurrences in the table RTDL Driver – rtdlDrv.c – IOCTL Functions

  25. RTDL Driver – rtdlDrv.c – Concurrency Control • Concurrency Control – protect reading while writing • A semaphore is used internally within the driver to control access to the read and write functions to one user at a time. If the semaphore is not available, the driver will wait until it does become available.

  26. RTDL Driver – rtdlDrv.c – Interrupt Handling • Interrupt Handling • Interrupts are generated when the encoder module does not get a response from a particular input channel. • The PARAMETER ID on the encoder module is read by the interrupt handler when a NO RESPONSE interrupt occurs in order to decipher which channel is at fault. • Interrupts are generated on the input module when the carrier on the local serial link has not been detected for 2us, when a frame has been received with a data integrity (CRC) error, and when a frame error occurs. • A count is kept of each type of error for each device. These are available through the ioctl functions.

  27. RTDL Driver – rtdlDrv.c – Read/Write Functions • Read/Write Functions • The read and write functions of the driver are limited to reading and writing from the parameter ID table within the encoder module.

  28. RTDL Driver – rtdlDrv.c – Parameter ID Table • Parameter ID Table The encoder module has a special table which is used for configuration, known as the parameter ID table. In it is the parameter ID list which the encoder board will use to determine the sequence of transmission for the input channel values at each transmission event. The table can contain a list of up to 256 entries. The table may be accessed using either the IOCTL functions RTDL_ENCODER_ADD_CODE, or RTDL_ENCODER_DELETE_CODE, or the driver's read or write functions if the user desires to read or insert a parameter list in one driver call. The beginning of the table is assigned to offset 0 of the read/write buffer used. It contains the following format: MSB ..... Parameter ID ..... LSB Entry 0  |___|___|___|___|___|___|___|___| . . . . . . . . . . Entry 255  |___|___|___|___|___|___|___|___| where "Entry" is an 8-bit code for an input channel. The first zero entry in the list will cause the encoder to stop scanning the table for more entries

  29. RTDL Driver – rtdlDrv.c – Encoder (v105) ISR /************************************************************************************ * rtdlEncIntHandler:Interrupt handler for interrupts generated by encoder module. * * * * Notes: * * 1) Interrupts can be generated when the encoder module does not get a response * * from a particular input channel. The PARAMETER ID of the channel at fault is * * stored and an error count is incremented. * * 2) The interrupt status is cleared when the status register is read (RORA). * * 3) The interrupt handler will disable ENCODER module interrupts and start a * * watchdog timer. When this is exhausted a routine (rtdlEncWD) is called to re- * * enable interrupts. This prevents a continuous error condition from taking over * * the system with continuous interrupts. * ***********************************************************************************/LOCAL void rtdlEncWD( FAST RTDL_DEV_HEADER *pRtdlDevHeader ){ /* Reenable interrupts. */ (*pRtdlDevHeader->pCommandRegister) |= ENC_INT_ENABLE;} LOCAL void rtdlEncIntHandler(FAST RTDL_DEV_HEADER *pRtdlDevHeader){ int status; /* Disable interrupts. Will re-enable when watchdog routine is called. */ (*pRtdlDevHeader->pCommandRegister) &= ~(ENC_INT_ENABLE); /* Start a watchdog timer which will call rest of routine (in rtdlEncWD), later on (want .5 second delay). */ wdStart( pRtdlDevHeader->watchdogId, sysClkRateGet()>>1, (FUNCPTR)rtdlEncWD, (int)pRtdlDevHeader ); /* Clear interrupt by reading status register of encoder module. */ status = (*pRtdlDevHeader->pStatusRegister); if ( status & ENC_NO_REPLY_INT ) { pRtdlDevHeader->encNoReplyErrCount++; pRtdlDevHeader->encNoReplyID = status >> 8; } return;}

  30. RTDL Driver – rtdlDrv.c – Input (v106) ISR /********************************************************************************* rtdlInputInthandler:Interrupt handler for input module. * * ** Notes: ** 1) On the input module interrupts are generated because of FRAME errors, ** CRC errors, or LINK not detected for 2 us. ** 2) Interrupt status is cleared when status register is read (RORA). ** 3) The interrupt handler will disable INPUT module interrupts and start ** a watchdog timer. When this is exhausted a routine (rtdlInpWD) is called ** to reenable interrupts. This prevents a continuous error condition from ** taking over the system with continuous interrupts. ** 4) There is no way of determining channel 1 or channel 2 at fault so ** handler will check status of both channels. ** 5) Will check for CRC and frame errors only when link is detected. * ********************************************************************************/LOCAL void rtdlInpWD( FAST RTDL_DEV_HEADER *pRtdlDevHeader ){ /* Reenable interrupts. */ (*pRtdlDevHeader->pCommandChan1Register) |= INP_INT_ENABLE; (*pRtdlDevHeader->pCommandChan2Register) |= INP_INT_ENABLE;} LOCAL void rtdlInputIntHandler(FAST RTDL_DEV_HEADER *pRtdlDevHeader){ int status;/* volatile UINT16 *pWord;*/ /* Disable interrupts. Will re-enable when watchdog routine is called. */ (*pRtdlDevHeader->pCommandChan1Register) &= ~(INP_INT_ENABLE); (*pRtdlDevHeader->pCommandChan2Register) &= ~(INP_INT_ENABLE); /* Start a watchdog timer which will call rest of routine (in rtdlInpWD), later on (want .5 second delay). */ wdStart( pRtdlDevHeader->watchdogId, sysClkRateGet()<<1, (FUNCPTR)rtdlInpWD, (int)pRtdlDevHeader );

  31. RTDL Driver – rtdlDrv.c – Input (v106) ISR – con’t /* Clear interrupt by reading status register of input module for channel 1. Check status bits for errors. */ status = (*pRtdlDevHeader->pStatusChan1Register); if( status & INP_LINK_INT_STATUS ) pRtdlDevHeader->inpLinkErrCount[0]++; /* Increment Input module LINK NOT DETECTED error count. */ else { /* Check for these only if link is detected. */ if( status & INP_FRAME_INT_STATUS ) pRtdlDevHeader->inpFrameErrCount[0]++; /* Increment Input module FRAME error count. */ if( status & INP_CRC_INT_STATUS ) pRtdlDevHeader->inpCrcErrCount[0]++; /* Increment Input module CRC error count. */ } /* Clear interrupt by reading status register of input module for channel 2. Check status bits for errors. */ status = (*pRtdlDevHeader->pStatusChan2Register); if( status & INP_LINK_INT_STATUS ) pRtdlDevHeader->inpLinkErrCount[1]++; /* Increment Input module LINK NOT DETECTED error count. */ else { /* Check for these only if link is detected. */ if( status & INP_FRAME_INT_STATUS ) pRtdlDevHeader->inpFrameErrCount[1]++; /* Increment Input module FRAME error count. */ if( status & INP_CRC_INT_STATUS ) pRtdlDevHeader->inpCrcErrCount[1]++; /* Increment Input module CRC error count. */ } return;}

  32. RTDL Driver – rtdlDrv.c – IOCTL RTDL_INPUT_SET_VME_DATA case RTDL_INPUT_SET_VME_DATA: /* Write to VME data register for the given input channel (not valid for encoder module). arg should contain the desired VME data. */ if( pRtdlOpenData->pRtdlDevHeader->module_type == RTDL_INPUT_MODULE ) { /* Write VME data to the appropriate input channel. */ /* Place the channel in VME mode and halt input module loading of data until write to VME DATA register is complete. */ (*pRtdlOpenData->pCommandRegister) |= ( INP_HALT_LOAD); /* Now write the placeholders out to the registers */ *(pRtdlOpenData->pVmeDataHigh) =(UINT8)(arg >> 16); *(pRtdlOpenData->pVmeDataLow) = (UINT16)(arg & 0xffff); /* Now allow Input module to load new data. */ (*pRtdlOpenData->pCommandRegister) &= ~(INP_HALT_LOAD); status = OK; } else { /* Can't do this to encoder module. */ errnoSet(EINVAL); status = ERROR; } break;

  33. RTDL EPICS Interface • New Customized Record vs. Record Template • Bi/Bo to configure/control command and status registers • Li/Lo to Read/Write RTDL VME data • Ai to Read RTDL Device data • Waveform to Read Parameter ID List in SRAM • A New Customized Record may replace all records above, clean, but • More maintenance work when upgrading EPICS system • A template with a group of records is flexible and suitable for a prototype hardware device • It will have more records for each device

  34. RTDL EPICS Interface – Device Support • Device Support # EPICS Device Support for RTDL Input Moduledevice(stringin,INST_IO,devStringinRtdlInput,"RtdlInput")device(longin,INST_IO,devLiRtdlInput,"RtdlInput")device(longout,INST_IO,devLoRtdlInput,"RtdlInput")device(bi,INST_IO,devBiRtdlInput,"RtdlInput")device(bo,INST_IO,devBoRtdlInput,"RtdlInput")# EPICS Device Support for RTDL Encoder Moduledevice(stringin,INST_IO,devStringinRtdlEncoder,"RtdlEncoder")device(longin,INST_IO,devLiRtdlEncoder,"RtdlEncoder")device(bi,INST_IO,devBiRtdlEncoder,"RtdlEncoder")device(bo,INST_IO,devBoRtdlEncoder,"RtdlEncoder")

  35. RTDL EPICS Interface – Test Application

  36. RTDL Master IOC Configuration

  37. RTDL Software Documentations http://www.sns.bnl.gov/epics/timing has the following documents : • RTDL Driver Manual • RTDL EPICS Device and Driver Support • RTDL Specification Source Code is available in SNS CVS repository at ORNL

  38. Summary • RTDL Software Driver is ready for its application use • A waveform support will be developed to display Parameter ID list (currently use “d” command @ console) • An ai support shall be developed if analog device input is supported on v206 • Upgrading current driver to support v206 • Integration with Utility module and VME-SG2 GPS interface module

More Related