1
0
forked from me/IronOS

Still testing

This commit is contained in:
Ben V. Brown
2020-07-21 13:39:50 +10:00
parent c70689df7d
commit b6c61cfb52
31 changed files with 674 additions and 557 deletions

View File

@@ -217,6 +217,7 @@ uint8_t getButtonB() {
} }
void reboot() { void reboot() {
asm("bkpt");
NVIC_SystemReset(); NVIC_SystemReset();
} }

View File

@@ -13,9 +13,11 @@
#define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET) #define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
#define SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0) #define SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0)
#define SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0) #define SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0)
#define I2C_DELAY() {for(int xx=0;xx<100;xx++){asm("nop");}} #define I2C_DELAY() {for(int xx=0;xx<1000;xx++){asm("nop");}}
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL; SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
StaticSemaphore_t I2CBB::xSemaphoreBuffer; StaticSemaphore_t I2CBB::xSemaphoreBuffer;
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
StaticSemaphore_t I2CBB::xSemaphoreBuffer2;
void I2CBB::init() { void I2CBB::init() {
//Set GPIO's to output open drain //Set GPIO's to output open drain
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
@@ -28,8 +30,14 @@ void I2CBB::init() {
SDA_HIGH(); SDA_HIGH();
SCL_HIGH(); SCL_HIGH();
I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer); I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer);
xSemaphoreGive(I2CSemaphore); I2CSemaphore2 = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer2);
unlock(); unlock();
unlock2();
//unstick bus
for (int i = 0; i < 8; i++) {
read_bit();
}
stop();
} }
bool I2CBB::probe(uint8_t address) { bool I2CBB::probe(uint8_t address) {
@@ -73,8 +81,8 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
return true; return true;
} }
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
uint16_t Size) { const uint8_t *pData, uint16_t Size) {
if (!lock()) if (!lock())
return false; return false;
start(); start();
@@ -205,6 +213,7 @@ void I2CBB::start() {
I2C_DELAY(); I2C_DELAY();
SCL_LOW(); SCL_LOW();
I2C_DELAY(); I2C_DELAY();
SDA_HIGH();
} }
void I2CBB::stop() { void I2CBB::stop() {
@@ -224,6 +233,7 @@ bool I2CBB::send(uint8_t value) {
value <<= 1; value <<= 1;
} }
SDA_HIGH();
bool ack = read_bit() == 0; bool ack = read_bit() == 0;
return ack; return ack;
} }
@@ -237,6 +247,7 @@ uint8_t I2CBB::read(bool ack) {
B |= read_bit(); B |= read_bit();
} }
SDA_HIGH();
if (ack) if (ack)
write_bit(0); write_bit(0);
else else
@@ -269,7 +280,7 @@ bool I2CBB::lock() {
if (I2CSemaphore == NULL) { if (I2CSemaphore == NULL) {
asm("bkpt"); asm("bkpt");
} }
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 50) == pdTRUE; bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 100) == pdTRUE;
if (!a) { if (!a) {
asm("bkpt"); asm("bkpt");
} }
@@ -277,13 +288,29 @@ bool I2CBB::lock() {
} }
void I2CBB::write_bit(uint8_t val) { void I2CBB::write_bit(uint8_t val) {
if (val > 0) if (val) {
SDA_HIGH(); SDA_HIGH();
else } else {
SDA_LOW(); SDA_LOW();
}
I2C_DELAY(); I2C_DELAY();
SCL_HIGH(); SCL_HIGH();
I2C_DELAY(); I2C_DELAY();
SCL_LOW(); SCL_LOW();
} }
void I2CBB::unlock2() {
xSemaphoreGive(I2CSemaphore2);
}
bool I2CBB::lock2() {
if (I2CSemaphore2 == NULL) {
asm("bkpt");
}
bool a = xSemaphoreTake(I2CSemaphore2, (TickType_t) 500) == pdTRUE;
if (!a) {
asm("bkpt");
}
return a;
}

View File

@@ -27,14 +27,18 @@ public:
uint8_t *pData, uint16_t Size); uint8_t *pData, uint16_t Size);
//Implements a register write //Implements a register write
static bool Mem_Write(uint16_t DevAddress, uint16_t MemAddress, static bool Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
uint8_t *pData, uint16_t Size); const uint8_t *pData, uint16_t Size);
static void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size); static void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
static void Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size); static void Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
static void TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, static void TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx,
uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx); uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx);
static void unlock2();
static bool lock2();
private: private:
static SemaphoreHandle_t I2CSemaphore; static SemaphoreHandle_t I2CSemaphore;
static StaticSemaphore_t xSemaphoreBuffer; static StaticSemaphore_t xSemaphoreBuffer;
static SemaphoreHandle_t I2CSemaphore2;
static StaticSemaphore_t xSemaphoreBuffer2;
static void unlock(); static void unlock();
static bool lock(); static bool lock();
static void start(); static void start();

View File

@@ -26,15 +26,7 @@ void power_check() {
uint8_t usb_pd_detect() { uint8_t usb_pd_detect() {
#ifdef MODEL_TS80P #ifdef MODEL_TS80P
FUSB302_present = fusb302_detect(); FUSB302_present = fusb302_detect();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 15, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
InterruptHandler::irqCallback();
return FUSB302_present; return FUSB302_present;
#endif #endif
return false; return false;

View File

@@ -33,9 +33,9 @@ static void MX_ADC2_Init(void);
void Setup_HAL() { void Setup_HAL() {
SystemClock_Config(); SystemClock_Config();
__HAL_AFIO_REMAP_SWJ_DISABLE() // __HAL_AFIO_REMAP_SWJ_DISABLE()
; // ;
__HAL_AFIO_REMAP_SWJ_NOJTAG();
MX_GPIO_Init(); MX_GPIO_Init();
MX_DMA_Init(); MX_DMA_Init();
MX_I2C1_Init(); MX_I2C1_Init();
@@ -43,7 +43,7 @@ void Setup_HAL() {
MX_ADC2_Init(); MX_ADC2_Init();
MX_TIM3_Init(); MX_TIM3_Init();
MX_TIM2_Init(); MX_TIM2_Init();
MX_IWDG_Init(); // MX_IWDG_Init();
HAL_ADC_Start(&hadc2); HAL_ADC_Start(&hadc2);
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*) ADCReadings, 64); // start DMA of normal readings HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*) ADCReadings, 64); // start DMA of normal readings
HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
@@ -458,3 +458,8 @@ static void MX_GPIO_Init(void) {
HAL_Delay(30); HAL_Delay(30);
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
} }
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line){
asm("bkpt");
}
#endif

View File

@@ -11,6 +11,7 @@
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/* #define DATA_IN_ExtSRAM */ /* #define DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
#define LOCAL_BUILD
#ifndef LOCAL_BUILD #ifndef LOCAL_BUILD
#define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field. #define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */ This value must be a multiple of 0x200. */

View File

@@ -18,7 +18,7 @@
#include "fusb302b.h" #include "fusb302b.h"
#include "I2CBB.hpp" #include "I2CBB.hpp"
#include <pd.h> #include <pd.h>
#include "int_n.h"
/* /*
* Read a single byte from the FUSB302B * Read a single byte from the FUSB302B
* *
@@ -29,7 +29,9 @@
*/ */
static uint8_t fusb_read_byte(uint8_t addr) { static uint8_t fusb_read_byte(uint8_t addr) {
uint8_t data[1]; uint8_t data[1];
I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) data, 1); if (!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) data, 1)) {
asm("bkpt");
}
return data[0]; return data[0];
} }
@@ -41,11 +43,8 @@ static uint8_t fusb_read_byte(uint8_t addr) {
* size: The number of bytes to read * size: The number of bytes to read
* buf: The buffer into which data will be read * buf: The buffer into which data will be read
*/ */
static void fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) { static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
if(!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) buf, size)){ return I2CBB::Mem_Read(FUSB302B_ADDR, addr, buf, size);
asm("bkpt");
}
} }
/* /*
@@ -55,11 +54,8 @@ static void fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
* addr: The memory address to which we will write * addr: The memory address to which we will write
* byte: The value to write * byte: The value to write
*/ */
static void fusb_write_byte(uint8_t addr, uint8_t byte) { static bool fusb_write_byte(uint8_t addr, uint8_t byte) {
if(!I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1)){ return I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1);
asm("bkpt");
}
} }
/* /*
@@ -70,14 +66,12 @@ static void fusb_write_byte(uint8_t addr, uint8_t byte) {
* size: The number of bytes to write * size: The number of bytes to write
* buf: The buffer to write * buf: The buffer to write
*/ */
static void fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
if(!I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &buf, size)){ return I2CBB::Mem_Write(FUSB302B_ADDR, addr, buf, size);
asm("bkpt");
}
} }
void fusb_send_message(const union pd_msg *msg) { void fusb_send_message(const union pd_msg *msg) {
/* Token sequences for the FUSB302B */ /* Token sequences for the FUSB302B */
static uint8_t sop_seq[5] = { static uint8_t sop_seq[5] = {
FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1,
@@ -98,16 +92,23 @@ void fusb_send_message(const union pd_msg *msg) {
/* Set the number of bytes to be transmitted in the packet */ /* Set the number of bytes to be transmitted in the packet */
sop_seq[4] = FUSB_FIFO_TX_PACKSYM | msg_len; sop_seq[4] = FUSB_FIFO_TX_PACKSYM | msg_len;
if (!I2CBB::lock2()) {
asm("bkpt");
}
/* Write all three parts of the message to the TX FIFO */ /* Write all three parts of the message to the TX FIFO */
fusb_write_buf( FUSB_FIFOS, 5, sop_seq); fusb_write_buf( FUSB_FIFOS, 5, sop_seq);
fusb_write_buf( FUSB_FIFOS, msg_len, msg->bytes); fusb_write_buf( FUSB_FIFOS, msg_len, msg->bytes);
fusb_write_buf( FUSB_FIFOS, 4, eop_seq); fusb_write_buf( FUSB_FIFOS, 4, eop_seq);
I2CBB::unlock2();
} }
uint8_t fusb_read_message(union pd_msg *msg) { uint8_t fusb_read_message(union pd_msg *msg) {
uint8_t garbage[4]; if (!I2CBB::lock2()) {
asm("bkpt");
}
static uint8_t garbage[4];
uint8_t numobj; uint8_t numobj;
/* If this isn't an SOP message, return error. /* If this isn't an SOP message, return error.
@@ -115,6 +116,8 @@ uint8_t fusb_read_message(union pd_msg *msg) {
* buffer is empty, and not try to read past a non-SOP message. */ * buffer is empty, and not try to read past a non-SOP message. */
if ((fusb_read_byte( FUSB_FIFOS) & FUSB_FIFO_RX_TOKEN_BITS) if ((fusb_read_byte( FUSB_FIFOS) & FUSB_FIFO_RX_TOKEN_BITS)
!= FUSB_FIFO_RX_SOP) { != FUSB_FIFO_RX_SOP) {
I2CBB::unlock2();
return 1; return 1;
} }
/* Read the message header into msg */ /* Read the message header into msg */
@@ -128,33 +131,56 @@ uint8_t fusb_read_message(union pd_msg *msg) {
/* Throw the CRC32 in the garbage, since the PHY already checked it. */ /* Throw the CRC32 in the garbage, since the PHY already checked it. */
fusb_read_buf( FUSB_FIFOS, 4, garbage); fusb_read_buf( FUSB_FIFOS, 4, garbage);
I2CBB::unlock2();
return 0; return 0;
} }
void fusb_send_hardrst() { void fusb_send_hardrst() {
if (!I2CBB::lock2()) {
asm("bkpt");
}
/* Send a hard reset */ /* Send a hard reset */
fusb_write_byte( FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET); fusb_write_byte( FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
I2CBB::unlock2();
} }
void fusb_setup() { void fusb_setup() {
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 10, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) {
asm("bkpt");
}
}
/* Fully reset the FUSB302B */ /* Fully reset the FUSB302B */
fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES); fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES);
delay_ms(2);
if (!fusb_read_id()) {
asm("bkpt");
}
/* Turn on all power */ /* Turn on all power */
fusb_write_byte( FUSB_POWER, 0x0F); fusb_write_byte( FUSB_POWER, 0x0F);
/* Set interrupt masks */ /* Set interrupt masks */
//Setting to 0 so interrupts are allowed
fusb_write_byte( FUSB_MASK1, 0x00); fusb_write_byte( FUSB_MASK1, 0x00);
fusb_write_byte( FUSB_MASKA, 0x00); fusb_write_byte( FUSB_MASKA, 0x00);
fusb_write_byte( FUSB_MASKB, 0x00); fusb_write_byte( FUSB_MASKB, 0x00);
fusb_write_byte( FUSB_CONTROL0, 0x04); fusb_write_byte( FUSB_CONTROL0, 0b11 << 2);
/* Enable automatic retransmission */ /* Enable automatic retransmission */
fusb_write_byte( FUSB_CONTROL3, 0x07); fusb_write_byte( FUSB_CONTROL3, 0x07);
//set defaults
fusb_write_byte( FUSB_CONTROL2, 0x00);
/* Flush the RX buffer */ /* Flush the RX buffer */
fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH); fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
@@ -184,29 +210,48 @@ void fusb_setup() {
fusb_write_byte( FUSB_SWITCHES0, 0x0B); fusb_write_byte( FUSB_SWITCHES0, 0x0B);
} }
resetWatchdog(); resetWatchdog();
fusb_reset();
/* Reset the PD logic */ if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
fusb_write_byte( FUSB_RESET, FUSB_RESET_PD_RESET); I2CBB::unlock2();
}
} }
void fusb_get_status(union fusb_status *status) { void fusb_get_status(union fusb_status *status) {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) {
asm("bkpt");
}
}
/* Read the interrupt and status flags into status */ /* Read the interrupt and status flags into status */
fusb_read_buf( FUSB_STATUS0A, 7, status->bytes); fusb_read_buf( FUSB_STATUS0A, 7, status->bytes);
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
I2CBB::unlock2();
}
} }
enum fusb_typec_current fusb_get_typec_current() { enum fusb_typec_current fusb_get_typec_current() {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) {
asm("bkpt");
}
}
/* Read the BC_LVL into a variable */ /* Read the BC_LVL into a variable */
enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte( enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte(
FUSB_STATUS0) & FUSB_STATUS0_BC_LVL); FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
I2CBB::unlock2();
}
return bc_lvl; return bc_lvl;
} }
void fusb_reset() { void fusb_reset() {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) {
asm("bkpt");
}
}
/* Flush the TX buffer */ /* Flush the TX buffer */
fusb_write_byte( FUSB_CONTROL0, 0x44); fusb_write_byte( FUSB_CONTROL0, 0x44);
@@ -214,5 +259,16 @@ void fusb_reset() {
fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH); fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
/* Reset the PD logic */ /* Reset the PD logic */
fusb_write_byte( FUSB_RESET, FUSB_RESET_PD_RESET); fusb_write_byte( FUSB_RESET, FUSB_RESET_PD_RESET);
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
I2CBB::unlock2();
}
}
bool fusb_read_id() {
//Return true if read of the revision ID is sane
uint8_t version = 0;
fusb_read_buf(FUSB_DEVICE_ID, 1, &version);
if (version == 0 || version == 0xFF)
return false;
return true;
} }

View File

@@ -300,4 +300,6 @@ void fusb_setup();
*/ */
void fusb_reset(); void fusb_reset();
bool fusb_read_id();
#endif /* PDB_FUSB302B_H */ #endif /* PDB_FUSB302B_H */

View File

@@ -23,6 +23,7 @@ uint8_t fusb302_detect() {
void fusb302_start_processing() { void fusb302_start_processing() {
/* Initialize the FUSB302B */ /* Initialize the FUSB302B */
fusb_setup(); fusb_setup();
resetWatchdog();
/* Create the policy engine thread. */ /* Create the policy engine thread. */
PolicyEngine::init(); PolicyEngine::init();
@@ -30,7 +31,7 @@ void fusb302_start_processing() {
ProtocolReceive::init(); ProtocolReceive::init();
ProtocolTransmit::init(); ProtocolTransmit::init();
ResetHandler::init(); ResetHandler::init();
resetWatchdog();
/* Create the INT_N thread. */ /* Create the INT_N thread. */
InterruptHandler::init(); InterruptHandler::init();
} }

View File

@@ -34,12 +34,12 @@ ResetHandler::hardrst_state ResetHandler::hardrst_reset_layer() {
/* First, wait for the signal to run a hard reset. */ /* First, wait for the signal to run a hard reset. */
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_HARDRST_RESET | PDB_EVT_HARDRST_I_HARDRST); PDB_EVT_HARDRST_RESET | PDB_EVT_HARDRST_I_HARDRST);
if (evt & (PDB_EVT_HARDRST_RESET | PDB_EVT_HARDRST_I_HARDRST)) {
/* Reset the Protocol RX machine */ /* Reset the Protocol RX machine */
ProtocolReceive::notify( PDB_EVT_PRLRX_RESET); ProtocolReceive::notify( PDB_EVT_PRLRX_RESET);
taskYIELD(); taskYIELD();
/* Reset the Protocol TX machine */ /* Reset the Protocol TX machine */
ProtocolTransmit::notify(PDB_EVT_PRLTX_RESET); ProtocolTransmit::notify( ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
taskYIELD(); taskYIELD();
/* Continue the process based on what event started the reset. */ /* Continue the process based on what event started the reset. */
if (evt & PDB_EVT_HARDRST_RESET) { if (evt & PDB_EVT_HARDRST_RESET) {
@@ -49,6 +49,9 @@ ResetHandler::hardrst_state ResetHandler::hardrst_reset_layer() {
/* PHY started the reset */ /* PHY started the reset */
return PRLHRIndicateHardReset; return PRLHRIndicateHardReset;
} }
} else {
return PRLHRResetLayer;
}
} }
ResetHandler::hardrst_state ResetHandler::hardrst_indicate_hard_reset() { ResetHandler::hardrst_state ResetHandler::hardrst_indicate_hard_reset() {
@@ -100,8 +103,7 @@ void ResetHandler::init() {
} }
void ResetHandler::notify(uint32_t notification) { void ResetHandler::notify(uint32_t notification) {
xTaskNotify(TaskHandle, notification, xTaskNotify(TaskHandle, notification, eNotifyAction::eSetBits);
eNotifyAction::eSetBits);
} }
void ResetHandler::Thread(const void *arg) { void ResetHandler::Thread(const void *arg) {
@@ -134,6 +136,7 @@ void ResetHandler::Thread(const void *arg) {
default: default:
/* This is an error. It really shouldn't happen. We might /* This is an error. It really shouldn't happen. We might
* want to handle it anyway, though. */ * want to handle it anyway, though. */
state = PRLHRResetLayer;
break; break;
} }
} }

View File

@@ -33,7 +33,7 @@ public:
private: private:
static void Thread(const void *arg); static void Thread(const void *arg);
static osThreadId TaskHandle; static osThreadId TaskHandle;
static const size_t TaskStackSize = 1024 / 4; static const size_t TaskStackSize = 1536 / 4;
static uint32_t TaskBuffer[TaskStackSize]; static uint32_t TaskBuffer[TaskStackSize];
static osStaticThreadDef_t TaskControlBlock; static osStaticThreadDef_t TaskControlBlock;
static uint32_t waitForEvent(uint32_t mask, uint32_t ticksToWait = static uint32_t waitForEvent(uint32_t mask, uint32_t ticksToWait =

View File

@@ -25,6 +25,7 @@
#include "policy_engine.h" #include "policy_engine.h"
#include "protocol_rx.h" #include "protocol_rx.h"
#include "protocol_tx.h" #include "protocol_tx.h"
#include "task.h"
#include "BSP.h" #include "BSP.h"
osThreadId InterruptHandler::TaskHandle; osThreadId InterruptHandler::TaskHandle;
@@ -32,39 +33,40 @@ uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
osStaticThreadDef_t InterruptHandler::TaskControlBlock; osStaticThreadDef_t InterruptHandler::TaskControlBlock;
void InterruptHandler::init() { void InterruptHandler::init() {
osThreadStaticDef(Task, Thread, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, osThreadStaticDef(Task, Thread, PDB_PRIO_PRL_INT_N, 0, TaskStackSize,
&TaskControlBlock); TaskBuffer, &TaskControlBlock);
TaskHandle = osThreadCreate(osThread(Task), NULL); TaskHandle = osThreadCreate(osThread(Task), NULL);
} }
void InterruptHandler::Thread(const void *arg) { void InterruptHandler::Thread(const void *arg) {
(void) arg; (void) arg;
union fusb_status status; union fusb_status status;
eventmask_t events; volatile uint32_t events;
while (true) { while (true) {
/* If the INT_N line is low */ /* If the INT_N line is low */
xTaskNotifyWait(0x00, 0x0F, NULL, 5); xTaskNotifyWait(0x00, 0x0F, NULL, 100);
/* Read the FUSB302B status and interrupt registers */ /* Read the FUSB302B status and interrupt registers */
fusb_get_status(&status); fusb_get_status(&status);
//Check for rx alerts
/* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
//This means a message was recieved with a good CRC
if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) { if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {
ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT); ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT);
} }
if ((status.status1 & FUSB_STATUS1_RX_EMPTY) == 0) {
ProtocolReceive::notify(PDB_EVT_PRLRX_I_GCRCSENT);
}
/* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX
* thread */ * thread */
events = 0; events = 0;
if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) {
events |= PDB_EVT_PRLTX_I_RETRYFAIL;
}
if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) { if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) {
events |= PDB_EVT_PRLTX_I_TXSENT; ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_TXSENT);
} }
if (events) { if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) {
ProtocolTransmit::notify(events); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
} }
/* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset /* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset
@@ -72,25 +74,25 @@ void InterruptHandler::Thread(const void *arg) {
events = 0; events = 0;
if (status.interrupta & FUSB_INTERRUPTA_I_HARDRST) { if (status.interrupta & FUSB_INTERRUPTA_I_HARDRST) {
events |= PDB_EVT_HARDRST_I_HARDRST; // events |= PDB_EVT_HARDRST_I_HARDRST;
} } else if (status.interrupta & FUSB_INTERRUPTA_I_HARDSENT) {
if (status.interrupta & FUSB_INTERRUPTA_I_HARDSENT) {
events |= PDB_EVT_HARDRST_I_HARDSENT; events |= PDB_EVT_HARDRST_I_HARDSENT;
} }
if (events) { if (events) {
ResetHandler::notify(events); ResetHandler::notify(events);
} }
/* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy /* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy
* Engine thread */ * Engine thread */
if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP
&& status.status1 & FUSB_STATUS1_OVRTEMP) { && status.status1 & FUSB_STATUS1_OVRTEMP) {
PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP); PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP);
} }
} }
} }
volatile uint8_t irqs = 0;
void InterruptHandler::irqCallback() { void InterruptHandler::irqCallback() {
xTaskNotify(TaskHandle, 0x0F, eNotifyAction::eSetBits); irqs++;
BaseType_t taskWoke = pdFALSE;
xTaskNotifyFromISR(TaskHandle, 0x0F, eNotifyAction::eSetBits, &taskWoke);
portYIELD_FROM_ISR(taskWoke);
} }

View File

@@ -30,7 +30,7 @@ public:
private: private:
static void Thread(const void *arg); static void Thread(const void *arg);
static osThreadId TaskHandle; static osThreadId TaskHandle;
static const size_t TaskStackSize = 1024 / 4; static const size_t TaskStackSize = 1536 / 4;
static uint32_t TaskBuffer[TaskStackSize]; static uint32_t TaskBuffer[TaskStackSize];
static osStaticThreadDef_t TaskControlBlock; static osStaticThreadDef_t TaskControlBlock;
/* /*

View File

@@ -273,18 +273,18 @@
* Where a range is specified, the middle of the range (rounded down to the * Where a range is specified, the middle of the range (rounded down to the
* nearest millisecond) is used. * nearest millisecond) is used.
*/ */
#define PD_T_CHUNKING_NOT_SUPPORTED (45) #define PD_T_CHUNKING_NOT_SUPPORTED (450)
#define PD_T_HARD_RESET_COMPLETE (4) #define PD_T_HARD_RESET_COMPLETE (400)
#define PD_T_PS_TRANSITION (500) #define PD_T_PS_TRANSITION (5000)
#define PD_T_SENDER_RESPONSE (27) #define PD_T_SENDER_RESPONSE (2700)
#define PD_T_SINK_REQUEST (100) #define PD_T_SINK_REQUEST (1000)
#define PD_T_TYPEC_SINK_WAIT_CAP (465) #define PD_T_TYPEC_SINK_WAIT_CAP (5000)
#define PD_T_PD_DEBOUNCE (15) #define PD_T_PD_DEBOUNCE (2000)
/* /*
* Counter maximums * Counter maximums
*/ */
#define PD_N_HARD_RESET_COUNT 10 #define PD_N_HARD_RESET_COUNT 20
/* /*
* Value parameters * Value parameters

View File

@@ -181,13 +181,13 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) { if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) {
/* If the other end is using at least version 3.0, we'll /* If the other end is using at least version 3.0, we'll
* use version 3.0. */ * use version 3.0. */
if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) { // if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) {
hdr_template |= PD_SPECREV_3_0; // hdr_template |= PD_SPECREV_3_0;
/* Otherwise, use 2.0. Don't worry about the 1.0 case // /* Otherwise, use 2.0. Don't worry about the 1.0 case
* because we don't have hardware for PD 1.0 signaling. */ // * because we don't have hardware for PD 1.0 signaling. */
} else { // } else {
hdr_template |= PD_SPECREV_2_0; hdr_template |= PD_SPECREV_2_0;
} // }
} }
return PESinkEvalCap; return PESinkEvalCap;
/* If the message was a Soft_Reset, do the soft reset procedure */ /* If the message was a Soft_Reset, do the soft reset procedure */
@@ -247,7 +247,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
/* Transmit the request */ /* Transmit the request */
ProtocolTransmit::pushMessage(&_last_dpm_request); ProtocolTransmit::pushMessage(&_last_dpm_request);
//Send indication that there is a message pending //Send indication that there is a message pending
ProtocolTransmit::notify( PDB_EVT_PRLTX_MSG_TX); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
/* Don't free the request; we might need it again */ /* Don't free the request; we might need it again */
@@ -396,7 +397,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
/* If the DPM wants us to, send a Get_Source_Cap message */ /* If the DPM wants us to, send a Get_Source_Cap message */
if (evt & PDB_EVT_PE_GET_SOURCE_CAP) { if (evt & PDB_EVT_PE_GET_SOURCE_CAP) {
/* Tell the protocol layer we're starting an AMS */ /* Tell the protocol layer we're starting an AMS */
ProtocolTransmit::notify( PDB_EVT_PRLTX_START_AMS); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_START_AMS);
return PESinkGetSourceCap; return PESinkGetSourceCap;
} }
@@ -406,14 +408,16 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
* design of this firmware. */ * design of this firmware. */
if (evt & PDB_EVT_PE_NEW_POWER) { if (evt & PDB_EVT_PE_NEW_POWER) {
/* Tell the protocol layer we're starting an AMS */ /* Tell the protocol layer we're starting an AMS */
ProtocolTransmit::notify( PDB_EVT_PRLTX_START_AMS); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_START_AMS);
return PESinkEvalCap; return PESinkEvalCap;
} }
/* If SinkPPSPeriodicTimer ran out, send a new request */ /* If SinkPPSPeriodicTimer ran out, send a new request */
if (evt & PDB_EVT_PE_PPS_REQUEST) { if (evt & PDB_EVT_PE_PPS_REQUEST) {
/* Tell the protocol layer we're starting an AMS */ /* Tell the protocol layer we're starting an AMS */
ProtocolTransmit::notify( PDB_EVT_PRLTX_START_AMS); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_START_AMS);
return PESinkSelectCap; return PESinkSelectCap;
} }
@@ -538,7 +542,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() {
| PD_NUMOBJ(0); | PD_NUMOBJ(0);
/* Transmit the Get_Source_Cap */ /* Transmit the Get_Source_Cap */
ProtocolTransmit::pushMessage(get_source_cap); ProtocolTransmit::pushMessage(get_source_cap);
ProtocolTransmit::notify( PDB_EVT_PRLTX_MSG_TX); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
/* Free the sent message */ /* Free the sent message */
@@ -562,7 +567,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() {
/* Transmit our capabilities */ /* Transmit our capabilities */
ProtocolTransmit::pushMessage(snk_cap); ProtocolTransmit::pushMessage(snk_cap);
ProtocolTransmit::notify( PDB_EVT_PRLTX_MSG_TX); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
@@ -623,7 +629,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() {
accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0); accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
/* Transmit the Accept */ /* Transmit the Accept */
ProtocolTransmit::pushMessage(&accept); ProtocolTransmit::pushMessage(&accept);
ProtocolTransmit::notify( PDB_EVT_PRLTX_MSG_TX); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
/* Free the sent message */ /* Free the sent message */
@@ -650,7 +657,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0); softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
/* Transmit the soft reset */ /* Transmit the soft reset */
ProtocolTransmit::pushMessage(softrst); ProtocolTransmit::pushMessage(softrst);
ProtocolTransmit::notify( PDB_EVT_PRLTX_MSG_TX); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
/* If we got reset signaling, transition to default */ /* If we got reset signaling, transition to default */
@@ -711,7 +719,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
/* Transmit the message */ /* Transmit the message */
ProtocolTransmit::pushMessage(not_supported); ProtocolTransmit::pushMessage(not_supported);
ProtocolTransmit::notify( PDB_EVT_PRLTX_MSG_TX); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
eventmask_t evt = waitForEvent( eventmask_t evt = waitForEvent(
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);

View File

@@ -116,7 +116,7 @@ private:
portMAX_DELAY); portMAX_DELAY);
//Task resources //Task resources
static osThreadId TaskHandle; static osThreadId TaskHandle;
static const size_t TaskStackSize = 1024 / 4; static const size_t TaskStackSize = 2048 / 4;
static uint32_t TaskBuffer[TaskStackSize]; static uint32_t TaskBuffer[TaskStackSize];
static osStaticThreadDef_t TaskControlBlock; static osStaticThreadDef_t TaskControlBlock;
static union pd_msg tempMessage; static union pd_msg tempMessage;

View File

@@ -39,7 +39,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
/* If we got a reset event, reset */ /* If we got a reset event, reset */
if (evt & PDB_EVT_PRLRX_RESET) { if (evt & PDB_EVT_PRLRX_RESET) {
waitForEvent(PDB_EVT_PRLRX_RESET, 0); // waitForEvent(PDB_EVT_PRLRX_RESET, 0);
return PRLRxWaitPHY; return PRLRxWaitPHY;
} }
/* If we got an I_GCRCSENT event, read the message and decide what to do */ /* If we got an I_GCRCSENT event, read the message and decide what to do */
@@ -73,7 +73,8 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
_rx_messageid = -1; _rx_messageid = -1;
/* TX transitions to its reset state */ /* TX transitions to its reset state */
ProtocolTransmit::notify( PDB_EVT_PRLTX_RESET); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
taskYIELD(); taskYIELD();
/* If we got a RESET signal, reset the machine */ /* If we got a RESET signal, reset the machine */
@@ -84,7 +85,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
/* Go to the Check_MessageID state */ /* Go to the Check_MessageID state */
return PRLRxCheckMessageID; return PRLRxCheckMessageID;
} }
volatile uint32_t rxCounter = 0;
/* /*
* PRL_Rx_Check_MessageID state * PRL_Rx_Check_MessageID state
*/ */
@@ -101,7 +102,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid(
/*if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) { /*if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
return PRLRxWaitPHY; return PRLRxWaitPHY;
} else*/ } else*/
rxCounter++;
{ {
return PRLRxStoreMessageID; return PRLRxStoreMessageID;
} }
@@ -113,7 +114,8 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid(
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid() { ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid() {
/* Tell ProtocolTX to discard the message being transmitted */ /* Tell ProtocolTX to discard the message being transmitted */
ProtocolTransmit::notify( PDB_EVT_PRLTX_DISCARD); ProtocolTransmit::notify(
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
taskYIELD(); taskYIELD();
/* Update the stored MessageID */ /* Update the stored MessageID */
@@ -163,6 +165,9 @@ void ProtocolReceive::thread(const void *args) {
} }
void ProtocolReceive::notify(uint32_t notification) { void ProtocolReceive::notify(uint32_t notification) {
if (notification == PDB_EVT_PRLRX_I_GCRCSENT) {
// asm("bkpt");
}
xTaskNotify(TaskHandle, notification, eNotifyAction::eSetBits); xTaskNotify(TaskHandle, notification, eNotifyAction::eSetBits);
} }

View File

@@ -34,7 +34,7 @@ private:
static void thread(const void *args); static void thread(const void *args);
static osThreadId TaskHandle; static osThreadId TaskHandle;
static const size_t TaskStackSize = 512 / 4; static const size_t TaskStackSize = 1024 / 4;
static uint32_t TaskBuffer[TaskStackSize]; static uint32_t TaskBuffer[TaskStackSize];
static osStaticThreadDef_t TaskControlBlock; static osStaticThreadDef_t TaskControlBlock;
/* /*

View File

@@ -59,18 +59,20 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
*/ */
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message() { ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message() {
/* Wait for an event */ /* Wait for an event */
eventmask_t evt = waitForEvent( ProtocolTransmit::Notifications evt = waitForEvent(
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD | PDB_EVT_PRLTX_MSG_TX); (uint32_t) Notifications::PDB_EVT_PRLTX_RESET
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
| (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX);
if (evt & PDB_EVT_PRLTX_RESET) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
return PRLTxPHYReset; return PRLTxPHYReset;
} }
if (evt & PDB_EVT_PRLTX_DISCARD) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
return PRLTxDiscardMessage; return PRLTxDiscardMessage;
} }
/* If the policy engine is trying to send a message */ /* If the policy engine is trying to send a message */
if (evt & PDB_EVT_PRLTX_MSG_TX) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX) {
/* Get the message */ /* Get the message */
getMessage(); getMessage();
@@ -104,13 +106,14 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
*/ */
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() { ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() {
/* Make sure nobody wants us to reset */ /* Make sure nobody wants us to reset */
eventmask_t evt = waitForEvent( ProtocolTransmit::Notifications evt = waitForEvent(
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD, 0); (uint32_t) Notifications::PDB_EVT_PRLTX_RESET
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD, 0);
if (evt & PDB_EVT_PRLTX_RESET) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
return PRLTxPHYReset; return PRLTxPHYReset;
} }
if (evt & PDB_EVT_PRLTX_DISCARD) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
return PRLTxDiscardMessage; return PRLTxDiscardMessage;
} }
@@ -121,8 +124,9 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
/* PD 3.0 collision avoidance */ /* PD 3.0 collision avoidance */
if (PolicyEngine::isPD3_0()) { if (PolicyEngine::isPD3_0()) {
/* If we're starting an AMS, wait for permission to transmit */ /* If we're starting an AMS, wait for permission to transmit */
evt = waitForEvent(PDB_EVT_PRLTX_START_AMS, 0); evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
if (evt & PDB_EVT_PRLTX_START_AMS) { 0);
if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
while (fusb_get_typec_current() != fusb_sink_tx_ok) { while (fusb_get_typec_current() != fusb_sink_tx_ok) {
osDelay(1); osDelay(1);
} }
@@ -141,23 +145,25 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_response() { ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_response() {
/* Wait for an event. There is no need to run CRCReceiveTimer, since the /* Wait for an event. There is no need to run CRCReceiveTimer, since the
* FUSB302B handles that as part of its retry mechanism. */ * FUSB302B handles that as part of its retry mechanism. */
eventmask_t evt = waitForEvent( ProtocolTransmit::Notifications evt = waitForEvent(
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD | PDB_EVT_PRLTX_I_TXSENT (uint32_t) Notifications::PDB_EVT_PRLTX_RESET
| PDB_EVT_PRLTX_I_RETRYFAIL); | (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
| (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT
| (uint32_t) Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
if (evt & PDB_EVT_PRLTX_RESET) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
return PRLTxPHYReset; return PRLTxPHYReset;
} }
if (evt & PDB_EVT_PRLTX_DISCARD) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
return PRLTxDiscardMessage; return PRLTxDiscardMessage;
} }
/* If the message was sent successfully */ /* If the message was sent successfully */
if (evt & PDB_EVT_PRLTX_I_TXSENT) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT) {
return PRLTxMatchMessageID; return PRLTxMatchMessageID;
} }
/* If the message failed to be sent */ /* If the message failed to be sent */
if (evt & PDB_EVT_PRLTX_I_RETRYFAIL) { if ((uint32_t)evt & (uint32_t) Notifications::PDB_EVT_PRLTX_I_RETRYFAIL) {
return PRLTxTransmissionError; return PRLTxTransmissionError;
} }
@@ -253,16 +259,16 @@ void ProtocolTransmit::thread(const void *args) {
} }
} }
void ProtocolTransmit::notify(uint32_t notification) { void ProtocolTransmit::notify(ProtocolTransmit::Notifications notification) {
xTaskNotify(TaskHandle, notification, eNotifyAction::eSetBits); xTaskNotify(TaskHandle, (uint32_t )notification, eNotifyAction::eSetBits);
} }
void ProtocolTransmit::init() { void ProtocolTransmit::init() {
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue); sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PE, 0, TaskStackSize,
TaskStackSize, TaskBuffer, &TaskControlBlock); TaskBuffer, &TaskControlBlock);
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL); TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
} }
@@ -279,8 +285,9 @@ void ProtocolTransmit::getMessage() {
xQueueReceive(messagesWaiting, &temp_msg, 1); xQueueReceive(messagesWaiting, &temp_msg, 1);
} }
uint32_t ProtocolTransmit::waitForEvent(uint32_t mask, uint32_t ticksToWait) { ProtocolTransmit::Notifications ProtocolTransmit::waitForEvent(uint32_t mask,
uint32_t ticksToWait) {
uint32_t pulNotificationValue; uint32_t pulNotificationValue;
xTaskNotifyWait(0x00, mask, &pulNotificationValue, ticksToWait); xTaskNotifyWait(0x00, mask, &pulNotificationValue, ticksToWait);
return pulNotificationValue & mask; return (Notifications) (pulNotificationValue & mask);
} }

View File

@@ -24,24 +24,28 @@
#include <pd.h> #include <pd.h>
/* Events for the Protocol TX thread */ /* Events for the Protocol TX thread */
#define PDB_EVT_PRLTX_RESET EVENT_MASK(0)
#define PDB_EVT_PRLTX_I_TXSENT EVENT_MASK(1)
#define PDB_EVT_PRLTX_I_RETRYFAIL EVENT_MASK(2)
#define PDB_EVT_PRLTX_DISCARD EVENT_MASK(3)
#define PDB_EVT_PRLTX_MSG_TX EVENT_MASK(4)
#define PDB_EVT_PRLTX_START_AMS EVENT_MASK(5)
class ProtocolTransmit { class ProtocolTransmit {
public: public:
static void init(); static void init();
//Push a message to the queue to be sent out the pd comms bus //Push a message to the queue to be sent out the pd comms bus
static void pushMessage(union pd_msg *msg); static void pushMessage(union pd_msg *msg);
static void notify(uint32_t notification);
enum class Notifications {
PDB_EVT_PRLTX_RESET = EVENT_MASK(0), //
PDB_EVT_PRLTX_I_TXSENT = EVENT_MASK(1), //
PDB_EVT_PRLTX_I_RETRYFAIL = EVENT_MASK(2), //
PDB_EVT_PRLTX_DISCARD = EVENT_MASK(3), //
PDB_EVT_PRLTX_MSG_TX = EVENT_MASK(4), //
PDB_EVT_PRLTX_START_AMS = EVENT_MASK(5), //
};
static void notify(Notifications notification);
private: private:
static void thread(const void *args); static void thread(const void *args);
static osThreadId TaskHandle; static osThreadId TaskHandle;
static const size_t TaskStackSize = 512 / 4; static const size_t TaskStackSize = 1024 / 4;
static uint32_t TaskBuffer[TaskStackSize]; static uint32_t TaskBuffer[TaskStackSize];
static osStaticThreadDef_t TaskControlBlock; static osStaticThreadDef_t TaskControlBlock;
/* /*
@@ -83,7 +87,7 @@ private:
//Reads a message off the queue into the temp message //Reads a message off the queue into the temp message
static void getMessage(); static void getMessage();
static union pd_msg temp_msg; static union pd_msg temp_msg;
static uint32_t waitForEvent(uint32_t mask, uint32_t ticksToWait = static Notifications waitForEvent(uint32_t mask, uint32_t ticksToWait =
portMAX_DELAY); portMAX_DELAY);
}; };

View File

@@ -213,7 +213,7 @@ void OLED::useSecondaryFramebuffer(bool useSecondary) {
} }
void OLED::setRotation(bool leftHanded) { void OLED::setRotation(bool leftHanded) {
#ifdef MODEL_TS80 #if defined( MODEL_TS80) +defined( MODEL_TS80P) > 0
leftHanded = !leftHanded; leftHanded = !leftHanded;
#endif #endif
if (inLeftHandedMode == leftHanded) { if (inLeftHandedMode == leftHanded) {

View File

@@ -27,7 +27,6 @@
* This was bought to my attention by <Kuba Sztandera> * This was bought to my attention by <Kuba Sztandera>
*/ */
uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) { uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
// This takes the raw ADC samples, converts these to uV // This takes the raw ADC samples, converts these to uV
// Then divides this down by the gain to convert to the uV on the input to the op-amp (A+B terminals) // Then divides this down by the gain to convert to the uV on the input to the op-amp (A+B terminals)
@@ -76,7 +75,7 @@ uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
tipuVDelta *= 10; tipuVDelta *= 10;
tipuVDelta /= systemSettings.TipGain; tipuVDelta /= systemSettings.TipGain;
#ifdef MODEL_TS80 #if defined( MODEL_TS80)+defined( MODEL_TS80P)>0
tipuVDelta /= OP_AMP_GAIN_STAGE_TS100 / OP_AMP_GAIN_STAGE_TS80; tipuVDelta /= OP_AMP_GAIN_STAGE_TS100 / OP_AMP_GAIN_STAGE_TS80;
#endif #endif

View File

@@ -98,11 +98,11 @@ extern uint32_t SystemCoreClock;
#define configUSE_IDLE_HOOK 1 #define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0 #define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ((TickType_t)100) #define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 6 ) #define configMAX_PRIORITIES ( 6 )
#define configMINIMAL_STACK_SIZE ((uint16_t)256) #define configMINIMAL_STACK_SIZE ((uint16_t)256)
#define configTOTAL_HEAP_SIZE ((size_t)1024*14) /*Currently use about 9000*/ #define configTOTAL_HEAP_SIZE ((size_t)1024*14) /*Currently use about 9000*/
#define configMAX_TASK_NAME_LEN ( 24 ) #define configMAX_TASK_NAME_LEN ( 32 )
#define configUSE_16_BIT_TICKS 0 #define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1 #define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8 #define configQUEUE_REGISTRY_SIZE 8

View File

@@ -338,7 +338,6 @@
#include "stm32f1xx_hal_hcd.h" #include "stm32f1xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */ #endif /* HAL_HCD_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT
/** /**

View File

@@ -37,6 +37,7 @@ void vApplicationStackOverflowHook(xTaskHandle *pxTask,
signed portCHAR *pcTaskName) { signed portCHAR *pcTaskName) {
(void) pxTask; (void) pxTask;
(void) pcTaskName; (void) pcTaskName;
asm("bkpt");
// We dont have a good way to handle a stack overflow at this point in time // We dont have a good way to handle a stack overflow at this point in time
reboot(); reboot();
} }

View File

@@ -30,16 +30,16 @@ void QC_SeekContMode() {
} }
void QC_SeekContPlus() { void QC_SeekContPlus() {
QC_SeekContMode(); QC_SeekContMode();
vTaskDelay(3); osDelay(30);
QC_Seek20V(); QC_Seek20V();
vTaskDelay(1); osDelay(10);
QC_SeekContMode(); QC_SeekContMode();
} }
void QC_SeekContNeg() { void QC_SeekContNeg() {
QC_SeekContMode(); QC_SeekContMode();
vTaskDelay(3); osDelay(30);
QC_Seek12V(); QC_Seek12V();
vTaskDelay(1); osDelay(10);
QC_SeekContMode(); QC_SeekContMode();
} }
uint8_t QCMode = 0; uint8_t QCMode = 0;
@@ -65,15 +65,15 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
if (steps > -2 && steps < 2) return; // dont bother with small steps if (steps > -2 && steps < 2) return; // dont bother with small steps
while (steps < 0) { while (steps < 0) {
QC_SeekContNeg(); QC_SeekContNeg();
vTaskDelay(3); osDelay(30);
steps++; steps++;
} }
while (steps > 0) { while (steps > 0) {
QC_SeekContPlus(); QC_SeekContPlus();
vTaskDelay(3); osDelay(30);
steps--; steps--;
} }
vTaskDelay(10); osDelay(100);
} }
#ifdef ENABLE_QC2 #ifdef ENABLE_QC2
// Re-measure // Re-measure
@@ -118,7 +118,7 @@ void startQC(uint16_t divisor) {
// Delay 1.25 seconds // Delay 1.25 seconds
uint8_t enteredQC = 0; uint8_t enteredQC = 0;
for (uint16_t i = 0; i < 200 && enteredQC == 0; i++) { for (uint16_t i = 0; i < 200 && enteredQC == 0; i++) {
vTaskDelay(1); // 10mS pause osDelay(10); // 10mS pause
if (i > 130) { if (i > 130) {
if (QC_DM_PulledDown()) { if (QC_DM_PulledDown()) {
enteredQC = 1; enteredQC = 1;
@@ -143,7 +143,7 @@ void startQC(uint16_t divisor) {
QCMode = 3; // We have at least QC2, pray for 3 QCMode = 3; // We have at least QC2, pray for 3
return; return;
} }
vTaskDelay(10); // 100mS osDelay(100); // 100mS
} }
QCMode = 5; QCMode = 5;
QCTries++; QCTries++;

View File

@@ -739,7 +739,7 @@ static void settings_setCalibrateVIN(void) {
osDelay(40); osDelay(40);
// Cap to sensible values // Cap to sensible values
#ifdef MODEL_TS80 #if defined(MODEL_TS80)+defined(MODEL_TS80P)>0
if (systemSettings.voltageDiv < 500) { if (systemSettings.voltageDiv < 500) {
systemSettings.voltageDiv = 500; systemSettings.voltageDiv = 500;
} else if (systemSettings.voltageDiv > 900) { } else if (systemSettings.voltageDiv > 900) {

View File

@@ -43,7 +43,7 @@ int main(void) {
OLED::setFont(0); // default to bigger font OLED::setFont(0); // default to bigger font
// Testing for which accelerometer is mounted // Testing for which accelerometer is mounted
resetWatchdog(); resetWatchdog();
usb_pd_available = usb_pd_detect(); usb_pd_available = true;//usb_pd_detect();
resetWatchdog(); resetWatchdog();
settingsWereReset = restoreSettings(); // load the settings from flash settingsWereReset = restoreSettings(); // load the settings from flash
/*if (MMA8652FC::detect()) { /*if (MMA8652FC::detect()) {
@@ -68,10 +68,10 @@ int main(void) {
GUITaskStackSize, GUITaskBuffer, &GUITaskControlBlock); GUITaskStackSize, GUITaskBuffer, &GUITaskControlBlock);
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL); GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
/* definition and creation of PIDTask */ // /* definition and creation of PIDTask */
osThreadStaticDef(PIDTask, startPIDTask, osPriorityRealtime, 0, // osThreadStaticDef(PIDTask, startPIDTask, osPriorityRealtime, 0,
PIDTaskStackSize, PIDTaskBuffer, &PIDTaskControlBlock); // PIDTaskStackSize, PIDTaskBuffer, &PIDTaskControlBlock);
PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL); // PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL);
osThreadStaticDef(MOVTask, startMOVTask, osPriorityNormal, 0, osThreadStaticDef(MOVTask, startMOVTask, osPriorityNormal, 0,
MOVTaskStackSize, MOVTaskBuffer, &MOVTaskControlBlock); MOVTaskStackSize, MOVTaskBuffer, &MOVTaskControlBlock);

View File

@@ -247,7 +247,7 @@ static void gui_solderingTempAdjust() {
if (xTaskGetTickCount() - lastChange > 200) if (xTaskGetTickCount() - lastChange > 200)
return; // exit if user just doesn't press anything for a bit return; // exit if user just doesn't press anything for a bit
#ifdef MODEL_TS80 #if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
if (!OLED::getRotation()) { if (!OLED::getRotation()) {
#else #else
if (OLED::getRotation()) { if (OLED::getRotation()) {
@@ -272,7 +272,7 @@ static void gui_solderingTempAdjust() {
OLED::drawSymbol(1); OLED::drawSymbol(1);
} }
OLED::print(SymbolSpace); OLED::print(SymbolSpace);
#ifdef MODEL_TS80 #if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
if (!OLED::getRotation()) { if (!OLED::getRotation()) {
#else #else
if (OLED::getRotation()) { if (OLED::getRotation()) {
@@ -770,7 +770,7 @@ void startGUITask(void const *argument __unused) {
} else { } else {
OLED::setFont(0); OLED::setFont(0);
#ifdef MODEL_TS80 #if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
if (!OLED::getRotation()) { if (!OLED::getRotation()) {
#else #else
if (OLED::getRotation()) { if (OLED::getRotation()) {
@@ -791,7 +791,7 @@ void startGUITask(void const *argument __unused) {
if (tempOnDisplay) { if (tempOnDisplay) {
// draw temp over the start soldering button // draw temp over the start soldering button
// Location changes on screen rotation // Location changes on screen rotation
#ifdef MODEL_TS80 #if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
if (!OLED::getRotation()) { if (!OLED::getRotation()) {
#else #else
if (OLED::getRotation()) { if (OLED::getRotation()) {

View File

@@ -14,9 +14,9 @@ MEMORY
{ {
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
/* LOCAL_BUILD*/ /* LOCAL_BUILD*/
/*ROM (rx) : ORIGIN = 0x08000000, LENGTH = 46K*/ ROM (rx) : ORIGIN = 0x08000000, LENGTH = 46K
/* production*/ /* production*/
ROM (rx) : ORIGIN = 0x08004000, LENGTH = 46K /*ROM (rx) : ORIGIN = 0x08004000, LENGTH = 46K*/

View File

@@ -108,7 +108,6 @@
#endif #endif
#ifdef MODEL_TS80 #ifdef MODEL_TS80
#define VOLTAGE_DIV_TS80P 768 // Default for TS80P with slightly different resistors
#define VOLTAGE_DIV 780 // Default divider from schematic #define VOLTAGE_DIV 780 // Default divider from schematic
#define PID_POWER_LIMIT 24 // Sets the max pwm power limit #define PID_POWER_LIMIT 24 // Sets the max pwm power limit
#define CALIBRATION_OFFSET 900 // the adc offset in uV #define CALIBRATION_OFFSET 900 // the adc offset in uV