Proton Basic Serial Interrupt
BASIC is a good choicewhen you arestarting out.BASIC is the simplest language and must not be dismissed because it is old.It's true it has some limitations (modern compilers do not have manylimitations) but it is excellent when you are starting out.There's even a free one calledBASIC was the first language that I ever used and PIC BASIC is BASIC optimizedfor the PIC Micro. OK I'll date myself a bit here - MZ80K, Spectrum, Amstrad -the heady days of the Z80 based computer which all used BASIC.BASIC has improved over the years getting rid of line number based listing and using theprocedure based method common to other languages.This fact alone makes PIC BASIC much easier to use e.g. Instead of GOSUB 9810 (aline number) you can use GOSUB abc where abc is the name of a subroutine.But it has not changed that much and this explains its popularity - you canuse the BASIC that you learnt years ago and program advanced PIC Micros.There areseveral PIC BASIC systems and these are either interpreter or compilerbased.Jump toJump to,.Jump to,If you arenew to programming, PIC BASIC is also a very easy introduction tomicrocontroller programming as the language is not difficult to master. I expect that lateron you can move onto other languages as the only disadvantage of PIC BASIC isthat sometimes, for advanced programming, it limits what you can do.In the past at work I have been asked to program in an ancient version ofBASIC and it is extremely frustrating as you tend to rely on the features ofthe program i.e.
You start programming because it claims to be able to dosomething. Once you get there you find you would like to add a tiny extraoperation and you can not! There is simply not enough functionality in thefunctions provided and you can not add any more.C tends to let you do more as most of the functions are themselves written in C- this basically means that if a function is not available you just write ityourself.This is whythe 'C' language is so popular you can do virtually anything you need to do in'C'. Also you can structure the program more easily and this lets youmore easilyunderstandhow the program works but PIC BASIC is still powerful and modern versions letyou do much more - even adding your own assembler code.Note: Even with advanced programminglimitations you can still do an enormous amount using PICBASIC.Sidebar: GOTONote: Use ofGOTO is not considered good programming practice.The reason is that when you useit you have no way of getting back to where you started. The program's flowis completely disrupted and you are dependent on the routine that you are in toget you to the next program operation. (This is ok for a small test programbut hopeless for anything large).You need to use GOSUB - better to just not use GOTO at all. A procedure thatyou have called using GOSUB will let you go back to the caller at any timeusing RETURN.
This method is equivalent to procedure/function calls in allother languages (Yes C does have a goto statement but everyone avoids it at allcost).Using subroutines structures your code for easy reading and maintenance as youcan use your main procedure at the top level - if you think of your program asa root system that branches down. Interpreted PIC BASICAn interpretedlanguage uses a controlling program to read a set of tokens and translate thesetokens into machine code on-the-fly. As each token is interpreted the machinecode is executed.For each instruction e.g. FOR, RETURN, GOSUB etc. A unique code is assignedtothe token -this is simply a number. These are read from memory and interpretedsequentially.Note: Special methods are used to distinguishbetween 'Tokens' and a number e.g. A WORD.The key points here are:.
controllingprogram. on-the-fly. ease ofuse.Interpreted PIC BASIC:Controlling programThe interpreteris acontrolling program that interprets the tokens and it has to be present in themicrocontroller and it will be quite large - so you loose some of the internal program memory of the PIC.The amount of memory you loose depends on the commands supported and in somecases this does not matter as the tokens are loaded into a separate externalmemory (serial eeprom) while in others only internal memory is used. You only need a serial cable to program it (e.g.picaxe).They work using the PIC feature of self programming where the PIC can write toits own internal (Flash) program memory (not the EEPROM).Note: This is effectively a bootloader with added 'BASIC' functions. Itbootloads the program into internal memory or I2C serial EEPROM and executesit.Interpreted PIC BASIC: Disadvantage?Its slow and inthe long run it costs you.Also some features may not be available e.g. Interrupts - you need to carefullycheck the documentation before buying it.Note: picaxe may be an exception as it ispriced a little bit more than the cost of the chip (ok it still costs more thanthe chip).Interpreted PIC BASIC: Advantage?A PIC BASICinterpreter is the easiest way to startprogramming with microcontrollers.Compiled PIC BASIC. The compiler directly outputs executablecode.The compileris the favored method of program generation in industry as it gives youcomplete control over the microcontroller but the C language usually used.PIC BASIC Compiler: Disadvantage?Separateprogrammer and programming software running on the PC.This adds more complexity to programming the chip.
You have either aserial or parallel cable (or USB) to the and then an connector to your target board and you use to stuff thedata into the microcontroller.Note: There is a way around this - by using abootloader - this consumes a small amount of internal memory (but is not as bigas the interpreter). But you still need a programmer to get the bootloader intothe Micro in the first place - this is what you buy when you buy a BS2 orpicaxe i.e.
A bootloader and interpreter combined.PIC BASIC Compiler: Advantage?A PIC BASICcompiler gives the maximum speed and best use of internal program memory andresources.Also, once you have bought the compiler you do not need to buy any other module(usually a costly component) you just buy the raw microcontroller chip.Note: Costs can mount up if you useinterpreted BASIC modules. e.g. If an interpreter module costs $50 each andyou do ten projects it will cost $500 (just for the module). If you buy acompiler $200 say and do ten projects (with a $10 microcontroller) then youspend a total of $300. So if you intend to do a lot of project work it'sworth investing in a good compiler (but check picaxe price).There's a free open source PIC BASICcompilerJump from page toBest-Microcontroller-Projects Home Page.
Serial HOWTO: Serial Port BasicsYou don't have to understand the basics to use the serial port Butunderstanding it may help to determine what is wrong if you run intoproblems. This section not only presents new topics but also repeatssome of what was said in the previous sectionbut in greater detail. Intro to SerialThe UART serial port (or just 'serial port for short' is an I/O (Input/Output) device.An I/O device is just a way to get data into and out of a computer.There are many types of I/O devices such as the older serial ports andparallel ports, network cards, universal serial buses (USB), andfirewire etc.Most pre-2007 PC's have a serial port or two (on older PC's). Eachhas a 9-pin connector (sometimes 25-pin) on the back of the computer.Computer programs can send data (bytes) to the transmit pin (output)and receive bytes from the receive pin (input). The other pins arefor control purposes and ground.The serial port is much more than just a connector. It converts thedata from parallel to serial and changes the electrical representationof the data. Inside the computer, data bits flow in parallel (usingmany wires at the same time).
Serial flow is a stream of bits over asingle wire (such as on the transmit or receive pin of the serialconnector). For the serial port to create such a flow, it mustconvert data from parallel (inside the computer) to serial on thetransmit pin (and conversely).Most of the electronics of the serial port is found in a computer chip(or a part of a chip) known as a UART. For more details on UARTssee the sectionBut you may want to finish this section first so that you willhopefully understand how the UART fits into the overall scheme ofthings. Pins and WiresOld PC's used 25 pin connectors but only about 9 pins wereactually used so later on most connectors were only 9-pin. Each ofthe 9 pins usually connects to a wire. Besides the two wires used fortransmitting and receiving data, another pin (wire) is signal ground.The voltage on any wire is measured with respect to this ground.
Thusthe minimum number of wires to use for 2-way transmission of data is3. Except that it has been known to work with no signal ground wirebut with degraded performance and sometimes with errors.There are still more wires which are for control purposes (signalling)only and not for sending bytes. All of these signals could have beenshared on a single wire, but instead, there is a separate dedicatedwire for every type of signal. Some (or all) of these control wiresare called 'modem control lines'. Modem control wires are either inthe asserted state (on) of +5 volts or in the negated state (off) of-5 volts.
One of these wires is to signal the computer to stopsending bytes out the serial port cable. Conversely, another wiresignals the device attached to the serial port to stop sending bytesto the computer. If the attached device is a modem, other wires maytell the modem to hang up the telephone line or tell the computer thata connection has been made or that the telephone line is ringing(someone is attempting to call in).
See sectionfor more details. RS-232 (EIA-232, etc.)The serial port (not the USB) is usually a RS-232-C, EIA-232-D, orEIA-232-E.
These three are almost the same thing. The original RS(Recommended Standard) prefix officially became EIA (ElectronicsIndustries Association) and later EIA/TIA after EIA merged with TIA(Telecommunications Industries Association). The EIA-232 specprovides also for synchronous (sync) communication but the hardware tosupport sync is almost always missing on PC's. The RS designation iswas intended to become obsolete but is still widely used and will beused in this howto for RS-232. Other documents may use the fullEIA/TIA designation, or just EIA or TIA.
For info on other(non-RS-232) serial ports see the sectionSince the computer needs to communicate with each serial port, theoperating system must know that each serial port exists and where itis (its I/O address). It also needs to know which wire (IRQ number)the serial port must use to request service from the computer's CPU.It requests service by sending an interrupt voltage on this wire.Thus every serial port device must store in its non-volatile memoryboth its I/O address and its Interrupt ReQuest number: IRQ. The PCI bus has its own system ofinterrupts. But since the PCI-aware BIOS sets up these PCI interruptsto map to IRQs, it seemingly behaves just as described above. Exceptthat sharing of PCI interrupts is allowed (2 or more devices may usethe same IRQ number).I/O addresses are not the same as memory addresses. When an I/Oaddresses is put onto the computer's address bus, another wire isenergized. This both tells main memory to ignore the address andtells all devices which have I/O addresses (such as the serial port)to listen to the address sent on the bus to see if it matches thedevice's.
If the address matches, then the I/O device reads the dataon the data bus.The I/O address of a certain device (such as ttyS2) will actually be arange of addresses. The lower address in this range is the baseaddress. 'address' usually means just the 'base address'.The serial ports are named ttyS0, ttyS1, etc. (and usuallycorrespond respectively to COM1, COM2, etc. In DOS/Windows). The /devdirectory has a special file for each port.
Type 'ls /dev/ttyS.' tosee them. Just because there may be (for example) a ttyS3 file,doesn't necessarily mean that there exists a physical serial portthere.Which one of these names (ttyS0, ttyS1, etc.) refers to whichphysical serial port is determined as follows. The serial driver(software) maintains a table showing which I/O address corresponds towhich ttyS. This mapping of names (such as ttyS1) to I/O addresses(and IRQ's) may be both set and viewed by the 'setserial' command.See. This doesnot set the I/O address and IRQ in the hardware itself (which isset by jumpers or by plug-and-play software). Thus which physical portcorresponds to say ttyS1 depends both on what the serial driver thinks(per setserial) and what is set in the hardware.
If a mistake hasbeen made, the physical port may not correspond to any name (such asttyS2) and thus it can't be used. Seefor more details.When the serial port receives a number of bytes (may be set to 1, 4,8, or 14) into its FIFO buffer, it signals the CPU to fetch them bysending an electrical signal known as an interrupt on a certain wirenormally used only by that port. Thus the FIFO waits until it hasreceived a number of bytes and then issues an interrupt.However, this interrupt will also be sent if there is an unexpecteddelay while waiting for the next byte to arrive (known as a timeout).Thus if the bytes are being received slowly (such as from someonetyping on a terminal keyboard) there may be an interrupt issued forevery byte received.


Proton Basic Serial Interrupt Key
For some UART chips the rule is like this: If 4bytes in a row could have been received in an interval of time, butnone of these 4 show up, then the port gives up waiting for more bytesand issues an interrupt to fetch the bytes currently in the FIFO. Ofcourse, if the FIFO is empty, no interrupt will be issued.Each interrupt conductor (inside the computer) has a number (IRQ) andthe serial port must know which conductor to use to signal on. Forexample, ttyS0 normally uses IRQ number 4 known as IRQ4 (or IRQ 4). Alist of them and more will be found in 'man setserial' (search for'Configuring Serial Ports'). Interrupts are issued whenever theserial port needs to get the CPU's attention. It's important to dothis in a timely manner since the buffer inside the serial port canhold only 16 incoming bytes. If the CPU fails to remove such receivedbytes promptly, then there will not be any space left for any moreincoming bytes and the small buffer may overflow (overrun) resultingin a loss of data bytes.There is noto prevent this.Interrupts are also issued when the serial port has just sent out allof its bytes from its small transmit FIFO buffer out the externalcable.
It then has space for 16 more outgoing bytes. The interruptis to notify the CPU of that fact so that it may put more bytes in thesmall transmit buffer to be transmitted. Also, when a modem controlline changes state, an interrupt is issued.The buffers mentioned above are all hardware buffers. The serial portalso has large buffers in main memory.
This will be explained laterInterrupts convey a lot of information but only indirectly. Theinterrupt itself just tells a chip called the interrupt controllerthat a certain serial port needs attention. The interrupt controllerthen signals the CPU. The CPU then runs a special program to servicethe serial port.
That program is called an interrupt service routine(part of the serial driver software). It tries to find out what hashappened at the serial port and then deals with the problem such atransferring bytes from (or to) the serial port's hardware buffer.This program can easily find out what has happened since the serialport has registers at IO addresses known to the serial driversoftware. These registers contain status information about the serialport.
The software reads these registers and by inspecting thecontents, finds out what has happened and takes appropriate action.Data (bytes representing letters, pictures, etc.) flows into andout of your serial port. Flow rates (such as 56k (56000) bits/sec)are (incorrectly) called 'speed'. But almost everyone says 'speed'instead of 'flow rate'.It's important to understand that the average speed is often less thanthe specified speed. Waits (or idle time) result in a lower averagespeed. These waits may include long waits of perhaps a second due to. At the other extremethere may be very short waits (idle time) of several micro-secondsbetween bytes. If the device on the serial port (such as a modem)can't accept the full serial port speed, then the average speed mustbe reduced.Flow control means the ability to slow down the flow of bytes in awire.
For serial ports this means the ability to stop and thenrestart the flow without any loss of bytes. Flow control is neededfor modems and other hardware to allow a jump in instantaneous flow rates. Example of Flow ControlFor example, consider the case where you connect a 33.6k externalmodem via a short cable to your serial port. The modem sends andreceives bytes over the phone line at 33.6k bits per second (bps).Assume it's not doing any data compression or error correction. Youhave set the serial port speed to 115,200 bits/sec (bps), and you aresending data from your computer to the phone line. Then the flow fromthe your computer to your modem over the short cable is at 115.2k bps.However the flow from your modem out the phone line is only 33.6k bps.Since a faster flow (115.2k) is going into your modem than is comingout of it, the modem is storing the excess flow (115.2k -33.6k = 81.6kbps) in one of its buffers. This buffer would soon overrun (run outof free storage space) unless the high 115.2k flow is stopped.But now flow control comes to the rescue.
When the modem's buffer isalmost full, the modem sends a stop signal to the serial port. Theserial port passes on the stop signal on to the device driver and the115.2k bps flow is halted. Then the modem continues to send out dataat 33.6k bps drawing on the data it previous accumulated in itsbuffer. Since nothing is coming into this buffer, the number of bytesin it starts to drop.
When almost no bytes are left in the buffer,the modem sends a start signal to the serial port and the 115.2k flowfrom the computer to the modem resumes. In effect, flow controlcreates an average flow rate in the short cable (in this case 33.6k)which is significantly less than the 'on' flow rate of 115.2k bps.This is 'start-stop' flow control.In the above simple example it was assumed that the modem did no datacompression. This could happen when the modem is sending a filewhich is already compressed and can't be compressed further. Nowlet's consider the opposite extreme where the modem is compressing thedata with a high compression ratio.
In such a case the modem mightneed an input flow rate of say 115.2k bps to provide an output (to thephone line) of 33.6k bps (compressed data). This compression ratio is3.43 (115.2/33.6).
In this case the modem is able to compress the115.2 bps PC-to-modem flow and send the same data (in compressed form)out the phone line at 33.6bps. There's no need for flow control hereso long as the compression ratio remains higher than 3.43.
But thecompression ratio varies from second to second and if it should dropbelow 3.43, flow control will be neededIn the above example, the modem was an external modem. But the samesituation exists (as of early 2003) for most internal modems. There isstill a speed limit on the PC-to-modem speed even though this flowdoesn't take place over an external cable. This makes the internalmodems compatible with the external modems.In the above example of flow control, the flow was from the computer toa modem.
But there is also flow control which is used for theopposite direction of flow: from a modem (or other device) to acomputer. Each direction of flow involves 3 buffers: 1. In the modem2. In the UART chip (called FIFOs) and 3. In main memory managed by theserial driver. Flow control protects all buffers (except the FIFOs)from overflowing.Under Linux, the small UART FIFO buffers are not protected by flowcontrol but instead rely on a fast response to the interrupts theyissue.
Some UART chips can be set to do hardware flow control toprotect their FIFOs but Linux (as of early 2003) doesn't seem tosupport it. FIFO stand for 'First In, First Out' which is the way ithandles bytes in a queue. All the 3 buffers use the FIFO rule butonly the one in the UART is named 'FIFO'.
This is the essence of flowcontrol but there are still some more details. Symptoms of No Flow ControlUnderstanding flow-control theory can be of practical use. Thesymptom of no flow control is that chunks of data missing from filessent without the benefit of flow control. When overflow happens,often hundreds or even thousands of bytes get lost, and all incontiguous chunks. Software Flow ControlIf feasible, it's best to use 'hardware' flow control that uses twodedicated 'modem control' wires to send the 'stop' and 'start'signals.
Hardware flow control at the serial port works like this:The two pins, RTS (Request to send) and CTS (Clear to send) are used.When the computer is ready to receive data it asserts RTS by putting apositive voltage on the RTS pin (meaning 'Request To Send to me').When the computer is not able to receive any more bytes, it negatesRTS by putting a negative voltage on the pin saying: 'stop sending tome'. The RTS pin is connected by the serial cable to another pin onthe modem, printer, terminal, etc. This other pin's only function isto receive this signal.For the case of a modem, this 'other' pin will be the modem's RTS pin.But for a printer, another PC, or a non-modem device, it's usually aCTS pin so a 'crossover' or 'null modem' cable is required. Thiscable connects the CTS pin at one end with the RTS pin at the otherend (two wires since each end of the cable has a CTS pin). For amodem, a straight-thru cable is used.For the opposite direction of flow a similar scheme is used.
For amodem, the CTS pin is used to send the flow control signal to the CTSpin on the PC. For a non-modem, the RTS pin sends the signal. Thusmodems and non-modems have the roles of their RTS and CTS pinsinterchanged.
Some non-modems such as dumb terminals may use otherpins for flow control such as the DTR pin instead of RTS.Software flow control uses the main receive and transmit data wires tosend the start and stop signals. It uses the ASCII control charactersDC1 (start) and DC3 (stop) for this purpose. They are just insertedinto the regular stream of data.
Software flow control is not onlyslower in reacting but also does not allow the sending of binary dataunless special precautions are taken. Since binary data will likelycontain DC1 and DC3 characters, special means must be taken todistinguish between a DC3 that means a flow control stop and a DC3that is part of the binary code. Likewise for DC1.It's been mentioned that there are 3 buffers for each direction offlow (3 pairs altogether): 16-byte FIFO buffers (in the UART), a pairof larger buffers inside a device connected to the serial port (suchas a modem), and a pair of buffers (say 8k) in main memory. When anapplication program sends bytes to the serial port they first getstashed in the transmit serial port buffer in main memory. The othermember of this pair consists of a receive buffer for the oppositedirection of byte-flow.
Here's an example diagram for the case ofbrowsing the Internet with a browser. Transmit data flow is left toright while receive flow is right to left.
There is a separate bufferfor each direction of flow.application 8k-byte 16-byte 1k-byte tele-BROWSER - MEMORY - FIFO - MODEM - phoneprogram buffer buffer buffer lineFor the transmit case, the serial device driver takes out say 15 bytesfrom this transmit buffer (in main memory), one byte at a time andputs them into the 16-byte transmit buffer in the serial UART fortransmission. Once in that transmit buffer, there is no way to stopthem from being transmitted. They are then transmitted to themodem or (other device connected to the serial port) which also has afair sized (say 1k) buffer. When the device driver (on orders fromflow control sent from the modem) stops the flow of outgoing bytesfrom the computer, what it actually stops is the flow of outgoingbytes from the large transmit buffer in main memory. Even after thishas happened and the flow to the modem has stopped, an applicationprogram may keep sending bytes to the 8k transmit buffer until itbecomes full. At the same time, the bytes stored in the FIFO continueto be sent out.
Ashrae fundamentals handbook free downl…. Bytes stored in the modem will continue to be sentout the phone line unless the modem has gotten a modem-to-modem flowcontrol stop from the modem at the other end of the phone line.When the memory buffer gets full, the application program can't sendany more bytes to it (a 'write' statement in a C-program blocks) andthe application program temporarily stops running and waits until somebuffer space becomes available. Thus a flow control 'stop' isultimately able to stop the program that is sending the bytes.
Eventhough this program stops, the computer does not necessarily stopcomputing since it may switch to running other processes while it'swaiting at a flow control stop.The above was a little oversimplified in three ways. First, some UARTscan do automatic hardware flow control which can stop the transmissionout of the FIFO buffers if needed (not yet supported by Linux).Second, while an application process is waiting to write to thetransmit buffer, it could possibly perform other tasks. Third, theserial driver (located between the memory buffer and the FIFO) hasit's own small buffer (in main memory) used to process characters.For many situations, there is a transmit path involving severallinks, each with its own flow control. For example, I type at atext-terminal connected to a PC and the PC (under my control) dialsout to another computer using a modem. Today, a 'text-terminal' islikely to be just another PC emulating a text-terminal.
The main(server) PC, in addition to serving my text-terminal, could also havesomeone else sitting at it doing something else. Note that callingthis PC a 'server' is not technically correct but it does serve theterminal.The text-terminal uses a command-line interface with no graphicaldisplay. Every letter I type at the text-terminal goes over theserial cable to my main PC and then over the phone line to thecomputer that I've dialed out to. To dial out, I've used thecommunication software: 'minicom' which runs on my PC.This sounds like a simple data path. I hit a key and the byte thatkey generates flows over just two cables (besides the keyboard cable):1. The cable from my text-terminal to my PC and 2.
The telephone linecable to some other computer. Of course, the telephone cable isactually a number of telephone system cables and includes switchesand electronics so that a single physical cable can transmit manyphone calls.
But I can think of it like one cable (or one link).Now, let's count the number and type of electronic devices eachkeystroke-byte has to pass thru. The terminal-to-PC cable has aserial port at each end. The telephone cable has both a serial portand a modem at each end. This adds up to 4 serial ports and 2 modems.Since each serial port has 2 buffers, and each modem one buffer, thatadds up to 10 buffers. And that's just for one direction of flow.Each byte also must pass thru the minicom software as well.While there's just 2 cables in the above scenario, if external modemswere used there would be an additional cable between each modem andit's serial port.
This makes 4 cables in all. Even with internalmodems it's like there is a 'virtual cable' between the modem and itsserial port. On all these 4 links (or cables), flow control takesplace.Now lets consider an example of the operation of flow control.Consider the flow of bytes from the remote computer at the other endof the phone line to the screen on the text-terminal that I'm sittingat.
A real text-terminal has a limit to the speed at which bytes canbe displayed on its screen and issues a flow control 'stop' from timeto time to slow down the flow. This 'stop' propagates in a directionopposite to the flow of bytes it controls. What happens when such a'stop' is issued? Let's consider a case where the 'stop' waits longenough before canceling it with a 'start', so that it gets thru tothe remote computer at the other end of the phone line. When it getsthere it will stop the program at the remote computer which is sendingout the bytes.Let's trace out the flow of this 'stop' (which may be 'hardware' onsome links and 'software' on others). First, suppose I'm 'capturing'a long file from the remote computer which is being sentsimultaneously to both my text-terminal and to a file on my hard-disk.The bytes are coming in faster than the terminal can handle them so itsends a 'stop' out its serial port to a serial port on my PC.
Thedevice driver detects it and stops sending bytes from the 8k PC serialbuffer (in main memory) to the terminal. But minicom still keepssending out bytes for the terminal into this 8k buffer.When this 8k transmit buffer (on the first serial port) is full,minicom must stop writing to it. Minicom stops and waits. But thisalso causes minicom to stop reading from the 8k receive buffer on the2nd serial port connected to the modem.
Flow from the modem continuesuntil this 8k buffer too fills up and sends a different 'stop' to themodem. Now the modem's buffer ceases to send to the serial port andalso fills up.
The modem (assuming error correction is enabled) sendsa 'stop signal' to the other modem at the remote computer. This modemstops sending bytes out of its buffer and when its buffer gets full,another stop signal is sent to the serial port of the remote computer.At the remote computer, the 8-k (or whatever) buffer fills up and theprogram at the remote computer can't write to it anymore and thustemporarily halts.Thus a stop signal from a text terminal has halted a program on aremote computer computer. What a long sequence of events! Notethat the stop signal passed thru 4 serial ports, 2 modems, and oneapplication program (minicom).
Each serial port has 2 buffers (in onedirection of flow): the 8k one and the hardware 16-byte one. Theapplication program may have a buffer in its Ccode.
This adds up to11 different buffers the data is passing thru. Note that the smallserial hardware buffers do not participate directly in flow control.Also note that the two buffers associated with the text-terminal'sserial port are going to be dumping their contents to the screenduring this flow control halt. This leaves 9 other buffers that maybe getting filled up during the flow control halt.If the terminal speed limitation is the bottleneck in the flow fromthe remote computer to the terminal, then its flow control 'stop' isactually stopping the program that is sending from the remote computeras explained above. But you may ask: How can a 'stop' last so longthat 9 buffers (some of them large) all get filled up?
It seldomhappens, but it can actually happen this way if all the buffers werenear their upper limits when the terminal sent out the 'stop'.But if you were to run a simulation on this you would discover that it'susually more complicated than this. At an instant of time some linksare flowing and others are stopped (due to flow control). A 'stop'from the terminal seldom propagates back to the remote computer neatly asdescribed above. It may take a few 'stops' from the terminal toresult in one 'stop' at the remote computer, etc. To understand whatis going on you really need to observe a simulation which can be donefor a simple case with coins on a table. Use only a few buffers andset the upper level for each buffer at only a few coins.Does one really need to understand all this? Well, understanding thisexplained to me why capturing text from a remote computer was loosingtext.
The situation was exactly the above example but modem-to-modemflow control was disabled. Chunks of captured text that were supposedto also get to my hard-disk never got there because of an overflow atmy modem buffer due to flow control 'stops' from the terminal. Eventhough the remote computer had a flow path to the hard-disk withoutbottlenecks, the same flow also went to a terminal which issued flowcontrol 'stops' with disastrous results for the branch of the flowgoing to a file on the hard-disk. The flow to the hard-disk passedthru my modem and since the overflow happened at the modem, bytesintended for the hard-disk were lost.The device driver for the serial port is the software thatoperates the serial port. It is now provided as a serial module.From kernel 2.2 on, this module will normally get loaded automaticallyif it's needed.
In earlier kernels, you had to have kerneldrunning in order to do auto-load modules on demand. Otherwise theserial module needed to be explicitly listed in /etc/modules. Beforemodules became popular with Linux, the serial driver was usually builtinto the kernel (and sometimes still is). If it's built-in don't letthe serial module load or else you will have two serial driversrunning at the same time. With 2 drivers there are all sorts oferrors including a possible 'I/O error' when attempting to open aserial port. Use 'lsmod' to see if the module is loaded.When the serial module is loaded it displays a message on the screenabout the existing serial ports (often showing a wrong IRQ).
But oncethe module is used by setserial to tell the device driver the(hopefully) correct IRQ then you should see a second display similarto the first but with the correct IRQ, etc. SeeSeefor more info onsetserial.The serial port istoday (2011) sort of obsolete on PCs (and often called a 'legacy'device) but it is still in use on some older computers and is used inimbedded systems, for communication with routers and point-of-saleequipment, etc.
The serial port isand after about 2005 most new PC's no longer had them. Most laptopsand Macs discontinued them even earlier. During the era when some newPC's came with serial ports and others didn't, the PC's that didn'thave serial ports were euphemistically called 'legacy-free'. However,while PC's today no longer have serial ports, some do have them builtinto a 'legacy' modem (which plugs into a telephone line). Such a serial portonly works with the modem and can't be used for any other device.
Thereason they have such a 'built in' serial port is that analog modemsare designed to only work thru a serial port.The physical serial port on the back of a PC (including the chip itsconnected to inside the PC), must pass data between the computer andan external cable. Thus it has two interfaces: the serial-port-tocable and the serial-port-to-computer-bus. Both of these interfacesare slow. First we'll consider the interface via external cable tothe outside world.The conventional RS-232 serial port is inherently low speed andis severely limited in distance. Ads often read 'high speed' but itcan only work at 'high speed' over very short distances such as to amodem located right next to the computer. Compared to a network card,even this 'high speed' is actually low speed.
All of the RS-232serial cable wires use a common ground return wire so thattwisted-pair technology (needed for high speeds) can't be used withoutadditional hardware. More modern interfaces for serial ports existbut they are not standard on PC's like the RS-232 is. Some multiport serialcards support them.It is somewhat tragic that the RS-232 standard from 1969 did not usetwisted pair technology which could operate about a hundred timesfaster. Twisted pairs have been used in telephone cables since thelate 1800's. In 1888 (over 120 years ago) the 'Cable Conference'reported its support of twisted-pair (for telephone systems) andpointed out its advantages.
But over 80 years after this approval bythe 'Cable Conference', RS-232 failed to utilize it. Since RS-232was originally designed for connecting a terminal to a low speed modemlocated nearby, the need for high speed and longer distancetransmission was apparently not recognized.
The result was that sincethe serial port couldn't handle high speeds, new types of serialinterfaces were devised that could: Ethernet, USB, Firewire, etc.The final outcome was the demise of the serial port which due to it'sancient technology became obsolete for high speed uses.The serial port communicates with the computer via the PCI bus,the LPC bus, X-bus, or ISA bus. The PCI bus is now 32 or 64 bits wide,but the serial port only sends a byte at a time (8 bits wide) which isa waste of PCI bus bandwidth. Not so for the LPC bus which has only a4-bit wide bus and thus provides an efficient interface. The ISA busis usually 16-bits wide and the efficiency is intermediate as comparedto efficient LPC and inefficient PCI.