pull/263/head
bcostm 2014-04-16 14:25:03 +02:00
commit 06434d9d38
9 changed files with 156 additions and 57 deletions

View File

@ -51,7 +51,13 @@ public:
* An integer with each bit corresponding to the value read from the associated DigitalIn pin
*/
int read();
/** Set the input pin mode
*
* @param mode PullUp, PullDown, PullNone
*/
void mode(PinMode pull);
#ifdef MBED_OPERATORS
/** A shorthand for read()
*/

View File

@ -49,6 +49,14 @@ int BusIn::read() {
return v;
}
void BusIn::mode(PinMode pull) {
for (int i=0; i<16; i++) {
if (_pin[i] != 0) {
_pin[i]->mode(pull);
}
}
}
#ifdef MBED_OPERATORS
BusIn::operator int() {
return read();

View File

@ -18,16 +18,20 @@
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
{
gpio_init(gpio, pin);
gpio_dir(gpio, PIN_INPUT);
gpio_mode(gpio, mode);
if (pin != NC) {
gpio_dir(gpio, PIN_INPUT);
gpio_mode(gpio, mode);
}
}
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
{
gpio_init(gpio, pin);
gpio_write(gpio, value);
gpio_dir(gpio, PIN_OUTPUT);
gpio_mode(gpio, mode);
if (pin != NC) {
gpio_write(gpio, value);
gpio_dir(gpio, PIN_OUTPUT);
gpio_mode(gpio, mode);
}
}
void gpio_init_in(gpio_t* gpio, PinName pin) {
@ -49,7 +53,8 @@ void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
if (direction == PIN_INPUT) {
_gpio_init_in(gpio, pin, mode);
gpio_write(gpio, value); // we prepare the value in case it is switched later
if (pin != NC)
gpio_write(gpio, value); // we prepare the value in case it is switched later
} else {
_gpio_init_out(gpio, pin, mode, value);
}

View File

@ -43,7 +43,7 @@ static const PinMap PinMap_PWM[] = {
{PA_2, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
//{PA_2, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH3
//{PA_2, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
//{PA_3, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH4
//{PA_3, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
{PA_5, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH1
@ -77,7 +77,7 @@ static const PinMap PinMap_PWM[] = {
{PC_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
{PC_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
{PC_8, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
{NC, NC, 0}
};
@ -183,13 +183,13 @@ void pwmout_write(pwmout_t* obj, float value) {
break;
// Channels 3
case PA_2:
case PA_3:
//case PA_3:
case PA_10:
//case PB_0:
case PB_8:
case PB_10:
case PC_8:
case PC_9:
//case PC_9:
channel = TIM_CHANNEL_3;
break;
// Channels 3N
@ -199,10 +199,11 @@ void pwmout_write(pwmout_t* obj, float value) {
complementary_channel = 1;
break;
// Channels 4
//case PA_3:
case PA_3:
case PA_11:
//case PB_1:
case PB_9:
case PC_9:
channel = TIM_CHANNEL_4;
break;
default:

View File

@ -1,28 +1,46 @@
#include "mbed.h"
#include "MMA8451Q.h"
#define MMA8451_I2C_ADDRESS (0x1d<<1)
#include "test_env.h"
#ifdef TARGET_KL05Z
#define SDA PTB4
#define SCL PTB3
#define SDA PTB4
#define SCL PTB3
#else
#define SDA PTE25
#define SCL PTE24
#define SDA PTE25
#define SCL PTE24
#endif
namespace {
const int MMA8451_I2C_ADDRESS = 0x1D << 1; // I2C bus address
const float MMA8451_DIGITAL_SENSITIVITY = 4096.0; // Counts/g
}
float calc_3d_vector_len(float x, float y, float z) {
return sqrt(x*x + y*y + z*z);
}
#define TEST_ITERATIONS 25
#define TEST_ITERATIONS_SKIP 5
#define MEASURE_DEVIATION_TOLERANCE 0.025 // 2.5%
int main(void) {
DigitalOut led(LED_GREEN);
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
printf("WHO AM I: 0x%2X\r\n", acc.getWhoAmI());
bool result = true;
printf("WHO AM I: 0x%2X\r\n\n", acc.getWhoAmI());
while (true) {
printf("-----------\r\n");
printf("acc_x: %d\r\n", acc.getAccX());
printf("acc_y: %d\r\n", acc.getAccY());
printf("acc_z: %d\r\n", acc.getAccZ());
wait(1);
for (int i = 0; i < TEST_ITERATIONS; i++) {
if (i < TEST_ITERATIONS_SKIP) {
// Skip first 5 measurements
continue;
}
const float g_vect_len = calc_3d_vector_len(acc.getAccX(), acc.getAccY(), acc.getAccZ()) / MMA8451_DIGITAL_SENSITIVITY;
const float deviation = fabs(g_vect_len - 1.0);
const char *succes_str = deviation <= MEASURE_DEVIATION_TOLERANCE ? "[OK]" : "[FAIL]";
result = result && (deviation <= MEASURE_DEVIATION_TOLERANCE);
printf("X:% 6d Y:% 6d Z:% 5d GF:%0.3fg, dev:%0.3f ... %s\r\n", acc.getAccX(), acc.getAccY(), acc.getAccZ(), g_vect_len, deviation, succes_str);
wait(0.5);
led = !led;
}
notify_completion(result);
}

View File

@ -1,34 +1,69 @@
#include "mbed.h"
#include "EthernetInterface.h"
const char* ECHO_SERVER_ADDRESS = "10.2.200.57";
const int ECHO_PORT = 7;
struct s_ip_address
{
int ip_1;
int ip_2;
int ip_3;
int ip_4;
};
#define MAX_ECHO_LOOPS 100
int main() {
char buffer[256] = {0};
char out_buffer[] = "Hello World\n";
char out_success[] = "{{success}}\n{{end}}\n";
char out_failure[] = "{{failure}}\n{{end}}\n";
s_ip_address ip_addr = {0, 0, 0, 0};
int port = 0;
printf("TCPCllient waiting for server IP and port...\r\n");
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
printf("Address received:%d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
printf("TCPClient IP Address is %s\r\n", eth.getIPAddress());
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
TCPSocketConnection socket;
while (true) {
while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_PORT) < 0) {
printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_PORT);
wait(1);
}
char hello[] = "Hello World\n";
socket.send_all(hello, sizeof(hello) - 1);
char buf[256];
int n = socket.receive(buf, 256);
buf[n] = '\0';
printf("%s", buf);
socket.close();
while (socket.connect(buffer, port) < 0) {
printf("TCPCllient unable to connect to %s:%d\r\n", buffer, port);
wait(1);
}
// Test loop for multiple client conenctions
bool result = true;
int count_error = 0;
for (int i = 0; i < MAX_ECHO_LOOPS; i++) {
socket.send_all(out_buffer, sizeof(out_buffer) - 1);
int n = socket.receive(buffer, sizeof(buffer));
if (n > 0)
{
buffer[n] = '\0';
printf("%s", buffer);
bool echoed = strncmp(out_buffer, buffer, sizeof(out_buffer) - 1) == 0;
result = result && echoed;
if (echoed == false) {
count_error++; // Count error messages
}
}
}
printf("Loop messages passed: %d/%d\r\n", MAX_ECHO_LOOPS - count_error, MAX_ECHO_LOOPS);
if (result) {
socket.send_all(out_success, sizeof(out_success) - 1);
}
else {
socket.send_all(out_failure, sizeof(out_failure) - 1);
}
socket.close();
eth.disconnect();
return 0;
}

View File

@ -39,14 +39,14 @@ int main()
{
bool result = true;
const char *url_httpbin_post = "http://httpbin.org/post";
HTTPMap map;
HTTPText text(http_request_buffer, BUFFER_SIZE);
HTTPMap map;
map.put("Hello", "World");
map.put("test", "1234");
printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post);
const int ret = http.post(url_httpbin_post, map, &text);
if (ret == 0) {
printf("HTTP_POST: Read %d chars ... [OK]\n", strlen(http_request_buffer));
printf("HTTP_POST: Read %d chars ... [OK]\r\n", strlen(http_request_buffer));
printf("HTTP_POST: %s\r\n", http_request_buffer);
}
else {

View File

@ -391,9 +391,12 @@ def get_result_summary_table():
counter_dict_test_id_types_all = dict((t, 0) for t in unique_test_id)
test_properties = ['id', 'automated', 'description', 'peripherals', 'host_test', 'duration']
# All tests status table print
pt = PrettyTable(test_properties)
for col in test_properties:
pt.align[col] = "l" # Left align
pt.align[col] = "l"
pt.align['duration'] = "r"
counter_all = 0
counter_automated = 0
@ -414,16 +417,32 @@ def get_result_summary_table():
counter_all += 1
counter_dict_test_id_types_all[test_id_prefix] += 1
print pt
print "Result:"
percent_progress = round(100.0 * counter_automated / float(counter_all), 2)
print "\tAutomated: %d / %d (%s %%)" % (counter_automated, counter_all, percent_progress)
print
# Automation result summary
test_id_cols = ['automated', 'all', 'percent [%]', 'progress']
pt = PrettyTable(test_id_cols)
pt.align['automated'] = "r"
pt.align['all'] = "r"
pt.align['percent [%]'] = "r"
percent_progress = round(100.0 * counter_automated / float(counter_all), 1)
str_progress = progress_bar(percent_progress, 75)
pt.add_row([counter_automated, counter_all, percent_progress, str_progress])
print "Automation coverage:"
print pt
print
# Test automation coverage table print
test_id_cols = ['id', 'automated', 'all', 'percent [%]', 'progress']
pt = PrettyTable(test_id_cols)
pt.align['id'] = "l" # Left align
pt.align['id'] = "l"
pt.align['automated'] = "r"
pt.align['all'] = "r"
pt.align['percent [%]'] = "r"
for unique_id in unique_test_id:
# print "\t\t%s: %d / %d" % (unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id])
percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 2)
percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 1)
str_progress = progress_bar(percent_progress, 75)
row = [unique_id,
counter_dict_test_id_types[unique_id],
@ -431,7 +450,9 @@ def get_result_summary_table():
percent_progress,
"[" + str_progress + "]"]
pt.add_row(row)
print "Test automation coverage:"
print pt
print
def progress_bar(percent_progress, saturation=0):
@ -545,7 +566,7 @@ if __name__ == '__main__':
if opts.test_only_peripheral and not test.peripherals:
if opts.verbose:
print "TargetTest::%s::NotPeripheralTestSkipped(%s)" % (target, ",".join(test.peripherals))
print "TargetTest::%s::NotPeripheralTestSkipped()" % (target)
continue
if test.automated and test.is_supported(target, toolchain):

View File

@ -660,6 +660,9 @@ TESTS = [
"id": "NET_13", "description": "TCP client echo loop",
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client_loop"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"automated": True,
"duration": 15,
"host_test": "tcpecho_client_auto",
"peripherals": ["ethernet"],
},
@ -761,7 +764,9 @@ TESTS = [
"source_dir": join(TEST_DIR, "mbed", "i2c_MMA8451Q"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'MMA8451Q')],
"mcu": ["KL25Z", "KL05Z", "KL46Z"],
},
"automated": True,
"duration": 15,
},
# Examples
{