S3C2440A serial port driver - Data communication between serial port and peripherals under WINCE6.0 (I)

Publisher:科技革新者Latest update time:2021-10-14 Source: eefocusKeywords:S3C2440A  WINCE6 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Development Environment

Write serial port driver under WINCE6.0, use UART0 of S3C2440A to communicate with PC, and UART1, UART2 to communicate with AVR Atemga162 microcontroller.


2. Serial stream driver process

Mainly complete XXX_Init, XXX_Open, XXX_Read, XXX_Write, XXX_Seek, XXX_PowerUp, XXX_PowerDown, XXX_Close, XXX_Deinit, XXX_IOControl functions. The following introduces the functions used in the driver.


1. XXX_Init()

In the XXX_Init() function, the initialization of the relevant variables and resources in the driver is completed. For example, the initialization of the relevant registers of S3C2440A and the allocation of address space for them. For example, the initialization of the serial port 0 control register


/*Uart0 Controller Register*/

v_pUART0regs = (volatile S3C2440A_UART_REG *)VirtualAlloc(0,sizeof(S3C2440A_UART_REG),MEM_RESERVE, PAGE_NOACCESS);

if (v_pUART0regs == NULL)

{

RETAILMSG(1,(TEXT("v_pUART0regs: VirtualAlloc failed!rn")));

goto MAP_ERROR;

}

if (!VirtualCopy((PVOID)v_pUART0regs,(PVOID)(S3C2440A_BASE_REG_PA_UART0>>8),sizeof(S3C2440A_UART_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCAUTION ))

{

RETAILMSG(1,(TEXT("v_pUART0regs: VirtualCopy failed!rn")));

goto MAP_ERROR;

}

RETAILMSG(1,(TEXT("[SRM] v_pUART0regs is mapped to %xnr"), v_pUART0regs));

In XXX_Init(), it is also important to apply for the logical interrupt of the WINCE system for the physical interrupt of the serial port. The mapping can be completed in two ways: dynamic mapping and static mapping. Static mapping can allocate some default logical interrupts of the system to the physical interrupt when the system is initialized in SrcCommonIntrintr.c, such as

OALIntrStaticTranslate(SYSINTR_ETH, IRQ_EINT7);

You can also use a dynamic method to apply for a logical interrupt number by calling the function KernelIoControl, such as the following code, to apply for a logical interrupt number for serial port 0 interrupt

if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &g_Uart0Irq, sizeof(UINT32), &g_Uart0SysIntr, sizeof(UINT32), NULL))

{

RETAILMSG(1, (TEXT("ERROR: UART0_INIT: Failed to request sysintr value for UART0_INIT interrupt.rn")));

return FALSE;

}

RETAILMSG(1,(TEXT("INFO: UART0: Mapped IRQ_UART0 to SysIntr 0x%x.rn"), g_Uart0SysIntr));


Of course, we need to configure the serial port registers and the serial port interrupt service thread. The configuration of the S3C2440A serial port interrupt register will be introduced in detail in the next article. When porting the serial port driver from WINCE5.0 to WINCE6.0, it is found that it has a lot to do with the serial port FIFO control register. The initialization code of the serial port receiving interrupt thread is as follows


BOOL UART0_InitInterruptThread()

{

BOOL bSuccess = FALSE;

RETAILMSG(DEBUGMODE,(TEXT("+++UART0_InitInterruptThreadn")));

 

m_hUART0InterruptEvent = CreateEvent( NULL, FALSE, FALSE, NULL);

 

if (!m_hUART0InterruptEvent)

{

RETAILMSG(1,(TEXT("+++Create m_hUART0Interrupt Faile n")));

return FALSE;

}

 

bSuccess = InterruptInitialize(g_Uart0SysIntr, m_hUART0InterruptEvent, NULL, 0);

if(!bSuccess)

{

RETAILMSG(1,(TEXT("+++InterruptInitialize Faile n")));

return FALSE;

}

 

m_hUART0InterruptThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL,

0,

(LPTHREAD_START_ROUTINE)CallUART0InterruptThread,

0,

0,

NULL);

if (!m_hUART0InterruptThread)

{

RETAILMSG(1,(TEXT("----UART0_InitInterruptThread failn")));

return FALSE;

}

 

// Bump up the priority since the interrupt must be serviced immediately.

CeSetThreadPriority(m_hUART0InterruptThread,30); //change 3

RETAILMSG(DEBUGMODE,(TEXT("----UART0_InitInterruptThreadn")));

return TRUE;

}


First, create an event through the CreateEvent() function, then bind the event to the logical interrupt number previously applied for through KernelIoControl(), and finally use the CreateThread() function to create the receiving thread. The CeSetThreadPriority() function sets the thread priority. The priority range is as follows


0 through 96 Reserved for real-time above drivers.

97 through 152 Used by the default Windows Embedded CE-based device drivers.

153 through 247 Reserved for real-time below drivers.

248 through 255 Maps to non-real-time priorities.


Different levels of settings can be made according to the real-time requirements of communication.

The initialization function of the serial port sending thread is as follows


BOOL UART0_InitTransmitThread(){

RETAILMSG(DEBUGMODE,(TEXT("+++UART0_InitTransmitThreadn")));

m_hUART0TransmitThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL,0,(LPTHREAD_START_ROUTINE)CallUART0TransmitThread,0,0,NULL);

if (!m_hUART0TransmitThread)

{

RETAILMSG(1,(TEXT("----CallUART0TransmitThread Failn")));

return FALSE;

}

CeSetThreadPriority(m_hUART0TransmitThread,30); //change 2

RETAILMSG(DEBUGMODE,(TEXT("----UART0_InitTransmitThreadn")));

return TRUE;

}


2. XXX_IOControl

The XXX_IOControl() function is mainly used to accept commands sent by the application when calling the driver, and perform different operations according to different commands. The function prototype is as follows


BOOL DMA_IOControl(DWORD hOpenContext,DWORD dwCode,PBYTE pBufIn,DWORD dwLenIn,

PBYTE pBufOut,DWORD dwLenOut,PDWORD pdwActualOut)


Where dwCode is the command control code and pBufIn is the parameter sent by the application.

Keywords:S3C2440A  WINCE6 Reference address:S3C2440A serial port driver - Data communication between serial port and peripherals under WINCE6.0 (I)

Previous article:Kernel (2.6.14) + root file system + Qtopia Core 4 ported for S3C2410
Next article:S3C2440A serial port driver - Data communication between serial port and peripherals under WINCE6.0 (Part 2)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号