Commit Graph

9436 Commits (d67b431f17836458850769a1fe1d052d4606bdae)

Author SHA1 Message Date
Adam Green 2056ad025e usbhost: USBHost::fileControlBuf() handle alignment and endianness
Based on great feedback from Martin Kojtal on my previous commit, I
have modified my USBHost::fileControlBuf() change to be more portable.
    ddb3fbe826 (commitcomment-3988044)

The code now fills in the setupPacket byte array a byte at a time,
using bit shifts to extract lower and upper bytes from the 16-bit
values so that the code should work on big endian or little endian
machines.  I also removed the 2-byte alignment attribute from the
setupPacket array as it is no longer required.
2013-09-01 12:19:59 -07:00
dinau 8503ccb7a3 LPC2368 [GCC_ARM, GCC_CR]:
1. Added: GCC_CR toolchain ID for LPC2368. (targets.py)
2. Modified: Startup codes for GCC_ARM and GCC_CR toolchain.
3. Verified: "ticker" and "basic" test program work well, so far.
(Fixed typo.)
2013-08-31 16:00:40 +09:00
dinau 7bcdf0b980 LPC2368 [GCC_ARM, GCC_CR]:
1. Added: GCC_CR toolchain ID for LPC2368. (targets.py)
2. Modified: Startup codes for GCC_ARM and GCC_CR toolchain.
3. Verified: "ticker" and "basic" test program works well, so far.
2013-08-31 13:33:34 +09:00
dinau 2b57e648a4 Fixed: [GCC_ARM : LPC1768] Issue ignored the linker option for _print_float and _scanf_float. 2013-08-31 11:34:53 +09:00
Adam Green 9e6d1683b8 gcc: Provide _sbrk implementation compatible with RTX
I verified that the hang issue I was seeing when building and running
the mbed official networking tests with GCC_ARM was related to this
issue reported on the mbed forums:
    http://mbed.org/forum/mbed/topic/3803/?page=1#comment-18934

If you are using the 4.7 2013q1 update of GCC_ARM or newer then it
will have a _sbrk() implementation which checks the new top of heap
pointer against the current thread SP, stack pointer.
See this GCC_ARM related thread for more information:
    https://answers.launchpad.net/gcc-arm-embedded/+question/218972
When using RTX RTOS threads, the thread's stack pointer can easily
point to an address which is below the current top of heap so this
check will incorrectly fail the allocation.

I have added a _sbrk() implementation to the mbed SDK which checks the
heap pointer against the MSP instead of the current thread SP.  I have
only enabled this for TOOLCHAIN_GCC_ARM as this is the only GCC based
toolchain that I am sure requires this.
2013-08-30 18:15:25 -07:00
Adam Green 7dddd9e578 Asm versions of netstack memcpy() and lwip_standard_chksum()
For tests such as TCPEchoServer
(http://mbed.org/users/emilmont/notebook/networking-libraries-benchmark/)
this change showed a 28% improvement (14Mbps to 18Mbps) when the echo
test was modified to instead use 1K data buffers.

I targetted these two functions based on manual profiling samples which
showed that a great deal of time was being spent in these two functions
when the network stack was being slammed with UDP packets.
2013-08-30 06:09:16 -07:00
Bogdan Marinescu e23be8a1b3 Merge pull request #46 from adamgreen/netAssertDisableAndCrashFixes2
Robustness fixes for netstack
2013-08-30 04:47:15 -07:00
Bogdan Marinescu 1798920cf4 Merge remote-tracking branch 'github/master' 2013-08-30 12:26:37 +03:00
Bogdan Marinescu e870a90ff2 Added toolchain hooks and support for LPC4088_EA binary generation
A new hooks mechanism (hooks.py) allows various targets to customize
part(s) of the build process. This was implemented to allow generation of
custom binary images for the EA LPC4088 target, but it should be generic
enough to allow other such customizations in the future. For now, only the
'binary' step is hooked in toolchains/arm.py.
2013-08-30 12:19:08 +03:00
Adam Green c0d7c3fb39 USBHost: Silence narrowing warning in USBHostMSD::inquiry
I changed the following initialization from:
    uint8_t cmd[6] = {0x12, (lun << 5) | evpd, page_code, 0, 36, 0};
to:
    uint8_t cmd[6] = {0x12, uint8_t((lun << 5) | evpd), page_code, 0, 36, 0};
This makes it clear to the compiler that we are Ok with the 32-bit
integer result from the shift and logical OR operation (after integral
promotions) being truncated down to a 8-bit unsigned value.  This is
safe as long as lun only has a value of 7 or lower.
2013-08-29 21:16:45 -07:00
Adam Green fb769b1566 USBHost: Don't pass NULL in for uint32_t parameters.
USBHostHub.cpp made a few calls to the USBHALHost::deviceDisconnected()
virtual method passing in NULL for the addr parameter which is actually
declared as uint32_t and not a pointer type.  Switching these calls
to pass in a 0 for this parameter silences GCC warnings about
incompatible types.
2013-08-29 21:12:12 -07:00
Adam Green 8281836df3 USBHost: Silence unused variable warnings.
I removed the initialization of some variables which were never used to
silence GCC warnings.

One of them had me removing the following line from
USBHostMouse::rxHandler():
    int len = int_in->getLengthTransferred();
The variable len is never used again in this method and it doesn't
appear that the int_in->getLengthTransferred() call has any side
effects which would require this extraneous call to remain in the code.
2013-08-29 21:07:43 -07:00
Adam Green ddb3fbe826 USBHost: Silence GCC warnings in USBHost.cpp
There are a few warnings thrown by GCC for this source file that I have
attempted to correct.  I would definitely appreciate feedback from
others on these changes:
* USBHost::usb_process() would attempt to write past the end of the
  deviceInited[] array in the following code snippet:
    if (i == MAX_DEVICE_CONNECTED) {
        USB_ERR("Too many device connected!!\r\n");
        deviceInited[i] = false;
  The i variable is guaranteed to index 1 item past then end of this
  array since it only contains MAX_DEVICE_CONNECTED elements.  I have
  removed the line which sets deviceInited[i] to false.  Two questions
  result though:
    1) What was the intent of this line of code and is it Ok that I
       just removed it or should it be replaced with something else?
    2) I see no where else that elements in the deviceInited array are
       set to false except when all are set to false in the usbThread()
       method.  Should there be code in DEVICE_DISCONNECTED_EVENT to
       do this as well?
* USBHost::transferCompleted(volatile uint32_t addr) was comparing addr
  to NULL, which is of pointer type.  GCC issues a warning on this
  since the types are different (void* being compared to uint32_t).  I
  switched it to just compare with 0 instead.
* There is a switch statement in USBHost::unqueueEndpoint() which
  is conditional on a ENDPOINT_TYPE enumeration but doesn't contain
  cases for all values in the enumeration.  I just added a default
  case to simply break on other values to silence this GCC warning and
  allow the code to continue working as it did before.  Is it Ok that
  this particular piece of code only handles these two particular
  cases?
* USBHost::fillControlBuf() was generating a warning about possible
  alignment issues when accessing the setupPacket byte array as 16-bit
  half words instead.  I changed the casting to silence the warnings
  and modified the declaration of the setupPacket field to make sure
  that it is at least 2-byte aligned for these 16-bit accesses.
2013-08-29 19:22:36 -07:00
Adam Green bfafd8a014 USBHost: Calling memcpy() instead of memset()?
The two following memcpy() calls in USBEndpoint::init() are passing in
a NULL pointer as the copy source location.

    memcpy(td_list_[0], 0, sizeof(HCTD));
    memcpy(td_list_[1], 0, sizeof(HCTD));

I suspect that these were meant to be memset() calls instead so I
switched them.  In one of the places that I found where this method is
called, USBHost::newEndpoint(), its passes in an array of HCTD objects
which have already been cleared with similar memset() calls.  I am
therefore pretty certain that these were meant to be memset() calls but
if all callers already guarantee that they are zeroed out then maybe
the memset()s can be removed from USBEndpoint::init() anyway.
2013-08-29 18:22:22 -07:00
Adam Green 8a6d5ebc34 USBHost: Updates to allow compilation with GCC_ARM
I updated a few things in the USBHost source code to get it to compile
with GCC:
* In USBHALHost.cpp, the usb_buf global variable was defined with two
  different aligmnent specifiers:
    static volatile __align(256) uint8_t usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM1"),aligned));  //256 bytes aligned!
  The first one was not accepted by GCC.  I removed the duplicate
  alignment specifier and updated the one in the existing __attribute
  property to force the desired 256 byte alignment.
* Removed the explicit use of the __packed property from structures
  and instead used the PACKED macro defined in the mbed SDK's
  toolchain.h header file.  This macro does the right thing for the
  various compilers supported by the mbed team.
* Updated USB_* message macros in dbg.h to place spaces around
  references to the 'x' macro parameter.  Without this, C++ 11
  compilation thought the x character was a string literal operator but
  it wasn't one it recognized.  Adding the spaces makes it easier to
  see the use of the parameter, fixes this compile time error, and
  doesn't add any extra space to the final output string since the
  compiler only concatenates the contents within the double quotes of
  the strings.

By the way, I build with the gnu++11 standard since I have had requests
for its support from gcc4mbed.  Some of the items fixed here might not
be errors when using older standards with GCC.

I built and tested a USBHostMSD sample with these updates using both
GCC and the online compiler.  I will test more of the host interfaces
before issuing a pull request containing this commit.
2013-08-29 12:48:20 -07:00
Bogdan Marinescu e8bd53f85d Merge pull request #45 from dinau/master
Fixed: The issue of interrupt vector remapping for GCC_ARM LPC1114
2013-08-29 07:28:17 -07:00
dinau 841ce1d719 Fixed: The issue of interrupt vector remapping for GCC_ARM LPC1114 2013-08-29 21:40:57 +09:00
dinau 97d92789ec Fixed: The issue of interrupt vector remapping for GCC_ARM LPC1114 2013-08-28 23:29:16 +09:00
Adam Green b0c0f47c7d Changed leading whitespace back to tab.
The leading whitespace preceeding the fields in the lpc_enetdata
structure definition were originally a tab and I used 4 spaces when
I added RxThread.
2013-08-27 23:57:24 -07:00
Adam Green 8cf3e658d1 Don't use semaphore from ENET_IRQHandler to packet_rx
I now use a signal to communicate when a packet has been received by
the ethernet hardware and should be processed by the packet_rx thread.
Previously the change to make the lwIP stack thread safe introduced
enough delay in packet_rx that the semaphore count could lag behind
the processed packets and overflow its maximum token count.  Now the
ISR uses the signal to indicate that >= 1 packet has been received
since the last time packet_rx() was awaken.

Previously the ethernet driver used generic sys_arch* APIs exposed from
lwIP to manipulate the semaphores.  I now call CMSIS RTOS APIs
directly when using the signals.  I think this is acceptable since that
same driver source file already contains similar os* calls that talk
directly to the RTOS.
2013-08-27 23:38:42 -07:00
Adam Green 2bed996462 Revert "net: Only process 1 packet per ethernet RX interrupt"
This reverts commit acb35785c9.

It turns out that this commit actually causes problems if an ethernet
interrupt is dropped because a higher privilege task is running, such
as LocalFileSystem accesses.  If this happens, the semaphore count isn't
incremented enough times and the packet_rx() thread will fall behind and
end up running as though it had only one ethernet receive buffer.  This
causes even more lost packets.

I plan to fix this by switching the semaphore to be a signal so that
the syncronization object is more boolean.  It simply indicates if an
interrupt has arrived since the last time packet_rx() was awaken to
process inbound packets.
2013-08-27 22:24:47 -07:00
Adam Green de8161fde1 net: Reset pbuf length when re-queueing on error.
I recently pulled a NXP crash fix for their ethernet driver which will
requeue a pbuf to the ethernet driver rather than sending it to the
lwip stack if it can't allocate a new pbuf to keep the ethernet
hardware primed with available packet buffers.  While recently
reviewing this code I noticed that the full size of the pbuf wasn't
used on this re-queueing operation but the size of the last received
packet.  I now reset the pbuf size back to its originally allocated
size before doing this requeue operation.
2013-08-27 22:24:03 -07:00
Adam Green acb35785c9 net: Only process 1 packet per ethernet RX interrupt
Previously the packet_rx() function would wait on the RxSem and when
signalled it would process all available inbound packets.  This used to
cause no problem but once the thread synchronization was turned
on via SYS_LIGHTWEIGHT_PROT, the semaphore actually started to overflow
its maximum token count of 65535.  This caused the mbed_die() flashing
LEDs of death.  The old code was really breaking the producer/consumer
pattern that I typically see with a semaphore since the consumer was
written to consume more than 1 produced object per semaphore wait.
Before the thread synchronization was enabled, the packet_rx() thread
could use a single time slice to process all of these packets and then
loop back around a few more times to decrement the semaphore count
while skipping the packet processing since it had all been done.
Now the packet processing code would cause the thread to give up its
time slice as it hit newly enabled critical sections.  In the end it
was possible for the code to leak 2 semaphore signals for every 1 by
which the thread was awaken.  After about 10 seconds of load, this
would cause a leak of 65535 signals.

NOTE: Two potential issues with this change:
1) The LPC_EMAC->RxConsumeIndex != LPC_EMAC->RxProduceIndex check was
   removed from packet_rx().  I believe that this is Ok since the same
   condition is later checked in lpc_low_level_input() anyway so it
   won't now try to process more packets than what exist.
2) What if ENET_IRQHandler(void) ends up not signalling the RxSem for
   every packet received?  When would that happen?  I could see it
   happening if the ethernet hardware would try to pend more than 1
   interrupt when the priority was too elevated to process the
   pending requests.  Putting the consumer loop back in packet_rx()
   and using a Signal instead of a Semaphore might be a better
   solution?
2013-08-27 22:24:03 -07:00
Adam Green f5ec5d3ab2 net: Enable SYS_LIGHTWEIGHT_PROT
This option actually enables the use of the lwip_sys_mutex for
protecting concurrent access to such important lwIP resources as:
  select_cb_list (this is the one which orig flagged problem)
  sockets array
  mem stats (if enabled)
  heap (if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT was non-zero)
  memp pool allocs/frees
  netif->loop_last pbuf linked list
  pbuf reference counts
  ...

I first noticed this issue when I hit a crash while slamming the net
stack with a large number of TCP packets (I was actually sending 1k
data buffers from the TCPEchoServer mbed sample.)  It crashed in the
last line of this code snippet from event_callback:
  for (scb = select_cb_list; scb != NULL; scb = scb->next) {
    if (scb->sem_signalled == 0) {

It was crashing because scb had an invalid address so it generated a
bus fault.  I figured that memory was either corrupted or there was
some kind of concurrency issue.  In trying to determine which, I wanted
to walk through the select_cb_list linked list and see where it was
corrupted:
    (gdb) p scb
    $1 = (struct lwip_select_cb *) 0x85100080
    (gdb) p select_cb_list
    $2 = (struct lwip_select_cb *) 0x0

That was interesting, the head of the linked list was now NULL but it
must have had a non-NULL value when this loop started running or we
would have never gotten to the point where we hit this crash.

This was starting to look like a concurrency issue since the linked
list was modified out from underneath this thread.  Looking through the
source code for this function, I saw use of macros like
SYS_ARCH_PROTECT and SYS_ARCH_UNPROTECT which looked like they should
be providing the thead synchronization.  I disassembled the
event_callback() function in the debugger and saw no signs of the
usage of synchronizition APIs that I expected.  A search
through the code for the definition of these SYS_ARCH_UN/PROTECT
macros led me to discovering that they were actually ignored unless an
implementation defined them itself (the mbed version doesn't do so) or
the SYS_LIGHTWEIGHT_PROT macro is set to non-zero (the mbed version
didn't do this either).  Flipping the SYS_LIGHTWEIGHT_PROT macro on in
lwipopts.h fixed the crash I kept hitting, increased the size of the
code a bit, and unfortunately slows things down a bit since it now
actually serializes access to these data structures by making calls
to the RTOS sync APIs.
2013-08-27 22:24:03 -07:00
Adam Green fa392423c8 Silence GCC unused variable warning.
After making my previous commit to completely disable LWIP_ASSERT
macro invocations, I ended up with a warning in pbuf.c where an
err variable was set but only checked for success in an assert.  I
added a "(void)err;" reference to silence this warning.
2013-08-27 22:24:03 -07:00
Adam Green 4603d729f9 net: Fully disable LWIP_ASSERTs
I was doing some debugging that had me looking at the disassembly of
lpc_rx_queue() from within the debugger.  I was looking for the call to
pbuf_alloc() that we see in the following code snippet:
		p = pbuf_alloc(PBUF_RAW, (u16_t) EMAC_ETH_MAX_FLEN, PBUF_RAM);
		if (p == NULL) {
			LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
				("lpc_rx_queue: could not allocate RX pbuf (free desc=%d)\n",
				lpc_enetif->rx_free_descs));
			return queued;
		}

		/* pbufs allocated from the RAM pool should be non-chained. */
		LWIP_ASSERT("lpc_rx_queue: pbuf is not contiguous (chained)",
			pbuf_clen(p) <= 1);

When I was looking through the disassembly for this code I noticed a
call to pbuf_clen() in the actual machine code.
=> 0x0000bab0 <+24>:	bl	0x44c0 <pbuf_clen>
   0x0000bab4 <+28>:	ldr	r3, [r4, #112]	; 0x70
   0x0000bab6 <+30>:	ldrh.w	r12, [r5, #10]
   0x0000baba <+34>:	add.w	r2, r3, #9
   0x0000babe <+38>:	add.w	r0, r12, #4294967295	; 0xffffffff

The only call to pbuf_clean made from this function is made from
within the LWIP_ASSERT.  When I looked more closely at how this macro
was defined, I saw that the mbed version of the stack had disabled the
LWIP_PLATFORM_ASSERT macro when LWIP_DEBUG was false which means that
no action will be taken if the assert is false but it still allows the
LWIP_ASSERT macro to potentially evaluate the assert expression.
Defining the LWIP_NOASSERT macro will fully disable the LWIP_ASSERT
macro.

I saw one of my TCP/IP samples shrink about 0.5K when I made this
change.
2013-08-27 22:24:03 -07:00
Bogdan Marinescu 2cdd41d9b1 Added support for LPC11U24/_301 and LPC11U35_401 in uARM 2013-08-27 15:31:47 +03:00
Bogdan Marinescu 9a270999d0 Added support for LPC11U35_401 in ARM and GCC_ARM 2013-08-27 15:19:01 +03:00
Bogdan Marinescu 1c23d68281 Added support for LPC11U24_301/401 compilation with ARM toolchain 2013-08-27 14:52:39 +03:00
ytsuboi 2e549668a8 [LPC810] fixed scatter file 2013-08-24 16:02:03 +09:00
ytsuboi 8dd6bdb701 [LPC810] add LPC810 support 2013-08-24 15:49:16 +09:00
ytsuboi 9ae383f8f4 [LPC1114] fixed simple bugs on export templates 2013-08-24 11:57:44 +09:00
Emilio Monti 4d08c0741f Merge pull request #43 from adamgreen/gccWarnFlagUpdate
Updates to GCC warning level flags
2013-08-23 02:30:08 -07:00
Adam Green 25a332d8f1 Updates to GCC warning level flags
In gcc4mbed, I have been running with "-Wall -Wextra" and then
disabling a couple of noisy warnings that result.  In particular, I
disable the unused-parameter and missing-field-initializers warnings.
The first commonly goes off for implementation of virtual methods or
other overridable functions where not all parameters are required for
every override.  I don't find the second warning to be all that useful
anyway since missing structure field initializers will be set to 0
according to the C language specification.  The RTOS code uses this
language feature and I see no reason that it shouldn't :)
2013-08-22 18:09:14 -07:00
Emilio Monti 32fa9b27f7 Merge pull request #42 from adamgreen/usbdeviceGccWarnSilence
USBDevice: Silence GCC warning
2013-08-22 01:54:24 -07:00
Adam Green 76b7bb4209 USBDevice: Silence GCC warning
The following line in USBHAL_KL25Z.cpp would generate a warning in GCC
because of a potential operator precendence issue:
    return((USB0->FRMNUML | (USB0->FRMNUMH << 8) & 0x07FF));

This would have been interpreted as:
    return((USB0->FRMNUML | ((USB0->FRMNUMH << 8) & 0x07FF)));
since & has higher precedence than |

I switched it to be:
    return((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF);
Since it makes more sense to & with 0x7FF after having merged the lower
and upper bytes together rather than just the upper byte.  It should
have resulted in the same value either way.
2013-08-21 22:23:35 -07:00
Emilio Monti dfd6fe6fbe Merge pull request #41 from ytsuboi/master
[LPC1114] fixed to use IRC and System PLL clock
2013-08-21 05:25:51 -07:00
ytsuboi 4c0b5ab404 [LPC1114] fixed to use IRC and System PLL clock 2013-08-21 20:44:31 +09:00
Emilio Monti 05b42afb68 Merge pull request #40 from ytsuboi/master
Fixed error handling and cleanup
2013-08-21 01:57:51 -07:00
Toyomasa Watarai 1ff64de847 Fixed gpio_irq_api bugs
Corrected improper implementation of channel_ids[] usage.
Revemod redundant arrays e.g. pin_names[] and trigger_events[]
2013-08-21 16:46:03 +09:00
Toyomasa Watarai 463bf47a40 Support LPC1114 platform
Added TARGET_LPC1114 pins for InterruptIn test case and changed to
PullUp mode.
2013-08-21 16:41:18 +09:00
Toyomasa Watarai 10e30b5cfb Fixed error handling and cleanup 2013-08-21 10:46:37 +09:00
Bogdan Marinescu d4e5206fe9 Merge pull request #39 from adamgreen/fsGccWarnSilence
fs: Silence GCC signed/unsigned warnings
2013-08-20 00:36:08 -07:00
Adam Green 5e4439bb19 fs: Silence GCC signed/unsigned warnings
The SDFileSystem class contained a few routines which compared a signed
integer loop index to an unsigned integer length/size.  I switched the
loop index to be uint32_t as well.
2013-08-19 22:53:49 -07:00
Bogdan Marinescu 3210ac98d1 Added LPC1114 in the official release list 2013-08-19 13:51:39 +03:00
Emilio Monti b248827341 Add script to export mbed SDK tests to different IDEs 2013-08-16 16:40:53 +01:00
Bogdan Marinescu b7301d7a54 Merge remote-tracking branch 'github/master' 2013-08-16 16:00:25 +03:00
Bogdan Marinescu 2139c101e5 Merge pull request #38 from ytsuboi/master
Added LPC1114 support and fixed hard fault
2013-08-16 05:59:41 -07:00
Bogdan Marinescu 15ed7ea66a Fix bug in Ticker code
The bug was introduced by the interrupt chaining code.
2013-08-16 15:55:24 +03:00
Toyomasa Watarai c26d2a990d Removed detach() call in test case 2013-08-16 21:47:42 +09:00