I am a business programmer with a few years of Linux administration experience. I'm starting out in embedded Linux. Yesterday, we were discussing a new device design and I was asked a few questions I had no answers for.
The engineers want to have some push buttons on an electronic board with a serial port on it. The OS is Linux.
Normally, when a user will connect to the serial port, a protocol will answer him instead of a Linux login prompt. However, if he pushes a sequence of buttons on the device, a Linux prompt will answer him on the serial port instead.
The Linu开发者_运维问答x driver to handle the push button interrupt handling aside, how can you switch the basic use of the serial port like that? Does anyone have a URL reference on how to do this? (preferably with some sample code)
Note: I proposed providing a nice menu on login for a given user, but no can do.
Thanks in advice for any suggestions.
Best regards, Bert
The main problem is that the process that implements your device protocol is probably keeping the serial port open.
In this case you should probably:
Wait for the button event
Have the protocol process close the serial port - terminating that process completely might also do for you
Launch a
*getty
process - or whatever your embedded target uses to present a login prompt on the serial portRestore the protocol process once you are done
EDIT:
In the steps above I assume the more common case where the process that controls the serial port (e.g. pppd
) is not able to act as a getty
substitute to provide a login prompt. It is also typically not the same process that provides telnet/SSH/whatever logins.
That said, it's quite possible on a customised embedded Linux system for a process to do more than one thing. In that case you have to configure or modify that process to switch operational modes when appropriate.
Without more information about your embedded target it's impossible to provide a more specific answer.
The getty
process is usually started on serial ports to provide a login prompt by /sbin/init
, which is configured in /etc/inittab
.
init
has the concept of "runlevels". Each runlevel defines a separate set of processes that init
will keep running. One elegant way to implement this would be to design your "protocol" process so that it is started by init
, in the same way as getty
. You can then tell init
to run your process in some runlevels, and getty
in others, and have the pushbutton switch between runlevels. For example, your /etc/inittab
might include:
T0:2:respawn:/sbin/getty -L ttyS0 9600 vt100
P0:345:respawn:/sbin/protocol ttyS0 9600
This will run your protocol
command on the first serial port in runlevels 3, 4 and 5; but getty
in runlevel 2.
精彩评论