./workspace/TS100 -> ./source/
This commit is contained in:
34
source/Core/Src/FreeRTOSHooks.c
Normal file
34
source/Core/Src/FreeRTOSHooks.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* FreeRTOSHooks.c
|
||||
*
|
||||
* Created on: 29 May 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "FreeRTOSHooks.h"
|
||||
#include "BSP.h"
|
||||
void vApplicationIdleHook(void) {
|
||||
resetWatchdog();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
|
||||
static StaticTask_t xIdleTaskTCBBuffer;
|
||||
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
||||
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
||||
StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
||||
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
/* place for user code */
|
||||
}
|
||||
|
||||
|
||||
void vApplicationStackOverflowHook(TaskHandle_t *pxTask,
|
||||
signed portCHAR *pcTaskName) {
|
||||
(void) pxTask;
|
||||
(void) pcTaskName;
|
||||
|
||||
// We dont have a good way to handle a stack overflow at this point in time
|
||||
reboot();
|
||||
}
|
||||
183
source/Core/Src/QC3.cpp
Normal file
183
source/Core/Src/QC3.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* QC3.c
|
||||
*
|
||||
* Created on: 29 May 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
// Quick charge 3.0 supporting functions
|
||||
#include "QC3.h"
|
||||
|
||||
#include "BSP.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "stdint.h"
|
||||
enum QCState {
|
||||
NOT_STARTED = 0, // Have not checked
|
||||
QC_3 = 1,
|
||||
QC_2 = 2,
|
||||
NO_QC = 3,
|
||||
|
||||
};
|
||||
void QC_Seek9V() {
|
||||
QC_DNegZero_Six();
|
||||
QC_DPlusThree_Three();
|
||||
}
|
||||
void QC_Seek12V() {
|
||||
QC_DNegZero_Six();
|
||||
QC_DPlusZero_Six();
|
||||
}
|
||||
void QC_Seek20V() {
|
||||
QC_DNegThree_Three();
|
||||
QC_DPlusThree_Three();
|
||||
}
|
||||
void QC_SeekContMode() {
|
||||
QC_DNegThree_Three();
|
||||
QC_DPlusZero_Six();
|
||||
}
|
||||
void QC_SeekContPlus() {
|
||||
QC_SeekContMode();
|
||||
osDelay(30);
|
||||
QC_Seek20V();
|
||||
osDelay(10);
|
||||
QC_SeekContMode();
|
||||
}
|
||||
void QC_SeekContNeg() {
|
||||
QC_SeekContMode();
|
||||
osDelay(30);
|
||||
QC_Seek12V();
|
||||
osDelay(10);
|
||||
QC_SeekContMode();
|
||||
}
|
||||
QCState QCMode = QCState::NOT_STARTED;
|
||||
uint8_t QCTries = 0;
|
||||
void seekQC(int16_t Vx10, uint16_t divisor) {
|
||||
if (QCMode == QCState::NOT_STARTED)
|
||||
startQC(divisor);
|
||||
|
||||
if (Vx10 < 45)
|
||||
return;
|
||||
if (xTaskGetTickCount() < TICKS_SECOND)
|
||||
return;
|
||||
#ifdef POW_QC_20V
|
||||
if (Vx10 > 200)
|
||||
Vx10 = 200; // Cap max value at 20V
|
||||
#else
|
||||
if (Vx10 > 130)
|
||||
Vx10 = 130; // Cap max value at 13V
|
||||
|
||||
#endif
|
||||
// Seek the QC to the Voltage given if this adapter supports continuous mode
|
||||
// try and step towards the wanted value
|
||||
|
||||
// 1. Measure current voltage
|
||||
int16_t vStart = getInputVoltageX10(divisor, 1);
|
||||
int difference = Vx10 - vStart;
|
||||
|
||||
// 2. calculate ideal steps (0.2V changes)
|
||||
|
||||
int steps = difference / 2;
|
||||
if (QCMode == QCState::QC_3) {
|
||||
if (steps > -2 && steps < 2)
|
||||
return; // dont bother with small steps
|
||||
while (steps < 0) {
|
||||
QC_SeekContNeg();
|
||||
osDelay(30);
|
||||
steps++;
|
||||
}
|
||||
while (steps > 0) {
|
||||
QC_SeekContPlus();
|
||||
osDelay(30);
|
||||
steps--;
|
||||
}
|
||||
osDelay(100);
|
||||
}
|
||||
#ifdef ENABLE_QC2
|
||||
// Re-measure
|
||||
/* Disabled due to nothing to test and code space of around 1k*/
|
||||
steps = vStart - getInputVoltageX10(divisor, 1);
|
||||
if (steps < 0)
|
||||
steps = -steps;
|
||||
if (steps > 4) {
|
||||
// No continuous mode, so QC2
|
||||
QCMode = QCState::QC_2;
|
||||
// Goto nearest
|
||||
if (Vx10 > 190) {
|
||||
// request 20V
|
||||
QC_Seek20V();
|
||||
} else if (Vx10 > 110) {
|
||||
// request 12V
|
||||
QC_Seek12V();
|
||||
} else {
|
||||
// request 9V
|
||||
QC_Seek9V();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// Must be called after FreeRToS Starts
|
||||
void startQC(uint16_t divisor) {
|
||||
// Pre check that the input could be >5V already, and if so, dont both
|
||||
// negotiating as someone is feeding in hv
|
||||
if (getInputVoltageX10(divisor, 1) > 80) {
|
||||
QCTries = 11;
|
||||
QCMode = QCState::NO_QC;
|
||||
return;
|
||||
}
|
||||
if (QCTries > 10) {
|
||||
QCMode = QCState::NO_QC;
|
||||
return;
|
||||
}
|
||||
QCMode = QCState::NOT_STARTED;
|
||||
QC_Init_GPIO();
|
||||
|
||||
// Tries to negotiate QC for 9V
|
||||
// This is a multiple step process.
|
||||
// 1. Set around 0.6V on D+ for 1.25 Seconds or so
|
||||
// 2. After this It should un-short D+->D- and instead add a 20k pulldown on
|
||||
// D-
|
||||
QC_DPlusZero_Six();
|
||||
|
||||
// Delay 1.25 seconds
|
||||
uint8_t enteredQC = 0;
|
||||
for (uint16_t i = 0; i < 200 && enteredQC == 0; i++) {
|
||||
osDelay(10); // 10mS pause
|
||||
if (i > 130) {
|
||||
if (QC_DM_PulledDown()) {
|
||||
enteredQC = 1;
|
||||
}
|
||||
if (i == 140) {
|
||||
// For some marginal QC chargers, we try adding a pulldown
|
||||
QC_DM_PullDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
QC_DM_No_PullDown();
|
||||
if (enteredQC) {
|
||||
// We have a QC capable charger
|
||||
QC_Seek9V();
|
||||
QC_Post_Probe_En();
|
||||
QC_Seek9V();
|
||||
// Wait for frontend ADC to stabilise
|
||||
QCMode = QCState::QC_2;
|
||||
for (uint8_t i = 0; i < 10; i++) {
|
||||
if (getInputVoltageX10(divisor, 1) > 80) {
|
||||
// yay we have at least QC2.0 or QC3.0
|
||||
QCMode = QCState::QC_3; // We have at least QC2, pray for 3
|
||||
return;
|
||||
}
|
||||
osDelay(100); // 100mS
|
||||
}
|
||||
QCMode = QCState::NOT_STARTED;
|
||||
QCTries++;
|
||||
|
||||
} else {
|
||||
// no QC
|
||||
QCTries++;
|
||||
QCMode = QCState::NO_QC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool hasQCNegotiated() {
|
||||
return QCMode == QCState::QC_3 || QCMode == QCState::QC_2;
|
||||
}
|
||||
101
source/Core/Src/Settings.cpp
Normal file
101
source/Core/Src/Settings.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Settings.c
|
||||
*
|
||||
* Created on: 29 Sep 2016
|
||||
* Author: Ralim
|
||||
*
|
||||
* This file holds the users settings and saves / restores them to the
|
||||
* devices flash
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Setup.h"
|
||||
#include "../../configuration.h"
|
||||
#include "BSP.h"
|
||||
|
||||
#include "string.h"
|
||||
volatile systemSettingsType systemSettings;
|
||||
|
||||
void saveSettings() {
|
||||
// First we erase the flash
|
||||
flash_save_buffer((uint8_t*) &systemSettings, sizeof(systemSettingsType));
|
||||
}
|
||||
|
||||
bool restoreSettings() {
|
||||
// We read the flash
|
||||
flash_read_buffer((uint8_t*) &systemSettings, sizeof(systemSettingsType));
|
||||
|
||||
// if the version is correct were done
|
||||
// if not we reset and save
|
||||
if (systemSettings.version != SETTINGSVERSION) {
|
||||
// probably not setup
|
||||
resetSettings();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Lookup function for cutoff setting -> X10 voltage
|
||||
/*
|
||||
* 0=DC
|
||||
* 1=3S
|
||||
* 2=4S
|
||||
* 3=5S
|
||||
* 4=6S
|
||||
*/
|
||||
uint8_t lookupVoltageLevel() {
|
||||
if (systemSettings.minDCVoltageCells == 0)
|
||||
return 90; // 9V since iron does not function effectively below this
|
||||
else
|
||||
return (systemSettings.minDCVoltageCells * 33) + (33 * 2);
|
||||
}
|
||||
void resetSettings() {
|
||||
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
||||
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
|
||||
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going
|
||||
// to sleep - default 1 min
|
||||
systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C
|
||||
systemSettings.minDCVoltageCells = CUT_OUT_SETTING; // default to no cut-off voltage
|
||||
systemSettings.QCIdealVoltage = 0; // Default to 9V for QC3.0 Voltage
|
||||
systemSettings.version = SETTINGSVERSION; // Store the version number to allow for easier upgrades
|
||||
systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen
|
||||
systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users)
|
||||
systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic
|
||||
systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity
|
||||
systemSettings.voltageDiv = VOLTAGE_DIV; // Default divider from schematic
|
||||
systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off
|
||||
systemSettings.BoostTemp = BOOST_TEMP; // default to 400C
|
||||
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
|
||||
systemSettings.lockingMode = LOCKING_MODE; // Disable locking for safety
|
||||
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
|
||||
#endif
|
||||
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
|
||||
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
|
||||
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit
|
||||
systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; //
|
||||
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; //
|
||||
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; //
|
||||
systemSettings.KeepAwakePulse = POWER_PULSE_DEFAULT;
|
||||
systemSettings.hallEffectSensitivity = 1;
|
||||
systemSettings.accelMissingWarningCounter = 0;
|
||||
systemSettings.pdMissingWarningCounter = 0;
|
||||
|
||||
saveSettings(); // Save defaults
|
||||
}
|
||||
|
||||
uint16_t lookupHallEffectThreshold() {
|
||||
// Return the threshold above which the hall effect sensor is "activated"
|
||||
switch (systemSettings.hallEffectSensitivity) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1: //Low
|
||||
return 1000;
|
||||
case 2: //Medium
|
||||
return 500;
|
||||
case 3: //High
|
||||
return 100;
|
||||
default:
|
||||
return 0; //Off
|
||||
}
|
||||
}
|
||||
52
source/Core/Src/freertos.c
Normal file
52
source/Core/Src/freertos.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* This notice applies to any and all portions of this file
|
||||
* that are not between comment pairs USER CODE BEGIN and
|
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools
|
||||
* are owned by their respective copyright owners.
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
1115
source/Core/Src/gui.cpp
Normal file
1115
source/Core/Src/gui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
71
source/Core/Src/main.cpp
Normal file
71
source/Core/Src/main.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
// By Ben V. Brown - V2.0 of the TS100 firmware
|
||||
|
||||
/*
|
||||
* Main.cpp bootstraps the device and then hands over to FreeRTOS and the threads
|
||||
*/
|
||||
|
||||
#include "BSP.h"
|
||||
#include <main.hpp>
|
||||
#include "LIS2DH12.hpp"
|
||||
#include <MMA8652FC.hpp>
|
||||
#include <power.hpp>
|
||||
#include "Settings.h"
|
||||
#include "cmsis_os.h"
|
||||
uint8_t DetectedAccelerometerVersion = 0;
|
||||
bool settingsWereReset = false;
|
||||
// FreeRTOS variables
|
||||
|
||||
osThreadId GUITaskHandle;
|
||||
static const size_t GUITaskStackSize = 1024 / 4;
|
||||
uint32_t GUITaskBuffer[GUITaskStackSize];
|
||||
osStaticThreadDef_t GUITaskControlBlock;
|
||||
|
||||
osThreadId PIDTaskHandle;
|
||||
static const size_t PIDTaskStackSize = 512 / 4;
|
||||
uint32_t PIDTaskBuffer[PIDTaskStackSize];
|
||||
osStaticThreadDef_t PIDTaskControlBlock;
|
||||
|
||||
osThreadId MOVTaskHandle;
|
||||
static const size_t MOVTaskStackSize = 1024 / 4;
|
||||
uint32_t MOVTaskBuffer[MOVTaskStackSize];
|
||||
osStaticThreadDef_t MOVTaskControlBlock;
|
||||
|
||||
osThreadId POWTaskHandle;
|
||||
static const size_t POWTaskStackSize = 512 / 4;
|
||||
uint32_t POWTaskBuffer[POWTaskStackSize];
|
||||
osStaticThreadDef_t POWTaskControlBlock;
|
||||
|
||||
// End FreeRTOS
|
||||
// Main sets up the hardware then hands over to the FreeRTOS kernel
|
||||
int main(void) {
|
||||
preRToSInit();
|
||||
setTipX10Watts(0); // force tip off
|
||||
resetWatchdog();
|
||||
OLED::setFont(0); // default to bigger font
|
||||
// Testing for which accelerometer is mounted
|
||||
settingsWereReset = restoreSettings(); // load the settings from flash
|
||||
resetWatchdog();
|
||||
/* Create the thread(s) */
|
||||
/* definition and creation of POWTask - Power management for QC */
|
||||
osThreadStaticDef(POWTask, startPOWTask, osPriorityAboveNormal, 0, POWTaskStackSize, POWTaskBuffer, &POWTaskControlBlock);
|
||||
POWTaskHandle = osThreadCreate(osThread(POWTask), NULL);
|
||||
|
||||
/* definition and creation of GUITask - The OLED control & update*/
|
||||
osThreadStaticDef(GUITask, startGUITask, osPriorityBelowNormal, 0, GUITaskStackSize, GUITaskBuffer, &GUITaskControlBlock);
|
||||
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
|
||||
|
||||
/* definition and creation of PIDTask - Heating control*/
|
||||
osThreadStaticDef(PIDTask, startPIDTask, osPriorityRealtime, 0, PIDTaskStackSize, PIDTaskBuffer, &PIDTaskControlBlock);
|
||||
PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL);
|
||||
|
||||
/* definition and creation of MOVTask - Accelerometer management */
|
||||
osThreadStaticDef(MOVTask, startMOVTask, osPriorityNormal, 0, MOVTaskStackSize, MOVTaskBuffer, &MOVTaskControlBlock);
|
||||
MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL);
|
||||
resetWatchdog();
|
||||
|
||||
/* Start scheduler */
|
||||
osKernelStart();
|
||||
/* We should never get here as control is now taken by the scheduler */
|
||||
for (;;) {
|
||||
}
|
||||
}
|
||||
75
source/Core/Src/power.cpp
Normal file
75
source/Core/Src/power.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* power.cpp
|
||||
*
|
||||
* Created on: 28 Oct, 2018
|
||||
* Authors: Ben V. Brown, David Hilton <- Mostly David
|
||||
*/
|
||||
|
||||
#include <power.hpp>
|
||||
#include <Settings.h>
|
||||
#include <BSP.h>
|
||||
|
||||
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample);
|
||||
|
||||
expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = { 0 };
|
||||
|
||||
int32_t tempToX10Watts(int32_t rawTemp) {
|
||||
// mass is in milliJ/*C, rawC is raw per degree C
|
||||
// returns milliWatts needed to raise/lower a mass by rawTemp
|
||||
// degrees in one cycle.
|
||||
int32_t milliJoules = tipMass * rawTemp;
|
||||
return milliJoules;
|
||||
}
|
||||
|
||||
void setTipX10Watts(int32_t mw) {
|
||||
int32_t output = X10WattsToPWM(mw, 1);
|
||||
setTipPWM(output);
|
||||
uint32_t actualMilliWatts = PWMToX10Watts(output, 0);
|
||||
|
||||
x10WattHistory.update(actualMilliWatts);
|
||||
}
|
||||
|
||||
static uint32_t availableW10(uint8_t sample) {
|
||||
//P = V^2 / R, v*v = v^2 * 100
|
||||
// R = R*10
|
||||
// P therefore is in V^2*100/R*10 = W*10.
|
||||
uint32_t v = getInputVoltageX10(systemSettings.voltageDiv, sample); // 100 = 10v
|
||||
uint32_t availableWattsX10 = (v * v) / tipResistance;
|
||||
//However, 100% duty cycle is not possible as there is a dead time while the ADC takes a reading
|
||||
//Therefore need to scale available milliwats by this
|
||||
|
||||
// avMw=(AvMw*powerPWM)/totalPWM.
|
||||
availableWattsX10 = availableWattsX10 * powerPWM;
|
||||
availableWattsX10 /= totalPWM;
|
||||
|
||||
//availableMilliWattsX10 is now an accurate representation
|
||||
return availableWattsX10;
|
||||
}
|
||||
|
||||
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
|
||||
// Scale input milliWatts to the pwm range available
|
||||
if (milliWatts < 1) {
|
||||
//keep the battery voltage updating the filter
|
||||
getInputVoltageX10(systemSettings.voltageDiv, sample);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Calculate desired milliwatts as a percentage of availableW10
|
||||
uint32_t pwm;
|
||||
do {
|
||||
pwm = (powerPWM * milliWatts) / availableW10(sample);
|
||||
if (pwm > powerPWM) {
|
||||
// constrain to max PWM counter, shouldn't be possible,
|
||||
// but small cost for safety to avoid wraps
|
||||
pwm = powerPWM;
|
||||
}
|
||||
} while (tryBetterPWM(pwm));
|
||||
|
||||
return pwm;
|
||||
}
|
||||
|
||||
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample) {
|
||||
uint32_t maxMW = availableW10(sample); //Get the milliwatts for the max pwm period
|
||||
//Then convert pwm into percentage of powerPWM to get the percentage of the max mw
|
||||
return (((uint32_t) pwm) * maxMW) / powerPWM;
|
||||
}
|
||||
19
source/Core/Src/syscalls.c
Normal file
19
source/Core/Src/syscalls.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* Includes */
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles() {
|
||||
}
|
||||
|
||||
int _getpid(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user