コード例 #1
0
ファイル: init.c プロジェクト: Flyagin/BS-MRZV
//*----------------------------------------------------------------------------
//* \fn    AT91F_LowLevelInit
//* \brief This function performs very low level HW initialization
//*----------------------------------------------------------------------------
void AT91F_LowLevelInit()
{
	unsigned int	tmp	= 0;
	AT91PS_PMC pPmc = AT91C_BASE_PMC;
	// Disable watchdog
	*(AT91C_WDTC_WDMR) = AT91C_WDTC_WDDIS;


	AT91F_MATRIX_Remap_ARM(AT91C_BASE_MATRIX);

	// Open PIO for DBGU
	AT91F_DBGU_CfgPIO();

	// Configure DBGU
	AT91F_US_Configure (
		(AT91PS_USART) AT91C_BASE_DBGU,          // DBGU base address
		AT91C_MASTER_CLOCK,
		AT91C_US_ASYNC_MODE,        // mode Register to be programmed
		115200 ,              // baudrate to be programmed
		0);                   // timeguard to be programmed

	// Enable Transmitter
	AT91F_US_EnableTx((AT91PS_USART) AT91C_BASE_DBGU);
	AT91F_US_EnableRx((AT91PS_USART) AT91C_BASE_DBGU);

}
コード例 #2
0
ファイル: serial.c プロジェクト: DuinOS/FreeRTOS
/*
 * See the serial2.h header file.
 */
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
xComPortHandle xReturn = serHANDLE;
extern void ( vUART_ISR )( void );

	/* Create the queues used to hold Rx and Tx characters. */
	xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
	xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );

	/* If the queues were created correctly then setup the serial port 
	hardware. */
	if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
	{
		portENTER_CRITICAL();
		{
			/* Enable the USART clock. */
   			AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_US0 );

			AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA, ( ( unsigned long ) AT91C_PA5_RXD0 ) | ( ( unsigned long ) AT91C_PA6_TXD0 ), serNO_PERIPHERAL_B_SETUP );

			/* Set the required protocol. */
			AT91F_US_Configure( serCOM0, configCPU_CLOCK_HZ, AT91C_US_ASYNC_MODE, ulWantedBaud, serNO_TIMEGUARD );

			/* Enable Rx and Tx. */
			serCOM0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;

			/* Enable the Rx interrupts.  The Tx interrupts are not enabled
			until there are characters to be transmitted. */
    		AT91F_US_EnableIt( serCOM0, AT91C_US_RXRDY );

			/* Enable the interrupts in the AIC. */
			AT91F_AIC_ConfigureIt( AT91C_BASE_AIC, AT91C_ID_US0, serINTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, ( void (*)( void ) ) vSerialISREntry );
			AT91F_AIC_EnableIt( AT91C_BASE_AIC, AT91C_ID_US0 );
		}
		portEXIT_CRITICAL();
	}
	else
	{
		xReturn = ( xComPortHandle ) 0;
	}

	/* This demo file only supports a single port but we have to return 
	something to comply with the standard demo header file. */
	return xReturn;
}
コード例 #3
0
ファイル: usart.c プロジェクト: tsugli/stm32
void Usart0_init ( long BaudRate )
{
    US0_QUEUE = xQueueCreate( 10, sizeof( unsigned int ) );
    US0_Error = ErrorCreate("US0_Error");
    while( US0_QUEUE == 0 ) ;    // Queue was not created and must not be used.
    portENTER_CRITICAL();
    {
        AT91F_US0_CfgPIO() ;        //* Define RXD and TXD as peripheral
        AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<<AT91C_ID_US0 ) ;       // First, enable the clock of the PIOB
        AT91F_US_Configure (COM0, MCK,AT91C_US_ASYNC_MODE, BaudRate , 0);        // Usart Configure
        AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC,
                                AT91C_ID_US0,
                                USART_INTERRUPT_LEVEL,
                                AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE,
                                ( void (*)( void ) )AT91_US0_ISR_ENTRY);
        AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_US0);
    }
    portEXIT_CRITICAL();
}
コード例 #4
0
ファイル: dbgu.c プロジェクト: 12019/openpcd
//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_Init
//* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
//*----------------------------------------------------------------------------
void AT91F_DBGU_Init(void)
{
	unsigned int rst_status = AT91F_RSTGetStatus(AT91C_BASE_RSTC);

	dbgu_rb_init();

	//* Open PIO for DBGU
	AT91F_DBGU_CfgPIO();
	//* Enable Transmitter & receivier
	((AT91PS_USART) AT91C_BASE_DBGU)->US_CR =
	    AT91C_US_RSTTX | AT91C_US_RSTRX;

	//* Configure DBGU
	AT91F_US_Configure((AT91PS_USART) AT91C_BASE_DBGU,	// DBGU base address
			   MCK, AT91C_US_ASYNC_MODE,	// Mode Register to be programmed
			   AT91C_DBGU_BAUD,	// Baudrate to be programmed
			   0);	// Timeguard to be programmed

	//* Enable Transmitter & receivier
	((AT91PS_USART) AT91C_BASE_DBGU)->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;

	//* Enable USART IT error and AT91C_US_ENDRX
	AT91F_US_EnableIt((AT91PS_USART) AT91C_BASE_DBGU, AT91C_US_RXRDY);

	//* open interrupt
	sysirq_register(AT91SAM7_SYSIRQ_DBGU, &DBGU_irq_handler);

	AT91F_DBGU_Printk("\n\r");
	AT91F_DBGU_Printk("(C) 2006-2011 by Harald Welte <*****@*****.**>\n\r"
			  "This software is FREE SOFTWARE licensed under GNU GPL\n\r");
	AT91F_DBGU_Printk("Version " COMPILE_SVNREV
			  " compiled " COMPILE_DATE
			  " by " COMPILE_BY "\n\r\n\r");
	AT91F_DBGU_Printk("\n\rDEBUG Interface:\n\r"
			  "0) Set Pull-up 1) Clear Pull-up 2) Toggle LED1 3) "
			  "Toggle LED2\r\n9) Reset\n\r");

	debugp("RSTC_SR=0x%08x\n", rst_status);
}
コード例 #5
0
int main()
{
	int				_row, _col;
	char			c;
	U32				status;
	
	AT91PS_PIO    	pPioA  	= AT91C_BASE_PIOA;
	AT91PS_PMC    	pPMC   	= AT91C_BASE_PMC;
	AT91PS_USART 	pUART0 	= AT91C_BASE_US0;

	
	/* Initialize the Atmel AT91SAM7X256 (watchdog, PLL clock, default interrupts, etc.) */
	AT91F_LowLevel_Init();
	
	/* Init the LCD */
	InitLCD();

	/* Init the UART */
	AT91F_US_Configure(pUART0, MCK, AT91C_US_ASYNC_MODE, 9600L, 0 );
	AT91F_PMC_EnablePeripheralClock(pPMC, 1 << AT91C_ID_US0 );
    AT91F_US_EnableRx(pUART0);
    AT91F_US_EnableTx(pUART0);
	AT91F_PIO_Disable( pPioA, RXD0 | TXD0 | RTS0 | CTS0  );
	AT91F_PIO_A_RegisterSelection( pPioA, RXD0 | TXD0 | RTS0 | CTS0  );

	
	/* enable interrupts */
	AT91F_Finalize_Init();

	
	/* add your program here ... */
	LCD_ClearScreen( LCD_COLOR_RED );
	LCD_WriteString("UART Demo:", &Fixedsys_descriptor, 2, Fixedsys_descriptor.font_height, 
			                                               LCD_COLOR_WHITE, LCD_COLOR_RED);
	_row = 2*(Fixedsys_descriptor.font_height+2);
	_col = 2;
	
	/* ... and here */
	while ( true )
	{
		status = AT91F_US_RxReady(pUART0);
		if(status) {
			c = AT91F_US_GetChar(pUART0);
			AT91F_US_PutChar(pUART0, c);
			LCD_WriteChar(c, &Fixedsys_descriptor, _col, _row, LCD_COLOR_WHITE, LCD_COLOR_RED);
			if (_col<(128-Fixedsys_descriptor.font_width))
				_col += Fixedsys_descriptor.font_width;
			else {
				_col = 2;
				_row += (Fixedsys_descriptor.font_height+2);
				if (_row>(128-Fixedsys_descriptor.font_height)) {
					LCD_ClearScreen( LCD_COLOR_RED );
					_row = 2; //Fixedsys_descriptor.font_height;
					_col = 2;
				}
			}
		}
		else
			status = AT91F_US_TxReady(pUART0);
			if(status) {
				//AT91F_US_PutChar(pUART0, '.');
			}
	}
	
	/* Actually, the execution never gets here */
	return 0;
}
コード例 #6
0
ファイル: usart.c プロジェクト: FlameN/STM32RUNO
//===============================================================================================
void AT91F_USART_OPEN(AT91_USART_ID idPort, long BaudRate, int mode)
{
	portENTER_CRITICAL();
	{
		switch (idPort)
		{
		case AT91_USART_COM0_ID:
			COM0.id = idPort;
			COM0.hPort = AT91C_BASE_US0;
			COM0.hError = ErrorCreate("US0_Error");
			COM0.hPDC = AT91C_BASE_PDC_US0;

			AT91F_PDC_Open(COM0.hPDC);
			// AT91F_US0_CfgPIO(); //* Define RXD and TXD as peripheral
			AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, // PIO controller base address
					(((unsigned int) AT91C_PA5_RXD0)
							| ((unsigned int) AT91C_PA6_TXD0)), // Peripheral A
					0);
			AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1 << AT91C_ID_US0); // First, enable the clock of the PIOB
			AT91F_US_Configure(COM0.hPort, MCK, mode, BaudRate, 0); // Usart Configure

			AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_US0,
					USART_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
					(void(*)(void)) AT91_US0_ISR_ENTRY);

			AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_US0);
			COM0.hRxQueue = xQueueCreate(1, sizeof(int));
			while (COM0.hRxQueue == 0)
				; // Queue was not created and must not be used.
			COM0.hTxQueue = xQueueCreate(1, sizeof(int));
			while (COM0.hTxQueue == 0)
				; // Queue was not created and must not be used.

			break;

		case AT91_USART_COM1_ID:
			COM1.id = idPort;
			COM1.hPort = AT91C_BASE_US1;
			COM1.hPDC = AT91C_BASE_PDC_US1;
			COM1.hError = ErrorCreate("US1_Error");
			AT91F_PDC_DisableTx(COM1.hPDC);
			AT91F_PDC_DisableRx(COM1.hPDC);
			AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, // PIO controller base address
					(((unsigned int) AT91C_PA21_RXD1)
							| ((unsigned int) AT91C_PA22_TXD1)), // Peripheral A
					0);
			AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1 << AT91C_ID_US1); // First, enable the clock of the PIOB
			AT91F_US_Configure(COM1.hPort, MCK, mode, BaudRate, 0); // Usart Configure
			AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_US1,
					USART_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
					(void(*)(void)) AT91_US1_ISR_ENTRY);
			AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_US1);

			COM1.hRxQueue = xQueueCreate(1, sizeof(int));
			while (COM1.hRxQueue == 0)
				; // Queue was not created and must not be used.

			COM1.hTxQueue = xQueueCreate(1, sizeof(int));
			while (COM1.hTxQueue == 0)
				; // Queue was not created and must not be used.
			break;
		default:
			while (1)
				;// error port notfound;
		}

	}
	portEXIT_CRITICAL();
}