Main Page | Modules | Related Pages | Examples

turboadapter/module-src/turboadapter.c

/*
 * Turbo Programmer Utilities, turbo-prog-utils, www.bladox.com 
 *
 * Copyright (C) 2004 BLADOX, s.r.o.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

#include <config.h>
#include <tprog/tprog.h>
#include <stdlib.h>
#include <avr/interrupt.h>

#include "turboadapter.h"
#include "btldr.h"
#include "dbg.h"
#include "clka.h"

void turbo_handler (u8 action, USB_Data * data)
{
  u8 *buf = buf_A ();
  u16 i;

  switch (action)
  {
    case ACTION_APP_VERSION:
      buf[0] = 2;
      buf[1] = 0;
      buf[2] = 0;
      usb_send (NO_ERROR, 3, buf);
      break;

    case ACTION_TURBO_ADAPTER_BTLDR_INIT:
      reg_action (ACTION_SIG_UART1_RECV);
      init_vars ();
      init_turboadapter_btldr_port ();
      init_btldrUart ();
      init_clka_timer ();

      btldrTxSendChar (UCMD_BTLDR_MODE_INIT);
      while (btldrRxChars () == 0);
      buf[0] = btldrRxGetChar ();

      usb_send (NO_ERROR, 1, buf);
      break;

    case ACTION_TURBO_ADAPTER_BTLDR_WRITE_PAGE:
      btldr_flash_page (data, buf);
      break;

    case ACTION_SIG_UART1_RECV:
      btldr_uart_irq ();
      break;

    case ACTION_TURBO_ADAPTER_DBG_INIT:
      reg_action (ACTION_SIG_SPI);
      init_turboadapter_dbg_port ();
      usb_send (NO_ERROR, 0, NULL);
      break;

    case ACTION_SIG_SPI:
      usb_put_char_nb (inb (SPDR));
      break;

    default:
      break;
  }
}


Copyright © 2004 BLADOX
Turbo Programmer version 2.0