Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unaligned access trickery #613

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
35f85cd
Found the right magic for correct direct unaligned access in GCC
dkfellows Jun 3, 2020
4348c66
Merge branch 'master' into unaligned-access-trickery
dkfellows Jun 11, 2020
421163f
Gradually reducing the mess in RIPMCS
dkfellows Jun 12, 2020
1e936b1
Merge branch 'master' into unaligned-access-trickery
dkfellows Jul 1, 2020
a0f4b28
Merge branch 'master' into unaligned-access-trickery
dkfellows Jul 16, 2020
f7e7b5e
Merge branch 'master' into unaligned-access-trickery
dkfellows Jul 21, 2020
982bf7c
Merge branch 'master' into unaligned-access-trickery
dkfellows Jul 22, 2020
6347f9d
Ignore
dkfellows Aug 27, 2020
79f4e08
Merge branch 'master' into unaligned-access-trickery
dkfellows Aug 27, 2020
0e9774e
More alignment trickery to tame EIEIO
dkfellows Aug 28, 2020
ad54f5d
Factor out a few bits where I'm not 100% sure I had it right
dkfellows Aug 28, 2020
6def597
All reading of potentially misaligned words routed via read_word()
dkfellows Aug 28, 2020
cbe166e
Merge branch 'master' into unaligned-access-trickery
dkfellows Sep 4, 2020
e37172f
Merge branch 'master' into unaligned-access-trickery
dkfellows Sep 7, 2020
00fbf62
Merge branch 'master' into unaligned-access-trickery
dkfellows Sep 11, 2020
3aed5f9
Merge branch 'master' into unaligned-access-trickery
dkfellows Sep 17, 2020
b1b7452
Merge branch 'master' into unaligned-access-trickery
dkfellows Sep 22, 2020
7f8e750
Merge branch 'master' into unaligned-access-trickery
dkfellows Sep 24, 2020
d355273
Merge branch 'master' into unaligned-access-trickery
dkfellows Oct 16, 2020
edf1c30
Merge branch 'master' into unaligned-access-trickery
dkfellows Oct 22, 2020
4a5ef5d
Merge branch 'master' into unaligned-access-trickery
dkfellows Nov 13, 2020
a5ac43d
Merge branch 'master' into unaligned-access-trickery
dkfellows Nov 17, 2020
1636e5e
Merge branch 'master' into unaligned-access-trickery
dkfellows Dec 10, 2020
0d1c7fc
Merge branch 'master' into unaligned-access-trickery
dkfellows Jan 4, 2021
1b6da60
Merge branch 'master' into unaligned-access-trickery
dkfellows Feb 12, 2021
111a369
Merge branch 'master' into unaligned-access-trickery
dkfellows Mar 2, 2021
ba0a2b4
Merge branch 'master' into unaligned-access-trickery
dkfellows Mar 11, 2021
2504a78
Tidy up a comment
dkfellows Mar 11, 2021
dd3cc5b
Merge branch 'master' into unaligned-access-trickery
dkfellows Mar 30, 2021
0dd7fb7
Merge branch 'master' into unaligned-access-trickery
dkfellows May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c_common/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ EXPAND_ONLY_PREDEF = YES
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = __attribute__(x)= PROFILER_ENABLED=YES INT_HANDLER=void UNUSED= ASSERT_WORD_SIZED(x)= DOXYGEN DOXYNAME(x)=x
PREDEFINED = __attribute__(x)= PROFILER_ENABLED=YES INT_HANDLER=void UNUSED= ASSERT_WORD_SIZED(x)= DOXYGEN DOXYNAME(x)=x __PACKED_STRUCT=
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES

Expand Down
7 changes: 5 additions & 2 deletions c_common/front_end_common_lib/include/buffered_eieio_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ typedef enum buffered_operations {
BUFFER_OPERATION_WRITE
} buffered_operations;

//! pointer to an EIEIO message
typedef uint16_t* eieio_msg_t;
//! Pointer to an EIEIO message
typedef const uint16_t *eieio_msg_t;

//! Pointer to a writable EIEIO message
typedef uint16_t *eieio_writable_msg_t;

//! The maximum sequence number
#define MAX_SEQUENCE_NO 0xFF
Expand Down
24 changes: 20 additions & 4 deletions c_common/front_end_common_lib/include/eieio.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,27 @@ union eieio_header_bitfields {
uint16_t count : 8;
// Padding
uint16_t : 2;
//! \brief The type of the packet (see eieio_data_message_types)
//! \brief The type of the packet (see ::eieio_data_message_types)
uint16_t packet_type : 2;
//! \brief Whether the payload is a timestamp
uint16_t payload_is_timestamp : 1;
//! \brief Whether to apply the current prefix to the payload
uint16_t apply_payload_prefix : 1;
//! \brief Whether the prefix is applied to the upper or lower half of the
//! payload.
//! \brief Whether the prefix is applied to the upper or lower half of
//! the payload.
uint16_t prefix_upper : 1;
//! \brief Whether to apply the prefix
uint16_t apply_prefix : 1;
};
//! The bits in the packet type
struct {
uint16_t : 10;
//! Whether the packet has a payload.
uint16_t packet_has_payload : 1;
//! Whether the packet contains 32-bit values (or 16-bit if false).
uint16_t packet_is_32bit : 1;
uint16_t : 4;
};
struct {
//! \brief What command is encoded in the packet.
uint16_t packet_command : 14;
Expand All @@ -99,7 +108,7 @@ typedef enum {
//! Message is just a key, 32 bits long
KEY_32_BIT,
//! Message is a key and a payload, each 32 bits long
KEY_PAYLOAD_32_bIT
KEY_PAYLOAD_32_BIT
} eieio_data_message_types;

//! The EIEIO prefix types
Expand All @@ -108,4 +117,11 @@ typedef enum {
PREFIX_TYPE_UPPER_HALF_WORD
} eieio_prefix_types;

//! Special packet classes
enum {
//! \brief The packet is a command.
//! \details This is an illegal combination of bits for a data packet.
PACKET_CLASS_COMMAND = 1
};

#endif //INCLUDE_FEC_EIEIO_H
21 changes: 10 additions & 11 deletions c_common/front_end_common_lib/include/recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,22 @@
typedef uint8_t channel_index_t;

//! \brief records some data into a specific recording channel.
//! \param[in] channel the channel to store the data into.
//! \param[in] data the data to store into the channel.
//! \param[in] size_bytes the number of bytes that this data will take up.
//! \param[in] channel: the channel to store the data into.
//! \param[in] data: the data to store into the channel.
//! \param[in] size_bytes: the number of bytes that this data will take up.
//! This may be any number of bytes, not just whole words.
//! \return boolean which is True if the data has been stored in the channel,
//! \return True if the data has been stored in the channel,
//! False otherwise.
bool recording_record(channel_index_t channel, void *data, size_t size_bytes);
bool recording_record(channel_index_t channel, const void *data, size_t size_bytes);

//! \brief Finishes recording - should only be called if recording_flags is
//! not 0
//! \brief Finishes recording.
//! \details should only be called if recording_flags is not 0
void recording_finalise(void);

//! \brief initialises the recording of data
//! \param[in,out] recording_data_address The start of the data about the
//! recording, updated to point to just
//! after the data if return True.
//! Data is:
//! \param[in,out] recording_data_address:
//! The start of the data about the recording, updated to point to just
//! after the data if return True. Data is:
//! ```
//! {
//! // number of potential recording regions
Expand Down
13 changes: 5 additions & 8 deletions c_common/front_end_common_lib/src/recording.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static inline void copy_data(
}
}

bool recording_record(uint8_t channel, void *data, uint32_t size_bytes) {
bool recording_record(uint8_t channel, const void *data, uint32_t size_bytes) {
recording_channel_t *rec = &channels[channel];
if (has_been_initialised(rec)) {

Expand All @@ -127,10 +127,9 @@ bool recording_record(uint8_t channel, void *data, uint32_t size_bytes) {
return false;
}

__attribute__((noreturn)) void recording_bad_offset(
void *data, uint32_t size) {
log_error("DMA transfer of non-word data quantity in recording! "
"(data=0x%08x, size=0x%x)", data, size);
NORETURN void recording_bad_offset(const void *data, uint32_t size) {
log_error("DMA transfer of non-word data quantity in recording! (data=0x%08x, size=0x%x)",
data, size);
rt_error(RTE_SWERR);
}

Expand Down Expand Up @@ -177,9 +176,7 @@ bool recording_initialize(
*recording_flags = 0;
}

/* Reserve the actual recording regions.
*
*/
// Reserve the actual recording regions.
for (uint32_t i = 0; i < n_regions; i++) {
recording_region_t *region = &regions->regions[i];
uint32_t space = region->space;
Expand Down
14 changes: 6 additions & 8 deletions c_common/models/live_packet_gather/src/live_packet_gather.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,18 @@ static struct lpg_config config;
//! _Only guaranteed to be half-word aligned._
//! \param[in] index: Offset in count of _words_ into the buffer.
//! \param[in] value: Value to write in (as little-endian).
static inline void write_word(void *base, uint32_t index, uint32_t value) {
uint16_t *ary = base;
uint32_t idx = index * 2;
ary[idx++] = CLAMP16(value);
ary[idx] = CLAMP16(value >> 16);
static inline void write_word(uint16_t *base, uint32_t index, uint32_t value) {
uint32_t *ary = __builtin_assume_aligned(base, 4, 2);
ary[index] = value;
}

//! \brief Simple mirror of write_word() for true 16 bit values.
//! \param[in] base: place to write to
//! \param[in] index: location in base to write to
//! \param[in] value: the value to write to the base.
static inline void write_short(void *base, uint32_t index, uint32_t value) {
uint16_t *ary = base;
ary[index] = CLAMP16(value);
static inline void write_short(
uint16_t *base, uint32_t index, uint32_t value) {
base[index] = CLAMP16(value);
}

//! \brief Get how many events there are waiting to be sent
Expand Down
Loading