Add some missing function attributes.

This commit is contained in:
Dean Camera 2013-04-11 17:39:00 +00:00
parent d5e84db5ab
commit 334f70aa80
12 changed files with 74 additions and 52 deletions

View file

@ -56,17 +56,17 @@
* // Initialize the SPI driver before first use
* SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING |
* SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
*
*
* // Send several bytes, ignoring the returned data
* SPI_SendByte(0x01);
* SPI_SendByte(0x02);
* SPI_SendByte(0x03);
*
*
* // Receive several bytes, sending a dummy 0x00 byte each time
* uint8_t Byte1 = SPI_ReceiveByte();
* uint8_t Byte2 = SPI_ReceiveByte();
* uint8_t Byte3 = SPI_ReceiveByte();
*
*
* // Send a byte, and store the received byte from the same transaction
* uint8_t ResponseByte = SPI_TransferByte(0xDC);
* \endcode
@ -165,6 +165,7 @@
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the \c SPI_SPEED_*,
* \c SPI_SCK_*, \c SPI_SAMPLE_*, \c SPI_ORDER_* and \c SPI_MODE_* masks.
*/
static inline void SPI_Init(const uint8_t SPIOptions);
static inline void SPI_Init(const uint8_t SPIOptions)
{
/* Prevent high rise times on PB.0 (/SS) from forcing a change to SPI slave mode */
@ -187,6 +188,7 @@
}
/** Turns off the SPI driver, disabling and returning used hardware to their default configuration. */
static inline void SPI_Disable(void);
static inline void SPI_Disable(void)
{
DDRB &= ~((1 << 1) | (1 << 2));

View file

@ -201,8 +201,10 @@
* \param[in] Prescale Prescaler to use when determining the bus frequency, a \c TWI_BIT_PRESCALE_* value.
* \param[in] BitLength Length of the bits sent on the bus.
*/
static inline void TWI_Init(const uint8_t Prescale, const uint8_t BitLength) ATTR_ALWAYS_INLINE;
static inline void TWI_Init(const uint8_t Prescale, const uint8_t BitLength)
static inline void TWI_Init(const uint8_t Prescale,
const uint8_t BitLength) ATTR_ALWAYS_INLINE;
static inline void TWI_Init(const uint8_t Prescale,
const uint8_t BitLength)
{
TWCR |= (1 << TWEN);
TWSR = Prescale;

View file

@ -53,17 +53,17 @@
* SPI_Init(&SPIC,
* SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING |
* SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
*
*
* // Send several bytes, ignoring the returned data
* SPI_SendByte(&SPIC, 0x01);
* SPI_SendByte(&SPIC, 0x02);
* SPI_SendByte(&SPIC, 0x03);
*
*
* // Receive several bytes, sending a dummy 0x00 byte each time
* uint8_t Byte1 = SPI_ReceiveByte(&SPIC);
* uint8_t Byte2 = SPI_ReceiveByte(&SPIC);
* uint8_t Byte3 = SPI_ReceiveByte(&SPIC);
*
*
* // Send a byte, and store the received byte from the same transaction
* uint8_t ResponseByte = SPI_TransferByte(&SPIC, 0xDC);
* \endcode
@ -163,6 +163,8 @@
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the \c SPI_SPEED_*,
* \c SPI_SCK_*, \c SPI_SAMPLE_*, \c SPI_ORDER_* and \c SPI_MODE_* masks.
*/
static inline void SPI_Init(SPI_t* const SPI,
const uint8_t SPIOptions) ATTR_NON_NULL_PTR_ARG(1);
static inline void SPI_Init(SPI_t* const SPI,
const uint8_t SPIOptions)
{
@ -173,6 +175,7 @@
*
* \param[in,out] SPI Pointer to the base of the SPI peripheral within the device.
*/
static inline void SPI_Disable(SPI_t* const SPI) ATTR_NON_NULL_PTR_ARG(1);
static inline void SPI_Disable(SPI_t* const SPI)
{
SPI->CTRL &= ~SPI_ENABLE_bm;
@ -184,7 +187,7 @@
*
* \return \ref SPI_MODE_MASTER if the interface is currently in SPI Master mode, \ref SPI_MODE_SLAVE otherwise
*/
static inline uint8_t SPI_GetCurrentMode(SPI_t* const SPI) ATTR_ALWAYS_INLINE;
static inline uint8_t SPI_GetCurrentMode(SPI_t* const SPI) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline uint8_t SPI_GetCurrentMode(SPI_t* const SPI)
{
return (SPI->CTRL & SPI_MASTER_bm);
@ -198,7 +201,7 @@
* \return Response byte from the attached SPI device.
*/
static inline uint8_t SPI_TransferByte(SPI_t* const SPI,
const uint8_t Byte) ATTR_ALWAYS_INLINE;
const uint8_t Byte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline uint8_t SPI_TransferByte(SPI_t* const SPI,
const uint8_t Byte)
{
@ -214,7 +217,7 @@
* \param[in] Byte Byte to send through the SPI interface.
*/
static inline void SPI_SendByte(SPI_t* const SPI,
const uint8_t Byte) ATTR_ALWAYS_INLINE;
const uint8_t Byte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline void SPI_SendByte(SPI_t* const SPI,
const uint8_t Byte)
{
@ -229,7 +232,7 @@
*
* \return The response byte from the attached SPI device.
*/
static inline uint8_t SPI_ReceiveByte(SPI_t* const SPI) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint8_t SPI_ReceiveByte(SPI_t* const SPI) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
static inline uint8_t SPI_ReceiveByte(SPI_t* const SPI)
{
SPI->DATA = 0;

View file

@ -53,17 +53,17 @@
* \code
* // Initialize the Master SPI mode USART driver before first use, with 1Mbit baud
* SerialSPI_Init(&USARTD0, (USART_SPI_SCK_LEAD_RISING | USART_SPI_SAMPLE_LEADING | USART_SPI_ORDER_MSB_FIRST), 1000000);
*
*
* // Send several bytes, ignoring the returned data
* SerialSPI_SendByte(&USARTD0, 0x01);
* SerialSPI_SendByte(&USARTD0, 0x02);
* SerialSPI_SendByte(&USARTD0, 0x03);
*
*
* // Receive several bytes, sending a dummy 0x00 byte each time
* uint8_t Byte1 = SerialSPI_ReceiveByte(&USARTD);
* uint8_t Byte2 = SerialSPI_ReceiveByte(&USARTD);
* uint8_t Byte3 = SerialSPI_ReceiveByte(&USARTD);
*
*
* // Send a byte, and store the received byte from the same transaction
* uint8_t ResponseByte = SerialSPI_TransferByte(&USARTD0, 0xDC);
* \endcode
@ -118,40 +118,44 @@
/** SPI data order mask for \ref SerialSPI_Init(). Indicates that data should be shifted out LSB first. */
#define USART_SPI_ORDER_LSB_FIRST USART_UDORD_bm
//@}
//@}
/* Inline Functions: */
/** Initialize the USART module in Master SPI mode.
/** Initialize the USART module in Master SPI mode.
*
* \param[in,out] USART Pointer to the base of the USART peripheral within the device.
* \param[in] SPIOptions USART SPI Options, a mask consisting of one of each of the \c USART_SPI_SCK_*,
* \c USART_SPI_SAMPLE_* and \c USART_SPI_ORDER_* masks.
* \param[in] BaudRate SPI baud rate, in bits per second.
*/
static inline void SerialSPI_Init(USART_t* const USART,
const uint8_t SPIOptions,
const uint32_t BaudRate) ATTR_NON_NULL_PTR_ARG(1);
static inline void SerialSPI_Init(USART_t* const USART,
const uint8_t SPIOptions,
const uint32_t BaudRate)
{
uint16_t BaudValue = SERIAL_SPI_UBBRVAL(BaudRate);
USART->BAUDCTRLB = (BaudValue >> 8);
USART->BAUDCTRLA = (BaudValue & 0xFF);
USART->CTRLC = (USART_CMODE_MSPI_gc | SPIOptions);
USART->CTRLB = (USART_RXEN_bm | USART_TXEN_bm);
}
/** Turns off the USART driver, disabling and returning used hardware to their default configuration.
*
* \param[in,out] USART Pointer to the base of the USART peripheral within the device.
*/
static inline void SerialSPI_Disable(USART_t* const USART) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline void SerialSPI_Disable(USART_t* const USART)
{
USART->CTRLA = 0;
USART->CTRLB = 0;
USART->CTRLC = 0;
}
/** Sends and receives a byte through the USART SPI interface, blocking until the transfer is complete.
*
* \param[in,out] USART Pointer to the base of the USART peripheral within the device.
@ -159,6 +163,8 @@
*
* \return Response byte from the attached SPI device.
*/
static inline uint8_t SerialSPI_TransferByte(USART_t* const USART,
const uint8_t DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline uint8_t SerialSPI_TransferByte(USART_t* const USART,
const uint8_t DataByte)
{
@ -174,6 +180,8 @@
* \param[in,out] USART Pointer to the base of the USART peripheral within the device.
* \param[in] DataByte Byte to send through the USART SPI interface.
*/
static inline void SerialSPI_SendByte(USART_t* const USART,
const uint8_t DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1)
static inline void SerialSPI_SendByte(USART_t* const USART,
const uint8_t DataByte)
{
@ -187,11 +195,12 @@
*
* \return The response byte from the attached SPI device.
*/
static inline uint8_t SerialSPI_ReceiveByte(USART_t* const USART) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
static inline uint8_t SerialSPI_ReceiveByte(USART_t* const USART)
{
return SerialSPI_TransferByte(USART, 0);
}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}

View file

@ -95,7 +95,7 @@ void Serial_SendData(USART_t* const USART,
Serial_SendByte(USART, *((uint8_t*)Buffer++));
}
void Serial_CreateStream(FILE* Stream)
void Serial_CreateStream(FILE* const Stream)
{
if (!(Stream))
{
@ -107,7 +107,7 @@ void Serial_CreateStream(FILE* Stream)
*Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar, _FDEV_SETUP_RW);
}
void Serial_CreateBlockingStream(FILE* Stream)
void Serial_CreateBlockingStream(FILE* const Stream)
{
if (!(Stream))
{

View file

@ -139,7 +139,8 @@
* \param[in] Length Length of the data to send, in bytes.
*/
void Serial_SendData(USART_t* const USART,
const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
const void* Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** Creates a standard character stream from the USART so that it can be used with all the regular functions
* in the avr-libc \c <stdio.h> library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created
@ -155,7 +156,7 @@
*
* \pre The USART must first be configured via a call to \ref Serial_Init() before the stream is used.
*/
void Serial_CreateStream(FILE* Stream);
void Serial_CreateStream(FILE* const Stream);
/** Identical to \ref Serial_CreateStream(), except that reads are blocking until the calling stream function terminates
* the transfer.
@ -165,7 +166,7 @@
*
* \pre The USART must first be configured via a call to \ref Serial_Init() before the stream is used.
*/
void Serial_CreateBlockingStream(FILE* Stream);
void Serial_CreateBlockingStream(FILE* const Stream);
/* Inline Functions: */
/** Initializes the USART, ready for serial data transmission and reception. This initializes the interface to
@ -175,6 +176,9 @@
* \param[in] BaudRate Serial baud rate, in bits per second.
* \param[in] DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate.
*/
static inline void Serial_Init(USART_t* const USART,
const uint32_t BaudRate,
const bool DoubleSpeed) ATTR_NON_NULL_PTR_ARG(1);
static inline void Serial_Init(USART_t* const USART,
const uint32_t BaudRate,
const bool DoubleSpeed)
@ -192,6 +196,7 @@
*
* \param[in,out] USART Pointer to the base of the USART peripheral within the device.
*/
static inline void Serial_Disable(USART_t* const USART) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline void Serial_Disable(USART_t* const USART)
{
USART->CTRLA = 0;
@ -205,7 +210,7 @@
*
* \return Boolean \c true if a character has been received, \c false otherwise.
*/
static inline bool Serial_IsCharReceived(USART_t* const USART) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Serial_IsCharReceived(USART_t* const USART) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
static inline bool Serial_IsCharReceived(USART_t* const USART)
{
return ((USART->STATUS & USART_RXCIF_bm) ? true : false);
@ -217,7 +222,7 @@
* \param[in] DataByte Byte to transmit through the USART.
*/
static inline void Serial_SendByte(USART_t* const USART,
const char DataByte) ATTR_ALWAYS_INLINE;
const char DataByte) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline void Serial_SendByte(USART_t* const USART,
const char DataByte)
{
@ -231,7 +236,7 @@
*
* \return Next byte received from the USART, or a negative value if no byte has been received.
*/
static inline int16_t Serial_ReceiveByte(USART_t* const USART) ATTR_ALWAYS_INLINE;
static inline int16_t Serial_ReceiveByte(USART_t* const USART) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1);
static inline int16_t Serial_ReceiveByte(USART_t* const USART)
{
if (!(Serial_IsCharReceived(USART)))