Does a lot of work towards the PIT
Added a math library, with clamp and POW. added printf support for printing doubles added a few helper functions in PIT for calcaulting the time in seconds of a clock cycle based on divisor
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef ARCH_KEYB_H
|
||||
#define ARCH_KEYB_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef ARCH_PIT_H
|
||||
#define ARCH_PIT_H
|
||||
|
||||
@ -16,6 +18,27 @@ enum PIT_CHANNEL {
|
||||
CHANNEL_0 = 0x0,
|
||||
CHANNEL_1,
|
||||
CHANNEL_2,
|
||||
/**
|
||||
* Isn't supported on 8253 chips, but should be supported on AT and later (except for PS/2).
|
||||
*
|
||||
* Layout goes:
|
||||
* bits:
|
||||
* 76 - Set for READ_BACK
|
||||
* 5 - Latch count flag (0 = latch count, 1 = don't latch count)
|
||||
* 4 - Latch status flag (0 = latch status, 1 = don't latch status) - If this is clear, the next read of the corresponding data port will be a status byte
|
||||
* 3 - Read back timer channel 2 (1 = yes, 0 = no)
|
||||
* 2 - Read back timer channel 1 (..)
|
||||
* 1 - Read back timer channel 0 (..)
|
||||
* 0 - Reserved - set to 0
|
||||
*
|
||||
* Read back status byte:
|
||||
* bits:
|
||||
* 7 - Output pin state
|
||||
* 6 - Null count flags
|
||||
* 54 - Access mode
|
||||
* 321 - Operating mode
|
||||
* 0 BCD/Binary mode
|
||||
*/
|
||||
READ_BACK // 8254 only
|
||||
};
|
||||
|
||||
@ -28,6 +51,13 @@ enum PIT_CHANNEL {
|
||||
* HI AND LOW means that the values will come sequentially through the IO port, lowest followed by highest
|
||||
*/
|
||||
enum PIT_ACCESS_MODE {
|
||||
/*
|
||||
* To prevent the count from being updated, we can use this command to latch the PIT.
|
||||
* This must be xx000000 ( where x is the channel ).
|
||||
* The value for each channel remains latched, until its fully read (or a new CMD has been issued).
|
||||
* Some older/cheap motherboards have an issue with this command being sent a lot, leading to innaccuracies
|
||||
* this command shouldn't be sent a lot anyways.
|
||||
*/
|
||||
LATCH_COUNT_VAL_CMD = 0x0,
|
||||
LO_BYTE_ONLY,
|
||||
HI_BYTE_ONLY,
|
||||
@ -213,5 +243,16 @@ enum PIT_DIGIT_MODE {
|
||||
BCD_MODE // four-digit bcd
|
||||
};
|
||||
|
||||
struct pit_state {
|
||||
uint32_t divisor;
|
||||
} __attribute__((packed));
|
||||
|
||||
void init_pit(uint32_t divisor);
|
||||
|
||||
double get_time_from_divisor(uint32_t divisor);
|
||||
|
||||
|
||||
uint16_t read_pit_count(uint8_t channel);
|
||||
void set_pit_count(uint8_t channel, uint16_t count);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user