<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def watchpoint_set(self, addr, addr_mask=0x0, data=0x0, data_mask=0x0, access_size=None, read=False, write=False, privileged=False):
 """Sets a watchpoint at the given address. This method allows for a watchpoint to be set on an given address or range of addresses. The watchpoint can then be triggered if the data at the given address matches the specified ``data`` or range of data as determined by ``data_mask``, on specific access size events, reads, writes, or privileged accesses. Both ``addr_mask`` and ``data_mask`` are used to specify ranges. Bits set to ``1`` are masked out and not taken into consideration when comparison against an address or data value. E.g. an ``addr_mask`` with a value of ``0x1`` and ``addr`` with value ``0xdeadbeef`` means that the watchpoint will be set on addresses ``0xdeadbeef`` and ``0xdeadbeee``. If the ``data`` was ``0x11223340`` and the given ``data_mask`` has a value of ``0x0000000F``, then the watchpoint would trigger for data matching ``0x11223340 - 0x1122334F``. Note: If both ``read`` and ``write`` are specified, then the watchpoint will trigger on both read and write events to the given address. Args: self (JLink):
 the ``JLink`` instance addr_mask (int):
 optional mask to use for determining which address the watchpoint should be set on data (int):
 optional data to set the watchpoint on in order to have the watchpoint triggered when the value at the specified address matches the given ``data`` data_mask (int):
 optional mask to use for determining the range of data on which the watchpoint should be triggered access_size (int):
 if specified, this must be one of ``{8, 16, 32}`` and determines the access size for which the watchpoint should trigger read (bool):
 if ``True``, triggers the watchpoint on read events write (bool):
 if ``True``, triggers the watchpoint on write events privileged (bool):
 if ``True``, triggers the watchpoint on privileged accesses Returns: The handle of the created watchpoint. Raises: ValueError: if an invalid access size is given. JLinkException: if the watchpoint fails to be set. """

        access_flags = 0x0
        access_mask_flags = 0x0

        # If an access size is not specified, we must specify that the size of
        # the access does not matter by specifying the access mask flags.
        if access_size is None:
            access_mask_flags = access_mask_flags | enums.JLinkAccessMaskFlags.SIZE
        elif access_size == 8:
            access_flags = access_flags | enums.JLinkAccessFlags.SIZE_8BIT
        elif access_size == 16:
            access_flags = access_flags | enums.JLinkAccessFlags.SIZE_16BIT
        elif access_size == 32:
            access_flags = access_flags | enums.JLinkAccessFlags.SIZE_32BIT
        else:
            raise ValueError('Invalid access size given: %d' % access_size)

        # The read and write access flags cannot be specified together, so if
        # the user specifies that they want read and write access, then the
        # access mask flag must be set.
        if read and write:
            access_mask_flags = access_mask_flags | enums.JLinkAccessMaskFlags.DIR
        elif read:
            access_flags = access_flags | enums.JLinkAccessFlags.READ
        elif write:
            access_flags = access_flags | enums.JLinkAccessFlags.WRITE

        # If privileged is not specified, then there is no specification level
        # on which kinds of writes should be accessed, in which case we must
        # specify that flag.
        if privileged:
            access_flags = access_flags | enums.JLinkAccessFlags.PRIV
        else:
            access_mask_flags = access_mask_flags | enums.JLinkAccessMaskFlags.PRIV

        # Populate the Data event to configure how the watchpoint is triggered.
        wp = structs.JLinkDataEvent()
        wp.Addr = addr
        wp.AddrMask = addr_mask
        wp.Data = data
        wp.DataMask = data_mask
        wp.Access = access_flags
        wp.AccessMask = access_mask_flags

        # Return value of the function is <= 0 in the event of an error,
        # otherwise the watchpoint was set successfully.
        handle = ctypes.c_uint32()
        res = self._dll.JLINKARM_SetDataEvent(ctypes.pointer(wp), ctypes.pointer(handle))
        if res < 0:
            raise errors.JLinkDataException(res)

        return handle.value