Skip to content

Commit dd594ae

Browse files
committed
support timeout in wait_xxxx
1 parent e25f008 commit dd594ae

File tree

5 files changed

+59
-28
lines changed

5 files changed

+59
-28
lines changed

example/cpt_example.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ PERFC_CPT_BEGIN(this)
8787
do {
8888
void *ptResource = NULL;
8989

90-
PERFC_CPT_WAIT_FOR_RES_UNTIL(
91-
(ptResource != NULL), /* quit condition */
92-
ptResource = malloc(100); /* try to allocate memory */
93-
)
90+
if (fsm_rt_timeout ==
91+
PERFC_CPT_WAIT_FOR_RES_UNTIL( (ptResource != NULL), /* quit condition */
92+
PERFC_CPT_TIMEOUT(5000) /* timeout */
93+
94+
ptResource = malloc(1024 * 1024); /* try to allocate memory */
95+
)) {
96+
printf("memory allocation timeout! \r\n");
97+
}
9498

9599
printf("LED ON [%lld][%p]\r\n", get_system_ms(), ptResource);
96100

example/example.uvoptx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@
735735
<GroupNumber>1</GroupNumber>
736736
<FileNumber>5</FileNumber>
737737
<FileType>1</FileType>
738-
<tvExp>0</tvExp>
738+
<tvExp>1</tvExp>
739739
<tvExpOptDlg>0</tvExpOptDlg>
740740
<bDave2>0</bDave2>
741741
<PathWithFileName>.\cpt_example.c</PathWithFileName>
@@ -839,15 +839,15 @@
839839

840840
<Group>
841841
<GroupName>::Device</GroupName>
842-
<tvExp>1</tvExp>
842+
<tvExp>0</tvExp>
843843
<tvExpOptDlg>0</tvExpOptDlg>
844844
<cbSel>0</cbSel>
845845
<RteFlg>1</RteFlg>
846846
</Group>
847847

848848
<Group>
849849
<GroupName>::Language Extension</GroupName>
850-
<tvExp>1</tvExp>
850+
<tvExp>0</tvExp>
851851
<tvExpOptDlg>0</tvExpOptDlg>
852852
<cbSel>0</cbSel>
853853
<RteFlg>1</RteFlg>

example/example.uvprojx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@
338338
<v6Rtti>0</v6Rtti>
339339
<VariousControls>
340340
<MiscControls></MiscControls>
341-
<Define>__PERFC_STACK_CHECK_IN_ISR__,__PERFC_ALLOWS_RUNNING_WIHTOUT_SYSTIMER_ISR__</Define>
341+
<Define>NDEBUG,__PERFC_STACK_CHECK_IN_ISR__,__PERFC_ALLOWS_RUNNING_WIHTOUT_SYSTIMER_ISR__</Define>
342342
<Undefine></Undefine>
343343
<IncludePath>..</IncludePath>
344344
</VariousControls>
@@ -1824,65 +1824,65 @@
18241824
</api>
18251825
</apis>
18261826
<components>
1827-
<component Capiversion="2.2.0" Cclass="CMSIS Driver" Cgroup="Ethernet" Csub="Custom" Cvendor="ARM" Cversion="1.0.0" custom="1">
1827+
<component Capiversion="2.2.0" Cclass="CMSIS Driver" Cgroup="Ethernet" Csub="Custom" Cvendor="ARM" Cversion="1.0.0" custom="1" ymlID="CMSIS Driver:Ethernet:Custom">
18281828
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
18291829
<targetInfos>
18301830
<targetInfo name="example_arm compiler_5"/>
18311831
<targetInfo name="example_arm_compiler_6"/>
18321832
<targetInfo name="library"/>
18331833
</targetInfos>
18341834
</component>
1835-
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device">
1835+
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device" ymlID="CMSIS:CORE">
18361836
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
18371837
<targetInfos>
18381838
<targetInfo name="example_arm compiler_5"/>
18391839
</targetInfos>
18401840
</component>
1841-
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="6.1.0" condition="ARMv6_7_8-M Device">
1842-
<package name="CMSIS" schemaVersion="1.7.36" url="https://www.keil.com/pack/" vendor="ARM" version="6.1.0"/>
1841+
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="6.1.1" condition="ARMv6_7_8-M Device" ymlID="CMSIS:CORE">
1842+
<package name="CMSIS" schemaVersion="1.7.40" url="https://www.keil.com/pack/" vendor="ARM" version="6.2.0"/>
18431843
<targetInfos>
18441844
<targetInfo name="example_arm_compiler_6"/>
18451845
<targetInfo name="library"/>
18461846
</targetInfos>
18471847
</component>
1848-
<component Cclass="Device" Cgroup="Startup" Cvariant="C Startup" Cvendor="ARM" Cversion="2.2.0" condition="ARMCM0 CMSIS">
1848+
<component Cclass="Device" Cgroup="Startup" Cvariant="C Startup" Cvendor="ARM" Cversion="2.2.0" condition="ARMCM0 CMSIS" ymlID="Device:Startup&amp;C Startup">
18491849
<package name="Cortex_DFP" schemaVersion="1.7.7" url="https://www.keil.com/pack/" vendor="ARM" version="1.0.0"/>
18501850
<targetInfos>
18511851
<targetInfo name="library"/>
18521852
</targetInfos>
18531853
</component>
1854-
<component Cclass="Device" Cgroup="Startup" Cvariant="C Startup" Cvendor="ARM" Cversion="2.2.0" condition="ARMCM4 CMSIS">
1854+
<component Cclass="Device" Cgroup="Startup" Cvariant="C Startup" Cvendor="ARM" Cversion="2.2.0" condition="ARMCM4 CMSIS" ymlID="Device:Startup&amp;C Startup">
18551855
<package name="Cortex_DFP" schemaVersion="1.7.33" url="https://www.keil.com/pack/" vendor="ARM" version="1.1.0"/>
18561856
<targetInfos>
18571857
<targetInfo name="example_arm compiler_5"/>
18581858
<targetInfo name="example_arm_compiler_6"/>
18591859
</targetInfos>
18601860
</component>
1861-
<component Cclass="Language Extension" Cgroup="Coroutine" Cvendor="GorgonMeducer" Cversion="1.0.0" condition="perf_counter">
1861+
<component Cclass="Language Extension" Cgroup="Coroutine" Cvendor="GorgonMeducer" Cversion="1.0.0" condition="perf_counter" ymlID="Language Extension:Coroutine">
18621862
<package name="perf_counter" schemaVersion="1.7.37" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/" vendor="GorgonMeducer" version="9.9.9"/>
18631863
<targetInfos>
18641864
<targetInfo name="example_arm compiler_5"/>
18651865
<targetInfo name="example_arm_compiler_6"/>
18661866
<targetInfo name="library"/>
18671867
</targetInfos>
18681868
</component>
1869-
<component Cclass="Language Extension" Cgroup="protoThread" Cvendor="GorgonMeducer" Cversion="1.1.0" condition="perf_counter">
1869+
<component Cclass="Language Extension" Cgroup="protoThread" Cvendor="GorgonMeducer" Cversion="1.1.0" condition="perf_counter" ymlID="Language Extension:protoThread">
18701870
<package name="perf_counter" schemaVersion="1.7.37" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/" vendor="GorgonMeducer" version="9.9.9"/>
18711871
<targetInfos>
18721872
<targetInfo name="example_arm compiler_5"/>
18731873
<targetInfo name="example_arm_compiler_6"/>
18741874
<targetInfo name="library"/>
18751875
</targetInfos>
18761876
</component>
1877-
<component Cclass="Utilities" Cgroup="perf_counter" Csub="Core" Cvariant="Source" Cvendor="GorgonMeducer" Cversion="2.5.2" condition="CMSIS-CORE">
1878-
<package name="perf_counter" schemaVersion="1.7.37" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/" vendor="GorgonMeducer" version="2.5.2"/>
1877+
<component Cclass="Utilities" Cgroup="perf_counter" Csub="Core" Cvariant="Source" Cvendor="GorgonMeducer" Cversion="2.5.3-dev" condition="CMSIS-CORE" ymlID="Utilities:perf_counter:Core&amp;Source">
1878+
<package name="perf_counter" schemaVersion="1.7.37" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/" vendor="GorgonMeducer" version="9.9.9"/>
18791879
<targetInfos>
18801880
<targetInfo name="example_arm compiler_5"/>
18811881
<targetInfo name="example_arm_compiler_6"/>
18821882
<targetInfo name="library"/>
18831883
</targetInfos>
18841884
</component>
1885-
<component Cbundle="ARM Compiler" Cclass="Compiler" Cgroup="I/O" Csub="STDOUT" Cvariant="User" Cvendor="Keil" Cversion="1.2.0" condition="ARMCC Cortex-M" isTargetSpecific="1">
1885+
<component Cbundle="ARM Compiler" Cclass="Compiler" Cgroup="I/O" Csub="STDOUT" Cvariant="User" Cvendor="Keil" Cversion="1.2.0" condition="ARMCC Cortex-M" isTargetSpecific="1" ymlID="Compiler&amp;ARM Compiler:I/O:STDOUT&amp;User">
18861886
<package name="ARM_Compiler" schemaVersion="1.7.7" url="https://www.keil.com/pack/" vendor="Keil" version="1.7.2"/>
18871887
<targetInfos>
18881888
<targetInfo name="example_arm compiler_5"/>

perf_counter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,12 @@ __asm(".global __ensure_systick_wrapper\n\t");
456456
typedef enum {
457457
fsm_rt_err = -1, //!< fsm error, error code can be get from other interface
458458
fsm_rt_cpl = 0, //!< fsm complete
459+
fsm_rt_ok = 0, //!< no error
459460
fsm_rt_on_going = 1, //!< fsm on-going
460461
fsm_rt_wait_for_obj = 2, //!< fsm wait for object
461462
fsm_rt_asyn = 3, //!< fsm asynchronose complete, you can check it later.
462463
fsm_rt_wait_for_res = 4, //!< fsm wait for resource
464+
fsm_rt_timeout = 5, //!< fsm timeout
463465
} fsm_rt_t;
464466
//! @}
465467
#endif

perfc_task_pt.h

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,47 +201,72 @@ label_switch_start:
201201
goto label_switch_start; \
202202
}
203203

204-
#define PERFC_CPT_WAIT_UNTIL(__CONDITION, ...) \
204+
/*!
205+
* \note this keyword can only be used inside PERFC_CPT_WAIT_...
206+
*/
207+
#define PERFC_CPT_TIMEOUT(__MS) \
205208
{ \
209+
int16_t lCurrentMs = get_system_ms(); \
210+
if (0 == lTimestamp) { \
211+
lTimestamp = lCurrentMs; \
212+
} else if ((lCurrentMs - lTimestamp) >= (__MS)) { \
213+
tCPTResult = fsm_rt_timeout; \
214+
} \
215+
}
216+
217+
#define PERFC_CPT_WAIT_UNTIL(__CONDITION, ...) \
218+
({ \
219+
fsm_rt_t tCPTResult = fsm_rt_ok; \
220+
int64_t lTimestamp = 0; \
221+
UNUSED_PARAM(lTimestamp); \
206222
label_wait_until_entry_##__LINE__: \
207223
(void)(ptTask); \
208224
__VA_ARGS__; \
209-
if ((__CONDITION)) { \
225+
if ((__CONDITION) || tCPTResult == fsm_rt_timeout) { \
210226
goto label_wait_until_exit_##__LINE__; \
211227
} \
212228
PERFC_CPT_YIELD(fsm_rt_on_going); \
213229
goto label_wait_until_entry_##__LINE__; \
214230
label_wait_until_exit_##__LINE__: \
215231
(void)(ptTask); \
216-
}
232+
tCPTResult; \
233+
})
217234

218235
#define PERFC_CPT_WAIT_FOR_OBJ_UNTIL(__CONDITION, ...) \
219-
{ \
236+
({ \
237+
fsm_rt_t tCPTResult = fsm_rt_ok; \
238+
int64_t lTimestamp = 0; \
239+
UNUSED_PARAM(lTimestamp); \
220240
label_wait_for_obj_until_entry_##__LINE__: \
221241
(void)(ptTask); \
222242
__VA_ARGS__; \
223-
if ((__CONDITION)) { \
243+
if ((__CONDITION) || tCPTResult == fsm_rt_timeout) { \
224244
goto label_wait_for_obj_until_exit_##__LINE__; \
225245
} \
226246
PERFC_CPT_YIELD(fsm_rt_wait_for_obj); \
227247
goto label_wait_for_obj_until_entry_##__LINE__; \
228248
label_wait_for_obj_until_exit_##__LINE__: \
229249
(void)(ptTask); \
230-
}
250+
tCPTResult; \
251+
})
231252

232253
#define PERFC_CPT_WAIT_FOR_RES_UNTIL(__CONDITION, ...) \
233-
{ \
254+
({ \
255+
fsm_rt_t tCPTResult = fsm_rt_ok; \
256+
int64_t lTimestamp = 0; \
257+
UNUSED_PARAM(lTimestamp); \
234258
label_wait_for_res_until_entry_##__LINE__: \
235259
(void)(ptTask); \
236260
__VA_ARGS__; \
237-
if ((__CONDITION)) { \
261+
if ((__CONDITION) || tCPTResult == fsm_rt_timeout) { \
238262
goto label_wait_for_res_until_exit_##__LINE__; \
239263
} \
240264
PERFC_CPT_YIELD(fsm_rt_wait_for_res); \
241265
goto label_wait_for_res_until_entry_##__LINE__; \
242266
label_wait_for_res_until_exit_##__LINE__: \
243267
(void)(ptTask); \
244-
}
268+
tCPTResult; \
269+
})
245270

246271
#define PERFC_CPT_DELAY_MS(__ms, ...) \
247272
{ \

0 commit comments

Comments
 (0)