5. Test Functions Specification

So that we can grade your work, you are required to implement the following testing functions. We will develop the code that will call them, so make sure that your implementation matches their prototypes.

When designing your solution always think about modularity and generality. The grade of your code will depend also on these aspects.

5.1 mouse_test_packet(unsigned short cnt)

The purpose of this function is to test that your code is able to read the packets from the PS/2 mouse using an interrupt handler.

Thus, mouse_test_packet() should first subscribe the mouse interrupts, as described in the previous section.

Then it should print on the console the packets received by the interrupt handler as shown in Figure 1.

B1=0x8 B2=0x12 B3=0x14 LB=0 MB=0 RB=0 XOV=0 YOV=0 X=18 Y=20
B1=0x8 B2=0x12 B3=0x12 LB=0 MB=0 RB=0 XOV=0 YOV=0 X=18 Y=18
B1=0x8 B2=0x12 B3=0xe LB=0 MB=0 RB=0 XOV=0 YOV=0 X=18 Y=14
B1=0x8 B2=0x10 B3=0xe LB=0 MB=0 RB=0 XOV=0 YOV=0 X=16 Y=14
B1=0x9 B2=0x0 B3=0x0 LB=1 MB=0 RB=0 XOV=0 YOV=0 X=0 Y=0
B1=0xC B2=0x0 B3=0x0 LB=0 MB=1 RB=0 XOV=0 YOV=0 X=0 Y=0
B1=0xA B2=0x0 B3=0x0 LB=0 MB=0 RB=1 XOV=0 YOV=0 X=0 Y=0
Figure 1: Example of output generated by mouse_test_packet

The mouse_test_packet() function should exit after it prints the number of packets specified in its argument cnt.

5.2 mouse_test_remote(unsigned long period, unsigned short cnt)

The purpose of this function is to test that your code is able to read the packets from the PS/2 mouse using remote mode and by polling the KBC's status register, rather than using streaming mode and interrupts, as in mouse_test_packet()

mouse_test_remote() should configure the mouse to operate in remote mode and periodically request a data packet from the mouse. The period to be used is specified in milliseconds in its first argument. It should also display the packets received from the mouse, as shown in Figure 1.

mouse_test_remote() should exit after it prints the number of packets specified in its argument cnt.

As described in Section 4.1, you will need to prevent Minix's default IH from running. To get the full credit, you need to disable mouse interrupts on the KBC, by changing the KBC's Command Byte. However, a simpler way is to subscribe the mouse interrupts in exclusive mode as described above. Although, the KBC will still generate interrupts when it puts a byte it receives from the mouse in the KBC's output buffer, it will not notify Minix's default IH, and therefore it will not run. On the other hand, since your code subscribed the mouse interrupts, it will be notified. This is no problem as long as you do not process these interrupts.

If your code disables mouse interrupts on the KBC, it should reenable them before returning from mouse_test_remote().

5.3 mouse_test_async(unsigned short idle_time)

The purpose of this function is to make you think about the structure of the code that handles asynchronous interrupt notifications from multiple devices, namely the PC's Timer 0 and the mouse.

This function should essentially do the same as mouse_test_packet(), i.e. it should display the packets received from the mouse, as shown in Figure 1.

The difference is on the exit condition: now, the function should terminate if it receives no packets from the mouse for the number of seconds specified in its argument idle_time.

For measuring the time you must use the Timer 0 interrupts. Furthermore, you cannot change the configuration of Timer 0.

5.4 mouse_test_gesture(short length)

The purpose of this function is to test whether you are able to implement a state machine, whose states change in response to events originating in I/O devices, more specifically the mouse.

This function should essentially do the same as mouse_test_packet(), i.e. it should display the packets received from the mouse, as shown in Figure 1.

The difference is on the exit condition: now, the function should terminate if the user makes a continuous movement with a positive slope in the same direction with the mouse while pressing its right button. The minimum length of the movement on the x-direction is specified in the length argument. The units of this argument are the units reported by the mouse. A positive number indicates an upwards movement, whereas a negative number indicates a downwards movement.