update AT91SAM9260 usart driver, using serial driver component.

This commit is contained in:
weety committed 2013-07-21 15:01:42 +08:00
1 parent 9980041de6
commit 885301bb14
10 files changed
+436 -822

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ Import('RTT_ROOT')
from building import *
src_bsp = ['application.c', 'startup.c', 'board.c']
src_drv = ['console.c']
src_drv = ['usart.c']
if GetDepend('RT_USING_LED'):
src_drv += ['led.c']
+7 -216
View File
File diff suppressed because it is too large. Load diff
-2
View File
@@ -16,9 +16,7 @@
#define __BOARD_H__
#include <at91sam926x.h>
#include <serial.h>
void rt_hw_board_init(void);
//void rt_hw_sdcard_init(void);
#endif
-180
View File
@@ -1,180 +0,0 @@
#include <rtthread.h>
#include <serial.h>
#define RT_CONSOLE_WIDTH 240
#define RT_CONSOLE_HEIGHT 320
#define RT_CONSOLE_FONT_WIDTH 8
#define RT_CONSOLE_FONT_HEIGHT 16
#define RT_CONSOLE_COL (RT_CONSOLE_WIDTH/RT_CONSOLE_FONT_WIDTH)
#define RT_CONSOLE_ROW (RT_CONSOLE_HEIGHT/RT_CONSOLE_FONT_HEIGHT)
#define RT_CONSOLE_TAB 4
#define RT_CONSOLE_FOREPIXEL (0x001f)
extern struct serial_device uart0;
struct rt_console
{
rt_uint8_t* video_ptr;
rt_uint8_t* font_ptr;
/* bpp and pixel of width */
rt_uint8_t bpp;
rt_uint32_t pitch;
/* current cursor */
rt_uint8_t current_col;
rt_uint8_t current_row;
};
struct rt_console console;
void rt_hw_console_init(rt_uint8_t* video_ptr, rt_uint8_t* font_ptr, rt_uint8_t bpp);
void rt_hw_console_newline(void);
void rt_hw_console_putc(char c);
void rt_hw_console_clear(void);
void rt_hw_console_init(rt_uint8_t* video_ptr, rt_uint8_t* font_ptr, rt_uint8_t bpp)
{
rt_memset(&console, 0, sizeof(struct rt_console));
console.video_ptr = video_ptr;
console.font_ptr = font_ptr;
console.bpp = bpp;
console.pitch = console.bpp * RT_CONSOLE_WIDTH;
rt_hw_console_clear();
}
void rt_hw_console_putc(char c)
{
switch (c)
{
case 10:
case 11:
case 12:
case 13:
/* to next line */
rt_hw_console_newline();
console.current_col = 0;
break;
case 9:
console.current_col += RT_CONSOLE_TAB;
break;
default:
{
rt_uint8_t* font_ptr;
register rt_uint32_t cursor;
register rt_uint32_t i, j;
if (console.current_col == RT_CONSOLE_COL)
{
rt_hw_console_newline();
console.current_col = 0;
rt_hw_console_putc(c);
return;
}
font_ptr = console.font_ptr + c * RT_CONSOLE_FONT_HEIGHT;
cursor = (console.current_row * RT_CONSOLE_FONT_HEIGHT) * console.pitch
+ console.current_col * RT_CONSOLE_FONT_WIDTH * console.bpp;
for (i = 0; i < RT_CONSOLE_FONT_HEIGHT; i ++ )
{
for (j = 0; j < RT_CONSOLE_FONT_WIDTH; j ++)
{
if ( ((font_ptr[i] >> (7-j)) & 0x01) != 0 )
{
/* draw a pixel */
rt_uint8_t *ptr = &(console.video_ptr[cursor + i * console.pitch + j * console.bpp]);
switch(console.bpp)
{
case 1:
*ptr = RT_CONSOLE_FOREPIXEL;
break;
case 2:
*(rt_uint16_t*)ptr = RT_CONSOLE_FOREPIXEL;
break;
case 3:
ptr[0] = RT_CONSOLE_FOREPIXEL & 0xff;
ptr[1] = (RT_CONSOLE_FOREPIXEL >> 8) & 0xff;
ptr[2] = (RT_CONSOLE_FOREPIXEL >> 16) & 0xff;
break;
case 4:
*(rt_uint32_t*)ptr = RT_CONSOLE_FOREPIXEL;
break;
}
}
}
}
console.current_col ++;
}
break;
}
}
void rt_hw_console_newline()
{
console.current_row ++;
if (console.current_row >= RT_CONSOLE_ROW)
{
rt_uint32_t i;
/* scroll to next line */
for (i = 0; i < RT_CONSOLE_ROW - 1; i ++)
{
rt_memcpy(console.video_ptr + i * RT_CONSOLE_FONT_HEIGHT * console.pitch,
console.video_ptr + (i + 1) * RT_CONSOLE_FONT_HEIGHT * console.pitch,
RT_CONSOLE_FONT_HEIGHT * console.pitch);
}
/* clear last line */
rt_memset(console.video_ptr + (RT_CONSOLE_ROW - 1) * RT_CONSOLE_FONT_HEIGHT * console.pitch,
0,
RT_CONSOLE_FONT_HEIGHT * console.pitch);
console.current_row = RT_CONSOLE_ROW - 1;
}
}
void rt_hw_console_clear()
{
console.current_col = 0;
console.current_row = 0;
rt_memset(console.video_ptr, 0, RT_CONSOLE_HEIGHT * console.pitch);
}
/* write one character to serial, must not trigger interrupt */
void rt_hw_serial_putc(const char c)
{
/*
to be polite with serial console add a line feed
to the carriage return character
*/
if (c=='\n')rt_hw_serial_putc('\r');
while (!(uart0.uart_device->USART_CSR & TXRDY));
uart0.uart_device->USART_THR = (c & 0x1FF);
}
/**
* This function is used by rt_kprintf to display a string on console.
*
* @param str the displayed string
*/
void rt_hw_console_output(const char* str)
{
while (*str)
{
rt_hw_serial_putc(*str++);
}
}
+12 -8
View File
@@ -62,18 +62,27 @@
/* Using SLAB Allocator */
#define RT_USING_SLAB
/* SECTION: Device System */
/* Using Device System */
#define RT_USING_DEVICE
/* SECTION: the runtime libc library */
/* the runtime libc library */
#define RT_USING_NEWLIB
#define RT_USING_PTHREADS
/* Using Module System */
#define RT_USING_MODULE
#define RT_USING_LIBDL
/* SECTION: Device System */
/* Using Device System */
#define RT_USING_DEVICE
#define RT_USING_DEVICE_IPC
#define RT_USING_SERIAL
/* SECTION: Console options */
#define RT_USING_CONSOLE
/* the buffer size of console */
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "dbgu"
/* SECTION: finsh, a C-Express shell */
/* Using FinSH as Shell*/
@@ -83,11 +92,6 @@
#define FINSH_USING_DESCRIPTION
#define FINSH_THREAD_STACK_SIZE 4096
/* SECTION: the runtime libc library */
/* the runtime libc library */
#define RT_USING_NEWLIB
#define RT_USING_PTHREADS
/* SECTION: C++ support */
/* Using C++ support */
/* #define RT_USING_CPLUSPLUS */
+1 -56
View File
@@ -19,14 +19,8 @@
#ifdef RT_USING_FINSH
#include <finsh.h>
#endif
#ifdef RT_USING_DEVICE
#include <serial.h>
#endif
extern void rt_hw_interrupt_init(void);
extern void rt_hw_board_init(void);
extern void rt_serial_init(void);
extern void rt_system_timer_init(void);
extern void rt_system_scheduler_init(void);
extern void rt_thread_idle_init(void);
@@ -37,9 +31,6 @@ extern void rt_system_heap_init(void*, void*);
extern void rt_hw_finsh_init(void);
extern void rt_application_init(void);
extern struct serial_device uart0;
extern struct rt_device uart0_device;
/**
* @addtogroup at91sam9260
*/
@@ -109,50 +100,6 @@ void rtthread_startup(void)
/* initialize scheduler system */
rt_system_scheduler_init();
#ifdef RT_USING_DEVICE
#ifdef RT_USING_DBGU
/* register dbgu */
rt_hw_serial_register(&uart0_device, "uart0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
&uart0);
#endif
#ifdef RT_USING_UART0
/* register uart0 */
rt_hw_serial_register(&uart1_device, "uart1",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
&uart1);
#endif
#ifdef RT_USING_UART1
/* register uart1 */
rt_hw_serial_register(&uart2_device, "uart2",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
&uart2);
#endif
#ifdef RT_USING_UART2
/* register uart2 */
rt_hw_serial_register(&uart3_device, "uart3",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
&uart3);
#endif
#ifdef RT_USING_UART3
/* register uart3 */
rt_hw_serial_register(&uart4_device, "uart4",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
&uart4);
#endif
#ifdef RT_USING_DFS
//rt_hw_sdcard_init();
#endif
/*init all registed devices */
rt_device_init_all();
#endif
/* initialize application */
rt_application_init();
@@ -160,9 +107,7 @@ void rtthread_startup(void)
/* initialize finsh */
finsh_system_init();
#ifdef RT_USING_DEVICE
#ifdef RT_USING_DBGU
finsh_set_device("uart0");
#endif
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#endif
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -95,7 +95,8 @@ extern "C" {
#define AT91SAM9260_BASE_TC4 0xfffdc040
#define AT91SAM9260_BASE_TC5 0xfffdc080
#define AT91SAM9260_BASE_ADC 0xfffe0000
#define AT91_BASE_SYS 0xffffe800
#define AT91_BASE_SYS 0xffffe800
#define AT91SAM9260_BASE_DBGU 0xfffff200
/*
* System Peripherals (offset from AT91_BASE_SYS)
File diff suppressed because it is too large. Load diff
-76
View File
@@ -1,76 +0,0 @@
#ifndef __RT_HW_SERIAL_H__
#define __RT_HW_SERIAL_H__
#include <rthw.h>
#include <rtthread.h>
#include "at91sam926x.h"
#define RXRDY 0x01
#define TXRDY (1 << 1)
#define BPS 115200 /* serial baudrate */
#define UART_RX_BUFFER_SIZE 64
#define UART_TX_BUFFER_SIZE 64
struct serial_int_rx
{
rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
rt_uint32_t read_index, save_index;
};
struct serial_int_tx
{
rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
rt_uint32_t write_index, save_index;
};
typedef struct uartport
{
/* USART register offsets */
volatile rt_uint32_t USART_CR;
volatile rt_uint32_t USART_MR;
volatile rt_uint32_t USART_IER;
volatile rt_uint32_t USART_IDR;
volatile rt_uint32_t USART_IMR;
volatile rt_uint32_t USART_CSR;
volatile rt_uint32_t USART_RHR;
volatile rt_uint32_t USART_THR;
volatile rt_uint32_t USART_BRGR;
volatile rt_uint32_t USART_RTOR;
volatile rt_uint32_t USART_TTGR;
volatile rt_uint32_t reseverd0[5];
volatile rt_uint32_t USART_FIDI;
volatile rt_uint32_t USART_NER;
volatile rt_uint32_t USART_XXR;
volatile rt_uint32_t USART_IFR;
volatile rt_uint32_t reserved1[44];
volatile rt_uint32_t USART_RPR;
volatile rt_uint32_t USART_RCR;
volatile rt_uint32_t USART_TPR;
volatile rt_uint32_t USART_TCR;
volatile rt_uint32_t USART_RNPR;
volatile rt_uint32_t USART_RNCR;
volatile rt_uint32_t USART_TNPR;
volatile rt_uint32_t USART_TNCR;
volatile rt_uint32_t USART_PTCR;
volatile rt_uint32_t USART_PTSR;
}uartport;
struct serial_device
{
uartport* uart_device;
/* rx structure */
struct serial_int_rx* int_rx;
/* tx structure */
struct serial_int_tx* int_tx;
};
rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
void rt_hw_serial_isr(rt_device_t device);
#endif