CMPE 401 - Computer Interfacing

Assignment #3 Solutions

Due: In the CMPE 401 assignment box at 15:45 on Wednesday, Nov. 3, 2004


  1. The MC68681 DUART has a single active-low interrupt request output called IRQ. In addition, it is possible to configure parallel outputs OP4, OP5, OP6 and OP7 to produce separate active-low interrupt request outputs for interrupt status conditions RxRDYA, RxRDYB, TxRDYA and TxRDYB, respectively. In the Laboratory 2 exercises you designed a single interrupt service routine for handling these same four interrupt conditions. Briefly explain how the system software and hardware would have to be modified to handle the four separate hardware interrupt signals. (Note: You can assume that the DUART has already been initialized and configured properly.) Be sure to explain whether or not each of the user interrupt and autovectored interrupt methods would be appropriate to use.

    [20 marks]
    Hardware modifications: The system hardware would have to be modified to accommodate the four interrupt request signals coming out of the DUART on pins OP4, OP5, OP6 and OP7. Four wires would need to be provided to carry the four IRQ signals, and the signals would need to be assigned interrupt priority levels (in the range 0b001 to 0b111) by the interrupt circuitry. In the 68332, the four wires could simply be connected to four different IRQ inputs.

    Software modifications: If the four hardware interrupts are to be handled with four separate interrupt service routines (the most likely scenario), then those four routines would need to be designed and the four corresponding exception vectors would need to be installed at the correct locations in the exception vector table. If the four hardware interrupts are handled by a single interrupt service routine, then a single conventional DUART interrupt service routine would need to be designed. This routine would need to have statements that determine the currently active interrupt conditions.

    Autovectored interrupts would be simplest to use: each of the four DUART interrupt signals could be assigned to one of the 7 available interrupt priority levels. As mentioned above, in a 68332-based system the four IRQ wires could just be connected to four different IRQ inputs. Fast IRQ handling could then be provided by four separate interrupt service routines. The four corresponding exception vectors would of course need to be installed in the exception vector table.

    User interrupts would not be as attractive as autovectored interrupts since the DUART can only store one exception vector number in its IVR. If this one number were to be shared for all four interrupt signals, then the one resulting interrupt service routine would be slowed down by the need to determine the source of the interrupt. This disadvantage would defeat the aim of having faster interrupt handling by using four separate interrupt request signals. Four exception vector registers could be implemented using additional hardware (say in an FPGA), but this would be a relatively complicated solution. The new hardware would need to monitor the system bus so that it would step in and supply the appropriate exception vector number on the data bus whenever the CPU was in the middle of an interrupt acknowledgement cycle caused by one of the four DUART interrupts. With such registers implemented in the system, it would be possible to have four separate user interrupts and fast response using four separate interrupt service routines.

  2. Consider the DUART interrupt service routine (ISR) shown below, which is required to handle interrupts for serial channel A. The ISR is to simultaneously handle both the transmit and receive directions for channel A. Received characters are to be added to a queue by calling the subroutine ADD_TO_RX_QUEUE. Transmitted characters are to be obtained from a pointer variable TX_BYTE_PTR provided a boolean flag ANY_BYTES_TO_TX is 1; otherwise, transmit interrupts are to be disabled (transmit interrupts are enabled properly in another routine). You can assume that the ISR uses the same symbol definitions as in the DUART driver software that you used in the laboratory exercises. Unfortunately, the ISR contains several simple programming errors. Try to find as many errors as possible, and indicate (by writing directly on the program) how the problems could be most easily fixed.

    [15 marks]
    DUART_ISR: MOVEM.L D0-D7/A0-A6,(SP)- DUART_ISR: MOVEM.L D0-D7/A0-A6,-(SP) /* predecrement */ LEA.L #DUART_ADDR,A0 LEA.L DUART_ADDR,A0 /* no # in LEA */ MOVE.B ISR(A0),D0 MOVE.B ISR(A0),D0 MOVE.B D0,D2 /* save copy of ISR*/ ANDI.B #RxRDYA,D0 ANDI.B #RxRDY,D0 BNE CheckTx BEQ CheckTx /* EQ, not NE */ RxIRQ: MOVE.W RBA(A1),D1 RxIRQ: MOVE.B RBA(A0),D1 /* A0, not A1 */ MOVE.W D1,-(A7) MOVE.W D1,-(A7) JSR ADD_TO_RX_QUEUE JSR ADD_TO_RX_QUEUE ADDQ.W #1,SP ADDQ.L #2,SP /* .L add and #2 data size */ BRA EXIT_ISR BRA EXIT_ISR CheckTx: ANDI.B #TxRDYB,D0 CheckTx: ANDI.B #TxRDYB,D2 /* use copy of the ISR */ BEQ EXIT_ISR BEQ EXIT_ISR TST.B ANY_BYTES_TO_TX TST.B ANY_BYTES_TO_TX BEQ DISABLE_TX_IRQS BEQ DISABLE_TX_IRQS LEA.L TX_BYTE_PTR,(A2) LEA.L TX_BYTE_PTR,A2 /* omit the brackets around A2 */ MOVE.B (A2)+,TBA(A0) MOVE.B (A2)+,TBA(A0) DISABLE_TX_IRQS: DISABLE_TX_IRQS: MOVE.B #TxRDYA,D3 /* create correct bit mask for ISR */ NOT.B D3 AND.B D3,IMR_COPY /* update copy of ISR */ MOVE.B TxRDYA,IMR(A0) MOVE.B IMR_COPY,IMR(A0) EXIT_ISR: MOVEM.L (SP)+,D0-D7/A1-A6 EXIT_ISR: MOVEM.L (SP)+,D0-D7/A0-A6 /* A0, not A1 */ RTS RTE /* RTE from ISRs, not RTS */

  3. Consider the design of an asynchronous serial interface (not RS232C). The new interface is to be capable of transporting 100-bit-long data packets without the need for resynchonization for the entire duration of the frame after the start bit has been used to synchronize the receiver clock. Assuming that the master clocks in both the transmitter and receiver operate 16 times faster than the nominal bit rate (100 kilobits per second), how accurately must the two clocks agree with each other in frequency (as a percentage) to guarantee that the last received data bit in each frame is sampled within 25% of a bit time of the ideal middle instant of the bit? How would the accuracy requirement change if the overclocking ratio were to be 8, instead of 16, and the data frames were to contain 300 bits, instead of 100?

    [15 marks]
    Let T1 be the period of the transmitter clock and let T2 be the period of a slightly fast receiver clock. We then have the following constraint:

    (8 + 16x99 + 4) x T1 = 16 x 100 x T2
    The right side gives the time interval that the receiver believes is exactly 100 bit times, from the exact middle of the start bit to the exact middle of the 100th data bit. The left side gives the same time interval in terms of T1, where the last data bit is sampled at the earliest allowed instant, namely, 25% of a bit time (4 clock periods of T1) too early. Solving for T2/T1 we get 0.9975. The two clock frequencies can therefore differ by up to (1/0.9975) - 1.0 = 1.00251 - 1.0 = 0.251%. Very close to the same percentage is obtained if the receiver clock is assumed to be slightly slow.

    The second problem is easily solved by modifying the appropriate numbers in the constraint as follows:

    (4 + 8x299 + 2) x T1 = 8 x 300 x T2
    Here T2/T1 = 0.999167, so the two frequencies can differ by up to (1/0.999167) - 1.0 = 1.000834 - 1.0 = 0.0834%. Note that the two frequencies must agree more closely with each other than before.

  4. In a human-to-human telephone call, what is the protocol for recovering from a bad connection (e.g. a connection that has a large degree of interfering random noise)? What sorts of errors could occur during reconnection attempts because the human protocol is usually informal?

    [10 marks]
    If reception gets poor in a human-to-human telephone call, one of the parties will either (a) hang-up immmediately and then redial, hoping to get a cleaner connection, or (b) talk more loudly hoping to be more clearly heard over the noise on the line.

    It is possible to have problems due to the informality of this protocol for handling errrors. Both parties could hang up and wait for the other to dial first. This could cause an unnecessarily long delay until the call was resumed when one party's redial attempts was successful.

    It is also possible that both parties could redial at exactly the same time, in which case it is possible that both call attempts will be blocked and both parties will hear a busy signal. However, eventually one of the repeated redial attempts by one party will succeed in getting through to the other party.

  5. What are the primary advantages to introducing layering into a communications interface? What are the possible disadvantages to having a relatively large number of layers over having a smaller number of layers?

    [10 marks]
    Primary advantage: Layering is used to manage the complexity of communications interfaces. Each resulting layer is, by itself, easier to specify, design, verify and modify than the entire interface would be if treated as one unit.

    Other advantages:

    • Each layer can be modified later without requiring changes to the other layers.
    • Each layer can be solved by a separate team of engineers or by a different product.
    • Application software can access the layer at one of several possible degrees of abstraction. The complexity of lower layers can be avoided by interfacing to the higher layers. Layering thus provides control over how much complexity needs to be faced.

    Possible disadvantages of having too many layers: Each layer in a communications interface will introduce some overhead that appears in several forms: (1) In the specification of the interface, each new layer adds a new set of services and a new interlayer interface that must be specified correctly. This work will have to be negotiated in the standards committees and this effort will cost time and money. (2) Each new implementation of the communications interface will have to be verified for compliance with the specification of the protocols in all layers. This requirement adds complexity to the protocol conformance testers and adds expense to the process of certifying compliance of each new product implementation of the interface. Having more layers in the interface thus tends to make the verification problem more expensive. (3) Overhead in the form of extra processing time and extra storage space is generally required when passing information from layer to layer. Thus adding a new layer will tend to add some extra processing and storage cost.

  6. Briefly describe the functions of routers, bridges and repeaters in a TCP/IP network. Consider the network illustrated in lecture slide 7-16. Briefly justify the positioning of the routers, bridges and repeaters in this network.

    [15 marks]
    A router is used to interface two networks at layers 1, 2 and 3. The two networks may be using different network layer (ISO layer 3) protocols, so a router has to have the intelligence to be able to look into the packets to: (1) adjust routing information if necessary, and (2) adjust layer 1, 2 and/or 3 packet formatting if necessary. Acting at layer 2, a router can make packet forwarding decisions based on the packet addresses. And acting at layer 1, a router can strengthen or refresh the signals.

    A bridge is used to interface two networks at layers 1 and 2. Intelligence may be used in the bridge to filter the packets based on information in the packet headers (e.g. address information). For this reason, bridges are widely used to isolate packet traffic in different subsegments of a network. Acting at layer 1, a bridge can strengthen or refresh the signals.

    A repeater is used to interface two networks at layer 1. The physical medium in the two networks can differ, but the bit-level structure of the packets cannot be changed by the repeater. Thus the bits are simply transferred from one network to the other network with no intelligent data processing. The repeater can amplify the signal to offset signal attenuation and/or can convert the signal between two different transmission media or signalling levels. A hub is a repeater that is used to form a star-shaped network topology.

    In slide 7-16, routers are shown in two positions: (1) between the FDDI campus backbone and (2) between an Ethernet branch and an Appletalk network. In these positions, the routers can make any necessary address and packet format adjustments (between Ethernet and Appletalk) to transitting packets. Also the signal levels can be adjusted and/or strengthened.

    The bridges are used in the network to isolate different Ethernet segments from the main departmental Ethernet backbone. In this way, traffic can be filtered by the bridges to avoid unnecessary traffic propagation and to reinforce security (packets can be kept out or maintained within selected Ethernet segments)

    A conventional repeater is used in one Ethernet segment to extend its length. The repeater is being used here to strengthen the signals. The hub repeater is used at the end of a second Ethernet segment to create a star topology. This is done frequently so that cheaper twisted pair cabling can be used in each segment of the star (instead of conventional more expensive shielded Ethernet cable).

  7. The window-based acknowledgement scheme used in TCP accomplishes two objectives at the same time: (1) it provides flow control between two communicating nodes, and (2) it provides a mechanism for recovering from the loss or reordering of data packets (e.g. TCP segments). In each segment sent by a node A to node B, there is a 32-bit sequence number in the header that corresponds to the first data byte in the segment's data field. The window field in the same segment indicates how many data bytes node A is prepared to send to node B without receiving a TCP segment coming back from node B to node A with an incremented acknowledgement number in its header. The acknowledge number is used by node B to tell node A what the last data byte was that was received in the correct order. (An identical but separate window protocol operates for data travelling in the reverse direction from node B to node A.)

    Briefly explain how the window scheme provides both features (1) and (2) mentioned at the start of this question.

    [15 marks]
    Flow control is provided because the receiving node can stop the further arrival of packets from a sending node by freezing the acknowledgement number that is including in the TCP header of packets heading in the opposite direction.

    Data packet loss and mis-ordering are detected at the receiver using the sequence number in the TCP header. The acknowledgement numbers should be strictly increasing (ignoring eventual wrap-around) in a sequence of packets that are in the correct order. Also, the number of bytes present in each new packet (TCP segment) should correspond to the increase in the sequence number from the last packet that was received. If one of these constraints is violated, the acknowledgement number in the reverse direction can be frozen, causing the sender to eventually resend the missing or out-of-order packets.