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
574b565e
Commit
574b565e
authored
8 years ago
by
Kees Bakker
Browse files
Options
Downloads
Patches
Plain Diff
cpu/samd21: add helper functions spi_power_on/off
parent
2a4655b6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/samd21/periph/spi.c
+43
-15
43 additions, 15 deletions
cpu/samd21/periph/spi.c
with
43 additions
and
15 deletions
cpu/samd21/periph/spi.c
+
43
−
15
View file @
574b565e
...
...
@@ -31,6 +31,16 @@
#include
"debug.h"
#if SPI_0_EN || SPI_1_EN
/**
* @brief Internal helper function to do the actual work for spi_poweroff
*/
static
void
_spi_poweroff
(
SercomSpi
*
spi_dev
);
/**
* @brief Internal helper function to do the actual work for spi_poweron
*/
static
void
_spi_poweron
(
SercomSpi
*
spi_dev
);
/**
* @brief Array holding one pre-initialized mutex for each SPI device
*/
...
...
@@ -177,8 +187,10 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
default:
return
-
1
;
}
spi_dev
->
CTRLA
.
bit
.
ENABLE
=
0
;
/* Disable spi to write confs */
while
(
spi_dev
->
SYNCBUSY
.
reg
)
{}
/* Disable spi to write confs */
_spi_poweroff
(
spi_dev
);
spi_dev
->
CTRLA
.
reg
|=
SERCOM_SPI_CTRLA_MODE_SPI_MASTER
;
while
(
spi_dev
->
SYNCBUSY
.
reg
)
{}
...
...
@@ -193,7 +205,9 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
while
(
spi_dev
->
SYNCBUSY
.
reg
)
{}
spi_dev
->
CTRLB
.
reg
=
(
SERCOM_SPI_CTRLB_CHSIZE
(
0
)
|
SERCOM_SPI_CTRLB_RXEN
);
while
(
spi_dev
->
SYNCBUSY
.
reg
)
{}
spi_poweron
(
dev
);
/* enable */
_spi_poweron
(
spi_dev
);
return
0
;
}
...
...
@@ -258,37 +272,51 @@ int spi_transfer_byte(spi_t dev, char out, char *in)
return
1
;
}
static
void
_spi_poweron
(
SercomSpi
*
spi_dev
)
{
if
(
spi_dev
==
NULL
)
{
return
;
}
spi_dev
->
CTRLA
.
reg
|=
SERCOM_SPI_CTRLA_ENABLE
;
while
(
spi_dev
->
SYNCBUSY
.
bit
.
ENABLE
)
{}
}
void
spi_poweron
(
spi_t
dev
)
{
switch
(
dev
)
{
#if
def
SPI_0_EN
#if SPI_0_EN
case
SPI_0
:
SPI_0_DEV
.
CTRLA
.
reg
|=
SERCOM_SPI_CTRLA_ENABLE
;
while
(
SPI_0_DEV
.
SYNCBUSY
.
bit
.
ENABLE
)
{}
_spi_poweron
(
&
SPI_0_DEV
);
break
;
#endif
#if
def
SPI_1_EN
#if SPI_1_EN
case
SPI_1
:
SPI_1_DEV
.
CTRLA
.
reg
|=
SERCOM_SPI_CTRLA_ENABLE
;
while
(
SPI_1_DEV
.
SYNCBUSY
.
bit
.
ENABLE
)
{}
_spi_poweron
(
&
SPI_1_DEV
);
break
;
#endif
}
}
static
void
_spi_poweroff
(
SercomSpi
*
spi_dev
)
{
if
(
spi_dev
==
NULL
)
{
return
;
}
spi_dev
->
CTRLA
.
bit
.
ENABLE
=
0
;
/* Disable spi */
while
(
spi_dev
->
SYNCBUSY
.
bit
.
ENABLE
)
{}
}
void
spi_poweroff
(
spi_t
dev
)
{
switch
(
dev
)
{
#if
def
SPI_0_EN
#if SPI_0_EN
case
SPI_0
:
SPI_0_DEV
.
CTRLA
.
bit
.
ENABLE
=
0
;
/* Disable spi */
while
(
SPI_0_DEV
.
SYNCBUSY
.
bit
.
ENABLE
)
{}
_spi_poweroff
(
&
SPI_0_DEV
);
break
;
#endif
#if
def
SPI_1_EN
#if SPI_1_EN
case
SPI_1
:
SPI_1_DEV
.
CTRLA
.
bit
.
ENABLE
=
0
;
/* Disable spi */
while
(
SPI_1_DEV
.
SYNCBUSY
.
bit
.
ENABLE
)
{}
_spi_poweroff
(
&
SPI_1_DEV
);
break
;
#endif
}
...
...
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