| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_spi_master_driver.c
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_spi_master_driver.c
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_spi_master_driver.c
10 * @brief \b fsl_spi_master_driver.c implements spi master driver layer.
11 */
12 #include "fsl_spi_master_driver.h"
13 #include "isf_fsl_spi_master_PEx.h"
14 #include "PE_Types.h"
15 #include "PE_Error.h"
16 #include "mqxlite.h"
17 #include "lwmem.h"
18 #include "isf_util.h"
19 /*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
23 extern uint8 gSys_NumSpiBuses;
24 extern spi_master_instance_PEx spi_master_instance_tbl[];
25
26 spi_master_state_t spi_master_state[];
27 /*******************************************************************************
28 * Variables
29 ******************************************************************************/
30
31
32 /*******************************************************************************
33 * Code
34 ******************************************************************************/
35
36 /***********************************************************************
37 *
38 * Function Name : spi_master_init
39 * Description : initializes the spi master driver.
40 * This function will initialize the spi driver,configure the MOSI and MISO and control baudrate.
41 *
42 ***************************************************************************/
43 void spi_master_init(uint32_t instance)
44 {
45
46 if(instance >= gSys_NumSpiBuses){
47 return ;
48 }
49 _lwevent_create(&spi_master_state[instance].eventHandler, LWEVENT_AUTO_CLEAR);
50 spi_master_state[instance].pDeviceHandle = spi_master_instance_tbl[instance].fnSPILLDInit(&spi_master_state[instance]);
51
52
53 }
54 /***********************************************************************
55 *
56 * Function Name : spi_master_configure_bus
57 * Description : Configure the spi master bus.
58 *
59 ***************************************************************************/
60 void spi_master_configure_bus(uint32_t instance, const spi_user_config_t * device)
61 {
62
63 }
64 /***********************************************************************
65 *
66 * Function Name : spi_master_transfer
67 * Description : Blocking receive call for the spi data transfer.
68 *
69 ***************************************************************************/
70 spi_status_t spi_master_transfer(uint32_t instance,
71 const spi_user_config_t * device,
72 const uint8_t * sendBuffer,
73 uint8_t * receiveBuffer,
74 uint16_t transferByteCount,
75 uint32_t timeout)
76
77 {
78 if(instance >= gSys_NumSpiBuses){
79 return kStatus_SPI_Error;
80 }
81 _mqx_uint event = 0;
82 // Flush out the receive buffer if something is there, even for just sending the data else read the accurate data.
83 if(ERR_OK != spi_master_instance_tbl[instance].fnSPICLLDRead(spi_master_state[instance].pDeviceHandle, receiveBuffer, transferByteCount)){
84 return kStatus_SPI_Error;
85 }
86
87 if(ERR_OK != spi_master_instance_tbl[instance].fnSPILLDWrite(spi_master_state[instance].pDeviceHandle, sendBuffer, transferByteCount)){
88 return kStatus_SPI_Error;
89 }
90
91 // wait for the receive to complete.
92 event = _lwevent_wait_ticks(&spi_master_state[instance].eventHandler, SPI_PEX_READ_EVENT_SUCCESS,
93 FALSE, timeout);
94 if(LWEVENT_WAIT_TIMEOUT == event){
95 return kStatus_SPI_Error;
96 }
97 return kStatus_SPI_Success;
98 }
99 /***********************************************************************
100 *
101 * Function Name : spi_master_transfer_async
102 * Description : Non-Blocking receive call for the SPI.
103 *
104 ***************************************************************************/
105 spi_status_t spi_master_transfer_async(uint32_t instance,
106 const spi_user_config_t * device,
107 const uint8_t * sendBuffer,
108 uint8_t * receiveBuffer,
109 uint16_t transferByteCount)
110 {
111
112 return kStatus_SPI_Success;
113 }
114
115
116 /*******************************************************************************
117 * EOF
118 ******************************************************************************/
119
120
121
spi_status_t
enum _spi_errors spi_status_t
Error codes for the SPI driver.
uint8
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
spi_master_configure_bus
void spi_master_configure_bus(uint32_t instance, const spi_user_config_t *device)
Configure the SPI port to access a device on the bus.
Definition: fsl_spi_master_driver.c:60
FALSE
#define FALSE
Definition: isf_types.h:56
gSys_NumSpiBuses
uint8 gSys_NumSpiBuses
Definition: isf_sysconf_comms.c:96
fsl_spi_master_driver.h
fsl_spi_master_driver.h defines structures and types for the spi master driver.
SPI_Master_State
Definition: fsl_spi_master_driver.h:46
spi_master_instance_tbl
spi_master_instance_PEx spi_master_instance_tbl[]
Lookup table for the LLD instance.
Definition: isf_fsl_spi_master_PEx.c:26
kStatus_SPI_Success
Definition: fsl_spi_hal.h:34
spi_master_transfer
spi_status_t spi_master_transfer(uint32_t instance, const spi_user_config_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount, uint32_t timeout)
Perform a blocking SPI master mode transfer.
Definition: fsl_spi_master_driver.c:70
isf_util.h
The isf_util.h file contains the utility method declarations and macros.
SPI_PEX_READ_EVENT_SUCCESS
#define SPI_PEX_READ_EVENT_SUCCESS
Definition: fsl_spi_master_driver.h:55
spi_master_state
spi_master_state_t spi_master_state[]
Definition: fsl_spi_master_driver.c:26
kStatus_SPI_Error
Definition: fsl_spi_hal.h:40
isf_fsl_spi_master_PEx.h
spi_master_instance_PEx
This structure contains i2c LLD function pointers.
Definition: isf_fsl_spi_master_PEx.h:26
spi_master_init
void spi_master_init(uint32_t instance)
Initialize a SPI instance for master mode operation.
Definition: fsl_spi_master_driver.c:43
SPI_Master_State::pDeviceHandle
LDD_TDeviceData * pDeviceHandle
Definition: fsl_spi_master_driver.h:48
spi_master_transfer_async
spi_status_t spi_master_transfer_async(uint32_t instance, const spi_user_config_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount)
Perform an non-blocking SPI master mode transfer.
Definition: fsl_spi_master_driver.c:105
SPIUserConfig
Information about a device on the SPI bus.
Definition: fsl_spi_master_driver.h:35
spi_master_instance_PEx::fnSPILLDInit
fnSPIInit_t fnSPILLDInit
Definition: isf_fsl_spi_master_PEx.h:27
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.