Initial compiling Zephyr integration
This commit is contained in:
+13
-11
@@ -14,17 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#include "adc_dma.h"
|
||||
|
||||
#include <math.h> // log for thermistor calculation
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __MBED__
|
||||
#include "mbed.h"
|
||||
#endif
|
||||
|
||||
#include "mcu.h"
|
||||
#include "main.h"
|
||||
#include "debug.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include "adc_dma.h"
|
||||
#include "pcb.h" // contains defines for pins
|
||||
#include <math.h> // log for thermistor calculation
|
||||
|
||||
// factory calibration values for internal voltage reference and temperature sensor
|
||||
// (see MCU datasheet, not RM)
|
||||
@@ -51,7 +53,7 @@
|
||||
#define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point
|
||||
#endif
|
||||
|
||||
#ifdef PIN_REF_I_DCDC
|
||||
#if defined(__MBED__) && defined(PIN_REF_I_DCDC)
|
||||
AnalogOut ref_i_dcdc(PIN_REF_I_DCDC);
|
||||
#endif
|
||||
|
||||
@@ -60,10 +62,10 @@ static float solar_current_offset;
|
||||
static float load_current_offset;
|
||||
|
||||
// for ADC and DMA
|
||||
static volatile uint16_t adc_readings[NUM_ADC_CH] = {0};
|
||||
static volatile uint32_t adc_filtered[NUM_ADC_CH] = {0};
|
||||
static volatile AdcAlert adc_alerts_upper[NUM_ADC_CH] = {0};
|
||||
static volatile AdcAlert adc_alerts_lower[NUM_ADC_CH] = {0};
|
||||
static volatile uint16_t adc_readings[NUM_ADC_CH] = {};
|
||||
static volatile uint32_t adc_filtered[NUM_ADC_CH] = {};
|
||||
static volatile AdcAlert adc_alerts_upper[NUM_ADC_CH] = {};
|
||||
static volatile AdcAlert adc_alerts_lower[NUM_ADC_CH] = {};
|
||||
|
||||
extern DeviceStatus dev_stat;
|
||||
|
||||
@@ -321,7 +323,7 @@ void adc_set_lv_alerts(float upper, float lower)
|
||||
adc_alerts_lower[ADC_POS_V_BAT].callback = low_voltage_alert;
|
||||
}
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#if defined(__MBED__) && !defined(UNIT_TEST)
|
||||
|
||||
void dma_setup()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifndef UNIT_TEST
|
||||
#if defined(__MBED__) && !defined(UNIT_TEST)
|
||||
|
||||
#include "mbed.h"
|
||||
#ifdef STM32F0 // STM32L0 does not have CAN
|
||||
|
||||
@@ -192,7 +192,7 @@ const data_object_t data_objects[] = {
|
||||
#endif
|
||||
|
||||
// FUNCTION CALLS (EXEC) //////////////////////////////////////////////////
|
||||
#ifndef UNIT_TEST
|
||||
#if defined(__MBED__) && !defined(UNIT_TEST)
|
||||
{0xE0, TS_EXEC, TS_EXEC_ALL, TS_T_BOOL, 0, (void*) &NVIC_SystemReset, "Reset"},
|
||||
#endif
|
||||
{0xE1, TS_EXEC, TS_EXEC_ALL, TS_T_BOOL, 0, (void*) &start_stm32_bootloader, "BootloaderSTM"},
|
||||
|
||||
+14
-5
@@ -14,11 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "eeprom.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mcu.h"
|
||||
#include "pcb.h"
|
||||
#include "thingset.h"
|
||||
#include "eeprom.h"
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
// versioning of EEPROM layout (2 bytes)
|
||||
// change the version number each time the data object array below is changed!
|
||||
@@ -154,7 +157,7 @@ int eeprom_read (unsigned int addr, uint8_t* ret, int len)
|
||||
return i2c_eeprom.read(device, (char*)ret, len);
|
||||
}
|
||||
|
||||
#elif defined(STM32L0) // internal EEPROM
|
||||
#elif defined(STM32L0) && defined(__MBED__) // internal EEPROM
|
||||
|
||||
int eeprom_write (unsigned int addr, const uint8_t* data, int len)
|
||||
{
|
||||
@@ -200,6 +203,12 @@ int eeprom_read (unsigned int addr, uint8_t* ret, int len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// ToDo for Zephyr
|
||||
int eeprom_write (unsigned int addr, const uint8_t* data, int len) { return 1; }
|
||||
int eeprom_read (unsigned int addr, uint8_t* ret, int len) { return 1; }
|
||||
|
||||
#endif // STM32L0
|
||||
|
||||
|
||||
@@ -216,7 +225,7 @@ void eeprom_restore_data()
|
||||
uint8_t buf_req[300]; // ThingSet request buffer
|
||||
|
||||
// EEPROM header
|
||||
uint8_t buf_header[EEPROM_HEADER_SIZE];
|
||||
uint8_t buf_header[EEPROM_HEADER_SIZE] = {}; // initialize to avoid compiler warning
|
||||
if (eeprom_read(0, buf_header, EEPROM_HEADER_SIZE) < 0) {
|
||||
printf("EEPROM: read error!\n");
|
||||
return;
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef EEPROM_H
|
||||
#define EEPROM_H
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @brief Handling of internal or external EEPROM to store device configuration
|
||||
|
||||
+7
-2
@@ -16,11 +16,11 @@
|
||||
|
||||
|
||||
#include "half_bridge.h"
|
||||
|
||||
#include "mcu.h"
|
||||
#include "pcb.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
|
||||
static int _pwm_resolution;
|
||||
static float _min_duty;
|
||||
static float _max_duty;
|
||||
@@ -57,8 +57,13 @@ class PWM_TIM3
|
||||
#endif
|
||||
|
||||
// Select AF2 on PB0 and PB1
|
||||
#ifdef __MBED__
|
||||
GPIOB->AFR[0] |= 0x2 << GPIO_AFRL_AFRL0_Pos;
|
||||
GPIOB->AFR[0] |= 0x2 << GPIO_AFRL_AFRL1_Pos;
|
||||
#else
|
||||
GPIOB->AFR[0] |= 0x2 << GPIO_AFRL_AFSEL0_Pos;
|
||||
GPIOB->AFR[0] |= 0x2 << GPIO_AFRL_AFSEL1_Pos;
|
||||
#endif
|
||||
|
||||
// No prescaler --> timer frequency == SystemClock
|
||||
TIM3->PSC = 0;
|
||||
|
||||
+6
-4
@@ -14,15 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#if defined(__MBED__)
|
||||
|
||||
#include "hardware.h"
|
||||
#include "pcb.h"
|
||||
#include "load.h"
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
#include "mcu.h"
|
||||
#include "pcb.h"
|
||||
#include "load.h"
|
||||
#include "half_bridge.h"
|
||||
#include "us_ticker_data.h"
|
||||
//#include "us_ticker_data.h"
|
||||
#include "leds.h"
|
||||
|
||||
extern LoadOutput load;
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ static int blink_state = 1; // global state of all blinking
|
||||
|
||||
static bool charging = false;
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#ifdef __MBED__
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
|
||||
+5
-4
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "load.h"
|
||||
|
||||
#include "pcb.h"
|
||||
#include "config.h"
|
||||
#include "hardware.h"
|
||||
@@ -145,7 +146,7 @@ void LoadOutput::switch_set(bool status)
|
||||
pgood = status;
|
||||
leds_set(LED_LOAD, status);
|
||||
|
||||
#ifdef PIN_LOAD_EN
|
||||
#if defined(__MBED__) && defined(PIN_LOAD_EN)
|
||||
DigitalOut load_enable(PIN_LOAD_EN);
|
||||
if (status == true) {
|
||||
load_enable = 1;
|
||||
@@ -155,7 +156,7 @@ void LoadOutput::switch_set(bool status)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PIN_LOAD_DIS
|
||||
#if defined(__MBED__) && defined(PIN_LOAD_DIS)
|
||||
DigitalOut load_disable(PIN_LOAD_DIS);
|
||||
if (status == true) {
|
||||
#ifdef PIN_I_LOAD_COMP
|
||||
@@ -175,12 +176,12 @@ void LoadOutput::usb_set(bool status)
|
||||
{
|
||||
usb_pgood = status;
|
||||
|
||||
#ifdef PIN_USB_PWR_EN
|
||||
#if defined(__MBED__) && defined(PIN_USB_PWR_EN)
|
||||
DigitalOut usb_pwr_en(PIN_USB_PWR_EN);
|
||||
if (status == true) usb_pwr_en = 1;
|
||||
else usb_pwr_en = 0;
|
||||
#endif
|
||||
#ifdef PIN_USB_PWR_DIS
|
||||
#if defined(__MBED__) && defined(PIN_USB_PWR_DIS)
|
||||
DigitalOut usb_pwr_dis(PIN_USB_PWR_DIS);
|
||||
if (status == true) usb_pwr_dis = 0;
|
||||
else usb_pwr_dis = 1;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#ifdef __MBED__
|
||||
|
||||
/** @file
|
||||
*
|
||||
@@ -217,4 +217,4 @@ void system_control()
|
||||
counter++;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // __MBED__
|
||||
@@ -0,0 +1,95 @@
|
||||
/* Libre Solar Battery Management System firmware
|
||||
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __ZEPHYR__
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "thingset.h" // handles access to internal data via communication interfaces
|
||||
#include "pcb.h" // hardware-specific settings
|
||||
#include "config.h" // user-specific configuration
|
||||
|
||||
#include "half_bridge.h" // PWM generation for DC/DC converter
|
||||
#include "hardware.h" // hardware-related functions like load switch, LED control, watchdog, etc.
|
||||
#include "dcdc.h" // DC/DC converter control (hardware independent)
|
||||
#include "pwm_switch.h" // PWM charge controller
|
||||
#include "bat_charger.h" // battery settings and charger state machine
|
||||
#include "adc_dma.h" // ADC using DMA and conversion to measurement values
|
||||
#include "uext.h" // communication interfaces, displays, etc. in UEXT connector
|
||||
#include "eeprom.h" // external I2C EEPROM
|
||||
#include "load.h" // load and USB output management
|
||||
#include "leds.h" // LED switching using charlieplexing
|
||||
#include "device_status.h" // log data (error memory, min/max measurements, etc.)
|
||||
#include "data_objects.h" // for access to internal data via ThingSet
|
||||
//#include "thingset_serial.h" // UART or USB serial communication
|
||||
#include "thingset_can.h" // CAN bus communication
|
||||
|
||||
PowerPort lv_terminal; // low voltage terminal (battery for typical MPPT)
|
||||
|
||||
#if FEATURE_DCDC_CONVERTER
|
||||
PowerPort hv_terminal; // high voltage terminal (solar for typical MPPT)
|
||||
PowerPort dcdc_lv_port; // internal low voltage side of DC/DC converter
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_INIT);
|
||||
#endif
|
||||
|
||||
#if FEATURE_PWM_SWITCH
|
||||
PowerPort pwm_terminal; // external terminal of PWM switch port (normally solar)
|
||||
PowerPort pwm_port_int; // internal side of PWM switch
|
||||
PwmSwitch pwm_switch(&pwm_terminal, &pwm_port_int);
|
||||
PowerPort &solar_terminal = pwm_terminal;
|
||||
#else
|
||||
PowerPort &solar_terminal = SOLAR_TERMINAL; // defined in config.h
|
||||
#endif
|
||||
|
||||
#if FEATURE_LOAD_OUTPUT
|
||||
PowerPort load_terminal; // load terminal (also connected to lv_bus)
|
||||
LoadOutput load(&load_terminal);
|
||||
#endif
|
||||
|
||||
PowerPort &bat_terminal = BATTERY_TERMINAL; // defined in config.h
|
||||
#ifdef GRID_TERMINAL
|
||||
PowerPort &grid_terminal = GRID_TERMINAL;
|
||||
#endif
|
||||
|
||||
Charger charger(&bat_terminal);
|
||||
|
||||
BatConf bat_conf; // actual (used) battery configuration
|
||||
BatConf bat_conf_user; // temporary storage where the user can write to
|
||||
|
||||
DeviceStatus dev_stat;
|
||||
|
||||
extern ThingSet ts; // defined in data_objects.cpp
|
||||
|
||||
time_t timestamp; // current unix timestamp (independent of time(NULL), as it is user-configurable)
|
||||
|
||||
void main(void)
|
||||
{
|
||||
printf("Booting Libre Solar Charge Controller: %s\n", CONFIG_BOARD);
|
||||
|
||||
while (1) {
|
||||
|
||||
k_sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
//K_THREAD_DEFINE(ts_serial_id, 4096, thingset_serial_thread, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
|
||||
|
||||
//K_THREAD_DEFINE(leds_id, 256, leds_update_thread, NULL, NULL, NULL, 4, 0, K_NO_WAIT);
|
||||
|
||||
//K_THREAD_DEFINE(uext_thread, 1024, uext_process_1s, NULL, NULL, NULL, 6, 0, K_NO_WAIT);
|
||||
|
||||
#endif // __ZEPHYR__
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
#ifndef MCU_H_
|
||||
#define MCU_H_
|
||||
|
||||
// mbed defines STM32Fxx variables automatically, so we define them also for Zephyr
|
||||
|
||||
#ifdef CONFIG_SOC_STM32L073XX
|
||||
#define STM32L0
|
||||
#define STM32L073
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SOC_STM32F072XX
|
||||
#define STM32F0
|
||||
#define STM32F072
|
||||
#endif
|
||||
|
||||
#ifdef STM32L073
|
||||
#include "stm32l073xx.h"
|
||||
#endif
|
||||
|
||||
#ifdef STM32F072
|
||||
#include "stm32f072xx.h"
|
||||
#endif
|
||||
|
||||
#endif // MCU_H_
|
||||
@@ -20,7 +20,9 @@
|
||||
#define DEVICE_TYPE "MPPT-1210-HUS"
|
||||
#define HARDWARE_VERSION "v0.4"
|
||||
|
||||
#ifdef __MBED__
|
||||
#include "mbed.h"
|
||||
#endif
|
||||
|
||||
// specify features of charge controller
|
||||
#define FEATURE_DCDC_CONVERTER 1
|
||||
@@ -66,6 +68,7 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT };
|
||||
#define LED_RXTX 3 // LED4, used to indicate when sending data
|
||||
#define LED_LOAD 4 // LED5
|
||||
|
||||
#ifdef __MBED__
|
||||
// LED pins and pin state configuration to switch above LEDs on
|
||||
#define NUM_LED_PINS 5
|
||||
static const PinName led_pins[NUM_LED_PINS] = {
|
||||
@@ -79,6 +82,7 @@ static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
|
||||
{ PIN_LOW, PIN_LOW, PIN_LOW, PIN_HIGH, PIN_LOW }, // LED4
|
||||
{ PIN_LOW, PIN_LOW, PIN_LOW, PIN_LOW, PIN_HIGH } // LED5
|
||||
};
|
||||
#endif // __MBED__
|
||||
|
||||
// pin definition only needed in adc_dma.cpp to detect if they are present on the PCB
|
||||
#define PIN_ADC_TEMP_FETS PA_5
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
#define DEVICE_TYPE "MPPT-1210-HUS"
|
||||
#define HARDWARE_VERSION "v0.7.1"
|
||||
|
||||
#ifdef __MBED__
|
||||
#include "mbed.h"
|
||||
#endif
|
||||
|
||||
// specify features of charge controller
|
||||
#define FEATURE_DCDC_CONVERTER 1
|
||||
@@ -75,6 +77,7 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT };
|
||||
#define LED_LOAD 3 // LED4
|
||||
#define LED_RXTX 4 // LED5, used to indicate when sending data
|
||||
|
||||
#ifdef __MBED__
|
||||
// LED pins and pin state configuration to switch above LEDs on
|
||||
#define NUM_LED_PINS 3
|
||||
static const PinName led_pins[NUM_LED_PINS] = {
|
||||
@@ -88,6 +91,7 @@ static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
|
||||
{ PIN_FLOAT, PIN_HIGH, PIN_LOW }, // LED4
|
||||
{ PIN_FLOAT, PIN_LOW, PIN_HIGH } // LED5
|
||||
};
|
||||
#endif // __MBED__
|
||||
|
||||
// pin definition only needed in adc_dma.cpp to detect if they are present on the PCB
|
||||
#define PIN_ADC_TEMP_BAT
|
||||
|
||||
@@ -16,11 +16,17 @@
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
#include "config.h"
|
||||
#include "mbed.h"
|
||||
#include "thingset.h"
|
||||
#include "thingset_interface.h"
|
||||
|
||||
#include <algorithm> // for for_each loop
|
||||
|
||||
#ifdef __MBED__
|
||||
#include "mbed.h"
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "thingset.h"
|
||||
|
||||
/*
|
||||
* Construct all global ThingSetInterfaces here.
|
||||
* All of these are added to the list of devices
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#ifdef __MBED__
|
||||
|
||||
#include "thingset_serial.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "mbed.h"
|
||||
#include "thingset.h"
|
||||
#include "thingset_serial.h"
|
||||
|
||||
char ThingSetStream::buf_resp[1000];
|
||||
|
||||
@@ -90,4 +90,4 @@ void ThingSetStream::process_input()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* UNIT_TEST */
|
||||
#endif /* __MBED__ */
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
#include "thingset_interface.h"
|
||||
|
||||
class ThingSetStream: public ThingSetInterface
|
||||
@@ -71,4 +72,5 @@ template<typename T> class ThingSetSerial: public ThingSetStream
|
||||
private:
|
||||
T& ser;
|
||||
};
|
||||
|
||||
#endif /* THINGSET_SERIAL_H */
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#ifdef __MBED__
|
||||
|
||||
#include "main.h"
|
||||
|
||||
@@ -187,4 +187,4 @@ void UExtOled::process_1s() {
|
||||
|
||||
#endif /* OLED_ENABLED */
|
||||
|
||||
#endif /* UNIT_TEST */
|
||||
#endif /* __MBED__ */
|
||||
|
||||
Reference in New Issue
Block a user