Squashed commit of the following:

commit 66e87f9bb3ef75fddf25400bc08475c5e6ad4c30
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Wed Jul 26 15:19:56 2017 -0600

    Spirit:  Brings in last of PktBasic logic.

commit 8b4c89d6a103003fa04363e2c2ae7b9ee390bf49
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Wed Jul 26 11:55:50 2017 -0600

    Spirit:  Bring in AES and MBUS logic.

commit d00022d39ab0ce839de29386949481e5c24feff3
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Wed Jul 26 09:22:03 2017 -0600

    Spirit:  Bring in remainder of calibration interfaces.

commit 40b4b2f902e04293f8940551a97a9a24a48988dd
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Wed Jul 26 08:44:32 2017 -0600

    Spirit:  Bring in DirectRF interfaces.

commit 7c109608e1a2989f3edbc2fd939a2d225fff382a
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Wed Jul 26 07:46:19 2017 -0600

    Spirit: Add CSMA support.

commit 0f88896595d162c4ac6138e7b1af2fc35c865b3d
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 18:57:43 2017 -0600

    Spirit:  Add some initial TX logic to network driver.

commit 4dc7058dfcdcf40980578680b7e1a4206dea4ea2
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 17:02:11 2017 -0600

    Spirit: Completes ports of spirit_management.* files

commit c904eef51d929e041b87d0c8aff6fa3c2f895341
Merge: 91e985a877 c9ff8cbab9
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 15:15:04 2017 -0600

    Merge remote-tracking branch 'origin/master' into spirit

commit 91e985a87729017a66d19276c4d47681064f95ea
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 15:13:54 2017 -0600

    Spirit:  Add a few more functions that will soon be needed for packet transmission.

commit b5981d29983907c2194fbc26af4b72ad532bee78
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 13:30:07 2017 -0600

    Spirit:  Finish off some initialization issues; Started some interrupt handling logic.

commit c21073e0bc2870b3d9ba40bdfdfd5151ce4f5890
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 09:35:52 2017 -0600

    Spirit:  Completes very basic radio initialization for network driver

commit 1b544334361c54f46bcf0ba313c125932e8dafc6
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Tue Jul 25 07:58:30 2017 -0600

    Spirit: Add more radio initialization logic... getting closer.

commit 45d1047db60843c57d394ec910c63e7c127671e0
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 19:15:33 2017 -0600

    Spirit: add some CSMA initialization logic

commit bcf55c71336d48947fe19bb09a799169852301c2
Merge: 89e9d426e9 2fc0fbcf7e
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 16:47:11 2017 -0600

    Merge remote-tracking branch 'origin/master' into spirit

commit 89e9d426e91c056e659fccf5e5c4392618f8f777
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 16:44:19 2017 -0600

    Update some comments

commit 9c5d8a5833350006ed389e898b11c8c8a20e5f4f
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 16:15:54 2017 -0600

    Spirit:  Rename drivers/wireless/spirit/src to lib.  Move Spirit network driver out of IEEE802.15.4 into drivers/wireless/spirit/drivers

commit cabc0ec9e6eb558dcb715ab17264383aa0105e7a
Merge: 87b616414a 6bd744c4b3
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 15:38:40 2017 -0600

    Merge remote-tracking branch 'origin/master' into spirit

commit 87b616414a79c01a71acea78f8258e05325c1996
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 15:37:27 2017 -0600

    Spirit radio driver is mutating into a standalone network driver.

commit 507798233868a661ae8adad3e3aa117075a7a146
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 13:32:08 2017 -0600

    Spirit: More radio initialization logic

commit 33af25704ce9ca83d576300d153cfe31cc6d2576
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 12:19:14 2017 -0600

    Spirit:  Beginning of radio initialization logic

commit 97b20014c016e55952a8f9d8f4ae29e2cc555b23
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Mon Jul 24 09:42:06 2017 -0600

    Spirit: More initialization logic.

commit 295d8e27824c0417fccea2344b30bb5c93ffbabe
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sun Jul 23 15:39:53 2017 -0600

    Spirit:  Add header file containing enumeration of commands.

commit 8a2d9dd8eb9cc70cbcdd1b913fc9022b9c9ec8da
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sun Jul 23 11:33:50 2017 -0600

    Spirit:  Add GPIO initialization logic

commit 8b6d80c44f92024c45a6ba63ba1af3fdafe94dc3
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sun Jul 23 10:07:25 2017 -0600

    Spirit:  Add interrupt control logic.

commit 423f846fe5c914f92a4bfea4d9d1fa33de1c77a5
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 19:06:52 2017 -0600

    Spirit: Yet a little more radio initialization logic.

commit 5895b979823e51ddde5ad52e6de66a8ad662e883
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 15:36:05 2017 -0600

    Spirit: A little more radio initialization logic.

commit 86311ab30aad386203c181c792847dd1d37f9a02
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 13:02:32 2017 -0600

    Spirit: A miniscule amount of radio initialization logic.

commit ad55e89d5ee12ea1eeea95fcd38ff3da0db4416a
Merge: 90a7666655 f4e46b0da7
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 10:56:30 2017 -0600

    Merge remote-tracking branch 'origin/master' into spirit

commit 90a766665534b05da0157dbc383cb06a98c86a79
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 10:52:52 2017 -0600

    Spirit1:  A few fixes for a clean build of initial configuration (not much there yet)

commit bbbf04c223230a52a7705a2161128265cfbaa480
Merge: 623d54a7f7 2319ea53a9
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 09:53:57 2017 -0600

    Merge remote-tracking branch 'origin/master' into spirit

commit 623d54a7f719e9032099f88f38203efee4b80722
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 09:43:52 2017 -0600

    b-l475e-iot01a: Add a configuration for testing sprit radio.

commit d309d73d9f4665f9d870eb03531f450043d9389d
Merge: 52c3ddfae6 d88dc9b2e5
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 09:02:06 2017 -0600

    Merge remote-tracking branch 'origin/master' into spirit

commit 52c3ddfae6802e111c2b5cf1207baf21a61dd00b
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Sat Jul 22 08:33:04 2017 -0600

    Spirit:  Add register definition header file.

commit 8d842ab5e8f9ca653b42f9ee88dc279f06b4fa98
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Fri Jul 21 17:27:03 2017 -0600

    b-l475e-iot01a: Add initial, unverified support for the SPSRGF/Spirit1 module.

commit 73d902a1048616fb9c2dd2147cabcd8ee78e19ac
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Fri Jul 21 15:49:43 2017 -0600

    Spirit: Fixes to get skeleton IEEE 802.15.4 driver build.

commit ebc5a8387bb94f0cc3827533795f3e4a33207e67
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Fri Jul 21 15:16:29 2017 -0600

    Spirit1:  Add framework for IEEE 802.15.4 driver.  Does not yet build.

commit 52e195a7ae14ddb18bdd56258f4877381d2501ca
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Fri Jul 21 14:02:42 2017 -0600

    Spirit:  A little more SPI logic.

commit 90048d0c5b8a5af4d81a15d99535c84ed38d8ae9
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Fri Jul 21 11:19:06 2017 -0600

    Spirit: Build directories setup.  Some initial files added, mostly just to verify build.

commit 8273a381ac1f6bb081b292b5e73226185e9e634c
Author: Gregory Nutt <gnutt@nuttx.org>
Date:   Fri Jul 21 08:34:04 2017 -0600

    USB composite:  Remove references to CDC/ACM and USB MSC from composite logic.  They are no longer coupled.
This commit is contained in:
Gregory Nutt 2017-07-26 15:35:42 -06:00
parent c9ff8cbab9
commit 598386ef90
31 changed files with 4685 additions and 234 deletions

View file

@ -39,5 +39,6 @@ ifeq ($(CONFIG_WL_SPIRIT),y)
include wireless$(DELIM)spirit$(DELIM)lib$(DELIM)Make.defs
include wireless$(DELIM)spirit$(DELIM)include$(DELIM)Make.defs
include wireless$(DELIM)spirit$(DELIM)drivers$(DELIM)Make.defs
endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,285 @@
/*******************************************************************************
* include/nuttx/wireless/spirit/include/spirit_aes.h
* Configuration and management of SPIRIT AES Engine.
*
* Copyright(c) 2015 STMicroelectronics
* Author: VMA division - AMS
* Version 3.2.2 08-July-2015
*
* Adapted for NuttX by:
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_AES_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_AES_H
/* In order to encrypt data, the user must manage the AES_END IRQ. The data
* must be split in blocks of 16 bytes and written into the AES DATA IN
* registers. Then, after the key is written into the AES KEY registers, a
* command of Execute encryption has to be sent.
*
* Example:
*
* spirit_aes_write_datain(spirit, inbuffer , buflen);
* spirit_aes_encrypt(spirit);
*
* Wait for encryption done (signalled via interrupt)
*
* spirit_aes_read_dataout(espirit, outbuffer , buflen);
*
* In order to decrypt data, the user must manage the AES_END IRQ and have a
* decryption key. There are two operative modes to make the data
* decryption:
*
* 1. Derive the decryption key from the encryption key and decrypt data
* directly using the spirit_aes_derivekey_decrypt() function
*
* Example:
*
* spirit_aes_write_datain(spirit, inbuffer , buflen);
* spirit_aes_derivekey_decrypt(spirit);
*
* Wait for key derivation to complete (signalled via interrupt)
*
* spirit_aes_read_dataout(spirit, outbuffer , buflen);
*
* 2 Derive the decryption key from the encryption key using the
* spirit_aes_enc2deckey() function, store it into the AES KEY
* registers and then decrypt data using the spirit_aes_decrypt()
* function
*
* Example:
*
* spirit_aes_write_datain(spirit, keyenc, 16);
* spirit_aes_enc2deckey(spirit);
*
* Wait for key derivation to complete (signalled via interrupt)
*
* spirit_aes_read_dataout(spirit, keydec, 16);
*
* spirit_aes_write_key(key_dec);
* spirit_aes_write_datain(inbuffer , 16);
* spirit_aes_decrypt(spirit);
*
* Wait for encryption done (signalled via interrupt)
*
* spirit_aes_read_dataout(spirit, outbuffer, buflen);
*/
/******************************************************************************
* Included Files
******************************************************************************/
#include "spirit_regs.h"
#include "spirit_types.h"
/******************************************************************************
* Public Function Prototypes
******************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************
* Name: spirit_aes_enable
*
* Description:
* Enables or Disables the AES engine.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate new state for AES engine.
* This parameter can be: S_ENABLE or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_enable(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name:
*
* Description:
* Writes the data to encrypt or decrypt, or the encryption key for the
* derive decryption key operation into the AES_DATA_IN registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* buffer - Pointer to the user data buffer. The first byte of the array
* must be the MSB byte and it will be put in the AES_DATA_IN[0]
* register, while the last one must be the LSB and it will be
* put in the AES_DATA_IN[buflen-1] register. If data to write
* are less than 16 bytes the remaining AES_DATA_IN registers
* will be filled with bytes equal to 0.
* buflen - Length of data in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_write_datain(FAR struct spirit_library_s *spirit,
FAR const uint8_t *buffer, uint8_t buflen);
/******************************************************************************
* Name:
*
* Description:
* Returns the encrypted or decrypted data or the decription key from the
* AES_DATA_OUT register.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* buffer - pointer to the user data buffer. The AES_DATA_OUT[0]
* register value will be put as first element of the buffer
* (MSB), while the AES_DAT_OUT[buflen-1] register value will be
* put as last element of the buffer (LSB).
* buflen - Length of data to read in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_read_dataout(FAR struct spirit_library_s *spirit,
FAR uint8_t *buffer, uint8_t buflen);
/******************************************************************************
* Name: spirit_aes_write_key
*
* Description:
* Writes the encryption key into the AES_KEY_IN register.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* key - Pointer to the buffer of 4 words containing the AES key.
* The first byte of the buffer must be the most significant byte
* AES_KEY_0 of the AES key. The last byte of the buffer must be
* the less significant byte AES_KEY_15 of the AES key.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_write_key(FAR struct spirit_library_s *spirit,
FAR const uint8_t *key);
/******************************************************************************
* Name:
*
* Description:
* Returns the encryption/decryption key from the AES_KEY_IN register.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* key pointer to the buffer of 4 words (16 bytes) containing the AES key.
* The first byte of the buffer shall be the most significant byte AES_KEY_0 of the AES key.
* The last byte of the buffer shall be the less significant byte AES_KEY_15 of the AES key.
* This parameter is an uint8_t*.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_read_key(FAR struct spirit_library_s *spirit, FAR uint8_t *key);
/******************************************************************************
* Name: spirit_aes_enc2deckey
*
* Description:
* Derives the decryption key from a given encryption key.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_enc2deckey(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_aes_encrypt
*
* Description:
* Executes the encryption operation.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_encrypt(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name:
*
* Description:
* Executes the decryption operation.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_decrypt(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_aes_derivekey_decrypt
*
* Description:
* Executes the key derivation and the decryption operation.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_derivekey_decrypt(FAR struct spirit_library_s *spirit);
#ifdef __cplusplus
}
#endif
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_AES_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_calibration.h
* include/nuttx/wireless/spirit/include/spirit_calibration.h
* Configuration and management of SPIRIT VCO-RCO calibration.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,38 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_CALIBRAITON_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_CALIBRAITON_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_CALIBRAITON_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_CALIBRAITON_H
/* This module allows the user to set some parameters which deal with the
* oscillators calibration. The state machine of Spirit contemplates some
* optional calibrating operations in the transition between the READY and
* the LOCK state. The user is allowed to enable or disable the automatic
* RCO/VCO calibration by calling the functions spirit_calib_enable_vco()
* spirit_calib_enable_rco().
*
* The following example shows how to do an initial calibration of VCO.
*
* Example:
*
* uint8_t caldata;
*
* spirit_calib_enable_vco(spirit, S_ENABLE);
* spirit_command(spirit, CMD_LOCKTX);
*
* while(spirit->state.MC_STATE != MC_STATE_LOCK)
* {
* (void)spirit_update_status(spirit);
* }
*
* caldata = spirit_calib_get_vcotxcal(spirit);
* spirit_calib_set_vcotxcal(spirit, caldata);
*
* spirit_command(spirit, CMD_READY);
* spirit_calib_enable_vco(spirit, S_DISABLE);
*
* Similar operations can be done for the RCO calibrator.
*/
/******************************************************************************
* Included Files
@ -50,7 +80,13 @@
/* Macros used in assertions */
#define IS_VCO_SEL(ref) ((ref) == VCO_L || (ref) == VCO_H)
#define IS_VCO_SEL(ref) \
((ref) == VCO_L || (ref) == VCO_H)
#define IS_VCO_WIN(ref) \
((ref) == CALIB_TIME_7_33_US_24MHZ || (ref) == CALIB_TIME_14_67_US_24MHZ ||\
(ref) == CALIB_TIME_29_33_US_24MHZ || (ref) == CALIB_TIME_58_67_US_24MHZ ||\
(ref) == CALIB_TIME_6_77_US_26MHZ || (ref) == CALIB_TIME_13_54_US_26MHZ ||\
(ref) == CALIB_TIME_27_08_US_26MHZ || (ref) == CALIB_TIME_54_15_US_26MHZ)
/******************************************************************************
* Public Types
@ -60,8 +96,32 @@
enum spirit_vcoselect_e
{
VCO_L = 0, /* VCO lower */
VCO_H /* VCO higher */
VCO_L = 0, /* VCO lower */
VCO_H /* VCO higher */
};
/* VCO / RCO calibration window. */
enum spirit_vcowin_e
{
CALIB_TIME_7_33_US_24MHZ = 0x00, /* Calibration window of 7.33 us
* with XTAL=24MHz */
CALIB_TIME_14_67_US_24MHZ, /* Calibration window of 14.67 us
* with XTAL=24MHz */
CALIB_TIME_29_33_US_24MHZ, /* Calibration window of 29.33 us
* with XTAL=24MHz */
CALIB_TIME_58_67_US_24MHZ, /* Calibration window of 58.67 us
* with XTAL=24MHz */
CALIB_TIME_6_77_US_26MHZ = 0x00, /* Calibration window of 6.77 us
* with XTAL=26MHz */
CALIB_TIME_13_54_US_26MHZ, /* Calibration window of 13.54 us
* with XTAL=26MHz */
CALIB_TIME_27_08_US_26MHZ, /* Calibration window of 27.08 us
* with XTAL=26MHz */
CALIB_TIME_54_15_US_26MHZ /* Dalibration window of 54.15 us with
* XTAL=26MHz */
};
/******************************************************************************
@ -106,6 +166,46 @@ int spirit_calib_enable_rco(FAR struct spirit_library_s *spirit,
int spirit_calib_enable_vco(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name: spirit_calibration_set_rcocal
*
* Description:
* Sets the RCO calibration words.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* rwt - RWT word for RCO calibration.
* rfb - RFB word for RCO calibration.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_calibration_set_rcocal(FAR struct spirit_library_s *spirit,
uint8_t rwt, uint8_t rfb);
/******************************************************************************
* Name: spirit_calibration_get_rcocal
*
* Description:
* Returns the RCO calibration words.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* rwt - Pointer to the variable in which the RWT word has to be
* stored.
* rfb - Pointer to the variable in which the RFB word has to be
* stored.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_calibration_get_rcocal(FAR struct spirit_library_s *spirit,
FAR uint8_t *rwt, FAR uint8_t *rfb);
/******************************************************************************
* Name: spirit_calib_get_vcocal
*
@ -190,6 +290,51 @@ int spirit_calib_set_vcorxcal(FAR struct spirit_library_s *spirit,
uint8_t spirit_calib_get_vcorxcal(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_calibration_set_vcowin
*
* Description:
* Sets the VCO calibration window.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* refword - Value of REFWORD corresponding to the Ref_period according to
* the formula:
*
* CALIBRATION_WIN = 11*Ref_period/fxo.
*
* This parameter can be a value of enum spirit_vcowin_e.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_calibration_set_vcowin(FAR struct spirit_library_s *spirit,
enum spirit_vcowin_e refword);
/******************************************************************************
* Name: spirit_calibration_get_vcowin
*
* Description:
* Returns the VCO calibration window.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Value of REFWORD corresponding to the Ref_period according to the
* formula:
*
* CALIBRATION_WIN = 11*Ref_period/fxo.
*
* This parameter can be a value of enum spirit_vcowin_e.
*
******************************************************************************/
enum spirit_vcowin_e
spirit_calibration_get_vcowin(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_calib_select_vco
*
@ -224,4 +369,4 @@ int spirit_calib_select_vco(FAR struct spirit_library_s *spirit,
enum spirit_vcoselect_e spirit_calib_get_vco(FAR struct spirit_library_s *spirit);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_CALIBRAITON_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_CALIBRAITON_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_commands.h
* include/nuttx/wireless/spirit/include/spirit_commands.h
* Management of SPIRIT Commands.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_COMMANDS_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_COMMANDS_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_COMMANDS_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_COMMANDS_H
/* In this module can be found all the API used to strobe commands to
* Spirit. Every command strobe is an SPI transaction with a specific command
@ -144,4 +144,4 @@ enum spirit_cmd_e
}
#endif
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_COMMANDS_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_COMMANDS_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_config.h
* include/nuttx/wireless/spirit/include/spirit_config.h
* Spirit Configuration and useful defines
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_CONFIG_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_CONFIG_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_CONFIG_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_CONFIG_H
/******************************************************************************
* Included Files
@ -43,4 +43,4 @@
#define DOUBLE_XTAL_THR 30000000
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_CONFIG_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_CONFIG_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_csma.h
* include/nuttx/wireless/spirit/include/spirit_csma.h
* Configuration and management of SPIRIT CSMA.
*
* Copyright(c) 2015 STMicroelectronics
@ -165,6 +165,330 @@ struct spirit_csma_init_s
* Public Function Prototypes
******************************************************************************/
/******************************************************************************
* Name: spirit_csma_initialize
*
* Description:
* Initializes the SPIRIT CSMA according to the specified parameters in the
* struct spirit_csma_init_s.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* csmainit - Reference to the Csma init structure.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_initialize(FAR struct spirit_library_s *spirit,
FAR const struct spirit_csma_init_s *csmainit);
/******************************************************************************
* Name: spirit_csma_getinfo
*
* Description:
* Returns the fitted structure struct spirit_csma_init_s starting from the
* registers values.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* csmainit - Csma structure to be fitted.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_getinfo(FAR struct spirit_library_s *spirit,
FAR struct spirit_csma_init_s *csmainit);
/******************************************************************************
* Name: spirit_csma_enable
*
* Description:
* Enables or Disables the CSMA.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - The state of the CSMA mode. This parameter can be: S_ENABLE
* or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_enable(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name: spirit_csma_getstate
*
* Description:
* Gets the CSMA mode. Says if it is enabled or disabled.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CSMA mode.
*
******************************************************************************/
enum spirit_functional_state_e
spirit_csma_getstate(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_persistentmode
*
* Description:
* Enables or Disables the persistent CSMA mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - The state of the persistent CSMA mode. This parameter can
* be: S_ENABLE or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_persistentmode(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name: spirit_csma_get_persistentmode
*
* Description:
* Gets the persistent CSMA mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CSMA persistent mode.
*
******************************************************************************/
enum spirit_functional_state_e
spirit_csma_get_persistentmode(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_seedreload
*
* Description:
* Enables or Disables the seed reload mode (if enabled it reloads the back-
* off generator seed using the value written in the BU_COUNTER_SEED register).
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - The state of the seed reload mode. This parameter can be:
* S_ENABLE or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_seedreload(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name: spirit_csma_get_seedreload
*
* Description:
* Gets the seed reload state.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CSMA seed reload mode.
*
******************************************************************************/
enum spirit_functional_state_e
spirit_csma_get_seedreload(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_bucounterseed
*
* Description:
* Sets the BU counter seed (BU_COUNTER_SEED register). The CSMA back off
* time is given by the formula: BO = rand(2^NB)*BU.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* seed - Seed of the random number generator used to apply the BBE
* algorithm.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_bucounterseed(FAR struct spirit_library_s *spirit,
uint16_t seed);
/******************************************************************************
* Name: spirit_csma_get_bucounterseed
*
* Description:
* Returns the BU counter seed (BU_COUNTER_SEED register).
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Seed of the random number generator used to apply the BBE algorithm.
*
******************************************************************************/
uint16_t spirit_csma_get_bucounterseed(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_buprescaler
*
* Description:
* Sets the BU prescaler. The CSMA back off time is given by the formula:
* BO = rand(2^NB)*BU.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* prescaler - Used to program the back-off unit BU.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_buprescaler(FAR struct spirit_library_s *spirit,
uint8_t prescaler);
/******************************************************************************
* Name: spirit_csma_get_buprescaler
*
* Description:
* Returns the BU prescaler.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Value back-off unit (BU).
*
******************************************************************************/
uint8_t spirit_csma_get_buprescaler(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_ccaperiod
*
* Description:
* Sets the CCA period.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* multbit - Value of CCA period to store. This parameter can be a value
* of enum spirit_cca_period_e.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_ccaperiod(FAR struct spirit_library_s *spirit,
enum spirit_cca_period_e multbit);
/******************************************************************************
* Name: spirit_csma_get_ccaperiod
*
* Description:
* Returns the CCA period.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CCA period.
*
******************************************************************************/
enum spirit_cca_period_e
spirit_csma_get_ccaperiod(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_ccalen
*
* Description:
* Sets the CCA length.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* ccalen - The CCA length (a value between 1 and 15 that multiplies the
* CCA period). This parameter can be any value of enum
* spirit_csmalen_e.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_ccalen(FAR struct spirit_library_s *spirit,
enum spirit_csmalen_e ccalen);
/******************************************************************************
* Name: spirit_csma_get_ccalen
*
* Description:
* Returns the CCA length.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CCA length.
*
******************************************************************************/
uint8_t spirit_csma_get_ccalen(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_csma_set_maxbackoff
*
* Description:
* Sets the max number of back-off. If reached Spirit stops the transmission.
*
* Input Parameters:
* maxnb the max number of back-off.
* This parameter is an uint8_t.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_maxbackoff(FAR struct spirit_library_s *spirit,
uint8_t maxnb);
/******************************************************************************
* Name: spirit_csma_get_maxbackoff
*
* Description:
* Returns the max number of back-off.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Max number of back-off.
*
******************************************************************************/
uint8_t spirit_csma_get_maxbackoff(FAR struct spirit_library_s *spirit);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,182 @@
/******************************************************************************
* include/nuttx/wireless/spirit/include/spirit_directrf.h
* Configuration and management of SPIRIT direct transmission / receive modes.
*
* Copyright(c) 2015 STMicroelectronics
* Author: VMA division - AMS
* Version 3.2.2 08-July-2015
*
* Adapted for NuttX by:
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_DIRECTRF_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_DIRECTRF_H
/* This module contains functions to manage the direct Tx/Rx mode.
* The user can choose the way to send data to Spirit through the
* enumerative types DirectTx/DirectRx.
*/
/******************************************************************************
* Included Files
******************************************************************************/
#include "spirit_regs.h"
#include "spirit_types.h"
/******************************************************************************
* Pre-processor Definitions
******************************************************************************/
/* Macros used for range-checking in assertions */
#define IS_DIRECT_TX(mode) \
(((mode) == NORMAL_TX_MODE) || ((mode) == DIRECT_TX_FIFO_MODE) || \
((mode) == DIRECT_TX_GPIO_MODE) || ((mode) == PN9_TX_MODE))
#define IS_DIRECT_RX(mode) \
(((mode) == NORMAL_RX_MODE) || ((mode) == DIRECT_RX_FIFO_MODE) || \
((mode) == DIRECT_RX_GPIO_MODE))
/******************************************************************************
* Public Types
******************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/* Direct transmission mode enumeration for SPIRIT. */
enum spirit_directtx_e
{
NORMAL_TX_MODE = 0x00, /* Normal mode, no direct transmission is
* used */
DIRECT_TX_FIFO_MODE = 0x04, /* Source is FIFO: payload bits are
* continuously read from the TX FIFO */
DIRECT_TX_GPIO_MODE = 0x08, /* Source is GPIO: payload bits are
* continuously read from one of the GPIO
* ports and transmitted without any
* processing */
PN9_TX_MODE = 0x0c /* A pseudorandom binary sequence is
* generated internally */
};
/* Direct receive mode enumeration for SPIRIT. */
enum spirit_directrx_e
{
NORMAL_RX_MODE = 0x00, /* Normal mode, no direct reception is used */
DIRECT_RX_FIFO_MODE = 0x10, /* Destination is FIFO: payload bits are
* continuously written to the RX FIFO and
* not subjected to any* processing */
DIRECT_RX_GPIO_MODE = 0x20 /* Destination is GPIO: payload bits are
* continuously written to one of the GPIO
* ports and not subjected to any processing */
};
/******************************************************************************
* Public Function Prototypes
******************************************************************************/
/******************************************************************************
* Name: spirit_directrf_set_rxmode
*
* Description:
* Sets the DirectRF RX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* directrx - Code of the desired mode.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_directrf_set_rxmode(FAR struct spirit_library_s *spirit,
enum spirit_directrx_e directrx);
/******************************************************************************
* Name:
*
* Description:
* Returns the DirectRF RX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Direct Rx mode.
*
******************************************************************************/
enum spirit_directrx_e
spirit_directrf_get_rxmode(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name:
*
* Description:
* Sets the TX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* directtx - Code of the desired source.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_directrf_set_txmode(FAR struct spirit_library_s *spirit,
enum spirit_directtx_e directtx);
/******************************************************************************
* Name:
*
* Description:
* Returns the DirectRF TX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Direct Tx mode.
*
******************************************************************************/
enum spirit_directtx_e
spirit_directrf_get_txmode(FAR struct spirit_library_s *spirit);
#ifdef __cplusplus
}
#endif
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_DIRECTRF_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_general.h
* include/nuttx/wireless/spirit/include/spirit_general.h
* Configuration and management of SPIRIT General functionalities.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GENERAL_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GENERAL_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GENERAL_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GENERAL_H
/******************************************************************************
* Included Files
@ -132,4 +132,4 @@ enum spirit_version_e
*
******************************************************************************/
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GENERAL_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GENERAL_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_gpio.h
* include/nuttx/wireless/spirit/include/spirit_gpio.h
* This file provides all the low level API to manage SPIRIT GPIO.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GPIO_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GPIO_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GPIO_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GPIO_H
/******************************************************************************
* Included Files
@ -235,4 +235,4 @@ struct spirit_gpio_init_s
int spirit_gpio_initialize(FAR struct spirit_library_s *spirit,
FAR const struct spirit_gpio_init_s *gpioinit);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GPIO_H*/
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GPIO_H*/

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_irq.h
* include/nuttx/wireless/spirit/include/spirit_irq.h
* Configuration and management of SPIRIT IRQs.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_IRQ_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_IRQ_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_IRQ_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_IRQ_H
/* On the Spirit side specific IRQs can be enabled by setting a specific bitmask.
* The Spirit libraries allow the user to do this in two different ways:
@ -452,4 +452,4 @@ bool spirit_irq_is_pending(FAR struct spirit_library_s *spirit,
}
#endif
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_IRQ_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_IRQ_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_Linearfifo.h
* include/nuttx/wireless/spirit/include/spirit_Linearfifo.h
* Configuration and management of SPIRIT Fifo.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_FIFO_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_FIFO_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_FIFO_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_FIFO_H
/******************************************************************************
* Included Files
@ -257,4 +257,4 @@ uint8_t spirit_fifo_get_txalmostempty(FAR struct spirit_library_s *spirit);
}
#endif
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_FIFO_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_FIFO_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_management.h
* include/nuttx/wireless/spirit/include/spirit_management.h
* The management layer for SPIRIT1 library.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_MANAGEMENT_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_MANAGEMENT_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_MANAGEMENT_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_MANAGEMENT_H
/******************************************************************************
* Included Files
@ -44,16 +44,6 @@
#include "spirit_config.h"
#include "spirit_types.h"
/******************************************************************************
* Pre-processor Definitions
******************************************************************************/
/* Macros used in assertions */
/******************************************************************************
* Public Types
******************************************************************************/
/******************************************************************************
* Public Function Prototypes
******************************************************************************/
@ -107,6 +97,22 @@ int spirit_management_txstrobe(FAR struct spirit_library_s *spirit);
int spirit_management_rxstrobe(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_management_waextracurrent
*
* Description:
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned on
* any failure.
*
******************************************************************************/
int spirit_management_waextracurrent(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_management_initcommstate
*
@ -124,4 +130,4 @@ int spirit_management_rxstrobe(FAR struct spirit_library_s *spirit);
void spirit_management_initcommstate(FAR struct spirit_library_s *spirit,
uint32_t frequency);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_MANAGEMENT_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_MANAGEMENT_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_pktbasic.h
* include/nuttx/wireless/spirit/include/spirit_pktbasic.h
* Configuration and management of SPIRIT Basic packets.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_PKTBASIC_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_PKTBASIC_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTBASIC_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTBASIC_H
/* This module can be used to manage the configuration of Spirit Basic
* packets. The user can obtain a packet configuration filling the
@ -118,8 +118,8 @@ struct pktbasic_init_s
uint32_t syncwords; /* Specifies the sync words. This parameter is
* a uint32_t word with format:
* 0x|SYNC1|SYNC2|SYNC3|SYNC4 */
uint8_t premblen; /* Specifies the preamble length. This parameter
* can be any value from enum pkt_premblen_e */
uint8_t preamblen; /* Specifies the preamble length. This parameter
* can be any value from enum pkt_preamblen_e */
uint8_t synclen; /* Specifies the sync word length. The 32bit
* word passed (syncwords) will be stored in
* the SYNCx registers from the MSB until the
@ -199,6 +199,97 @@ struct pktbasic_addr_s
int spirit_pktbasic_initialize(FAR struct spirit_library_s *spirit,
FAR const struct pktbasic_init_s *pktbasic);
/******************************************************************************
* Name: spirit_pktbasic_get_setup
*
* Description:
* Returns the SPIRIT Basic packet structure according to the specified
* parameters in the registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* pktbasic - Basic packet init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_get_setup(FAR struct spirit_library_s *spirit,
FAR struct pktbasic_init_s *pktbasic);
/******************************************************************************
* Name: spirit_pktbasic_addr_initialize
*
* Description:
* Initializes the SPIRIT Basic packet addresses according to the specified
* parameters in the struct struct pktbasic_init_s struct.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* basicaddr - Basic packet addresses init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_addr_initialize(FAR struct spirit_library_s *spirit,
FAR struct pktbasic_addr_s *basicaddr);
/******************************************************************************
* Name: spirit_pktbasic_get_addrsetup
*
* Description:
* Returns the SPIRIT Basic packet addresses structure according to the
* specified parameters in the registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* basicaddr - Basic packet addresses init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_get_addrsetup(FAR struct spirit_library_s *spirit,
FAR struct pktbasic_addr_s *basicaddr);
/******************************************************************************
* Name: spirit_pktbasic_set_format
*
* Description:
* Configures the Basic packet format as packet used by SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_set_format(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_pktbase_set_addrfield
*
* Description:
* Sets the address length for SPIRIT Basic packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* txdestaddr - Length of ADDRESS in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbase_set_addrfield(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e txdestaddr);
/******************************************************************************
* Name: spirit_pktbase_get_addrfield
*
@ -238,6 +329,25 @@ enum spirit_functional_state_e
int spirit_pktbasic_set_payloadlen(FAR struct spirit_library_s *spirit,
uint16_t payloadlen);
/******************************************************************************
* Name: spirit_pktbase_get_payloadlen
*
* Description:
* Returns the payload length for SPIRIT Basic packets. Since the packet
* length depends from the address and the control field size, this function
* reads the correspondent registers in order to determine the correct
* payload length to be returned.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Payload length in bytes.
*
******************************************************************************/
uint16_t spirit_pktbase_get_payloadlen(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_pktbasic_rxpktlen
*
@ -254,4 +364,26 @@ int spirit_pktbasic_set_payloadlen(FAR struct spirit_library_s *spirit,
uint16_t spirit_pktbasic_rxpktlen(FAR struct spirit_library_s *spirit);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_PKTBASIC_H*/
/******************************************************************************
* Name: spirit_pktbasic_set_varlen
*
* Description:
* Computes and sets the variable payload length for SPIRIT Basic packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* payloadlen - Payload length in bytes.
* txdestaddr - Enable or Disable Address Field.
* ctrllen - Control length in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_pktbasic_set_varlen(FAR struct spirit_library_s *spirit,
uint16_t payloadlen,
enum spirit_functional_state_e txdestaddr,
enum pkt_ctrllen_e ctrllen);
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTBASIC_H*/

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_pktcommon.h
* include/nuttx/wireless/spirit/include/spirit_pktcommon.h
* Configuration and management of the common features of SPIRIT packets.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_PKTCOMMON_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_PKTCOMMON_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTCOMMON_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTCOMMON_H
/* This module provides all the common functions and definitions used by the
* packets modules. Here are also defined all the generic enumeration types
@ -118,7 +118,7 @@ extern "C"
/* Preamble length in bytes enumeration. */
enum pkt_premblen_e
enum pkt_preamblen_e
{
PKT_PREAMBLE_LENGTH_01BYTE = 0x00, /* Preamble length 1 byte */
PKT_PREAMBLE_LENGTH_02BYTES = 0x08, /* Preamble length 2 bytes */
@ -255,4 +255,4 @@ int spirit_pktcommon_enable_crcfilter(FAR struct spirit_library_s *spirit,
}
#endif
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_PKTCOMMON_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTCOMMON_H */

View file

@ -0,0 +1,349 @@
/******************************************************************************
* drivers/wireless/spirit/include/spirit_pktmbus.h
* Configuration and management of SPIRIT MBUS packets.
*
* Copyright(c) 2015 STMicroelectronics
* Author: VMA division - AMS
* Version 3.2.2 08-July-2015
*
* Adapted for NuttX by:
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef __DRVIERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTMBUS_H
#define __DRVIERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTMBUS_H
/* This module can be used to manage the configuration of Spirit MBUS packets.
* The user can obtain a packet configuration filling the structure
* struct spirit_pktmbus_init_s, defining in it some general parameters for the Spirit MBUS
* packet format. Since the MBUS protocol is a standard, the configuration
* of a MBUS* packet is very simple to do.
*
* Example:
*
* struct spirit_pktmbus_init_s mbusInit =
* {
* MBUS_SUBMODE_S1_S2_LONG_HEADER, // MBUS submode selection
* 36, // added "01" chips on preamble
* 16 // postamble length in "01" chips
* };
*
* ...
*
* SpiritPktMbusInit(&mbusInit);
*
* ...
*
* The module provides some other functions that can be used to modify
* or read only some configuration parameters.
*/
/******************************************************************************
* Included Files
******************************************************************************/
#include "spirit_regs.h"
#include "spirit_types.h"
#include "spirit_pktcommon.h"
/******************************************************************************
* Pre-processor Definitions
******************************************************************************/
/* Macros used in assertions */
#define IS_MBUS_SUBMODE(mode) \
(((mode) == MBUS_SUBMODE_S1_S2_LONG_HEADER) || \
((mode) == MBUS_SUBMODE_S1_M_S2_T2_OTHER_TO_METER) || \
((mode) == MBUS_SUBMODE_T1_T2_METER_TO_OTHER) || \
((mode) == MBUS_SUBMODE_R2_SHORT_HEADER))
/******************************************************************************
* Public Types
******************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/* Configuration and management of SPIRIT MBUS packets. */
/* Pkt MBUS Exported Types */
/* MBUS submode enumeration. */
enum spirit_mbus_submode_e
{
/* MBUS submode S1, S2 (long header):
* Header length = mbus_prmbl_ctrl + 279 (in "01" bit pairs)
* Sync word = 0x7696 (length 18 bits)
*/
MBUS_SUBMODE_S1_S2_LONG_HEADER = MBUS_CTRL_MBUS_SUBMODE_S1_S2L,
/* MBUS submode S1-m, S2, T2 (other to meter):
* Header length = mbus_prmbl_ctrl + 15 (in "01" bit pairs)
* Sync word = 0x7696 (length 18 bits)
*/
MBUS_SUBMODE_S1_M_S2_T2_OTHER_TO_METER = MBUS_CTRL_MBUS_SUBMODE_S2_S1M_T2_OTHER,
/* MBUS submode T1, T2 (meter to other):
* Header length = mbus_prmbl_ctrl + 19 (in "01" bit pairs):
* Sync word = 0x3d (length 10 bits)
*/
MBUS_SUBMODE_T1_T2_METER_TO_OTHER = MBUS_CTRL_MBUS_SUBMODE_T1_T2_METER,
/* MBUS submode R2, short header:
* Header length = mbus_prmbl_ctrl + 39 (in "01" bit pairs)
* Sync word = 0x7696 (length 18 bits)
*/
MBUS_SUBMODE_R2_SHORT_HEADER = MBUS_CTRL_MBUS_SUBMODE_R2,
};
/* SPIRIT MBUS Packet Init structure definition */
struct spirit_pktmbus_init_s
{
enum spirit_mbus_submode_e submode; /* Specifies the SUBMODE to be
* configured. This field can be any
* value from enum spirit_mbus_submode_e */
uint8_t preamblen; /* Specifies the PREAMBLE length. This
* parameter can be any value between
* 0 and 255 chip sequence '01' */
uint8_t postamblen; /* Specifies the POSTAMBLE length. This
* parameter can be any value between 0
* and 255 chip sequence '01' */
};
/******************************************************************************
* Public Function Prototypes
******************************************************************************/
/******************************************************************************
* Name: spirit_pktmbus_initialize
*
* Description:
* Initializes the SPIRIT MBUS packet according to the specified parameters
* in the struct spirit_pktmbus_init_s structure.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* mbusinit - Pointer to a struct spirit_pktmbus_init_s structure that
* contains the configuration information for the specified
* SPIRIT MBUS PACKET FORMAT.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_initialize(FAR struct spirit_library_s *spirit,
FAR const struct spirit_pktmbus_init_s *mbusinit);
/******************************************************************************
* Name: spirit_pktmbus_get_setup
*
* Description:
* Returns the SPIRIT MBUS packet structure according to the specified
* parameters in the registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* mbusinit - MBUS packet init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_get_setup(FAR struct spirit_library_s *spirit,
FAR struct spirit_pktmbus_init_s *mbusinit);
/******************************************************************************
* Name: spirit_pktmbus_set_format
*
* Description:
* Configures the MBUS packet format as the one used by SPIRIT.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_format(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_pktmbus_set_preamble
*
* Description:
* Sets how many chip sequence 01 shall be added in the preamble respect
* to the minimum value as defined according to the specified sub-mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* preamble - The number of chip sequence.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_preamble(FAR struct spirit_library_s *spirit,
uint8_t preamble);
/******************************************************************************
* Name: spirit_pktmbus_get_preamble
*
* Description:
* Returns how many chip sequence "01" are added in the preamble respect to
* the minimum value as defined according to the specified sub-mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Preable in number of "01" chip sequences.
*
******************************************************************************/
uint8_t spirit_pktmbus_get_preamble(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_pktmbus_set_postamble
*
* Description:
* Sets how many chip sequence 01 will be used in postamble
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* postamble - The number of chip sequence.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_postamble(FAR struct spirit_library_s *spirit,
uint8_t postamble);
/******************************************************************************
* Name:
*
* Description:
* Returns how many chip sequence "01" are used in the postamble
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Postamble in number of "01" chip sequences.
*
******************************************************************************/
uint8_t spirit_pktmbus_get_postamble(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name:
*
* Description:
* Sets the MBUS submode used.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* submode - The submode used.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_submode(FAR struct spirit_library_s *spirit,
enum spirit_mbus_submode_e submode);
/******************************************************************************
* Name: spirit_pktmbus_get_submode
*
* Description:
* Returns the MBUS submode used.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* MBUS submode.
*
******************************************************************************/
enum spirit_mbus_submode_e
spirit_pktmbus_get_submode(FAR struct spirit_library_s *spirit);
/******************************************************************************
* Name: spirit_pktmbus_set_payloadlen
*
* Description:
* Sets the payload length for SPIRIT MBUS packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* payloadlen - Payload length in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_payloadlen(FAR struct spirit_library_s *spirit,
uint16_t payloadlen);
/******************************************************************************
* Name: spirit_pktmbus_get_payloadlen
*
* Description:
* Returns the payload length for SPIRIT MBUS packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Payload length in bytes.
*
******************************************************************************/
uint16_t spirit_pktmbus_get_payloadlen(FAR struct spirit_library_s *spirit);
#ifdef __cplusplus
}
#endif
#endif /* __DRVIERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_PKTMBUS_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_qi.h
* include/nuttx/wireless/spirit/include/spirit_qi.h
* Configuration and management of SPIRIT QI.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_QI_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_QI_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_QI_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_QI_H
/******************************************************************************
* Included Files
@ -191,4 +191,4 @@ enum spirit_sqi_threshold_e
int spirit_qi_set_rssithreshold(FAR struct spirit_library_s *spirit,
int dbmvalue);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_GENERAL_H*/
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_GENERAL_H*/

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_radio.h
* include/nuttx/wireless/spirit/include/spirit_radio.h
* This file provides all the low level API to manage Analog and Digital radio
* part of SPIRIT.
*
@ -35,8 +35,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_RADIO_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_RADIO_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_RADIO_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_RADIO_H
/* In order to configure the Radio main parameters, the user can fit struct
* radio_init_s structure the and call the spirit_radio_initialize()
@ -222,17 +222,28 @@
/* Other macros used in assertions */
#define IS_XTAL_FLAG(flag) \
(((flag) == XTAL_FLAG_24_MHz) || ((flag) == XTAL_FLAG_26_MHz))
(((flag) == XTAL_FLAG_24_MHz) || ((flag) == XTAL_FLAG_26_MHz))
#define IS_BAND_SELECTED(band) \
(((band) == HIGH_BAND) || ((band) == MIDDLE_BAND) || \
((band) == LOW_BAND) || ((band) == VERY_LOW_BAND))
(((band) == HIGH_BAND) || ((band) == MIDDLE_BAND) || \
((band) == LOW_BAND) || ((band) == VERY_LOW_BAND))
#define IS_MODULATION_SELECTED(mod) \
(((mod) == FSK) || ((mod) == GFSK_BT05) || \
((mod) == GFSK_BT1) || ((mod) == ASK_OOK) || \
(((mod) == FSK) || ((mod) == GFSK_BT05) || \
((mod) == GFSK_BT1) || ((mod) == ASK_OOK) || \
((mod) == MSK))
#define IS_PA_LOAD_CAP(cwc) \
(((cwc) == LOAD_0_PF) || ((cwc) == LOAD_1_2_PF) || \
((cwc) == LOAD_2_4_PF) || ((cwc) == LOAD_3_6_PF))
(((cwc) == LOAD_0_PF) || ((cwc) == LOAD_1_2_PF) || \
((cwc) == LOAD_2_4_PF) || ((cwc) == LOAD_3_6_PF))
#define IS_AFC_MODE(mode) \
((mode) == AFC_SLICER_CORRECTION || (mode) == AFC_2ND_IF_CORRECTION)
#define IS_AGC_MODE(mode) \
((mode) == AGC_LINEAR_MODE || (mode) == AGC_BINARY_MODE)
#define IS_CLK_REC_MODE(mode) \
((mode) == CLK_REC_PLL || (mode) == CLK_REC_DLL)
#define IS_PST_FLT_LENGTH(len) \
((len) == PSTFLT_LENGTH_8 || (len) == PSTFLT_LENGTH_16)
#define IS_OOK_PEAK_DECAY(decay) \
(((decay) == FAST_DECAY) || ((decay) == MEDIUM_FAST_DECAY) ||\
((decay) == MEDIUM_SLOW_DECAY) || ((decay) == SLOW_DECAY))
/******************************************************************************
* Public Types
@ -278,6 +289,49 @@ enum spirit_paload_capacitor_e
LOAD_3_6_PF = PA_POWER0_CWC_3_6P /* 3.6pF additional PA load capacitor */
};
/* SPIRIT AFC Mode selection */
enum spirit_afcmode_e
{
AFC_SLICER_CORRECTION = AFC2_AFC_MODE_SLICER, /* AFC loop closed on slicer */
AFC_2ND_IF_CORRECTION = AFC2_AFC_MODE_MIXER /* AFC loop closed on 2nd
* conversion stage */
};
/* SPIRIT AGC Mode selection */
enum spirit_agcmode_e
{
AGC_LINEAR_MODE = AGCCTRL0_AGC_MODE_LINEAR, /* AGC works in linear mode */
AGC_BINARY_MODE = AGCCTRL0_AGC_MODE_BINARY /* AGC works in binary mode */
};
/* SPIRIT Clock Recovery Mode selection */
enum spirit_clkrecmode_e
{
CLK_REC_PLL = FDEV0_CLOCK_REG_ALGO_SEL_PLL, /* PLL alogrithm for clock recovery */
CLK_REC_DLL = FDEV0_CLOCK_REG_ALGO_SEL_DLL /* DLL alogrithm for clock recovery */
};
/* SPIRIT Postfilter length */
enum spirit_pstfltlen_e
{
PSTFLT_LENGTH_8 = 0x00, /* Postfilter length is 8 symbols */
PSTFLT_LENGTH_16 = 0x10 /* Postfilter length is 16 symbols */
};
/* SPIRIT OOK Peak Decay */
enum spirit_ookpeakdelay_e
{
FAST_DECAY = 0x00, /* Peak decay control for OOK: fast decay */
MEDIUM_FAST_DECAY = 0x01, /* Peak decay control for OOK: medium_fast decay */
MEDIUM_SLOW_DECAY = 0x02, /* Peak decay control for OOK: medium_fast decay */
SLOW_DECAY = 0x03 /* Peak decay control for OOK: slow decay */
};
/* SPIRIT Radio initialization structure definition */
struct radio_init_s
@ -820,6 +874,25 @@ int spirit_radio_set_palevel_maxindex(FAR struct spirit_library_s *spirit,
int spirit_radio_afcfreezeonsync(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name: spirit_radio_enable_csblanking
*
* Description:
* Enables or Disables the received data blanking when the CS is under the
* threshold.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - New state of this mode.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_radio_enable_csblanking(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate);
/******************************************************************************
* Name: spirit_radio_persistentrx
*
@ -908,4 +981,4 @@ int spirit_radio_enable_digdivider(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e
spirit_radio_isenabled_digdivider(FAR struct spirit_library_s *spirit);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_RADIO_H*/
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_RADIO_H*/

View file

@ -1,5 +1,5 @@
/**********************************************************************************************
* include/nuttx/wireless/spirit/spirit_regs.h
* include/nuttx/wireless/spirit/include/spirit_regs.h
* This file contains all the SPIRIT registers address and masks.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
**********************************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_REGS_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_REGS_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_REGS_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_REGS_H
/**********************************************************************************************
* Pre-processor Definitions
@ -2376,4 +2376,4 @@
#define COMMAND_FLUSHTXFIFO ((uint8_t)0x72) /* Clean the TX FIFO; valid from all
* states */
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_REGS_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_REGS_H */

View file

@ -1,5 +1,5 @@
/******************************************************************************
* include/nuttx/wireless/spirit/spirit_timer.h
* include/nuttx/wireless/spirit/include/spirit_timer.h
* Configuration and management of SPIRIT timers.
*
* Copyright(c) 2015 STMicroelectronics
@ -34,8 +34,8 @@
*
******************************************************************************/
#ifndef __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_TIMER_H
#define __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_TIMER_H
#ifndef __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_TIMER_H
#define __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_TIMER_H
/******************************************************************************
* Included Files
@ -143,4 +143,4 @@ int spirit_timer_set_rxtimeout_stopcondition(FAR struct spirit_library_s *spirit
enum spirit_rxtimeout_stopcondition_e
stopcondition);
#endif /* __INCLUDE_NUTT_WIRELESS_SPIRIT_SPIRIT_TIMER_H */
#endif /* __DRIVERS_WIRELESS_SPIRIT_INCLUDE_SPIRIT_TIMER_H */

View file

@ -35,10 +35,10 @@
# Include Spirit driver source files in the build
CSRCS += spirit_radio.c spirit_pktbasic.c spirit_pktcommon.c spirit_qi.c
CSRCS += spirit_calibration.c spirit_management.c spirit_csma.c
CSRCS += spirit_linearfifo.c spirit_irq.c spirit_timer.c spirit_gpio.c
CSRCS += spirit_spi.c
CSRCS += spirit_radio.c spirit_pktbasic.c spirit_pktcommon.c
CSRCS += spirit_pktmbus.c spirit_directrf.c spirit_qi.c spirit_calibration.c
CSRCS += spirit_management.c spirit_aes.c spirit_csma.c spirit_linearfifo.c
CSRCS += spirit_irq.c spirit_timer.c spirit_gpio.c spirit_spi.c
# Include Spirit driver build support

View file

@ -0,0 +1,361 @@
/******************************************************************************
* drivers/wireless/spirit/lib/spirit_aes.c
* Configuration and management of SPIRIT AES Engine.
*
* Copyright(c) 2015 STMicroelectronics
* Author: VMA division - AMS
* Version 3.2.2 08-July-2015
*
* Adapted for NuttX by:
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
/******************************************************************************
* Included Files
******************************************************************************/
#include <assert.h>
#include "spirit_aes.h"
#include "spirit_spi.h"
/******************************************************************************
* Public Functions
******************************************************************************/
/******************************************************************************
* Name: spirit_aes_enable
*
* Description:
* Enables or Disables the AES engine.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate new state for AES engine.
* This parameter can be: S_ENABLE or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_enable(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate)
{
uint8_t regval = 0;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(newstate));
/* Modifies the register value */
ret = spirit_reg_read(spirit, ANA_FUNC_CONF0_BASE, &regval, 1);
if (ret >= 0)
{
if (newstate == S_ENABLE)
{
regval |= AES_MASK;
}
else
{
regval &= ~AES_MASK;
}
/* Write to the ANA_FUNC_CONF0 register to enable or disable the AES
* engine
*/
ret = spirit_reg_write(spirit, ANA_FUNC_CONF0_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name:
*
* Description:
* Writes the data to encrypt or decrypt, or the encryption key for the
* derive decryption key operation into the AES_DATA_IN registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* buffer - Pointer to the user data buffer. The first byte of the array
* must be the MSB byte and it will be put in the AES_DATA_IN[0]
* register, while the last one must be the LSB and it will be
* put in the AES_DATA_IN[buflen-1] register. If data to write
* are less than 16 bytes the remaining AES_DATA_IN registers
* will be filled with bytes equal to 0.
* buflen - Length of data in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_write_datain(FAR struct spirit_library_s *spirit,
FAR const uint8_t *buffer, uint8_t buflen)
{
uint8_t datain[16];
uint8_t i;
/* Verifies that there are no more than 16 bytes */
(buflen > 16) ? (buflen = 16) : buflen;
/* Fill the datain with the data buffer, using padding */
for (i = 0; i < 16; i++)
{
if (i < (16 - buflen))
{
datain[i] = 0;
}
else
{
datain[i] = buffer[15 - i];
}
}
/* Writes the AES_DATA_IN registers */
return spirit_reg_write(spirit, AES_DATA_IN_15_BASE, datain, 16);
}
/******************************************************************************
* Name:
*
* Description:
* Returns the encrypted or decrypted data or the decription key from the
* AES_DATA_OUT register.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* buffer - pointer to the user data buffer. The AES_DATA_OUT[0]
* register value will be put as first element of the buffer
* (MSB), while the AES_DAT_OUT[buflen-1] register value will be
* put as last element of the buffer (LSB).
* buflen - Length of data to read in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_read_dataout(FAR struct spirit_library_s *spirit,
FAR uint8_t *buffer, uint8_t buflen)
{
uint8_t dataout[16];
uint8_t address;
int ret;
/* Verifies that there are no more than 16 bytes */
if (buflen > 16)
{
buflen = 16;
}
/* Evaluates the address of AES_DATA_OUT from which start to read */
address = AES_DATA_OUT_15_BASE + 16 - buflen;
/* Reads the exact number of AES_DATA_OUT registers */
ret = spirit_reg_read(spirit, address, dataout, buflen);
if (ret >= 0)
{
int i;
/* Copy in the user buffer the read values changing the order */
for (i = buflen - 1; i >= 0; i--)
{
*buffer++ = dataout[i];
}
}
return ret;
}
/******************************************************************************
* Name: spirit_aes_write_key
*
* Description:
* Writes the encryption key into the AES_KEY_IN register.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* key - Pointer to the buffer of 4 words containing the AES key.
* The first byte of the buffer must be the most significant byte
* AES_KEY_0 of the AES key. The last byte of the buffer must be
* the less significant byte AES_KEY_15 of the AES key.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_write_key(FAR struct spirit_library_s *spirit,
FAR const uint8_t *key)
{
uint8_t tmp[16];
int i;
for (i = 0; i < 16; i++)
{
tmp[15 - i] = key[i];
}
/* Write to the AES_DATA_IN registers */
return spirit_reg_write(spirit, AES_KEY_IN_15_BASE, tmp, 16);
}
/******************************************************************************
* Name:
*
* Description:
* Returns the encryption/decryption key from the AES_KEY_IN register.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* key pointer to the buffer of 4 words (16 bytes) containing the AES key.
* The first byte of the buffer shall be the most significant byte AES_KEY_0 of the AES key.
* The last byte of the buffer shall be the less significant byte AES_KEY_15 of the AES key.
* This parameter is an uint8_t*.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_read_key(FAR struct spirit_library_s *spirit, FAR uint8_t *key)
{
uint8_t tmp[16];
int ret;
int i;
/* Reads the AES_DATA_IN registers */
ret = spirit_reg_read(spirit, AES_KEY_IN_15_BASE, tmp, 16);
if (ret >= 0)
{
for (i = 0; i < 16; i++)
{
key[i] = tmp[15 - i];
}
}
return ret;
}
/******************************************************************************
* Name: spirit_aes_enc2deckey
*
* Description:
* Derives the decryption key from a given encryption key.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_enc2deckey(FAR struct spirit_library_s *spirit)
{
/* Sends the COMMAND_AES_KEY command */
return spirit_command(spirit, COMMAND_AES_KEY);
}
/******************************************************************************
* Name: spirit_aes_encrypt
*
* Description:
* Executes the encryption operation.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_encrypt(FAR struct spirit_library_s *spirit)
{
/* Sends the COMMAND_AES_ENC command */
return spirit_command(spirit, COMMAND_AES_ENC);
}
/******************************************************************************
* Name:
*
* Description:
* Executes the decryption operation.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_decrypt(FAR struct spirit_library_s *spirit)
{
/* Sends the COMMAND_AES_DEC command */
return spirit_command(spirit, COMMAND_AES_DEC);
}
/******************************************************************************
* Name: spirit_aes_derivekey_decrypt
*
* Description:
* Executes the key derivation and the decryption operation.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_aes_derivekey_decrypt(FAR struct spirit_library_s *spirit)
{
/* Sends the COMMAND_AES_KEY_DEC command */
return spirit_command(spirit, COMMAND_AES_KEY_DEC);
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* drivers/wireless/spirit/spirit_calibration.c
* drivers/wireless/spirit/lib/spirit_calibration.c
* Configuration and management of SPIRIT VCO-RCO calibration.
*
* Copyright(c) 2015 STMicroelectronics
@ -148,6 +148,90 @@ int spirit_calib_enable_vco(FAR struct spirit_library_s *spirit,
return ret;
}
/******************************************************************************
* Name: spirit_calibration_set_rcocal
*
* Description:
* Sets the RCO calibration words.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* rwt - RWT word for RCO calibration.
* rfb - RFB word for RCO calibration.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_calibration_set_rcocal(FAR struct spirit_library_s *spirit,
uint8_t rwt, uint8_t rfb)
{
uint8_t regval[2];
int ret;
/* Build the value of RWT and the MSbits of the RFB word */
regval[0] = (rwt << 4) | (rfb >> 1);
/* Reads the register value to update the LSbit of RFB */
ret = spirit_reg_read(spirit, RCO_VCO_CALIBR_IN1_BASE, &regval[1], 1);
if (ret >= 0)
{
/* Build new value for the register */
regval[1] = (regval[1] & 0x7f) | (rfb << 7);
/* Write the new value for RCO calibration words */
ret = spirit_reg_write(spirit, RCO_VCO_CALIBR_IN2_BASE, regval, 2);
}
return ret;
}
/******************************************************************************
* Name: spirit_calibration_get_rcocal
*
* Description:
* Returns the RCO calibration words.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* rwt - Pointer to the variable in which the RWT word has to be
* stored.
* rfb - Pointer to the variable in which the RFB word has to be
* stored.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_calibration_get_rcocal(FAR struct spirit_library_s *spirit,
FAR uint8_t *rwt, FAR uint8_t *rfb)
{
uint8_t regval[2];
int ret;
/* Read the registers values */
ret = spirit_reg_read(spirit, RCO_VCO_CALIBR_OUT1_BASE, regval, 2);
if (ret >= 0)
{
/* Build the RWT value */
(*rwt) = regval[0] >> 4;
/* Build the RFB value */
(*rfb) = (regval[0] & 0x0F) << 1 | (regval[1] >> 7);
}
return ret;
}
/******************************************************************************
* Name: spirit_calib_get_vcocal
*
@ -307,6 +391,147 @@ uint8_t spirit_calib_get_vcorxcal(FAR struct spirit_library_s *spirit)
return (regval & 0x7f);
}
/******************************************************************************
* Name: spirit_calibration_set_vcowin
*
* Description:
* Sets the VCO calibration window.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* refword - Value of REFWORD corresponding to the Ref_period according to
* the formula:
*
* CALIBRATION_WIN = 11*Ref_period/fxo.
*
* This parameter can be a value of enum spirit_vcowin_e.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure.
*
******************************************************************************/
int spirit_calibration_set_vcowin(FAR struct spirit_library_s *spirit,
enum spirit_vcowin_e refword)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_VCO_WIN(refword));
/* Reads the register value */
ret = spirit_reg_read(spirit, SYNTH_CONFIG1_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the values to be written */
regval &= 0xfc;
regval |= refword;
/* Write the new value of VCO calibration window */
ret = spirit_reg_write(spirit, SYNTH_CONFIG1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_calibration_get_vcowin
*
* Description:
* Returns the VCO calibration window.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Value of REFWORD corresponding to the Ref_period according to the
* formula:
*
* CALIBRATION_WIN = 11*Ref_period/fxo.
*
* This parameter can be a value of enum spirit_vcowin_e.
*
******************************************************************************/
enum spirit_vcowin_e
spirit_calibration_get_vcowin(FAR struct spirit_library_s *spirit)
{
uint8_t regval1, regval2;
enum spirit_vcowin_e refword;
/* Reads the register containing the REFWORD value */
(void)spirit_reg_read(spirit, SYNTH_CONFIG1_BASE, &regval1, 1);
/* Reads the Xtal configuration */
(void)spirit_reg_read(spirit, ANA_FUNC_CONF0_BASE, &regval2, 1);
/* Mask the REFWORD field */
regval1 &= 0x03;
/* Mask the 24_26_MHz_SELECT field */
regval2 = ((regval2 & 0x40) >> 6);
/* In case of 26 MHz crystal */
if (regval2 != 0)
{
switch (regval1)
{
case 0:
refword = CALIB_TIME_6_77_US_26MHZ;
break;
case 1:
refword = CALIB_TIME_13_54_US_26MHZ;
break;
case 2:
refword = CALIB_TIME_27_08_US_26MHZ;
break;
case 3:
refword = CALIB_TIME_54_15_US_26MHZ;
break;
}
}
/* In case of 24 MHz crystal */
else
{
switch (regval1)
{
case 0:
refword = CALIB_TIME_7_33_US_24MHZ;
break;
case 1:
refword = CALIB_TIME_14_67_US_24MHZ;
break;
case 2:
refword = CALIB_TIME_29_33_US_24MHZ;
break;
case 3:
refword = CALIB_TIME_58_67_US_24MHZ;
break;
}
}
return refword;
}
/******************************************************************************
* Name: spirit_calib_select_vco
*

View file

@ -1,5 +1,5 @@
/******************************************************************************
* drivers/wireless/spirit/spirit_csma.c
* drivers/wireless/spirit/lib/spirit_csma.c
* Configuration and management of SPIRIT CSMA.
*
* Copyright(c) 2015 STMicroelectronics
@ -38,6 +38,7 @@
* Included Files
******************************************************************************/
#include <sys/types.h>
#include <assert.h>
#include <debug.h>
@ -65,7 +66,7 @@
******************************************************************************/
int spirit_csma_initialize(FAR struct spirit_library_s *spirit,
FAR struct spirit_csma_init_s *csmainit)
FAR const struct spirit_csma_init_s *csmainit)
{
uint8_t regval[5];
int ret;
@ -129,3 +130,675 @@ int spirit_csma_initialize(FAR struct spirit_library_s *spirit,
ret = spirit_reg_write(spirit, CSMA_CONFIG3_BASE, regval, 4);
return ret;
}
/******************************************************************************
* Name: spirit_csma_getinfo
*
* Description:
* Returns the fitted structure struct spirit_csma_init_s starting from the
* registers values.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* csmainit - Csma structure to be fitted.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_getinfo(FAR struct spirit_library_s *spirit,
FAR struct spirit_csma_init_s *csmainit)
{
uint8_t regval[5];
int ret;
/* Reads PROTOCOL1_BASE register */
ret = spirit_reg_read(spirit, PROTOCOL1_BASE, &regval[4], 1);
if (ret < 0)
{
return ret;
}
/* Reads CSMA_CONFIGx_BASE registers */
ret = spirit_reg_read(spirit, CSMA_CONFIG3_BASE, regval, 4);
if (ret < 0)
{
return ret;
}
/* Reads the bu counter seed */
csmainit->seed = (uint16_t)regval[1] | (uint16_t)regval[0] << 8;
/* Reads the bu prescaler */
csmainit->prescaler = regval[2] >> 2;
/* Reads the Cca period */
csmainit->multbit = (enum spirit_cca_period_e) (regval[2] & 0x03);
/* Reads the Cca length */
csmainit->ccalen = (enum spirit_csmalen_e) (regval[3] & 0xF0);
/* Reads the max number of back off */
csmainit->maxnb = regval[3] & 0x07;
/* Reads the persistent mode enable bit */
csmainit->csmapersistent =
(enum spirit_functional_state_e)((regval[4] >> 1) & 0x01);
return OK;
}
/******************************************************************************
* Name: spirit_csma_enable
*
* Description:
* Enables or Disables the CSMA.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - The state of the CSMA mode. This parameter can be: S_ENABLE
* or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_enable(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(newstate));
/* Reads the PROTOCOL1 register value */
ret = spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
if (ret >= 0)
{
/* Sets or resets the CSMA enable bit */
if (newstate == S_ENABLE)
{
regval |= PROTOCOL1_CSMA_ON_MASK;
}
else
{
regval &= ~PROTOCOL1_CSMA_ON_MASK;
}
/* Write the new value on the PROTOCOL1 register */
ret = spirit_reg_write(spirit, PROTOCOL1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_getstate
*
* Description:
* Gets the CSMA mode. Says if it is enabled or disabled.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CSMA mode.
*
******************************************************************************/
enum spirit_functional_state_e
spirit_csma_getstate(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the PROTOCOL1 register value */
(void)spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
/* Return if set or reset */
if (regval & PROTOCOL1_CSMA_ON_MASK)
{
return S_ENABLE;
}
else
{
return S_DISABLE;
}
}
/******************************************************************************
* Name: spirit_csma_set_persistentmode
*
* Description:
* Enables or Disables the persistent CSMA mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - The state of the persistent CSMA mode. This parameter can
* be: S_ENABLE or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_persistentmode(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(newstate));
/* Reads the PROTOCOL1 register value */
ret = spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
if (ret >= 0)
{
/* Enables/disables the CSMA persistent mode */
if (newstate == S_ENABLE)
{
regval |= PROTOCOL1_CSMA_PERS_ON_MASK;
}
else
{
regval &= ~PROTOCOL1_CSMA_PERS_ON_MASK;
}
/* Write the new vaue on the PROTOCOL1 register */
ret = spirit_reg_write(spirit, PROTOCOL1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_get_persistentmode
*
* Description:
* Gets the persistent CSMA mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CSMA persistent mode.
*
******************************************************************************/
enum spirit_functional_state_e
spirit_csma_get_persistentmode(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the PROTOCOL1 register value */
(void)spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
/* Return if set or reset */
if (regval & PROTOCOL1_CSMA_PERS_ON_MASK)
{
return S_ENABLE;
}
else
{
return S_DISABLE;
}
}
/******************************************************************************
* Name: spirit_csma_set_seedreload
*
* Description:
* Enables or Disables the seed reload mode (if enabled it reloads the back-
* off generator seed using the value written in the BU_COUNTER_SEED register).
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - The state of the seed reload mode. This parameter can be:
* S_ENABLE or S_DISABLE.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_seedreload(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(newstate));
/* Reads the PROTOCOL1 register value */
ret = spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
if (ret >= 0)
{
/* Enables/disables the seed reload mode */
if (newstate == S_ENABLE)
{
regval |= PROTOCOL1_SEED_RELOAD_MASK;
}
else
{
regval &= ~PROTOCOL1_SEED_RELOAD_MASK;
}
/* Write the new value on the PROTOCOL1 register */
ret = spirit_reg_write(spirit, PROTOCOL1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_get_seedreload
*
* Description:
* Gets the seed reload state.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CSMA seed reload mode.
*
******************************************************************************/
enum spirit_functional_state_e
spirit_csma_get_seedreload(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the PROTOCOL1 register value */
(void)spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
/* Return if set or reset */
if (regval & PROTOCOL1_SEED_RELOAD_MASK)
{
return S_ENABLE;
}
else
{
return S_DISABLE;
}
}
/******************************************************************************
* Name: spirit_csma_set_bucounterseed
*
* Description:
* Sets the BU counter seed (BU_COUNTER_SEED register). The CSMA back off
* time is given by the formula: BO = rand(2^NB)*BU.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* seed - Seed of the random number generator used to apply the BBE
* algorithm.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_bucounterseed(FAR struct spirit_library_s *spirit,
uint16_t seed)
{
uint8_t regval[2];
/* Check parameters */
DEBUGASSERT(IS_BU_COUNTER_SEED(seed));
/* Build value (MSB) */
regval[0] = (uint8_t) (seed >> 8);
/* Build value (LSB) */
regval[1] = (uint8_t) seed;
/* Writes the CSMA_CONFIG3 registers */
return spirit_reg_write(spirit, CSMA_CONFIG3_BASE, regval, 2);
}
/******************************************************************************
* Name: spirit_csma_get_bucounterseed
*
* Description:
* Returns the BU counter seed (BU_COUNTER_SEED register).
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Seed of the random number generator used to apply the BBE algorithm.
*
******************************************************************************/
uint16_t spirit_csma_get_bucounterseed(FAR struct spirit_library_s *spirit)
{
uint8_t regval[2];
/* Reads the CSMA_CONFIGx registers value */
(void)spirit_reg_read(spirit, CSMA_CONFIG3_BASE, regval, 2);
/* Build the counter seed and return it */
return ((uint16_t) regval[1] + (((uint16_t) regval[0]) << 8));
}
/******************************************************************************
* Name: spirit_csma_set_buprescaler
*
* Description:
* Sets the BU prescaler. The CSMA back off time is given by the formula:
* BO = rand(2^NB)*BU.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* prescaler - Used to program the back-off unit BU.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_buprescaler(FAR struct spirit_library_s *spirit,
uint8_t prescaler)
{
uint8_t regval;
int ret;
/* Check parameters */
DEBUGASSERT(IS_BU_PRESCALER(prescaler));
/* Reads the CSMA_CONFIG1 register value */
ret = spirit_reg_read(spirit, CSMA_CONFIG1_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the new value for the BU prescaler */
regval &= 0x03;
regval |= (prescaler << 2);
/* Write the new value on the CSMA_CONFIG1_BASE register */
ret = spirit_reg_write(spirit, CSMA_CONFIG1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_get_buprescaler
*
* Description:
* Returns the BU prescaler.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Value back-off unit (BU).
*
******************************************************************************/
uint8_t spirit_csma_get_buprescaler(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the CSMA_CONFIG1 register value */
(void)spirit_reg_read(spirit, CSMA_CONFIG1_BASE, &regval, 1);
/* Build and return the BU prescaler value */
return (regval >> 2);
}
/******************************************************************************
* Name: spirit_csma_set_ccaperiod
*
* Description:
* Sets the CCA period.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* multbit - Value of CCA period to store. This parameter can be a value
* of enum spirit_cca_period_e.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_ccaperiod(FAR struct spirit_library_s *spirit,
enum spirit_cca_period_e multbit)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_CCA_PERIOD(multbit));
/* Reads the CSMA_CONFIG1 register value */
ret = spirit_reg_read(spirit, CSMA_CONFIG1_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the new value setting the the CCA period */
regval &= 0xfc;
regval |= multbit;
/* Write the new value on the CSMA_CONFIG1 register */
ret = spirit_reg_write(spirit, CSMA_CONFIG1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_get_ccaperiod
*
* Description:
* Returns the CCA period.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CCA period.
*
******************************************************************************/
enum spirit_cca_period_e
spirit_csma_get_ccaperiod(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the CSMA_CONFIG1 register value */
(void)spirit_reg_read(spirit, CSMA_CONFIG1_BASE, &regval, 1);
/* Build and return the CCA period value */
return (enum spirit_cca_period_e) (regval & 0x03);
}
/******************************************************************************
* Name: spirit_csma_set_ccalen
*
* Description:
* Sets the CCA length.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* ccalen - The CCA length (a value between 1 and 15 that multiplies the
* CCA period). This parameter can be any value of enum
* spirit_csmalen_e.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_ccalen(FAR struct spirit_library_s *spirit,
enum spirit_csmalen_e ccalen)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_CSMA_LENGTH(ccalen));
/* Reads the CSMA_CONFIG0 register value */
ret = spirit_reg_read(spirit, CSMA_CONFIG0_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the value of CCA length to be set */
regval &= 0x0f;
regval |= ccalen;
/* Write the new value on the CSMA_CONFIG0 register */
ret = spirit_reg_write(spirit, CSMA_CONFIG0_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_get_ccalen
*
* Description:
* Returns the CCA length.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* CCA length.
*
******************************************************************************/
uint8_t spirit_csma_get_ccalen(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the CSMA_CONFIG0 register value */
(void)spirit_reg_read(spirit, CSMA_CONFIG0_BASE, &regval, 1);
/* Build and return the CCA length */
return regval >> 4;
}
/******************************************************************************
* Name: spirit_csma_set_maxbackoff
*
* Description:
* Sets the max number of back-off. If reached Spirit stops the transmission.
*
* Input Parameters:
* maxnb the max number of back-off.
* This parameter is an uint8_t.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_csma_set_maxbackoff(FAR struct spirit_library_s *spirit,
uint8_t maxnb)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_CMAX_NB(maxnb));
/* Reads the CSMA_CONFIG0 register value */
ret = spirit_reg_read(spirit, CSMA_CONFIG0_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the value of max back off to be set */
regval &= 0xf8;
regval |= maxnb;
/* Write the new value on the CSMA_CONFIG0 register */
ret = spirit_reg_write(spirit, CSMA_CONFIG0_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_csma_get_maxbackoff
*
* Description:
* Returns the max number of back-off.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Max number of back-off.
*
******************************************************************************/
uint8_t spirit_csma_get_maxbackoff(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the CSMA_CONFIG0 register value */
(void)spirit_reg_read(spirit, CSMA_CONFIG0_BASE, &regval, 1);
/* Build and return the max number of back-off */
return (regval & 0x07);
}

View file

@ -0,0 +1,190 @@
/******************************************************************************
* drivers/wireless/spirit/lib/spirit_directrf.c
* Configuration and management of SPIRIT direct transmission / receive modes.
*
* Copyright(c) 2015 STMicroelectronics
* Author: VMA division - AMS
* Version 3.2.2 08-July-2015
*
* Adapted for NuttX by:
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
/******************************************************************************
* Included Files
******************************************************************************/
#include <assert.h>
#include "spirit_directrf.h"
#include "spirit_spi.h"
/******************************************************************************
* Public Functions
******************************************************************************/
/******************************************************************************
* Name: spirit_directrf_set_rxmode
*
* Description:
* Sets the DirectRF RX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* directrx - Code of the desired mode.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_directrf_set_rxmode(FAR struct spirit_library_s *spirit,
enum spirit_directrx_e directrx)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_DIRECT_RX(directrx));
/* Reads the register value */
ret = spirit_reg_read(spirit, PCKTCTRL3_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the value to be stored */
regval &= ~PCKTCTRL3_RX_MODE_MASK;
regval |= (uint8_t)directrx;
/* Write value to register */
ret = spirit_reg_write(spirit, PCKTCTRL3_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name:
*
* Description:
* Returns the DirectRF RX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Direct Rx mode.
*
******************************************************************************/
enum spirit_directrx_e
spirit_directrf_get_rxmode(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the register value and mask the RX_Mode field */
(void)spirit_reg_read(spirit, PCKTCTRL3_BASE, &regval, 1);
/* Rebuild and return value */
return (enum spirit_directrx_e)(regval & 0x30);
}
/******************************************************************************
* Name:
*
* Description:
* Sets the TX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* directtx - Code of the desired source.
*
* Returned Value:
* Zero (OK) on success; A negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_directrf_set_txmode(FAR struct spirit_library_s *spirit,
enum spirit_directtx_e directtx)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_DIRECT_TX(directtx));
/* Reads the register value */
ret = spirit_reg_read(spirit, PCKTCTRL1_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the value to be stored */
regval &= ~PCKTCTRL1_TX_SOURCE_MASK;
regval |= (uint8_t) directtx;
/* Write value to register */
ret = spirit_reg_write(spirit, PCKTCTRL1_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name:
*
* Description:
* Returns the DirectRF TX mode of SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Direct Tx mode.
*
******************************************************************************/
enum spirit_directtx_e
spirit_directrf_get_txmode(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the register value and mask the RX_Mode field */
(void)spirit_reg_read(spirit, PCKTCTRL1_BASE, &regval, 1);
/* Returns value */
return (enum spirit_directtx_e)(regval & 0x0c);
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* drivers/wireless/spirit/spirit_Linearfifo.c
* drivers/wireless/spirit/lib/spirit_Linearfifo.c
* Configuration and management of SPIRIT Fifo.
*
* Copyright(c) 2015 STMicroelectronics

View file

@ -550,6 +550,52 @@ int spirit_management_rxstrobe(FAR struct spirit_library_s *spirit)
return OK;
}
/******************************************************************************
* Name: spirit_management_waextracurrent
*
* Description:
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned on
* any failure.
*
******************************************************************************/
int spirit_management_waextracurrent(FAR struct spirit_library_s *spirit)
{
uint8_t tmp;
int ret;
tmp = 0xca;
ret = spirit_reg_write(spirit, 0xb2, &tmp, 1);
if (ret < 0)
{
return ret;
}
tmp = 0x04;
ret = spirit_reg_write(spirit, 0xa8, &tmp, 1);
if (ret < 0)
{
return ret;
}
/* Just a read to lose a few more microseconds */
ret = spirit_reg_read(spirit, 0xa8, &tmp, 1);
if (ret < 0)
{
return ret;
}
tmp = 0x00;
ret = spirit_reg_write(spirit, 0xa8, &tmp, 1);
return ret;
}
/******************************************************************************
* Name: spirit_management_initcommstate
*

View file

@ -38,6 +38,7 @@
* Included Files
******************************************************************************/
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
@ -76,7 +77,7 @@ int spirit_pktbasic_initialize(FAR struct spirit_library_s *spirit,
/* Check the parameters */
DEBUGASSERT(IS_PKT_PREAMBLE_LENGTH(pktpasic->premblen));
DEBUGASSERT(IS_PKT_PREAMBLE_LENGTH(pktpasic->preamblen));
DEBUGASSERT(IS_PKT_SYNC_LENGTH(pktpasic->synclen));
DEBUGASSERT(IS_PKT_CRC_MODE(pktpasic->crcmode));
DEBUGASSERT(IS_PKT_LENGTH_WIDTH_BITS(pktpasic->pktlenwidth));
@ -153,7 +154,7 @@ int spirit_pktbasic_initialize(FAR struct spirit_library_s *spirit,
/* Preamble, sync and fixed or variable length setting */
regval[2] = (uint8_t)pktpasic->premblen | (uint8_t)pktpasic->synclen |
regval[2] = (uint8_t)pktpasic->preamblen | (uint8_t)pktpasic->synclen |
(uint8_t)pktpasic->fixedvarlen;
/* CRC length, whitening and FEC setting */
@ -211,6 +212,343 @@ int spirit_pktbasic_initialize(FAR struct spirit_library_s *spirit,
return spirit_reg_write(spirit, SYNC4_BASE, regval, 4);
}
/******************************************************************************
* Name: spirit_pktbasic_get_setup
*
* Description:
* Returns the SPIRIT Basic packet structure according to the specified
* parameters in the registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* pktbasic - Basic packet init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_get_setup(FAR struct spirit_library_s *spirit,
FAR struct pktbasic_init_s *pktbasic)
{
uint8_t regval[10];
int ret;
int i;
/* Reads registers */
ret = spirit_reg_read(spirit, PCKTCTRL4_BASE, regval, 10);
if (ret < 0)
{
return ret;
}
/* Length width */
pktbasic->pktlenwidth = (regval[1] & 0x0f) + 1;
/* Address field */
pktbasic->txdestaddr =
(enum spirit_functional_state_e)((regval[0] >> 3) & 0x01);
/* Control length */
pktbasic->ctrllen = (enum pkt_ctrllen_e)(regval[0] & 0x07);
/* CRC mode */
pktbasic->crcmode = (enum pkt_crcmode_e)(regval[3] & 0xe0);
/* Whitening */
pktbasic->datawhite =
(enum spirit_functional_state_e) ((regval[3] >> 4) & 0x01);
/* FEC */
pktbasic->fec = (enum spirit_functional_state_e)(regval[3] & 0x01);
/* FIX or VAR bit */
pktbasic->fixedvarlen = (enum pkt_fixvar_len_e)(regval[2] & 0x01);
/* Preamble length */
pktbasic->preamblen = (enum pkt_preamblen_e)(regval[2] & 0xf8);
/* Sync length */
pktbasic->synclen = (enum pkt_synlen_e)(regval[2] & 0x06);
/* Sync Words */
pktbasic->syncwords = 0;
for (i = 0; i < 4; i++)
{
if (i > 2 - (((uint8_t)pktbasic->synclen) >> 1))
{
pktbasic->syncwords |= (uint32_t) (regval[i + 6]) << (8 * i);
}
}
return OK;
}
/******************************************************************************
* Name: spirit_pktbasic_addr_initialize
*
* Description:
* Initializes the SPIRIT Basic packet addresses according to the specified
* parameters in the struct struct pktbasic_init_s struct.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* basicaddr - Basic packet addresses init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_addr_initialize(FAR struct spirit_library_s *spirit,
FAR struct pktbasic_addr_s *basicaddr)
{
uint8_t regval[3];
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(basicaddr->destfilter));
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(basicaddr->mcastfilter));
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(basicaddr->bcastfilter));
/* Reads the PCKT_FLT_OPTIONS ragister */
ret = spirit_reg_read(spirit, PCKT_FLT_OPTIONS_BASE, &regval[0], 1);
if (ret < 0)
{
return ret;
}
/* Enables or disables filtering on my address */
if (basicaddr->destfilter == S_ENABLE)
{
regval[0] |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
}
else
{
regval[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
}
/* Enables or disables filtering on multicast address */
if (basicaddr->mcastfilter == S_ENABLE)
{
regval[0] |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
}
else
{
regval[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
}
/* Enables or disables filtering on broadcast address */
if (basicaddr->bcastfilter == S_ENABLE)
{
regval[0] |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
}
else
{
regval[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
}
/* Writes the new value on the PCKT_FLT_OPTIONS register */
ret = spirit_reg_write(spirit, PCKT_FLT_OPTIONS_BASE, &regval[0], 1);
/* Fills the array with the addresses passed in the structure */
regval[0] = basicaddr->bcastaddr;
regval[1] = basicaddr->mcastaddr;
regval[2] = basicaddr->srcaddr;
/* Writes values on the PCKT_FLT_GOALS registers */
return spirit_reg_write(spirit, PCKT_FLT_GOALS_BROADCAST_BASE, regval, 3);
}
/******************************************************************************
* Name: spirit_pktbasic_get_addrsetup
*
* Description:
* Returns the SPIRIT Basic packet addresses structure according to the
* specified parameters in the registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* basicaddr - Basic packet addresses init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_get_addrsetup(FAR struct spirit_library_s *spirit,
FAR struct pktbasic_addr_s *basicaddr)
{
uint8_t regval[3];
int ret;
/* Reads values on the PCKT_FLT_GOALS registers */
ret = spirit_reg_read(spirit, PCKT_FLT_GOALS_BROADCAST_BASE, regval, 3);
if (ret >= 0)
{
/* Fit the structure with the read addresses */
basicaddr->bcastaddr = regval[0];
basicaddr->mcastaddr = regval[1];
basicaddr->srcaddr = regval[2];
ret = spirit_reg_read(spirit, PCKT_FLT_OPTIONS_BASE, &regval[0], 1);
if (ret >= 0)
{
/* Fit the structure with the read filtering bits */
basicaddr->bcastfilter =
(enum spirit_functional_state_e)((regval[0] >> 1) & 0x01);
basicaddr->mcastfilter =
(enum spirit_functional_state_e)((regval[0] >> 2) & 0x01);
basicaddr->destfilter =
(enum spirit_functional_state_e)((regval[0] >> 3) & 0x01);
}
}
return ret;
}
/******************************************************************************
* Name: spirit_pktbasic_set_format
*
* Description:
* Configures the Basic packet format as packet used by SPIRIT.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbasic_set_format(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
int ret;
/* Reads the register value */
ret = spirit_reg_read(spirit, PCKTCTRL3_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the new value. Also set to 0 the direct RX mode bits */
regval &= 0x0f;
regval |= (uint8_t) PCKTCTRL3_PCKT_FRMT_BASIC;
/* Write the value to the PCKTCTRL3 register */
ret = spirit_reg_write(spirit, PCKTCTRL3_BASE, &regval, 1);
}
if (ret >= 0)
{
/* Reads the PCKTCTRL1_BASE register */
ret = spirit_reg_read(spirit, PCKTCTRL1_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the new value. Set to 0 the direct TX mode bits */
regval &= 0xf3;
/* Write the value to the PCKTCTRL1 register */
ret = spirit_reg_write(spirit, PCKTCTRL1_BASE, &regval, 1);
}
}
if (ret >= 0)
{
/* Reads the PROTOCOL1 register */
ret = spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
if (ret >= 0)
{
/* Mask a reserved bit */
regval &= ~0x20;
/* Write the value to the register */
ret = spirit_reg_write(spirit, PROTOCOL1_BASE, &regval, 1);
}
}
return ret;
}
/******************************************************************************
* Name: spirit_pktbase_set_addrfield
*
* Description:
* Sets the address length for SPIRIT Basic packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* txdestaddr - Length of ADDRESS in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktbase_set_addrfield(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e txdestaddr)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(txdestaddr));
/* Reads the PCKTCTRL4 register value */
ret = spirit_reg_read(spirit, PCKTCTRL4_BASE, &regval, 1);
if (ret >= 0)
{
/* Build the address length for the register */
if (txdestaddr == S_ENABLE)
{
regval |= 0x08;
}
else
{
regval &= 0x07;
}
/* Writes the new value on the PCKTCTRL4 register */
ret = spirit_reg_write(spirit, PCKTCTRL4_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_pktbase_get_addrfield
*
@ -293,6 +631,46 @@ int spirit_pktbasic_set_payloadlen(FAR struct spirit_library_s *spirit,
return spirit_reg_write(spirit, PCKTLEN1_BASE, regval, 2);
}
/******************************************************************************
* Name: spirit_pktbase_get_payloadlen
*
* Description:
* Returns the payload length for SPIRIT Basic packets. Since the packet
* length depends from the address and the control field size, this function
* reads the correspondent registers in order to determine the correct
* payload length to be returned.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Payload length in bytes.
*
******************************************************************************/
uint16_t spirit_pktbase_get_payloadlen(FAR struct spirit_library_s *spirit)
{
uint8_t regval[2];
uint16_t oversize = 0;
/* Computes the oversize (address + control) size */
if (spirit_pktbase_get_addrfield(spirit))
{
oversize = 1;
}
oversize += (uint16_t)spirit_pktcommon_get_controllen(spirit);
/* Reads the packet length registers */
(void)spirit_reg_read(spirit, PCKTLEN1_BASE, regval, 2);
/* Returns the packet length */
return ((((uint16_t) regval[0]) << 8) + (uint16_t) regval[1]) - oversize;
}
/******************************************************************************
* Name: spirit_pktbasic_rxpktlen
*
@ -329,3 +707,82 @@ uint16_t spirit_pktbasic_rxpktlen(FAR struct spirit_library_s *spirit)
return (((((uint16_t) regval[0]) << 8) + (uint16_t)regval[1]) - oversize);
}
/******************************************************************************
* Name: spirit_pktbasic_set_varlen
*
* Description:
* Computes and sets the variable payload length for SPIRIT Basic packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* payloadlen - Payload length in bytes.
* txdestaddr - Enable or Disable Address Field.
* ctrllen - Control length in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value is returned on any failure.
*
******************************************************************************/
int spirit_pktbasic_set_varlen(FAR struct spirit_library_s *spirit,
uint16_t payloadlen,
enum spirit_functional_state_e txdestaddr,
enum pkt_ctrllen_e ctrllen)
{
uint32_t pktlen;
uint8_t regval;
uint8_t addrlen;
int ret;
int i;
/* Sets the address length according to txdestaddr */
if (txdestaddr == S_ENABLE)
{
addrlen = 1;
}
else
{
addrlen = 0;
}
/* packet length = payload length + address length + control length */
pktlen = payloadlen + addrlen + ctrllen;
/* Computes the number of bits */
for (i = 0; i < 16; i++)
{
if (pktlen == 0)
{
break;
}
pktlen >>= 1;
}
if (i == 0)
{
i = 1;
}
/* Reads the PCKTCTRL3 register value */
ret = spirit_reg_read(spirit, PCKTCTRL3_BASE, &regval, 1);
if (ret >= 0)
{
/* Build value for the length width */
regval &= ~PCKTCTRL3_LEN_WID_MASK;
regval |= (uint8_t)(i - 1);
/* Write to the PCKTCTRL3 register value */
ret = spirit_reg_write(spirit, PCKTCTRL3_BASE, &regval, 1);
}
return ret;
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* drivers/wireless/spirit/spirit_pktcommon.c
* drivers/wireless/spirit/lib/spirit_pktcommon.c
* Configuration and management of the common features of SPIRIT packets.
*
* Copyright(c) 2015 STMicroelectronics

View file

@ -0,0 +1,420 @@
/******************************************************************************
* drivers/wireless/spirit/spirit_pktmbus.c
* Configuration and management of SPIRIT MBUS packets.
*
* Copyright(c) 2015 STMicroelectronics
* Author: VMA division - AMS
* Version 3.2.2 08-July-2015
*
* Adapted for NuttX by:
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
/******************************************************************************
* Included Files
******************************************************************************/
#include <assert.h>
#include "spirit_pktmbus.h"
#include "spirit_radio.h"
#include "spirit_spi.h"
/******************************************************************************
* Public Functions
******************************************************************************/
/******************************************************************************
* Name: spirit_pktmbus_initialize
*
* Description:
* Initializes the SPIRIT MBUS packet according to the specified parameters
* in the struct spirit_pktmbus_init_s structure.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* mbusinit - Pointer to a struct spirit_pktmbus_init_s structure that
* contains the configuration information for the specified
* SPIRIT MBUS PACKET FORMAT.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_initialize(FAR struct spirit_library_s *spirit,
FAR const struct spirit_pktmbus_init_s *mbusinit)
{
uint8_t regval[3];
/* Check the parameters */
DEBUGASSERT(IS_MBUS_SUBMODE(mbusinit->submode));
/* Packet format config */
spirit_pktmbus_set_format(spirit);
spirit_pktcommon_enable_crcfilter(spirit, S_DISABLE);
spirit_radio_enable_csblanking(spirit, S_ENABLE);
/* Preamble, postamble and submode config */
regval[0] = mbusinit->preamblen;
regval[1] = mbusinit->postamblen;
regval[2] = (uint8_t) mbusinit->submode;
/* Writes the new values on the MBUS_PRMBL registers */
return spirit_reg_write(spirit, MBUS_PRMBL_BASE, regval, 3);
}
/******************************************************************************
* Name: spirit_pktmbus_get_setup
*
* Description:
* Returns the SPIRIT MBUS packet structure according to the specified
* parameters in the registers.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* mbusinit - MBUS packet init structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_get_setup(FAR struct spirit_library_s *spirit,
FAR struct spirit_pktmbus_init_s *mbusinit)
{
uint8_t regval[3];
int ret;
/* Reads the MBUS regs value */
ret = spirit_reg_read(spirit, MBUS_PRMBL_BASE, regval, 3);
if (ret >= 0)
{
/* Fit the structure */
mbusinit->preamblen = regval[0];
mbusinit->postamblen = regval[1];
mbusinit->submode = (enum spirit_mbus_submode_e) (regval[2] & 0x0E);
}
return ret;
}
/******************************************************************************
* Name: spirit_pktmbus_set_format
*
* Description:
* Configures the MBUS packet format as the one used by SPIRIT.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_format(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
int ret;
/* Reads the PCKTCTRL3 register value */
ret = spirit_reg_read(spirit, PCKTCTRL3_BASE, &regval, 1);
if (ret < 0)
{
return ret;
}
/* Sets format bits. Also set to 0 the direct RX mode bits */
regval &= 0x0F;
regval |= ((uint8_t) PCKTCTRL3_PCKT_FRMT_MBUS);
/* Writes value on the PCKTCTRL3 register */
ret = spirit_reg_write(spirit, PCKTCTRL3_BASE, &regval, 1);
if (ret < 0)
{
return ret;
}
/* Reads the PCKTCTRL1 register value */
ret = spirit_reg_read(spirit, PCKTCTRL1_BASE, &regval, 1);
if (ret < 0)
{
return ret;
}
/* Build the new value. Set to 0 the direct TX mode bits */
regval &= 0xf3;
/* Writes the value on the PCKTCTRL1 register */
ret = spirit_reg_write(spirit, PCKTCTRL1_BASE, &regval, 1);
if (ret < 0)
{
return ret;
}
/* Reads the PROTOCOL1 register */
ret = spirit_reg_read(spirit, PROTOCOL1_BASE, &regval, 1);
if (ret < 0)
{
return ret;
}
/* Mask a reserved bit */
regval &= ~0x20;
/* Writes the value on the PROTOCOL1 register */
return spirit_reg_write(spirit, PROTOCOL1_BASE, &regval, 1);
}
/******************************************************************************
* Name: spirit_pktmbus_set_preamble
*
* Description:
* Sets how many chip sequence 01 shall be added in the preamble respect
* to the minimum value as defined according to the specified sub-mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* preamble - The number of chip sequence.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_preamble(FAR struct spirit_library_s *spirit,
uint8_t preamble)
{
/* Modifies the MBUS_PRMBL register value */
return spirit_reg_write(spirit, MBUS_PRMBL_BASE, &preamble, 1);
}
/******************************************************************************
* Name: spirit_pktmbus_get_preamble
*
* Description:
* Returns how many chip sequence "01" are added in the preamble respect to
* the minimum value as defined according to the specified sub-mode.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Preable in number of "01" chip sequences.
*
******************************************************************************/
uint8_t spirit_pktmbus_get_preamble(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Modifies the MBUS_PRMBL register value */
(void)spirit_reg_read(spirit, MBUS_PRMBL_BASE, &regval, 1);
/* Return value */
return regval;
}
/******************************************************************************
* Name: spirit_pktmbus_set_postamble
*
* Description:
* Sets how many chip sequence 01 will be used in postamble
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* postamble - The number of chip sequence.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_postamble(FAR struct spirit_library_s *spirit,
uint8_t postamble)
{
/* Modifies the MBUS_PSTMBL register value */
return spirit_reg_write(spirit, MBUS_PSTMBL_BASE, &postamble, 1);
}
/******************************************************************************
* Name:
*
* Description:
* Returns how many chip sequence "01" are used in the postamble
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Postamble in number of "01" chip sequences.
*
******************************************************************************/
uint8_t spirit_pktmbus_get_postamble(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the MBUS_PSTMBL register */
(void)spirit_reg_read(spirit, MBUS_PSTMBL_BASE, &regval, 1);
/* Returns value */
return regval;
}
/******************************************************************************
* Name:
*
* Description:
* Sets the MBUS submode used.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* submode - The submode used.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_submode(FAR struct spirit_library_s *spirit,
enum spirit_mbus_submode_e submode)
{
/* Modifies the MBUS_CTRL register value */
return spirit_reg_write(spirit, MBUS_CTRL_BASE, (FAR uint8_t *)submode, 1);
}
/******************************************************************************
* Name: spirit_pktmbus_get_submode
*
* Description:
* Returns the MBUS submode used.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* MBUS submode.
*
******************************************************************************/
enum spirit_mbus_submode_e
spirit_pktmbus_get_submode(FAR struct spirit_library_s *spirit)
{
uint8_t regval;
/* Reads the MBUS_CTRL register value */
(void)spirit_reg_read(spirit, MBUS_CTRL_BASE, &regval, 1);
/* Returns value */
return (enum spirit_mbus_submode_e) regval;
}
/******************************************************************************
* Name: spirit_pktmbus_set_payloadlen
*
* Description:
* Sets the payload length for SPIRIT MBUS packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* payloadlen - Payload length in bytes.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_pktmbus_set_payloadlen(FAR struct spirit_library_s *spirit,
uint16_t payloadlen)
{
uint8_t regval[2];
/* Computes PCKTLEN0 value from payloadlen */
regval[1] = BUILD_PCKTLEN0(payloadlen);
/* Computes PCKTLEN1 value from payloadlen */
regval[0] = BUILD_PCKTLEN1(payloadlen);
/* Writes data on the PCKTLEN1/0 register */
return spirit_reg_write(spirit, PCKTLEN1_BASE, regval, 2);
}
/******************************************************************************
* Name: spirit_pktmbus_get_payloadlen
*
* Description:
* Returns the payload length for SPIRIT MBUS packets.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
*
* Returned Value:
* Payload length in bytes.
*
******************************************************************************/
uint16_t spirit_pktmbus_get_payloadlen(FAR struct spirit_library_s *spirit)
{
uint8_t regval[2];
/* Reads the packet length registers */
(void)spirit_reg_read(spirit, PCKTLEN1_BASE, regval, 2);
/* Returns the packet length */
return ((((uint16_t)regval[0]) << 8) + (uint16_t)regval[1]);
}

View file

@ -1714,6 +1714,54 @@ int spirit_radio_afcfreezeonsync(FAR struct spirit_library_s *spirit,
return ret;
}
/******************************************************************************
* Name: spirit_radio_enable_csblanking
*
* Description:
* Enables or Disables the received data blanking when the CS is under the
* threshold.
*
* Input Parameters:
* spirit - Reference to a Spirit library state structure instance
* newstate - New state of this mode.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
******************************************************************************/
int spirit_radio_enable_csblanking(FAR struct spirit_library_s *spirit,
enum spirit_functional_state_e newstate)
{
uint8_t regval;
int ret;
/* Check the parameters */
DEBUGASSERT(IS_SPIRIT_FUNCTIONAL_STATE(newstate));
/* Reads the ANT_SELECT_CONF_BASE and mask the CS_BLANKING BIT field */
ret = spirit_reg_read(spirit, ANT_SELECT_CONF_BASE, &regval, 1);
if (ret >= 0)
{
if (newstate == S_ENABLE)
{
regval |= ANT_SELECT_CS_BLANKING_MASK;
}
else
{
regval &= (~ANT_SELECT_CS_BLANKING_MASK);
}
/* Write the new value to the ANT_SELECT_CONF register */
ret = spirit_reg_write(spirit, ANT_SELECT_CONF_BASE, &regval, 1);
}
return ret;
}
/******************************************************************************
* Name: spirit_radio_persistentrx
*