Esempio n. 1
0
 def init_dividers(self):
     """
         Add clock dividers to the clock tree
     """
     table = make_table(self.RCC.CFGR.RTCPRE, hsertc_get_div)
     Divider(
         tree=self.tree,
         name='HSERTC',
         parent='HSE',
         div_field=self.RCC.CFGR.RTCPRE,
         table=table,
     )
     #                min=MHz(1), max=MHz(1))
     table = make_table(self.RCC.CFGR.HPRE, hpre_get_div)
     Divider(tree=self.tree,
             name='AHB',
             parent='SW',
             div_field=self.RCC.CFGR.HPRE,
             table=table,
             min=MHz(25))
     table = make_table(self.RCC.CFGR.PPRE1, ppre_get_div)
     Divider(tree=self.tree,
             name='APB1',
             parent='AHB',
             div_field=self.RCC.CFGR.PPRE1,
             table=table,
             max=MHz(45))
     Divider(tree=self.tree,
             name='APB2',
             parent='AHB',
             div_field=self.RCC.CFGR.PPRE2,
             table=table,
             max=MHz(90))
Esempio n. 2
0
 def setUpClass(self):
     super(TestClockTree, self).setUpClass()
     FixedClock(name='osc1', tree=self.tree, freq=1234)
     FixedClock(name='osc2', tree=self.tree, freq=2345)
     FixedClock(name='osc3', tree=self.tree, freq=5432)
     Mux(name='mux1',
         tree=self.tree,
         mux_field=self.dev.TEST1.TESTA.A3,
         parents={
             0: 'osc1',
             1: 'osc2',
             2: 'osc3',
             3: 'osc3'
         })
     Divider(name='div1', tree=self.tree, div=2, parent='osc1')
     Divider(name='div2', tree=self.tree, div=4, parent='mux1')
     Gate(name='gate1',
          tree=self.tree,
          parent='div1',
          en_field=self.dev.TEST1.TESTA.A1)
     Gate(name='gate2',
          tree=self.tree,
          parent='div2',
          en_field=self.dev.TEST1.TESTA.A2)
     Divider(name='div3', tree=self.tree, div=2, parent='gate2')
Esempio n. 3
0
 def __init__(self, device):
     super(BL123ClockTree, self).__init__(device)
     device.tree = self
     clk0 = device.CLOCK0
     FixedClock(tree=self, name='OSC0',
                freq=MHz(1), en_field=clk0.OSC0.EN)
     FixedClock(tree=self, name='OSC1',
                freq=MHz(8), en_field=clk0.OSC1.EN)
     FixedClock(tree=self, name='OSC2',
                freq=MHz(16), en_field=clk0.OSC2.EN)
     Mux(tree=self, name='PLLSRC',
         parents={0: 'OSC0', 1: 'OSC1', 2: 'OSC2'}, mux_field=clk0.PLL.SRC)
     PLL(tree=self, name='PLL', parent='PLLSRC',
         get_freq=pll_get_freq, en_field=clk0.PLL.EN)
     Mux(tree=self, name='BUS0SRC', mux_field=clk0.BUS0.SRC,
         parents={0: 'OSC0', 1: 'OSC1', 2: 'OSC2', 3: 'PLL'})
     Divider(tree=self, name='BUS0DIV', parent='BUS0SRC',
         div_field=clk0.BUS0.DIV, div_type=Divider.POWER_OF_TWO)
     Divider(tree=self, name='BUS1DIV', parent='BUS0DIV',
         div_field=clk0.BUS1.DIV, div_type=Divider.POWER_OF_TWO)
     Gate(tree=self, name='UART0', parent='BUS0DIV',
          en_field=clk0.UART0.EN)
     Gate(tree=self, name='UART1', parent='BUS0DIV',
          en_field=clk0.UART1.EN)
     Gate(tree=self, name='GPIO0', parent='BUS1DIV',
          en_field=clk0.GPIO0.EN)
     Gate(tree=self, name='GPIO1', parent='BUS1DIV',
          en_field=clk0.GPIO1.EN)
     Gate(tree=self, name='GPIO2', parent='BUS1DIV',
          en_field=clk0.GPIO2.EN)
     Gate(tree=self, name='GPIO3', parent='BUS1DIV',
          en_field=clk0.GPIO3.EN)
Esempio n. 4
0
    def test_enabled(self):
        freq = 123456
        tree = ClockTree(self.dev)
        FixedClock(name='test', tree=self.tree, freq=freq)

        div = Divider(name='div', tree=self.tree, parent='test', div=2)
        self.assertTrue(div.enabled())

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      get_div=ext_get_div_zero,
                      div_type=Divider.ZERO_TO_GATE)
        self.assertFalse(div.enabled())

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      get_div=ext_get_div_none)
        self.assertFalse(div.enabled())
Esempio n. 5
0
    def test_build(self):
        self.assertTrue(self.tree.build())

        Divider(name='div4', tree=self.tree)
        self.assertFalse(self.tree.build())
        self.tree.clocks.pop('div4')
Esempio n. 6
0
    def test_get_freq(self):
        freq = 123456
        tree = ClockTree(self.dev)
        FixedClock(name='test', tree=self.tree, freq=freq)

        div = Divider(name='div', tree=self.tree, parent='test', div=2)
        self.assertEqual(div._get_freq(), freq / 2)

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      get_div=ext_get_div_none)
        self.assertEqual(div._get_freq(), 0)

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      get_div=ext_get_div_zero)
        with self.assertRaises(ZeroDivisionError):
            self.assertEqual(div._get_freq(), 0)

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      get_div=ext_get_div_zero,
                      div_type=Divider.ZERO_TO_GATE)
        self.assertEqual(div._get_freq(), 0)
Esempio n. 7
0
    def test_get_div(self):
        tree = ClockTree(self.dev)
        FixedClock(name='test', tree=self.tree, freq=123456)

        div = Divider(name='div', tree=self.tree, parent='test', div=2)
        self.assertEqual(div._get_div(), 2)

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      div_field=self.dev.TEST1.TESTA.A3)
        self.assertEqual(int(div._get_div()), 3)

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      div_field=self.dev.TEST1.TESTA.A3,
                      div_type=Divider.POWER_OF_TWO)
        self.assertEqual(int(div._get_div()), 8)

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      div_field=self.dev.TEST1.TESTA.A3,
                      table={
                          3: 12,
                          4: 16
                      })
        self.assertEqual(int(div._get_div()), 12)

        self.dev.TEST1.TESTA.A3.write(2)
        with self.assertRaises(InvalidDivider):
            div._get_div()

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      div_field=self.dev.TEST1.TESTA.A3,
                      div_type=9999)
        with self.assertRaises(InvalidDivider):
            div._get_div()

        div = Divider(name='div',
                      tree=self.tree,
                      parent='test',
                      get_div=ext_get_div)
        self.assertTrue(div.build())
        self.assertEqual(int(div._get_div()), 3)
Esempio n. 8
0
    def test_build(self):
        div = Divider()
        self.assertFalse(div.build())

        div = Divider(parent='test')
        self.assertFalse(div.build())

        div = Divider(parent='test', div=2)
        self.assertTrue(div.build())

        table = {0: 1, 1: 4, 2: 16}
        div = Divider(parent='test', table=table)
        self.assertFalse(div.build())

        div = Divider(parent='test',
                      table=table,
                      div_field=self.dev.TEST1.TESTA.A3)
        self.assertTrue(div.build())

        div = Divider(parent='test', table=table)
        self.assertFalse(div.build())

        div = Divider(parent='test', div_field=self.dev.TEST1.TESTA.A3)
        self.assertTrue(div.build())