Beispiel #1
0
uint8 InitDevice()//TODO:异常处理
{
	uint8 r=0,t=0;
	//GPIO
	PinInit();
	IO0DIR=1<<29|1<<30;//P0.29,P0.30必须同为输出才能输出(SSP0的片选).
	//GpioSpeedHigh();//全局高速模式,因为P0.29问题无法使用。

	//指示系统启动
	LED1ON();

	//UART0-GCS
	r+=UARTInit(FCUARTPORT,FCUARTBPS);//UART0-PC
	UARTSendChar(FCUARTPORT,0x40);
	UARTSendChar(FCUARTPORT,0x40);

	//UART2-INS
	r+=UARTInit(INSUARTPORT,INSUARTBPS);
	//UARTSendChar(2,0x40);
	//UARTSendChar(2,0x40);

	//SSP0-FPGA
	r+=SSP0FPGAMode();
	//r+=SPIInit();
	//while(1)
	//{
	t=FPGACheck();
	//}
	if(t==TRUE)
	{
		FCEventSend(OKFPGA);
	}
	else
	{
		FCEventSend(ErrFPGA);
	}
	r+=t;

	//SSP1-FLASH
	r+=FlashInit(FlashQueueSize);

	//Timer0-MainLoop
	r+=TimerInit(0,1000/MainLoopHz);
	TimerDisable(0);
	//TimerEnable(0);

	//Timer1-Time+LED1
	r+=TimerInit(1,1000);
	TimerEnable(1);
	
	//Timer2-Working-LED2
	r+=TimerInit(2,100);
	TimerDisable(2);

	//启动中断
	IRQEnable();
	
	return r;
}
Beispiel #2
0
BOOL
default_putchar (uint8_t data)
{
    if (USB_Configuration)
    {
        __disable_irq ();

        if (fifo_out_count >= (int) sizeof (fifo_out))
            CDC_BulkIn_Handler (TRUE);

        fifo_out[fifo_out_count++] = data;

        if (data == '\n')
            CDC_BulkIn_Handler (TRUE);

        __enable_irq ();
    }

#ifdef  ENABLE_BLUETOOTH
    if(bluetooth_suppress)
        return TRUE;
    else
#endif /*ENABLE_BLUETOOTH */
        return UARTSendChar (data);
}
Beispiel #3
0
int _write(int fd, char * str, int len)
{
	int i;
    for (i = 0; i < len; i++)
    {
        UARTSendChar(str[i]);
    }
    return len;
}
Beispiel #4
0
/*
 * overwrite default_putchar with USB CDC ACM
 * output to enable USB support for debug_printf
 */
BOOL default_putchar(uint8_t data)
{
	if (vTasksRunning)
		vUSBSendByte(data);
	/* always send out over serial port as well */
	UARTSendChar(data);

	return TRUE;
}
Beispiel #5
0
/*----------------------------------------------------------------------------
Write character to Serial Port
*----------------------------------------------------------------------------*/
int sendchar( int c ) {

	#ifdef __RTGT_GLCD
	//call init_scroll if it is not called
	//Warning, this is not a thread safe code
	if ( glcd_init_called == 0 ) {
		glcd_init_called = 1;
		ScrollInit();
	}
	#endif

	#ifdef __RTGT_UART

	//call init_scroll if it is not called
	//Warning, this is not a thread safe code
	if ( uart_init_called == 0 ) {
		uart_init_called = 1;
		UARTInit(PORT_NUM, BAUD_RATE);
	}

	#endif
	
	if ( c == '\r' || c == '\n' ) {
		#if defined( __RTGT_UART ) || defined( __DBG_ITM )
			UARTSendChar( PORT_NUM, 0x0D );
			UARTSendChar( PORT_NUM, 0x0A );
		#endif

		#ifdef __RTGT_GLCD
			CharAppend('\n');
		#endif
	} else {
		#if defined(__RTGT_UART) || defined(__DBG_ITM)
			UARTSendChar(PORT_NUM, c);
		#endif
		#ifdef __RTGT_GLCD
			CharAppend(c);
		#endif
	}

	return c;
}
Beispiel #6
0
BOOL
default_putchar (uint8_t data)
{
  __disable_irq ();

  if (fifo_out_count < (int) sizeof (fifo_out))
    fifo_out[fifo_out_count++] = data;

  if (data == '\n')
    CDC_BulkIn_Handler (TRUE);

  __enable_irq ();

  return UARTSendChar (data);
}
Beispiel #7
0
static void serial_task(void *handle)
{
	int i;
	(void) handle;
	portCHAR data;

	vTasksRunning = TRUE;

	i = 0;
	for (;;)
	{
		debug_printf("%04i: Hello Task! (%04i bytes free heap memory)\n", i++,
				xPortGetFreeHeapSize());

		GPIOSetValue(LED_PORT, LED_BIT, LED_ON);
		vTaskDelay(10 / portTICK_RATE_MS);
		GPIOSetValue(LED_PORT, LED_BIT, LED_OFF);

		while (vUSBRecvByte(&data, sizeof(data), 990))
			UARTSendChar(data);
	}
}
Beispiel #8
0
static void
number (long num, unsigned int base, int size, int precision,
	int type)
{
  char c, sign;
  static char tmp[66];

  const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
  int i;

  if (type & LARGE)
    digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (type & LEFT)
    type &= ~ZEROPAD;
  if (base < 2 || base > 36)
    return;
  c = (type & ZEROPAD) ? '0' : ' ';
  sign = 0;
  if (type & SIGN)
    {
      if (num < 0)
	{
	  sign = '-';
	  num = -num;
	  size--;
	}
      else if (type & PLUS)
	{
	  sign = '+';
	  size--;
	}
      else if (type & SPACE)
	{
	  sign = ' ';
	  size--;
	}
    }
  i = 0;
  if (num == 0)
    tmp[i++] = '0';
  else
    while (num != 0)
      tmp[i++] = digits[do_div (num, base)];
  if (i > precision)
    precision = i;
  size -= precision;
  if (!(type & (ZEROPAD + LEFT)))
    while (size-- > 0)
      UARTSendChar(' ');
  if (sign)
    UARTSendChar(sign);
  if (!(type & LEFT))
    while (size-- > 0)
      UARTSendChar(c);
  while (i < precision--)
    UARTSendChar('0');
  while (i-- > 0)
    UARTSendChar(tmp[i]);
  while (size-- > 0)
    UARTSendChar(' ');
}
Beispiel #9
0
static void
tiny_vsprintf (const char *fmt, va_list args)
{
  int len;
  unsigned long num;
  int i, base;
  const char *s;

  int flags;			/* flags to number() */

  int field_width;		/* width of output field */
  int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
  int qualifier;		/* 'h', 'l', or 'q' for integer fields */

  for (; *fmt; ++fmt)
    {
      if (*fmt != '%')
	{
	  if(*fmt=='\n')
	    UARTSendChar('\r');
	  UARTSendChar(*fmt);
	  continue;
	}

      /* process flags */
      flags = 0;
    repeat:
      ++fmt;			/* this also skips first '%' */
      switch (*fmt)
	{
	case '-':
	  flags |= LEFT;
	  goto repeat;
	case '+':
	  flags |= PLUS;
	  goto repeat;
	case ' ':
	  flags |= SPACE;
	  goto repeat;
	case '0':
	  flags |= ZEROPAD;
	  goto repeat;
	}

      /* get field width */
      field_width = -1;
      if (is_digit (*fmt))
	field_width = skip_atoi (&fmt);
      else if (*fmt == '*')
	{
	  ++fmt;
	  /* it's the next argument */
	  field_width = va_arg (args, int);
	  if (field_width < 0)
	    {
	      field_width = -field_width;
	      flags |= LEFT;
	    }
	}

      /* get the precision */
      precision = -1;
      if (*fmt == '.')
	{
	  ++fmt;
	  if (is_digit (*fmt))
	    precision = skip_atoi (&fmt);
	  else if (*fmt == '*')
	    {
	      ++fmt;
	      /* it's the next argument */
	      precision = va_arg (args, int);
	    }
Beispiel #10
0
static void put_char(void *arg, char c) {
  //UARTSendChar((uint8_t) c);
  UARTSendChar(c);
}