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< } if (s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_P )) { cam_intr |= ( 1 << IRQ_SUB_CAM_P ); s2440INT->SUBSRCPND = (1< } 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.
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
- 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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- TI DSP specific model meaning
- What is a connector?
- Please help me analyze how this circuit works
- Help
- How to set up PCB routing like this?
- Dear bachelors, do you cook your dinner yourself or eat out?
- [Popular Science] Usage Scenarios and Precautions for Common Probes & Differential Probes
- Former ZTE Labor Union Chairman Sentenced to 20 Years for Illegal Fund Raising of 2.119 Billion Yuan
- Providing antenna flexibility and high performance for mid-range and high-end smartphones
- Broadband power divider simulation verification + physical parameter comparison analysis