예제 #1
0
파일: timer.c 프로젝트: PTJohe/LCOM
int timer_set_square(unsigned long timer, unsigned long freq) {
	char buf[12];
	sprintf(buf, "TIMER_SEL", timer);
	unsigned long div = (TIMER_FREQ / freq);
	unsigned long LSB = div;
	unsigned long MSB = (div >> 8);
	unsigned char conf, port;
	if (freq < 19){
		printf("Error: Frequency must be greater than 18 Hz.\n");
		printf("OVERFLOW -> (Clock signal frequency)/freq must have a maximum of 16 bits.\n");
		return EXIT_FAILURE;
	}
	else if (TIMER_FREQ < freq){
		printf("Error: Frequency must be less than 1193182 Hz (clock signal frequency).\n");
		return EXIT_FAILURE;
	}
	int i = timer_get_conf(timer, &conf);
	if (i != 0)
		return EXIT_FAILURE;
	port = (TIMER_0 + timer);
	unsigned char counting_mode;
	if (conf == 0)
		counting_mode = TIMER_BIN;
	else if (conf == 1)
		counting_mode = TIMER_BCD;
	if (sys_outb(TIMER_CTRL, (int) buf | TIMER_LSB_MSB | TIMER_SQR_WAVE | counting_mode ) != OK
				|| sys_outb(port, LSB) != OK
				|| sys_outb(port, MSB) != OK)
		return EXIT_FAILURE;
	else
		return EXIT_SUCCESS;

}
예제 #2
0
파일: timer.c 프로젝트: PTJohe/LCOM
int timer_test_config(unsigned long timer) {
	unsigned char conf;
	timer_get_conf(timer, &conf);
	timer_display_conf(conf);
	if (conf = 0xB6)
		return EXIT_SUCCESS;
	else
		return EXIT_FAILURE;
}
예제 #3
0
int timer_test_config(unsigned long timer) {
	unsigned long *st;
	if ((st = malloc(sizeof(unsigned char))) != NULL)
	{
		if (timer_get_conf(timer, st))
		{
			free(st);
			return 1;
		}
		return timer_display_conf((unsigned char)*st);
	}
	free(st);
	return 1;
}
예제 #4
0
파일: timer.c 프로젝트: tomislaaaav/LCOM
int timer_set_square(unsigned long timer, unsigned long freq) {

	unsigned long tempByte;
	unsigned char st;

	if (timer == 0)
		{
			timer_get_conf(timer, &st);
			st = 0x0F & st; //st fica com os ultimos 4 bits
			tempByte = (TIMER_SEL0 | TIMER_LSB_MSB | st); // seleciona o TIMER_0 e ativa LSB followed by MSB
			sys_outb(TIMER_CTRL, tempByte);
			sys_outb(TIMER_0, TIMER_FREQ/freq); //manda LSB
			sys_outb(TIMER_0, (TIMER_FREQ/freq >> 8)); //manda MSB
			return 0;
		}
예제 #5
0
파일: timer.c 프로젝트: pedro-c/LCOM-FEUP
int timer_set_square(unsigned long timer, unsigned long freq) {
	unsigned long lsb;
	unsigned char msb;
	unsigned long fr;
	unsigned char st;

	//verifica se o resultado da frequencia é menor que o valor maximo possivel de representar em 2 bytes.
	if(TIMER_FREQ/freq >= 0xFFFF)
	{
		printf("Frequencia nao suportavel pelo timer (overflow).\n");
		return 1;
	}

	fr = TIMER_FREQ / freq;
	if (timer == 0 || timer == 1 || timer == 2)
	{
		timer_get_conf(timer, &st);

		st=st<<4;
		st=st>>4;
		st=(TIMER_0 + timer | TIMER_LSB_MSB | st); //controlador criado mantendo o counting mode e operation
		if (sys_outb(TIMER_CTRL, st)) {
			printf("Error by calling sys_outb for confs\n");
			return 1;
		}

		lsb = (char)fr; //isola o primeiro byte da frequencia
		fr = fr>>8;
		msb = (char)fr; //isola o segundo byte da frequencia

		if (sys_outb(TIMER_0 + timer, lsb))	//envia o LSB para o timer
				{
			printf("Error by calling sys_outb for lsb.\n");
			return 1;
				}
		else if (sys_outb(TIMER_0 + timer, msb)) //envia o MSB para o timer
				{
			printf("Error by calling sys_outb for msb.\n");
			return 1;
				}
		else {
			return 0;
		}
	} else
예제 #6
0
int timer_test_config(unsigned long timer)
{
	unsigned char tempo;
	int erro;
	if(timer<0 || timer >2)
	{
		return 1;
	}
	erro = timer_get_conf(timer,&tempo);

	if(erro == 1)
		return 1;


	erro = timer_display_conf(tempo);

	if(erro == 1)
		return 1;

	return 0;
}
예제 #7
0
int timer_set_square(unsigned long timer, unsigned long freq)
{
	unsigned long div = TIMER_FREQ/freq;
	char conf;
		if(freq == 0 || freq > TIMER_FREQ || div >= (1 << 16))
		{
			return 1;
		}

		if(timer >= 0 && timer <= 2)
		{

		if(timer_get_conf(timer,&conf)!= 0)
		{
			return 1;
		}

		if(sys_outb(TIMER_CTRL,TIMER_SEL0 | TIMER_LSB_MSB | TIMER_SQR_WAVE | (conf & BIT(0))) != 0)
		{
			return 1;
		}

		if(sys_outb(TIMER_0+timer, (char)div) != 0)
		{
			return 1;
		}

		if(sys_outb(TIMER_0+timer,(char)(div>>8)) != 0)
		{
			return 1;
		}

		return 0;
		}

		return 1;
}