Skip to content

Commit 9c78680

Browse files
authored
Merge pull request #5310 from mysterywolf/printf2
[kservice] 优化RT_PRINTF_LONGLONG,减少重复代码
2 parents f4c3b83 + 2d505d8 commit 9c78680

File tree

2 files changed

+124
-142
lines changed

2 files changed

+124
-142
lines changed

src/Kconfig

Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -115,37 +115,40 @@ config RT_USING_TIMER_SOFT
115115
thread.
116116

117117
if RT_USING_TIMER_SOFT
118-
config RT_TIMER_THREAD_PRIO
119-
int "The priority level value of timer thread"
120-
default 4
121-
122-
config RT_TIMER_THREAD_STACK_SIZE
123-
int "The stack size of timer thread"
124-
default 512
118+
config RT_TIMER_THREAD_PRIO
119+
int "The priority level value of timer thread"
120+
default 4
125121

122+
config RT_TIMER_THREAD_STACK_SIZE
123+
int "The stack size of timer thread"
124+
default 512
126125
endif
127126

128127
menu "kservice optimization"
129128

130-
config RT_KSERVICE_USING_STDLIB
131-
bool "Enable kservice to use standard C library"
132-
default n
129+
config RT_KSERVICE_USING_STDLIB
130+
bool "Enable kservice to use standard C library"
131+
default n
133132

134-
config RT_KSERVICE_USING_TINY_SIZE
135-
bool "Enable kservice to use tiny size"
136-
default n
133+
config RT_KSERVICE_USING_TINY_SIZE
134+
bool "Enable kservice to use tiny size"
135+
default n
137136

138-
config RT_USING_ASM_MEMCPY
139-
bool
140-
default n
137+
config RT_USING_ASM_MEMCPY
138+
bool
139+
default n
141140

142-
config RT_USING_ASM_MEMSET
143-
bool
144-
default n
141+
config RT_USING_ASM_MEMSET
142+
bool
143+
default n
145144

146-
config RT_USING_TINY_FFS
147-
bool "Enable kservice to use tiny ffs"
148-
default n
145+
config RT_USING_TINY_FFS
146+
bool "Enable kservice to use tiny finding first bit set method"
147+
default n
148+
149+
config RT_PRINTF_LONGLONG
150+
bool "Enable rt_printf-family functions to support long long format"
151+
default n
149152

150153
endmenu
151154

@@ -155,121 +158,122 @@ menuconfig RT_DEBUG
155158

156159
if RT_DEBUG
157160

158-
config RT_DEBUG_COLOR
159-
bool "Enable color debugging log"
160-
default n
161+
config RT_DEBUG_COLOR
162+
bool "Enable color debugging log"
163+
default n
161164

162-
config RT_DEBUG_INIT_CONFIG
163-
bool "Enable debugging of components initialization"
164-
default n
165+
config RT_DEBUG_INIT_CONFIG
166+
bool "Enable debugging of components initialization"
167+
default n
165168

166-
config RT_DEBUG_INIT
167-
int
168-
default 1 if RT_DEBUG_INIT_CONFIG
169+
config RT_DEBUG_INIT
170+
int
171+
default 1 if RT_DEBUG_INIT_CONFIG
169172

170-
config RT_DEBUG_THREAD_CONFIG
171-
bool "Enable debugging of Thread State Changes"
172-
default n
173+
config RT_DEBUG_THREAD_CONFIG
174+
bool "Enable debugging of Thread State Changes"
175+
default n
173176

174-
config RT_DEBUG_THREAD
175-
int
176-
default 1 if RT_DEBUG_THREAD_CONFIG
177+
config RT_DEBUG_THREAD
178+
int
179+
default 1 if RT_DEBUG_THREAD_CONFIG
177180

178-
config RT_DEBUG_SCHEDULER_CONFIG
179-
bool "Enable debugging of Scheduler"
180-
default n
181+
config RT_DEBUG_SCHEDULER_CONFIG
182+
bool "Enable debugging of Scheduler"
183+
default n
181184

182-
config RT_DEBUG_SCHEDULER
183-
int
184-
default 1 if RT_DEBUG_SCHEDULER_CONFIG
185+
config RT_DEBUG_SCHEDULER
186+
int
187+
default 1 if RT_DEBUG_SCHEDULER_CONFIG
185188

186-
config RT_DEBUG_IPC_CONFIG
187-
bool "Enable debugging of IPC"
188-
default n
189+
config RT_DEBUG_IPC_CONFIG
190+
bool "Enable debugging of IPC"
191+
default n
189192

190-
config RT_DEBUG_IPC
191-
int
192-
default 1 if RT_DEBUG_IPC_CONFIG
193+
config RT_DEBUG_IPC
194+
int
195+
default 1 if RT_DEBUG_IPC_CONFIG
193196

194-
config RT_DEBUG_TIMER_CONFIG
195-
bool "Enable debugging of Timer"
196-
default n
197+
config RT_DEBUG_TIMER_CONFIG
198+
bool "Enable debugging of Timer"
199+
default n
197200

198-
config RT_DEBUG_TIMER
199-
int
200-
default 1 if RT_DEBUG_TIMER_CONFIG
201+
config RT_DEBUG_TIMER
202+
int
203+
default 1 if RT_DEBUG_TIMER_CONFIG
201204

202-
config RT_DEBUG_IRQ_CONFIG
203-
bool "Enable debugging of IRQ(Interrupt Request)"
204-
default n
205+
config RT_DEBUG_IRQ_CONFIG
206+
bool "Enable debugging of IRQ(Interrupt Request)"
207+
default n
205208

206-
config RT_DEBUG_IRQ
207-
int
208-
default 1 if RT_DEBUG_IRQ_CONFIG
209+
config RT_DEBUG_IRQ
210+
int
211+
default 1 if RT_DEBUG_IRQ_CONFIG
209212

210-
config RT_DEBUG_MEM_CONFIG
211-
bool "Enable debugging of Small Memory Algorithm"
212-
default n
213+
config RT_DEBUG_MEM_CONFIG
214+
bool "Enable debugging of Small Memory Algorithm"
215+
default n
213216

214-
config RT_DEBUG_MEM
215-
int
216-
default 1 if RT_DEBUG_MEM_CONFIG
217+
config RT_DEBUG_MEM
218+
int
219+
default 1 if RT_DEBUG_MEM_CONFIG
217220

218-
config RT_DEBUG_SLAB_CONFIG
219-
bool "Enable debugging of SLAB Memory Algorithm"
220-
default n
221+
config RT_DEBUG_SLAB_CONFIG
222+
bool "Enable debugging of SLAB Memory Algorithm"
223+
default n
221224

222-
config RT_DEBUG_SLAB
223-
int
224-
default 1 if RT_DEBUG_SLAB_CONFIG
225+
config RT_DEBUG_SLAB
226+
int
227+
default 1 if RT_DEBUG_SLAB_CONFIG
225228

226-
config RT_DEBUG_MEMHEAP_CONFIG
227-
bool "Enable debugging of Memory Heap Algorithm"
228-
default n
229+
config RT_DEBUG_MEMHEAP_CONFIG
230+
bool "Enable debugging of Memory Heap Algorithm"
231+
default n
229232

230-
config RT_DEBUG_MEMHEAP
231-
int
232-
default 1 if RT_DEBUG_MEMHEAP_CONFIG
233+
config RT_DEBUG_MEMHEAP
234+
int
235+
default 1 if RT_DEBUG_MEMHEAP_CONFIG
233236

234-
config RT_DEBUG_MODULE_CONFIG
235-
bool "Enable debugging of Application Module"
236-
default n
237+
config RT_DEBUG_MODULE_CONFIG
238+
bool "Enable debugging of Application Module"
239+
default n
237240

238-
config RT_DEBUG_MODULE
239-
int
240-
default 1 if RT_DEBUG_MODULE_CONFIG
241+
config RT_DEBUG_MODULE
242+
int
243+
default 1 if RT_DEBUG_MODULE_CONFIG
241244

242245
endif
243246

244247
menu "Inter-Thread communication"
245248

246-
config RT_USING_SEMAPHORE
247-
bool "Enable semaphore"
248-
default y
249+
config RT_USING_SEMAPHORE
250+
bool "Enable semaphore"
251+
default y
249252

250-
config RT_USING_MUTEX
251-
bool "Enable mutex"
252-
default y
253+
config RT_USING_MUTEX
254+
bool "Enable mutex"
255+
default y
253256

254-
config RT_USING_EVENT
255-
bool "Enable event flag"
256-
default y
257+
config RT_USING_EVENT
258+
bool "Enable event flag"
259+
default y
257260

258-
config RT_USING_MAILBOX
259-
bool "Enable mailbox"
260-
default y
261+
config RT_USING_MAILBOX
262+
bool "Enable mailbox"
263+
default y
261264

262-
config RT_USING_MESSAGEQUEUE
263-
bool "Enable message queue"
264-
default y
265+
config RT_USING_MESSAGEQUEUE
266+
bool "Enable message queue"
267+
default y
268+
269+
config RT_USING_SIGNALS
270+
bool "Enable signals"
271+
select RT_USING_MEMPOOL
272+
default n
273+
help
274+
A signal is an asynchronous notification sent to a specific thread
275+
in order to notify it of an event that occurred.
265276

266-
config RT_USING_SIGNALS
267-
bool "Enable signals"
268-
select RT_USING_MEMPOOL
269-
default n
270-
help
271-
A signal is an asynchronous notification sent to a specific thread
272-
in order to notify it of an event that occurred.
273277
endmenu
274278

275279
menu "Memory Management"
@@ -375,10 +379,6 @@ menu "Kernel Device Object"
375379
config RT_CONSOLE_DEVICE_NAME
376380
string "the device name for console"
377381
default "uart"
378-
379-
config RT_PRINTF_LONGLONG
380-
bool "rt_kprintf support long long"
381-
default n
382382
endif
383383

384384
endmenu

src/kservice.c

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ RTM_EXPORT(rt_show_version);
593593
/* private function */
594594
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
595595

596-
#ifdef RT_PRINTF_LONGLONG
597596
/**
598597
* This function will duplicate a string.
599598
*
@@ -603,44 +602,38 @@ RTM_EXPORT(rt_show_version);
603602
*
604603
* @return the duplicated string pointer.
605604
*/
605+
#ifdef RT_PRINTF_LONGLONG
606606
rt_inline int divide(long long *n, int base)
607+
#else
608+
rt_inline int divide(long *n, int base)
609+
#endif /* RT_PRINTF_LONGLONG */
607610
{
608611
int res;
609612

610613
/* optimized for processor which does not support divide instructions. */
611614
if (base == 10)
612615
{
616+
#ifdef RT_PRINTF_LONGLONG
613617
res = (int)(((unsigned long long)*n) % 10U);
614618
*n = (long long)(((unsigned long long)*n) / 10U);
615-
}
616-
else
617-
{
618-
res = (int)(((unsigned long long)*n) % 16U);
619-
*n = (long long)(((unsigned long long)*n) / 16U);
620-
}
621-
622-
return res;
623-
}
624619
#else
625-
rt_inline int divide(long *n, int base)
626-
{
627-
int res;
628-
629-
/* optimized for processor which does not support divide instructions. */
630-
if (base == 10)
631-
{
632620
res = (int)(((unsigned long)*n) % 10U);
633621
*n = (long)(((unsigned long)*n) / 10U);
622+
#endif
634623
}
635624
else
636625
{
626+
#ifdef RT_PRINTF_LONGLONG
627+
res = (int)(((unsigned long long)*n) % 16U);
628+
*n = (long long)(((unsigned long long)*n) / 16U);
629+
#else
637630
res = (int)(((unsigned long)*n) % 16U);
638631
*n = (long)(((unsigned long)*n) / 16U);
632+
#endif
639633
}
640634

641635
return res;
642636
}
643-
#endif /* RT_PRINTF_LONGLONG */
644637

645638
rt_inline int skip_atoi(const char **s)
646639
{
@@ -659,7 +652,6 @@ rt_inline int skip_atoi(const char **s)
659652
#define SPECIAL (1 << 5) /* 0x */
660653
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
661654

662-
#ifdef RT_PRINTF_PRECISION
663655
static char *print_number(char *buf,
664656
char *end,
665657
#ifdef RT_PRINTF_LONGLONG
@@ -669,20 +661,10 @@ static char *print_number(char *buf,
669661
#endif /* RT_PRINTF_LONGLONG */
670662
int base,
671663
int s,
664+
#ifdef RT_PRINTF_PRECISION
672665
int precision,
673-
int type)
674-
#else
675-
static char *print_number(char *buf,
676-
char *end,
677-
#ifdef RT_PRINTF_LONGLONG
678-
long long num,
679-
#else
680-
long num,
681-
#endif /* RT_PRINTF_LONGLONG */
682-
int base,
683-
int s,
684-
int type)
685666
#endif /* RT_PRINTF_PRECISION */
667+
int type)
686668
{
687669
char c, sign;
688670
#ifdef RT_PRINTF_LONGLONG

0 commit comments

Comments
 (0)