-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[log timing] add time logs for tasks.
(cherry picked from commit 72b51e6)
- Loading branch information
Mikaël BRIDAY
authored and
Siméon Marijon
committed
May 1, 2020
1 parent
45132e9
commit f143099
Showing
12 changed files
with
227 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#ifndef LOG_TIMING_H | ||
#define LOG_TIMING_H | ||
|
||
/* The purpose of log timing is to measure: | ||
* - time of each interrupt/task (=proc) | ||
* - periodicity of procs | ||
* It is useful during dev only, as it consums a few resources | ||
* | ||
* Hardware required: TIM6 | ||
* serial output : uart2 | ||
* | ||
* in 'native mode', no behavior | ||
*/ | ||
|
||
/* if the following line is commented, there is no log | ||
* i.e, #define are expanded in nothing | ||
*/ | ||
#define LOG_TIME | ||
|
||
/* number of entries. 3 bytes per entry */ | ||
#define LOG_TIME_SIZE 1024 | ||
|
||
#define LOG_TIME_NB_TASKS 4 | ||
|
||
/* use msb of the id for start/stop */ | ||
#define LOG_TIME_EVENT_START 0x80 | ||
#define LOG_TIME_EVENT_STOP 0x00 | ||
|
||
/* id. 7 bits allowed */ | ||
#define LOG_TIME_TASK_BREATHING 0x0 | ||
#define LOG_TIME_TASK_MONITORING 0x1 | ||
#define LOG_TIME_TASK_CONTROLLER 0x2 | ||
#define LOG_TIME_TASK_HMI 0x3 | ||
|
||
#ifdef LOG_TIME | ||
#include <FreeRTOS.h> | ||
#include <task.h> /*we need TaskHandle_t */ | ||
|
||
#ifdef native | ||
void log_time_initHw() {} | ||
void log_time_start() {} | ||
void log_time_event(int id) {UNUSED(id);} | ||
void log_time_dump() {} | ||
int log_time_full() {return 0;} | ||
|
||
void log_time_init_task(const char *name, int id) {UNUSED(name); UNUSED(id) ;} | ||
void log_time_event_task(TaskHandle_t t,int start) {UNUSED(t) ; UNUSED(start);} | ||
#else /* stm32 target => implementation in lowlevel/stm32f303/log_timings.h */ | ||
void log_time_initHw(); | ||
void log_time_start(); | ||
void log_time_event(int id); | ||
void log_time_dump(); | ||
int log_time_full(); | ||
|
||
void log_time_init_task(const char *name, int id); | ||
void log_time_event_task(TaskHandle_t t,int start); | ||
#endif /* native */ | ||
|
||
/* should be called */ | ||
#define LOG_TIME_INIT_TIM6_HARDWARE() log_time_initHw(); | ||
#define LOG_TIME_START() log_time_start(); | ||
#define LOG_TIME_EVENT(id) log_time_event(id); | ||
#define LOG_TIME_DUMP() log_time_dump(); | ||
#define LOG_TIME_FULL() log_time_full() /* no ';' here */ | ||
|
||
#define LOG_TIME_INIT_TASK(name,id) log_time_init_task(name,id); | ||
#define LOG_TIME_EVENT_TASK(t,s) log_time_event_task(t,s); | ||
|
||
#else /* no log */ | ||
|
||
#define LOG_TIME_INIT_TIM6_HARDWARE() | ||
#define LOG_TIME_START() | ||
#define LOG_TIME_EVENT(id) | ||
#define LOG_TIME_DUMP() | ||
#define LOG_TIME_FULL() 0 | ||
|
||
#define LOG_TIME_INIT_TASK(name,id) | ||
#define LOG_TIME_EVENT_TASK(t,s) | ||
|
||
#endif /* LOG_TIME */ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include "stm32f3xx.h" | ||
#include "log_timings.h" | ||
#include "common.h" | ||
#include <string.h> /* strlen */ | ||
|
||
typedef struct | ||
{ | ||
uint8_t id; /* id: MSB=1 start, else end. 7 low bits = id. */ | ||
uint16_t date; /* date in us from TIM6. there are overflows */ | ||
} log_time_entry; | ||
|
||
/* save logs before sending externally (through uart..)*/ | ||
/* 3 bytes per entry */ | ||
volatile log_time_entry log_time_tab[LOG_TIME_SIZE]; | ||
volatile int log_time_current_size; /* current size */ | ||
|
||
|
||
void log_time_initHw(){ | ||
//start TIM6 | ||
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; | ||
__asm("nop"); | ||
RCC->APB1RSTR |= RCC_APB1RSTR_TIM6RST; | ||
RCC->APB1RSTR &= ~RCC_APB1RSTR_TIM6RST; | ||
__asm("nop"); | ||
|
||
//configure TIM6 | ||
TIM6->PSC = 72-1; //tick@1us | ||
TIM6->EGR = TIM_EGR_UG; //update event => load PSC | ||
TIM6->CR1 = TIM_CR1_CEN; //enable, all other fields to 0 | ||
|
||
log_time_current_size = 0; | ||
} | ||
|
||
void log_time_event(int id) | ||
{ | ||
__disable_irq(); | ||
const uint16_t date = TIM6->CNT; | ||
if(log_time_current_size < LOG_TIME_SIZE) { | ||
log_time_tab[log_time_current_size].id = id; | ||
log_time_tab[log_time_current_size].date = date; | ||
log_time_current_size++; | ||
} | ||
__enable_irq(); | ||
} | ||
|
||
void log_time_start() | ||
{ | ||
log_time_current_size = 0; | ||
} | ||
|
||
void log_time_dump() | ||
{ | ||
const int size = log_time_current_size; | ||
dbg_printf("dump log timings\r\n"); | ||
for(int i = 0;i<size;i++) | ||
{ | ||
char c; | ||
if(log_time_tab[i].id & LOG_TIME_EVENT_START) c = 's'; | ||
else c = 'e'; | ||
dbg_printf("%c\t%d\t%d\r\n",c,log_time_tab[i].id & 0x7F,log_time_tab[i].date); | ||
} | ||
} | ||
|
||
int log_time_full() | ||
{ | ||
return (log_time_current_size == LOG_TIME_SIZE); | ||
} | ||
|
||
/* store the task handle of tasks */ | ||
TaskHandle_t idToTaskHandle[4]; | ||
void log_time_init_task(const char *name, int id) | ||
{ | ||
TaskHandle_t handle = xTaskGetHandle(name); | ||
if(id < LOG_TIME_NB_TASKS) { | ||
idToTaskHandle[id] = handle; | ||
} | ||
} | ||
|
||
void log_time_event_task(TaskHandle_t t,int start) | ||
{ | ||
int i=0; | ||
int found = 0; | ||
while(i<LOG_TIME_NB_TASKS && !found) | ||
{ | ||
found = (t==idToTaskHandle[i]); | ||
if(!found) i++; | ||
} | ||
if(found) log_time_event(start | i); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.