Commit Graph

1182 Commits

Author SHA1 Message Date
George Oikonomou
026864d129 Merge pull request #665 from hexluthor/cc2538-flash-conf
CC2538: Add FLASH_CONF_ORIGIN and FLASH_CONF_SIZE config parameters.
2014-05-18 13:12:49 +02:00
Nicolas Tsiftes
73086e34f7 Merge pull request #632 from nfi/verbosity-control-stm32w
Add support for verbosity control for building STM32W-based platforms
2014-05-07 16:12:12 +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
Oliver Schmidt
5829bc5159 Adjustment to cc65 change. 2014-05-01 21:32:32 +02: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
3183805ba4 Implement extended RF API for the CC2530 RF 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
Nicolas Tsiftes
19cd33664d Merge pull request #633 from nfi/verbosity-control-msp430
Add support for verbosity control for building MSP430-based platforms with the IAR compiler.
2014-04-14 16:38:07 +02:00
George Oikonomou
0ec1eda75e Implement extended RF API for the CC2538 2014-04-14 15:25:30 +02:00
Niclas Finne
f0c48c55ca Fixed STM32W radio to return RADIO_RESULT_INVALID_VALUE if trying to
set a transmission power outside the valid range instead of using
closest valid value.
2014-04-13 21:36:45 +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
George Oikonomou
22554e6d72 Merge pull request #596 from hexluthor/cc2538-uart-baudrate
cc2538: Support any UART baudrate.
2014-04-13 02:51:58 +01:00
Niclas Finne
757950f87f Set the RAM and flash size based on the CPU configuration for STM32W 2014-04-11 17:41:09 +02:00
Niclas Finne
0122373fdc OBJECTDIR is defined by Makefile.include 2014-04-11 17:41:08 +02:00
Niclas Finne
4e7abb09c2 Support verbosity control when building for STM32W-based platforms 2014-04-11 17:41:06 +02:00
Niclas Finne
2c953c3346 Support verbosity control when building MSP430-based platforms with
the IAR compiler.
2014-04-11 17:36:42 +02:00
Niclas Finne
207f1987ee Implemented radio rx mode parameter for STM32W, changed the byte order
of the 64 bit address to big-endian.
2014-04-11 14:46:48 +02:00
Nicolas Tsiftes
1b49b68c3b Merge pull request #606 from atiselsts/master
Fix MCU clock calibration in msp430f2xxx based platforms (e.g. Zolertia Z1)
2014-04-09 21:52:08 +02:00
Niclas Finne
4834816306 Added radio parameter RADIO_PARAM_CCA_THRESHOLD for STM32W 2014-04-08 16:42:18 +02:00
Niclas Finne
441beb8f74 Added stub for extended radio API for rl78 2014-04-03 13:38:28 +02:00
Niclas Finne
2dc4d06078 Added stub for extended radio API for mc1322x 2014-04-03 13:38:26 +02:00
Niclas Finne
14ffa35b3f Added stub for extended radio API for cc253x 2014-04-03 13:38:25 +02:00
Niclas Finne
a98e153e23 Added stub for extended radio API for cc2538 2014-04-03 13:38:23 +02:00
Niclas Finne
1fdb04e10c Added stub for extended radio API for cc2430 2014-04-03 13:38:21 +02:00
Niclas Finne
cb3e053232 Added stub for extended radio API for rf230 2014-04-03 13:38:20 +02:00
Niclas Finne
fa908dcaff Added extended radio API implementation for STM32W 2014-04-03 13:38:09 +02:00
Ian Martin
56d0dfdc7a CC2538: Add a Makefile rule to generate a final assembly listing. 2014-04-02 18:17:49 -04:00
Niclas Finne
767a9aeef1 Use platform configuration for CC2420/CC2520 SFD on MSP430 based platforms 2014-03-28 11:54:10 +01:00
Niclas Finne
279b7fd040 Added rule to autocompile mspsim if needed and show warning if submodule MSPSim has not been initialized 2014-03-28 11:11:51 +01:00
Oliver Schmidt
a630fbd5da Removed unused variable. 2014-03-27 19:24:23 +01:00
Atis Elsts
68b65e6c47 Fix CPU clock calibration in msp430f2xxx based platforms (e.g. Zolertia Z1).
The following problems were present in the existing DCO calibration algorithm:

Problem #1. In function msp430_quick_synch_dco(), the "for(i=0; i < 1000; i++) { .. }" loop is optimized away by the compiler, as i is not volatile. Making i volatile would improve the results, but would not be sufficient: see the next point.

Problem #2. According to MSP430F2617 Device Erratasheet, bug BCL12 precludes a naive implementations of "fast" calibration altogether. The bug is present on all MCU revisions up to date.

The description of the bug:
"After switching RSELx bits (located in register BCSCTL1) from a value of >13 to a value of <12 OR from a value of <12 to a value of >13, the resulting clock delivered by the DCO can stop before the new clock frequency is applied. This dead time is approximately 20 us. In some instances, the DCO may completely stop, requiring a power cycle.

Furthermore, if all of the RSELx bits in the BSCTL1 register are set, modifying the DCOCTL register to change the DCOx or the MODx bits could also result in DCO dead time or DCO hang up."

In Contiki code for msp430f2xxx @ 8MHz, the RSEL search currently typically goes from 15 down to 11, thus violating the rules.

Step-by-step RSEL change is proposed as the best possible workaround:
"[..] more reliable method can be implemented by changing the RSEL bits step by step in order to guarantee safe function without any dead time of the DCO."

Problem #3. The old Contiki code started from the highest possible calibration values: RSEL=15, DCOx=7. According to MSP430F2617
datasheet, this means that the DCO frequency is set to 26 MHz. For one, Vcc under 3V is not supported for this frequency, so this means that battery-powered nodes have a big problem. The minimal operating voltages are:
- 1.8V for RSEL <= 13
- 2.2V for RSEL = 14
- 3.0V for RSEL = 15
So the correct way is to always start calibration from RSEL <= 13, unless explicityly pre-calibred values are present.

Problem #4. Timer B should be turned off after the calibration, following the "Principles for Low-Power Applications" in MSP430 user's Guide.

The patch fixes these issues by performing step-by-step calibration and turning off Timer B afterwards. As opposed to MSP430F1xxx calibration, this algorithm does not change the ACLK divider beforehand; attempts to make calibration more precise would lead to looping in some cases, as the calibration step granularity at larger frequencies is quite big.

Additionally, the patch improves DCOSYNCH_CONF_ENABLED behavior, allowing the resynchronization to correct for more than one step.
2014-03-25 11:47:13 +01: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
Oliver Schmidt
370650baa3 Updated cc65 URL. 2014-03-15 16:55:39 +01: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
Oliver Schmidt
b6c9950b94 Adjust shadow register to full 8kB RX buffer. 2014-02-27 20:23:41 +01:00
Oliver Schmidt
3e5e054f2a Adjusted base address to final product. 2014-02-26 20:23:09 +01:00
LudovicW
d979e5b096 CC2538: add support for UART baudrate 9600, 38400 and 57600 2014-02-11 16:01:36 +01:00
Oliver Schmidt
9a44bafb16 Merge pull request #553 from oliverschmidt/master
Some fine tuning after the recent general modularization.
2014-02-02 11:14:17 -08:00
Oliver Schmidt
ee3050897a Some fine tuning after the recent general modularization. 2014-02-02 17:59:06 +01:00
Oliver Schmidt
4db675e259 Some fine tuning after the recent general modularization. 2014-02-02 17:47:17 +01:00
Oliver Schmidt
e16521e5c1 Merge pull request #550 from oliverschmidt/master
Avoid compiler warnings.
2014-01-31 16:22:53 -08:00
Oliver Schmidt
a94e7e63e2 Avoid compiler warnings. 2014-02-01 00:46:57 +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
824d2047da Add the explicit list of modules, since we cannot do auto-dependency management of them 2014-01-26 23:20:47 +01:00
Adam Dunkels
a40a73db9a Made a module out of the core/ctk code 2014-01-26 23:20:44 +01:00
Adam Dunkels
dee654cfe5 Put the cc253x custom makerules in its own customrules file 2014-01-26 23:20:41 +01:00
Adam Dunkels
7846eb2e2f Split the cc2430 custom rules into its own file 2014-01-26 23:20:40 +01:00
Adam Dunkels
36a5aadc9e Moved the 6502 custom rules into its own Makefile.customrules-6502 file 2014-01-26 23:20:40 +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
Adam Dunkels
c9efe3c3c4 Moved the cc2520 driver into its own dev/cc2520 module 2014-01-26 23:20:31 +01:00
Adam Dunkels
0b805e4763 Moved the cc2420 driver into a separate dev/cc2420 module 2014-01-26 23:20:27 +01:00
Adam Dunkels
5f3fe7f7c7 Updated include paths for the moved files under net/ 2014-01-26 23:20:23 +01:00
Ian Martin
935322665e rl78: Attempt to locate the IAR installation automatically and instruct the user how to specify IAR_PATH if it cannot be found. 2014-01-24 12:50:43 -05:00
Ian Martin
ffa0147920 rl78: Rename CORE to RL78_CORE to avoid a conflict with Contiki's CORE variable. 2014-01-24 11:49:47 -05:00
Oliver Schmidt
8baf2d7b42 Merge pull request #536 from oliverschmidt/master
Copied 'contiki_arg[c|v]' from 'native' to the other desktop targets.
2014-01-24 03:41:42 -08:00
Oliver Schmidt
fc983e2e79 Copied 'contiki_arg[c|v]' from 'native' to the other desktop targets.
- On the retro targets support for 'contiki_arg[c|v]' is optional as accesing arg[c|v] is rather expensive.
2014-01-24 11:56:40 +01:00
Ian Martin
1b61f1bb7b Add cpu/rl78/dev/uart1.h because some examples rely on it. 2014-01-22 18:42:24 -05:00
Ian Martin
a897426410 Increase the default baudrate to 38400 bps for RL78. 2014-01-22 18:42:18 -05:00
Ian Martin
00468a3f53 Fix buggy UART baudrate calculation in the RL78 UART driver. 2014-01-22 18:41:55 -05:00
Oliver Schmidt
510678bed0 Added mouse support for the Atari. 2014-01-20 22:51:40 +01:00
Oliver Schmidt
a24865de72 Add somewhat more support to use different mouse drivers.
- The default mouse driver is now always named 'contiki.mou'.
- Alternative mouse drivers are present in the disk images.
- Users can select their mouse driver by renaming the files.
2014-01-17 23:45:59 +01:00
Oliver Schmidt
fb20cf5ee6 Added UIP_CONF_LLH_LEN. 2014-01-17 22:07:03 +01:00
Ian Martin
7d3053bbc5 Remove hyphen from preprocessor symbol to fix compiler warning. 2014-01-10 16:31:05 -05:00
Benoît Thébaudeau
7f48057b9e leds: Fix the API
The leds API did not work in some cases. E.g. with the following sequence:
  leds_off(LEDS_ALL);
  leds_toggle(LEDS_GREEN);
  leds_off(LEDS_ALL);
the green LED was remaining on after the last call.

This was caused by the toggle feature made synonymous with the invert feature,
although it is unrelated. leds_toggle() is indeed supposed to toggle an LED,
while leds_invert() is supposed to change the active level of an LED. However,
all users of leds_invert() actually meant leds_toggle(), and the invert feature
does not make sense in this module because it is not handy due to successive
calls to leds_invert() changing the intended behavior, and hardware active
levels should be managed in leds_arch_set() (e.g. by XORing the passed value
with a hardware-specific constant before setting the output levels of the pins).

Consequently, this change:
 - removes the leds_invert() function,
 - makes leds_toggle() behave as expected relatively to leds_off() / leds_on(),
 - sanitizes the code in the leds module.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2014-01-07 13:02:41 +01:00
Ian Martin
174d4dd80c Adds support for ADF7023 sub-GHz radio from Analog Devices and RL78 series MCU from Renesas.
This example platform for this port is the EVAL-ADF7XXXMB4Z w/ radio
daughter cards:

    http://www.analog.com/en/evaluation/eval-adf7023/eb.html

See the platform readme for usage and platform information:

    https://github.com/contiki-os/contiki/tree/master/platform/eval-adf7xxxmb4z/readme.md

All files provided by Analog Devices for this port are released under
the same license as Contiki and copyright Analog Devices Inc. per
agreement between Redwire Consulting, LLC and Analog Devices Inc. (SOW 08122013)
2014-01-04 18:56:51 -05:00
Ian Martin
e90af44ca7 Merge ADF7023 driver from https://github.com/analogdevicesinc/no-OS 2014-01-04 17:38:26 -05:00
Ian Martin
6d36c83513 Merge SPI driver from https://github.com/analogdevicesinc/no-OS 2014-01-04 17:38:26 -05:00
Ian Martin
6a88905f9d Merge UART driver from https://github.com/msalov/rl78-samples-R5F100SLAFB 2014-01-04 17:38:26 -05:00
Ian Martin
d0abf415e7 Merge RL78 files from https://sourceware.org/git/?p=newlib.git 2014-01-04 17:38:26 -05:00
Dragos Bogdan
cfd554dc24 Move files. 2014-01-04 17:27:52 -05:00
Dragos Bogdan
94d5d384e0 Move files. 2014-01-04 17:27:29 -05:00
Maxim Salov
2668b17f52 Move files. 2014-01-04 17:27:24 -05:00
DJ Delorie
5115554247 Move/rename files. 2014-01-04 17:27:23 -05: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
Oliver Schmidt
63725eff36 Merge remote-tracking branch 'upstream/master' 2013-12-12 20:46:43 +01:00
Oliver Schmidt
3b2173e01f Have CBM DOS filetype of imported files match the one used by cc65.
CFS_WRITE implies O_TRUNC which is implemented on CBM DOS by deleting an
exsisting file. Hoewever this succeeds only if the CBM DOS filetype matches.

We need a working O_TRUNC in order to be able to overwrite the contiki.cfg
configuration file.

Note: Now it has be clarified why overwriting the configuration file started to
fail the CBM PFS (platform file system) can be activated for the recently added
ethconfig program.
2013-12-12 18:57:40 +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