@@ -288,7 +288,8 @@ def main(
288
288
debugwait = state .debug_wait
289
289
measure_energy = state .measure_energy
290
290
pll = state .pll
291
- clock_switch = pll and state .balance_power
291
+ pipeline = state .pipeline
292
+ clock_switch = pll and pipeline and state .balance_power
292
293
clock_speed = f'PLL ({ tc .dev .PLL_SPEED } MHz)' if pll else f'APB ({ tc .dev .APB_SPEED } MHz)'
293
294
sleep = state .sleep
294
295
softmax = state .softmax
@@ -527,7 +528,7 @@ def main(
527
528
memfile .write (' cnn_disable(); // Disable clock and power to CNN\n '
528
529
' // Enable primary clock\n '
529
530
' MXC_SYS_ClockSourceEnable(MXC_SYS_CLOCK_IPO);\n \n '
530
- ' printf("Measuring system base power...\\ n");\n '
531
+ ' printf("Measuring system base (idle) power...\\ n");\n '
531
532
' SYS_START;\n ' )
532
533
if not riscv :
533
534
memfile .write (' MXC_Delay(SEC(1));\n ' )
@@ -536,7 +537,7 @@ def main(
536
537
memfile .write (' SYS_COMPLETE;\n \n ' )
537
538
538
539
if embedded_code and apifile is not None :
539
- cdiv = '4' if clock_switch else '1'
540
+ cdiv = '4' if pll and state . balance_power else '1'
540
541
memfile .write (' // Enable peripheral, enable CNN interrupt, turn on CNN clock\n '
541
542
f' // CNN clock: { clock_speed } div { cdiv } \n '
542
543
' cnn_enable(MXC_S_GCR_PCLKDIV_CNNCLKSEL_'
@@ -694,7 +695,7 @@ def main(
694
695
memfile .write (' load_input(); // Load data input\n ' )
695
696
if clock_switch :
696
697
select_clock (memfile , 'IPLL' , 'DIV1' , f'CNN clock: { clock_speed } div 1' ,
697
- pll_wait = False )
698
+ pll_wait = False , prefix = ' ' )
698
699
memfile .write (' cnn_start(); // Run inference\n ' )
699
700
if fifo :
700
701
memfile .write (' load_input(); // Load data input via FIFO\n ' )
@@ -710,7 +711,7 @@ def main(
710
711
memfile .write (' while (cnn_time == 0); // Spin wait\n ' )
711
712
if clock_switch :
712
713
select_clock (memfile , 'IPLL' , 'DIV4' , f'CNN clock: { clock_speed } div 4' ,
713
- pll_wait = False )
714
+ pll_wait = False , prefix = ' ' )
714
715
memfile .write (' }\n '
715
716
' CNN_COMPLETE;\n \n ' )
716
717
@@ -733,9 +734,9 @@ def main(
733
734
memfile .write (' }\n \n ' )
734
735
735
736
if clock_switch :
736
- select_clock (memfile , 'PCLK ' , 'DIV1 ' ,
737
- f'Switch CNN clock to APB ( { tc . dev . APB_SPEED } MHz) and disable PLL' )
738
- memfile . write ( ' MXC_GCR->ipll_ctrl &= ~MXC_F_GCR_IPLL_CTRL_EN; \n \n ' )
737
+ select_clock (memfile , 'IPLL ' , 'DIV4 ' ,
738
+ f'Switch CNN clock to { clock_speed } div 4 \n ' ,
739
+ pll_wait = False )
739
740
740
741
if embedded_code and apifile is not None :
741
742
function_header (apifile , function = 'boost_disable' ,
@@ -792,6 +793,9 @@ def main(
792
793
793
794
if embedded_code and apifile is not None :
794
795
function_footer (apifile ) # disable()
796
+ if pll :
797
+ memfile .write (' MXC_GCR->ipll_ctrl &= ~MXC_F_GCR_IPLL_CTRL_EN; '
798
+ '// Disable IPLL\n \n ' )
795
799
796
800
if not forever :
797
801
if softmax :
@@ -902,16 +906,17 @@ def select_clock(
902
906
divider : int ,
903
907
comment : str = '' ,
904
908
pll_wait : bool = True ,
909
+ prefix : str = '' ,
905
910
) -> None :
906
911
"""
907
912
Switch clock source and divider.
908
913
"""
909
914
if comment != '' :
910
- memfile .write (f' // { comment } \n ' )
915
+ memfile .write (f'{ prefix } // { comment } \n ' )
911
916
if source == 'IPLL' and pll_wait :
912
- memfile .write (' while ((MXC_GCR->ipll_ctrl & MXC_F_GCR_IPLL_CTRL_RDY) != '
917
+ memfile .write (f' { prefix } while ((MXC_GCR->ipll_ctrl & MXC_F_GCR_IPLL_CTRL_RDY) != '
913
918
'MXC_F_GCR_IPLL_CTRL_RDY) ;\n ' )
914
- memfile .write (' MXC_GCR->pclkdiv = (MXC_GCR->pclkdiv & '
919
+ memfile .write (f' { prefix } MXC_GCR->pclkdiv = (MXC_GCR->pclkdiv & '
915
920
'~(MXC_F_GCR_PCLKDIV_CNNCLKDIV | MXC_F_GCR_PCLKDIV_CNNCLKSEL))\n '
916
- f' | MXC_S_GCR_PCLKDIV_CNNCLKDIV_{ divider } | '
921
+ f'{ prefix } | MXC_S_GCR_PCLKDIV_CNNCLKDIV_{ divider } | '
917
922
f'MXC_S_GCR_PCLKDIV_CNNCLKSEL_{ source } ;\n ' )
0 commit comments