Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
3edc40e4
You need to sign in or sign up before continuing.
Commit
3edc40e4
authored
9 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
drivers: nrf24l01p: use xtimer
parent
e934063b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
drivers/nrf24l01p/include/nrf24l01p_settings.h
+7
-7
7 additions, 7 deletions
drivers/nrf24l01p/include/nrf24l01p_settings.h
drivers/nrf24l01p/nrf24l01p.c
+48
-48
48 additions, 48 deletions
drivers/nrf24l01p/nrf24l01p.c
with
55 additions
and
55 deletions
drivers/nrf24l01p/include/nrf24l01p_settings.h
+
7
−
7
View file @
3edc40e4
...
...
@@ -31,18 +31,18 @@ extern "C" {
#define INITIAL_RF_CHANNEL 5
#define INITIAL_RX_POWER_0dB 0
#define DELAY_CS_TOGGLE_TICKS
2
#define DELAY_AFTER_FUNC_TICKS
2
#define DELAY_CE_HIGH
_US
HWTIMER_TICKS
(20)
#define DELAY_CHANGE_PWR_MODE
_US
HWTIMER_TICKS
(1500)
#define DELAY_CHANGE_TXRX
_US
HWTIMER_TICKS
(130)
#define DELAY_CE_START
_US
HWTIMER_TICKS
(5)
#define DELAY_CS_TOGGLE_TICKS 2
#define DELAY_AFTER_FUNC_TICKS 2
#define DELAY_CE_HIGH (20)
#define DELAY_CHANGE_PWR_MODE (1500)
#define DELAY_CHANGE_TXRX (130)
#define DELAY_CE_START (5)
/*
* This is the time which is needed to physically transmit the data.
* Compare nrf24l01+ pruduct specification p.42. It is computed just
* for this setup
*/
#define DELAY_DATA_ON_AIR
HWTIMER_TICKS
(1300)
#define DELAY_DATA_ON_AIR (1300)
#define CMD_R_REGISTER 0x00
...
...
This diff is collapsed.
Click to expand it.
drivers/nrf24l01p/nrf24l01p.c
+
48
−
48
View file @
3edc40e4
...
...
@@ -18,7 +18,7 @@
#include
"mutex.h"
#include
"periph/gpio.h"
#include
"periph/spi.h"
#include
"
hw
timer.h"
#include
"
x
timer.h"
#include
"thread.h"
#include
"msg.h"
...
...
@@ -34,14 +34,14 @@ int nrf24l01p_read_reg(nrf24l01p_t *dev, char reg, char *answer)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_reg
(
dev
->
spi
,
(
CMD_R_REGISTER
|
(
REGISTER_MASK
&
reg
)),
CMD_NOP
,
answer
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
@@ -54,14 +54,14 @@ int nrf24l01p_write_reg(nrf24l01p_t *dev, char reg, char write)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_reg
(
dev
->
spi
,
(
CMD_W_REGISTER
|
(
REGISTER_MASK
&
reg
)),
write
,
&
reg_content
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
@@ -100,7 +100,7 @@ int nrf24l01p_init(nrf24l01p_t *dev, spi_t spi, gpio_t ce, gpio_t cs, gpio_t irq
return
status
;
}
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
/* Flush TX FIFIO */
status
=
nrf24l01p_flush_tx_fifo
(
dev
);
...
...
@@ -204,7 +204,7 @@ int nrf24l01p_on(nrf24l01p_t *dev)
nrf24l01p_read_reg
(
dev
,
REG_CONFIG
,
&
read
);
status
=
nrf24l01p_write_reg
(
dev
,
REG_CONFIG
,
(
read
|
PWR_UP
));
hw
timer_
wait
(
DELAY_CHANGE_PWR_MODE_US
);
x
timer_
usleep
(
DELAY_CHANGE_PWR_MODE_US
);
return
status
;
}
...
...
@@ -217,7 +217,7 @@ int nrf24l01p_off(nrf24l01p_t *dev)
nrf24l01p_read_reg
(
dev
,
REG_CONFIG
,
&
read
);
status
=
nrf24l01p_write_reg
(
dev
,
REG_CONFIG
,
(
read
&
~
PWR_UP
));
hw
timer_
wait
(
DELAY_CHANGE_PWR_MODE_US
);
x
timer_
usleep
(
DELAY_CHANGE_PWR_MODE_US
);
return
status
;
}
...
...
@@ -225,10 +225,10 @@ int nrf24l01p_off(nrf24l01p_t *dev)
void
nrf24l01p_transmit
(
nrf24l01p_t
*
dev
)
{
gpio_set
(
dev
->
ce
);
hw
timer_
wait
(
DELAY_CE_HIGH_US
);
/* at least 10 us high */
x
timer_
usleep
(
DELAY_CE_HIGH_US
);
/* at least 10 us high */
gpio_clear
(
dev
->
ce
);
hw
timer_spin
(
DELAY_CHANGE_TXRX_US
);
x
timer_spin
(
DELAY_CHANGE_TXRX_US
);
}
int
nrf24l01p_read_payload
(
nrf24l01p_t
*
dev
,
char
*
answer
,
unsigned
int
size
)
...
...
@@ -238,11 +238,11 @@ int nrf24l01p_read_payload(nrf24l01p_t *dev, char *answer, unsigned int size)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
CMD_R_RX_PAYLOAD
,
0
,
answer
,
size
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
...
...
@@ -273,12 +273,12 @@ void nrf24l01p_get_id(nrf24l01p_t *dev, unsigned int *pid)
void
nrf24l01p_start
(
nrf24l01p_t
*
dev
)
{
gpio_set
(
dev
->
ce
);
hw
timer_
wait
(
DELAY_CE_START_US
);
x
timer_
usleep
(
DELAY_CE_START_US
);
}
void
nrf24l01p_stop
(
nrf24l01p_t
*
dev
)
{
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_clear
(
dev
->
ce
);
}
...
...
@@ -291,14 +291,14 @@ int nrf24l01p_preload(nrf24l01p_t *dev, char *data, unsigned int size)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
CMD_W_TX_PAYLOAD
,
data
,
NULL
,
size
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
@@ -318,7 +318,7 @@ int nrf24l01p_set_address_width(nrf24l01p_t *dev, nrf24l01p_aw_t aw)
char
aw_setup
;
nrf24l01p_read_reg
(
dev
,
REG_SETUP_AW
,
&
aw_setup
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
switch
(
aw
)
{
case
NRF24L01P_AW_3BYTE
:
...
...
@@ -396,14 +396,14 @@ int nrf24l01p_set_tx_address(nrf24l01p_t *dev, char *saddr, unsigned int length)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
(
CMD_W_REGISTER
|
(
REGISTER_MASK
&
REG_TX_ADDR
)),
saddr
,
NULL
,
length
);
/* address width is 5 byte */
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
@@ -427,14 +427,14 @@ int nrf24l01p_set_tx_address_long(nrf24l01p_t *dev, uint64_t saddr, unsigned int
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
(
CMD_W_REGISTER
|
(
REGISTER_MASK
&
REG_TX_ADDR
)),
buf
,
NULL
,
length
);
/* address width is 5 byte */
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
@@ -448,20 +448,20 @@ uint64_t nrf24l01p_get_tx_address_long(nrf24l01p_t *dev)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
(
CMD_R_REGISTER
|
(
REGISTER_MASK
&
REG_TX_ADDR
)),
0
,
addr_array
,
INITIAL_ADDRESS_WIDTH
);
/* address width is 5 byte */
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
if
(
status
<
0
)
{
return
-
1
;
}
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
for
(
int
i
=
0
;
i
<
INITIAL_ADDRESS_WIDTH
;
i
++
)
{
saddr_64
|=
(((
uint64_t
)
addr_array
[
i
])
<<
(
8
*
(
INITIAL_ADDRESS_WIDTH
-
i
-
1
)));
...
...
@@ -508,14 +508,14 @@ int nrf24l01p_set_rx_address(nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, char *s
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
(
CMD_W_REGISTER
|
(
REGISTER_MASK
&
pipe_addr
)),
saddr
,
NULL
,
length
);
/* address width is 5 byte */
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
/* Enable this pipe */
nrf24l01p_enable_pipe
(
dev
,
pipe
);
...
...
@@ -580,9 +580,9 @@ uint64_t nrf24l01p_get_rx_address_long(nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pip
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_regs
(
dev
->
spi
,
(
CMD_R_REGISTER
|
(
REGISTER_MASK
&
pipe_addr
)),
0
,
addr_array
,
INITIAL_ADDRESS_WIDTH
);
/* address width is 5 byte */
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
...
...
@@ -591,7 +591,7 @@ uint64_t nrf24l01p_get_rx_address_long(nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pip
return
-
1
;
}
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
for
(
int
i
=
0
;
i
<
INITIAL_ADDRESS_WIDTH
;
i
++
)
{
saddr_64
|=
(((
uint64_t
)
addr_array
[
i
])
<<
(
8
*
(
INITIAL_ADDRESS_WIDTH
-
i
-
1
)));
...
...
@@ -635,14 +635,14 @@ int nrf24l01p_get_status(nrf24l01p_t *dev)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
spi_transfer_byte
(
dev
->
spi
,
CMD_NOP
,
&
status
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
(
int
)
status
;
}
...
...
@@ -717,7 +717,7 @@ int nrf24l01p_set_txmode(nrf24l01p_t *dev)
conf
&=
~
(
PRIM_RX
);
status
=
nrf24l01p_write_reg
(
dev
,
REG_CONFIG
,
conf
);
hw
timer_
wait
(
DELAY_CHANGE_TXRX_US
);
x
timer_
usleep
(
DELAY_CHANGE_TXRX_US
);
return
status
;
}
...
...
@@ -738,7 +738,7 @@ int nrf24l01p_set_rxmode(nrf24l01p_t *dev)
nrf24l01p_start
(
dev
);
hw
timer_
wait
(
DELAY_CHANGE_TXRX_US
);
x
timer_
usleep
(
DELAY_CHANGE_TXRX_US
);
return
status
;
}
...
...
@@ -874,14 +874,14 @@ int nrf24l01p_flush_tx_fifo(nrf24l01p_t *dev)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_byte
(
dev
->
spi
,
CMD_FLUSH_TX
,
&
reg_content
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
@@ -894,14 +894,14 @@ int nrf24l01p_flush_rx_fifo(nrf24l01p_t *dev)
/* Acquire exclusive access to the bus. */
spi_acquire
(
dev
->
spi
);
gpio_clear
(
dev
->
cs
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
status
=
spi_transfer_byte
(
dev
->
spi
,
CMD_FLUSH_RX
,
&
reg_content
);
hw
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
x
timer_spin
(
DELAY_CS_TOGGLE_TICKS
);
gpio_set
(
dev
->
cs
);
/* Release the bus for other threads. */
spi_release
(
dev
->
spi
);
hw
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
x
timer_spin
(
DELAY_AFTER_FUNC_TICKS
);
return
status
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment