Esempio n. 1
0
/***********************************************************************
 *
 * Function: term_init
 *
 * Purpose: Initialize terminal I/O interface
 *
 * Processing:
 *     Use the UART driver to open and initialize the serial port
 *     session.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void term_init(void) {
	UART_CBS_T cbs;
	UART_CONTROL_T ucntl;
	UART_REGS_T *puartregs = UART5;

	/* Setup UART */
	uartdev = uart_open((void *) puartregs, 0);

	if (uartdev != 0) {
		/* 115.2K, 8 data bits, no parity, 1 stop bit */
		ucntl.baud_rate = 115200;
		ucntl.parity = UART_PAR_NONE;
		ucntl.databits = 8;
		ucntl.stopbits = 1;
		uart_ioctl(uartdev, UART_SETUP_TRANSFER, (INT_32) &ucntl);
		uartbrk = FALSE;

		/* Setup RX and TX callbacks */
		cbs.rxcb = term_dat_recv_cb;
		cbs.txcb = term_dat_send_cb;
		cbs.rxerrcb = term_status_cb;
		uart_ioctl(uartdev, UART_INSTALL_CBS, (INT_32) &cbs);
		int_enable(IRQ_UART_IIR5);
	}

	/* Initialize TX and RX ring buffers */
	txfill = txget = rxfill = rxget = txsize = rxsize = 0;
}
Esempio n. 2
0
/***********************************************************************
 *
 * Function: term_status_cb
 *
 * Purpose: UART misc callback
 *
 * Processing:
 *     Tests for the break condition.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void term_status_cb(void) 
{
	UNS_32 tmp;
	
	tmp = uart_ioctl(uartdev, UART_GET_STATUS, UART_GET_LINE_STATUS);
	if ((tmp & UART_LSR_BI) != 0) 
	{
		uartbrk = TRUE;
	}
}
Esempio n. 3
0
/***********************************************************************
 *
 * Function: term_setbaud
 *
 * Purpose: Reset terminal baud rate
 *
 * Processing:
 *     Use the serial port IOCTL to reset baud rate.
 *
 * Parameters:
 *     baud : New baud rate in Hz
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void term_setbaud(UNS_32 baud) 
{
	UART_CONTROL_T ucntl;

		/* 8 data bits, no parity, 1 stop bit */
		ucntl.baud_rate = baud;
		ucntl.parity = UART_PAR_NONE;
		ucntl.databits = 8;
		ucntl.stopbits = 1;
		uart_ioctl(uartdev, UART_SETUP_TRANSFER, (INT_32) &ucntl);
}
void app_proc()
{
  OS_PRINTK("enter app proc\n");

  crc_setup_fast_lut(CRC_MODE);

  init_diamond_cfg();

  uart_ioctl(UART_CMD_EN_INTERRUPT, FALSE, 0);

  OS_PRINTK("enter app proc end\n");

  mtos_close_printk();
  while(1)
  {
    get_cmd(); 
    dispatch_cmd();

    switch(dm_status)
    {
      case DM_ST_IDLE:
        break;

      case DM_ST_TEST:
        diamond_test();
        break;

      case DM_ST_GET_KEY:
        diamond_get_key();
        continue;  //break;

      case DM_ST_SET_HW:
        diamond_set_hw();
        break;

      case DM_ST_GET_LED_MAP:
        if(diamond_get_led_map())
        {
          continue;
        }
        break;

      case DM_ST_WAIT_USER_ACK:
        continue;

      case DM_ST_LED_ACK_CHECK:
        if(diamond_led_map_check((led_map_status_t)cmd_buff[2]))
        {
          continue;
        }
        if(gp_uio_dev!=NULL)
        {
          uio_display(gp_uio_dev, "", 4);
          dev_io_ctrl(gp_uio_dev, UIO_FP_SET_LOCK_LBD, FALSE);
        }
        mtos_task_delay_ms(1);
        break;

      case DM_ST_SET_DATA:
        diamond_set_data();
        break;

      case DM_ST_GET_DATA:
        diamond_get_data();
        break;

      case DM_ST_TEST_LED:
        if(diamond_test_led())
        {
          continue;
        }
        break;

      case DM_ST_LIGHT_ALL:
        diamond_light_all(cmd_buff[2]);
        break;

      default:
        break;
    }
    dm_status = DM_ST_IDLE;
  }
  return;
}
Esempio n. 5
0
/***********************************************************************
 *
 * Function: term_dat_flush
 *
 * Purpose: Flush data in the terminal input buffer
 *
 * Processing:
 *     Flush the UART FIFOs.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void term_dat_flush(void) {
	uart_ioctl(uartdev, UART_CLEAR_FIFOS, (UART_FCR_TXFIFO_FLUSH |
		UART_FCR_RXFIFO_FLUSH));
}
/*!
  UPG task
 */
static void upg_single_step(void *p_handle, os_msg_t *p_msg)
{
  upg_ret_t ret = UPG_RET_SUCCESS;
  u32 i = 0;
  upg_priv_t *p_priv = (upg_priv_t *)p_handle;
  upg_data_t *p_data = &p_priv->upg_data;
  upg_policy_t *p_policy = p_priv->p_upg_impl;
  slave_info_t *p_info = p_priv->upg_data.cfg.p_slave_info;
  
  if(NULL != p_msg)
  {
    switch(p_msg->content)
    {
      case UPG_CMD_START:
        
        if(UPG_SM_IDLE != p_data->sm)
        {
          break;
        }
       
        p_policy->p_pre_start(&(p_data->cfg));
        
        p_data->upg_mode = (p_msg->para1) >> 16;
        p_data->blk_num = (p_msg->para1)& 0xFF;

        p_data->divides_mode = ((p_msg->para1 >> 8)& 0xFF);

        p_data->divides = p_data->blk_num;

        p_data->divides_ready = 0;

          
        memcpy((void *)(p_data->upg_block), 
          (void *)(p_msg->para2), p_data->blk_num * sizeof(upg_block_t));

        
       
        uart_ioctl(UART_CMD_EN_INTERRUPT,FALSE,0); 

        p_data->key = UPGRD_KEY_IGNORE;
        p_data->sm = UPG_SM_SYNCING;
        break;
        
      default:
        break;
    }
    return;
  }  
  
  switch(p_data->sm)
  {
    case UPG_SM_IDLE:
      break;

    case UPG_SM_SYNCING:
      ret = p2p_cmd_sync(p_priv);
      if(ret == UPG_RET_SUCCESS)
      {
        for(i = 0; i < 150; i++)
        {
          mtos_task_delay_ms(10);
          
          if(UPGRD_KEY_EXIT == p_data->key)
          {
            p_data->sm = UPG_SM_EXIT;  
            return;
          }
          else if(UPGRD_KEY_MENU == p_data->key)
          {
            p_data->sm = UPG_SM_EXIT;  
            return;
          }
        }
        p_data->sm = UPG_SM_NEGOTIATING;          
      }
      else if(ret == UPG_RET_ERROR)
      {
        p_data->key = UPGRD_KEY_MENU;
        p_data->sm = UPG_SM_EXIT;           
      }
      else if(ret == UPG_RET_EXIT)
      {
        p_data->key = UPGRD_KEY_EXIT;
        p_data->sm = UPG_SM_EXIT;          
      }
      else if(ret == UPG_RET_MENU)
      {
        p_data->key = UPGRD_KEY_MENU;
        p_data->sm = UPG_SM_EXIT;          
      }
      break;
      
    case UPG_SM_NEGOTIATING:
      if(UPG_RET_SUCCESS != p2p_cmd_test(p_priv))
      {
        p_data->key = UPGRD_KEY_MENU;
        p_data->sm = UPG_SM_EXIT;   
        break;
      }

      if((UPGRD_ALL_SINGLE == p_data->upg_mode)||(UPGRD_ALL_MULTI == p_data->upg_mode))
      {
        if(UPG_RET_SUCCESS != p2p_cmd_inform(p_priv, p_data->blk_num, p_data->upg_block))
        {
          p_data->key = UPGRD_KEY_MENU;
          p_data->sm = UPG_SM_EXIT;   
        }
        else
        {
          p_data->sm = UPG_SM_TRANSFERING;
        }
      }
      else
      {
        memset(p_info, 0, sizeof(slave_info_t));

        if(UPG_RET_SUCCESS != p2p_cmd_collect(p_priv,TRUE, (u8 *)p_info))
        {
          p_data->key = UPGRD_KEY_MENU;
          p_data->sm = UPG_SM_EXIT;   
        }
        else if(UPG_RET_SUCCESS != p_priv->p_upg_impl->p_block_process(
          p_data->blk_num, p_data->upg_block, p_info))
        {
          p_data->key = UPGRD_KEY_MENU;
          p_data->sm = UPG_SM_EXIT;   
        }
        else if(UPG_RET_SUCCESS != p2p_cmd_inform(p_priv, p_data->blk_num, p_data->upg_block))
        {
          p_data->key = UPGRD_KEY_MENU;
          p_data->sm = UPG_SM_EXIT;   
        }
        else
        {
          p_data->sm = UPG_SM_TRANSFERING;
        }
      }
      break;
      
    case UPG_SM_TRANSFERING:
      if(p_data->divides_mode)
      {
        if(UPG_RET_SUCCESS != p2p_cmd_transfer(p_priv, FALSE, p_data->upg_block[0].master_block_id))
        {
          if((UPGRD_ALL_MULTI == p_data->upg_mode)|| (UPGRD_BLOCKS_MULTI == p_data->upg_mode))
          {            
            p_priv->upg_data.key = UPGRD_KEY_IGNORE;
            p_data->sm = UPG_SM_SYNCING;
          }
          else
          {
            p_data->key = UPGRD_KEY_MENU;
            p_data->sm = UPG_SM_EXIT;   
          }          
          return;
        }

        p_data->sm = UPG_SM_BURNING;

      }
      else
      {
        for(i = 0; i < p_data->blk_num; i++)
        {
          if(UPG_RET_SUCCESS != 
            p2p_cmd_transfer(p_priv, FALSE, p_data->upg_block[i].master_block_id))
          {
            if((UPGRD_ALL_MULTI == p_data->upg_mode)|| (UPGRD_BLOCKS_MULTI == p_data->upg_mode))
            {            
              p_priv->upg_data.key = UPGRD_KEY_IGNORE;
              p_data->sm = UPG_SM_SYNCING;
            }
            else
            {
              p_data->key = UPGRD_KEY_MENU;
            p_data->sm = UPG_SM_EXIT;   
          }          
          return;
          }
        }
        p_data->sm = UPG_SM_BURNING;
      }
      break;
      
    case UPG_SM_BURNING:
      if(p_data->divides_mode)
      {
        ret = p2p_cmd_burn(p_priv);
        if(UPG_RET_SUCCESS != ret)
        {
          if((UPGRD_ALL_MULTI == p_data->upg_mode) || (UPGRD_BLOCKS_MULTI == p_data->upg_mode))
          {
            p_priv->upg_data.key = UPGRD_KEY_IGNORE;
            p_data->sm = UPG_SM_SYNCING;
          }
          else
          {
            p_data->key = UPGRD_KEY_MENU;
            p_data->sm = UPG_SM_EXIT;
          }
          p_data->divides_ready = 0;
        } 
        else
        {
          p_data->divides_ready++;
          
          if (p_data->divides_ready >= p_data->divides)
          {
            p_data->sm = UPG_SM_REBOOTING;
          }
          else
          {
            p_data->sm = UPG_SM_TRANSFERING;
          }
        }

      }
      else
      {
        ret = p2p_cmd_burn(p_priv);
        if(UPG_RET_SUCCESS != ret)
        {
          if((UPGRD_ALL_MULTI == p_data->upg_mode) || (UPGRD_BLOCKS_MULTI == p_data->upg_mode))
          {
            p_priv->upg_data.key = UPGRD_KEY_IGNORE;
            p_data->sm = UPG_SM_SYNCING;
          }
          else
          {
            p_data->key = UPGRD_KEY_MENU;
            p_data->sm = UPG_SM_EXIT;
          }
        } 
        else
        {
          p_data->sm = UPG_SM_REBOOTING;
        }
      }
      break;
      
    case UPG_SM_REBOOTING:
      p2p_cmd_reboot(p_priv);
        
      if((UPGRD_ALL_MULTI == p_data->upg_mode) || (UPGRD_BLOCKS_MULTI == p_data->upg_mode))
      {
        p_data->sm = UPG_SM_SYNCING;
      }
      else
      {
        p_data->sm = UPG_SM_IDLE;
        p_policy->p_post_exit(&(p_data->cfg));
        upg_send_evt_to_ui(UPG_EVT_SUCCESS, 0, 0);
      }
      break;
      
    case UPG_SM_EXIT:
      p_policy->p_post_exit(&(p_data->cfg));

      if(p_data->key == UPGRD_KEY_EXIT)
      {
        upg_send_evt_to_ui(UPG_EVT_QUIT_UPG, 1, 0);
      }
      else if(p_data->key == UPGRD_KEY_MENU)
      {
        upg_send_evt_to_ui(UPG_EVT_QUIT_UPG, 0, 0);
      }

      uart_ioctl(UART_CMD_EN_INTERRUPT,TRUE,0);

      p_data->key = UPGRD_KEY_IGNORE;
      p_data->sm = UPG_SM_IDLE;
      break;
      
    default:
      break;
  }
}