* Remove unused includes * Adding in submodule * Move fusb functions to the BSP * Remove old code * Creating IronOS PD integration wrapper * Redirect to wrapper * pd lib updates * fix Docker build * Finish linking across * Cleanup * Update Makefile * Update push.yml * Update push.yml * PD -> Compensate for different tick rates * Update codeql-analysis.yml * Fix PD #define for @Firebie * Check irq low at start * Update BSP.h * Update main.cpp * Closer delay * Update OLED.cpp * Bugfix trying to start QC too early * Missing fusb shouldnt hang qc * Update FreeRTOSConfig.h * Update the GD drivers * Update Pinecil IRQ setup * Redirect printf() to uart * Update Power.cpp * Adding extras to PD state * Update USBPD.cpp * Delay in printf * Iterate once before delay on start * Update usb-pd * master usb-pd now * Format gd libs * Update gd32vf103_bkp.c * Guard with PD timeout * Remove CodeQL * Slow for testing, fix runt pulses at start * Fix runt pulse in read size 1 * Cleaner probing setup * Testing delay during stop gen in read 1 * Update I2C driver * Update gd32vf103_i2c.c * Cleaning up i2c wrapper a little, given up on dma for rx * Update preRTOS.cpp * Update Setup.cpp * Update MOVThread.cpp * Slow down UART to work with new clock config * Better ack setup for 2 byte read * Cleanup POW_PD so cant be lost in #includes * tipResistance -> TIP_RESISTANCE * handle NOP race on len==2 * Update configuration.h * Dont use neg timeout to mask anymore * Not required for MHP * Fix up source display Miniware * Fix race on PD init * Update POWThread.cpp * Update formatting * MHP format * Update push.yml * Faster TS80P I2C * Bugfix for IRQ handlers * Correctly handle I2C race on PD access * Fix CI error (unused var) and MHP IRQ * Test Pinecil alt ADC mode
62 lines
2.3 KiB
C++
62 lines
2.3 KiB
C++
/*
|
|
* Debug.cpp
|
|
*
|
|
* Created on: 26 Jan. 2021
|
|
* Author: Ralim
|
|
*/
|
|
#include "Debug.h"
|
|
#include "FreeRTOS.h"
|
|
#include "Pins.h"
|
|
|
|
extern "C" {
|
|
|
|
#include "gd32vf103_usart.h"
|
|
}
|
|
char uartOutputBuffer[uartOutputBufferLength];
|
|
volatile uint32_t currentOutputPos = 0xFF;
|
|
volatile uint32_t outputLength = 0;
|
|
extern volatile uint8_t pendingPWM;
|
|
void log_system_state(int32_t PWMWattsx10) {
|
|
if (currentOutputPos == 0xFF) {
|
|
|
|
// Want to print a CSV log out the uart
|
|
// Tip_Temp_C,Handle_Temp_C,Output_Power_Wattx10,PWM,Tip_Raw\r\n
|
|
// 3+1+3+1+3+1+3+1+5+2 = 23, so sizing at 32 for now
|
|
|
|
outputLength = snprintf(uartOutputBuffer, uartOutputBufferLength, "%lu,%u,%li,%u,%lu\r\n", //
|
|
TipThermoModel::getTipInC(false), // Tip temp in C
|
|
getHandleTemperature(0), // Handle temp in C X10
|
|
PWMWattsx10, // Output Wattage
|
|
pendingPWM, // PWM
|
|
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true) // Tip temp in uV
|
|
);
|
|
|
|
// Now print this out the uart via IRQ (DMA cant be used as oled has it)
|
|
currentOutputPos = 0;
|
|
/* enable USART1 Transmit Buffer Empty interrupt */
|
|
usart_interrupt_enable(UART_PERIF, USART_INT_TBE);
|
|
}
|
|
}
|
|
ssize_t _write(int fd, const void *ptr, size_t len) {
|
|
if (len > uartOutputBufferLength) {
|
|
len = uartOutputBufferLength;
|
|
}
|
|
outputLength = len;
|
|
currentOutputPos = 0;
|
|
memcpy(uartOutputBuffer, ptr, len);
|
|
/* enable USART1 Transmit Buffer Empty interrupt */
|
|
usart_interrupt_enable(UART_PERIF, USART_INT_TBE);
|
|
delay_ms(1);
|
|
return len;
|
|
}
|
|
void USART1_IRQHandler(void) {
|
|
if (RESET != usart_interrupt_flag_get(UART_PERIF, USART_INT_FLAG_TBE)) {
|
|
/* write one byte to the transmit data register */
|
|
usart_data_transmit(UART_PERIF, uartOutputBuffer[currentOutputPos++]);
|
|
if (currentOutputPos >= outputLength) {
|
|
currentOutputPos = 0xFF; // Mark done
|
|
usart_interrupt_disable(UART_PERIF, USART_INT_TBE);
|
|
}
|
|
}
|
|
}
|