OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 20, 2024 4:06 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: serial console ; speed settings ; error detection
PostPosted: Wed Dec 28, 2022 7:11 am 
Offline
Member
Member

Joined: Fri Apr 08, 2022 3:12 pm
Posts: 54
I've decided to have serial console output of my "kernel" so I can capture easily output when I'm testing stuff on actual HW. I'm starting simple - both bootloader and my kernel are just sending bytes by polling if byte can be sent via com0 serial port. My kernel init function: early_uart_init().

It does work however I wonder:
How can I detect if setting given speed is OK for remote side? Will reading LSR just after setting speed give me any information about that? Actually even int $0x14 AH=00h returns line status after attempted initialization. Can I assume 0xff as error during initialization ?

In my poll_uart_write() I set the arbitrary number to wait before I give up on sending a byte out. Some tutorials used infinite loop when waiting for it but I don't think it's a good idea. Is there a good common practice how long to wait? Can there be actually a situation when the buffer is always full ?


Top
 Profile  
 
 Post subject: Re: serial console ; speed settings ; error detection
PostPosted: Wed Dec 28, 2022 12:30 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5174
mtbro wrote:
How can I detect if setting given speed is OK for remote side?

Will the remote side respond in a particular way when it receives data at the correct speed? If not, you have no way to detect whether the remote side understands the data you're sending.

mtbro wrote:
Will reading LSR just after setting speed give me any information about that?

Only if the remote side is trying to send data; LSR will usually indicate errors when the speed doesn't match.

mtbro wrote:
Actually even int $0x14 AH=00h returns line status after attempted initialization. Can I assume 0xff as error during initialization ?

It's pretty unlikely that the line status register would be 0xFF immediately after initialization, but you can be a lot more certain by also checking the modem status register (which is also returned). If both status registers are 0xFF, there's probably no UART.

mtbro wrote:
Is there a good common practice how long to wait? Can there be actually a situation when the buffer is always full ?

If you're using one of the rare UARTs that actually supports hardware flow control in hardware and you've enabled that hardware flow control, the buffer could remain full forever if the remote device never requests more data. Otherwise, the only way the buffer could stay full is if the UART breaks.


Top
 Profile  
 
 Post subject: Re: serial console ; speed settings ; error detection
PostPosted: Wed Dec 28, 2022 1:28 pm 
Offline
Member
Member

Joined: Fri Apr 08, 2022 3:12 pm
Posts: 54
Octocontrabass wrote:
Will the remote side respond in a particular way when it receives data at the correct speed? If not, you have no way to detect whether the remote side understands the data you're sending.

At this time I don't expect any response from remote side. It's just passively showing whatever I send to it. At least at this stage. I was toying with the idea of creating gdb stub but it's nothing but an idea right now.

Thanks. I'll do a check on MSR too then.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group