misc.c 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#include <termios.h>
#include <sys/select.h>
#include <sys/time.h>

#include "irq.h"
#include "uart.h"
#include "endpoint.h"
#include "pps_gen.h"
#include "rxts_calibrator.h"

15 16
#include "host.h"

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
uint32_t _endram;

int wrc_stat_running;

/* timer */

void usleep_init(void)
{ printf("%s\n", __func__); }

void timer_init(uint32_t enable)
{ printf("%s\n", __func__); }

void timer_delay(uint32_t tics)
{
	usleep(tics * 1000);
}

uint32_t uptime_sec;

uint32_t timer_get_tics(void)
{
	struct timeval tv;
	uint64_t msecs;

	gettimeofday(&tv, NULL);
	msecs = tv.tv_sec * 1000 + tv.tv_usec / 1000;
	return msecs;
}

void shw_pps_gen_get_time(uint64_t * seconds, uint32_t * nanoseconds)
{
	struct timespec ts;

	clock_gettime(CLOCK_MONOTONIC, &ts);
	if (seconds)
		*seconds = ts.tv_sec;
	if (nanoseconds)
		*nanoseconds = ts.tv_nsec / NS_PER_CLOCK;
}



/* uart */
void uart_init_hw(void)
{
	struct termios t;

	printf("%s\n", __func__);

	tcgetattr(STDIN_FILENO, &t);
	cfmakeraw(&t);
	t.c_oflag |= ONLCR | OPOST;
	tcsetattr(STDIN_FILENO, 0, &t);
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stdin, NULL, _IONBF, 0);
	printf("UART simulator on the host: use ctrl-C or ctrl-D to exit\n");

}

void uart_init_sw(void)
{ printf("%s\n", __func__); }

79 80 81 82 83 84 85

void uart_exit(int i)
{
	system("stty sane");
	exit(i);
}

86 87 88 89 90 91 92 93 94 95 96 97
int uart_read_byte(void)
{
	fd_set set;
	int ret = -1;
	struct timeval tv = {0, 0};

	FD_ZERO(&set);
	FD_SET(STDIN_FILENO, & set);
	if (select(STDIN_FILENO + 1, &set, NULL, NULL, &tv) > 0)
		ret = getchar();
	/* Use ctrl-C and ctrl-D specially (hack!) */
	if (ret == 3 || ret == 4) {
98
		uart_exit(0);
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	}
	return ret;
}

/* unused stuff */

void disable_irq(void)
{ printf("%s\n", __func__); }

void enable_irq(void)
{ printf("%s\n", __func__); }

int wrc_mon_gui(void)
{ printf("%s\n", __func__); return 0;}

void sdb_find_devices(void)
{ printf("%s\n", __func__); }

int calib_t24p(int mode, uint32_t *value)
{ return 0; }

int ep_get_bitslide(void)
{ return 0; }

int ep_enable(int enabled, int autoneg)
{ return 0; }

void ep_init(uint8_t mac_addr[])
{ printf("%s\n", __func__); }

void pfilter_init_default(void)
{}
131 132 133 134 135 136 137 138 139 140

static int task_relax(void)
{
	usleep(1000);
	return 1; /* we did something */
}
DEFINE_WRC_TASK(relax) = {
	.name = "relax",
	.job = task_relax,
};