15
15
* limitations under the License.
16
16
*/
17
17
18
- #if DEVICE_SERIAL
19
-
20
18
#include < ctype.h>
21
19
#include < cstdio>
22
20
#include < string.h>
23
21
#include " greentea-client/test_env.h"
24
- #include " greentea-client/greentea_serial.h"
25
22
#include " greentea-client/greentea_metrics.h"
26
23
#include " mbed_trace.h"
24
+ #include " platform/mbed_retarget.h"
27
25
28
26
/* *
29
27
* Generic test suite transport protocol keys
@@ -59,7 +57,6 @@ static void greentea_notify_timeout(const int);
59
57
static void greentea_notify_hosttest (const char *);
60
58
static void greentea_notify_completion (const int );
61
59
static void greentea_notify_version ();
62
- static void greentea_write_string (const char *str);
63
60
64
61
/* * \brief Handle the handshake with the host
65
62
* \details This is contains the shared handhshake functionality that is used between
@@ -212,53 +209,51 @@ void greentea_notify_coverage_end() {
212
209
*
213
210
* This function writes the preamble "{{" which is required
214
211
* 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.
212
+ * This uses greentea_putc which allows the direct writing of characters
213
+ * using the write() method.
218
214
* This suite of functions are provided to allow for serial communication
219
215
* to the host from within a thread/ISR.
220
- *
221
216
*/
222
217
inline void greentea_write_preamble ()
223
218
{
224
- greentea_serial-> putc (' {' );
225
- greentea_serial-> putc (' {' );
219
+ greentea_putc (' {' );
220
+ greentea_putc (' {' );
226
221
}
227
222
228
223
/* *
229
224
* \brief Write the postamble characters to the serial port
230
225
*
231
226
* This function writes the postamble "{{\n" which is required
232
227
* 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.
228
+ * This uses greentea_putc which allows the direct writing of characters
229
+ * using the write() method.
236
230
* This suite of functions are provided to allow for serial communication
237
231
* to the host from within a thread/ISR.
238
232
*
239
233
*/
240
234
inline void greentea_write_postamble ()
241
235
{
242
- greentea_serial-> putc (' }' );
243
- greentea_serial-> putc (' }' );
244
- greentea_serial-> putc (' \r ' );
245
- greentea_serial-> putc (' \n ' );
236
+ greentea_putc (' }' );
237
+ greentea_putc (' }' );
238
+ greentea_putc (' \r ' );
239
+ greentea_putc (' \n ' );
246
240
}
247
241
248
242
/* *
249
243
* \brief Write a string to the serial port
250
244
*
251
245
* This function writes a '\0' terminated string from the target
252
246
* to the host. It writes directly to the serial port using the
253
- * greentea_serial, Rawserial object.
247
+ * greentea_putc which allows the direct writing of characters
248
+ * using the write() method.
254
249
*
255
250
* \param str - string value
256
251
*
257
252
*/
258
253
inline void greentea_write_string (const char *str)
259
254
{
260
255
while (*str != ' \0 ' ) {
261
- greentea_serial-> putc (*str);
256
+ greentea_putc (*str);
262
257
str ++;
263
258
}
264
259
}
@@ -270,7 +265,7 @@ inline void greentea_write_string(const char *str)
270
265
* This function writes an integer value from the target
271
266
* to the host. The integer value is converted to a string and
272
267
* and then written character by character directly to the serial
273
- * port using the greentea_serial, Rawserial object .
268
+ * port using the console .
274
269
* sprintf() is used to convert the int to a string. Sprintf if
275
270
* inherently thread safe so can be used.
276
271
*
@@ -284,7 +279,7 @@ inline void greentea_write_int(const int val)
284
279
unsigned int i = 0 ;
285
280
sprintf (intval, " %d" , val);
286
281
while (intval[i] != ' \0 ' ) {
287
- greentea_serial-> putc (intval[i]);
282
+ greentea_putc (intval[i]);
288
283
i++;
289
284
}
290
285
}
@@ -304,7 +299,7 @@ extern "C" void greentea_send_kv(const char *key, const char *val) {
304
299
if (key && val) {
305
300
greentea_write_preamble ();
306
301
greentea_write_string (key);
307
- greentea_serial-> putc (' ;' );
302
+ greentea_putc (' ;' );
308
303
greentea_write_string (val);
309
304
greentea_write_postamble ();
310
305
}
@@ -327,7 +322,7 @@ void greentea_send_kv(const char *key, const int val) {
327
322
if (key) {
328
323
greentea_write_preamble ();
329
324
greentea_write_string (key);
330
- greentea_serial-> putc (' ;' );
325
+ greentea_putc (' ;' );
331
326
greentea_write_int (val);
332
327
greentea_write_postamble ();
333
328
}
@@ -351,9 +346,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
351
346
if (key) {
352
347
greentea_write_preamble ();
353
348
greentea_write_string (key);
354
- greentea_serial-> putc (' ;' );
349
+ greentea_putc (' ;' );
355
350
greentea_write_string (val);
356
- greentea_serial-> putc (' ;' );
351
+ greentea_putc (' ;' );
357
352
greentea_write_int (result);
358
353
greentea_write_postamble ();
359
354
@@ -384,11 +379,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
384
379
if (key) {
385
380
greentea_write_preamble ();
386
381
greentea_write_string (key);
387
- greentea_serial-> putc (' ;' );
382
+ greentea_putc (' ;' );
388
383
greentea_write_string (val);
389
- greentea_serial-> putc (' ;' );
384
+ greentea_putc (' ;' );
390
385
greentea_write_int (passes);
391
- greentea_serial-> putc (' ;' );
386
+ greentea_putc (' ;' );
392
387
greentea_write_int (failures);
393
388
greentea_write_postamble ();
394
389
}
@@ -417,9 +412,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
417
412
if (key) {
418
413
greentea_write_preamble ();
419
414
greentea_write_string (key);
420
- greentea_serial-> putc (' ;' );
415
+ greentea_putc (' ;' );
421
416
greentea_write_int (passes);
422
- greentea_serial-> putc (' ;' );
417
+ greentea_putc (' ;' );
423
418
greentea_write_int (failures);
424
419
greentea_write_postamble ();
425
420
}
@@ -562,7 +557,21 @@ enum Token {
562
557
*
563
558
*/
564
559
extern " C" int greentea_getc () {
565
- return greentea_serial->getc ();
560
+ uint8_t c;
561
+ read (STDERR_FILENO, &c, 1 );
562
+ return c;
563
+ }
564
+
565
+
566
+ /* *
567
+ * \brief Write character from stream of data
568
+ *
569
+ * \return The number of bytes written
570
+ *
571
+ */
572
+ extern " C" void greentea_putc (int c) {
573
+ uint8_t _c = c;
574
+ write (STDERR_FILENO, &_c, 1 );
566
575
}
567
576
568
577
/* *
@@ -786,5 +795,3 @@ static int HandleKV(char *out_key,
786
795
getNextToken (0 , 0 );
787
796
return 0 ;
788
797
}
789
-
790
- #endif
0 commit comments