-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from ARMmbed/yotta_config_parse
Add yotta config parse functionality
- Loading branch information
Showing
4 changed files
with
276 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
mbed SDK | ||
Copyright (c) 2011-2015 ARM Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com> | ||
""" | ||
|
||
import os | ||
import json | ||
|
||
|
||
class YottaConfig(): | ||
|
||
yotta_config = None | ||
|
||
def __init__(self): | ||
self.BUILD_DIR = 'build' | ||
self.YOTTA_CONFIG_NAME = 'yotta_config.json' | ||
self.DEFAULT_BAUDRATE = 115200 | ||
|
||
def init(self, target_name): | ||
"""! Loads yotta_config.json as an object from local yotta build directory | ||
@return True if data was successfuly loaded from the file | ||
""" | ||
try: | ||
path = os.path.join(self.BUILD_DIR, target_name, self.YOTTA_CONFIG_NAME) | ||
with open(path, 'r') as data_file: | ||
self.yotta_config = json.load(data_file) | ||
except IOError as e: | ||
self.yotta_config = {} | ||
return bool(len(self.yotta_config)) | ||
|
||
def set_yotta_config(self, yotta_config): | ||
self.yotta_config = yotta_config | ||
|
||
def get_baudrate(self): | ||
"""! Returns default baudrate for stdio serial | ||
@return Configuration baudrate of default on (115200) | ||
Example yotta_config.json | ||
{ | ||
"minar": { | ||
"initial_event_pool_size": 50, | ||
"additional_event_pools_size": 100 | ||
}, | ||
"mbed-os": { | ||
"net": { | ||
"stacks": { | ||
"lwip": true | ||
} | ||
}, | ||
"stdio": { | ||
"default-baud": 9600 | ||
} | ||
}, | ||
""" | ||
# Get default baudrate for this target | ||
if self.yotta_config and 'mbed-os' in self.yotta_config: | ||
if 'stdio' in self.yotta_config['mbed-os']: | ||
if 'default-baud' in self.yotta_config['mbed-os']['stdio']: | ||
return int(self.yotta_config['mbed-os']['stdio']['default-baud']) | ||
return self.DEFAULT_BAUDRATE | ||
|
||
def get_test_pins(self): | ||
if self.yotta_config and 'hardware' in self.yotta_config: | ||
if 'test-pins' in self.yotta_config['hardware']: | ||
return self.yotta_config['hardware']['test-pins'] | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,3 +216,5 @@ def list_platforms_ext(self): | |
return {'K64F': 2} | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
#!/usr/bin/env python | ||
""" | ||
mbed SDK | ||
Copyright (c) 2011-2015 ARM Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
import unittest | ||
from mbed_greentea.mbed_yotta_target_parse import YottaConfig | ||
|
||
class YOttaConfigurationParse(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.YOTTA_CONFIG_LONG = { | ||
"minar": { | ||
"initial_event_pool_size": 50, | ||
"additional_event_pools_size": 100 | ||
}, | ||
"mbed-os": { | ||
"net": { | ||
"stacks": { | ||
"lwip": True | ||
} | ||
}, | ||
"stdio": { | ||
"default-baud": 9600 | ||
} | ||
}, | ||
"cmsis": { | ||
"nvic": { | ||
"ram_vector_address": "0x1FFF0000", | ||
"flash_vector_address": "0x0", | ||
"user_irq_offset": 16, | ||
"user_irq_number": 86 | ||
} | ||
}, | ||
"hardware": { | ||
"pins": { | ||
"LED_RED": "PTB22", | ||
"LED_GREEN": "PTE26", | ||
"LED_BLUE": "PTB21", | ||
"LED1": "LED_RED", | ||
"LED2": "LED_GREEN", | ||
"LED3": "LED_BLUE", | ||
"LED4": "LED_RED", | ||
"SW2": "PTC6", | ||
"SW3": "PTA4", | ||
"USBTX": "PTB17", | ||
"USBRX": "PTB16", | ||
"D0": "PTC16", | ||
"D1": "PTC17", | ||
"D2": "PTB9", | ||
"D3": "PTA1", | ||
"D4": "PTB23", | ||
"D5": "PTA2", | ||
"D6": "PTC2", | ||
"D7": "PTC3", | ||
"D8": "PTA0", | ||
"D9": "PTC4", | ||
"D10": "PTD0", | ||
"D11": "PTD2", | ||
"D12": "PTD3", | ||
"D13": "PTD1", | ||
"D14": "PTE25", | ||
"D15": "PTE24", | ||
"I2C_SCL": "D15", | ||
"I2C_SDA": "D14", | ||
"A0": "PTB2", | ||
"A1": "PTB3", | ||
"A2": "PTB10", | ||
"A3": "PTB11", | ||
"A4": "PTC10", | ||
"A5": "PTC11", | ||
"DAC0_OUT": "0xFEFE" | ||
}, | ||
"test-pins": { | ||
"spi": { | ||
"mosi": "PTD2", | ||
"miso": "PTD3", | ||
"sclk": "PTD1", | ||
"ssel": "PTD0" | ||
}, | ||
"i2c": { | ||
"sda": "PTE25", | ||
"scl": "PTE24" | ||
}, | ||
"serial": { | ||
"tx": "PTC17", | ||
"rx": "PTD2" | ||
} | ||
} | ||
}, | ||
"uvisor": { | ||
"present": 1 | ||
}, | ||
"arch": { | ||
"arm": {} | ||
}, | ||
"mbed": {} | ||
} | ||
|
||
self.YOTTA_CONFIG_SHORT = { | ||
"minar": { | ||
"initial_event_pool_size": 50, | ||
"additional_event_pools_size": 100 | ||
}, | ||
"mbed-os": { | ||
"net": { | ||
"stacks": { | ||
"lwip": True | ||
} | ||
}, | ||
"stdio": { | ||
"default-baud": 38400 | ||
} | ||
}, | ||
"cmsis": { | ||
"nvic": { | ||
"ram_vector_address": "0x1FFF0000", | ||
"flash_vector_address": "0x0", | ||
"user_irq_offset": 16, | ||
"user_irq_number": 86 | ||
} | ||
}, | ||
} | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_get_baudrate_9600(self): | ||
yotta_config = YottaConfig() | ||
yotta_config.set_yotta_config(self.YOTTA_CONFIG_LONG) | ||
self.assertEqual(yotta_config.get_baudrate(), 9600) | ||
|
||
def test_get_baudrate_38400(self): | ||
yotta_config = YottaConfig() | ||
yotta_config.set_yotta_config(self.YOTTA_CONFIG_SHORT) | ||
self.assertEqual(yotta_config.get_baudrate(), 38400) | ||
|
||
def test_get_baudrate_default_115200(self): | ||
yotta_config = YottaConfig() | ||
self.assertEqual(115200, yotta_config.DEFAULT_BAUDRATE) | ||
|
||
def test_get_baudrate_default_115200_no_yotta_config(self): | ||
yotta_config = YottaConfig() | ||
self.assertEqual(yotta_config.get_baudrate(), yotta_config.DEFAULT_BAUDRATE) | ||
|
||
def test_get_baudrate_None(self): | ||
yotta_config = YottaConfig() | ||
yotta_config.set_yotta_config(None) | ||
self.assertEqual(yotta_config.get_baudrate(), yotta_config.DEFAULT_BAUDRATE) | ||
self.assertEqual(115200, yotta_config.DEFAULT_BAUDRATE) | ||
|
||
def test_get_test_pins(self): | ||
yotta_config = YottaConfig() | ||
yotta_config.set_yotta_config(self.YOTTA_CONFIG_LONG) | ||
self.assertEqual(yotta_config.get_baudrate(), 9600) | ||
self.assertIn('spi', yotta_config.get_test_pins()) | ||
self.assertIn('i2c', yotta_config.get_test_pins()) | ||
self.assertIn('serial', yotta_config.get_test_pins()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |