Skip to content

Commit b3afd60

Browse files
Bogdan PricopKevin Moloney
authored andcommitted
Fix Klocwork#137: Non-void function does not return value
Move getTimeStampClks() function to an *.S file It is fully implemented in assembly and we take care of returning value by filling in the proper value in the proper registers. Signed-off-by: Bogdan Pricop <[email protected]>
1 parent 0ffb974 commit b3afd60

File tree

4 files changed

+48
-26
lines changed

4 files changed

+48
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*.swp
66
*.bin
77
.*
8+
cscope.*

cores/arduino/utils.S

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright (c) 2015 Intel Corporation. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
18+
*/
19+
20+
21+
.globl getTimeStampClks
22+
.type getTimeStampClks, %function
23+
24+
getTimeStampClks:
25+
/* Disable interrupts - we don't want to be disturbed */
26+
clri r2
27+
/* Load in r1 value of timer0_overflows */
28+
ld r1, [timer0_overflows]
29+
/* Read COUNT0 register */
30+
lr r0, [0x21]
31+
/* Read CONTROL0 register */
32+
lr r3, [0x22]
33+
/* If CONTROL0.IP is set COUNT0 reached LIMIT0 => r1 value might not be
34+
* accurate => read COUNT0 again */
35+
bbit0.nt r3, 3, end
36+
/* Read COUNT0 again*/
37+
lr r0, [0x21]
38+
/* Timer0 overflowed => timer0_overflows++ */
39+
add r1, r1, 1
40+
/***/
41+
end:
42+
seti r2
43+

cores/arduino/wiring.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2929
#define FREQ_MHZ ((ARCV2_TIMER0_CLOCK_FREQ)/1000000)
3030
static const uint64_t MS_TO_CLKS = (FREQ_MHZ * 1000);
3131

32-
static uint64_t getTimeStampClks(void)
33-
{
34-
__asm__ volatile (
35-
/* Disable interrupts - we don't want to be disturbed */
36-
"clri r2 \n\t"
37-
/* Load in r1 value of timer0_overflows */
38-
"ld r1, %0 \n\t"
39-
/* Read COUNT0 register */
40-
"lr r0, [0x21] \n\t"
41-
/* Read CONTROL0 register */
42-
"lr r3, [0x22] \n\t"
43-
/* If CONTROL0.IP is set COUNT0 reached LIMIT0 => r1 value might not be
44-
* accurate => read COUNT0 again */
45-
"bbit0.nt r3, 3, end \n\t"
46-
/* Read COUNT0 again*/
47-
"lr r0, [0x21] \n\t"
48-
/* Timer0 overflowed => timer0_overflows++ */
49-
"add r1, r1, 1 \n\t"
50-
/***/
51-
"end: \n\t"
52-
"seti r2 \n\t"
53-
: /* Output parameters and their constraints */
54-
: "m"(timer0_overflows) /* Input parameters and their constraints */
55-
: "r0", "r1", "r2", "r3" /* Killed registers */
56-
);
57-
}
32+
extern uint64_t getTimeStampClks(void);
5833

5934
void delay(uint32_t msec)
6035
{

platform.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ build.usb_manufacturer="Unknown"
5959
## Compile c files
6060
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
6161

62+
## Compile S files
63+
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
64+
6265
## Compile c++ files
6366
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
6467

0 commit comments

Comments
 (0)