Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
François Revol
firmware
Commits
a44bc26e
Commit
a44bc26e
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
fix(bsec): Reduce stack usage by calling init before stating the task
parent
48773132
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
epicardium/main.c
+11
-9
11 additions, 9 deletions
epicardium/main.c
epicardium/modules/bsec.c
+50
-28
50 additions, 28 deletions
epicardium/modules/bsec.c
epicardium/modules/modules.h
+1
-0
1 addition, 0 deletions
epicardium/modules/modules.h
with
62 additions
and
37 deletions
epicardium/main.c
+
11
−
9
View file @
a44bc26e
...
...
@@ -126,15 +126,17 @@ int main(void)
}
/* BSEC */
if
(
xTaskCreate
(
vBSECTask
,
(
const
char
*
)
"BSEC"
,
configMINIMAL_STACK_SIZE
*
4
,
NULL
,
tskIDLE_PRIORITY
+
1
,
NULL
)
!=
pdPASS
)
{
LOG_CRIT
(
"startup"
,
"Failed to create %s task!"
,
"BSEC"
);
abort
();
if
(
bsec_activate
()
==
0
)
{
if
(
xTaskCreate
(
vBSECTask
,
(
const
char
*
)
"BSEC"
,
configMINIMAL_STACK_SIZE
*
3
,
/* 768 bytes. Mainly for state saving... */
NULL
,
tskIDLE_PRIORITY
+
1
,
NULL
)
!=
pdPASS
)
{
LOG_CRIT
(
"startup"
,
"Failed to create %s task!"
,
"BSEC"
);
abort
();
}
}
/* API */
...
...
This diff is collapsed.
Click to expand it.
epicardium/modules/bsec.c
+
50
−
28
View file @
a44bc26e
...
...
@@ -20,7 +20,7 @@
TaskHandle_t
bsec_task_id
;
static
struct
bme680_sensor_data
last_bme680_data
;
static
int64_t
last_bme680_timestamp
;
static
bool
active
;
static
bool
bsec_task_
active
;
#define ULP 0
// From generic_18v_3s_4d/bsec_serialized_configurations_iaq.c
...
...
@@ -227,6 +227,17 @@ static int8_t i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
return
ret
;
}
static
void
delay
(
uint32_t
msec
)
{
if
(
xTaskGetSchedulerState
()
==
taskSCHEDULER_NOT_STARTED
)
{
/* We need to fall back to hardware waits if not running
* in a task context */
card10_bosch_delay
(
msec
);
}
else
{
vTaskDelay
(
pdMS_TO_TICKS
(
msec
));
}
}
/*!
* @brief Load library config from non-volatile memory
*
...
...
@@ -280,19 +291,14 @@ void ulp_plus_trigger_iaq()
}
#endif
static
void
delay
(
uint32_t
msec
)
{
vTaskDelay
(
pdMS_TO_TICKS
(
msec
));
}
bool
bsec_active
(
void
)
{
return
active
;
return
bsec_task_
active
;
}
int
bsec_read_bme680
(
struct
bme680_sensor_data
*
data
)
{
if
(
!
active
)
{
if
(
!
bsec_task_
active
)
{
return
BME680_E_COM_FAIL
;
}
while
(
last_bme680_timestamp
==
0
)
...
...
@@ -301,46 +307,62 @@ int bsec_read_bme680(struct bme680_sensor_data *data)
return
BME680_OK
;
}
void
vBSECTask
(
void
*
pvParameters
)
/**
* Checks config and activates the BSEC libary if requested.
*
* Initializes the BSEC library before starting the task to
* reduce the stack size needed for the task by at least 512 bytes
*/
int
bsec_activate
(
void
)
{
return_values_init
ret
;
active
=
true
;
bsec_task_id
=
xTaskGetCurrentTaskHandle
();
#if ULP
float
sample_rate
=
BSEC_SAMPLE_RATE_ULP
;
/* State is saved every 100 samples, which means every 100 * 300 secs = 500 minutes */
const
int
stat_save_interval
=
100
;
#else
float
sample_rate
=
BSEC_SAMPLE_RATE_LP
;
/* State is saved every 10.000 samples, which means every 10.000 * 3 secs = 500 minutes */
const
int
stat_save_interval
=
10000
;
#endif
float
temperature_offset
=
0
.
0
;
ret
=
bsec_iot_init
(
sample_rate
,
temperature_offset
,
i2c_write
,
i2c_read
,
delay
,
state_load
,
config_load
/* Puts AT LEAST 2 * #BSEC_MAX_PROPERTY_BLOB_SIZE = 2 * 454 = 908 bytes onto the stack */
ret
=
bsec_iot_init
(
sample_rate
,
temperature_offset
,
i2c_write
,
i2c_read
,
delay
,
state_load
,
config_load
);
if
(
ret
.
bme680_status
)
{
printf
(
"bme680 init failed
\n
"
);
/* Could not intialize BME680 */
while
(
1
)
;
return
-
1
;
}
else
if
(
ret
.
bsec_status
)
{
printf
(
"bsec init failed
\n
"
);
/* Could not intialize BSEC library */
while
(
1
)
;
return
-
1
;
}
return
0
;
}
void
vBSECTask
(
void
*
pvParameters
)
{
bsec_task_active
=
true
;
bsec_task_id
=
xTaskGetCurrentTaskHandle
();
#if ULP
/* State is saved every 100 samples, which means every 100 * 300 secs = 500 minutes */
const
int
stat_save_interval
=
100
;
#else
/* State is saved every 10.000 samples, which means every 10.000 * 3 secs = 500 minutes */
const
int
stat_save_interval
=
10000
;
#endif
/* Call to endless loop function which reads and processes data based on sensor settings */
/* Puts AT LEAST 2 * BSEC_MAX_STATE_BLOB_SIZE + 8 * sizeof(bsec_input_t) =
* 2 * 139 + 8 * 20 = 438 bytes onto the stack */
bsec_iot_loop
(
delay
,
get_timestamp_us
,
...
...
This diff is collapsed.
Click to expand it.
epicardium/modules/modules.h
+
1
−
0
View file @
a44bc26e
...
...
@@ -137,6 +137,7 @@ void max30001_mutex_init(void);
extern
gpio_cfg_t
gpio_configs
[];
/* ---------- BSEC / BME680 ------------------------------------------------ */
int
bsec_activate
(
void
);
void
vBSECTask
(
void
*
pvParameters
);
bool
bsec_active
(
void
);
struct
bme680_sensor_data
;
...
...
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