diff --git a/cpu/src/kernel/service/svc_dsp.c b/cpu/src/kernel/service/svc_dsp.c index 43c65141..7bad7f3c 100644 --- a/cpu/src/kernel/service/svc_dsp.c +++ b/cpu/src/kernel/service/svc_dsp.c @@ -53,6 +53,7 @@ under the terms of the GNU Affero General Public License as published by /*----- Macros -------------------------------------------------------*/ #define MSG_START 0xf0 +#define SYSTEM_PROFILE_PAYLOAD_LENGTH 12 /*----- Typedefs -----------------------------------------------------*/ @@ -88,7 +89,7 @@ typedef void (*t_module_param_value_callback)(uint16_t module_id, typedef void (*t_system_port_state_callback)(uint16_t port_f, uint16_t port_g, uint16_t port_h); -typedef void (*t_system_profile_callback)(uint32_t period, uint32_t cycles); +typedef void (*t_system_profile_callback)(uint32_t period, uint64_t cycles); static t_module_param_value_callback p_module_param_value_callback; static t_system_port_state_callback p_system_port_state_callback; @@ -541,13 +542,23 @@ static t_status _handle_system_port_state(uint8_t *payload, uint8_t length) { static t_status _handle_system_profile(uint8_t *payload, uint8_t length) { - if (p_system_profile_callback != NULL) { + if (length < SYSTEM_PROFILE_PAYLOAD_LENGTH) { + return ERROR; + } - uint32_t period = (payload[3] << 24 | payload[2] << 16 | - payload[1] << 8 | payload[0]); + if (p_system_profile_callback != NULL) { - uint32_t cycles = (payload[7] << 24 | payload[6] << 16 | - payload[5] << 8 | payload[4]); + uint32_t period = (uint32_t)payload[3] << 24 | + (uint32_t)payload[2] << 16 | + (uint32_t)payload[1] << 8 | payload[0]; + + uint64_t cycles = (uint64_t)payload[11] << 56 | + (uint64_t)payload[10] << 48 | + (uint64_t)payload[9] << 40 | + (uint64_t)payload[8] << 32 | + (uint64_t)payload[7] << 24 | + (uint64_t)payload[6] << 16 | + (uint64_t)payload[5] << 8 | payload[4]; p_system_profile_callback(period, cycles); } diff --git a/dsp/src/kernel/knl_profile.c b/dsp/src/kernel/knl_profile.c index da4f2a55..4375d290 100644 --- a/dsp/src/kernel/knl_profile.c +++ b/dsp/src/kernel/knl_profile.c @@ -61,7 +61,7 @@ t_profile knl_profile_stats(void) { static t_profile stats; stats.period = (uint32_t)sport0_period(); - stats.cycles = (uint32_t)g_module_cycles; + stats.cycles = g_module_cycles; return stats; } diff --git a/dsp/src/kernel/knl_profile.h b/dsp/src/kernel/knl_profile.h index c08f3b57..e59e1bba 100644 --- a/dsp/src/kernel/knl_profile.h +++ b/dsp/src/kernel/knl_profile.h @@ -59,7 +59,7 @@ extern "C" { typedef struct { uint32_t period; - uint32_t cycles; + uint64_t cycles; } t_profile; diff --git a/dsp/src/kernel/service/svc_cpu.c b/dsp/src/kernel/service/svc_cpu.c index 1b8118e1..0c04adc0 100644 --- a/dsp/src/kernel/service/svc_cpu.c +++ b/dsp/src/kernel/service/svc_cpu.c @@ -53,6 +53,7 @@ under the terms of the GNU Affero General Public License as published by /*----- Macros -------------------------------------------------------*/ #define MSG_START 0xf0 +#define SYSTEM_PROFILE_PAYLOAD_LENGTH 12 /*----- Typedefs -----------------------------------------------------*/ @@ -505,10 +506,12 @@ static t_status _respond_system_profile(t_profile stats) { (stats.period >> 16) & 0xff, (stats.period >> 24) & 0xff, stats.cycles & 0xff, (stats.cycles >> 8) & 0xff, (stats.cycles >> 16) & 0xff, (stats.cycles >> 24) & 0xff, + (stats.cycles >> 32) & 0xff, (stats.cycles >> 40) & 0xff, + (stats.cycles >> 48) & 0xff, (stats.cycles >> 56) & 0xff, }; _transmit_message(MSG_TYPE_SYSTEM, SYSTEM_PROFILE, payload, - sizeof(payload)); + SYSTEM_PROFILE_PAYLOAD_LENGTH); return SUCCESS; }