Beispiel #1
0
int main(void)
{
	int i;
	char buf[BUFSZ + 1];

	init();
	serial_init();
	softserial_init(2, 3);

	serial_begin(&serial[0], 19200);
	softserial_begin(&sserial, 19200);
	serial_write(&serial[0], "\r\n", 2);
	while(1) {
		i = serial_read(&serial[0], buf, BUFSZ);
		if(i > 0) {
			softserial_write(&sserial, buf, i);
		}
		i = softserial_read(&sserial, buf, BUFSZ);
		if(i > 0) {
			serial_write(&serial[0], buf, i);
		}
	}
	return 0;
}
Beispiel #2
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;
		}
	}
}
Beispiel #3
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  my_usb_init();
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM1_Init();
  MX_USB_DEVICE_Init();
  MX_USART3_UART_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
  HAL_TIM_Base_Start(&htim2);
  delay_us_init(&htim2);
  softserial_init(SOFTSERIAL_TX_GPIO_Port, SOFTSERIAL_TX_Pin);
  hmi_lcd_init(&huart3);
  cpu_ctrl_init(&htim1);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  HAL_Delay(100);
  hsc_stop();
  cpu_reset();
  lcd_clear();
  addr_input();
  data_input();
  build_ui();
  HAL_Delay(100);

  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    if(is_running == 0)
      addr_data_display_update();

    // z80 reset button
    if(is_button_1_pressed)
    {
      hsc_stop();
      cpu_reset();
      lcd_print_width(130, 110, 180, 45, "CYAN", "RESET");
      is_button_1_pressed = 0;
      HAL_Delay(500);
      build_ui();
    }

    // clk step button
    if(is_button_3_pressed)
    {
      hsc_stop();
      cycle_clock(1);
      lcd_print_width(130, 110, 180, 45, "RED", "CLK STEP");
      is_button_3_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // ins step button
    if(is_button_4_pressed)
    {
      hsc_stop();
      lcd_print_width(130, 110, 180, 45, "GREEN", "INS STEP");
      // cycle clock until we're at next M1 cycle
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == LOW)
        cycle_clock(1);
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == HIGH)
        cycle_clock(1);
      is_button_4_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // run/stop button
    if(is_button_5_pressed)
    {
      is_running = (is_running + 1) % 2;
      if(is_running)
      {
        lcd_print_width(130, 110, 180, 45, "GREEN", "RUNNING");
        hsc_start();
      }
      else
      {
        hsc_stop();
        build_ui();
      }
      is_button_5_pressed = 0;
    }

    usb_data = my_usb_readline();
    if(usb_data != NULL && strstr(usb_data, "epm") != NULL)
    {
      hsc_stop();
      program_mode();
      build_ui();
    }
  }
  /* USER CODE END 3 */

}