Skip to content

Commit 1768819

Browse files
committed
Replace RawSerial instances as it has been deprecated
1 parent d128ff4 commit 1768819

File tree

12 files changed

+117
-107
lines changed

12 files changed

+117
-107
lines changed

TEST_APPS/device/nanostack_mac_tester/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545

4646
extern mac_api_s *mac_interface;
47-
RawSerial pc(USBTX, USBRX);
47+
UnbufferedSerial pc(USBTX, USBRX);
4848
osThreadId_t main_thread;
4949
static CircularBuffer<uint8_t, RX_BUFFER_SIZE> rx_buffer;
5050
static uint8_t ns_heap[HEAP_FOR_MAC_TESTER_SIZE];
@@ -68,7 +68,8 @@ static void app_heap_error_handler(heap_fail_t event)
6868

6969
static void rx_interrupt(void)
7070
{
71-
uint8_t c = pc.getc();
71+
uint8_t c;
72+
pc.read(&c, 1);
7273
rx_buffer.push(c);
7374
if (main_thread != NULL) {
7475
osThreadFlagsSet(main_thread, 1);

drivers/RawSerial.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#include <cstdarg>
2828

2929
namespace mbed {
30-
/** \defgroup drivers-public-api-uart UART
31-
* \ingroup drivers-public-api
32-
*/
3330

3431
/**
3532
* \defgroup drivers_RawSerial RawSerial class

drivers/UnbufferedSerial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131

3232
namespace mbed {
33+
/** \defgroup drivers-public-api-uart UART
34+
* \ingroup drivers-public-api
35+
*/
3336

3437
/**
3538
* \defgroup drivers_UnbufferedSerial UnbufferedSerial class

features/FEATURE_BLE/targets/TARGET_CORDIO/driver/H4TransportDriver.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ class H4TransportDriver : public CordioHCITransportDriver {
6969
private:
7070
void on_controller_irq();
7171

72-
// Use RawSerial as opposed to Serial as we don't require the locking primitives
73-
// provided by the Serial class (access to the UART should be exclusive to this driver)
74-
// Furthermore, we access the peripheral in interrupt context which would clash
75-
// with Serial's locking facilities
76-
RawSerial uart;
72+
// Use UnbufferedSerial as we don't require locking primitives.
73+
// We access the peripheral in interrupt context.
74+
UnbufferedSerial uart;
7775
PinName cts;
7876
PinName rts;
7977
};

features/FEATURE_BLE/targets/TARGET_Cypress/COMPONENT_CYW43XXX/CyH4TransportDriver.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ class CyH4TransportDriver : public cordio::CordioHCITransportDriver {
8282
void assert_bt_dev_wake();
8383
void deassert_bt_dev_wake();
8484

85-
// Use RawSerial as opposed to Serial as we don't require the locking primitives
86-
// provided by the Serial class (access to the UART should be exclusive to this driver)
87-
// Furthermore, we access the peripheral in interrupt context which would clash
88-
// with Serial's locking facilities
89-
RawSerial uart;
85+
// Use UnbufferedSerial as we don't require locking primitives.
86+
// We access the peripheral in interrupt context.
87+
UnbufferedSerial uart;
9088
PinName cts;
9189
PinName rts;
9290
PinName bt_host_wake_name;

features/frameworks/greentea-client/greentea-client/greentea_serial.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

features/frameworks/greentea-client/greentea-client/test_env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void greentea_send_kv(const char * key, const char * val);
117117
int greentea_parse_kv(char * key, char * val,
118118
const int key_len, const int val_len);
119119
int greentea_getc();
120+
int greentea_putc(int c);
120121

121122
#ifdef __cplusplus
122123
}

features/frameworks/greentea-client/source/greentea_serial.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

features/frameworks/greentea-client/source/greentea_test_env.cpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18-
#if DEVICE_SERIAL
19-
2018
#include <ctype.h>
2119
#include <cstdio>
2220
#include <string.h>
2321
#include "greentea-client/test_env.h"
24-
#include "greentea-client/greentea_serial.h"
2522
#include "greentea-client/greentea_metrics.h"
2623
#include "mbed_trace.h"
24+
#include "platform/mbed_retarget.h"
2725

2826
/**
2927
* Generic test suite transport protocol keys
@@ -212,53 +210,53 @@ void greentea_notify_coverage_end() {
212210
*
213211
* This function writes the preamble "{{" which is required
214212
* for key-value comunication between the target and the host.
215-
* This uses a Rawserial object, greentea_serial, which provides
213+
* This uses a GreenteaSerial object, greentea_serial, which provides
216214
* a direct interface to the USBTX and USBRX serial pins and allows
217-
* the direct writing of characters using the putc() method.
215+
* the direct writing of characters using the write() method.
218216
* This suite of functions are provided to allow for serial communication
219217
* to the host from within a thread/ISR.
220218
*
221219
*/
222220
inline void greentea_write_preamble()
223221
{
224-
greentea_serial->putc('{');
225-
greentea_serial->putc('{');
222+
greentea_putc('{');
223+
greentea_putc('{');
226224
}
227225

228226
/**
229227
* \brief Write the postamble characters to the serial port
230228
*
231229
* This function writes the postamble "{{\n" which is required
232230
* for key-value comunication between the target and the host.
233-
* This uses a Rawserial object, greentea_serial, which provides
231+
* This uses a GreenteaSerial object, greentea_serial, which provides
234232
* a direct interface to the USBTX and USBRX serial pins and allows
235-
* the direct writing of characters using the putc() method.
233+
* the direct writing of characters using the write() method.
236234
* This suite of functions are provided to allow for serial communication
237235
* to the host from within a thread/ISR.
238236
*
239237
*/
240238
inline void greentea_write_postamble()
241239
{
242-
greentea_serial->putc('}');
243-
greentea_serial->putc('}');
244-
greentea_serial->putc('\r');
245-
greentea_serial->putc('\n');
240+
greentea_putc('}');
241+
greentea_putc('}');
242+
greentea_putc('\r');
243+
greentea_putc('\n');
246244
}
247245

248246
/**
249247
* \brief Write a string to the serial port
250248
*
251249
* This function writes a '\0' terminated string from the target
252250
* to the host. It writes directly to the serial port using the
253-
* greentea_serial, Rawserial object.
251+
* greentea_serial, GreenteaSerial object.
254252
*
255253
* \param str - string value
256254
*
257255
*/
258256
inline void greentea_write_string(const char *str)
259257
{
260258
while (*str != '\0') {
261-
greentea_serial->putc(*str);
259+
greentea_putc(*str);
262260
str ++;
263261
}
264262
}
@@ -270,7 +268,7 @@ inline void greentea_write_string(const char *str)
270268
* This function writes an integer value from the target
271269
* to the host. The integer value is converted to a string and
272270
* and then written character by character directly to the serial
273-
* port using the greentea_serial, Rawserial object.
271+
* port using the greentea_serial, GreenteaSerial object.
274272
* sprintf() is used to convert the int to a string. Sprintf if
275273
* inherently thread safe so can be used.
276274
*
@@ -284,7 +282,7 @@ inline void greentea_write_int(const int val)
284282
unsigned int i = 0;
285283
sprintf(intval, "%d", val);
286284
while (intval[i] != '\0') {
287-
greentea_serial->putc(intval[i]);
285+
greentea_putc(intval[i]);
288286
i++;
289287
}
290288
}
@@ -304,7 +302,7 @@ extern "C" void greentea_send_kv(const char *key, const char *val) {
304302
if (key && val) {
305303
greentea_write_preamble();
306304
greentea_write_string(key);
307-
greentea_serial->putc(';');
305+
greentea_putc(';');
308306
greentea_write_string(val);
309307
greentea_write_postamble();
310308
}
@@ -327,7 +325,7 @@ void greentea_send_kv(const char *key, const int val) {
327325
if (key) {
328326
greentea_write_preamble();
329327
greentea_write_string(key);
330-
greentea_serial->putc(';');
328+
greentea_putc(';');
331329
greentea_write_int(val);
332330
greentea_write_postamble();
333331
}
@@ -351,9 +349,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
351349
if (key) {
352350
greentea_write_preamble();
353351
greentea_write_string(key);
354-
greentea_serial->putc(';');
352+
greentea_putc(';');
355353
greentea_write_string(val);
356-
greentea_serial->putc(';');
354+
greentea_putc(';');
357355
greentea_write_int(result);
358356
greentea_write_postamble();
359357

@@ -384,11 +382,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
384382
if (key) {
385383
greentea_write_preamble();
386384
greentea_write_string(key);
387-
greentea_serial->putc(';');
385+
greentea_putc(';');
388386
greentea_write_string(val);
389-
greentea_serial->putc(';');
387+
greentea_putc(';');
390388
greentea_write_int(passes);
391-
greentea_serial->putc(';');
389+
greentea_putc(';');
392390
greentea_write_int(failures);
393391
greentea_write_postamble();
394392
}
@@ -417,9 +415,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
417415
if (key) {
418416
greentea_write_preamble();
419417
greentea_write_string(key);
420-
greentea_serial->putc(';');
418+
greentea_putc(';');
421419
greentea_write_int(passes);
422-
greentea_serial->putc(';');
420+
greentea_putc(';');
423421
greentea_write_int(failures);
424422
greentea_write_postamble();
425423
}
@@ -562,7 +560,20 @@ enum Token {
562560
*
563561
*/
564562
extern "C" int greentea_getc() {
565-
return greentea_serial->getc();
563+
uint8_t c;
564+
read(STDERR_FILENO, &c, 1);
565+
return c;
566+
}
567+
568+
569+
/**
570+
* \brief Write character from stream of data
571+
*
572+
* \return The number of bytes written
573+
*
574+
*/
575+
extern "C" int greentea_putc(int c) {
576+
return write(STDERR_FILENO, &c, 1);
566577
}
567578

568579
/**
@@ -786,5 +797,3 @@ static int HandleKV(char *out_key,
786797
getNextToken(0, 0);
787798
return 0;
788799
}
789-
790-
#endif

features/frameworks/utest/source/unity_handler.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
#include "utest/utest_harness.h"
2020
#include "utest/utest_stack_trace.h"
2121
#include "utest/unity_handler.h"
22+
#include "greentea-client/test_env.h"
2223

23-
#if DEVICE_SERIAL
24-
#include "greentea-client/greentea_serial.h"
25-
#endif
2624

2725
void utest_unity_assert_failure(void)
2826
{
@@ -36,10 +34,7 @@ void utest_unity_ignore_failure(void)
3634
utest::v1::Harness::raise_failure(utest::v1::failure_reason_t(utest::v1::REASON_ASSERTION | utest::v1::REASON_IGNORE));
3735
}
3836

39-
#if DEVICE_SERIAL
4037
void utest_safe_putc(int chr)
4138
{
42-
greentea_serial->putc(chr);
43-
}
44-
#endif
45-
39+
greentea_putc(chr);
40+
}

0 commit comments

Comments
 (0)