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

Publisher:平和宽容Latest update time:2021-10-14 Source: eefocusKeywords:S3C2440A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

3. Serial port interrupt service thread

After the serial port interrupt is generated, the specific data processing will be completed in the interrupt service thread. Take the camera interrupt thread in the BSP package as an example.


DWORD CameraCaptureThread(void)

{

unsigned char tmp=0;

static unsigned int time,old_time;

static unsigned int cam_intr;

DWORD dwCause;

 

//dwDisplayTimeout = INFINITE;

 

SetProcPermissions((DWORD)-1);

while(TRUE)

{

RETAILMSG(0,(TEXT("[CAM_HW] InterruptThread : Waiting For a Single Objectnr")));

dwCause = WaitForSingleObject(CameraEvent, dwDisplayTimeout);

RETAILMSG(MSG_EN_1,(_T("CameraCaptureThread(%d)++rn"), frame_count));

if (dwCause == WAIT_OBJECT_0)

{

Lock();

 

__try

{

 

if (s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_C ))

{

frame_count++;

cam_intr |= ( 1 << IRQ_SUB_CAM_C );

    

s2440INT->SUBSRCPND  =  (1< s2440INT->INTSUBMSK &= ~(1< //RETAILMSG(1,(_T("CAM_C, ts %drn"), GetTickCount()));

}

 

if (s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_P ))

{

cam_intr |= ( 1 << IRQ_SUB_CAM_P );

s2440INT->SUBSRCPND  =  (1< s2440INT->INTSUBMSK &= ~(1< //RETAILMSG(1,(_T("CAM_P, ts %drn"), GetTickCount()));

}

 

if (((s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_C )) == 0) && ((s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_P )) == 0))

{

RETAILMSG(MSG_EN_1,(_T("[CAM]NOPrn")));

}

InterruptDone(g_CamSysIntr);

//time = GetTickCount();

//RETAILMSG(1,(TEXT("+time:%drn"),(time - old_time)));

// Handle any interrupts on the input source

if (cam_intr & ( 1 << IRQ_SUB_CAM_P ))

{

// display the image

if (DRIVER_PREVIEW_ENABLE == 1)

Display_Cam_Image(LCD_XSIZE_TFT-PREVIEW_X,0,PREVIEW_X, PREVIEW_Y, PORT_A);

 

Buffer_preview_info_update();

cam_intr &= ~( 1 << IRQ_SUB_CAM_P );

}

if (cam_intr & ( 1 << IRQ_SUB_CAM_C ))

{

Buffer_codec_info_update();

cam_intr &= ~( 1 << IRQ_SUB_CAM_C );

}

 

// Enable camera interrupt

//s2440INT->INTSUBMSK &= ~(( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));

//s2440INT->INTMSK &= ~( 1 << IRQ_CAM );

 

//old_time = GetTickCount();

//RETAILMSG(1,(TEXT("-time:%drn"),(old_time-time)));

 

}

__except(EXCEPTION_EXECUTE_HANDLER)

{

RETAILMSG(PM_MSG, (TEXT("Camera.DLL:InterruptThread() - EXCEPTION: %d"), GetExceptionCode()));

}

Unlock();

}

else if (dwCause == WAIT_TIMEOUT)

{

Lock();

RETAILMSG(PM_MSG,(_T("[CAM_HW] InterruptThread Timeout : %d msecrn"), dwDisplayTimeout));

dwDisplayTimeout = INFINITE; // reset timeout until Camera Interrupt occurs

bIdlePwrDown = TRUE; // Codec is off

 

CamInterface_PowerDown();

RETAILMSG(PM_MSG, (TEXT("[CAM_HW] InterruptThread : bIdlePwrDown = TRUErn")));

 

Unlock();

}

else

{

RETAILMSG(PM_MSG, (TEXT("[CAM_HW] InterruptThread : Exit %d, Cause %drn"), GetLastError(), dwCause));

}

}

 

return 0;

}

The WaitForSingleObject() function is a way to wait for interrupt events. It is used to bind events and logical interrupts when the serial port interrupt thread is initialized. The second parameter of the function indicates the time to wait for the event to occur. INFINITE means waiting forever. After the interrupt is triggered, the interrupt flag variable cam_intr is set and the interrupt is enabled. The interrupt function of the OAL layer is implemented in intr.c in the common directory. The control of the sub-interrupt register can be implemented in intr.c in the OAL directory.


4. Configuration of S3C2440A serial port registers

The serial port FIFO mode is used to transmit data, so the key is to configure UFCON and UCON. UFCON sets the interrupt trigger value of the serial port FIFO, as shown in the figure

The 4th bit is used to enable FIFO mode and reset FIFO. The upper 4 bits set the interrupt trigger value. If it is set to 0, it is equivalent to not using FIFO mode.


The 8th and 9th bits in UCON that are related to FIFO are used to set the interrupt trigger mode to LEVEL or PULSE.

Pulse mode means that an interrupt will be generated when the amount of data in the FIFO reaches your requirement. But please note that the interrupt will only be generated at that moment. If you are processing the previous interrupt at that time and mask the interrupt, the interrupt will be lost and the data in the FIFO will continue to increase until it overflows.


Level mode means that an interrupt will be generated as long as the amount of data in the FIFO reaches your requirement, including when it is more than you require.


In the case of serial port receiving data loss, we usually set the trigger threshold of FIFO receiving interrupt to 0 and the interrupt trigger mode to LEVEL; that is, when the value in FIFO is greater than or equal to 0, the receiving interrupt will be triggered, so that the interrupt service thread can receive the data in time. In addition, in order to respond to interrupts more promptly, we can change the InterruptDone function in the interrupt service thread to write the clear interrupt flag and enable interrupt instead, so as to improve the interrupt efficiency.

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

Previous article:S3C2440A serial port driver - Data communication between serial port and peripherals under WINCE6.0 (I)
Next article:Uboot replaces eboot to burn and start wince

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号