Several implementation methods of print function in ARM

Publisher:qpb1234Latest update time:2021-03-17 Source: eefocusKeywords:ARM  print Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1Use the C library function printf.


step:


1) First you need to include the header file stdio.h.


2) Then define the file handle, which is actually an int variable encapsulated in a structure.


struct__FILE{inthandle;};


3) Define FILE__stdout; FILE is __FILE, which is defined by the stdio.h macro.


4) Implement the function


intfputc(intch,FILE*f){chartempch=ch;sendchar(tempch);returnch;}


5) Implement the function


intsendchar(intch){


if(ch=='n'){


while(!(console_tty_f->lsr&UART_LSR_THRE));


console_tty_f->dll_fifo=0x0d;


}


while(!(console_tty_f->lsr&UART_LSR_THRE));


return(console_tty_f->dll_fifo=ch);


}




As can be seen from the above code, printf is a blocking function. Waiting for the message to be sent may affect other processes. If you write a non-waiting print function, you can use the second method.


2 Use the C library function vsprintf and variable parameter function.


step:


1) Include the header files stdio.h and stdarg.h.


2) Write a variable parameter function.


voidprint(constchar*lpszFormat,...){charszBuffer[PRINT_BUF]={0};


va_listargs; enter; va_start(args, lpszFormat);


ret=vsprintf(szBuffer,lpszFormat,args);


va_end(args);


uart[console_uart].put_2_ring(console_uart,szBuffer,ret);


}


It can be seen that the library function vsprintf is used to format the input string and then send it when idle.


3. Complete parameter extraction and formatting by yourself.


step:


1) Define variable parameter list typedef char*va_list;


2) Define address alignment macro


#define_AUPBND(sizeof(int)-1)


#define_ADNBND(sizeof(int)-1)


#define_bnd(X,bnd)(((sizeof(X))+(bnd))&(~(bnd)))


3) Define variable length parameter extraction macro


#defineva_start(ap,A)(void)((ap)=(((char*)&(A))+(_bnd(A,_AUPBND))))


#defineva_arg(ap,T)(*(T*)(((ap)+=(_bnd(T,_AUPBND)))-(_bnd(T,_ADNBND)))


#defineva_end(ap)(void)0


4) Write a variable parameter function, as in step 2 of method 2.


5) Implement the vsprintf function. There are many implementation source codes, such as Linux, etc. But there is no support for floating points.


Keywords:ARM  print Reference address:Several implementation methods of print function in ARM

Previous article:Design of ARM matrix keyboard and its linux driver implementation
Next article:Video Acquisition and Processing System Based on FPGA and ARM

Recommended ReadingLatest update time:2024-11-16 10:35

Summary of ARM architecture related learning
As an ecosystem, ARM not only provides CPU Core, but also provides a series of related IPs, such as GIC, MMU, AMBA, CoreLink, CoreSight, Mali, etc. Others include Debug tools, development tools, IDE, etc. It is very important to establish an overview of the architecture of the entire ARM ecosystem, and then clarif
[Microcontroller]
Summary of ARM architecture related learning
Design of automobile energy-saving control device based on CAN bus and ARM
This paper takes energy conservation as the starting point, and designs an energy-saving control device according to the frequent braking characteristics of urban buses. Through this device, the original braking of the car is changed from the resistance generated by the friction plate to driving the air compressor.
[Microcontroller]
Design of automobile energy-saving control device based on CAN bus and ARM
Various ARM emulator interface diagrams
ULINK2 JTAG/SWD interface How is the ULINK2 interface defined? The following is the definition of the ULINK2 interface: The following is the standard interface arrangement: ST-Link SWIM & JTAG/SWD interfaces The following is the standard interface arrangement: ST-Link specified standard interface  J-Link JTAG
[Microcontroller]
Various ARM emulator interface diagrams
ARM coprocessor access instructions (Linux learning records)
What is a coprocessor? Coprocessors are used to perform specific processing tasks, such as math coprocessors that can control digital processing to reduce the burden on the processor. ARM can support up to 16 coprocessors, of which CP15 is the most important one. What is the function of CP15? The system control
[Microcontroller]
Design of LCD driver terminal based on ARM9 and Linux
1 Introduction At present, the existing LCD driver terminals are mainly designed by combining microcontrollers with front-end and back-end software. This type of terminal can only display pictures in font mode. The display data of this type of terminal is stored in its own NAND Flash. In the process of human-machine
[Microcontroller]
Design of LCD driver terminal based on ARM9 and Linux
ARM IMPORT Image$$RO$$Limit meaning
ARM IMPORT Image$$RO$$Limit meaning IMPORT |Image$$RO$$Base| ; Base of ROM code IMPORT |Image$$RO$$Limit| ; End of ROM code (=start of ROM data) IMPORT |Image$$RW$$Base| ; Base of RAM to initialise IMPORT |Image$$ZI$$Base| ; Base and limit of area IMPORT |Image$$ZI$$Limit| ; to zero initialise IMPORT MMU_SetAsyncBusMo
[Microcontroller]
Google Cloud announces adoption of ARM chips: putting pressure on Intel and AMD
Early morning on July 14, it was reported that Alphabet's Google Cloud division announced on Wednesday local time that they will begin to adopt chips based on ARM technology, becoming another large technology company to join this transformation wave, thus putting more pressure on Intel and AMD.    Google said its new
[Semiconductor design/manufacturing]
How to define addresses using structures in header files of ARM microcontrollers
Below we use the header file lpc11xx.h of the ARM Cortex-M0 core microcontroller LPC1114 to illustrate. 1. A few words first The lpc11xx.h file is the header file included in the lpc11xx series of microcontrollers. The function of this file is the same as the reg51.h header file in the 51 microcontroller, both of whic
[Microcontroller]
How to define addresses using structures in header files of ARM microcontrollers
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号