Commit graph

62 commits

Author SHA1 Message Date
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 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
Benoît Thébaudeau a2686e581e cc2538: Add header file for flash CCA page and use it
Create a dedicated header file with all the definitions for the flash lock bit
page and customer configuration area. This avoids duplicating those definitions
in the startup-gcc.c files of all CC2538-based platforms, and this also allows
to easily manipulate the CCA from outside startup-gcc.c (e.g. for on-the-air
firmware update).

The definitions are now complete contrary to what was in startup-gcc.c:
 - Definitions have been added to select the bootloader backdoor pin and active
   level if enabled.
 - Definitions have been added to access the page and debug lock bits. The debug
   lock bit can be used to prevent someone from reading back a programmed
   firmware through JTAG if the firmware binary image has to be confidential,
   which should be combined with a disabled bootloader backdoor.
 - The application entry point is now tied to the beginning of the .text section
   instead of to the beginning of the flash. This allows projects using custom
   linker scripts to place the application entry point anywhere in the flash,
   which can be useful e.g. for on-the-air firmware update.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-05 18:45:51 +01:00
George Oikonomou 8b003c30c7 Merge pull request #471 from ADVANSEE/cc2538-gpio-power-up
cc2538: gpio: Add support for power up
2013-12-05 09:25:05 -08:00
George Oikonomou 97cdf39b95 Merge pull request #464 from ADVANSEE/cc2538-pm2-sram
cc2538: lpm: Give access to the SRAM non-retention area for PM2
2013-12-05 09:19:22 -08:00
Benoît Thébaudeau 1a696eb123 cc2538: gpio: Clear the power-up interrupts in the port ISRs
The pending GPIO power-up interrupts have to be cleared in the ISRs in order not
to re-trigger the interrupts and the wake-up events.

The power-up interrupts of all pins are cleared for each port in the
corresponding port ISR. This is done after calling the registered callbacks so
that the callbacks can know which pin woke up the SoC. This is done after
clearing the regular interrupt in order to avoid getting a new wake-up interrupt
without the regular interrupt in the case of a new wake-up edge occurring
between the two clears.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-26 22:20:05 +01:00
Benoît Thébaudeau 44a5c76884 cc2538: gpio: Add macros to use GPIO power-up interrupts
The GPIO power-up interrupts have to be configured and enabled in order to be
able to wake-up the SoC from PM1+ upon a signal edge occurring on a GPIO input
pin.

This set of macros allows to:
 - configure the signal edge triggering a power-up interrupt,
 - enable and disable a power-up interrupt,
 - clear a power-up interrupt flag.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-26 22:10:47 +01:00
Benoît Thébaudeau 621f4f7339 cc2538: lpm: Give access to the SRAM non-retention area for PM2
If PM2 is enabled with LPM_CONF_MAX_PM, but not active, the non-retention area
of the SRAM can be useful to place temporary data that does not fit in the
low-leakage SRAM, typically after having called lpm_set_max_pm(LPM_PM1). Hence,
give access to this non-retention area thanks to .nrdata* sections.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-25 15:43:37 +01:00
Benoît Thébaudeau 270ed237fd cc2538: usb: Make the GPIO driving the pull-up optional
The data sheet recommends that the USB pull-up resistor be driven by a GPIO so
that it can be controlled by software, but this is not mandatory. Hence, leave
the choice so that CC253-based boards not using this option can build and work
fine.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-25 15:15:35 +01:00
Benoît Thébaudeau d2f3795a30 cc2538: Clean up port and pin definitions
Homogenize port and pin definitions naming:
 - PERIPHERAL_FUNCTION_PORT for the port ID,
 - PERIPHERAL_FUNCTION_PIN for the pin ID,
 - PERIPHERAL_FUNCTION_PORT_BASE for the port base,
 - PERIPHERAL_FUNCTION_PIN_MASK for the pin mask.

Define only PERIPHERAL_FUNCTION_PORT and PERIPHERAL_FUNCTION_PIN in board.h, and
deduce PERIPHERAL_FUNCTION_PORT_BASE and PERIPHERAL_FUNCTION_PIN_MASK in the
driver from the former definitions.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-25 15:00:41 +01:00
Adam Dunkels bb2dcaa057 A massive all-tree automated update of all double inclusion guard #defines that changes from using two underscores as a prefix, which are reserved, to not using two underscores as a prefix 2013-11-24 20:20:11 +01:00
Adam Dunkels 1ab28e4668 Added missing argument declaration 2013-11-23 15:05:16 +01:00
Adam Dunkels e95236b642 Added header declarations for cc2538_rf_read_rssi() and cc2538_rf_set_promiscous_mode() 2013-11-23 15:05:16 +01:00
Adam Dunkels 76f2a10c9a Added a function for setting promiscous mode on the CC2538 RF core 2013-11-23 15:05:15 +01:00
Adam Dunkels 473d519926 Added a way to obtain the RSSI from the CC2538 RF core 2013-11-23 15:05:15 +01:00
George Oikonomou f13af20f12 Merge pull request #409 from ADVANSEE/cc2538-spi
cc2538: spi: Bug fix and various improvements
2013-11-20 06:51:26 -08:00
Benoît Thébaudeau e8a8870d1d cc2538: spi: Add enable and disable functions
This makes it possible to reduce the power consumption when the SPI is unused.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-20 14:20:50 +01:00
Benoît Thébaudeau b134e35450 cc2538: spi: Add format configuration options
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-20 14:20:43 +01:00
George Oikonomou dc05eea3f5 Merge pull request #426 from ADVANSEE/cc2538-rom
cc2538: Add driver for the rom utility function library
2013-11-19 03:09:16 -08:00
Benoît Thébaudeau 1f1b940cb9 cc2538: Add driver for the rom utility function library
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-18 12:38:06 +01:00
Benoît Thébaudeau 035a30602b cc2538: lpm: Make periph_permit_pm1_funcs static
periph_permit_pm1_funcs[] is a private member of lpm.c, so define it as static.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-18 11:57:59 +01:00
George Oikonomou b10c78f854 Merge pull request #425 from ADVANSEE/cc2538-gpio
cc2538: gpio: Bug fix and various improvements
2013-11-15 13:04:09 -08:00
George Oikonomou 98a1f2dfa9 Merge pull request #408 from ADVANSEE/cc2538-uart
cc2538: lpm: Add registration mechanism for peripherals and use it
2013-11-15 12:57:03 -08:00
Benoît Thébaudeau 680050861c cc2538: gpio: Use accessor macros
Use the GPIO accessor macros instead of copying raw register access code all
over the place. This is cleaner and less error prone.

This fixes the setting of the USB pull-up resistor that worked only by chance on
the CC2538DK because it is controlled by the pin 0 of the used GPIO port.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 19:57:44 +01:00
Benoît Thébaudeau 923f161b7b cc2538: gpio: Add pin read / write and interrupt clear macros
Introduce new useful GPIO macros to:
 - read the levels of some port pins,
 - write the levels of some port pins (pass bit-field value to be set),
 - clear the interrupt flags for some port pins.

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@advansee.com>
2013-11-15 19:48:24 +01:00
Benoît Thébaudeau 300d2d79ae cc2538: gpio: Fix usage of parameters in macros
The parameters in the GPIO macros were used without being parenthesized. This
could generate wrong values for register assignments in the case of expressions
passed as arguments to these macros.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 19:43:06 +01:00
Benoît Thébaudeau b8b54a033c cc2538: uart: Fix crippled output occurring upon lpm_enter()
lpm_enter() must not enter PM1+ if the UART TX FIFO is not empty. Otherwise, the
UART clock gets disabled, and its TX is broken.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 17:24:26 +01:00
Benoît Thébaudeau 0692ee251d cc2538: usb: Use the new LPM peripheral registration
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 17:14:45 +01:00
Benoît Thébaudeau d35732505b cc2538: lpm: Add registration mechanism for peripherals
Some peripherals have their clocks automatically gated in PM1+ modes, so they
cannot operate. This new mechanism gives peripherals a way to prohibit PM1+
modes so that they can properly complete their current operations before
entering PM1+.

This mechanism is implemented with peripheral functions registered to the LPM
module. These functions return whether the associated peripheral permits or not
PM1+ modes. They are called by the LPM module each time PM1+ might be possible.
If any of the peripherals wants to block PM1+, then the system is only dropped
to PM0.

Partly from: George Oikonomou
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 17:09:22 +01:00
George Oikonomou d08a87880c Merge pull request #410 from ADVANSEE/cc2538-sys_ctrl
cc2538: sys_ctrl: Make it possible to use the 32-kHz crystal
2013-11-15 07:42:45 -08:00
Benoît Thébaudeau f1ca1b742c cc2538: spi: Include spi-arch.h before dev/spi.h
spi-arch.h configures dev/spi.h, so it must be #included first. Luckily, this
mistake did not have any consequence here, but fix it in order to avoid possible
future issues.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 15:56:40 +01:00
Benoît Thébaudeau f34731c1a9 cc2538: spi: Do not call SPI_WAITFOREORx() at end of init
If the SSI has never been used and spi_init() is called, then the SSI receive
FIFO is empty and remains so, so calling SPI_WAITFOREORx() at the end of
spi_init() waits endlessly for SSI_SR.RNE to be set. Hence, this call must be
removed in order to avoid a deadlock.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 15:56:40 +01:00
Benoît Thébaudeau 47d570343e cc2538: sys_ctrl: Make it possible to use the 32-kHz crystal
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 15:52:10 +01:00
Benoît Thébaudeau a7d10ce2ad cc2538: Make it possible to use a custom linker script
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-11-15 15:41:58 +01:00