Better messages flowing

This commit is contained in:
Ben V. Brown
2020-06-16 20:21:26 +10:00
parent 54a8aa7ac6
commit 2fd06887e8
18 changed files with 132 additions and 75 deletions

View File

@@ -8,9 +8,9 @@
#ifndef BSP_MINIWARE_PINS_H_
#define BSP_MINIWARE_PINS_H_
#if defined(MODEL_TS100) + defined(MODEL_TS80) > 1
#if defined(MODEL_TS100) + defined(MODEL_TS80)+defined(MODEL_TS80P) > 1
#error "Multiple models defined!"
#elif defined(MODEL_TS100) + defined(MODEL_TS80) == 0
#elif defined(MODEL_TS100) + defined(MODEL_TS80)+ defined(MODEL_TS80P) == 0
#error "No model defined!"
#endif
@@ -45,8 +45,8 @@
#define SCL_GPIO_Port GPIOB
#define SDA_Pin GPIO_PIN_7
#define SDA_GPIO_Port GPIOB
#else
#endif
#ifdef MODEL_TS80
// TS80 pin map
#define KEY_B_Pin GPIO_PIN_0
#define KEY_B_GPIO_Port GPIOB
@@ -84,6 +84,45 @@
#define INT_PD_Pin GPIO_PIN_9
#define INT_PD_GPIO_Port GPIOA
#endif
#ifdef MODEL_TS80P
// TS80P pin map
#define KEY_B_Pin GPIO_PIN_0
#define KEY_B_GPIO_Port GPIOB
#define TMP36_INPUT_Pin GPIO_PIN_4
#define TMP36_INPUT_GPIO_Port GPIOA
#define TMP36_ADC1_CHANNEL ADC_CHANNEL_4
#define TIP_TEMP_Pin GPIO_PIN_3
#define TIP_TEMP_GPIO_Port GPIOA
#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_3
#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_3
#define VIN_Pin GPIO_PIN_2
#define VIN_GPIO_Port GPIOA
#define VIN_ADC1_CHANNEL ADC_CHANNEL_2
#define VIN_ADC2_CHANNEL ADC_CHANNEL_2
#define OLED_RESET_Pin GPIO_PIN_15
#define OLED_RESET_GPIO_Port GPIOA
#define KEY_A_Pin GPIO_PIN_1
#define KEY_A_GPIO_Port GPIOB
#define INT_Orientation_Pin GPIO_PIN_4
#define INT_Orientation_GPIO_Port GPIOB
#define PWM_Out_Pin GPIO_PIN_6
#define PWM_Out_GPIO_Port GPIOA
#define PWM_Out_CHANNEL TIM_CHANNEL_1
#define INT_Movement_Pin GPIO_PIN_5
#define INT_Movement_GPIO_Port GPIOB
#define SCL_Pin GPIO_PIN_6
#define SCL_GPIO_Port GPIOB
#define SDA_Pin GPIO_PIN_7
#define SDA_GPIO_Port GPIOB
#define SCL2_Pin GPIO_PIN_5
#define SCL2_GPIO_Port GPIOA
#define SDA2_Pin GPIO_PIN_1
#define SDA2_GPIO_Port GPIOA
#define INT_PD_Pin GPIO_PIN_9
#define INT_PD_GPIO_Port GPIOA
#endif
#endif /* BSP_MINIWARE_PINS_H_ */

View File

@@ -8,10 +8,9 @@ bool FUSB302_present = false;
void power_probe() {
// If TS80 probe for QC
// If TS100 - noop
#ifdef MODEL_TS80
#ifdef defined(MODEL_TS80)+defined(MODEL_TS80P)>0
startQC(systemSettings.voltageDiv);
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with
@@ -19,12 +18,12 @@ void power_probe() {
}
void power_check() {
#ifdef MODEL_TS80
#ifdef defined(MODEL_TS80)+defined(MODEL_TS80P)>0
QC_resync();
#endif
}
uint8_t usb_pd_detect() {
#ifdef MODEL_TS80
#ifdef MODEL_TS80P
FUSB302_present = fusb302_detect();
if (FUSB302_present) {
GPIO_InitTypeDef GPIO_InitStruct;
@@ -39,9 +38,11 @@ uint8_t usb_pd_detect() {
return false;
}
uint8_t pd_irq_read() {
#ifdef MODEL_TS80
return HAL_GPIO_ReadPin(INT_PD_GPIO_Port, INT_PD_Pin) == GPIO_PIN_SET ?
1 : 0;
#ifdef MODEL_TS80P
if (FUSB302_present) {
return HAL_GPIO_ReadPin(INT_PD_GPIO_Port, INT_PD_Pin) == GPIO_PIN_SET ?
1 : 0;
}
#endif
return 0;
}

View File

@@ -67,8 +67,8 @@ void QC_Post_Probe_En() {
uint8_t QC_DM_PulledDown() { return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0; }
void QC_resync() {
#ifdef MODEL_TS80
#if defined(MODEL_TS80) + defined(MODEL_TS80P) >0
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // Run the QC seek again if we have drifted too much
#endif
}
}

View File

@@ -8,7 +8,7 @@
#ifndef BSP_MINIWARE_UNITSETTINGS_H_
#define BSP_MINIWARE_UNITSETTINGS_H_
//On the TS80, the LIS accel is mounted backwards
#ifdef MODEL_TS80
#if defined(MODEL_TS80)+defined(MODEL_TS80P)>0
#define LIS_ORI_FLIP
#endif

View File

@@ -20,7 +20,7 @@ void preRToSInit() {
HAL_Delay(50);
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
HAL_Delay(50);
#ifdef MODEL_TS80
#ifdef MODEL_TS80P
I2CBB::init();
//Spawn all of the USB-C processors
fusb302_start_processing();

View File

@@ -42,7 +42,9 @@ static uint8_t fusb_read_byte(uint8_t addr) {
* buf: The buffer into which data will be read
*/
static void fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) buf, size);
if(!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) buf, size)){
asm("bkpt");
}
}
@@ -54,7 +56,9 @@ static void fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
* byte: The value to write
*/
static void fusb_write_byte(uint8_t addr, uint8_t byte) {
I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1);
if(!I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1)){
asm("bkpt");
}
}
@@ -67,7 +71,9 @@ static void fusb_write_byte(uint8_t addr, uint8_t byte) {
* buf: The buffer to write
*/
static void fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &buf, size);
if(!I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &buf, size)){
asm("bkpt");
}
}

View File

@@ -21,7 +21,7 @@ uint8_t fusb302_detect() {
}
void fusb302_start_processing() {
HAL_Delay(30);
/* Initialize the FUSB302B */
fusb_setup();

View File

@@ -103,7 +103,7 @@ void ResetHandler::init() {
void ResetHandler::notify(uint32_t notification) {
xTaskNotify(TaskHandle, notification,
eNotifyAction::eSetValueWithOverwrite);
eNotifyAction::eSetBits);
}
void ResetHandler::Thread(const void *arg) {

View File

@@ -278,15 +278,13 @@
#define PD_T_PS_TRANSITION (500)
#define PD_T_SENDER_RESPONSE (27)
#define PD_T_SINK_REQUEST (100)
#define PD_T_TYPEC_SINK_WAIT_CAP (465)
#define PD_T_PPS_REQUEST TIME_S2I(10)
/* This is actually from Type-C, not Power Delivery, but who cares? */
#define PD_T_TYPEC_SINK_WAIT_CAP (465+100)
#define PD_T_PD_DEBOUNCE (15)
/*
* Counter maximums
*/
#define PD_N_HARD_RESET_COUNT 2
#define PD_N_HARD_RESET_COUNT 10
/*
* Value parameters

View File

@@ -22,21 +22,6 @@
/* Number of messages in the message pool */
#define PDB_MSG_POOL_SIZE 4
/* Size of the Policy Engine thread's working area */
#define PDB_PE_WA_SIZE 256
/* Size of the protocol layer RX thread's working area */
#define PDB_PRLRX_WA_SIZE 256
/* Size of the protocol layer TX thread's working area */
#define PDB_PRLTX_WA_SIZE 256
/* Size of the protocol layer hard reset thread's working area */
#define PDB_HARDRST_WA_SIZE 256
/* Size of the INT_N thread's working area */
#define PDB_INT_N_WA_SIZE 128
#define EVENT_MASK(x) (1<<x)
#define eventmask_t uint32_t
/* PD Buddy thread priorities */

View File

@@ -55,7 +55,7 @@ void PolicyEngine::init() {
void PolicyEngine::notify(uint32_t notification) {
xTaskNotify(TaskHandle, notification,
eNotifyAction::eSetValueWithOverwrite);
eNotifyAction::eSetBits);
}
void PolicyEngine::pe_task(const void *arg) {

View File

@@ -81,6 +81,7 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(
return true;
}
}
#if 0
/* If we have a PPS APDO, our desired V lies within its range, and
* its I is at least our desired I */
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
@@ -108,6 +109,7 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(
//
// return true;
}
#endif
}
/* If there's a PDO in the voltage range, use it */
// int8_t i = dpm_get_range_fixed_pdo_index(caps, scfg);

View File

@@ -34,10 +34,12 @@ uint8_t ProtocolReceive::_tx_messageidcounter;
*/
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
/* Wait for an event */
_rx_messageid = 0;
eventmask_t evt = waitForEvent(0xFFFFFFFF);
/* If we got a reset event, reset */
if (evt & PDB_EVT_PRLRX_RESET) {
waitForEvent(PDB_EVT_PRLRX_RESET, 0);
return PRLRxWaitPHY;
}
/* If we got an I_GCRCSENT event, read the message and decide what to do */
@@ -75,7 +77,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
taskYIELD();
/* If we got a RESET signal, reset the machine */
if (waitForEvent(PDB_EVT_PRLRX_RESET) != 0) {
if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) != 0) {
return PRLRxWaitPHY;
}
@@ -88,17 +90,16 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
*/
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
/* If we got a RESET signal, reset the machine */
if (waitForEvent(PDB_EVT_PRLRX_RESET) != 0) {
if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
return PRLRxWaitPHY;
}
/* If the message has the stored ID, we've seen this message before. Free
* it and don't pass it to the policy engine. */
/* Otherwise, there's either no stored ID or this message has an ID we
* haven't just seen. Transition to the Store_MessageID state. */
if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
return PRLRxWaitPHY;
/* Otherwise, there's either no stored ID or this message has an ID we
* haven't just seen. Transition to the Store_MessageID state. */
} else {
return PRLRxStoreMessageID;
}
@@ -160,12 +161,11 @@ void ProtocolReceive::thread(const void *args) {
}
void ProtocolReceive::notify(uint32_t notification) {
xTaskNotify(TaskHandle, notification,
eNotifyAction::eSetValueWithOverwrite);
xTaskNotify(TaskHandle, notification, eNotifyAction::eSetBits);
}
uint32_t ProtocolReceive::waitForEvent(uint32_t mask, uint32_t ticksToWait) {
uint32_t pulNotificationValue;
xTaskNotifyWait(0x00, mask, &pulNotificationValue, ticksToWait);
return pulNotificationValue;
return pulNotificationValue & mask;
}

View File

@@ -45,7 +45,9 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
/* Tell the policy engine that we failed */
PolicyEngine::notify( PDB_EVT_PE_TX_ERR);
/* Finish failing to send the message */
getMessage(); //Discard
while (messagePending()) {
getMessage(); //Discard
}
}
/* Wait for a message request */
@@ -103,7 +105,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() {
/* Make sure nobody wants us to reset */
eventmask_t evt = waitForEvent(
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD);
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD, 0);
if (evt & PDB_EVT_PRLTX_RESET) {
return PRLTxPHYReset;
@@ -119,7 +121,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
/* PD 3.0 collision avoidance */
if (PolicyEngine::isPD3_0()) {
/* If we're starting an AMS, wait for permission to transmit */
evt = waitForEvent(PDB_EVT_PRLTX_START_AMS);
evt = waitForEvent(PDB_EVT_PRLTX_START_AMS, 0);
if (evt & PDB_EVT_PRLTX_START_AMS) {
while (fusb_get_typec_current() != fusb_sink_tx_ok) {
osDelay(1);
@@ -253,14 +255,14 @@ void ProtocolTransmit::thread(const void *args) {
void ProtocolTransmit::notify(uint32_t notification) {
xTaskNotify(TaskHandle, notification,
eNotifyAction::eSetValueWithOverwrite);
eNotifyAction::eSetBits);
}
void ProtocolTransmit::init() {
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
osThreadStaticDef(pd_txTask, thread,osPriorityAboveNormal, 0, TaskStackSize,
TaskBuffer, &TaskControlBlock);
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
}

View File

@@ -9,6 +9,7 @@
#include <history.hpp>
#include "BSP.h"
#include "expMovingAverage.h"
#include "../../configuration.h"
#ifndef POWER_HPP_
#define POWER_HPP_
@@ -18,16 +19,6 @@
// This is necessary because of the temp noise and thermal lag in the system.
// Once we have feed-forward temp estimation we should be able to better tune this.
#ifdef MODEL_TS100
const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
#endif
#ifdef MODEL_TS80
const uint32_t tipMass = 40;
const uint8_t tipResistance = 45; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
#endif
const uint8_t wattHistoryFilter = 24; // I term look back weighting
extern expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory;

View File

@@ -43,6 +43,8 @@ int main(void) {
OLED::setFont(0); // default to bigger font
// Testing for which accelerometer is mounted
resetWatchdog();
usb_pd_available = usb_pd_detect();
resetWatchdog();
settingsWereReset = restoreSettings(); // load the settings from flash
if (MMA8652FC::detect()) {
PCBVersion = 1;
@@ -58,8 +60,6 @@ int main(void) {
systemSettings.sensitivity = 0;
}
resetWatchdog();
usb_pd_available = usb_pd_detect();
resetWatchdog();
/* Create the thread(s) */
/* definition and creation of GUITask */

View File

@@ -22,6 +22,7 @@ FRTOS_CMIS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
FRTOS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/include
FRTOS_GCC_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3
DRIVER_INC_DIR =./Core/Drivers
FUSB_DRIVERS_INC_DIR = ./Core/Drivers/FUSB302
BSP_INC_DIR = ./Core/BSP
MINIWARE_INC_DIR = ./Core/BSP/Miniware
THREADS_INC_DIR = ./Core/Threads
@@ -37,7 +38,8 @@ INCLUDES = -I$(APP_INC_DIR) \
-I$(DRIVER_INC_DIR) \
-I$(BSP_INC_DIR) \
-I$(MINIWARE_INC_DIR) \
-I$(THREADS_INC_DIR)
-I$(THREADS_INC_DIR) \
-I$(FUSB_DRIVERS_INC_DIR)
# output folder
HEXFILE_DIR=Hexfile

View File

@@ -76,7 +76,6 @@
#define DETAILED_SOLDERING 0 // 0: Disable 1: Enable - Default 0
#define DETAILED_IDLE 0 // 0: Disable 1: Enable - Default 0
#define CUT_OUT_SETTING 0 // default to no cut-off voltage (or 18W for TS80)
#define TEMPERATURE_INF 0 // default to 0
#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow
@@ -94,6 +93,10 @@
#define OP_AMP_GAIN_STAGE_TS80 (1+(OP_AMP_Rf_TS80/OP_AMP_Rin_TS80))
//Deriving the Voltage div:
// Vin_max = (3.3*(r1+r2))/(r2)
//vdiv = (32768*4)/(vin_max*10)
#ifdef MODEL_TS100
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
@@ -105,11 +108,39 @@
#endif
#ifdef MODEL_TS80
#define VOLTAGE_DIV 780 // Default divider from schematic
#define PID_POWER_LIMIT 24 // Sets the max pwm power limit
#define CALIBRATION_OFFSET 900 // the adc offset in uV
#define POWER_LIMIT 24 // 24 watts default power limit
#define MAX_POWER_LIMIT 30 //
#define POWER_LIMIT_STEPS 2
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
#define VOLTAGE_DIV_TS80P 768 // Default for TS80P with slightly different resistors
#define VOLTAGE_DIV 780 // Default divider from schematic
#define PID_POWER_LIMIT 24 // Sets the max pwm power limit
#define CALIBRATION_OFFSET 900 // the adc offset in uV
#define POWER_LIMIT 24 // 24 watts default power limit
#define MAX_POWER_LIMIT 30 //
#define POWER_LIMIT_STEPS 2
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
#endif
#ifdef MODEL_TS80P
#define VOLTAGE_DIV 768 // Default for TS80P with slightly different resistors
#define PID_POWER_LIMIT 30 // Sets the max pwm power limit
#define CALIBRATION_OFFSET 900 // the adc offset in uV
#define POWER_LIMIT 24 // 24 watts default power limit
#define MAX_POWER_LIMIT 30 //
#define POWER_LIMIT_STEPS 2
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
#endif
#ifdef MODEL_TS100
const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
#endif
#ifdef MODEL_TS80
const uint32_t tipMass = 40;
const uint8_t tipResistance = 45; //x10 ohms, 4.5 typical for ts80 tips
#endif
#ifdef MODEL_TS80P
const uint32_t tipMass = 40;
const uint8_t tipResistance = 45; //x10 ohms, 4.5 typical for ts80 tips
#endif