CCxxxx Driver  0.0.1
ccx_api.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (c) 2017, Alan Barr
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *******************************************************************************/
32 #ifndef __CCX_API_H__
33 #define __CCX_API_H__
34 
35 #include <cc1100_cc2500.h>
36 #include <stddef.h>
37 #include <stdint.h>
38 /******************************************************************************/
47 /******************************************************************************/
48 
49 
50 #if CCX_LOG_ERRORS || defined(__DOXYGEN__)
51 
61 # define CCX_STATUS_LOG(_STATUS) _CCX_STATUS_LOG(_STATUS, __FILE__, __LINE__)
62 #else
63  /* Error logging not desired, do nothing */
64 # define CCX_STATUS_LOG(_STATUS)
65 #endif
66 
72 #define __CCX_STATUS_LOG(_STATUS, F, L) ccxErrorLog(_STATUS, F, #L)
73 
79 #define _CCX_STATUS_LOG(_STATUS, F, L) __CCX_STATUS_LOG(_STATUS, F, L)
80 
89 #define CCX_STATUS_CHECK(_STATEMENT, _STATUS) \
90 do { \
91  _STATUS = (_STATEMENT); \
92  if ((_STATUS) != CCX_OK) \
93  { \
94  CCX_STATUS_LOG(_STATUS); \
95  return _STATUS; \
96  } \
97 } while (0);
98 
109 #define CCX_STATUS_CHECK_CLEANUP(_STATEMENT, _STATUS, _CLEANUP) \
110 do { \
111  _STATUS = (_STATEMENT); \
112  if ((_STATUS) != CCX_OK) \
113  { \
114  CCX_STATUS_LOG(_STATUS); \
115  _CLEANUP; \
116  } \
117 } while (0);
118 
126 typedef enum {
136 } CcxStatus;
137 
138 
148 void ccxErrorLog(uint8_t status, char *file, char *line);
149 
150 
157 uint8_t ccxWriteByte(uint8_t address, uint8_t value);
158 
173 uint8_t ccxWriteBytes(uint8_t address,
174  const uint8_t *writeBuffer,
175  uint8_t writeBufferLength);
176 
187 uint8_t ccxStrobe(uint8_t strobeAddress);
188 
196 uint8_t ccxReadByte(uint8_t address, uint8_t *readByte);
197 
214 uint8_t ccxReadBytes(uint8_t startAddress,
215  uint8_t *readBuffer,
216  uint8_t readBufferLength);
217 
232 uint8_t ccxReadStatusRegister(uint8_t address,
233  uint8_t *readStatus);
234 
240 uint8_t ccxDelay25us(void);
241 
250 uint8_t ccxReset(void);
251 
258 uint8_t ccxInit(void);
259 
266 uint8_t ccxShutdown(void);
267 
268 
276 uint8_t ccxRunTests(void);
277 
278 /******************************************************************************/
280 /******************************************************************************/
281 
282 
283 #endif
Internal, unexpected error detected.
Definition: ccx_api.h:129
void ccxErrorLog(uint8_t status, char *file, char *line)
Optional error logging function.
uint8_t ccxInit(void)
Initialise the ccx module. This must be called prior to using any other function in this library...
Contains CCxxxx register and bitfield values See Registers: Normal, Registers: Status, Registers: Multibyte, Registers: Strobe Command.
CcxStatus
List of possible error return codes.
Definition: ccx_api.h:126
uint8_t ccxWriteBytes(uint8_t address, const uint8_t *writeBuffer, uint8_t writeBufferLength)
Write multiple bytes (oxtets) to the CCxxxx.
uint8_t ccxDelay25us(void)
Initiate a busy, blocking wait of 25 us.
uint8_t ccxStrobe(uint8_t strobeAddress)
Send a strobe to the CCxxx.
uint8_t ccxReadByte(uint8_t address, uint8_t *readByte)
Read a single byte from specified register.
No error, operational as expected.
Definition: ccx_api.h:127
One or more of the FIFOs are in error.
Definition: ccx_api.h:134
uint8_t ccxShutdown(void)
Shutdown the module. Can optionally be called when finished with using the module.
Device was in an unexpected state.
Definition: ccx_api.h:133
Communications timed out.
Definition: ccx_api.h:130
Sanity assert failed.
Definition: ccx_api.h:135
uint8_t ccxReset(void)
Initiate a software reset of the radio.
SPI error.
Definition: ccx_api.h:131
Bad value passed by API.
Definition: ccx_api.h:128
Received CRC was incorrect.
Definition: ccx_api.h:132
uint8_t ccxRunTests(void)
Run basic sanity tests to ensure communications between MCU and CCxxxx module are operating as expect...
uint8_t ccxReadBytes(uint8_t startAddress, uint8_t *readBuffer, uint8_t readBufferLength)
Read multiple bytes beginning at the specified register.
uint8_t ccxWriteByte(uint8_t address, uint8_t value)
Write a single byte (octet) to the CCxxxx.
uint8_t ccxReadStatusRegister(uint8_t address, uint8_t *readStatus)
Read a single byte from a status register.