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.
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)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- There are already over 300 CircuitPython libraries
- Is LDO a DC/DC?
- EEWORLD University - Strengthen power knowledge through the TI Power Management Lab Kit (TI-PMLK) series
- [TI recommended course] #[High Precision Lab] Clock and Timing#
- How do you estimate the number of vias on the capacitors in the power supply section of a PCB? Do you need to drill a lot of vias if the capacitors don't carry a lot of current?
- The blueNRG-1 chip will burn out automatically when running the program (solved)
- Application of DSP repetitive control technology in inverter power supply system
- The ov7725 camera has serious distortion. What's going on?
- 【CH579M-R1】+Help: How to receive complete serial port data
- Regarding the calculation of the values of TA0CCR1 and TA0CCR2 configured by the PWM library function