Skip to content

Commit

Permalink
Replace RawSerial instances as it has been deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
hugueskamba committed Jan 6, 2020
1 parent de798c4 commit 8e9ae1c
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 126 deletions.
2 changes: 1 addition & 1 deletion TESTS/mbed_drivers/flashiap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#else

#include "utest/utest.h"
#include "utest/utest_serial.h"
#include "utest/utest_print.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "FlashIAP.h"
Expand Down
5 changes: 3 additions & 2 deletions TEST_APPS/device/nanostack_mac_tester/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#endif

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

static void rx_interrupt(void)
{
uint8_t c = pc.getc();
uint8_t c;
pc.read(&c, 1);
rx_buffer.push(c);
if (main_thread != NULL) {
osThreadFlagsSet(main_thread, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort;

#if DEVICE_SERIAL
#if DEVICE_SERIAL_FC
#include "hal/serial_api.h"
struct UARTMaps {
static const PinMap *maps[];
static const char *const pin_type_names[];
Expand Down
3 changes: 0 additions & 3 deletions drivers/RawSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include <cstdarg>

namespace mbed {
/** \defgroup drivers-public-api-uart UART
* \ingroup drivers-public-api
*/

/**
* \defgroup drivers_RawSerial RawSerial class
Expand Down
9 changes: 9 additions & 0 deletions drivers/UnbufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@


namespace mbed {
/** \defgroup drivers-public-api-uart UART
* \ingroup drivers-public-api
*/

/**
* \defgroup drivers_UnbufferedSerial UnbufferedSerial class
Expand Down Expand Up @@ -152,6 +155,12 @@ class UnbufferedSerial:
*/
virtual short poll(short events) const;

using SerialBase::readable;
using SerialBase::writeable;
using SerialBase::format;
using SerialBase::attach;
using SerialBase::baud;

#if DEVICE_SERIAL_FC
// For now use the base enum - but in future we may have extra options
// such as XON/XOFF or manual GPIO RTSCTS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
while (i < len + 1) {
uint8_t to_write = i == 0 ? type : pData[i - 1];
while (uart.writeable() == 0);
uart.putc(to_write);
uart.write(&to_write, 1);
++i;
}
return len;
Expand All @@ -62,8 +62,10 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
void H4TransportDriver::on_controller_irq()
{
while (uart.readable()) {
uint8_t char_received = uart.getc();
on_data_received(&char_received, 1);
uint8_t char_received;
if (uart.read(&char_received, 1)) {
on_data_received(&char_received, 1);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ class H4TransportDriver : public CordioHCITransportDriver {
private:
void on_controller_irq();

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void greentea_send_kv(const char * key, const char * val);
int greentea_parse_kv(char * key, char * val,
const int key_len, const int val_len);
int greentea_getc();
void greentea_putc(int c);
void greentea_write_string(const char *str);

#ifdef __cplusplus
}
Expand Down
27 changes: 0 additions & 27 deletions features/frameworks/greentea-client/source/greentea_serial.cpp

This file was deleted.

83 changes: 43 additions & 40 deletions features/frameworks/greentea-client/source/greentea_test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
* limitations under the License.
*/

#if DEVICE_SERIAL

#include <ctype.h>
#include <cstdio>
#include <string.h>
#include "greentea-client/test_env.h"
#include "greentea-client/greentea_serial.h"
#include "greentea-client/greentea_metrics.h"
#include "mbed_trace.h"
#include "platform/mbed_retarget.h"

/**
* Generic test suite transport protocol keys
Expand Down Expand Up @@ -59,7 +57,6 @@ static void greentea_notify_timeout(const int);
static void greentea_notify_hosttest(const char *);
static void greentea_notify_completion(const int);
static void greentea_notify_version();
static void greentea_write_string(const char *str);

/** \brief Handle the handshake with the host
* \details This is contains the shared handhshake functionality that is used between
Expand Down Expand Up @@ -212,55 +209,49 @@ void greentea_notify_coverage_end() {
*
* This function writes the preamble "{{" which is required
* for key-value comunication between the target and the host.
* This uses a Rawserial object, greentea_serial, which provides
* a direct interface to the USBTX and USBRX serial pins and allows
* the direct writing of characters using the putc() method.
* This uses greentea_putc which allows the direct writing of characters
* using the write() method.
* This suite of functions are provided to allow for serial communication
* to the host from within a thread/ISR.
*
*/
inline void greentea_write_preamble()
static void greentea_write_preamble()
{
greentea_serial->putc('{');
greentea_serial->putc('{');
greentea_putc('{');
greentea_putc('{');
}

/**
* \brief Write the postamble characters to the serial port
*
* This function writes the postamble "{{\n" which is required
* for key-value comunication between the target and the host.
* This uses a Rawserial object, greentea_serial, which provides
* a direct interface to the USBTX and USBRX serial pins and allows
* the direct writing of characters using the putc() method.
* This uses greentea_putc which allows the direct writing of characters
* using the write() method.
* This suite of functions are provided to allow for serial communication
* to the host from within a thread/ISR.
*
*/
inline void greentea_write_postamble()
static void greentea_write_postamble()
{
greentea_serial->putc('}');
greentea_serial->putc('}');
greentea_serial->putc('\r');
greentea_serial->putc('\n');
greentea_putc('}');
greentea_putc('}');
greentea_putc('\r');
greentea_putc('\n');
}

/**
* \brief Write a string to the serial port
*
* This function writes a '\0' terminated string from the target
* to the host. It writes directly to the serial port using the
* greentea_serial, Rawserial object.
* the write() method.
*
* \param str - string value
*
*/
inline void greentea_write_string(const char *str)
void greentea_write_string(const char *str)
{
while (*str != '\0') {
greentea_serial->putc(*str);
str ++;
}
write(STDOUT_FILENO, str, strlen(str));
}


Expand All @@ -270,21 +261,21 @@ inline void greentea_write_string(const char *str)
* This function writes an integer value from the target
* to the host. The integer value is converted to a string and
* and then written character by character directly to the serial
* port using the greentea_serial, Rawserial object.
* port using the console.
* sprintf() is used to convert the int to a string. Sprintf if
* inherently thread safe so can be used.
*
* \param val - integer value
*
*/
#define MAX_INT_STRING_LEN 15
inline void greentea_write_int(const int val)
static void greentea_write_int(const int val)
{
char intval[MAX_INT_STRING_LEN];
unsigned int i = 0;
sprintf(intval, "%d", val);
while (intval[i] != '\0') {
greentea_serial->putc(intval[i]);
greentea_putc(intval[i]);
i++;
}
}
Expand All @@ -304,7 +295,7 @@ extern "C" void greentea_send_kv(const char *key, const char *val) {
if (key && val) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_string(val);
greentea_write_postamble();
}
Expand All @@ -327,7 +318,7 @@ void greentea_send_kv(const char *key, const int val) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(val);
greentea_write_postamble();
}
Expand All @@ -351,9 +342,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_string(val);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(result);
greentea_write_postamble();

Expand Down Expand Up @@ -384,11 +375,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_string(val);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(passes);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(failures);
greentea_write_postamble();
}
Expand Down Expand Up @@ -417,9 +408,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(passes);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(failures);
greentea_write_postamble();
}
Expand Down Expand Up @@ -562,7 +553,21 @@ enum Token {
*
*/
extern "C" int greentea_getc() {
return greentea_serial->getc();
uint8_t c;
read(STDOUT_FILENO, &c, 1);
return c;
}


/**
* \brief Write character from stream of data
*
* \return The number of bytes written
*
*/
extern "C" void greentea_putc(int c) {
uint8_t _c = c;
write(STDOUT_FILENO, &_c, 1);
}

/**
Expand Down Expand Up @@ -786,5 +791,3 @@ static int HandleKV(char *out_key,
getNextToken(0, 0);
return 0;
}

#endif
11 changes: 3 additions & 8 deletions features/frameworks/utest/source/unity_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#include "utest/utest_harness.h"
#include "utest/utest_stack_trace.h"
#include "utest/unity_handler.h"
#include "greentea-client/test_env.h"

#if DEVICE_SERIAL
#include "greentea-client/greentea_serial.h"
#endif

void utest_unity_assert_failure(void)
{
Expand All @@ -36,10 +34,7 @@ void utest_unity_ignore_failure(void)
utest::v1::Harness::raise_failure(utest::v1::failure_reason_t(utest::v1::REASON_ASSERTION | utest::v1::REASON_IGNORE));
}

#if DEVICE_SERIAL
void utest_safe_putc(int chr)
{
greentea_serial->putc(chr);
}
#endif

greentea_putc(chr);
}
Loading

0 comments on commit 8e9ae1c

Please sign in to comment.