Microchip® Advanced Software Framework

freertos_twi_master.h File Reference

FreeRTOS Peripheral Control API For the TWI.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "twi_master.h"
#include "freertos_peripheral_control.h"

Macros

#define freertos_twi_read_packet(p_twi, p_packet, block_time_ticks)   freertos_twi_read_packet_async((p_twi), (p_packet), (block_time_ticks), (NULL))
 Initiate a multi-byte read operation on an TWI peripheral. More...
 
#define freertos_twi_write_packet(p_twi, p_packet, block_time_ticks)   freertos_twi_write_packet_async((p_twi), (p_packet), (block_time_ticks), (NULL))
 Initiate a multi-byte write operation on an TWI peripheral. More...
 

Typedefs

typedef void * freertos_twi_if
 Type returned from a call to freertos_twi_master_init(), and then used to reference a TWI port in calls to FreeRTOS peripheral control functions. More...
 

Functions

freertos_twi_if freertos_twi_master_init (Twi *p_twi, const freertos_peripheral_options_t *const freertos_driver_parameters)
 Initializes the FreeRTOS ASF TWI (I2C) master driver for the specified TWI port. More...
 
status_code_t freertos_twi_read_packet_async (freertos_twi_if p_twi, twi_packet_t *p_packet, portTickType block_time_ticks, xSemaphoreHandle notification_semaphore)
 Initiate a completely asynchronous multi-byte read operation on an TWI peripheral. More...
 
status_code_t freertos_twi_write_packet_async (freertos_twi_if p_twi, twi_packet_t *p_packet, portTickType block_time_ticks, xSemaphoreHandle notification_semaphore)
 Initiate a completely asynchronous multi-byte write operation on a TWI peripheral. More...
 

#define freertos_twi_read_packet (   p_twi,
  p_packet,
  block_time_ticks 
)    freertos_twi_read_packet_async((p_twi), (p_packet), (block_time_ticks), (NULL))

Initiate a multi-byte read operation on an TWI peripheral.

freertos_twi_read_packet() is an ASF specific FreeRTOS driver function. It configures the TWI peripheral DMA controller (PDC) to read data from the TWI port, then waits until the requested number of bytes have been received. Other RTOS tasks execute while the DMA transfer is in progress.

freertos_twi_read_packet_async() is a version that does not wait for the reception to complete before returning.

The FreeRTOS ASF TWI driver is initialized using a call to freertos_twi_master_init(). The freertos_driver_parameters.options_flags parameter passed into the initialization function defines the driver behavior. freertos_twi_read_packet() can only be used if the freertos_driver_parameters.options_flags parameter passed to the initialization function had the WAIT_RX_COMPLETE bit set.

Readers are recommended to also reference the application note and examples that accompany the FreeRTOS ASF drivers.

The FreeRTOS ASF driver both installs and handles the TWI PDC interrupts. Users do not need to concern themselves with interrupt handling, and must not install their own interrupt handler.

Parameters
p_twiThe handle to the TWI port returned by the freertos_twi_master_init() call used to initialise the port.
p_packetStructure that defines the TWI transfer parameters, such as the I2C chip being addressed, the destination for the data being read, and the number of bytes to read. twi_packet_t is a standard ASF type (it is not FreeRTOS specific).
block_time_ticksThe FreeRTOS ASF TWI driver is initialized using a call to freertos_twi_master_init(). The freertos_driver_parameters.options_flags parameter passed to the initialization function defines the driver behavior. If freertos_driver_parameters.options_flags had the USE_RX_ACCESS_MUTEX bit set, then the driver will only read from the TWI peripheral if it has first gained exclusive access to it. block_time_ticks specifies the maximum amount of time the driver will wait to get exclusive access before aborting the read operation. Other tasks will execute during any waiting time. block_time_ticks is specified in RTOS tick periods. To specify a block time in milliseconds, divide the milliseconds value by portTICK_RATE_MS, and pass the result in block_time_ticks. portTICK_RATE_MS is defined by FreeRTOS.
Returns
ERR_INVALID_ARG is returned if an input parameter is invalid. ERR_TIMEOUT is returned if block_time_ticks passed before exclusive access to the TWI peripheral could be obtained. STATUS_OK is returned if the PDC was successfully configured to perform the TWI read operation.