Example #1
0
uint8_t ICACHE_FLASH_ATTR 
twi_writeTo(uint8_t address, uint8_t *buf, unsigned int len,
	    uint8_t sendStop)
{
	unsigned int i;
	if (!twi_write_start()) {
		serial_print("I2C: bus busy\r\n");
		return 4;
	}
	if (!twi_write_byte(((address << 1) | 0) & 0xFF)) {
		if (sendStop)
			twi_write_stop();
		serial_print("I2C: received NACK on transmit of address\r\n");
		return 2;
	}
	for (i = 0; i < len; i++) {
		if (!twi_write_byte(buf[i])) {
			if (sendStop)
				twi_write_stop();
			serial_print("I2C: received NACK on transmit of data\r\n");
			return 3;
		}
	}
	if (sendStop)
		twi_write_stop();
	i = 0;
	while (SDA_READ() == 0 && (i++) < 10) {
		SCL_LOW();
		twi_delay(twi_dcount);
		SCL_HIGH();
		twi_delay(twi_dcount);
	}
	return 0;
}
Example #2
0
uint8_t ICACHE_FLASH_ATTR 
twi_readFrom(uint8_t address, uint8_t *buf, unsigned int len,
	     uint8_t sendStop)
{
	unsigned int i;
	if (!twi_write_start()) {
		serial_print("I2C: bus busy\r\n");
		return 4;
	}
	if (!twi_write_byte(((address << 1) | 1) & 0xFF)) {
		if (sendStop)
			twi_write_stop();
		serial_print("I2C: received NACK on transmit of address\r\n");
		return 2;
	}
	for (i = 0; i < (len - 1); i++)
		buf[i] = twi_read_byte(false);
	buf[len - 1] = twi_read_byte(true);
	if (sendStop)
		twi_write_stop();
	i = 0;
	while (SDA_READ() == 0 && (i++) < 10) {
		SCL_LOW();
		twi_delay(twi_dcount);
		SCL_HIGH();
		twi_delay(twi_dcount);
	}
	return 0;
}
Example #3
0
void check_for_new_bytes_received( )
{
	while(serial_get_received_bytes(USB_COMM) != receive_buffer_position)
	{
		// Remember the byte that was received, ignore if user pushed too many bytes
		if ( bytes_received > sizeof(my_received_buffer) )
		{
			bytes_received = 0;
			memset( my_received_buffer, 0, sizeof(my_received_buffer) );
			serial_print( "Buffer Exceeded, try again!" );
		}
		else
		{
			if ( receive_buffer[receive_buffer_position] == 0x8 || receive_buffer[receive_buffer_position] == 0x7F )
			{
				// treat this as a backspace
				bytes_received = (bytes_received > 0) ? bytes_received - 1 : bytes_received;
				my_received_buffer[bytes_received] = '\0';
			}
			else
			{
				my_received_buffer[bytes_received] = receive_buffer[receive_buffer_position];
				bytes_received++;
			}
			
			// echo what was typed on the serial console back to the serial console
			serial_print_char( receive_buffer[receive_buffer_position] );
		}
		
		// Increment receive_buffer_position, but wrap around when it gets to
		// the end of the buffer.
		if (receive_buffer_position == sizeof(receive_buffer)-1)
		{
			receive_buffer_position = 0;
		}
		else
		{
			receive_buffer_position++;
		}
	}
	
	if ( bytes_received && (my_received_buffer[bytes_received-1] == '\r' || my_received_buffer[bytes_received-1] == '\n') )
	{
		// echo string to serial console
		serial_print( "%s", my_received_buffer );
		
		// check makes sure we have atleast 3 bytes of data from user interface
		if ( bytes_received > 1)
		{
			strip( my_received_buffer, sizeof(my_received_buffer) );
			process_received_bytes( my_received_buffer );
		}
		
		memset( my_received_buffer, 0, sizeof(my_received_buffer) );
		bytes_received = 0;
	}
}
Example #4
0
void gettime()
{
    serial_print(gethour());
    serial_print(":");

    serial_print(getminute());
    serial_print(":");

    serial_println(getsecond());
    serial_println("");
}
Example #5
0
void showPCB() {
    serial_print("Please enter the name of the desired PCB to view: ");
    char* pcbName = polling();
    PCB* process = findPCB(pcbName);
    
    if (process == NULL) {
      serial_print(pcbName);
      serial_println(" is not a valid PCB");
      return;
    } 
    PrintPCB(process);
    sys_free_mem(pcbName);
    sys_free_mem(process);
}
Example #6
0
static void endpoint0_transmit(const void *data, uint32_t len)
{
#if 0
	serial_print("tx0:");
	serial_phex32((uint32_t)data);
	serial_print(",");
	serial_phex16(len);
	serial_print(ep0_tx_bdt_bank ? ", odd" : ", even");
	serial_print(ep0_tx_data_toggle ? ", d1\n" : ", d0\n");
#endif
	table[index(0, TX, ep0_tx_bdt_bank)].addr = (void *)data;
	table[index(0, TX, ep0_tx_bdt_bank)].desc = BDT_DESC(len, ep0_tx_data_toggle);
	ep0_tx_data_toggle ^= 1;
	ep0_tx_bdt_bank ^= 1;
}
Example #7
0
extern "C" int main()
{
    pinMode(LED_BUILTIN, OUTPUT);
    leds.begin();

    // Announce firmware version
    serial_begin(BAUD2DIV(115200));
    serial_print("Fadecandy v" DEVICE_VER_STRING "\r\n");

    // Application main loop
    while (usb_dfu_state == DFU_appIDLE) {
        watchdog_refresh();

        buffers.handleUSB();
        updateDrawBuffer(calculateInterpCoefficient());
        leds.show();

        // Optionally disable dithering by clearing our residual buffer every frame.
        if (buffers.flags & CFLAG_NO_DITHERING) {
            for (unsigned i = 0; i < CHANNELS_TOTAL; ++i)
                residual[i] = 0;
        }
    }

    // Reboot into DFU bootloader
    dfu_reboot();
}
Example #8
0
File: serial.c Project: else/xelix
static int console_driver_serial_write(console_info_t *info, char c)
{
	if (c == 0x8 || c == 0x7f)
	{
		serial_print("\b \b");
		return 1;
	}

	char cs[2];
	cs[0] = c;
	cs[1] = 0;

	serial_print(cs);

	return 1;
}
Example #9
0
void __init plat_mem_setup(void)
{
#if 1
	board_be_handler = ath_be_handler;
#endif
	_machine_restart = ath_restart;
	_machine_halt = ath_halt;
	pm_power_off = ath_power_off;

	/*
	 ** early_serial_setup seems to conflict with serial8250_register_port()
	 ** In order for console to work, we need to call register_console().
	 ** We can call serial8250_register_port() directly or use
	 ** platform_add_devices() function which eventually calls the
	 ** register_console(). AP71 takes this approach too. Only drawback
	 ** is if system screws up before we register console, we won't see
	 ** any msgs on the console.  System being stable now this should be
	 ** a special case anyways. Just initialize Uart here.
	 */

#ifdef CONFIG_SERIAL_8250
	UartInit();
#endif

#ifdef CONFIG_MACH_AR933x
	/* clear wmac reset */
	ath_reg_wr(ATH_RESET,
		      (ath_reg_rd(ATH_RESET) & (~ATH_RESET_WMAC)));
#endif
	serial_print("Booting %s\n", get_system_type());
}
Example #10
0
static void
handle_serial_input(void)
{
	while (1) {
		switch (serial_getchar()) {
		case '\0':
			cli();
			if (!serial_available())
				events &= ~EV_SERIAL;
			sei();
			return;

		case 'O': /* open */
			pin_low(PIN_GREEN_LED);
			pin_low(PIN_OPEN_LOCK);
			_delay_ms(500);
			pin_high(PIN_OPEN_LOCK);
			serial_print("OPENAKCK\n");
			pin_high(PIN_GREEN_LED);
			break;

		case 'D': /* day */
			pin_low(PIN_GREEN_LED);
			pin_low(PIN_DAYMODE);     /* day mode   */
			pin_high(PIN_STATUS_LED); /* status on  */
			break;

		case 'N': /* night */
			pin_high(PIN_GREEN_LED);
			pin_high(PIN_DAYMODE);    /* nightmode  */
			pin_low(PIN_STATUS_LED);  /* status off */
			break;

		case 'R': /* rejected */
			pin_low(PIN_YELLOW_LED);
			_delay_ms(200);
			pin_high(PIN_YELLOW_LED);
			_delay_ms(200);
			pin_low(PIN_YELLOW_LED);
			_delay_ms(200);
			pin_high(PIN_YELLOW_LED);
			break;

		case 'V': /* validated */
			pin_low(PIN_GREEN_LED);
			_delay_ms(300);
			pin_high(PIN_GREEN_LED);
			_delay_ms(200);
			pin_low(PIN_GREEN_LED);
			_delay_ms(300);
			pin_high(PIN_GREEN_LED);
			_delay_ms(200);
			pin_low(PIN_GREEN_LED);
			_delay_ms(300);
			pin_high(PIN_GREEN_LED);
			break;
		}
	}
}
Example #11
0
void setdate()
{
    setyear();
    setmonth();
    setday();

    serial_print("Time successfully changed to -> ");
    getdate();
}
Example #12
0
void settime()
{
	sethour();
    setminute();
    setseconds();

    serial_print("Time successfully changed to -> ");
    gettime();
}
Example #13
0
void help()
{
  while(1) {
    serial_println("Which command would you like to know more about?");
    serial_println("Enter CommandList for a list of commands.");
    serial_println("Enter QuitHelp to exit.");
    char *command = polling();
    if (!strcmpigncase(command, "CommandList")) {
	serial_println("Here's a list of available commands:");
	serial_println("Version");
	serial_println("Help");
	serial_println("Setdate");
	serial_println("Getdate");
	serial_println("Settime");
	serial_println("Gettime");
	serial_println("Shutdown");
	serial_println("");
    }
    else if (!strcmpigncase(command, "QuitHelp")) {
      return;
    }
    else if (!strcmpigncase(command, "Version")) {
      serial_println("Version shows the current version of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Help")) {
      serial_println("Help gets further help for a prompted command");
      return;
    }
    else if (!strcmpigncase(command, "Setdate")) {
      serial_println("Setdate allows the user to set the date of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Getdate")) {
      serial_println("Getdate returns the current date of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Settime")) {
      serial_println("Settime allows the user to set the time of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Gettime")) {
      serial_println("Gettime returns the current date of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Shutdown")) {
      serial_println("Shutdown turns off the operating system.");
      return;
    }
    else {
      serial_print("Unrecognized command: ");
      serial_println(command);
    }
  }    
}
Example #14
0
void serial_println(char *str)
{
    serial_print(str);
    //finish by sending a newline character
    //usart0_transmit_buffer_insert(0x0D);
    //loop_until_bit_is_set(UCSRA, UDRE); // wait for UDR to be clear
    //UDR = 0x0D;    //send the character
    loop_until_bit_is_set(UART_CONTROL_STATUS_REG_A, UART_READY_TO_TRANSMIT); // wait for UDR to be clear
    UART_DATA_REG = 0x0D;    //send the character


}
Example #15
0
void getdate()
{
	char *encodedweekday = getweekday();
    serial_print(toweekday(encodedweekday));
    serial_print(" ");

    char *encodedmonth = getmonth();
    serial_print(tomonth(encodedmonth));
    serial_print(" ");

    serial_print(getmonthday());
    serial_print(" ");

    char *encodedyear = getyear();
    char *year = sys_alloc_mem(5);
    year[0] = '2';
    year[1] = '0';
    year[2] = encodedyear[0];
    year[3] = encodedyear[1];
    year[4] = '\0';
    serial_println(year);
    serial_println("");
    sys_free_mem(encodedyear);
    sys_free_mem(encodedweekday);
    sys_free_mem(encodedmonth);
    sys_free_mem(year);
}
Example #16
0
void gettime()
{
	outb(0x70, 0x04);
	unsigned char bcdtime = inb(0x71);
	char *convtime = sys_alloc_mem(5);
	fromBCD(bcdtime, convtime);
    serial_print(convtime);
    serial_print(":");

    outb(0x70, 0x02);
    bcdtime = inb(0x71);
    fromBCD(bcdtime, convtime);
    serial_print(convtime);
    serial_print(":");

    outb(0x70, 0x00);
    bcdtime = inb(0x71);
    fromBCD(bcdtime, convtime);
    serial_println(convtime);
    serial_println("");
    sys_free_mem(convtime);
}
// send the contents of keyboard_keys and keyboard_modifier_keys
int usb_keyboard_send(void)
{
#if 0
	serial_print("Send:");
	serial_phex(keyboard_modifier_keys);
	serial_phex(keyboard_keys[0]);
	serial_phex(keyboard_keys[1]);
	serial_phex(keyboard_keys[2]);
	serial_phex(keyboard_keys[3]);
	serial_phex(keyboard_keys[4]);
	serial_phex(keyboard_keys[5]);
	serial_print("\n");
#endif
#if 1
	uint32_t wait_count=0;
	usb_packet_t *tx_packet;

	while (1) {
		if (!usb_configuration) {
			return -1;
		}
		if (usb_tx_packet_count(KEYBOARD_ENDPOINT) < TX_PACKET_LIMIT) {
			tx_packet = usb_malloc();
			if (tx_packet) break;
		}
		if (++wait_count > TX_TIMEOUT || transmit_previous_timeout) {
			transmit_previous_timeout = 1;
			return -1;
		}
		yield();
	}
	*(tx_packet->buf) = keyboard_modifier_keys;
	*(tx_packet->buf + 1) = keyboard_media_keys;
	memcpy(tx_packet->buf + 2, keyboard_keys, 6);
	tx_packet->len = 8;
	usb_tx(KEYBOARD_ENDPOINT, tx_packet);
#endif
	return 0;
}
Example #18
0
void resumePCB()
{
	serial_print("Please enter the name of the process to resume: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		target->suspendedState = 0;
		serial_print("The process \"");
		serial_print(name);
		serial_println("\" has resumed successfully");
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Example #19
0
void main(void) {
  serial_print(2, "Done!\n");
  spi_slow();
  CLEAR_BIT(SPI_CTL, LED_SEL);
  spi_xfer(0x01); // write
  spi_xfer(0x00); // first pos
  spi_xfer(0xff); // turn it all on
  spi_xfer(0xff); // turn it all on
  spi_xfer(0x01); // write
  spi_xfer(0x08); // 9 pos
  spi_xfer(0xcc); //
  spi_xfer(0xff); // turn it all on
  SET_BIT(SPI_CTL, LED_SEL);
  while (1);
}
Example #20
0
void loop()
{
	int addr = 9;

	serial_print("Hello World!\r\n");		// only print strings

	serial_printf("%d, %s, %p, 0x%X\r\n",
		  			addr, "Hello World!", &addr, 128);

	serial_printf("%f\r\n", 11.2);		// can not support float

	// print float or double:
	char out_buf[7];
	serial_printf("float: |%s|\r\n", dtostrf(13.6672, 6, 3, out_buf));
	serial_printf("float: |%s|\r\n", dtostrf(13.6672, 6, 1, out_buf));
	serial_printf("float: |%s|\r\n", dtostrf(13.6672, 3, 3, out_buf));

	delay(1800);						// delay 1800ms
}
Example #21
0
extern "C" int main()
{
    pinMode(LED_BUILTIN, OUTPUT);
    leds.begin();

    // Announce firmware version
    serial_begin(BAUD2DIV(115200));
    serial_print("Fadecandy v" DEVICE_VER_STRING "\r\n");

    // Application main loop
    while (usb_dfu_state == DFU_appIDLE) {
        watchdog_refresh();

        // Select a different drawing loop based on our firmware config flags
        switch (buffers.flags & (CFLAG_NO_INTERPOLATION | CFLAG_NO_DITHERING)) {
            case 0:
            default:
                updateDrawBuffer_I1_D1(calculateInterpCoefficient());
                break;
            case CFLAG_NO_INTERPOLATION:
                updateDrawBuffer_I0_D1(0x10000);
                break;
            case CFLAG_NO_DITHERING:
                updateDrawBuffer_I1_D0(calculateInterpCoefficient());
                break;
            case CFLAG_NO_INTERPOLATION | CFLAG_NO_DITHERING:
                updateDrawBuffer_I0_D0(0x10000);
                break;
        }

        // Start sending the next frame over DMA
        leds.show();

        // We can switch to the next frame's buffer now.
        buffers.finalizeFrame();

        // Performance counter, for monitoring frame rate externally
        perf_frameCounter++;
    }

    // Reboot into DFU bootloader
    dfu_reboot();
}
Example #22
0
void __init ath_serial_setup(void)
{
	struct uart_port p;

	memset(&p, 0, sizeof(p));

	p.flags = (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST);
	p.iotype = UPIO_MEM32;
	p.uartclk = ath_ahb_freq;
	p.irq = ATH_MISC_IRQ_UART;
	p.regshift = 2;
	p.mapbase = (u32) KSEG1ADDR(ATH_UART_BASE);
	p.membase = (void __iomem *)p.mapbase;

	if (early_serial_setup(&p) != 0)
		printk(KERN_ERR "early_serial_setup failed\n");

	serial_print("%s: early_serial_setup done..\n", __func__);

}
Example #23
0
void settime()
{
	serial_println("What is the current hour?");
    char *response = polling();
    unsigned char portnum = 0x04; //hours port
    writetoRTC(portnum, response);

    serial_println("What is the current minute?");
    response = polling();
    portnum = 0x02; //minutes port
    writetoRTC(portnum, response);

    serial_println("What is the current second?");
    response = polling();
    portnum = 0x00; //seconds port
    writetoRTC(portnum, response);

    serial_print("Time successfully changed to -> ");
    gettime();
    sys_free_mem(response);
}
Example #24
0
void menu_process_keypad(int key)
{
	serial_print("menu process keyboard ");
	serial_println(key);

	switch (key) {
		case 0: /* cancel */
			setmode_cb(MENU_CANCEL);
			break;
		case KEYPAD_POUND: /* enter */
			setmode_cb(modes[mode_idx].mode_val);
			break;
		case 3:
			rotate_mode_up();
			break;
		case 9:
			rotate_mode_down();
			break;
		default:
			break;
	}
}
Example #25
0
void setdate()
{
	serial_println("What day of the week is it?");
    char *response = polling();
  	char *bcdweekday = fromweekday(response);
    unsigned char portnum = 0x06; //weekday port
    writetoRTC(portnum, bcdweekday);

    serial_println("What month is it?");
    response = polling();
  	char *bcdmonth = frommonth(response);
    portnum = 0x08; //month port
  	writetoRTC(portnum, bcdmonth);

    serial_println("What day of the month is it?");
    response = polling();
    portnum = 0x07; //month day port
  	writetoRTC(portnum, response);

    serial_println("What year is it?");
    response = polling();
  	char *bcdyear = sys_alloc_mem(2);
  	if (strlen(response) != 4 || atoi(response) < 2000) {
  		bcdyear[0] = '\0';
  	} else {
  		bcdyear[0] = response[2];
  		bcdyear[1] = response[3];
  	}
    portnum = 0x09;
    writetoRTC(portnum, bcdyear);

    serial_print("Time successfully changed to -> ");
    getdate();
    sys_free_mem(response);
    sys_free_mem(bcdweekday);
    sys_free_mem(bcdmonth);
    sys_free_mem(bcdyear);
}
Example #26
0
void setPriority()
{
	serial_print("Please enter the name of the process to alter: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		serial_print("What is the new priority? ");
		char* newPriority = polling();
		int priority = atoi(newPriority);
		if(-1 < priority && 10 > priority)
		{
			target->priority = priority;
			int readyIndex = indexByNameReady(name);
			int blockedIndex = indexByNameBlocked(name);
			if (readyIndex >= 0) {
				removePCBAtIndexReady(readyIndex);
			} else {
				removePCBAtIndexBlocked(blockedIndex);
			}
			insertPCB(target);
			serial_print("The process \"");
			serial_print(name);
			serial_println("\" has successfully updated its priority");
		}
		else
		{
			serial_println("Cannot set priority: invalid range");
		}
		sys_free_mem(newPriority);
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Example #27
0
void getdate()
{
	outb(0x70, 0x06);
	unsigned char beforeconv = inb(0x71);
	char *afterconv = sys_alloc_mem(5);
	fromBCD(beforeconv, afterconv);
	char *weekday = toweekday(afterconv);
    serial_print(weekday);
    serial_print(" ");

    outb(0x70, 0x08);
    beforeconv = inb(0x71);
    fromBCD(beforeconv, afterconv);
    char *month = tomonth(afterconv);
    serial_print(month);
    serial_print(" ");

    outb(0x70, 0x07);
    beforeconv = inb(0x71);
    fromBCD(beforeconv, afterconv);
    serial_print(afterconv);
    serial_print(" ");

    outb(0x70, 0x09);
    beforeconv = inb(0x71);
    fromBCD(beforeconv, afterconv);
    char *year = sys_alloc_mem(5);
    year[0] = '2';
    year[1] = '0';
    year[2] = afterconv[0];
    year[3] = afterconv[1];
    year[4] = '\0';
    serial_println(year);
    serial_println("");
    sys_free_mem(afterconv);
    sys_free_mem(weekday);
    sys_free_mem(month);
    sys_free_mem(year);
}
Example #28
0
void deletePCB()
{
	serial_print("Please enter the name of the process to delete: ");
	char* name = polling();
	PCB* target = findPCB(name);
	if(target == NULL)
	{
		if(strlen(name) == 0) {
			serial_print("Process not found: \"");
			serial_print(name);
			serial_println("\" does not appear to exist");
		}
	}
	else
	{
		int readyIndex = indexByNameReady(name);
		int blockedIndex = indexByNameBlocked(name);
		PCB* removedPCB = NULL;
		if (readyIndex >- 0) {
			removedPCB = removePCBAtIndexReady(readyIndex);
		} else {
			removedPCB = removePCBAtIndexBlocked(blockedIndex);
		}
		FreePCB(removedPCB);
		// if (!FreePCB(removedPCB)) {
			serial_print("The process \"");
			serial_print(name);
			serial_print("\" has been deleted successfully");
		// } else {
		//	serial_print("An error occurred while attempting to remove the process \"");
		//	serial_print(name);
		//	serial_println("\"");
		//}
	}
	serial_println("");
}
Example #29
0
int
door_main(void)
{
	serial_init(9600, 8e2);

	pin_mode_output(PIN_RFID_ENABLE);

	pin_mode_input(PIN_CLK);         /* clk             */
	pin_mode_input(PIN_DATA);        /* data            */
	pin_mode_output(PIN_GREEN_LED);  /* green led lock  */
	pin_mode_output(PIN_YELLOW_LED); /* yellow led lock */
	pin_mode_output(PIN_OPEN_LOCK);  /* open            */
	pin_mode_output(PIN_DAYMODE);    /* stay open       */
	pin_mode_output(PIN_STATUS_LED); /* yellow status   */

	pin_high(PIN_OPEN_LOCK);
	pin_high(PIN_DAYMODE);
	pin_high(PIN_GREEN_LED);
	pin_high(PIN_YELLOW_LED);

	/* trigger pin2 interrupt when the clock
	 * signal goes high */
	pin2_interrupt_mode_rising();
	pin2_interrupt_enable();

	data_reset();

	/* setup timer1 to trigger interrupt a 4 times a second */
	timer1_mode_ctc();
	timer1_compare_a_set(62499);
	timer1_clock_d64();
	timer1_interrupt_a_enable();

        softserial_init();
	pin_mode_output(PIN_RFID_ENABLE);
	pin_low(PIN_RFID_ENABLE);

        init_mfrc522();

	sleep_mode_idle();

	while (1) {
		/*
		 * sleep if no new events need to be handled
		 * while avoiding race conditions. see
		 * http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html
		 */
		cli();
		if (events == EV_NONE && !ev_softserial) {
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();
			continue;
		}
		sei();

		if (events & EV_SERIAL) {
			handle_serial_input();
			continue;
		}

		if (ev_softserial) {
			handle_rfid_input();
		}

		events &= ~EV_DATA;
		if (cnt > 0 && data[cnt - 1] == 0xB4) {
			if (cnt >= 10) {
				struct sha1_context ctx;
				char digest[SHA1_DIGEST_LENGTH];

				sha1_init(&ctx);
				sha1_update(&ctx, (char *)data, 256);
				sha1_final(&ctx, digest);
				serial_print("HASH+");
				serial_hexdump(digest, SHA1_DIGEST_LENGTH);
				serial_print("\n");
			}
			data_reset();
			continue;
		}

                if (events & EV_TIME)
                {
                  char buf[20];
                  uint8_t len;

                  len = check_mfrc522(buf, sizeof(buf));
                  handle_mfr_input(buf, len);
                }

		events &= ~EV_TIME;

                /*
                  This code can be used during development, to simulate the
                  press of the '#' button 8 seconds after every idle timeout:

                if (second == 32 && cnt < 255)
                {
                  data[cnt] = 0xB4;
                  cnt++;
                  events |= EV_DATA;
                }
                */

		if (second > 10*4) {
			serial_print("ALIVE\n");
			second = 0;
			data_reset();
			continue;
		}
	}
}
Example #30
0
void serial_println(char *fmt,...)
{
	serial_print(fmt);
	serial_printf("\n\r");
}