Skip to content

Commit 10b2d1c

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

File tree

12 files changed

+118
-110
lines changed

12 files changed

+118
-110
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: 39 additions & 32 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,51 @@ 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
216-
* a direct interface to the USBTX and USBRX serial pins and allows
217-
* the direct writing of characters using the putc() method.
213+
* This uses greentea_putc which allows the direct writing of characters
214+
* using the write() method.
218215
* This suite of functions are provided to allow for serial communication
219216
* to the host from within a thread/ISR.
220-
*
221217
*/
222218
inline void greentea_write_preamble()
223219
{
224-
greentea_serial->putc('{');
225-
greentea_serial->putc('{');
220+
greentea_putc('{');
221+
greentea_putc('{');
226222
}
227223

228224
/**
229225
* \brief Write the postamble characters to the serial port
230226
*
231227
* This function writes the postamble "{{\n" which is required
232228
* for key-value comunication between the target and the host.
233-
* This uses a Rawserial object, greentea_serial, which provides
234-
* a direct interface to the USBTX and USBRX serial pins and allows
235-
* the direct writing of characters using the putc() method.
229+
* This uses greentea_putc which allows the direct writing of characters
230+
* using the write() method.
236231
* This suite of functions are provided to allow for serial communication
237232
* to the host from within a thread/ISR.
238233
*
239234
*/
240235
inline void greentea_write_postamble()
241236
{
242-
greentea_serial->putc('}');
243-
greentea_serial->putc('}');
244-
greentea_serial->putc('\r');
245-
greentea_serial->putc('\n');
237+
greentea_putc('}');
238+
greentea_putc('}');
239+
greentea_putc('\r');
240+
greentea_putc('\n');
246241
}
247242

248243
/**
249244
* \brief Write a string to the serial port
250245
*
251246
* This function writes a '\0' terminated string from the target
252247
* to the host. It writes directly to the serial port using the
253-
* greentea_serial, Rawserial object.
248+
* greentea_putc which allows the direct writing of characters
249+
* using the write() method.
254250
*
255251
* \param str - string value
256252
*
257253
*/
258254
inline void greentea_write_string(const char *str)
259255
{
260256
while (*str != '\0') {
261-
greentea_serial->putc(*str);
257+
greentea_putc(*str);
262258
str ++;
263259
}
264260
}
@@ -270,7 +266,7 @@ inline void greentea_write_string(const char *str)
270266
* This function writes an integer value from the target
271267
* to the host. The integer value is converted to a string and
272268
* and then written character by character directly to the serial
273-
* port using the greentea_serial, Rawserial object.
269+
* port using the greentea_serial, GreenteaSerial object.
274270
* sprintf() is used to convert the int to a string. Sprintf if
275271
* inherently thread safe so can be used.
276272
*
@@ -284,7 +280,7 @@ inline void greentea_write_int(const int val)
284280
unsigned int i = 0;
285281
sprintf(intval, "%d", val);
286282
while (intval[i] != '\0') {
287-
greentea_serial->putc(intval[i]);
283+
greentea_putc(intval[i]);
288284
i++;
289285
}
290286
}
@@ -304,7 +300,7 @@ extern "C" void greentea_send_kv(const char *key, const char *val) {
304300
if (key && val) {
305301
greentea_write_preamble();
306302
greentea_write_string(key);
307-
greentea_serial->putc(';');
303+
greentea_putc(';');
308304
greentea_write_string(val);
309305
greentea_write_postamble();
310306
}
@@ -327,7 +323,7 @@ void greentea_send_kv(const char *key, const int val) {
327323
if (key) {
328324
greentea_write_preamble();
329325
greentea_write_string(key);
330-
greentea_serial->putc(';');
326+
greentea_putc(';');
331327
greentea_write_int(val);
332328
greentea_write_postamble();
333329
}
@@ -351,9 +347,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
351347
if (key) {
352348
greentea_write_preamble();
353349
greentea_write_string(key);
354-
greentea_serial->putc(';');
350+
greentea_putc(';');
355351
greentea_write_string(val);
356-
greentea_serial->putc(';');
352+
greentea_putc(';');
357353
greentea_write_int(result);
358354
greentea_write_postamble();
359355

@@ -384,11 +380,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
384380
if (key) {
385381
greentea_write_preamble();
386382
greentea_write_string(key);
387-
greentea_serial->putc(';');
383+
greentea_putc(';');
388384
greentea_write_string(val);
389-
greentea_serial->putc(';');
385+
greentea_putc(';');
390386
greentea_write_int(passes);
391-
greentea_serial->putc(';');
387+
greentea_putc(';');
392388
greentea_write_int(failures);
393389
greentea_write_postamble();
394390
}
@@ -417,9 +413,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
417413
if (key) {
418414
greentea_write_preamble();
419415
greentea_write_string(key);
420-
greentea_serial->putc(';');
416+
greentea_putc(';');
421417
greentea_write_int(passes);
422-
greentea_serial->putc(';');
418+
greentea_putc(';');
423419
greentea_write_int(failures);
424420
greentea_write_postamble();
425421
}
@@ -562,7 +558,20 @@ enum Token {
562558
*
563559
*/
564560
extern "C" int greentea_getc() {
565-
return greentea_serial->getc();
561+
uint8_t c;
562+
read(STDERR_FILENO, &c, 1);
563+
return c;
564+
}
565+
566+
567+
/**
568+
* \brief Write character from stream of data
569+
*
570+
* \return The number of bytes written
571+
*
572+
*/
573+
extern "C" int greentea_putc(int c) {
574+
return write(STDERR_FILENO, &c, 1);
566575
}
567576

568577
/**
@@ -786,5 +795,3 @@ static int HandleKV(char *out_key,
786795
getNextToken(0, 0);
787796
return 0;
788797
}
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)