need a way to sleep for 10ms or less, but!!!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

need a way to sleep for 10ms or less, but!!!

Post by ITchimp »

I am writing an experimental floppy driver (1.44mb) , and need to be able to sleep for 10ms.

but my PIT timer is 50ms per tick, if I use a linked list of count down objects, the least amount of sleep time is 50ms ... so I have to use some other methods to implement 10ms delay...

Any recommendations?
foliagecanine
Member
Member
Posts: 148
Joined: Sun Aug 23, 2020 4:35 pm

Re: need a way to sleep for 10ms or less, but!!!

Post by foliagecanine »

Use a lower PIT frequency?
My OS: TritiumOS
https://github.com/foliagecanine/tritium-os
void warranty(laptop_t laptop) { if (laptop.broken) return laptop; }
I don't get it: Why's the warranty void?
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: need a way to sleep for 10ms or less, but!!!

Post by kzinti »

Surely you mean a higher frequency?

50 ms = 20Hz
10 ms = 100Hz
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: need a way to sleep for 10ms or less, but!!!

Post by nullplan »

ITchimp wrote:I am writing an experimental floppy driver (1.44mb) , and need to be able to sleep for 10ms.

but my PIT timer is 50ms per tick,[...]
You do love your fossils, don't you?

Option 1: Speed up the PIT. The PIT is certainly capable of delivering interrupts to you quickly enough for your requirement, so just speed up the PIT, and add a software divider for the other function that uses it.
Option 2: Use a different timer. In a modern PC, you have the HPET, LAPIC timer, ACPI PM timer, and the TSC available. All of which more than capable of measuring 10ms.
Carpe diem!
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: need a way to sleep for 10ms or less, but!!!

Post by bzt »

ITchimp wrote:I am writing an experimental floppy driver (1.44mb) , and need to be able to sleep for 10ms.

but my PIT timer is 50ms per tick, if I use a linked list of count down objects, the least amount of sleep time is 50ms ... so I have to use some other methods to implement 10ms delay...

Any recommendations?
PS/2 control port B (0x61) bit 5 is oscillating at 15 us. SeaBIOS uses that to calibrate tsc freq, but you could poll that bit to wait for 15 us.
1. wait until it changes to get a baseline
2. as soon as the bit changes again, 15 us has elapsed
The bochs bios implements INT 15 AH=86 (wait n microsec) directly by watching that port.

Cheers,
bzt
Last edited by bzt on Wed Sep 30, 2020 9:34 am, edited 1 time in total.
foliagecanine
Member
Member
Posts: 148
Joined: Sun Aug 23, 2020 4:35 pm

Re: need a way to sleep for 10ms or less, but!!!

Post by foliagecanine »

Sorry, kzinti,
Yes I did mean a higher PIT frequency.

--------------------------------------------

You can easily have a 1ms delay = 1000hz PIT with this code:

Code: Select all

outb(0x43, 0x34);
outb(0x40, 169);
outb(0x40, 4); 
You'd have to adjust your sleep function though.
My OS: TritiumOS
https://github.com/foliagecanine/tritium-os
void warranty(laptop_t laptop) { if (laptop.broken) return laptop; }
I don't get it: Why's the warranty void?
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: need a way to sleep for 10ms or less, but!!!

Post by Schol-R-LEA »

Why are you sleeping, exactly? More details of your design could help, as I suspect you could avoid sleeping entirely with a slightly different approach.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Post Reply