@ -80,55 +80,58 @@ int8_t cal_auto_interpolate = TRUE;
uint16_t redraw_request = 0 ; // contains REDRAW_XXX flags
uint16_t redraw_request = 0 ; // contains REDRAW_XXX flags
int16_t vbat = 0 ;
int16_t vbat = 0 ;
static THD_WORKING_AREA ( waThread1 , 512 ) ;
//
// Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show:
// Stack maximum usage = 480 bytes, free stack = 32+64 bytes
//
static THD_WORKING_AREA ( waThread1 , 512 + 64 ) ;
static THD_FUNCTION ( Thread1 , arg )
static THD_FUNCTION ( Thread1 , arg )
{
{
( void ) arg ;
( void ) arg ;
chRegSetThreadName ( " sweep " ) ;
chRegSetThreadName ( " sweep " ) ;
while ( 1 ) {
while ( 1 ) {
bool completed = false ;
bool completed = false ;
if ( sweep_enabled | | sweep_once ) {
if ( sweep_enabled | | sweep_once ) {
chMtxLock ( & mutex ) ;
chMtxLock ( & mutex ) ;
// Sweep require 8367 system tick
// Sweep require 8367 system tick
completed = sweep ( true ) ;
completed = sweep ( true ) ;
sweep_once = FALSE ;
sweep_once = FALSE ;
chMtxUnlock ( & mutex ) ;
chMtxUnlock ( & mutex ) ;
} else {
} else {
__WFI ( ) ;
__WFI ( ) ;
}
chMtxLock ( & mutex ) ;
// Ui and render require 800 system tick
ui_process ( ) ;
if ( sweep_enabled ) {
if ( vbat ! = - 1 ) {
adc_stop ( ADC1 ) ;
vbat = adc_vbat_read ( ADC1 ) ;
touch_start_watchdog ( ) ;
draw_battery_status ( ) ;
}
}
chMtxLock ( & mutex ) ;
// calculate trace coordinates and plot only if scan completed
// Ui and render require 800 system tick
if ( completed ) {
ui_process ( ) ;
plot_into_index ( measured ) ;
redraw_request | = REDRAW_CELLS ;
if ( sweep_enabled ) {
if ( vbat ! = - 1 ) {
adc_stop ( ADC1 ) ;
vbat = adc_vbat_read ( ADC1 ) ;
touch_start_watchdog ( ) ;
draw_battery_status ( ) ;
}
/* calculate trace coordinates and plot only if scan completed */
if ( marker_tracking ) {
if ( completed ) {
int i = marker_search ( ) ;
plot_into_index ( measured ) ;
if ( i ! = - 1 & & active_marker ! = - 1 ) {
redraw_request | = REDRAW_CELLS ;
markers [ active_marker ] . index = i ;
redraw_request | = REDRAW_MARKER ;
if ( marker_tracking ) {
int i = marker_search ( ) ;
if ( i ! = - 1 & & active_marker ! = - 1 ) {
markers [ active_marker ] . index = i ;
redraw_request | = REDRAW_MARKER ;
}
}
}
}
}
}
}
/* plot trace and other indications as raster */
draw_all ( completed ) ; // flush markmap only if scan completed to prevent remaining traces
chMtxUnlock ( & mutex ) ;
}
}
// plot trace and other indications as raster
draw_all ( completed ) ; // flush markmap only if scan completed to prevent remaining traces
chMtxUnlock ( & mutex ) ;
}
}
}
void
void
@ -207,6 +210,7 @@ transform_domain(void)
break ;
break ;
}
}
for ( int ch = 0 ; ch < 2 ; ch + + ) {
for ( int ch = 0 ; ch < 2 ; ch + + ) {
memcpy ( tmp , measured [ ch ] , sizeof ( measured [ 0 ] ) ) ;
memcpy ( tmp , measured [ ch ] , sizeof ( measured [ 0 ] ) ) ;
for ( int i = 0 ; i < POINTS_COUNT ; i + + ) {
for ( int i = 0 ; i < POINTS_COUNT ; i + + ) {
@ -1939,12 +1943,22 @@ VNA_SHELL_FUNCTION(cmd_threads) {
thread_t * tp ;
thread_t * tp ;
( void ) argc ;
( void ) argc ;
( void ) argv ;
( void ) argv ;
chprintf( chp , " stklimit stack addr refs prio state name" VNA_SHELL_NEWLINE_STR ) ;
shell_printf( " stklimit| stack|stk free| addr|refs|prio| state| name" VNA_SHELL_NEWLINE_STR ) ;
tp = chRegFirstThread ( ) ;
tp = chRegFirstThread ( ) ;
do {
do {
uint32_t max_stack_use = 0U ;
# if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
uint32_t stklimit = ( uint32_t ) tp - > wabase ;
uint32_t stklimit = ( uint32_t ) tp - > wabase ;
shell_printf ( " %08x %08x %08x %4u %4u %9s %12s " VNA_SHELL_NEWLINE_STR ,
# if CH_DBG_FILL_THREADS == TRUE
stklimit , ( uint32_t ) tp - > ctx . sp , ( uint32_t ) tp ,
uint8_t * p = ( uint8_t * ) tp - > wabase ; while ( p [ max_stack_use ] = = CH_DBG_STACK_FILL_VALUE ) max_stack_use + + ;
# endif
# else
uint32_t stklimit = 0U ;
# endif
shell_printf ( " %08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s " VNA_SHELL_NEWLINE_STR ,
stklimit , ( uint32_t ) tp - > ctx . sp , max_stack_use , ( uint32_t ) tp ,
( uint32_t ) tp - > refs - 1 , ( uint32_t ) tp - > prio , states [ tp - > state ] ,
( uint32_t ) tp - > refs - 1 , ( uint32_t ) tp - > prio , states [ tp - > state ] ,
tp - > name = = NULL ? " " : tp - > name ) ;
tp - > name = = NULL ? " " : tp - > name ) ;
tp = chRegNextThread ( tp ) ;
tp = chRegNextThread ( tp ) ;
@ -2142,68 +2156,65 @@ static DACConfig dac1cfg1 = {
datamode : DAC_DHRM_12BIT_RIGHT
datamode : DAC_DHRM_12BIT_RIGHT
} ;
} ;
// Main thread stack size defined in makefile USE_PROCESS_STACKSIZE = 0x200
// Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show:
// Stack maximum usage = 472 bytes (need test more and run all commands), free stack = 40 bytes
//
int main ( void )
int main ( void )
{
{
halInit ( ) ;
halInit ( ) ;
chSysInit ( ) ;
chSysInit ( ) ;
chMtxObjectInit ( & mutex ) ;
//palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(1) | PAL_STM32_OTYPE_OPENDRAIN);
//palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(1) | PAL_STM32_OTYPE_OPENDRAIN);
i2cStart ( & I2CD1 , & i2ccfg ) ;
si5351_init ( ) ;
// MCO on PA8
//palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(0));
/*
* Initializes a serial - over - USB CDC driver .
*/
sduObjectInit ( & SDU1 ) ;
sduStart ( & SDU1 , & serusbcfg ) ;
/*
* Activates the USB driver and then the USB bus pull - up on D + .
* Note , a delay is inserted in order to not have to disconnect the cable
* after a reset .
*/
usbDisconnectBus ( serusbcfg . usbp ) ;
chThdSleepMilliseconds ( 100 ) ;
usbStart ( serusbcfg . usbp , & usbcfg ) ;
usbConnectBus ( serusbcfg . usbp ) ;
/*
* SPI LCD Initialize
*/
ili9341_init ( ) ;
/*
chMtxObjectInit ( & mutex ) ;
* Initialize graph plotting
*/
//palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(1) | PAL_STM32_OTYPE_OPENDRAIN);
plot_init ( ) ;
//palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(1) | PAL_STM32_OTYPE_OPENDRAIN);
i2cStart ( & I2CD1 , & i2ccfg ) ;
si5351_init ( ) ;
// MCO on PA8
//palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(0));
/*
* Initializes a serial - over - USB CDC driver .
*/
sduObjectInit ( & SDU1 ) ;
sduStart ( & SDU1 , & serusbcfg ) ;
/*
* Activates the USB driver and then the USB bus pull - up on D + .
* Note , a delay is inserted in order to not have to disconnect the cable
* after a reset .
*/
usbDisconnectBus ( serusbcfg . usbp ) ;
chThdSleepMilliseconds ( 100 ) ;
usbStart ( serusbcfg . usbp , & usbcfg ) ;
usbConnectBus ( serusbcfg . usbp ) ;
/* restore config */
/*
* SPI LCD Initialize
*/
ili9341_init ( ) ;
/* restore config */
config_recall ( ) ;
config_recall ( ) ;
dac1cfg1 . init = config . dac_value ;
dac1cfg1 . init = config . dac_value ;
/*
/*
* Starting DAC1 driver , setting up the output pin as analog as suggested
* Starting DAC1 driver , setting up the output pin as analog as suggested
* by the Reference Manual .
* by the Reference Manual .
*/
*/
dacStart ( & DACD2 , & dac1cfg1 ) ;
dacStart ( & DACD2 , & dac1cfg1 ) ;
/* initial frequencies */
/* initial frequencies */
update_frequencies ( ) ;
update_frequencies ( ) ;
/* restore frequencies and calibration properties from flash memory */
/* restore frequencies and calibration properties from flash memory */
if ( config . default_loadcal > = 0 )
if ( config . default_loadcal > = 0 )
caldata_recall ( config . default_loadcal ) ;
caldata_recall ( config . default_loadcal ) ;
redraw_frame ( ) ;
/*
* I2S Initialize
/*
*/
* I2S Initialize
*/
tlv320aic3204_init ( ) ;
tlv320aic3204_init ( ) ;
i2sInit ( ) ;
i2sInit ( ) ;
i2sObjectInit ( & I2SD2 ) ;
i2sObjectInit ( & I2SD2 ) ;
@ -2211,12 +2222,17 @@ int main(void)
i2sStartExchange ( & I2SD2 ) ;
i2sStartExchange ( & I2SD2 ) ;
ui_init ( ) ;
ui_init ( ) ;
//Initialize graph plotting
plot_init ( ) ;
redraw_frame ( ) ;
chThdCreateStatic ( waThread1 , sizeof ( waThread1 ) , NORMALPRIO - 1 , Thread1 , NULL ) ;
chThdCreateStatic ( waThread1 , sizeof ( waThread1 ) , NORMALPRIO - 1 , Thread1 , NULL ) ;
while ( 1 ) {
while ( 1 ) {
if ( SDU1 . config - > usbp - > state = = USB_ACTIVE ) {
if ( SDU1 . config - > usbp - > state = = USB_ACTIVE ) {
# ifdef VNA_SHELL_THREAD
# ifdef VNA_SHELL_THREAD
# if CH_CFG_USE_WAITEXIT == FALSE
# error "VNA_SHELL_THREAD use chThdWait, need enable CH_CFG_USE_WAITEXIT in chconf.h"
# endif
thread_t * shelltp = chThdCreateStatic ( waThread2 , sizeof ( waThread2 ) ,
thread_t * shelltp = chThdCreateStatic ( waThread2 , sizeof ( waThread2 ) ,
NORMALPRIO + 1 ,
NORMALPRIO + 1 ,
myshellThread , NULL ) ;
myshellThread , NULL ) ;