Denislam Valeev / Mbed OS Nucleo_rtos_basic
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers module_reset_mbed.py Source File

module_reset_mbed.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2013 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 from __future__ import print_function
00018 
00019 from .host_test_plugins import HostTestPluginBase
00020 
00021 
00022 class HostTestPluginResetMethod_Mbed(HostTestPluginBase):
00023 
00024     def safe_sendBreak(self, serial):
00025         """ Wraps serial.sendBreak() to avoid serial::serialposix.py exception on Linux
00026             Traceback (most recent call last):
00027               File "make.py", line 189, in <module>
00028                 serial.sendBreak()
00029               File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 511, in sendBreak
00030                 termios.tcsendbreak(self.fd, int(duration/0.25))
00031             error: (32, 'Broken pipe')
00032         """
00033         result = True
00034         try:
00035             serial.sendBreak()
00036         except:
00037             # In linux a termios.error is raised in sendBreak and in setBreak.
00038             # The following setBreak() is needed to release the reset signal on the target mcu.
00039             try:
00040                 serial.setBreak(False)
00041             except:
00042                 result = False
00043         return result
00044 
00045     # Plugin interface
00046     name = 'HostTestPluginResetMethod_Mbed'
00047     type = 'ResetMethod'
00048     stable = True
00049     capabilities = ['default']
00050     required_parameters = ['serial']
00051 
00052     def setup(self, *args, **kwargs):
00053         """ Configure plugin, this function should be called before plugin execute() method is used.
00054         """
00055         return True
00056 
00057     def execute(self, capabilitity, *args, **kwargs):
00058         """ Executes capability by name.
00059             Each capability may directly just call some command line
00060             program or execute building pythonic function
00061         """
00062         result = False
00063         if self.check_parameters(capabilitity, *args, **kwargs) is True:
00064             if capabilitity == 'default':
00065                 serial = kwargs['serial']
00066                 result = self.safe_sendBreak(serial)
00067         return result
00068 
00069 
00070 def load_plugin ():
00071     """ Returns plugin available in this module
00072     """
00073     return HostTestPluginResetMethod_Mbed()