target-utils: added 10 ms delay at the end of abb_power_off()
The deosmification of the ABB access code (replacement of osmo_delay_ms()
bogus delays with correctly-timed ones, which are significantly shorter)
had one annoying side effect: when executing the poweroff command from
any of the programs, one last '=' prompt character was being sent (and
received by the x86 host) as the Calypso board powers off. With delays
being shorter now, the abb_power_off() function was returning and the
standalone program's main loop was printing its prompt before the Iota chip
fully executed the switch-off sequence!
I thought about inserting an endless tight loop at the end of the
abb_power_off() function, but the implemented solution of a 10 ms delay
is a little nicer IMO because if the DEVOFF operation doesn't happen for
some reason in a manual hacking scenario, there won't be an artificial
blocker in the form of a tight loop keeping us from further poking around.
The highest baud rate supported by "standard" PC serial ports is 115200 bps,but Calypso UARTs can go quite a bit faster. Being clocked with 13 MHz (astandard frequency in the GSM world), these UARTs can produce non-standard(outside of the GSM world) baud rates of 203125, 406250 and 812500 bps. Eventhough these high baud rates aren't supported by "standard" RS-232 serial portson PCs, they *are* supported by some of the better USB to serial adapters,namely CP2102 (USB to single UART) and the FT2232x family (USB to two UARTs).The Pirelli DP-L10 phone supported by FreeCalypso host tools has a CP2102 builtin, the officially recommended 2.5 mm headset jack USB-serial cables for workingwith Motorola C1xx and Openmoko GTA01/02 phones also use CP2102 adapters,whereas our FreeCalypso development boards (FCDEV3B) are typically used with anFT2232D or other FT2232x USB to dual UART adapter.FreeCalypso tools can use these high serial baud rates in the following ways:* When you use fc-loadtool to dump and program GSM device flash memory (flashing firmware images), the transfers get annoyingly slow at 115200 baud if you have to do it a lot. Switching to 406250 or even better 812500 baud makes them go considerably faster.* Some of our target devices have large enough RAM to execute a GSM firmware image entirely from RAM without flashing - very handy for development and experimentation. The tool used to run these RAM-based images is fc-xram, and it also supports the option of using high serial baud rates for the image transfer for the same reason: repeatedly transferring >2 MiB images over 115200 baud gets tiresome.* If you are building your own FreeCalypso-based or TI-based GSM firmware in a special non-standard configuration, you can make it run its RVTMUX interface at 406250 or 812500 baud. We used this trick when we tried to make TCS211 with D-Sample-targeting UI (176x220 pix LCD, 16 bits per pixel) send its virtual LCD raster blits out the serial port. Our rvtdump and rvinterf utilities support this mode of operation by providing options to select different baud rates.Recent changes for better FTDI adapter support==============================================There is one fundamental difference between the way CP2102 adapters supportnon-standard baud rates (like the high GSM baud rates of interest to us) andthe way in which FTDI adapters support them. CP2102 chips have a built-inEEPROM that contains (among other things) a 32-entry table in which thesupported serial baud rates are programmed, and the programming of this EEPROMeffects a remapping: a Linux userspace process can request B230400, B460800 orB921600 from termios, but magically get 203125, 406250 or 812500 as the actualresulting serial baud rate instead. In contrast, FTDI adapters have no suchmagic remapping mechanism in hardware, thus in order to get 203125, 406250 or812500 baud with an FTDI adapter, the userspace process has to explicitlyrequest these special baud rates from the serial driver in the kernel, anddoing the latter requires foregoing the standard termios API and using Linux-specific <asm/...> header files and raw ioctl calls instead.When support for high GSM baud rates was first added to FreeCalypso host toolsback in 2013, there was no need to support the more difficult FTDI adapters asthe easier to work with CP2102 was fully sufficient for our needs, hence ouroriginal FC host tools implementation required "magic" baud rate remappingsomewhere below, usually in form of CP2102 EEPROM programming but also possiblyby way of a hacky patch to the ftdi_sio driver in the Linux kernel to achievethe same effect with rarely-needed FTDI adapters.The situation has changed with the introduction of our own FreeCalypsodevelopment boards (currently FCDEV3B, possibly others in the future) whichbring out both Calypso UARTs to the user, rather than just one. The mostconvenient serial adapters for working with these dual UARTs are FT2232x (ourcurrent official adapter is FT2232D), thus we now have a strong need to supportthe use of these FTDI adapters, including the use of high GSM baud rates, in amanner which does not fight against the mainline Linux kernel.In a radical change from fc-host-tools-r6 and earlier, the present version ofFreeCalypso host tools uses new libserial code that differs from the old codeas follows:* Linux-specific <asm/...> headers are used instead of <termios.h>;* Linux-specific raw ioctl calls are used instead of tcsetattr() for serial port setup;* When the user requests 203125, 406250 or 812500 baud, these are the actual baud rates requested from the kernel, not 230400/460800/921600 baud.This change is expected to have no adverse effect on the existing CP2102 users,as the cp210x driver in Linux appears to cope fine with the strange baud raterequests from userspace and the correct CP2102 EEPROM baud rate entry stillgets selected (tested on Slackware 13.37 and Debian 9), but when working withFTDI adapters such as our FT2232D adapter for the FCDEV3B this change makes thehigh GSM baud rates work without needing the dirty kernel patch which theMother has been using up until now.Support for other Unix flavors==============================The serial port handling code for all of FC host tools has been factored outinto a common library called libserial. We have two versions of libserial:* libserial-orig uses the standard and presumably portable termios API, but requires "magic" remapping of baud rates by some invisible genie below (like CP2102 EEPROM programming) in order to get 203125/406250/812500 baud.* libserial-newlnx uses Linux-specific header files and raw ioctl calls to request the actual desired baud rates.If you would like to run FreeCalypso host tools under FreeBSD, illumos or someother alternative-to-Linux OS, you have two basic choices:* If you wish to use high GSM baud rates with non-remapping FTDI adapters or other serial interfaces which support the baud rates in question without remapping, you will need to figure out how to request non-standard serial baud rates from the underlying drivers under your OS, and create your own version of libserial ported to use that method.* If you don't need high GSM baud rates or need them only with CP2102 adapters which "magically" remap them, you should be able to use libserial-orig. You can also completely remove the entries for the high GSM baud rates from libserial-orig/baudtab.c if you don't need these high baud rates and your version of termios does not have B230400/B460800/B921600 baud rate constants.It is assumed that any system on which someone may desire to run our FC hosttools supports at least 115200 baud. The Mother remembers the days when thisbaud rate was considered very high and non-standard and even has some of thoselovely old systems still running; fc-loadtool and friends going through theCalypso boot ROM (not through Compal's bootloader) can be made to work with ahost system whose UARTs max out at 19200 baud, but most Calypso GSM devicefirmwares including our own use the 115200 baud rate.Using CP2102 adapters with Mot C1xx and Openmoko phones=======================================================As already mentioned above, CP2102 chips have a built-in EEPROM that contains(among other things) a 32-entry table in which the supported serial baud ratesare programmed. In order to support the special GSM baud rates, these ratesneed to be added to that table, displacing some other entries. The conventionestablished by the Pirelli DP-L10 phone (has a CP2102 built in and programmedat the factory for GSM baud rates) is that 203120 baud takes the place of230400, 406250 takes the place of 460800, and 812500 takes the place of 921600.Because you need a special cable anyway to make the necessary physicalconnection to the debug/programming serial port presented on a 2.5 mm headsetjack, you will probably be buying the requisite cable from a specializedprofessional vendor. In that case it is that vendor's responsibility to sellyou the cable with the CP2102 chip already programmed with GSM baud rates:because the physical construction of the cable (2.5 mm headset jack on theserial end) makes it specific to GSM devices, and all known GSM devices use a13 MHz clock or some integer multiple thereof, it is pointless for aphysically-GSM-specific cable to be set up for 230400/460800/921600 baud whenall known GSM devices will need 203125/406250/812500 baud instead.If you are making a CP2102-based serial cable yourself (either for your ownpersonal use or professionally/commercially), please follow these instructionsfor baud rate programming:http://osmocom.org/projects/baseband/wiki/HardwareCP210xTutorialIf you follow the procedure given on that page, your CP2102 will be programmedthe same way as the one in the Pirelli DP-L10 (Foxconn's original factoryprogramming).Using adapters built into phones================================The Calypso chip has no native USB capabilities, thus if a Calypso phonepresents a USB charging+data port to the user, it must have a USB to serialconverter built in. The only phone we currently know of that does this isPirelli DP-L10, and its built-in USB-serial adapter chip is CP2102. It hasalready been programmed with the correct GSM baud rates on Foxconn's originalproduction line, thus one can always use 812500 baud with FreeCalypso tools onthis phone and it will Just Work.