Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from abc import ABC, abstractmethod 

10 

11 

12class RegisterField(ABC): 

13 

14 """ 

15 Meta class for all register fields (bits, bit vectors, integers, ...). 

16 Lists a few methods that must be implemented. 

17 """ 

18 

19 @property 

20 @abstractmethod 

21 def width(self): 

22 """ 

23 Return the width, in number of bits, that this field occupies. 

24 

25 Returns: 

26 int: The width. 

27 """ 

28 raise NotImplementedError("Must be implemented in child class") 

29 

30 @property 

31 @abstractmethod 

32 def range(self): 

33 """ 

34 Return the bits that this field occupies in a readable format. 

35 The way it shall appear in documentation. 

36 

37 Returns: 

38 str: The bit range. 

39 """ 

40 raise NotImplementedError("Must be implemented in child class") 

41 

42 @property 

43 @abstractmethod 

44 def default_value_str(self): 

45 """ 

46 Return a formatted string of the default value. The way it shall appear in documentation. 

47 

48 Returns: 

49 str: The default value. 

50 """ 

51 raise NotImplementedError("Must be implemented in child class") 

52 

53 @property 

54 @abstractmethod 

55 def default_value_uint(self): 

56 """ 

57 Return a the default value as an unsigned int. 

58 

59 Returns: 

60 int: The default value. 

61 """ 

62 raise NotImplementedError("Must be implemented in child class") 

63 

64 @abstractmethod 

65 def get_value(self, register_value): 

66 """ 

67 Get the value of this field, given the supplied register value. 

68 Child classes might implement sanity checks on the value. 

69 

70 Arguments: 

71 register_value (int): Value of the register that this field belongs to. 

72 

73 Returns: 

74 int: The value. 

75 """ 

76 raise NotImplementedError("Must be implemented in child class")