forked from fedetft/miosix-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (67 loc) · 2.36 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//default baudrate 19200
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#include <cstdio>
#include <iostream>
#include <kernel/kernel.h>
#include "miosix.h"
#include "Lps22hb.h"
#include "SyncQueue.h"
#include "NeuralNetwork.h"
#include "util/util.h"
using namespace std;
using namespace miosix;
//pressure sensor address
const unsigned char lps22hb_addr = 0xBA;
// TO BE CHECKED BEFORE EACH COMPILATION
// altitude of the sensor (in meters), used to compute the sea-level atm pressure
const unsigned int sensor_altitude = 130;
void initRCC(){
//enable RCC pheripherals
FastInterruptDisableLock a;
RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
CRC->CR = CRC_CR_RESET;
}
typedef Gpio<GPIOB_BASE,9> sda;
typedef Gpio<GPIOB_BASE,8> scl;
Lps22hb<sda,scl,lps22hb_addr> pressure_sensor(sensor_altitude);
SyncQueue<float> in_queue;
int main()
{
MemoryProfiling::print();
initRCC();
//initialize the sensor via I2C
pressure_sensor.init();
//it starts the neural network which is an active object
NeuralNetwork nn(in_queue, pressure_sensor.getODR());
for(;;)
{
//This call block the main thread until PB10 pass from 0 to 1.
//When it happens it means that the fifo is full and it can be read
pressure_sensor.waitForFullFifo();
//This function read the 32 slots of the fifo, calculate the avg and
//return the value reshaped considering the altitude of the measure
float pressure_val = pressure_sensor.getLast32AvgPressure();
printf("Pressure reading: %f \n", pressure_val);
in_queue.put(pressure_val);
MemoryProfiling::print();
}
}