Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stm32_libraries
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
humanoides
tools
stm32_libraries
Commits
2a057f4d
Commit
2a057f4d
authored
7 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Added a new generic RAM module to handle accesses to the internal memory.
parent
beba5872
No related branches found
No related tags found
1 merge request
!6
Dynamixel manager
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
memory/include/ram.h
+34
-0
34 additions, 0 deletions
memory/include/ram.h
memory/src/ram.c
+110
-0
110 additions, 0 deletions
memory/src/ram.c
with
144 additions
and
0 deletions
memory/include/ram.h
0 → 100644
+
34
−
0
View file @
2a057f4d
#ifndef _RAM_H
#define _RAM_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include
"memory.h"
#define RAM_SUCCESS 0
#define RAM_BAD_ADDRESS -1
#define RAM_WRITE_ERROR -2
#define RAM_BAD_BIT -3
#define RAM_BAD_ACCESS -4
extern
unsigned
char
ram_data
[
RAM_SIZE
];
unsigned
char
ram_init
(
TMemory
*
memory
);
inline
void
ram_read_byte
(
unsigned
short
int
address
,
unsigned
char
*
data
);
inline
void
ram_read_word
(
unsigned
short
int
address
,
unsigned
short
int
*
data
);
unsigned
char
ram_read_table
(
unsigned
short
int
address
,
unsigned
short
int
length
,
unsigned
char
*
data
);
unsigned
char
ram_set_bit
(
unsigned
short
int
address
,
unsigned
char
bit
);
unsigned
char
ram_clear_bit
(
unsigned
short
int
address
,
unsigned
char
bit
);
unsigned
char
ram_write_byte
(
unsigned
short
int
address
,
unsigned
char
data
);
unsigned
char
ram_write_word
(
unsigned
short
int
address
,
unsigned
short
int
data
);
unsigned
char
ram_write_table
(
unsigned
short
int
address
,
unsigned
short
int
length
,
unsigned
char
*
data
);
inline
unsigned
char
ram_in_range
(
unsigned
short
int
reg
,
unsigned
short
int
address
,
unsigned
short
int
length
);
unsigned
char
ram_in_window
(
unsigned
short
int
start_reg
,
unsigned
short
int
reg_length
,
unsigned
short
int
start_address
,
unsigned
short
int
address_length
);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
Click to expand it.
memory/src/ram.c
0 → 100644
+
110
−
0
View file @
2a057f4d
#include
"ram.h"
unsigned
char
ram_data
[
RAM_SIZE
]
=
{
0
};
unsigned
char
ram_init
(
TMemory
*
memory
)
{
mem_initialize_data
(
memory
);
return
0x01
;
}
inline
void
ram_read_byte
(
unsigned
short
int
address
,
unsigned
char
*
data
)
{
(
*
data
)
=
ram_data
[
address
];
}
inline
void
ram_read_word
(
unsigned
short
int
address
,
unsigned
short
int
*
data
)
{
(
*
data
)
=
ram_data
[
address
];
(
*
data
)
+=
ram_data
[
address
+
1
]
*
256
;
}
unsigned
char
ram_read_table
(
unsigned
short
int
address
,
unsigned
short
int
length
,
unsigned
char
*
data
)
{
unsigned
short
int
i
;
if
((
address
+
length
)
<=
(
RAM_SIZE
-
1
))
{
for
(
i
=
0
;
i
<
length
;
i
++
)
data
[
i
]
=
ram_data
[
address
+
i
];
return
RAM_SUCCESS
;
}
else
return
RAM_BAD_ADDRESS
;
}
unsigned
char
ram_set_bit
(
unsigned
short
int
address
,
unsigned
char
bit
)
{
if
(
bit
>=
0
&&
bit
<
8
)
{
ram_data
[
address
]
|=
(
0x01
<<
bit
);
return
RAM_SUCCESS
;
}
else
return
RAM_BAD_BIT
;
}
unsigned
char
ram_clear_bit
(
unsigned
short
int
address
,
unsigned
char
bit
)
{
if
(
bit
>=
0
&&
bit
<
8
)
{
ram_data
[
address
]
&=
(
~
(
0x01
<<
bit
));
return
RAM_SUCCESS
;
}
else
return
RAM_BAD_BIT
;
}
unsigned
char
ram_write_byte
(
unsigned
short
int
address
,
unsigned
char
data
)
{
ram_data
[
address
]
=
data
;
return
RAM_SUCCESS
;
}
unsigned
char
ram_write_word
(
unsigned
short
int
address
,
unsigned
short
int
data
)
{
if
(
address
<
(
RAM_SIZE
-
1
))
{
ram_data
[
address
]
=
data
%
256
;
ram_data
[
address
+
1
]
=
data
/
256
;
return
RAM_SUCCESS
;
}
else
return
RAM_BAD_ADDRESS
;
}
unsigned
char
ram_write_table
(
unsigned
short
int
address
,
unsigned
short
int
length
,
unsigned
char
*
data
)
{
unsigned
short
int
i
;
if
((
address
+
length
)
<
RAM_SIZE
)
{
for
(
i
=
0
;
i
<
length
;
i
++
)
ram_data
[
address
+
i
]
=
data
[
i
];
return
RAM_SUCCESS
;
}
else
return
RAM_BAD_ADDRESS
;
}
inline
unsigned
char
ram_in_range
(
unsigned
short
int
reg
,
unsigned
short
int
address
,
unsigned
short
int
length
)
{
if
(
reg
>=
address
&&
reg
<
(
address
+
length
))
return
0x01
;
else
return
0x00
;
}
unsigned
char
ram_in_window
(
unsigned
short
int
start_reg
,
unsigned
short
int
reg_length
,
unsigned
short
int
start_address
,
unsigned
short
int
address_length
)
{
unsigned
short
int
end_reg
=
start_reg
+
reg_length
-
1
;
unsigned
short
int
end_address
=
start_address
+
address_length
-
1
;
if
((
start_reg
>=
start_address
&&
start_reg
<=
end_address
)
||
(
end_reg
>=
start_address
&&
end_reg
<=
end_address
))
return
0x01
;
else
return
0x00
;
}
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