Commit Graph

194 Commits

Author SHA1 Message Date
Benoît Thébaudeau
e8a268cd15 cc2538: aes: Add support for 192- and 256-bit keys
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-02 21:41:56 +02:00
Benoît Thébaudeau
801315e819 cc2538: aes: Make it possible to have several keys stored at once
Several keys can be kept at the same time in the key store, and several
keys can be loaded at once. Give access to these features.

The ccm-test example is also improved to better demonstrate the use of
the key store.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-02 21:41:07 +02:00
Benoît Thébaudeau
b92a5afcc4 cc2538: ccm: Make it possible to use the interrupt
Using the AES interrupt allows the user process not to waste time
polling for the completion of the operation. This time can be used by
the user process to do something else, or to let the system enter PM0.

Since the system is now free to perform various operations during a
crypto operation, a protection of the crypto resource is added, and PM1+
is prohibited in order not to stall crypto operations.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-02 21:41:07 +02:00
Benoît Thébaudeau
117dc4e5e3 cc2538: Add crypto drivers and examples for AES-CCM and SHA-256
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-02 21:41:06 +02:00
Benoît Thébaudeau
66acf74612 cc2538: examples: Fix build warnings
Toolchain used:
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150303
(release) [ARM/embedded-4_9-branch revision 221220]

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-06-02 01:38:11 +02:00
George Oikonomou
d28eb023ef Remove CC2530 and CC2538 dummy watchdog_stop()
The CC2538 the WDT cannot be stopped once it has been started.
The CC2530/1 WDT can be stopped if it is running in timer mode,
but it cannot be stopped once it has been started in watchdog mode.

Both platforms currently provide "dummy" implementations of `watchdog_stop()`,
one does nothing and the other one basically re-maps `_stop()` to
`_periodic()`.

This was originally done in order to provide implementations for all prototypes
declared in `core/dev/watchdog.h`. In hindsight and as per the discussion
in #1088, this is bad practice since, if the build succeeds, the caller will
expect that the WDT has in fact been stopped, when in reality it has not.

Since the feature (stopping the WDT) is unsupported by the hardware, this pull
removes those dummy implementations. Thus, we will now be able to reliably
detect - at build time - attempts at using this unsupported feature.
2015-06-01 15:24:14 +01:00
Benoît Thébaudeau
1cd3c9e7e5 cc2538: Initialize .data/.bss using ROM functions
This is safer because the previous code assumed that the start and end
VMAs of .data and .bss were word-aligned, which is not always the case,
so the initialization code could write data outside these sections. The
ROM functions support any address boundary.

This is faster because the ROM functions are ultra optimized, using
realignment and the LDM/STM instructions, which is much better than the
previous simple loops of single word accesses.

This is smaller because the ROM functions don't require to add any code
to the target device other than simple function calls.

This makes the code simpler and more maintainable because standard
functions are not reimplemented and no assembly is used.

Note that this is also faster and smaller than the corresponding
functions from the standard string library.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-05-23 18:50:52 +02:00
Benoît Thébaudeau
609c615303 cc2538: Move the stack out of .bss
The initialization code clearing .bss is allowed to use the stack, so
the stack can not be in .bss, or this code will badly fail if it uses
the stack.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-05-23 18:50:52 +02:00
Benoît Thébaudeau
0de729572b cc2538: Word-align .data LMA
In order to be fast, the reset_handler() function uses word accesses to
initialize the .data output section. However, most toolchains do not
automatically force the alignment of an output section LMA to use the
maximum alignment of all its input sections. Because of that, assuming
that .data contains some words, the LMA of the .data output section was
not word-aligned in some cases, resulting in an initialization performed
using slow unaligned word accesses.

This commit forces the alignment of the LMA of the .data output section
with a word boundary in order to always use fast aligned word accesses
to read the .data load area.

Note that this solution is better than using ALIGN_WITH_INPUT, both
because the latter is a new feature incompatible with older toolchains,
and because it could create a big gap between _etext and the LMA of
.data if strongly-aligned data were added to .data, although only a word
alignment is required here.

The same considerations apply to the VMA of .data. However, it is
already automatically word-aligned, both because .data contains words,
and because the end VMA of the previous output section (.socdata) is
word-aligned. Moreover, if the VMA of .data were forcibly word-aligned,
then a filled gap could appear at the beginning of this section if
strongly-aligned data were added to it, thus wasting flash memory.
Consequently, it's better not to change anything for the VMA of .data,
all the more it's very unlikely that it does not contain any word and
that the end VMA of .socdata becomes non-word-aligned, and this would
only result in a slower initialization.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-05-23 18:12:54 +02:00
Benoît Thébaudeau
0d260f61a0 cc2538: Fix .data LMA/VMA mismatch with some toolchains
Some toolchains, like Sourcery CodeBench Lite 2013.05-23 arm-none-eabi
(http://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/)
automatically force the alignment of an output section LMA to use the
maximum alignment of all its input sections. This toolchain uses GNU
binutils 2.23, and this automatic behavior is the same as the manual
behavior of the ALIGN_WITH_INPUT feature of GNU binutils 2.24+.

This behavior is not an issue per se, but it creates a gap between
_etext and the LMA of the .data output section if _etext does not have
the same alignment, while reset_handler() initialized this section by
copying the data from _etext to its VMA, hence an offset in the
addresses of loaded data, and missing data.

This commit fixes this issue by making reset_handler() directly use the
LMA of the .data section using LOADADDR(.data), rather than assuming
that _etext is this LMA.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-05-23 18:12:53 +02:00
Ulf Knoblich
d8efa8428c cc2538: Allow for configuration of processor speed 2015-05-19 18:55:55 +02:00
Ulf Knoblich
a388a1bcd7 CC2538: added support for SSI1 2015-05-18 10:02:55 +02:00
Benoît Thébaudeau
25532e8abf Merge pull request #754 from wwhuang/master
[CC2538] Fix SPI_FLUSH
2015-05-16 20:55:30 +02:00
Benoît Thébaudeau
d64927397f Merge pull request #968 from g-oikonomou/cc2538-contrib-on-chip-sensors
Move CC2538 VDD/3 and On-Chip Temp sensors to the CPU dir
2015-05-14 19:21:56 +02:00
Benoît Thébaudeau
71f22b1775 Merge pull request #966 from g-oikonomou/cc2538-startup-to-cpu-dir
Move cc2538 startup-gcc.c to the CPU dir
2015-05-14 18:43:39 +02:00
George Oikonomou
f7baf5aba2 Change CC2538 USB and UART handlers to weak 2015-05-13 01:31:26 +01:00
George Oikonomou
96e1647270 Move cc2538 startup-gcc.c to the CPU dir 2015-05-13 01:31:10 +01:00
George Oikonomou
3717522680 Re-work the CC2538 driver to be a driver for the Srf06 ALS only 2015-05-12 23:42:19 +01:00
George Oikonomou
06b0ee4a8b Include CC2538 sensors in the build 2015-05-12 23:42:19 +01:00
George Oikonomou
9cc800d728 Add CC2538 VDD sensor driver 2015-05-12 23:42:19 +01:00
George Oikonomou
f474514ee5 Add CC2538 tmp sensor driver 2015-05-12 23:42:19 +01:00
George Oikonomou
40716ab515 Add generic header for CC2538 sensors 2015-05-12 23:42:18 +01:00
George Oikonomou
a2d6df225e Merge pull request #967 from g-oikonomou/cc2538-contrib-rf-local-vars
Use local variable to store RF on/off state
2015-05-09 22:23:31 +01:00
George Oikonomou
2059be3a43 Merge pull request #1031 from bthebaudeau/cc2538-gpio-irqs
cc2538: gpio: Improve and fix IRQ management
2015-05-03 18:42:53 +01:00
Ulf Knoblich
8e624c750d cc2538 i2c bug in clock computation 2015-04-29 11:07:59 +02:00
Benoît Thébaudeau
3d9d52de87 cc2538: gpio: Fix missed interrupts
Only the interrupt flags that have been handled must be cleared.
Otherwise, if a new interrupt occurs after the interrupt statuses are
read and before they are cleared, then it is discarded without having
been handled. This issue was particularly likely with two interrupt
trigger conditions occurring on different pins of the same port in a
short period of time.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-04-27 01:14:51 +02:00
Benoît Thébaudeau
1a5632cba0 cc2538: gpio: Fix missed power-up interrupts
Power-up interrupts do not always update the regular interrupt status.
Because of that, in order not to miss power-up interrupts, the ISR must
handle both the regular and the power-up interrupt statuses.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-04-27 01:14:51 +02:00
Benoît Thébaudeau
1e67ab3941 cc2538: gpio: Add macros to get interrupt status
Introduce new useful GPIO macros to:
 - get the raw interrupt status of a port,
 - get the masked interrupt status of a port,
 - get the power-up interrupt status of a port.

These macros are cleaner and less error-prone than raw register access
code copied all over the place.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-04-27 01:14:51 +02:00
Benoît Thébaudeau
41d9078ed4 cc2538: gpio: Factor out duplicated ISR code
This makes the code easier to maintain, and this reduces the binary
image size.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-04-27 01:14:50 +02:00
George Oikonomou
48e987baac Merge pull request #1005 from alignan/i2c_cc2538
CC2538 I2C driver
2015-03-28 23:23:06 +00:00
Benoît Thébaudeau
19fd7a3551 Use additive offsets
OR-ing an offset to a base address instead of adding it is dangerous
because it can only work if the base address is aligned enough for the
offset.

Moreover, if the base address or the offset has a value unknown at
compile time, then the assembly instructions dedicated to 'base +
offset' addressing on most CPUs can't be emitted by the compiler because
this would require the alignment of the base address against the offset
to be known in order to optimize 'base | offset' into 'base + offset'.
In that case, the compiler has to emit more instructions in order to
compute 'base | offset' on most CPUs, e.g. on ARM, which means larger
binary size and slower execution.

Hence, replace all occurrences of 'base | offset' with 'base + offset'.
This must become a coding rule.

Here are the results for the cc2538-demo example:
 - Compilation of uart_init():
    * before:
        REG(regs->base | UART_CC) = 0;
        200b78:	f446 637c 	orr.w	r3, r6, #4032	; 0xfc0
        200b7c:	f043 0308 	orr.w	r3, r3, #8
        200b80:	2200      	movs	r2, #0
        200b82:	601a      	str	r2, [r3, #0]

    * now:
        REG(regs->base + UART_CC) = 0;
        200b7a:	2300      	movs	r3, #0
        200b7c:	f8c4 3fc8 	str.w	r3, [r4, #4040]	; 0xfc8

 - Size of the .text section:
    * before:	0x4c7c
    * now:	0x4c28
    * saved:	84 bytes

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2015-03-28 17:28:15 +01:00
William Huang
1e39c9a454 fixed SPI_FLUSH. current implementation waits for rx buffer to fill first. Thus, if we call SPI_FLUSH to make sure the rx fifo is empty when the rx fifo is already empty, we enter an infinite loop 2015-03-26 14:17:06 -04:00
Antonio Lignan
22be9fd8b7 I2C driver taken from PR #677, uncrustified, made functions static and added burst modes 2015-03-25 16:44:12 +01:00
George Oikonomou
5288725af7 Use local variable to store RF on/off state
Fixes #823
2015-02-18 09:05:02 +01:00
George Oikonomou
6bd8bb05f6 Improve wording 2015-02-16 10:17:58 +01:00
George Oikonomou
72914369e8 Re-structure CC2538 doxygen module hierarchy 2015-02-16 10:17:58 +01:00
George Oikonomou
8751e55c94 Improve wording, fix warnigs in the SSI/SPI docs 2015-02-16 10:17:58 +01:00
George Oikonomou
a93a8912c2 Clarify GPIO read and write macros 2015-02-16 10:17:57 +01:00
George Oikonomou
4100cbc9c0 Fix doxygen warning in the CC2538 uDMA driver's header 2015-02-16 10:17:57 +01:00
George Oikonomou
88e190103c Fix doxygen warning in the CC2538 SPI driver 2015-02-16 10:17:57 +01:00
George Oikonomou
b6bd556805 Fix clock.h warnings caused by multiple, conflicting documentation blocks of clock functions 2015-02-15 21:48:30 +01:00
Michael Karlsson
62fc6f2f07 corrected code style error 2015-02-13 13:46:57 +01:00
Michael Karlsson
be9879cf18 fixed error in saving status 2015-01-21 22:35:30 +01:00
Michael Karlsson
37def294ce fixed bug that made radio die after error when not using default channel and/or not using a RDC protocol 2015-01-21 22:28:31 +01:00
Jelmer Tiete
b088326b5e Corrected the register offset value of ANA_REGS_IVCTRL. TI was using the address offset instead of the physical address in their header file. 2014-12-19 04:14:34 -05:00
George Oikonomou
9d7c3b9866 Improve documentation for the CC2538 IEEE address re-ordering 2014-06-06 18:33:28 +01:00
George Oikonomou
5acc20fc47 Improve code style 2014-06-06 18:32:58 +01:00
George Oikonomou
623d6084e7 Make the CC2538 secondary IEEE address location configurable 2014-06-06 18:15:07 +01:00
LudovicW
66edb5b263 Fix incorrect IEEE address byte re-ordering 2014-06-06 17:22:33 +01:00
George Oikonomou
2e166a83c7 Merge pull request #691 from hexluthor/rts-cts
CC2538: Add hardware flow control (RTS/CTS) support on UART1.
2014-06-04 09:22:58 +01:00
George Oikonomou
ba9c2d40eb Merge pull request #682 from g-oikonomou/watchdog-cc2538
Confine CC2538 WDT on/off conf inside the driver
2014-06-03 22:05:08 +01:00
Adam Dunkels
64f65b4e45 Merge pull request #617 from nfi/extended-radio-api
Extended radio API with support for setting channel, pan id, addressing modes, etc
2014-06-03 21:32:53 +02:00
Ian Martin
274b3dcd0b CC2538: Add hardware flow control (RTS/CTS) support on UART1. 2014-06-03 12:38:24 -04:00
George Oikonomou
807ee624e4 Confine CC2538 WDT on/off conf inside the driver
Instead of requiring all calls to `watchdog_start` to be
wrapped inside `#if WATCHDOG_CONF_ENABLE` guards, we control
things from within the WDT driver itself.

This commit also includes some minor documentation and
indentation cleanups
2014-05-18 14:12:16 +02:00
George Oikonomou
b864ec2b71 Merge pull request #661 from hexluthor/watchdog-enable
CC2538: Add WATCHDOG_CONF_ENABLE to optionally disable the watchdog timer
2014-05-18 14:11:49 +02:00
Ian Martin
2abaeaa8cc CC2538: Add FLASH_CONF_ORIGIN and FLASH_CONF_SIZE config parameters. 2014-05-02 11:35:58 -04:00
Ian Martin
7081440eff CC2538: Add WATCHDOG_CONF_ENABLE to optionally disable the watchdog timer. 2014-05-02 10:28:30 -04:00
George Oikonomou
08c884afa0 Improve the CC2538 extended RF API implementation
* Decouple 64-bit address from LINKADDR_SIZE
* get and set object from/to the start/end of the src/dest buffer
* We expect size == 8 (rather than size < 8) for both get_ and set_object. Error otherwise
* The RF no longer sets parameters by itself. We let the platform do this, using the extended API.
2014-04-23 12:20:16 +01:00
George Oikonomou
6028c0765f Don't hardcode min and max TX power values 2014-04-23 12:16:50 +01:00
George Oikonomou
b0f1199202 Merge pull request #636 from g-oikonomou/fix-random-init-lockup
Fix CC2538 random_init lockup
2014-04-18 13:28:40 +01:00
George Oikonomou
49bf7cc241 Merge pull request #616 from hexluthor/listing
CC2538: Add a Makefile rule to generate a final assembly listing.
2014-04-17 22:13:52 +01:00
Benoît Thébaudeau
d93d129da6 cc2538: uart: Make it possible to use several UARTs simultaneously
This avoids the limitation of having a single UART available at runtime, without
duplicating code.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2014-04-17 18:53:44 +02:00
Brad Campbell
af27d2d252 [CC2538-SPI] Implement SPI_FLUSH, spi mode, !CS
Because the CC2538 has a multi-byte SPI RX FIFO, flushing the buffer
requires more than just a single read. This adds a loop that empties the
entire RX buffer on a FLUSH().

Different SPI chips needs different SPI settings. This commit adds a
function that allows chip drivers to configure the SPI peripheral before
using it.

The frame pin the driver was using as a chip select does not work as
most devices expect it to. It toggles after every byte, and most chips
interpret that as end of message. To make drivers more reliable, each
chip driver should setup a GPIO and assert it as needed.
2014-04-15 14:07:10 -04:00
George Oikonomou
0ec1eda75e Implement extended RF API for the CC2538 2014-04-14 15:25:30 +02:00
George Oikonomou
602f834caf Merge pull request #472 from ADVANSEE/cc2538-clock-adjust-etimer-poll
cc2538: clock: Fix clock / timer issues with PM1/2
2014-04-13 16:35:17 +01:00
George Oikonomou
eed1352282 Fix CC2538 random_init lockup
Contiki sometimes fails to boot correctly and locks up in
random_init()

This problem only manifests itself for specific versions
of the arm-gcc toolchain and then again only for specific
levels of optimisation (-Os vs -O2, depending on the
value of the SMALL make variable)

The lockup is caused when we write an RFCORE XREG before
the RF clock ungating has taken effect, which in turn
only occurs depending on the assembly generated for those
two instructions:

  REG(SYS_CTRL_RCGCRFC) = 1;

  REG(RFCORE_XREG_FRMCTRL0) = 0x00000008;

This commit makes the RNG wait for the ungating to take
effect before attempting to write the register
2014-04-13 14:38:00 +01:00
George Oikonomou
33abe26ec8 Merge pull request #411 from ADVANSEE/cc2538-adc
cc2538: Add adc driver and example
2014-04-13 03:05:12 +01:00
Niclas Finne
a98e153e23 Added stub for extended radio API for cc2538 2014-04-03 13:38:23 +02:00
Ian Martin
56d0dfdc7a CC2538: Add a Makefile rule to generate a final assembly listing. 2014-04-02 18:17:49 -04:00
Ian Martin
336224633a Eliminate UART_CONF_IBRD and UART_CONF_FBRD. 2014-03-22 10:26:03 -04:00
Ian Martin
ee45fc7533 Change uart_set_baudrate() to a do-while statement. 2014-03-22 10:22:11 -04:00
Ian Martin
1ceb8ae358 Fix rounding error in baudrate calculation. 2014-03-22 10:21:54 -04:00
Ian Martin
e3c19714d4 cc2538: Support any UART baudrate. 2014-03-14 16:06:24 -04:00
George Oikonomou
5675e688a8 Merge pull request #562 from Noolitic/CC2538_UART
CC2538: add support for UART baudrate 9600, 38400 and 57600
2014-03-08 23:41:52 +00:00
Brad Campbell
d14f0d5eed CC2538: add secondary location to ieee address
The CC2538 currently has two addressing options: a hardcoded address set
at compile time or the address stored in primary address section of the
info page. This commit adds the option to choose the secondary location
of the ieee address from the info page, or any memory address.

To use, define `IEEE_ADDR_CONF_USE_SECONDARY_LOCATION` in `project-conf.h`
or similar.

For example:

    #define IEEE_ADDR_CONF_USE_SECONDARY_LOCATION 1
2014-03-06 10:31:30 -05:00
LudovicW
d979e5b096 CC2538: add support for UART baudrate 9600, 38400 and 57600 2014-02-11 16:01:36 +01:00
George Oikonomou
332d56ac11 Make some CC2538 CFLAGS and LDFLAGS common
Some CFLAGS and LDFLAGS previously only enabled with SMALL=1 have
now been enabled for all builds, regardless of the value of SMALL.

Therefore, from now on, SMALL only chooses between -Os and -O2
2014-01-31 20:02:43 +00:00
George Oikonomou
a63376f8be Use -Os for CC2538 builds
As discussed in #503, -Os was broken with one of the toolchains
recommended in the platform's README and for that reason we were
using -O2 by default.

This commit sets the default to -Os and updates the README to no
longer recommend the toolchain in question
2014-01-31 20:02:43 +00:00
George Oikonomou
c8fbf8ca6e Merge pull request #503 from ADVANSEE/cc2538-nrdata-noload
cc2538: Clean up link stage
2014-01-30 07:58:55 -08:00
Nicolas Tsiftes
4e6bed24f9 Merge pull request #547 from adamdunkels/push/rimeaddr-linkaddr
Rename the rimeaddr module to linkaddr
2014-01-29 12:57:44 -08:00
Adam Dunkels
45265249fc Changed the name of the rimeaddr module to linkaddr 2014-01-29 20:12:24 +01:00
George Oikonomou
345532c559 Merge pull request #546 from ADVANSEE/cc2538-fix-disabled-lpm
cc2538: lpm: Fix build for LPM_CONF_ENABLE == 0
2014-01-29 08:40:56 -08:00
Adam Dunkels
765e9acded Merge pull request #499 from adamdunkels/bold/modularize-everything
A bold move: modularize everything
2014-01-29 08:17:10 -08:00
Benoît Thébaudeau
42c287f363 cc2538: lpm: Fix build for LPM_CONF_ENABLE == 0
lpm.c needs to #include lpm.h in order to get the definition of
lpm_periph_permit_pm1_func_t, which made the replacement macros conflict with
the function definitions for the LPM_CONF_ENABLE == 0 case. This change fixes
this issue by #if-ing out the code in lpm.c in that case. Also, the replacement
macro for lpm_register_peripheral() was missing in that case, which is fixed
here.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2014-01-28 20:21:06 +01:00
Benoît Thébaudeau
a562acb160 cc2538: Fix library linkage
If a project needs to use some libraries at link stage, then the corresponding
linker options (e.g. '-lm') have to be passed after any .o file depending on
these libraries. Hence, LDFLAGS cannot be used to add such options when invoking
$(LD) in Makefile.cc2538, or it should be moved to the correct location.
Instead, this change adds TARGET_LIBFILES to the correct location, like most
other Contiki targets.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2014-01-28 14:32:30 +01:00
Adam Dunkels
0fe08205e1 Moved the rimeaddr.[ch] code from the core/net/rime module to the core/net module, as it is used not only by rime code 2014-01-26 23:20:36 +01:00
Benoît Thébaudeau
fe4eb545c0 cc2538: Remove the unused vtable section
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-23 15:50:05 +01:00
Benoît Thébaudeau
37e73894f1 cc2538: Move SoC data to a dedicated section to save space
Some SoC data requires huge alignments. E.g., the µDMA channel control table has
to be 1024-byte aligned. This table was simply aligned to 1024 bytes in the C
code, which had the following consequences, wasting a lot of RAM:
 - As this table could be placed anywhere in .bss, there could be an alignment
   gap of up to 1023 bytes between the preceding data and this table.
 - The size of this table was also aligned to 1024 bytes, regardless of
   UDMA_CONF_MAX_CHANNEL, making this configuration option supposed to save RAM
   just useless.
 - .bss was also aligned to at least 1024 bytes, creating a huge alignment gap
   between .data and .bss.

Instead of relying on the compiler to force this alignment, and on the linker to
automatically place data, this change places carefully such SoC data in RAM
using the linker script. A dedicated section is created to place such SoC data
requiring huge alignments, and it is put at the beginning of the SRAM in order
to ensure a maximal alignment without any gap. In this way, the alignment of
.bss also remains normal, and the size of this table is not constrained by its
alignment, but only by its contents (i.e. by UDMA_CONF_MAX_CHANNEL).

In the case of the µDMA channel control table, the data is still zeroed by
udma_init() (instead of also being zeroed as part of .bss).

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-23 15:06:13 +01:00
Benoît Thébaudeau
ab4b955f17 cc2538: Sort link input sections by alignment to optimize size
Normally, the linker does not sort files and sections matched by wildcards, so
they are placed in the order in which they are seen during link. If numerous
objects with different alignments are mixed, or if objects with unusually large
alignments are present, this very likely leads to a lot of space being wasted
because of accumulated alignment gaps.

This commit forces input sections to be sorted by alignment (unless this is
overridden by the linker script), which decreases the number and the size of
alignment gaps, thus saving space.

For a typical Contiki project, this change saves nearly 1 kiB, mainly in .bss.

Note that this behavior is only enabled if the SMALL make variable is set to 1,
because this makes more sense for a size optimization.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-19 21:45:27 +01:00
Benoît Thébaudeau
e1147ec787 cc2538: Set the type of the .nrdata output section to NOLOAD
The .nrdata section is volatile, so its initialization must be controlled by the
application, and not be automatically done by the startup code. It should
neither be zeroed like .bss, nor be initialized from data in flash memory like
.data. This was already supposed to be the case, but the output section type of
.nrdata was not set to NOLOAD, causing the generated ELF .nrdata section header
to be of type PROGBITS instead of NOBITS, i.e. load data was generated to be
programmed in RAM, thus producing huge unprogrammable .bin files.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-13 17:45:57 +01:00
Benoît Thébaudeau
dbba311270 cc2538: Add adc driver and example
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-06 22:07:45 +01:00
Benoît Thébaudeau
d86b8275ec cc2538: clock: Fix time drift occurring with PM1/2
The clock adjustments made when waking up from PM1/2 were very inaccurate. If
relying on ContikiMAC's rtimer to sleep, this led to Contiki's software clock
time, seconds and etimers to be 2.5 s slower after each min, i.e. 1 hour slower
after each day, which is a show stopper issue for most real-life applications.

This was caused by a lack of accuracy in several pieces of code during sleep
entry and wake-up:
 - It was difficult to synchronize the calls to RTIMER_NOW() before and after
   sleep with the deactivation and activation of the SysTick peripheral caused
   by PM1/2. This caused an inaccuracy in the corrective number of ticks passed
   to clock_adjust().
 - The value passed to clock_adjust() was truncated from an rtimer_clock_t
   value, but the accumulated error caused by these truncated bits was ignored.
 - The SysTick peripheral had to be stopped during the call to clock_adjust().

Rather than creating even more complicated clock adjustment mechanisms that
would probably still have mixed results as to accuracy, this change simply uses
the Sleep Timer counter as a base value for Contiki's clock and seconds
counters. The tick from the Systick peripheral is still used as the interrupt
source to update Contiki's clocks and timers. When running, the SysTick
peripheral and the Sleep Timer are synchronized, so combining both is not an
issue, and this allows not to alter the rtimer interrupt mechanism using the
Sleep Timer. The purpose of the Sleep Timer is to be an RTC, so it is the
perfect fit for the clock module, all the more it can not be disturbed by PM1/2.
If the 32-kHz XOSC is used, the Sleep Timer is also very accurate. If the
32-kHZ RCOSC is used, it is calibrated from the 32-MHz XOSC, so it is also
accurate, and the 32753-Hz vs. 32768-Hz systematic error in that case is
negligible, all the more one would use the 32-kHz XOSC for better accuracy.

Besides fixing this time drift issue, this change has several benefits:
 - clock_time(), clock_seconds() and RTIMER_NOW() start synchronized, and they
   change at the same source pace.
 - If clock_set_seconds() is called, then clock_seconds() indicates one more
   second almost exactly one second later, then exactly each second. Before this
   change, clock_seconds() was not synchronized with clock_set_seconds(), so the
   value returned by the former could be incremented immediately after the call
   to the latter in some cases.
 - The code tied to the clock module is simpler and more robust.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-06 13:04:30 +01:00
Benoît Thébaudeau
b7515004da cc2538: clock: Fix secs update in clock_adjust()
Whole elapsed seconds are added to secs first, so only the remaining subsecond
ticks should then be subtracted from second_countdown in order to decide whether
secs should be incremented again.

Otherwise, secs is not correctly updated in some cases, typically if the bit 7
of ticks is 1. E.g., with ticks = 128 (i.e. exactly 1 s elapsed) and
second_countdown = 128, secs was first incremented as expected, then 128 was
subtracted from second_countdown, giving 0 and triggering an unwanted second
increment of secs. Or with ticks = 129 (i.e. 1 s + 1 tick) and
second_countdown = 1, secs was first incremented as expected, then 129 was
subtracted from second_countdown, giving 128 and missing a second increment of
secs that should have occurred because second_countdown wrapped around.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-06 13:02:37 +01:00
Benoît Thébaudeau
28a563a24b cc2538: clock: Request an etimer poll in clock_adjust()
During PM1+, the hardware timer used to implement the Contiki clock is frozen,
so clock_adjust() needs to be called when exiting those modes in order to
compensate for the clock ticks missed while the timer was frozen. Doing so
changes the Contiki clock time, so etimer_request_poll() needs to be called in
order to inform the etimer library that an etimer might have expired.

Note that waiting for the next clock ISR to call etimer_request_poll() is
unreliable because the system might go back to sleep beforehand.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-06 13:02:37 +01:00
Benoît Thébaudeau
5261bb861d cc2538: lpm: Fix RTIMER_NOW() upon wake-up
When returning from PM1/2, the sleep timer value (used by RTIMER_NOW()) is not
up-to-date until a positive edge on the 32-kHz clock has been detected after the
system clock restarted. To ensure an updated value is read, wait for a positive
transition on the 32-kHz clock by polling the SYS_CTRL_CLOCK_STA.SYNC_32K bit,
before reading the sleep timer value.

Because of this RTIMER_NOW() fixup, lpm_exit() has to be called at the very
beginning of ISRs waking up the SoC. This also ensures that all clocks and
timers are enabled at the correct frequency and updated before using them
following wake-up.

Without this fix, etimers could sometimes (randomly, depending on timings)
become ultra slow (observed from 10x to 40x slower than normal) if the system
exited PM1/2 very often. This issue occurred more often with PM1.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-05 20:23:29 +01:00
Benoît Thébaudeau
f149197aa8 cc2538: lpm: Speed up the transition to the 32-MHz XOSC after wake-up
As recommended by the CC2538 User's Guide, set SYS_CTRL_CLOCK_CTRL.OSC_PD to 0
before asserting WFI, and set it to 1 after the system clock is sourced from the
32-MHz XOSC following wake-up. This allows to automatically start both
oscillators upon wake-up in order to partially hide the 32-MHz XOSC startup time
by the 16-MHz RCOSC startup time.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-05 20:23:29 +01:00
Benoît Thébaudeau
13006e1c73 cc2538: lpm: Let system clock transitions complete before further changes
As a matter of precaution, always make sure that pending system clock
transitions are complete before requesting a new change of the system clock
source.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-05 20:23:29 +01:00
Benoît Thébaudeau
8514a91ea9 cc2538: lpm: Fix energest context when aborting lpm_enter()
In one of the abort cases in lpm_enter(), the energest context has previously
been set to LPM, so the abort code needs to set it back to CPU.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-05 20:23:29 +01:00
George Oikonomou
f2c552bb55 Merge pull request #478 from ADVANSEE/cc2538-startup-cleanup
cc2538: Startup cleanup
2013-12-05 11:07:19 -08:00
George Oikonomou
17b2150081 Merge pull request #463 from ADVANSEE/cc2538-ports-pins
cc2538: Clean up and improve port and pin definitions
2013-12-05 10:31:29 -08:00