REG= { ADC_ADDR0=1074659328, ADC_ADDR1=1074659332, ADC_ADDR2=1074659336, ADC_ADDR3=1074659340, ADC_ADDR4=1074659344, ADC_ADDR5=1074659348, ADC_ADDR6=1074659352, ADC_ADDR7=1074659356, ADC_ADCR=1074659360, ADC_ADCHER=1074659364, ADC_ADCMPR0=1074659368, ADC_ADCMPR1=1074659372, ADC_ADSR=1074659376, ADC_ADCALR=1074659380, CLK_PWRCON=1342177792, CLK_AHBCLK=1342177796, CLK_APBCLK=1342177800, CLK_CLKSTATUS=1342177804, CLK_CLKSEL0=1342177808, CLK_CLKSEL1=1342177812, CLK_CLKDIV=1342177816, CLK_CLKSEL2=1342177820, CLK_PLLCON=1342177824, CLK_FRQDIV=1342177828, EBI_CTL_EBICON=1342242816, EBI_CTL_EXTIME=1342242820, FMC_ISPCON=1342226432, FMC_ISPADR=1342226436, FMC_ISPDAT=1342226440, FMC_ISPCMD=1342226444, FMC_ISPTRG=1342226448, FMC_DFBADR=1342226452, FMC_FATCON=1342226456, GCR_PDID=1342177280, GCR_RSTSRC=1342177284, GCR_IPRSTC1=1342177288, GCR_IPRSTC2=1342177292, GCR_BODCR=1342177304, GCR_PORCR=1342177316, GCR_P0_MFP=1342177328, GCR_P1_MFP=1342177332, GCR_P2_MFP=1342177336, GCR_P3_MFP=1342177340, GCR_P4_MFP=1342177344, GCR_P5_MFP=1342177348, GCR_P6_MFP=1342177352, GCR_P7_MFP=1342177372, GCR_REGWRPROT=1342177536, GPIO_P0_PMD=1342193664, GPIO_P0_OFFD=1342193668, GPIO_P0_DOUT=1342193672, GPIO_P0_DMASK=1342193676, GPIO_P0_PIN=1342193680, GPIO_P0_DBEN=1342193684, GPIO_P0_IMD=1342193688, GPIO_P0_IEN=1342193692, GPIO_P0_ISRC=1342193696, GPIO_P1_PMD=1342193728, GPIO_P1_OFFD=1342193732, GPIO_P1_DOUT=1342193736, GPIO_P1_DMASK=1342193740, GPIO_P1_PIN=1342193744, GPIO_P1_DBEN=1342193748, GPIO_P1_IMD=1342193752, GPIO_P1_IEN=1342193756, GPIO_P1_ISRC=1342193760, GPIO_P2_PMD=1342193792, GPIO_P2_OFFD=1342193796, GPIO_P2_DOUT=1342193800, GPIO_P2_DMASK=1342193804, GPIO_P2_PIN=1342193808, GPIO_P2_DBEN=1342193812, GPIO_P2_IMD=1342193816, GPIO_P2_IEN=1342193820, GPIO_P2_ISRC=1342193824, GPIO_P3_PMD=1342193856, GPIO_P3_OFFD=1342193860, GPIO_P3_DOUT=1342193864, GPIO_P3_DMASK=1342193868, GPIO_P3_PIN=1342193872, GPIO_P3_DBEN=1342193876, GPIO_P3_IMD=1342193880, GPIO_P3_IEN=1342193884, GPIO_P3_ISRC=1342193888, GPIO_P4_PMD=1342193920, GPIO_P4_OFFD=1342193924, GPIO_P4_DOUT=1342193928, GPIO_P4_DMASK=1342193932, GPIO_P4_PIN=1342193936, GPIO_P4_DBEN=1342193940, GPIO_P4_IMD=1342193944, GPIO_P4_IEN=1342193948, GPIO_P4_ISRC=1342193952, GPIO_P5_PMD=1342194368, GPIO_P5_OFFD=1342194372, GPIO_P5_DOUT=1342194376, GPIO_P5_DMASK=1342194380, GPIO_P5_PIN=1342194384, GPIO_P5_DBEN=1342194388, GPIO_P5_IMD=1342194392, GPIO_P5_IEN=1342194396, GPIO_P5_ISRC=1342194400, GPIO_P6_PMD=1342194432, GPIO_P6_OFFD=1342194436, GPIO_P6_DOUT=1342194440, GPIO_P6_DMASK=1342194444, GPIO_P6_PIN=1342194448, GPIO_P6_DBEN=1342194452, GPIO_P6_IMD=1342194456, GPIO_P6_IEN=1342194460, GPIO_P6_ISRC=1342194464, GPIO_P7_PMD=1342194496, GPIO_P7_OFFD=1342194500, GPIO_P7_DOUT=1342194504, GPIO_P7_DMASK=1342194508, GPIO_P7_PIN=1342194512, GPIO_P7_DBEN=1342194516, GPIO_P7_IMD=1342194520, GPIO_P7_IEN=1342194524, GPIO_P7_ISRC=1342194528, GPIO_DBNCECON=1342194048, GP0_BITS_Px0_DOUT=1342194688, GP0_BITS_Px1_DOUT=1342194692, GP0_BITS_Px2_DOUT=1342194696, GP0_BITS_Px3_DOUT=1342194700, GP0_BITS_Px4_DOUT=1342194704, GP0_BITS_Px5_DOUT=1342194708, GP0_BITS_Px6_DOUT=1342194712, GP0_BITS_Px7_DOUT=1342194716, GP1_BITS_Px0_DOUT=1342194720, GP1_BITS_Px1_DOUT=1342194724, GP1_BITS_Px2_DOUT=1342194728, GP1_BITS_Px3_DOUT=1342194732, GP1_BITS_Px4_DOUT=1342194736, GP1_BITS_Px5_DOUT=1342194740, GP1_BITS_Px6_DOUT=1342194744, GP1_BITS_Px7_DOUT=1342194748, GP2_BITS_Px0_DOUT=1342194752, GP2_BITS_Px1_DOUT=1342194756, GP2_BITS_Px2_DOUT=1342194760, GP2_BITS_Px3_DOUT=1342194764, GP2_BITS_Px4_DOUT=1342194768, GP2_BITS_Px5_DOUT=1342194772, GP2_BITS_Px6_DOUT=1342194776, GP2_BITS_Px7_DOUT=1342194780, GP3_BITS_Px0_DOUT=1342194784, GP3_BITS_Px1_DOUT=1342194788, GP3_BITS_Px2_DOUT=1342194792, GP3_BITS_Px3_DOUT=1342194796, GP3_BITS_Px4_DOUT=1342194800, GP3_BITS_Px5_DOUT=1342194804, GP3_BITS_Px6_DOUT=1342194808, GP3_BITS_Px7_DOUT=1342194812, GP4_BITS_Px0_DOUT=1342194816, GP4_BITS_Px1_DOUT=1342194820, GP4_BITS_Px2_DOUT=1342194824, GP4_BITS_Px3_DOUT=1342194828, GP4_BITS_Px4_DOUT=1342194832, GP4_BITS_Px5_DOUT=1342194836, GP4_BITS_Px6_DOUT=1342194840, GP4_BITS_Px7_DOUT=1342194844, GP5_BITS_Px0_DOUT=1342194560, GP5_BITS_Px1_DOUT=1342194564, GP5_BITS_Px2_DOUT=1342194568, GP5_BITS_Px3_DOUT=1342194572, GP5_BITS_Px4_DOUT=1342194576, GP5_BITS_Px5_DOUT=1342194580, GP5_BITS_Px6_DOUT=1342194584, GP5_BITS_Px7_DOUT=1342194588, GP6_BITS_Px0_DOUT=1342194592, GP6_BITS_Px1_DOUT=1342194596, GP6_BITS_Px2_DOUT=1342194600, GP6_BITS_Px3_DOUT=1342194604, GP6_BITS_Px4_DOUT=1342194608, GP6_BITS_Px5_DOUT=1342194612, GP6_BITS_Px6_DOUT=1342194616, GP6_BITS_Px7_DOUT=1342194620, GP7_BITS_Px0_DOUT=1342194624, GP7_BITS_Px1_DOUT=1342194628, I2C_I2CON=1073872896, I2C_I2CADDR0=1073872900, I2C_I2CDAT=1073872904, I2C_I2CSTATUS=1073872908, I2C_I2CLK=1073872912, I2C_I2CTOC=1073872916, I2C_I2CADDR1=1073872920, I2C_I2CADDR2=1073872924, I2C_I2CADDR3=1073872928, I2C_I2CADM0=1073872932, I2C_I2CADM1=1073872936, I2C_I2CADM2=1073872940, I2C_I2CADM3=1073872944, I2C0_I2CON=1073872896, I2C0_I2CADDR0=1073872900, I2C0_I2CDAT=1073872904, I2C0_I2CSTATUS=1073872908, I2C0_I2CLK=1073872912, I2C0_I2CTOC=1073872916, I2C0_I2CADDR1=1073872920, I2C0_I2CADDR2=1073872924, I2C0_I2CADDR3=1073872928, I2C0_I2CADM0=1073872932, I2C0_I2CADM1=1073872936, I2C0_I2CADM2=1073872940, I2C0_I2CADM3=1073872944, I2C1_I2CON=1074921472, I2C1_I2CADDR0=1074921476, I2C1_I2CDAT=1074921480, I2C1_I2CSTATUS=1074921484, I2C1_I2CLK=1074921488, I2C1_I2CTOC=1074921492, I2C1_I2CADDR1=1074921496, I2C1_I2CADDR2=1074921500, I2C1_I2CADDR3=1074921504, I2C1_I2CADM0=1074921508, I2C1_I2CADM1=1074921512, I2C1_I2CADM2=1074921516, I2C1_I2CADM3=1074921520, INT_IRQ0_SRC=1342178048, INT_IRQ1_SRC=1342178052, INT_IRQ2_SRC=1342178056, INT_IRQ3_SRC=1342178060, INT_IRQ4_SRC=1342178064, INT_IRQ5_SRC=1342178068, INT_IRQ6_SRC=1342178072, INT_IRQ7_SRC=1342178076, INT_IRQ8_SRC=1342178080, INT_IRQ9_SRC=1342178084, INT_IRQ10_SRC=1342178088, INT_IRQ11_SRC=1342178092, INT_IRQ12_SRC=1342178096, INT_IRQ13_SRC=1342178100, INT_IRQ14_SRC=1342178104, INT_IRQ15_SRC=1342178108, INT_IRQ18_SRC=1342178120, INT_IRQ21_SRC=1342178132, INT_IRQ22_SRC=1342178136, INT_IRQ28_SRC=1342178160, INT_IRQ29_SRC=1342178164, INT_IRQ30_SRC=1342178168, INT_NMI_SEL=1342178176, INT_MCU_IRQ=1342178180, PWMA_PPR=1074003968, PWMA_CSR=1074003972, PWMA_PCR=1074003976, PWMA_CNR0=1074003980, PWMA_CMR0=1074003984, PWMA_PDR0=1074003988, PWMA_CNR1=1074003992, PWMA_CMR1=1074003996, PWMA_PDR1=1074004000, PWMA_CNR2=1074004004, PWMA_CMR2=1074004008, PWMA_PDR2=1074004012, PWMA_CNR3=1074004016, PWMA_CMR3=1074004020, PWMA_PDR3=1074004024, PWMA_PIER=1074004032, PWMA_PIIR=1074004036, PWMA_CCR0=1074004048, PWMA_CCR2=1074004052, PWMA_CRLR0=1074004056, PWMA_CFLR0=1074004060, PWMA_CRLR1=1074004064, PWMA_CFLR1=1074004068, PWMA_CRLR2=1074004072, PWMA_CFLR2=1074004076, PWMA_CRLR3=1074004080, PWMA_CFLR3=1074004084, PWMA_CAPENR=1074004088, PWMA_POE=1074004092, PWMB_PPR=1075052544, PWMB_CSR=1075052548, PWMB_PCR=1075052552, PWMB_CNR0=1075052556, PWMB_CMR0=1075052560, PWMB_PDR0=1075052564, PWMB_CNR1=1075052568, PWMB_CMR1=1075052572, PWMB_PDR1=1075052576, PWMB_CNR2=1075052580, PWMB_CMR2=1075052584, PWMB_PDR2=1075052588, PWMB_CNR3=1075052592, PWMB_CMR3=1075052596, PWMB_PDR3=1075052600, PWMB_PIER=1075052608, PWMB_PIIR=1075052612, PWMB_CCR0=1075052624, PWMB_CCR2=1075052628, PWMB_CRLR0=1075052632, PWMB_CFLR0=1075052636, PWMB_CRLR1=1075052640, PWMB_CFLR1=1075052644, PWMB_CRLR2=1075052648, PWMB_CFLR2=1075052652, PWMB_CRLR3=1075052656, PWMB_CFLR3=1075052660, PWMB_CAPENR=1075052664, PWMB_POE=1075052668, SCS_SYST_CSR=3758153744, SCS_SYST_RVR=3758153748, SCS_SYST_CVR=3758153752, SCS_NVIC_ISER=3758153984, SCS_NVIC_ICER=3758154112, SCS_NVIC_ISPR=3758154240, SCS_NVIC_ICPR=3758154368, SCS_NVIC_IPR0=3758154752, SCS_NVIC_IPR1=3758154756, SCS_NVIC_IPR2=3758154760, SCS_NVIC_IPR3=3758154764, SCS_NVIC_IPR4=3758154768, SCS_NVIC_IPR5=3758154772, SCS_NVIC_IPR6=3758154776, SCS_NVIC_IPR7=3758154780, SCS_CPUID=3758157056, SCS_ICSR=3758157060, SCS_AIRCR=3758157068, SCS_SCR=3758157072, SCS_SHPR2=3758157084, SCS_SHPR3=3758157088, TMR0_TCSR=1073807360, TMR0_TCMPR=1073807364, TMR0_TISR=1073807368, TMR0_TDR=1073807372, TMR1_TCSR=1073807392, TMR1_TCMPR=1073807396, TMR1_TISR=1073807400, TMR1_TDR=1073807404, TMR2_TCSR=1074855936, TMR2_TCMPR=1074855940, TMR2_TISR=1074855944, TMR2_TDR=1074855948, TMR3_TCSR=1074855968, TMR3_TCMPR=1074855972, TMR3_TISR=1074855976, TMR3_TDR=1074855980, WDT_WTCR=1073758208, SPI0_SPI_CNTRL=1073938432, SPI0_SPI_DIVIDER=1073938436, SPI0_SPI_SSR=1073938440, SPI0_SPI_RX0=1073938448, SPI0_SPI_RX1=1073938452, SPI0_SPI_TX0=1073938464, SPI0_SPI_TX1=1073938468, SPI0_SPI_VARCLK=1073938484, SPI0_SPI_CNTRL2=1073938492, SPI1_SPI_CNTRL=1073954816, SPI1_SPI_DIVIDER=1073954820, SPI1_SPI_SSR=1073954824, SPI1_SPI_RX0=1073954832, SPI1_SPI_RX1=1073954836, SPI1_SPI_TX0=1073954848, SPI1_SPI_TX1=1073954852, SPI1_SPI_VARCLK=1073954868, SPI1_SPI_CNTRL2=1073954876, UART0_UA_RBR=1074069504, UART0_UA_THR=1074069504, UART0_UA_IER=1074069508, UART0_UA_FCR=1074069512, UART0_UA_LCR=1074069516, UART0_UA_MCR=1074069520, UART0_UA_MSR=1074069524, UART0_UA_FSR=1074069528, UART0_UA_ISR=1074069532, UART0_UA_TOR=1074069536, UART0_UA_BAUD=1074069540, UART0_UA_IRCR=1074069544, UART0_UA_ACT_CSR=1074069548, UART0_UA_FUN_SEL=1074069552, UART1_UA_RBR=1075118080, UART1_UA_THR=1075118080, UART1_UA_IER=1075118084, UART1_UA_FCR=1075118088, UART1_UA_LCR=1075118092, UART1_UA_MCR=1075118096, UART1_UA_MSR=1075118100, UART1_UA_FSR=1075118104, UART1_UA_ISR=1075118108, UART1_UA_TOR=1075118112, UART1_UA_BAUD=1075118116, UART1_UA_IRCR=1075118120, UART1_UA_ACT_CSR=1075118124, UART1_UA_FUN_SEL=1075118128, EBI_EBICON=1342242816, EBI_EXTIME=1342242820, } g_M051_regs=REG function read_M051_Registers(t,t,t,e) local a=false local t={ M058S_AN_TSSOP20=1, M058S_AN_QFN33=1, M058S_AN_LQFP48=1, M058S_AN_LQFP64=1} if e~=nil and t[e]~=nil then a=true end local t=false local o={ M058S_AN_TSSOP20=1, M058S_AN_QFN33=1, M058S_AN_LQFP48=1, M058S_AN_LQFP64=1} if e~=nil and o[e]~=nil then t=true end local o=false local i={ M058S_AN_TSSOP20=1, M058S_AN_QFN33=1, M058S_AN_LQFP48=1, M058S_AN_LQFP64=1} if e~=nil and i[e]~=nil then o=true end local i=true local n={ M058S_AN_TSSOP20=1, M058S_AN_QFN33=1, M058S_AN_LQFP48=1, M058S_AN_LQFP64=1} if e~=nil and n[e]~=nil then i=false end local e={} e["GCR_P0_MFP"], e["GCR_P1_MFP"], e["GCR_P2_MFP"], e["GCR_P3_MFP"], e["GCR_P4_MFP"]=ice:ReadMem32(g_M051_regs.GCR_P0_MFP,5) if a and t and o then e["GCR_P5_MFP"], e["GCR_P6_MFP"], e["GCR_P7_MFP"]=ice:ReadMem32(g_M051_regs.GCR_P5_MFP,3) end e["GPIO_P0_PMD"], e["GPIO_P0_OFFD"], e["GPIO_P0_DOUT"], e["GPIO_P0_DMASK"], e["GPIO_P0_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P0_PMD,5) e["GPIO_P1_PMD"], e["GPIO_P1_OFFD"], e["GPIO_P1_DOUT"], e["GPIO_P1_DMASK"], e["GPIO_P1_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P1_PMD,5) e["GPIO_P2_PMD"], e["GPIO_P2_OFFD"], e["GPIO_P2_DOUT"], e["GPIO_P2_DMASK"], e["GPIO_P2_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P2_PMD,5) e["GPIO_P3_PMD"], e["GPIO_P3_OFFD"], e["GPIO_P3_DOUT"], e["GPIO_P3_DMASK"], e["GPIO_P3_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P3_PMD,5) e["GPIO_P4_PMD"], e["GPIO_P4_OFFD"], e["GPIO_P4_DOUT"], e["GPIO_P4_DMASK"], e["GPIO_P4_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P4_PMD,5) if a then e["GPIO_P5_PMD"], e["GPIO_P5_OFFD"], e["GPIO_P5_DOUT"], e["GPIO_P5_DMASK"], e["GPIO_P5_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P5_PMD,5) end if t then e["GPIO_P6_PMD"], e["GPIO_P6_OFFD"], e["GPIO_P6_DOUT"], e["GPIO_P6_DMASK"], e["GPIO_P6_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P6_PMD,5) end if o then e["GPIO_P7_PMD"], e["GPIO_P7_OFFD"], e["GPIO_P7_DOUT"], e["GPIO_P7_DMASK"], e["GPIO_P7_PIN"]=ice:ReadMem32(g_M051_regs.GPIO_P7_PMD,5) end e["CLK_PWRCON"], e["CLK_AHBCLK"], e["CLK_APBCLK"], e["CLK_CLKSTATUS"], e["CLK_CLKSEL0"], e["CLK_CLKSEL1"], e["CLK_CLKDIV"], e["CLK_CLKSEL2"], e["CLK_PLLCON"], e["CLK_FRQDIV"]=ice:ReadMem32(g_M051_regs.CLK_PWRCON,10) e["SPI0_SPI_CNTRL"], e["SPI0_SPI_DIVIDER"], e["SPI1_SPI_CNTRL"], e["SPI1_SPI_DIVIDER"]=ice:ReadMemMulti(g_M051_regs.SPI0_SPI_CNTRL, g_M051_regs.SPI0_SPI_DIVIDER, g_M051_regs.SPI1_SPI_CNTRL, g_M051_regs.SPI1_SPI_DIVIDER) e["SPI0_SPI_CNTRL2"], e["SPI1_SPI_CNTRL2"]=ice:ReadMemMulti(g_M051_regs.SPI0_SPI_CNTRL2, g_M051_regs.SPI1_SPI_CNTRL2) e["ADC_ADCR"], e["I2C_I2CON"], e["I2C_I2CLK"]=ice:ReadMemMulti(g_M051_regs.ADC_ADCR, g_M051_regs.I2C_I2CON, g_M051_regs.I2C_I2CLK) e["I2C0_I2CON"], e["I2C0_I2CLK"], e["I2C1_I2CON"], e["I2C1_I2CLK"]=ice:ReadMemMulti(g_M051_regs.I2C0_I2CON, g_M051_regs.I2C0_I2CLK, g_M051_regs.I2C1_I2CON, g_M051_regs.I2C1_I2CLK) e["UART0_UA_BAUD"], e["UART1_UA_BAUD"]=ice:ReadMemMulti(g_M051_regs.UART0_UA_BAUD, g_M051_regs.UART1_UA_BAUD) e["PWMA_PPR"], e["PWMA_CSR"], e["PWMB_PPR"], e["PWMB_CSR"]=ice:ReadMemMulti(g_M051_regs.PWMA_PPR, g_M051_regs.PWMA_CSR, g_M051_regs.PWMB_PPR, g_M051_regs.PWMB_CSR) e["TMR0_TCSR"], e["TMR1_TCSR"], e["TMR2_TCSR"], e["TMR3_TCSR"]=ice:ReadMemMulti(g_M051_regs.TMR0_TCSR, g_M051_regs.TMR1_TCSR, g_M051_regs.TMR2_TCSR, g_M051_regs.TMR3_TCSR) if i then e["EBI_EBICON"]=ice:ReadMem32(g_M051_regs.EBI_EBICON) end return e end local n={ [0]=kPinDirection_In, [1]=kPinDirection_PushPullOut, [2]=kPinDirection_OpenDrainOut, [3]=kPinDirection_Bi, } local a={ [0]="INPUT", [1]="OUTPUT", [2]="Open-Drain", [3]="Quasi-bidirectional", } function get_mfp_regs(t,e) local e={string.format("GCR_P%d_MFP",e)} if#e>1 then return reg2str("Multi-Function registers",g_M051_regs,t,e) else return reg2str("Multi-Function register",g_M051_regs,t,e) end end function fill_M051_GPIO(i,s,t,e,d) local o if d==nil then d=string.format("P%d.%d",t,e)end local h=s[string.format("GCR_P%d_MFP",t)] local u=s[string.format("GPIO_P%d_PMD",t)] local c=s[string.format("GPIO_P%d_OFFD",t)] local r=s[string.format("GPIO_P%d_DOUT",t)] local h=s[string.format("GPIO_P%d_DMASK",t)] local l=s[string.format("GPIO_P%d_PIN",t)] i["highlight_text"]=d i["normal_color"]=kColor_Invalid i["highlight_color"]=kColor_GPIO i["pin_bg_color"]=kBgColor_GPIO o=ext.band(ext.rshift(u,e*2),3) i["direction"]=n[o] if n[o]==kPinDirection_In or n[o]==kPinDirection_Bi then if ext.band(l,ext.lshift(1,e))==0 then i["status"]=kPinStatus_Low else i["status"]=kPinStatus_High end else if ext.band(h,ext.lshift(1,e))~=0 then i["status"]=kPinStatus_Unknown elseif ext.band(r,ext.lshift(1,e))==0 then i["status"]=kPinStatus_Low else i["status"]=kPinStatus_High end end local a=string.format("P%d.%d is in %s mode
", t,e,a[o]) if n[o]==kPinDirection_In or n[o]==kPinDirection_Bi then if ext.band(l,ext.lshift(1,e))==0 then a=a.."Pin input low
" else a=a.."Pin input high
" end end if n[o]==kPinDirection_PushPullOut or n[o]==kPinDirection_OpenDrainOut or n[o]==kPinDirection_Bi then if ext.band(h,ext.lshift(1,e))~=0 then a=a.."Pin output masked
" elseif ext.band(r,ext.lshift(1,e))==0 then a=a.."Pin output low
" else a=a.."Pin output high
" end end if ext.band(c,ext.lshift(1,e+16))==0 then a=a.."IO digital input path enabled
" else a=a.."IO digital input path disabled(digital input tied to low)
" end local h="" if n[o]==kPinDirection_PushPullOut or n[o]==kPinDirection_Bi then if ext.band(r,ext.lshift(1,e))==0 and ext.band(l,ext.lshift(1,e))~=0 then h=string.format("Leakage warning: P%d_DOUT[%d] = 0, P%d_PIN[%d] = 1
",t,e,t,e) elseif ext.band(r,ext.lshift(1,e))~=0 and ext.band(l,ext.lshift(1,e))==0 then h=string.format("Leakage warning: P%d_DOUT[%d] = 1, P%d_PIN[%d] = 0
",t,e,t,e) end end if h~=""then i["pin_no_color"]=kBgColor_Error h=""..h.."" end local e={ string.format("GPIO_P%d_PMD",t), string.format("GPIO_P%d_OFFD",t), string.format("GPIO_P%d_DOUT",t), string.format("GPIO_P%d_DMASK",t), string.format("GPIO_P%d_PIN",t)} local e=reg2str("GPIO setting registers",g_M051_regs,s,e) i["information"]=string.format("%s
%s
".. "%s%s".. "Information
".. "%s", d, h, get_mfp_regs(s,t), e, a) end function fill_invalid_GPIO(e,o,t,a) local i=o[string.format("GCR_P%d_MFP",t)] e["highlight_text"]=string.format("P%d.%d",t,a) e["normal_color"]=kColor_Invalid e["highlight_color"]=kColor_Invalid e["pin_bg_color"]=kBgColor_Invalid e["direction"]=kPinDirection_Unknown e["status"]=kPinStatus_Unknown e["pin_no_color"]=kBgColor_Error local i="Undefined setting in Multi-Function register for this pin
" e["information"]=string.format("P%s.%d
%s
".. "%s", t,a, i, get_mfp_regs(o,t)) end function get_XTL12M_clock(o,a) local t local e table.insert(a,"CLK_PWRCON") local a=ext.band(o["CLK_PWRCON"],1) if a==1 then t=12000000 e="external input, when external input clock is 12M" else t=0 e="invalid external clock (see PWRCON[0].XTL12M_EN)" end return t,e end function get_OSC22M_clock(o,a) local e local t table.insert(a,"CLK_PWRCON") local a=ext.band(o["CLK_PWRCON"],4) if a==0 then e=0 t="invalid internal 22.1184MHz oscillator clock (see PWRCON[2].OSC22M_EN)" else e=22118400 t="internal 22.1184MHz oscillator clock" end return e,t end function get_OSC10K_clock(a,o) local e local t table.insert(o,"CLK_PWRCON") local a=ext.band(a["CLK_PWRCON"],8) if a==0 then e=0 t="invalid internal 10kHz oscillator clock (see PWRCON[3].OSC10K_EN)" else e=10000 t="internal 10kHz oscillator clock" end return e,t end function get_PLL_clock(a,o) local t local e table.insert(o,"CLK_PLLCON") if ext.band(a["CLK_PLLCON"],65536)~=0 then t=0 e="invalid PLL clock, PLL is in power down mode (see PLLCON[16].PD)" else if ext.band(a["CLK_PLLCON"],524288)~=0 then t,e=get_OSC22M_clock(a,o) else t,e=get_XTL12M_clock(a,o) end if t~=0 then if ext.band(a["CLK_PLLCON"],131072)~=0 then e=string.format("PLL clock (%sHz), bypassed from %s",val2str(t),e) else local o={1,2,2,4} local i=ext.band(a["CLK_PLLCON"],511)+2 local n=ext.rshift(ext.band(a["CLK_PLLCON"],15872),9)+2 local a=o[ext.rshift(ext.band(a["CLK_PLLCON"],49152),14)+1] t=t*i/n/a e=string.format("PLL clock (%sHz), from %s",val2str(t),e) end else e="PLL clock from "..e end end return t,e end function get_sys_clock(o,a,n) table.insert(a,"CLK_CLKSEL0") local i=ext.band(o["CLK_CLKSEL0"],7) local e local t if i==0 then e,t=get_XTL12M_clock(o,a) elseif i==2 then e,t=get_PLL_clock(o,a) elseif i==3 then e,t=get_OSC10K_clock(o,a) elseif i==7 then e,t=get_OSC22M_clock(o,a) else e=0 t="invalid "..n.." clock (see CLKSEL0[2:0].HCLK_S)" return e,t end if e==0 then t=""..n.." clock from "..t else table.insert(a,"CLK_CLKDIV") local a=ext.band(o["CLK_CLKDIV"],15) e=e/(a+1) t=string.format("%s clock (%sHz), from %s",n,val2str(e),t) end return e,t end function get_HCLK_clock(e,t) return get_sys_clock(e,t,"HCLK") end function get_PCLK_clock(t,e) return get_sys_clock(t,e,"PCLK") end function get_clk_informnation(t,e) return reg2str("Clock setting registers",g_M051_regs,t,e) end function fill_M051_ACMP(e,a,h,t,i,o) local t="" local n={} local o=ext.rshift(o,1) local s=({'ACMP01','ACMP23'})[1+o] e["highlight_text"]=i e["normal_color"]=kColor_Invalid e["highlight_color"]=kColor_CMP e["pin_bg_color"]=kBgColor_CMP e["direction"]=kPinDirection_In e["status"]=kPinStatus_Unknown table.insert(n,"CLK_APBCLK") local r=ext.band(a["CLK_APBCLK"],ext.lshift(1073741824,o)) if r==0 then t=string.format("%s clock is not available (see APBCLK[%d].%s_EN).
",s,o+30,s) t=""..t.."" e["pin_no_color"]=kBgColor_Error end e["information"]=string.format( "%s
%s
".. "%s%s", i, t, get_mfp_regs(a,h), get_clk_informnation(a,n)) end function fill_M051_UART(o,e,l,t,r,n) local d=get_chip_info()["series_group"] local i="" local t="" local a={} local h=0 o["highlight_text"]=r o["normal_color"]=kColor_Invalid o["highlight_color"]=kColor_UART o["pin_bg_color"]=kBgColor_UART o["direction"]=kPinDirection_Unknown o["status"]=kPinStatus_Unknown function get_uart_baudate(s) local o=string.format("UART%d",n) local t=string.format("UART%d_UA_BAUD",n) table.insert(a,t) local i=ext.band(e[t],536870912) local n=ext.band(e[t],268435456) local h=ext.rshift(ext.band(e[t],251658240),24) local t=ext.band(e[t],65535) local a=0 local e="" if i==0 and n==0 then a=s/(16*(t+2)) elseif i~=0 and n==0 then if h>=8 then a=s/((h+1)*(t+2)) else e="invalid "..o.."'s UA_BAUD value, DIVIDER_X must >= 8" end elseif i~=0 and n~=0 then if t>=3 then a=s/(t+2) else e="invalid "..o.."'s UA_BAUD value, BRD must >= 3" end else e="invalid "..o.."'s UA_BAUD value" end return a,e end table.insert(a,"CLK_APBCLK") if ext.band(e["CLK_APBCLK"],ext.lshift(65536,n))~=0 then table.insert(a,"CLK_CLKSEL1") local s=ext.band(ext.rshift(e["CLK_CLKSEL1"],24),3) local r=ext.band(ext.rshift(e["CLK_CLKDIV"],8),15) local n local o if s==0 then n,o=get_XTL12M_clock(e,a) elseif s==1 then n,o=get_PLL_clock(e,a) elseif s==2 and(d~=4 and d==0)then n,o=get_OSC22M_clock(e,a) elseif s==3 then n,o=get_OSC22M_clock(e,a) else t="UART clock is not available (see CLKSEL1[25:24].UART_S).
" end if t==""then h=n/(r+1) if h~=0 then table.insert(a,"CLK_CLKDIV") i=string.format("UART clock frequency: %sHz, from %s.
",val2str(h),o) else t=string.format("UART clock is not available, %s.
",o) end end else t=string.format("UART%d clock is not available (see APBCLK[%d].UART%d_EN).
", n,n+16,n) end if t==""then local e,a=get_uart_baudate(h) if e~=0 then i=i..string.format("UART baudrate: %d
",e) else t=a..".
" end end if t~=""then t=""..t.."" o["pin_no_color"]=kBgColor_Error end if i~=""then i="Information
"..i end o["information"]=string.format( "%s
%s
%s%s%s", r, t, get_mfp_regs(e,l), get_clk_informnation(e,a), i) end function fill_M051_SPI(h,t,u,e,l,a) local r=get_chip_info()["series_group"] local e="" local d="" local o={} h["highlight_text"]=l h["normal_color"]=kColor_Invalid h["highlight_color"]=kColor_SPI h["pin_bg_color"]=kBgColor_SPI h["direction"]=kPinDirection_Unknown h["status"]=kPinStatus_Unknown table.insert(o,"CLK_APBCLK") if ext.band(t["CLK_APBCLK"],ext.lshift(4096,a))~=0 then local i,n if(r~=4 and r==0)or r==1 then i,n=get_PCLK_clock(t,o) else table.insert(o,"CLK_CLKSEL1") local e=ext.band(ext.rshift(t["CLK_CLKSEL1"],a+4),1) if e==0 then i,n=get_PLL_clock(t,o) else i,n=get_HCLK_clock(t,o) end end if i~=0 then local h=string.format("SPI%d_SPI_CNTRL",a) local d=string.format("SPI%d_SPI_CNTRL2",a) local s=string.format("SPI%d_SPI_DIVIDER",a) table.insert(o,h) local l=ext.band(t[h],262144) if l~=0 then e="SPI is in slave mode.
" else e="SPI is in master mode.
" if r~=4 and r==0 then table.insert(o,s) local o=ext.band(t[s],65535) local s=ext.band(ext.rshift(t[s],16),65535) local o=i/((o+1)*2) local i=i/((s+1)*2) local t=ext.band(t[h],8388608) if t~=0 then e=e..string.format("SPI%d clock frequency is variable: %sHz or %sHz, from %s.
", a,val2str(o),val2str(i),n) else e=e..string.format("SPI%d clock frequency: %sHz, from %s.
", a,val2str(o),n) end elseif r==1 then table.insert(o,d) local r=ext.band(t[d],1) if r~=0 then e=e..string.format("SPI%d clock frequency: %sHz, from %s.
", a,val2str(i),n) else table.insert(o,s) local o=ext.band(t[s],65535) local s=ext.band(ext.rshift(t[s],16),65535) local o=i/((o+1)*2) local i=i/((s+1)*2) local t=ext.band(t[h],8388608) if t~=0 then e=e..string.format("SPI%d clock frequency is variable: %sHz or %sHz, from %s.
", a,val2str(o),val2str(i),n) else e=e..string.format("SPI%d clock frequency: %sHz, from %s.
", a,val2str(o),n) end end else table.insert(o,s) table.insert(o,d) local o=ext.band(t[s],255) local s=ext.band(t[d],2147483648) local t=0 if s~=0 then t=i/(o+1) else t=i/((o+1)*2) end e=e..string.format("SPI%d clock frequency: %sHz, from %s.
", a,val2str(t),n) end end else d=string.format("SPI%d clock is not available, %s.
",a,n) end else d=string.format("SPI%d clock is not available (see APBCLK[%d].SPI%d_EN).
",a,a+12,a) end if d~=""then d=""..d.."" h["pin_no_color"]=kBgColor_Error end if e~=""then e="Information
"..e end h["information"]=string.format( "%s
%s
%s%s%s", l, d, get_mfp_regs(t,u), get_clk_informnation(t,o), e) end function fill_M051_SPI_IO(e,a,o,t) local o=string.format("SPI%d_SPI_CNTRL",o) local a=ext.band(a[o],262144) if a==0 then if t then e["direction"]=kPinDirection_In else e["direction"]=kPinDirection_PushPullOut end else if t then e["direction"]=kPinDirection_PushPullOut else e["direction"]=kPinDirection_In end end end function fill_M051_ADC(o,e,d,t,r) local h=get_chip_info()["series_group"] local n="" local a="" local t={} o["highlight_text"]=r o["normal_color"]=kColor_Invalid o["highlight_color"]=kColor_ADC o["pin_bg_color"]=kBgColor_ADC o["direction"]=kPinDirection_In o["status"]=kPinStatus_Unknown table.insert(t,"CLK_APBCLK") if ext.band(e["CLK_APBCLK"],268435456)~=0 then table.insert(t,"CLK_CLKSEL1") local s=ext.rshift(ext.band(e["CLK_CLKSEL1"],12),2) local r=ext.rshift(ext.band(e["CLK_CLKDIV"],16711680),16) local i local o if s==0 then i,o=get_XTL12M_clock(e,t) elseif s==1 then i,o=get_PLL_clock(e,t) elseif s==2 then if h~=4 and h==0 then i,o=get_OSC22M_clock(e,t) else i,o=get_HCLK_clock(e,t) end elseif s==3 then i,o=get_OSC22M_clock(e,t) else a="ADC clock is not available (see CLKSEL1[3:2].ADC_S).
" end if a==""then local e=i/(r+1) if e~=0 then table.insert(t,"CLK_CLKDIV") n=string.format("ADC clock frequency: %sHz, from %s.
",val2str(e),o) else a="ADC clock is not available, "..o..".
" end end else a="ADC clock is not available (see APBCLK[28].ADC_EN).
" end if a~=""then a=""..a.."" o["pin_no_color"]=kBgColor_Error end if n~=""then n="Information
"..n end o["information"]=string.format( "%s
%s
%s%s%s", r, a, get_mfp_regs(e,d), get_clk_informnation(e,t), n) end function fill_M051_I2C(t,o,r,a,s,e) local i="" local a="" local n={} t["highlight_text"]=s t["normal_color"]=kColor_Invalid t["highlight_color"]=kColor_I2C t["pin_bg_color"]=kBgColor_I2C t["direction"]=kPinDirection_Unknown t["status"]=kPinStatus_Unknown table.insert(n,"CLK_APBCLK") if ext.band(o["CLK_APBCLK"],ext.lshift(256,e))~=0 then local t=string.format("I2C%d_I2CON",e) local h=string.format("I2C%d_I2CLK",e) table.insert(n,t) local t=ext.band(o[t],64) if t~=0 then local t,s=get_PCLK_clock(o,n) if t~=0 then table.insert(n,h) local a=ext.band(o[h],255) local t=t/(4*(a+1)) i=string.format("I2C%d clock frequency: %sHz, from %s.
",e,val2str(t),s) else a=string.format("I2C%d clock is not available, %s.
",e,s) end else a=string.format("I2C%d controller disabled (see I2C%d.I2CON[6].ENS1).
",e,e) end else a=string.format("I2C%d clock is not available (see APBCLK[%d].I2C%d_EN).
",e,e+8,e) end if a~=""then a=""..a.."" t["pin_no_color"]=kBgColor_Error end if i~=""then i="Information
"..i end t["information"]=string.format( "%s
%s
%s%s%s", s, a, get_mfp_regs(o,r), get_clk_informnation(o,n), i) end function fill_M051_CLKO(a,e,d,t,r) local h=get_chip_info()["series_group"] local n="" local t="" local o={} a["highlight_text"]=r a["normal_color"]=kColor_Invalid a["highlight_color"]=kColor_CLK a["pin_bg_color"]=kBgColor_CLK a["direction"]=kPinDirection_PushPullOut a["status"]=kPinStatus_Unknown table.insert(o,"CLK_APBCLK") if ext.band(e["CLK_APBCLK"],64)~=0 then table.insert(o,"CLK_FRQDIV") if ext.band(e["CLK_FRQDIV"],16)~=0 then table.insert(o,"CLK_CLKSEL2") local s=ext.rshift(ext.band(e["CLK_CLKSEL2"],12),2) local r=ext.band(e["CLK_FRQDIV"],15) local a local i if s==0 then a,i=get_XTL12M_clock(e,o) elseif s==1 and h==3 then a,i=get_OSC10K_clock(e,o) elseif s==2 then a,i=get_HCLK_clock(e,o) elseif s==3 then a,i=get_OSC22M_clock(e,o) else t="Frequency divider is not available (see CLKSEL2[3:2].FRQDIV_S).
" end if t==""then local o local e=ext.band(e["CLK_FRQDIV"],32) if h==3 and e~=0 then o=a else o=a/ext.lshift(1,(r+1)) end if o~=0 then n=string.format("FRQDIV clock frequency: %sHz, from %s.
",val2str(o),i) else t="FRQDIV clock is not available, "..i..".
" end end else t="Frequency divider disabled (see FRQDIV[4].DIVIDER_EN).
" end else t="FRQDIV clock is not available (see APBCLK[6].FDIV_EN).
" end if t~=""then t=""..t.."" a["pin_no_color"]=kBgColor_Error end if n~=""then n="Information
"..n end a["information"]=string.format( "%s
%s
%s%s%s", r, t, get_mfp_regs(e,d), get_clk_informnation(e,o), n) end function fill_M051_PWM(s,t,w,e,m) local f=get_chip_info()["series_group"] local l="" local o="" local n={} local a=tonumber((m:gsub("^PWM",""))) local e=ext.rshift(a,1) local i=ext.rshift(e,1) local c=({'PWMA','PWMB'})[1+i] s["highlight_text"]=m s["normal_color"]=kColor_Invalid s["highlight_color"]=kColor_PWM s["pin_bg_color"]=kBgColor_PWM s["direction"]=kPinDirection_Unknown s["status"]=kPinStatus_Unknown table.insert(n,"CLK_APBCLK") local r=ext.band(t["CLK_APBCLK"],ext.lshift(1048576,e)) local h if r~=0 then local s local u if e==0 then s="CLKSEL1" u="[29:28]" h=ext.rshift(ext.band(t["CLK_CLKSEL1"],805306368),28) elseif e==1 then s="CLKSEL1" u="[31:30]" h=ext.rshift(ext.band(t["CLK_CLKSEL1"],3221225472),30) elseif e==2 then s="CLKSEL2" u="[5:4]" h=ext.rshift(ext.band(t["CLK_CLKSEL2"],48),4) else s="CLKSEL2" u="[7:6]" h=ext.rshift(ext.band(t["CLK_CLKSEL2"],192),6) end table.insert(n,"CLK_"..s) local d local r if h==0 then d,r=get_XTL12M_clock(t,n) elseif h==1 and(f==4 or f==2 or f==3)then d,r=get_OSC10K_clock(t,n) elseif h==2 then d,r=get_HCLK_clock(t,n) elseif h==3 then d,r=get_OSC22M_clock(t,n) else o=string.format("PWM%d clock is not available (see "..s..u..".PWM%d%d_S).
", a,e*2,e*2+1) end if o==""then if d==0 then o=string.format("PWM%d clock is not available, %s.
",a,r) else local s=c.."_CSR" local h=c.."_PPR" table.insert(n,s) table.insert(n,h) local n=ext.band(ext.rshift(t[s],4*(a-4*i)),7) local n=({2,4,8,16,1,0,0,0})[n+1] local t=ext.band(ext.rshift(t[h],8*(e-2*i)),255) if t==0 then o=string.format("PWM%d counter will be stopped since %s_PPR[%d:%d].CP%d%d = 0
", a,c, 8*(e-2*i)+7, 8*(e-2*i), (e-2*i)*2, (e-2*i)*2+1) elseif n==0 then o=string.format("PWM%d counter clock is not available (see %s_CSR[%d:%d].CSR%d).
", a,c, 4*(a-4*i)+3, 4*(a-4*i), (a-4*i)) else local e=d/(t+1) local t=e/n l=string.format("PWM%d clock frequency: %sHz (Pre-Scaled), from %s.
".. "PWM%d counter frequency: %sHz
", a,val2str(e),r, a,val2str(t)) end end end else o=string.format("PWM%d clock is not available (see APBCLK[%d].PWM%d%d_EN).
", a,e+20,e*2,e*2+1) end if o~=""then o=""..o.."" s["pin_no_color"]=kBgColor_Error end if l~=""then l="Information
"..l end s["information"]=string.format( "%s
%s
%s%s%s", m, o, get_mfp_regs(t,w), get_clk_informnation(t,n), l) end function fill_M051_TM(o,t,l,a,d,e) local s=get_chip_info()["series_group"] local n="" local i="" local a={} o["highlight_text"]=d o["normal_color"]=kColor_Invalid o["highlight_color"]=kColor_TM o["pin_bg_color"]=kBgColor_TM o["direction"]=kPinDirection_Unknown o["status"]=kPinStatus_Unknown table.insert(a,"CLK_APBCLK") local h=ext.band(t["CLK_APBCLK"],ext.lshift(4,e)) if h~=0 then local o=string.format("TMR%d_TCSR",e) table.insert(a,o) local o=ext.band(t[o],16777216) if(s==4 or s~=0)and o~=0 then n=string.format("Timer%d external counter mode enabled.
",e) else local h local o table.insert(a,"CLK_CLKSEL1") local r=ext.band(ext.rshift(t["CLK_CLKSEL1"],8+e*4),7) if r==0 then h,o=get_XTL12M_clock(t,a) elseif r==2 then h,o=get_HCLK_clock(t,a) elseif r==3 and(s==4 or s==2 or s==3)then n=string.format("Timer%d clock source is from external trigger.
",e) elseif r==5 and(s==4 or s==2 or s==3)then h,o=get_OSC10K_clock(t,a) elseif r==7 then h,o=get_OSC22M_clock(t,a) else i=string.format("Timer%d clock source is undefined (see CLK_CLKSEL1[%d:%d].TMR%d_S).
", e,8+e*4+2,8+e*4,e) end if i==""and n==""then if h~=0 then n=string.format("Timer%d clock frequency: %sHz, from %s.
", e,val2str(h),o) else i=string.format("Timer%d clock is not available, %s.
",e,o) end end end else i=string.format("Timer%d clock is disabled (see APBCLK[%d].TMR%d_EN).
",e,e+2,e) end if i~=""then i=""..i.."" o["pin_no_color"]=kBgColor_Error end if n~=""then n="Information
"..n end o["information"]=string.format( "%s
%s
%s%s%s", d, i, get_mfp_regs(t,l), get_clk_informnation(t,a), n) end function fill_M051_EBI(t,a,h,e,s) local e="" local o="" local i={} t["highlight_text"]=s t["normal_color"]=kColor_Invalid t["highlight_color"]=kColor_EBI t["pin_bg_color"]=kBgColor_EBI t["direction"]=kPinDirection_PushPullOut t["status"]=kPinStatus_Unknown table.insert(i,"CLK_AHBCLK") local n=ext.band(a["CLK_AHBCLK"],8) if n~=0 then local t local n t,n=get_HCLK_clock(a,i) if t~=0 then table.insert(i,"EBI_EBICON") local o=ext.band(ext.rshift(a["EBI_EBICON"],8),7) local i=t if o<=5 then i=ext.rshift(t,o) end e=e..string.format("EBI MCLK frequency: %sHz, from %s
", val2str(i),n) local o=ext.band(ext.rshift(a["EBI_EBICON"],1),1) local t=ext.band(a["EBI_EBICON"],1) if t~=0 then e=e..string.format("EBI Bank: address/data bus multiplex mode, and data width %d-bit
", (o~=0)and 16 or 8) else e=e..string.format("EBI Bank disabled
") end else o=string.format("EBI clock is not available, %s.
",n) end else o="EBI clock is disabled (see AHBCLK[3].EBI_EN).
" end if o~=""then o=""..o.."" t["pin_no_color"]=kBgColor_Error end if e~=""then e="Information
"..e end t["information"]=string.format( "%s
%s
%s%s%s", s, o, get_mfp_regs(a,h), get_clk_informnation(a,i), e) end function fill_M051_Normal(e,o,a,i,t) local n="" e["highlight_text"]=t e["normal_color"]=kColor_Invalid e["highlight_color"]=kColor_Normal e["pin_bg_color"]=kBgColor_Normal e["direction"]=kPinDirection_Unknown e["status"]=kPinStatus_Unknown n=t.."
" if a==nil or i==nil then e["information"]=string.format( "%s
", t) else e["information"]=string.format( "%s

".. "%s", t, get_mfp_regs(o,a)) end end