UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
cc112x_spi.c
1 #include "cc112x_spi.h"
2 #include <stdint.h>
3 
4 #include "../firmware.h"
5 
6 rfStatus_t cc112xSpiReadReg(uint8_t spi_device, uint16_t addr, uint8_t *data)
7 {
8  /* Decide what register space is accessed */
9  if((addr & 0xFF00) == 0x0000)
10  {
11  /* 8-bit register space */
12  return SPI_read8(spi_device, (uint8_t)(addr | 0x80), data);
13  }
14  else
15  {
16  /* 16-bit register space */
17  return SPI_read16(spi_device, (addr | 0x8000), data);
18  }
19 }
20 
21 rfStatus_t cc112xSpiWriteReg(uint8_t spi_device, uint16_t addr, uint8_t *data)
22 {
23  /* Decide what register space is accessed */
24  if((addr & 0xFF00) == 0x0000)
25  {
26  /* 8-bit register space */
27  return SPI_write8(spi_device, (uint8_t)(addr & 0x7F), data);
28  }
29  else
30  {
31  /* 16-bit register space */
32  return SPI_write16(spi_device, (addr & 0x7FFF), data);
33  }
34 }
35 
36 rfStatus_t cc112xSpiReadBurstReg(uint8_t spi_device, uint16_t addr, uint8_t *data, uint8_t len)
37 {
38  /* Decide what register space is accessed */
39  if((addr & 0xFF00) == 0x0000)
40  {
41  /* 8-bit register space */
42  return SPI_burstread8(spi_device, (uint8_t)(addr | 0x80), data, len);
43  }
44  else
45  {
46  /* 16-bit register space */
47  return SPI_burstread16(spi_device, (addr | 0x8000), data, len);
48  }
49 }
50 
51 rfStatus_t cc112xSpiWriteBurstReg(uint8_t spi_device, uint16_t addr, uint8_t *data, uint8_t len)
52 {
53  /* Decide what register space is accessed */
54  if((addr & 0xFF00) == 0x0000)
55  {
56  /* 8-bit register space */
57  return SPI_burstwrite8(spi_device, (uint8_t)(addr & 0x7F), data, len);
58  }
59  else
60  {
61  /* 16-bit register space */
62  return SPI_burstwrite16(spi_device, (addr & 0x7FFF), data, len);
63  }
64 }
65 
66 rfStatus_t cc112xSpiWriteTxFifo(uint8_t spi_device, uint8_t *data, uint8_t len)
67 {
68  return SPI_burstwrite8(spi_device, (CC112X_BURST_TXFIFO & 0x7F), data, len);
69 }
70 
71 rfStatus_t cc112xSpiReadRxFifo(uint8_t spi_device, uint8_t *data, uint8_t len)
72 {
73  return SPI_burstread8(spi_device, (CC112X_BURST_RXFIFO | 0x80), data, len);
74 }
75 
76 rfStatus_t cc112xGetTxStatus(uint8_t spi_device)
77 {
78  return SPI_cmd(spi_device, CC112X_SNOP);
79 }
80 
81 rfStatus_t cc112xGetRxStatus(uint8_t spi_device)
82 {
83  return SPI_cmd(spi_device, (CC112X_SNOP | 0x80));
84 }
uint8_t SPI_burstread8(uint8_t spi_num, uint8_t addr, uint8_t *data, uint32_t len)
Definition: spi.c:32
uint8_t SPI_burstwrite8(uint8_t spi_num, uint8_t addr, uint8_t *data, uint32_t len)
Definition: spi.c:51
uint8_t SPI_burstread16(uint8_t spi_num, uint16_t addr, uint8_t *data, uint32_t len)
Definition: spi.c:70
uint8_t SPI_cmd(uint8_t spi_num, uint8_t cmd)
Definition: spi.c:15
uint8_t SPI_write8(uint8_t spi_num, uint8_t addr, uint8_t *data)
Definition: spi.c:42
uint8_t SPI_burstwrite16(uint8_t spi_num, uint16_t addr, uint8_t *data, uint32_t len)
Definition: spi.c:89
uint8_t SPI_write16(uint8_t spi_num, uint16_t addr, uint8_t *data)
Definition: spi.c:80
uint8_t SPI_read8(uint8_t spi_num, uint8_t addr, uint8_t *data)
Definition: spi.c:23
uint8_t SPI_read16(uint8_t spi_num, uint16_t addr, uint8_t *data)
Definition: spi.c:61