Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 """
switches 0:5c4d7b2438d3 2 mbed SDK
switches 0:5c4d7b2438d3 3 Copyright (c) 2011-2014 ARM Limited
switches 0:5c4d7b2438d3 4
switches 0:5c4d7b2438d3 5 Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 6 you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 7 You may obtain a copy of the License at
switches 0:5c4d7b2438d3 8
switches 0:5c4d7b2438d3 9 http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 10
switches 0:5c4d7b2438d3 11 Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 12 distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 14 See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 15 limitations under the License.
switches 0:5c4d7b2438d3 16
switches 0:5c4d7b2438d3 17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
switches 0:5c4d7b2438d3 18 """
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 import re
switches 0:5c4d7b2438d3 21 import json
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 class BaseDBAccess():
switches 0:5c4d7b2438d3 25 """ Class used to connect with test database and store test results
switches 0:5c4d7b2438d3 26 """
switches 0:5c4d7b2438d3 27 def __init__(self):
switches 0:5c4d7b2438d3 28 self.db_object = None
switches 0:5c4d7b2438d3 29 self.db_type = None
switches 0:5c4d7b2438d3 30 # Connection credentials
switches 0:5c4d7b2438d3 31 self.host = None
switches 0:5c4d7b2438d3 32 self.user = None
switches 0:5c4d7b2438d3 33 self.passwd = None
switches 0:5c4d7b2438d3 34 self.db = None
switches 0:5c4d7b2438d3 35
switches 0:5c4d7b2438d3 36 # Test Suite DB scheme (table names)
switches 0:5c4d7b2438d3 37 self.TABLE_BUILD_ID = 'mtest_build_id'
switches 0:5c4d7b2438d3 38 self.TABLE_BUILD_ID_STATUS = 'mtest_build_id_status'
switches 0:5c4d7b2438d3 39 self.TABLE_BUILD_ID_TYPE = 'mtest_build_id_type'
switches 0:5c4d7b2438d3 40 self.TABLE_TARGET = 'mtest_target'
switches 0:5c4d7b2438d3 41 self.TABLE_TEST_ENTRY = 'mtest_test_entry'
switches 0:5c4d7b2438d3 42 self.TABLE_TEST_ID = 'mtest_test_id'
switches 0:5c4d7b2438d3 43 self.TABLE_TEST_RESULT = 'mtest_test_result'
switches 0:5c4d7b2438d3 44 self.TABLE_TEST_TYPE = 'mtest_test_type'
switches 0:5c4d7b2438d3 45 self.TABLE_TOOLCHAIN = 'mtest_toolchain'
switches 0:5c4d7b2438d3 46 # Build ID status PKs
switches 0:5c4d7b2438d3 47 self.BUILD_ID_STATUS_STARTED = 1 # Started
switches 0:5c4d7b2438d3 48 self.BUILD_ID_STATUS_IN_PROGRESS = 2 # In Progress
switches 0:5c4d7b2438d3 49 self.BUILD_ID_STATUS_COMPLETED = 3 #Completed
switches 0:5c4d7b2438d3 50 self.BUILD_ID_STATUS_FAILED = 4 # Failed
switches 0:5c4d7b2438d3 51 # Build ID type PKs
switches 0:5c4d7b2438d3 52 self.BUILD_ID_TYPE_TEST = 1 # Test
switches 0:5c4d7b2438d3 53 self.BUILD_ID_TYPE_BUILD_ONLY = 2 # Build Only
switches 0:5c4d7b2438d3 54
switches 0:5c4d7b2438d3 55 def get_hostname(self):
switches 0:5c4d7b2438d3 56 """ Useful when creating build_id in database
switches 0:5c4d7b2438d3 57 Function returns (hostname, uname) which can be used as (build_id_name, build_id_desc)
switches 0:5c4d7b2438d3 58 """
switches 0:5c4d7b2438d3 59 # Get hostname from socket
switches 0:5c4d7b2438d3 60 import socket
switches 0:5c4d7b2438d3 61 hostname = socket.gethostbyaddr(socket.gethostname())[0]
switches 0:5c4d7b2438d3 62 # Get uname from platform resources
switches 0:5c4d7b2438d3 63 import platform
switches 0:5c4d7b2438d3 64 uname = json.dumps(platform.uname())
switches 0:5c4d7b2438d3 65 return (hostname, uname)
switches 0:5c4d7b2438d3 66
switches 0:5c4d7b2438d3 67 def get_db_type(self):
switches 0:5c4d7b2438d3 68 """ Returns database type. E.g. 'mysql', 'sqlLite' etc.
switches 0:5c4d7b2438d3 69 """
switches 0:5c4d7b2438d3 70 return self.db_type
switches 0:5c4d7b2438d3 71
switches 0:5c4d7b2438d3 72 def detect_database(self, verbose=False):
switches 0:5c4d7b2438d3 73 """ detect database and return VERION data structure or string (verbose=True)
switches 0:5c4d7b2438d3 74 """
switches 0:5c4d7b2438d3 75 return None
switches 0:5c4d7b2438d3 76
switches 0:5c4d7b2438d3 77 def parse_db_connection_string(self, str):
switches 0:5c4d7b2438d3 78 """ Parsing SQL DB connection string. String should contain:
switches 0:5c4d7b2438d3 79 - DB Name, user name, password, URL (DB host), name
switches 0:5c4d7b2438d3 80 Function should return tuple with parsed (db_type, username, password, host, db_name) or None if error
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 (db_type, username, password, host, db_name) = self.parse_db_connection_string(db_url)
switches 0:5c4d7b2438d3 83
switches 0:5c4d7b2438d3 84 E.g. connection string: 'mysql://username:password@127.0.0.1/db_name'
switches 0:5c4d7b2438d3 85 """
switches 0:5c4d7b2438d3 86 result = None
switches 0:5c4d7b2438d3 87 if type(str) == type(''):
switches 0:5c4d7b2438d3 88 PATTERN = '^([\w]+)://([\w]+):([\w]*)@(.*)/([\w]+)'
switches 0:5c4d7b2438d3 89 result = re.match(PATTERN, str)
switches 0:5c4d7b2438d3 90 if result is not None:
switches 0:5c4d7b2438d3 91 result = result.groups() # Tuple (db_name, host, user, passwd, db)
switches 0:5c4d7b2438d3 92 return result # (db_type, username, password, host, db_name)
switches 0:5c4d7b2438d3 93
switches 0:5c4d7b2438d3 94 def is_connected(self):
switches 0:5c4d7b2438d3 95 """ Returns True if we are connected to database
switches 0:5c4d7b2438d3 96 """
switches 0:5c4d7b2438d3 97 pass
switches 0:5c4d7b2438d3 98
switches 0:5c4d7b2438d3 99 def connect(self, host, user, passwd, db):
switches 0:5c4d7b2438d3 100 """ Connects to DB and returns DB object
switches 0:5c4d7b2438d3 101 """
switches 0:5c4d7b2438d3 102 pass
switches 0:5c4d7b2438d3 103
switches 0:5c4d7b2438d3 104 def connect_url(self, db_url):
switches 0:5c4d7b2438d3 105 """ Connects to database using db_url (database url parsing),
switches 0:5c4d7b2438d3 106 store host, username, password, db_name
switches 0:5c4d7b2438d3 107 """
switches 0:5c4d7b2438d3 108 pass
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 def reconnect(self):
switches 0:5c4d7b2438d3 111 """ Reconnects to DB and returns DB object using stored host name,
switches 0:5c4d7b2438d3 112 database name and credentials (user name and password)
switches 0:5c4d7b2438d3 113 """
switches 0:5c4d7b2438d3 114 pass
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116 def disconnect(self):
switches 0:5c4d7b2438d3 117 """ Close DB connection
switches 0:5c4d7b2438d3 118 """
switches 0:5c4d7b2438d3 119 pass
switches 0:5c4d7b2438d3 120
switches 0:5c4d7b2438d3 121 def escape_string(self, str):
switches 0:5c4d7b2438d3 122 """ Escapes string so it can be put in SQL query between quotes
switches 0:5c4d7b2438d3 123 """
switches 0:5c4d7b2438d3 124 pass
switches 0:5c4d7b2438d3 125
switches 0:5c4d7b2438d3 126 def select_all(self, query):
switches 0:5c4d7b2438d3 127 """ Execute SELECT query and get all results
switches 0:5c4d7b2438d3 128 """
switches 0:5c4d7b2438d3 129 pass
switches 0:5c4d7b2438d3 130
switches 0:5c4d7b2438d3 131 def insert(self, query, commit=True):
switches 0:5c4d7b2438d3 132 """ Execute INSERT query, define if you want to commit
switches 0:5c4d7b2438d3 133 """
switches 0:5c4d7b2438d3 134 pass
switches 0:5c4d7b2438d3 135
switches 0:5c4d7b2438d3 136 def get_next_build_id(self, name, desc='', location='', type=None, status=None):
switches 0:5c4d7b2438d3 137 """ Insert new build_id (DB unique build like ID number to send all test results)
switches 0:5c4d7b2438d3 138 """
switches 0:5c4d7b2438d3 139 pass
switches 0:5c4d7b2438d3 140
switches 0:5c4d7b2438d3 141 def get_table_entry_pk(self, table, column, value, update_db=True):
switches 0:5c4d7b2438d3 142 """ Checks for entries in tables with two columns (<TABLE_NAME>_pk, <column>)
switches 0:5c4d7b2438d3 143 If update_db is True updates table entry if value in specified column doesn't exist
switches 0:5c4d7b2438d3 144 """
switches 0:5c4d7b2438d3 145 pass
switches 0:5c4d7b2438d3 146
switches 0:5c4d7b2438d3 147 def update_table_entry(self, table, column, value):
switches 0:5c4d7b2438d3 148 """ Updates table entry if value in specified column doesn't exist
switches 0:5c4d7b2438d3 149 Locks table to perform atomic read + update
switches 0:5c4d7b2438d3 150 """
switches 0:5c4d7b2438d3 151 pass
switches 0:5c4d7b2438d3 152
switches 0:5c4d7b2438d3 153 def update_build_id_info(self, build_id, **kw):
switches 0:5c4d7b2438d3 154 """ Update additional data inside build_id table
switches 0:5c4d7b2438d3 155 Examples:
switches 0:5c4d7b2438d3 156 db.update_build_is(build_id, _status_fk=self.BUILD_ID_STATUS_COMPLETED, _shuffle_seed=0.0123456789):
switches 0:5c4d7b2438d3 157 """
switches 0:5c4d7b2438d3 158 pass
switches 0:5c4d7b2438d3 159
switches 0:5c4d7b2438d3 160 def insert_test_entry(self, build_id, target, toolchain, test_type, test_id, test_result, test_time, test_timeout, test_loop, test_extra=''):
switches 0:5c4d7b2438d3 161 """ Inserts test result entry to database. All checks regarding existing
switches 0:5c4d7b2438d3 162 toolchain names in DB are performed.
switches 0:5c4d7b2438d3 163 If some data is missing DB will be updated
switches 0:5c4d7b2438d3 164 """
switches 0:5c4d7b2438d3 165 pass