Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
ad0b7a85
Commit
ad0b7a85
authored
12 years ago
by
Oleg Hahm
Browse files
Options
Downloads
Patches
Plain Diff
* convert to coding conventions
parent
349bec1f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cpu/arm_common/arm_cpu.c
+39
-30
39 additions, 30 deletions
cpu/arm_common/arm_cpu.c
cpu/arm_common/syscalls.c
+135
-141
135 additions, 141 deletions
cpu/arm_common/syscalls.c
with
174 additions
and
171 deletions
cpu/arm_common/arm_cpu.c
+
39
−
30
View file @
ad0b7a85
...
...
@@ -25,59 +25,68 @@
#include
"sched.h"
#include
"kernel_intern.h"
void
thread_yield
()
{
#define STACK_MARKER (0x77777777)
#define REGISTER_CNT (12)
void
thread_yield
(
void
)
{
asm
(
"svc 0
\n
"
);
}
/
/
----------------------------------------------------------------------------
//
Processor specific routine - here for ARM7
//
sizeof(void*) = sizeof(int)
//
--------------------------------------------------------------------------
--
char
*
thread_stack_init
(
void
*
task_func
,
void
*
stack_start
,
int
stack_size
)
/
*
----------------------------------------------------------------------------
*
Processor specific routine - here for ARM7
*
sizeof(void*) = sizeof(int)
*
--------------------------------------------------------------------------
*/
char
*
thread_stack_init
(
void
*
task_func
,
void
*
stack_start
,
int
stack_size
)
{
unsigned
int
*
stk
;
stk
=
(
unsigned
int
*
)
(
stack_start
+
stack_size
);
unsigned
int
*
stk
;
stk
=
(
unsigned
int
*
)
(
stack_start
+
stack_size
);
stk
--
;
*
stk
=
0x77777777
;
stk
--
;
*
stk
=
STACK_MARKER
;
*
stk
=
(
unsigned
int
)
sched_task_exit
;
// LR
/* set the return address (LR) */
stk
--
;
*
stk
=
(
unsigned
int
)
sched_task_exit
;
stk
--
;
*
stk
=
(
unsigned
int
)
(
stack_start
+
stack_size
)
-
4
;
// SP
/* set the stack pointer (SP) */
stk
--
;
*
stk
=
(
unsigned
int
)
(
stack_start
+
stack_size
)
-
4
;
for
(
int
i
=
12
;
i
>=
0
;
i
--
)
{
// build base stack
stk
--
;
*
stk
=
i
;
}
/* build base stack */
for
(
int
i
=
REGISTER_CNT
;
i
>=
0
;
i
--
)
{
stk
--
;
*
stk
=
i
;
}
stk
--
;
*
stk
=
((
unsigned
int
)
task_func
);
// Entry Point
stk
--
;
*
stk
=
(
unsigned
int
)
NEW_TASK_CPSR
;
// spsr
/* set the entry point */
stk
--
;
*
stk
=
((
unsigned
int
)
task_func
);
/* set the saved program status register */
stk
--
;
*
stk
=
(
unsigned
int
)
NEW_TASK_CPSR
;
return
(
char
*
)
stk
;
return
(
char
*
)
stk
;
}
void
thread_print_stack
()
{
register
void
*
stack
=
0
;
void
thread_print_stack
(
void
)
{
register
void
*
stack
=
0
;
asm
(
"mov %0, sp"
:
"=r"
(
stack
));
register
unsigned
int
*
s
=
(
unsigned
int
*
)
stack
;
printf
(
"task: %X SP: %X
\n
"
,
(
unsigned
int
)
active_thread
,
(
unsigned
int
)
stack
);
register
unsigned
int
*
s
=
(
unsigned
int
*
)
stack
;
printf
(
"task: %X SP: %X
\n
"
,
(
unsigned
int
)
active_thread
,
(
unsigned
int
)
stack
);
register
int
i
=
0
;
s
+=
5
;
while
(
*
s
!=
0x77777777
)
{
printf
(
"STACK (%u) addr=%X = %X
\n
"
,
i
,(
unsigned
int
)
s
,
(
unsigned
int
)
*
s
);
while
(
*
s
!=
STACK_MARKER
)
{
printf
(
"STACK (%u) addr=%X = %X
\n
"
,
i
,
(
unsigned
int
)
s
,
(
unsigned
int
)
*
s
);
s
++
;
i
++
;
}
printf
(
"STACK (%u)= %X
\n
"
,
i
,
*
s
);
}
__attribute__
((
naked
,
noreturn
))
void
arm_reset
(
void
)
__attribute__
((
naked
,
noreturn
))
void
arm_reset
(
void
)
{
dINT
();
WDTC
=
0x00FFF
;
...
...
This diff is collapsed.
Click to expand it.
cpu/arm_common/syscalls.c
+
135
−
141
View file @
ad0b7a85
...
...
@@ -17,23 +17,15 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
/**
* @file
* @ingroup
lpc2387
* @brief
LPC2387 NewLib system calls implementation
* @ingroup
lpc2387
* @brief
LPC2387 NewLib system calls implementation
*
* @author Freie Universität Berlin, Computer Systems & Telematics
* @author Michael Baar <michael.baar@fu-berlin.de>
* @version $Revision$
* @author Michael Baar <michael.baar@fu-berlin.de>
*
* @note $Id$
*/
#include
<errno.h>
...
...
@@ -56,9 +48,9 @@ and the mailinglist (subscription via web site)
#include
"hal-syscalls.h"
#endif
#define DEBUG_SYSCALLS
0
#define DEBUG_SYSCALLS
0
#if DEBUG_SYSCALLS
#define
PRINTF(...)
printf(__VA_ARGS__)
#define
PRINTF(...)
printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
...
...
@@ -71,14 +63,14 @@ and the mailinglist (subscription via web site)
* @name Heaps (defined in linker script)
* @{
*/
#define NUM_HEAPS
3//2
#define NUM_HEAPS
3//2
extern
uintptr_t
__heap1_start
;
///< start of heap memory space
extern
uintptr_t
__heap1_max
;
///< maximum for end of heap memory space
extern
uintptr_t
__heap2_start
;
///< start of heap memory space
extern
uintptr_t
__heap2_max
;
///< maximum for end of heap memory space
extern
uintptr_t
__heap3_start
;
///< start of heap memory space
extern
uintptr_t
__heap3_max
;
///< maximum for end of heap memory space
extern
uintptr_t
__heap1_start
;
///< start of heap memory space
extern
uintptr_t
__heap1_max
;
///< maximum for end of heap memory space
extern
uintptr_t
__heap2_start
;
///< start of heap memory space
extern
uintptr_t
__heap2_max
;
///< maximum for end of heap memory space
extern
uintptr_t
__heap3_start
;
///< start of heap memory space
extern
uintptr_t
__heap3_max
;
///< maximum for end of heap memory space
/// current position in heap
...
...
@@ -92,25 +84,27 @@ static const caddr_t heap_start[NUM_HEAPS] = {(caddr_t)&__heap1_start,(caddr_t)&
/** @} */
/*-----------------------------------------------------------------------------------*/
void
heap_stats
(
void
)
{
for
(
int
i
=
0
;
i
<
NUM_HEAPS
;
i
++
)
printf
(
"# heap %i: %p -- %p -> %p (%li of %li free)
\n
"
,
i
,
heap_start
[
i
],
heap
[
i
],
heap_max
[
i
],
(
uint32_t
)
heap_max
[
i
]
-
(
uint32_t
)
heap
[
i
],
(
uint32_t
)
heap_max
[
i
]
-
(
uint32_t
)
heap_start
[
i
]);
void
heap_stats
(
void
)
{
for
(
int
i
=
0
;
i
<
NUM_HEAPS
;
i
++
)
printf
(
"# heap %i: %p -- %p -> %p (%li of %li free)
\n
"
,
i
,
heap_start
[
i
],
heap
[
i
],
heap_max
[
i
],
(
uint32_t
)
heap_max
[
i
]
-
(
uint32_t
)
heap
[
i
],
(
uint32_t
)
heap_max
[
i
]
-
(
uint32_t
)
heap_start
[
i
]);
}
/*-----------------------------------------------------------------------------------*/
void
__assert_func
(
const
char
*
file
,
int
line
,
const
char
*
func
,
const
char
*
failedexpr
)
{
#if SYSLOG_CONF_ASSERT
trace_number
(
TRACELOG_EV_ASSERTION
,
line
);
syslog
(
SL_EMERGENCY
,
"assert"
,
"%s() in %s:%u
\n
"
,
func
,
file
,
line
);
trace_number
(
TRACELOG_EV_ASSERTION
,
line
);
syslog
(
SL_EMERGENCY
,
"assert"
,
"%s() in %s:%u
\n
"
,
func
,
file
,
line
);
#endif
printf
(
"#! assertion %s failed
\n\t
%s() in %s:%u
\n
"
,
failedexpr
,
func
,
file
,
line
);
_exit
(
3
);
printf
(
"#! assertion %s failed
\n\t
%s() in %s:%u
\n
"
,
failedexpr
,
func
,
file
,
line
);
_exit
(
3
);
}
/*-----------------------------------------------------------------------------------*/
void
__assert
(
const
char
*
file
,
int
line
,
const
char
*
failedexpr
)
{
__assert_func
(
file
,
line
,
"?"
,
failedexpr
);
__assert_func
(
file
,
line
,
"?"
,
failedexpr
);
}
/*-----------------------------------------------------------------------------------*/
caddr_t
_sbrk_r
(
struct
_reent
*
r
,
size_t
incr
)
...
...
@@ -125,198 +119,198 @@ caddr_t _sbrk_r(struct _reent *r, size_t incr)
uint32_t
cpsr
=
disableIRQ
();
/* check all heaps for a chunk of the requested size */
for
(
volatile
uint8_t
iUsedHeap
=
0
;
iUsedHeap
<
NUM_HEAPS
;
iUsedHeap
++
)
{
caddr_t
new_heap
=
heap
[
iUsedHeap
]
+
incr
;
#ifdef MODULE_TRACELOG
trace_pointer
(
TRACELOG_EV_MEMORY
,
heap
[
iUsedHeap
]);
#endif
if
(
new_heap
<=
heap_max
[
iUsedHeap
]
)
{
caddr_t
prev_heap
=
heap
[
iUsedHeap
];
#ifdef MODULE_TRACELOG
trace_pointer
(
TRACELOG_EV_MEMORY
,
new_heap
);
#endif
heap
[
iUsedHeap
]
=
new_heap
;
r
->
_errno
=
0
;
restoreIRQ
(
cpsr
);
return
prev_heap
;
}
}
restoreIRQ
(
cpsr
);
#ifdef MODULE_TRACELOG
trace_string
(
TRACELOG_EV_MEMORY
,
"heap!"
);
// heap full
#endif
r
->
_errno
=
ENOMEM
;
for
(
volatile
uint8_t
iUsedHeap
=
0
;
iUsedHeap
<
NUM_HEAPS
;
iUsedHeap
++
)
{
caddr_t
new_heap
=
heap
[
iUsedHeap
]
+
incr
;
#ifdef MODULE_TRACELOG
trace_pointer
(
TRACELOG_EV_MEMORY
,
heap
[
iUsedHeap
]);
#endif
if
(
new_heap
<=
heap_max
[
iUsedHeap
]
)
{
caddr_t
prev_heap
=
heap
[
iUsedHeap
];
#ifdef MODULE_TRACELOG
trace_pointer
(
TRACELOG_EV_MEMORY
,
new_heap
);
#endif
heap
[
iUsedHeap
]
=
new_heap
;
r
->
_errno
=
0
;
restoreIRQ
(
cpsr
);
return
prev_heap
;
}
}
restoreIRQ
(
cpsr
);
#ifdef MODULE_TRACELOG
trace_string
(
TRACELOG_EV_MEMORY
,
"heap!"
);
// heap full
#endif
r
->
_errno
=
ENOMEM
;
return
NULL
;
}
/*---------------------------------------------------------------------------*/
int
_isatty_r
(
struct
_reent
*
r
,
int
fd
)
{
r
->
_errno
=
0
;
if
(
fd
==
STDOUT_FILENO
||
fd
==
STDERR_FILENO
)
return
1
;
else
return
0
;
r
->
_errno
=
0
;
if
(
fd
==
STDOUT_FILENO
||
fd
==
STDERR_FILENO
)
return
1
;
else
return
0
;
}
/*---------------------------------------------------------------------------*/
_off_t
_lseek_r
(
struct
_reent
*
r
,
int
fd
,
_off_t
pos
,
int
whence
)
{
_off_t
result
=
-
1
;
PRINTF
(
"lseek [%i] pos %li whence %i
\n
"
,
fd
,
pos
,
whence
);
_off_t
result
=
-
1
;
PRINTF
(
"lseek [%i] pos %li whence %i
\n
"
,
fd
,
pos
,
whence
);
r
->
_errno
=
ENODEV
;
r
->
_errno
=
ENODEV
;
#ifdef MODULE_FAT
result
=
ff_lseek_r
(
r
,
fd
,
pos
,
whence
);
#endif
PRINTF
(
"lseek returned %li (0 is success)
\n
"
,
result
);
return
result
;
PRINTF
(
"lseek returned %li (0 is success)
\n
"
,
result
);
return
result
;
}
/*---------------------------------------------------------------------------*/
int
_open_r
(
struct
_reent
*
r
,
const
char
*
name
,
int
mode
)
{
int
ret
=
-
1
;
PRINTF
(
"open '%s' mode %#x
\n
"
,
name
,
mode
);
int
ret
=
-
1
;
PRINTF
(
"open '%s' mode %#x
\n
"
,
name
,
mode
);
r
->
_errno
=
ENODEV
;
// no such device
r
->
_errno
=
ENODEV
;
// no such device
#ifdef MODULE_FAT
ret
=
ff_open_r
(
r
,
name
,
mode
);
ret
=
ff_open_r
(
r
,
name
,
mode
);
#endif
PRINTF
(
"open [%i] errno %i
\n
"
,
ret
,
r
->
_errno
);
return
ret
;
PRINTF
(
"open [%i] errno %i
\n
"
,
ret
,
r
->
_errno
);
return
ret
;
}
/*---------------------------------------------------------------------------*/
int
_stat_r
(
struct
_reent
*
r
,
char
*
name
,
struct
stat
*
st
)
{
int
ret
=
-
1
;
PRINTF
(
"_stat_r '%s'
\n
"
,
name
);
r
->
_errno
=
ENODEV
;
// no such device
int
ret
=
-
1
;
PRINTF
(
"_stat_r '%s'
\n
"
,
name
);
r
->
_errno
=
ENODEV
;
// no such device
#ifdef MODULE_FAT
ret
=
ff_stat_r
(
r
,
name
,
st
);
ret
=
ff_stat_r
(
r
,
name
,
st
);
#endif
PRINTF
(
"_stat_r [%i] errno %i
\n
"
,
ret
,
r
->
_errno
);
return
ret
;
PRINTF
(
"_stat_r [%i] errno %i
\n
"
,
ret
,
r
->
_errno
);
return
ret
;
}
/*---------------------------------------------------------------------------*/
int
_fstat_r
(
struct
_reent
*
r
,
int
fd
,
struct
stat
*
st
)
{
int
ret
=
-
1
;
int
ret
=
-
1
;
r
->
_errno
=
0
;
memset
(
st
,
0
,
sizeof
(
*
st
));
if
(
fd
==
STDOUT_FILENO
||
fd
==
STDERR_FILENO
)
{
st
->
st_mode
=
S_IFCHR
;
ret
=
0
;
}
else
{
r
->
_errno
=
0
;
memset
(
st
,
0
,
sizeof
(
*
st
));
if
(
fd
==
STDOUT_FILENO
||
fd
==
STDERR_FILENO
)
{
st
->
st_mode
=
S_IFCHR
;
ret
=
0
;
}
else
{
#ifdef MODULE_FAT
PRINTF
(
"_fstat_r '%i'
\n
"
,
fd
);
PRINTF
(
"_fstat_r '%i'
\n
"
,
fd
);
ret
=
ff_fstat_r
(
r
,
fd
,
st
);
PRINTF
(
"_fstat_r [%i] errno %i
\n
"
,
ret
,
r
->
_errno
);
ret
=
ff_fstat_r
(
r
,
fd
,
st
);
PRINTF
(
"_fstat_r [%i] errno %i
\n
"
,
ret
,
r
->
_errno
);
#else
r
->
_errno
=
ENODEV
;
r
->
_errno
=
ENODEV
;
#endif
}
return
ret
;
}
return
ret
;
}
/*---------------------------------------------------------------------------*/
int
_write_r
(
struct
_reent
*
r
,
int
fd
,
const
void
*
data
,
unsigned
int
count
)
{
int
result
=
EOF
;
r
->
_errno
=
EBADF
;
switch
(
fd
)
{
case
STDOUT_FILENO
:
case
STDERR_FILENO
:
#if FEUERWARE_CONF_ENABLE_HAL
if
(
stdio
!=
NULL
)
result
=
chardevice_write
(
stdio
,
(
char
*
)
data
,
count
);
else
if
(
hal_state
==
HAL_NOT_INITIALIZED
)
result
=
fw_puts
((
char
*
)
data
,
count
);
#else
result
=
fw_puts
((
char
*
)
data
,
count
);
#endif
break
;
default:
#ifdef MODULE_FAT
result
=
ff_write_r
(
r
,
fd
,
data
,
count
);
#endif
PRINTF
(
"write [%i] data @%p count %i
\n
"
,
fd
,
data
,
count
);
PRINTF
(
"write [%i] returned %i errno %i
\n
"
,
fd
,
result
,
r
->
_errno
);
break
;
}
return
result
;
int
result
=
EOF
;
r
->
_errno
=
EBADF
;
switch
(
fd
)
{
case
STDOUT_FILENO
:
case
STDERR_FILENO
:
#if FEUERWARE_CONF_ENABLE_HAL
if
(
stdio
!=
NULL
)
result
=
chardevice_write
(
stdio
,
(
char
*
)
data
,
count
);
else
if
(
hal_state
==
HAL_NOT_INITIALIZED
)
result
=
fw_puts
((
char
*
)
data
,
count
);
#else
result
=
fw_puts
((
char
*
)
data
,
count
);
#endif
break
;
default:
#ifdef MODULE_FAT
result
=
ff_write_r
(
r
,
fd
,
data
,
count
);
#endif
PRINTF
(
"write [%i] data @%p count %i
\n
"
,
fd
,
data
,
count
);
PRINTF
(
"write [%i] returned %i errno %i
\n
"
,
fd
,
result
,
r
->
_errno
);
break
;
}
return
result
;
}
/*---------------------------------------------------------------------------*/
int
_read_r
(
struct
_reent
*
r
,
int
fd
,
void
*
buffer
,
unsigned
int
count
)
{
int
result
=
-
1
;
r
->
_errno
=
EBADF
;
int
result
=
-
1
;
r
->
_errno
=
EBADF
;
#ifdef MODULE_FAT
result
=
ff_read_r
(
r
,
fd
,
buffer
,
count
);
result
=
ff_read_r
(
r
,
fd
,
buffer
,
count
);
#endif
PRINTF
(
"read [%i] buffer @%p count %i
\n
"
,
fd
,
buffer
,
count
);
PRINTF
(
"read [%i] returned %i
\n
"
,
fd
,
result
);
PRINTF
(
"read [%i] returned %i
\n
"
,
fd
,
result
);
return
result
;
}
/*---------------------------------------------------------------------------*/
int
_close_r
(
struct
_reent
*
r
,
int
fd
)
{
int
result
=
-
1
;
r
->
_errno
=
EBADF
;
#ifdef MODULE_FAT
ret
=
ff_close_r
(
r
,
fd
);
#endif
int
result
=
-
1
;
r
->
_errno
=
EBADF
;
#ifdef MODULE_FAT
ret
=
ff_close_r
(
r
,
fd
);
#endif
PRINTF
(
"close [%i]
\n
"
,
fd
);
PRINTF
(
"close returned %i errno %i
\n
"
,
result
,
errno
);
PRINTF
(
"close returned %i errno %i
\n
"
,
result
,
errno
);
return
result
;
}
/*---------------------------------------------------------------------------*/
int
_unlink_r
(
struct
_reent
*
r
,
char
*
path
)
{
int
result
=
-
1
;
r
->
_errno
=
ENODEV
;
int
result
=
-
1
;
r
->
_errno
=
ENODEV
;
#ifdef MODULE_FAT
result
=
ff_unlink_r
(
r
,
path
);
result
=
ff_unlink_r
(
r
,
path
);
#endif
PRINTF
(
"unlink '%s'
\n
"
,
path
);
PRINTF
(
"unlink returned %i errno %i
\n
"
,
result
,
errno
);
PRINTF
(
"unlink returned %i errno %i
\n
"
,
result
,
errno
);
return
result
;
}
/*---------------------------------------------------------------------------*/
void
_exit
(
int
n
)
{
#ifdef MODULE_TRACELOG
trace_number
(
TRACELOG_EV_EXIT
,
n
);
trace_number
(
TRACELOG_EV_EXIT
,
n
);
#endif
printf
(
"#! exit %i: resetting
\n
"
,
n
);
printf
(
"#! exit %i: resetting
\n
"
,
n
);
stdio_flush
();
arm_reset
();
while
(
1
);
stdio_flush
();
arm_reset
();
while
(
1
);
}
/*---------------------------------------------------------------------------*/
int
_getpid
(
void
)
{
return
active_thread
->
pid
;
return
active_thread
->
pid
;
}
/*---------------------------------------------------------------------------*/
int
_kill_r
(
struct
_reent
*
r
,
int
pid
,
int
sig
)
{
/* not implemented */
r
->
_errno
=
ESRCH
;
// no such process
return
-
1
;
/* not implemented */
r
->
_errno
=
ESRCH
;
// no such process
return
-
1
;
}
/*---------------------------------------------------------------------------*/
void
_init
(
void
){}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment