Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discussions on hw1 Objectives Modify I/O library for serial ports

Similar presentations


Presentation on theme: "Discussions on hw1 Objectives Modify I/O library for serial ports"— Presentation transcript:

1 Discussions on hw1 Objectives Modify I/O library for serial ports
change from ring buffer to queue implement interrupts testio Application I/O Library TTY0 TTYn OS

2 Services Provided by I/O Library
ioinit read irqinthandc write control

3 I/O Library APIs TTY0 (0 for COM1) TTY1 (1 for COM2)
#ifndef IO_PUBLIC_H #define IO_PUBLIC_H #include "tty_public.h" /* initialize io package*/ void ioinit(void); /* read nchar bytes into buf from dev */ int read(int dev, char *buf, int nchar); /* write nchar bytes from buf to dev */ int write(int dev, char *buf, int nchar); /* misc. device functions */ int control(int dev, int fncode, int val); #endif TTY0 (0 for COM1) TTY1 (1 for COM2)

4 I/O Library APIs (cont’d)
Look a lot like UNIX system calls: “dev” instead “fd” “device independent” I/O library generic, not specific to any particular device can be determined at runtime(e.g. ask user for a device number)

5 SAPC Device Numbers #defined in $pcinc/sysapi.h
this is included in stdio.h for SAPC #define CONSOLE 100 #define KBMON 0 #define COM1 1 #define COM2 2 Current console where Tutor prompts show up Keyboard + monitor (not available via mtip)

6 Tutor Console For mtip, Tutor console line is COM2
fprintf(CONSOLE, “hi”) or printf(“hi”) output directly to the user All outputs via CONSOLE is sent to remote gdb and the Tutor console Note: printf function does not force a line out on the port until it gets the eol character

7 SAPC Support Library The makefile links to the SAPC Support Library which includes: - Standard C library calls (e.g. printf, scanf, getchar, putchar, strcpy, strcmp, etc) - C library calls, with device numbers instead of FILE *’s (e.g. fprintf, fgets, etc) - Special SAPC functions (e.g. sys_get_console_dev(), other sys_functions, kprintf for debugging)

8 What you are asked to do Part 1 (due in 1 week):
testio.c calls through the APIs e.g. write(ldev, “hi\n”,4) read(ldev, buf, 10) Generate the remote gdb session for testio.lnx Current I/O library shows: write works already read can deliver previously type-in chars(“type ahead”) read does not wait for all chars. It only returns what is there already Part 2 (due in 2+ weeks): Fix the I/O library

9 I/O Library Assignment
implement write using interrupts implement read/write using queues from queue.c instead of buffers allow a few characters to input before read executes all edits are made in tty.c; no need to change routines in the queue directory

10 Dataflow using Queues Input (read): Output (write):
characters arrive in the interrupt handler queue into the input queue ttyread dequeues each character and store in the user buffer Output (write): characters arrive from the user in the user buffer ttywrite enqueues them into the output buffer interrupt handler dequeues them

11 Go over the makefile

12 Review of C Data Types Watch out for garbage pointers created using: typedef struct rect { int x1, y1, x2, y2; } Rectangle; Rectangle *recp; recp->x1 = 10; What is wrong with the above code? Answer: no memory pointed to by recp recp->x1 causes segmentation violation on UNIX, but writes into a random location in SAPC

13 malloc() in SAPC malloc() not supported in SAPC
just define the variable Rectangle rect; rect.x1 = 10; Similarly, we can set up typedef struct view{ Rectangle first, last; } View; View v; v.first.x1 = 10; v.first = rect;


Download ppt "Discussions on hw1 Objectives Modify I/O library for serial ports"

Similar presentations


Ads by Google