Commit Graph

117 Commits (ba03499b21f0c277c5105c5c3fea25eda5893e08)

Author SHA1 Message Date
Russ Butler a84142fc4e Prevent recursive call to error()
Only allow error to be called once. This prevents a loop where error()
calls exit() which in turn triggers another call to exit().
2017-06-02 23:50:35 -05:00
Russ Butler 770ad616dd Trap on RTX errors if enabled
If MBED_TRAP_ERRORS_ENABLED is defined to 1 then trap on RTX errors.
This includes using mutexes in ISR context.
2017-06-02 23:50:33 -05:00
Russ Butler b44e6f8a16 Assert that file IO is not used in ISRs
Trigger an assert if a file is read from or written to from an
interrupt handler or critical section. This includes using printf
from an interrupt handler or critical section. This makes failures
due to use in incorrect context deterministic and easier to locate.

This feature is enabled by defining MBED_TRAP_ERRORS_ENABLED to 1 or
by using the debug profile.
2017-06-02 23:50:31 -05:00
Russ Butler 5ab3de0bfa Add function to check for ISR context
Add the function core_util_in_isr() so code can determine if it is
running in the context of an ISR.
2017-06-02 23:50:29 -05:00
Sam Grove 5f138810a9 Merge pull request #4294 from ARMmbed/feature_cmsis5
Update CMSIS-Core and RTX to version 5
2017-06-02 23:44:32 -05:00
Hasnain Virk 24de27c989 Major Refactoring & extensions
For keep supporting external APIs with the same name (supposedly there are a larger
number of users of those APIs), BufferedSerial and ATParser are being renamed.
BufferedSerial becomes UARTSerial, will complement a  future USBSerial etc.
ATParser becomes ATCmdParser.

* UARTSerial moves to /drivers

* APN_db.h is moved from platform to cellular/util/.

* Original CellularInterface is restored for backward compatability (again, supposedly there
  are users of that).

* A new file, CellularBase is added which will now servce as the base class for all
  upcoming drivers.

* Special restructuring for the driver has been undertaken. This makes a clear cut distinction
  between an on-board or an off-board implementation.
  	- PPPCellularInterface is a generic network interface that works with a generic FileHandle
          and PPP. A derived class is needed to pass that FileHandle.
        - PPPCellularInterface provides some base functionality like network registration, AT setup,
          PPP connection etc. Lower level job is delegated to the derived classes and various modem
          specific APIs are provided which are supposed to be overridden.
        - UARTCellularInterface is derived from PPPCellularInterface. It constructs a FileHandle and
          passes it back to PPPCellularInterface as well as provides modem hangupf functionality.
          In future we could proive a USBInterface that would derive from PPPCellularInterface and could
          pass the FileHandle back.
	- OnboardCellularInterface is derived from UARTCellularInterfae and provides hooks to
          the target provided implementation of onbard_modem_api.h. An off-board modem, i.e, a modem on
          a shield has to override the modem_init(), modem_power_up() etc as it cannot use
          onboard_modem_api.h.
2017-05-31 15:02:11 +03:00
Hasnain Virk c8933e4c71 Removing _poll_change() for now
There is currently no proper wake up mechanism provided
by mbed-os. _poll_change() was supposed to wake upa blocking
poll() in case of a POLL event but the implementation was dependent
upon underlying wake up mechanism. In the absence of conditioanl
variables or some other alternative, _poll_change() wasn't able to
serve its purpose. Removing it for now. Should be implemented at some later stage
2017-05-31 15:02:11 +03:00
Hasnain Virk c65f81bf46 Remove sigio implementation from FileHandle
Make FileHandle more of an interface class, by requiring implementers to
provide the sigio() functionality themselves.

sigio() and poll() remain parallel independent mechanisms, so FileHandle
implementations must trigger both on state changes.
2017-05-31 15:02:11 +03:00
Hasnain Virk 01088647b9 Finalizing the public API for Cellular
* state machine corrections
* adding various standard API methods
* Addition/revision/enhancement of the nsapi_ppp glue layer
* Turning off debug by default
2017-05-31 15:02:11 +03:00
Hasnain Virk 3b44f4758d Adding support for APN lookup
Mainly reutilizing code from ublox C027 support lib.
As we are using external PDP context, i.e., an external IP stack,
we will pass username and password to underlying stack running PPP.
We only support CHAP as the authentication protocol.
2017-05-31 15:02:11 +03:00
Hasnain Virk 93f436ebe0 Using DCD line to invoke poll() HUP
POSIX poll() provides a mechanism to attach a POLL_HUP event
if the modem or device hangs up on you. POLL_HUP and POLL_OUT are
mutually exclusive. We poll in the PPP_input() routine if the modem
hung up. If it did we stop the data consumption, close PPP and go back
to the driver for reserruction of AT parser and subsequent retries or
application specific actions.
This is achieved by attaching an interrupt to the DCD line of the modem.
When DCD line goes high (off), we have lost the carrier. So we record an
POLLHUP event using _poll_change().
2017-05-31 15:02:11 +03:00
Hasnain Virk ea117e5a1a Memory Optimizations and simplifications in ATParser
ATParser had been using std <vector> which had been pulling along a lot
of standard C++ stuff. We have an alternative implementation whcih achieves
a similar effect but without using <vector>. this saves a bunch of valuable
RAM resource.

We have also simplified the overall system by introducing proper CR and LF
rather than \r\n type of delimiters. This newline simplification is borrowed
from retarget.cpp.
2017-05-31 15:02:11 +03:00
Hasnain Virk 4a04c9ce5d Extending ATParser to use FileHandle
Existing ATParser is extended to use FileHandle. This essentially detaches
ATParser from previous tight binding with various implementations of serial
interfaces with buffering.
Now the ATParser uses only abstract FileHandle and doesn't really care about
the underlying implementation. Underneath, it could be a USB device type FileHandle
or a Serial device type FileHandle etc.
Some simplification steps were taken as the code provided opportunities to simplify
and optimize.
2017-05-31 15:02:11 +03:00
Hasnain Virk 2790d44862 Introducing a BufferedSerial
BufferedSerial is a FileHandle and using SerialBase.
It keeps the SerialBase private however lets the user extend FileHandle
by keeping it public.

It is using CircularBuffer class for having circular buffers.

There are some minor amendments in CircularBuffer too.

Adding an entry for tx/rx buffer sizes in platform/mbed_lib.json.
Default size is 256 bytes.

For RTOS read(), write() calls yield for other threads to carry on with their stuff.
For non-RTOS blovking read or write would mean a loop where 100 percent resources are
consumed by this loop. Need to get a better implementation in. Currently no mechanism to
wake the mcu up after WFE.
2017-05-31 15:02:11 +03:00
Hasnain Virk 09ae609d56 Stream class should use mbed::fdopen() to attach a stream
mbed::fdopen() is provided in mbed_retarget.cpp which will attach a stream to the
given FileHandle. Removing mbed_set_unbuffered_stream() from stream class as it
is defined in mbed_retarget.cpp. Stream class should not decide whether it wants
to detach buffers from c library or not. mbed::fdopen() will do that based upon
isatty() call. So if a FileHandle is not a tty, i.e., is not a device type, c library
buffering will not be turned off. For device type FileHandles, c library buffering
is turned off.
2017-05-31 15:02:11 +03:00
Hasnain Virk b2408d8a16 Extending FileHandle & introducing mbed_poll
This has been an attempt to extend existing FileHandle to behave like POSIX
file descriptor for input/output resources/devices too.
This will now provide an abstract indicator/handle any arbitrary file or device
type resource. May be in future, sockets too.

In order to correctly detect availability of read/write a FileHandle, we needed
a select or poll mechanisms. We opted for poll as POSIX defines in
http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html Currently,
mbed::poll() just spins and scans filehandles looking for any events we are
interested in. In future, his spinning behaviour will be replaced with
condition variables.

In retarget.cpp we have introduced an mbed::fdopen() function which is
equivalent to C fdopen(). It attaches a std stream to our FileHandle stream.
newlib-nano somehow does not seem to call isatty() so retarget doesn't work for
device type file handles. We handle this by checking ourselves in
mbed::fdopen() if we wish to attach our stream to std stream.  We also turn off
buffering by C library as our stuff will be buffered already.

sigio() is also provided, matching the API of the Socket class, with a view to
future unification. As well as unblocking poll(), _poll_change calls the user
sigio callback if an event happens, i.e., when FileHandle becomes
readable/writable.
2017-05-31 15:02:11 +03:00
Kevin Bracey fb7cbdf356 Tighten mbed_retarget.cpp error handling
* Don't set errno when calls are successful (will slightly alleviate the problem
  of errno not being thread-safe yet).
* Transfer errors returned from size() and seek() into errno.
* Fix isatty() - could never return 1 from a FileHandle.
* Use more appropriate errors than EBADF in some places (eg ENOENT for non-existant path).
2017-05-31 15:02:11 +03:00
Kevin Bracey 533910cb87 Correct return type of FileHandle::size()
File size should be off_t, not size_t.
2017-05-31 15:02:11 +03:00
Bartek Szatkowski b793a3fb89 Update codebase for CMSIS5/RTX5
Update all of mbed-os to use RTX5.
2017-05-30 18:55:52 +01:00
Bartek Szatkowski 2ddf4b33cb CMSIS5: Remove ARM7 support and targets 2017-05-12 13:48:43 -05:00
Anna Bridge 8543279901 Merge pull request #4259 from LMESTM/fix_Stream_issue687
Add error check in Stream constructor
2017-05-04 15:56:44 +01:00
Anna Bridge aa80b55628 Merge pull request #4233 from sg-/fix-the-docs2
[platform] Update doxygen comments
2017-05-04 15:12:54 +01:00
Jimmy Brisson 7ace0cbb14 Merge pull request #3881 from geky/log-no-io
Remove debug links to printf/exit in NDEBUG builds
2017-05-02 11:37:10 -05:00
Laurent MEUNIER 4ad4b2a2ef On small targets there might be memory issues that lead to
failing on file allocation / opening during Stream creation.

The consequence was application continues running, but any printf
to the Serial object whose Stream was not properly created
would not show any error (and characters would not show either)

Let's add a check to properly inform user of the error.
2017-05-02 17:53:58 +02:00
Christopher Haster 8705305cab callback: Moved out sfinae logic into a macro
This is required to allow doxygen to properly parse the function
declarations, otherwise it gets confused around the nested templates.
2017-04-28 16:02:36 -05:00
Sam Grove 6c65a0a7f4 [platform] Fix undocumented parameters and fix parameters that didnt
match the arguments
2017-04-26 18:41:02 -05:00
Sam Grove 5b580f6e16 [platform] Fix documentation error between argument names and @param 2017-04-26 18:39:59 -05:00
Sam Grove 33e1d66d66 [platform] Remove stale doxygen parameter that doesnt exist in code 2017-04-26 18:07:47 -05:00
Sam Grove f5d598fb61 [platform] update incorrect doxygen tag for return documentation 2017-04-26 18:06:53 -05:00
Sam Grove 4e417eb3dc [platform] fix doxygen preprocessor constant expresison warnings 2017-04-26 17:51:24 -05:00
Sam Grove 75e5b6500d [platform] Fix doxygen errors in mbed_mem_trace.h 2017-04-26 17:49:45 -05:00
Sam Grove dcbb6f6ab8 [platform] fix doxygen group close 2017-04-26 09:14:36 -05:00
Sam Grove 6062ca7404 [platform] Update doxygen errors with example code comments 2017-04-26 09:13:34 -05:00
Sam Grove 93b8bb8e52 [platform] Fix doxygen error @Return to @return 2017-04-25 14:50:29 -05:00
Sam Grove 5e7ce5fa23 [platform] Update doxygen errors from @Note to @note 2017-04-25 14:37:08 -05:00
Christopher Haster cfc223cc3f Removed debug links to printf/exit in NDEBUG builds
Allows development of small applications where stdio is avoided
2017-04-24 10:40:24 -05:00
Anna Bridge 47b1a9eeec Merge pull request #4111 from sg-/fix-the-docs
[drivers] Update doxygen errors
2017-04-21 14:10:17 +01:00
Francisco J. Manno 4398b1f3c1 Fix gcc [-Wsign-compare] warning
[Warning] mbed_board.c@99,36: comparison between signed and unsigned
integer expressions [-Wsign-compare] is seen during compilation.
Fix the warning and small improvements.

1. Change type of loop variable "i" to the same type as "size".
   Size is > 0 checked by the if statement and i stops at == size
   so none can be negative. However size still needs to be signed
   to detect error codes from vsnprintf.
2. Reduced scope of stdio_out_prev and make sure it's initialized.
3. Define a name for the error buffer size and use vsnprintf instead
   of vsprintf to avoid writing outside of the array.
   NOTE: the if(size > 0) statement doesn't need to change. If
   the message to write is larger than the buffer size vsnprintf
   truncates it automatically but still returns a positive value.
2017-04-19 18:37:37 +01:00
Sam Grove af63b57f89 Merge pull request #4141 from tung7970/fix-mbedos
Fix mbed_board.c compiler warning
2017-04-19 02:17:08 -05:00
Jimmy Brisson fb8fda3cee Merge pull request #4097 from bulislaw/build_debug_macro
Debug build flag + change to sleep behavior in debug mode
2017-04-18 15:05:02 -05:00
Jimmy Brisson 61c4d50109 Fix typo in doxygen tag 2017-04-12 15:23:24 -05:00
Sam Grove b2cd20c5c5 Merge pull request #4122 from neilt6/patch-1
Fixed compiler warning in mbed_retarget.cpp
2017-04-10 16:38:08 -05:00
Bartek Szatkowski c5f0ad506e Disable sleep when uVisor is in use 2017-04-10 11:40:04 +01:00
Bartek Szatkowski 57dc2a540c Disable sleep and deepsleep when MBED_DEBUG macro is defined 2017-04-10 11:40:04 +01:00
Tony Wu 913febd3db Fix mbed_board.c compiler warning
Fix the following compiler warning.

Compile [ 63.7%]: mbed_board.c
[Warning] mbed_board.c@99,36: comparison between signed and unsigned integer expressions [-Wsign-compare]

Signed-off-by: Tony Wu <tonyw@realtek.com>
2017-04-10 11:42:14 +08:00
Neil Thiessen 6b671e5903 Fixed compiler warning in mbed_retarget.cpp
Fixed compiler warning about openmode_to_posix() being declared but never referenced.
2017-04-05 20:58:23 -06:00
Jimmy Brisson f945d71319 Update class documentation tags
stop using scope for \addtogroup. It was placing class methods into the
group documentation instead of the class documentation. The new style is
to explicitly tag the class as @ingroup. This new method will allow the
class to be linked in the group page, and the class page will contain
the detailed documentation of the class methods.
2017-04-04 14:21:53 -05:00
Adam Green 408cff4f8d Modify semihost_disabledebug() to support more interface FW revs
The current implementation of semihost_disabledebug() hangs when used
with mbed interface firwmare revision 21164, the first version which
added support for this semihost call. I encountered this hang when
running a Release build on my mbed-LPC1768 board as the RTOS attempted
to disable the debugger before the idle thread put the CPU to sleep.

The 21164 interface firmware expects that R1 points to a valid argument
block but the current implementation passes in NULL. The fix was to
pass in a dummy block which is ignored by the newer 141212 revision of
the firmware and allows the 21164 version to proceeed without halting
the CPU until a manual reset.

Before this fix semihost_disabledebug() did work with the latest
mbed interface firmware revision 141212 but I rarely use this revision
of the interface firmware due to the instability issues I have
encountered in the past with its CDC and LocalFileSystem functionality.

With this proposed fix, the code now works with both the 21164 and
141212 revisions of the mbed interface firmware on the mbed-LPC1768.
2017-03-31 13:33:55 -07:00
Anna Bridge 039ef42822 Merge pull request #3867 from geky/fs-revert-filehandle
Filesystem: Revert deprecation of FileHandle
2017-03-23 15:45:01 +00:00
Andres AG 2d0135632d Fix C declaration of dir functions and types
This patch fixes the declaration of the DIR type and related functions
so that they can be called from C code. This is necessary when enabling
functionality that uses the filesystem in mbed TLS.
2017-03-16 16:13:44 +00:00