Exemplo n.º 1
0
Arquivo: hal_uart.c Projeto: gxp/node
void USART_Init(char uart, char USART_InitStruct)
{ 
     
   IO_PER_LOC_USART0_AT_PORT0_PIN2345();
   SET_MAIN_CLOCK_SOURCE(CRYSTAL);

   UART_SETUP(0, 57600, HIGH_STOP);
   UTX0IF = 1;
}
Exemplo n.º 2
0
/******************************************************************************
* @fn  initUART
*
* @brief
*      Initializes components for the UART application example.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void initUART(void)
{
   // Setup for UART0
   IO_PER_LOC_UART0_AT_PORT0_PIN2345();

   SET_MAIN_CLOCK_SOURCE(CRYSTAL);

   UART_SETUP(0, 57600, HIGH_STOP);

   UTX0IF = 1;

}
Exemplo n.º 3
0
Arquivo: hal_uart.c Projeto: gxp/node
/****************************************************************************** 
 * @TODO 20061013
 * if the uart adapter is driven by interrupt, then you should enable the interrupt 
 * in configure function. however, whether the ISR really works or not still depends
 * on the global interrupt flag. 
 *
 * @assume: the global interrupt should be disabled before calling this function.
 * @todo stop bits input is actually no use now.
 *****************************************************************************/
TiUartAdapter * uart_open( TiUartAdapter * uart, uint8 id, uint16 baudrate, uint8 databits, uint8 stopbits, uint8 option )
{
    //USART_InitTypeDef USART_InitStructure;

	/* assume: 
	 * - the global interrupt is disabled when calling this function 
	 * - you have already call HAL_SET_PIN_DIRECTIONS. the pin should initialized correctly. or else it doesn't work.
	 */

	uart->id = id;
	uart->baudrate = baudrate;
	uart->databits = databits;
	uart->stopbits = stopbits;
	uart->option = option;

    #ifdef CONFIG_UART_INTERRUPT_DRIVEN
    uart->txlen = 0;
	uart->txidx = 0;
    uart->rxlen = 0;
    uart->listener = NULL;
	uart->lisowner = NULL;
    #endif

	switch (id)
	{
	    case 0:
            IO_PER_LOC_USART0_AT_PORT0_PIN2345();
            SET_MAIN_CLOCK_SOURCE(CRYSTAL);

            UART_SETUP(0, 38400, HIGH_STOP);
            //UART_SETUP(0, 57600, HIGH_STOP);
            UTX0IF = 1;
		    break;

	    case 1:
            break;

        case 2:
		    break;

	    default:
            // not support now.
            hal_assert(false);
		    uart = NULL;
		    break;
	}

	return uart;
}
Exemplo n.º 4
0
void flash_main(void){
#else
void main(void){
#endif
   BYTE buffer[30];
   char inputBuffer[STRING_LENGTH];
   INT8 pointer = 0;
   BOOL stop = FALSE;
   BOOL write = FALSE;
   char c;
   char *menuText[] = {(char*)" CPU write?", (char*)" DMA write?"};
   BYTE command;
   BOOL unUsed;

   initFlash();

   // Clearing buffers
   memset(buffer,0,sizeof(buffer));
   memset(inputBuffer,0,sizeof(inputBuffer));

   // Setting up UART
   UART_SETUP(0,57600,HIGH_STOP);
   UTX0IF = 1;  // Set UART 0 TX interrupt flag

   while(getJoystickDirection() != CENTRED);

   //Displaying the stored flash message.
   lcdUpdateLine(LINE1,(char*)"Last written:");
   if((unUsed = flashUnused((BYTE*)testData, STRING_LENGTH)))
   {
      lcdUpdateLine(LINE2,(char*)"Unused");
   }
   else
   {
      scrollText((char*) testData, STRING_LENGTH);
   }

   while(getJoystickDirection() != CENTRED);
   while(getJoystickDirection() == CENTRED);
   while(getJoystickDirection() != CENTRED);


   // User decides whether to use CPU or DMA to write flash or to abort.
   command = lcdMenu(menuText,2);
   if(command == ABORT_MENU)
   {
      return;
   }


   // Uart communication
   lcdUpdate((char*)"Enter UART", (char*)"data");
   printf((char*)"\n\nFlash Programming\n");


   printf((char*)"Press a key\n\n");
   uartGetkey (); // wait for a key to be pressed or the application to be ended
   if (stopApplication() ) return;
   else
   {
      inputBuffer[0] = U0DBUF;
      halWait(5);
      USART0_FLUSH();
      inputBuffer[1] = U0DBUF;
   }

   // Printing the previously written data
   printf((char*)"\nLast written:\n");
   if(unUsed)
   {
      printf((char*)"Unused\n");
   }
   else
   {
      printf((char*)"%s\n",&testData);
   }

   //Aquiring new data:
   printf((char*)"\n\nType data to be written.\nWill be printed to the LCD next time.");
   printf((char*)"\n(ENTER: store in flash, ESC: abort)\n\n");
   memset(inputBuffer,0,STRING_LENGTH);

   while(!stop)
   {
      c = getkey();
      U0DBUF = c;

      switch (c){
      case ENTER:
         inputBuffer[pointer] = 0;
         printf((char*)"\n\nTo write: %s\nENTER if OK.\n",inputBuffer);
         if(getkey() == ENTER)
         {
            // Write data to flash;
            stop = TRUE;
            write = TRUE;
         }
         else
         {
            // Reaquire data.
            printf((char*)"\nEnter text:\n");
            pointer = 0;
         }
         break;
      case BACK_SPACE:
         // Erasing the last typed data.
         if (pointer > 0)
         {
            pointer--;
            inputBuffer[pointer] = ' ';
         }
         break;
      case ESC:
         // Abort Flash write.
         stop = TRUE;
         write = FALSE;
         break;
      default:
         // Add typed data to buffer.
         if (pointer < STRING_LENGTH-1)
         {
            inputBuffer[pointer] = c;
            pointer++;
         }
         break;
      }
   }

  INT_GLOBAL_ENABLE(INT_OFF);

   // Updating the flash if asked to.
   if(write == TRUE)
   {
      if(command == 0)
      {
         halFlashWritePage((BYTE*) &inputBuffer, buffer, PAGE_NUMBER);
      }
      else
      {
         writeFlashUsingDMA((BYTE*) &inputBuffer, STRING_LENGTH, PAGE_ADDRESS, TRUE);
      }
      printf((char*)"\nUpdated:");
      printf((char*)" %s\n",(char __code*) (PAGE_NUMBER << 10));
      lcdUpdateLine(LINE1,(char*)"Updated");
   }
   else
   {
      printf((char*)"\nNot updated\n");
      lcdUpdateLine(LINE1,(char*)"Not updated");
   }
   lcdUpdateLine(LINE2,(char*)"LEFT to continue");


   // Done
   haltApplicationWithLED();

   return;
}
Exemplo n.º 5
0
#include <linux/serial_8250.h>

#define	UART_SETUP( _addr, _irq, _regshift )       \
	{                                              \
		.membase	= 0,                           \
		.mapbase	= (_addr),                     \
		.irq		= (_irq),                      \
		.flags		= UPF_SKIP_TEST | UPF_IOREMAP, \
		.iotype		= UPIO_MEM,                    \
		.regshift	= (_regshift),                 \
		.uartclk	= 3686400,                     \
	}

static struct plat_serial8250_port serial_platform_data[] = {

	UART_SETUP( PXA_CS2_PHYS + 0x000, IRQ_GPIO(23), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x100, IRQ_GPIO(23), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x200, IRQ_GPIO(23), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x300, IRQ_GPIO(23), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x400, IRQ_GPIO(24), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x500, IRQ_GPIO(24), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x600, IRQ_GPIO(24), 1 ),
	UART_SETUP( PXA_CS2_PHYS + 0x700, IRQ_GPIO(24), 1 ),
	
	{(struct plat_serial8250_port *)NULL}
};


static struct platform_device serial_device = {
	.name   = "serial8250",
	.id	    = 0,