Skip to content

Commit 5faf4b2

Browse files
authored
Merge pull request #3837 from ARMmbed/release-candidate
Release candidate for mbed-os-5.3.6
2 parents bcf7085 + e0b27cc commit 5faf4b2

File tree

30 files changed

+293
-296
lines changed

30 files changed

+293
-296
lines changed

TESTS/events/queue/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ SIMPLE_POSTS_TEST(0)
7070

7171

7272
void time_func(Timer *t, int ms) {
73-
TEST_ASSERT_INT_WITHIN(2, ms, t->read_ms());
73+
TEST_ASSERT_INT_WITHIN(5, ms, t->read_ms());
7474
t->reset();
7575
}
7676

TESTS/events/timing/main.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "mbed_events.h"
2+
#include "mbed.h"
3+
#include "rtos.h"
4+
#include "greentea-client/test_env.h"
5+
#include "unity.h"
6+
#include "utest.h"
7+
#include <cstdlib>
8+
#include <cmath>
9+
10+
using namespace utest::v1;
11+
12+
13+
// Test delay
14+
#ifndef TEST_EVENTS_TIMING_TIME
15+
#define TEST_EVENTS_TIMING_TIME 20000
16+
#endif
17+
18+
#ifndef TEST_EVENTS_TIMING_MEAN
19+
#define TEST_EVENTS_TIMING_MEAN 25
20+
#endif
21+
22+
#ifndef M_PI
23+
#define M_PI 3.14159265358979323846264338327950288
24+
#endif
25+
26+
// Random number generation to skew timing values
27+
float gauss(float mu, float sigma) {
28+
float x = (float)rand() / ((float)RAND_MAX+1);
29+
float y = (float)rand() / ((float)RAND_MAX+1);
30+
float x2pi = x*2.0*M_PI;
31+
float g2rad = sqrt(-2.0 * log(1.0-y));
32+
float z = cos(x2pi) * g2rad;
33+
return mu + z*sigma;
34+
}
35+
36+
float chisq(float sigma) {
37+
return pow(gauss(0, sqrt(sigma)), 2);
38+
}
39+
40+
41+
Timer timer;
42+
DigitalOut led(LED1);
43+
44+
equeue_sema_t sema;
45+
46+
// Timer timing test
47+
void timer_timing_test() {
48+
timer.reset();
49+
timer.start();
50+
int prev = timer.read_us();
51+
52+
while (prev < TEST_EVENTS_TIMING_TIME*1000) {
53+
int next = timer.read_us();
54+
if (next < prev) {
55+
printf("backwards drift %d -> %d (%08x -> %08x)\r\n",
56+
prev, next, prev, next);
57+
}
58+
TEST_ASSERT(next >= prev);
59+
prev = next;
60+
}
61+
}
62+
63+
// equeue tick timing test
64+
void tick_timing_test() {
65+
unsigned start = equeue_tick();
66+
int prev = 0;
67+
68+
while (prev < TEST_EVENTS_TIMING_TIME) {
69+
int next = equeue_tick() - start;
70+
if (next < prev) {
71+
printf("backwards drift %d -> %d (%08x -> %08x)\r\n",
72+
prev, next, prev, next);
73+
}
74+
TEST_ASSERT(next >= prev);
75+
prev = next;
76+
}
77+
}
78+
79+
// equeue semaphore timing test
80+
void semaphore_timing_test() {
81+
srand(0);
82+
timer.reset();
83+
timer.start();
84+
85+
int err = equeue_sema_create(&sema);
86+
TEST_ASSERT_EQUAL(0, err);
87+
88+
while (timer.read_ms() < TEST_EVENTS_TIMING_TIME) {
89+
int delay = chisq(TEST_EVENTS_TIMING_MEAN);
90+
91+
int start = timer.read_us();
92+
equeue_sema_wait(&sema, delay);
93+
int taken = timer.read_us() - start;
94+
95+
printf("delay %dms => error %dus\r\n", delay, abs(1000*delay - taken));
96+
TEST_ASSERT_INT_WITHIN(5000, taken, delay * 1000);
97+
98+
led = !led;
99+
}
100+
101+
equeue_sema_destroy(&sema);
102+
}
103+
104+
105+
// Test setup
106+
utest::v1::status_t test_setup(const size_t number_of_cases) {
107+
GREENTEA_SETUP((number_of_cases+1)*TEST_EVENTS_TIMING_TIME, "default_auto");
108+
return verbose_test_setup_handler(number_of_cases);
109+
}
110+
111+
const Case cases[] = {
112+
Case("Testing accuracy of timer", timer_timing_test),
113+
Case("Testing accuracy of equeue tick", tick_timing_test),
114+
Case("Testing accuracy of equeue semaphore", semaphore_timing_test),
115+
};
116+
117+
Specification specification(test_setup, cases);
118+
119+
int main() {
120+
return !Harness::run(specification);
121+
}
122+

events/equeue/equeue_mbed.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626

2727
// Ticker operations
2828
static bool equeue_tick_inited = false;
29-
static unsigned equeue_minutes = 0;
29+
static volatile unsigned equeue_minutes = 0;
3030
static unsigned equeue_timer[
3131
(sizeof(Timer)+sizeof(unsigned)-1)/sizeof(unsigned)];
3232
static unsigned equeue_ticker[
3333
(sizeof(Ticker)+sizeof(unsigned)-1)/sizeof(unsigned)];
3434

3535
static void equeue_tick_update() {
36+
equeue_minutes += reinterpret_cast<Timer*>(equeue_timer)->read_ms();
3637
reinterpret_cast<Timer*>(equeue_timer)->reset();
37-
equeue_minutes += 1;
3838
}
3939

4040
static void equeue_tick_init() {
@@ -48,7 +48,7 @@ static void equeue_tick_init() {
4848
equeue_minutes = 0;
4949
reinterpret_cast<Timer*>(equeue_timer)->start();
5050
reinterpret_cast<Ticker*>(equeue_ticker)
51-
->attach_us(equeue_tick_update, (1 << 16)*1000);
51+
->attach_us(equeue_tick_update, 1000 << 16);
5252

5353
equeue_tick_inited = true;
5454
}
@@ -58,8 +58,15 @@ unsigned equeue_tick() {
5858
equeue_tick_init();
5959
}
6060

61-
unsigned equeue_ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
62-
return (equeue_minutes << 16) + equeue_ms;
61+
unsigned minutes;
62+
unsigned ms;
63+
64+
do {
65+
minutes = equeue_minutes;
66+
ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
67+
} while (minutes != equeue_minutes);
68+
69+
return minutes + ms;
6370
}
6471

6572

features/unsupported/USBDevice/USBDevice/TARGET_STM/USBHAL_STM32F769NI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ USBHAL::USBHAL(void) {
135135
/* bulk/int 64 bytes in FS */
136136
HAL_PCDEx_SetTxFiFo(&hpcd, 0, (MAX_PACKET_SIZE_EP0/4)+1);
137137
/* bulk/int bytes in FS */
138-
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4));
138+
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4)+1);
139139
HAL_PCDEx_SetTxFiFo(&hpcd, 2, (MAX_PACKET_SIZE_EP2/4));
140140
/* ISOchronous */
141141
HAL_PCDEx_SetTxFiFo(&hpcd, 3, (MAX_PACKET_SIZE_EP3/4));

features/unsupported/USBDevice/USBDevice/TARGET_STM/USBHAL_STM32L476VG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ USBHAL::USBHAL(void) {
131131
/* bulk/int 64 bytes in FS */
132132
HAL_PCDEx_SetTxFiFo(&hpcd, 0, (MAX_PACKET_SIZE_EP0/4)+1);
133133
/* bulk/int bytes in FS */
134-
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4));
134+
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4)+1);
135135
HAL_PCDEx_SetTxFiFo(&hpcd, 2, (MAX_PACKET_SIZE_EP2/4));
136136
/* ISOchronous */
137137
HAL_PCDEx_SetTxFiFo(&hpcd, 3, (MAX_PACKET_SIZE_EP3/4));

features/unsupported/USBDevice/USBDevice/TARGET_STM/USBHAL_STM_144_64pins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ USBHAL::USBHAL(void) {
121121
/* bulk/int 64 bytes in FS */
122122
HAL_PCDEx_SetTxFiFo(&hpcd, 0, (MAX_PACKET_SIZE_EP0/4)+1);
123123
/* bulk/int bytes in FS */
124-
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4));
124+
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4)+1);
125125
HAL_PCDEx_SetTxFiFo(&hpcd, 2, (MAX_PACKET_SIZE_EP2/4));
126126
/* ISOchronous */
127127
HAL_PCDEx_SetTxFiFo(&hpcd, 3, (MAX_PACKET_SIZE_EP3/4));

features/unsupported/USBDevice/USBDevice/USBHAL.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
//#define __packed __attribute__ ((__packed__))
2828
//#endif
2929

30+
#ifdef __GNUC__
31+
#define __packed __attribute__ ((__packed__))
32+
#endif
33+
3034
class USBHAL {
3135
public:
3236
/* Configuration */

mbed.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#ifndef MBED_H
1717
#define MBED_H
1818

19-
#define MBED_LIBRARY_VERSION 136
19+
#define MBED_LIBRARY_VERSION 137
2020

2121
#if MBED_CONF_RTOS_PRESENT
2222
// RTOS present, this is valid only for mbed OS 5
2323
#define MBED_MAJOR_VERSION 5
2424
#define MBED_MINOR_VERSION 3
25-
#define MBED_PATCH_VERSION 5
25+
#define MBED_PATCH_VERSION 6
2626

2727
#else
2828
// mbed 2

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/spi_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
6565
spi_master_config_t master_config;
6666
spi_slave_config_t slave_config;
6767

68-
if ((bits != 8) || (bits != 16)) {
68+
if ((bits != 8) && (bits != 16)) {
6969
error("Only 8bits and 16bits SPI supported");
7070
return;
7171
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/spi_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
6565
spi_master_config_t master_config;
6666
spi_slave_config_t slave_config;
6767

68-
if ((bits != 8) || (bits != 16)) {
68+
if ((bits != 8) && (bits != 16)) {
6969
error("Only 8bits and 16bits SPI supported");
7070
return;
7171
}

0 commit comments

Comments
 (0)