Contiki-NG
enc28j60-arch-spi.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, CETIC.
3 * Copyright (c) 2016, Zolertia <http://www.zolertia.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32/*---------------------------------------------------------------------------*/
33/**
34 * \addtogroup zolertia-orion-ethernet-router
35 * @{
36 *
37 * \defgroup zolertia-eth-arch-spi Zolertia ENC28J60 SPI arch
38 *
39 * ENC28J60 eth-gw SPI arch specifics
40 * @{
41 *
42 * \file
43 * eth-gw SPI arch specifics
44 */
45/*---------------------------------------------------------------------------*/
46#include "dev/spi-arch-legacy.h"
47#include "dev/spi-legacy.h"
48#include "dev/gpio.h"
49/*---------------------------------------------------------------------------*/
50#define RESET_PORT GPIO_PORT_TO_BASE(ETH_RESET_PORT)
51#define RESET_BIT GPIO_PIN_MASK(ETH_RESET_PIN)
52/*---------------------------------------------------------------------------*/
53void
54enc28j60_arch_spi_init(void)
55{
56 spix_init(ETH_SPI_INSTANCE);
57 spix_cs_init(ETH_SPI_CSN_PORT, ETH_SPI_CSN_PIN);
58 spix_set_mode(ETH_SPI_INSTANCE, SSI_CR0_FRF_MOTOROLA, 0, 0, 8);
59 GPIO_SOFTWARE_CONTROL(RESET_PORT, RESET_BIT);
60 GPIO_SET_OUTPUT(RESET_PORT, RESET_BIT);
61 GPIO_SET_INPUT(RESET_PORT, RESET_BIT);
62}
63/*---------------------------------------------------------------------------*/
64void
65enc28j60_arch_spi_select(void)
66{
67 SPIX_CS_CLR(ETH_SPI_CSN_PORT, ETH_SPI_CSN_PIN);
68}
69/*---------------------------------------------------------------------------*/
70void
71enc28j60_arch_spi_deselect(void)
72{
73 SPIX_CS_SET(ETH_SPI_CSN_PORT, ETH_SPI_CSN_PIN);
74}
75/*---------------------------------------------------------------------------*/
76void
77enc28j60_arch_spi_write(uint8_t output)
78{
79 SPIX_WAITFORTxREADY(ETH_SPI_INSTANCE);
80 SPIX_BUF(ETH_SPI_INSTANCE) = output;
81 SPIX_WAITFOREOTx(ETH_SPI_INSTANCE);
82 SPIX_WAITFOREORx(ETH_SPI_INSTANCE);
83 uint32_t dummy = SPIX_BUF(ETH_SPI_INSTANCE);
84 (void) dummy;
85}
86/*---------------------------------------------------------------------------*/
87uint8_t
88enc28j60_arch_spi_read(void)
89{
90 SPIX_WAITFORTxREADY(ETH_SPI_INSTANCE);
91 SPIX_BUF(ETH_SPI_INSTANCE) = 0;
92 SPIX_WAITFOREOTx(ETH_SPI_INSTANCE);
93 SPIX_WAITFOREORx(ETH_SPI_INSTANCE);
94 return SPIX_BUF(ETH_SPI_INSTANCE);
95}
96/*---------------------------------------------------------------------------*/
97/**
98 * @}
99 * @}
100 */
101
Header file with register and macro declarations for the cc2538 GPIO module.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE.
Definition: gpio.h:258
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
Definition: gpio.h:78
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
Definition: gpio.h:85
void spix_set_mode(uint8_t spi, uint32_t frame_format, uint32_t clock_polarity, uint32_t clock_phase, uint32_t data_size)
Configure the SPI data and clock polarity and the data size for the instance given.
Definition: spi-legacy.c:295
#define SSI_CR0_FRF_MOTOROLA
Motorola frame format.
Definition: ssi.h:156
void spix_init(uint8_t spi)
Initialize the SPI bus for the instance given.
Definition: spi-legacy.c:213
void spix_cs_init(uint8_t port, uint8_t pin)
Configure a GPIO to be the chip select pin.
Definition: spi-legacy.c:354
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
Definition: sicslowpan.c:1606
Header file for the cc2538 SPI driver, including macros for the implementation of the low-level SPI p...
Basic SPI macros.