#include "hardware_timestamp.h"

#include <io.h>

#define REG_STATE_OFFSET 0
#define STOPPED 0
#define RUNNING 1

#define REG_CYCLE_COUNT_OFFSET 1

uint32_t hardware_timestamp_is_running( uint32_t base ) {
    return IORD( base, REG_STATE_OFFSET ) == RUNNING;
}

uint32_t hardware_timestamp_is_stopped( uint32_t base ) {
    return IORD( base, REG_STATE_OFFSET ) == STOPPED;
}

uint32_t hardware_timestamp( uint32_t base ) {
    return IORD( base, REG_CYCLE_COUNT_OFFSET );
}

void hardware_timestamp_start( uint32_t base ) {
    IOWR( base, REG_STATE_OFFSET, RUNNING );
}

void hardware_timestamp_stop( uint32_t base ) {
    IOWR( base, REG_STATE_OFFSET, STOPPED );
}

