Statistics
| Branch: | Tag: | Revision:

mongoose / examples / PIC32 / mqtt_client / firmware / src / system_config / mx795_CC3100_e16 / framework / driver / spi / static / src / drv_spi_static_tasks.c @ eaef5bd1

History | View | Annotate | Download (5.72 KB)

1
/* clang-format off */
2
/*******************************************************************************
3
  SPI Driver Functions for Static Driver Tasks Functions
4

5
  Company:
6
    Microchip Technology Inc.
7

8
  File Name:
9
    drv_spi_static_tasks.c
10

11
  Summary:
12
    SPI driver tasks functions
13

14
  Description:
15
    The SPI device driver provides a simple interface to manage the SPI
16
    modules on Microchip microcontrollers. This file contains implemenation
17
    for the SPI driver.
18

19
  Remarks:
20
  This file is generated from framework/driver/spi/template/drv_spi_static_tasks.c.ftl
21
*******************************************************************************/
22

    
23
//DOM-IGNORE-BEGIN
24
/*******************************************************************************
25
Copyright (c) 2015 released Microchip Technology Inc.  All rights reserved.
26

27
Microchip licenses to you the right to use, modify, copy and distribute
28
Software only when embedded on a Microchip microcontroller or digital signal
29
controller that is integrated into your product or third party product
30
(pursuant to the sublicense terms in the accompanying license agreement).
31

32
You should refer to the license agreement accompanying this Software for
33
additional information regarding your rights and obligations.
34

35
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
36
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
37
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
38
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
39
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
40
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
41
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
42
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
43
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
44
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
45
*******************************************************************************/
46
//DOM-IGNORE-END
47
#include "system_config.h"
48
#include "system_definitions.h"
49

    
50

    
51

    
52
int32_t DRV_SPI0_PolledMasterRM8BitTasks ( struct DRV_SPI_OBJ * dObj )
53
{
54
    volatile bool continueLoop;
55
    uint8_t counter = 0;
56
    uint8_t numPolled = dObj->numTrfsSmPolled;
57
    uint8_t result = 0;
58
    do {
59
        
60
        DRV_SPI_JOB_OBJECT * currentJob = dObj->currentJob;
61

    
62
        /* Check for a new task */
63
        if (dObj->currentJob == NULL)
64
        {
65
            if (DRV_SPI_SYS_QUEUE_DequeueLock(dObj->queue, (void *)&(dObj->currentJob)) != DRV_SPI_SYS_QUEUE_SUCCESS)
66
            {
67
                SYS_ASSERT(false, "\r\nSPI Driver: Error in dequeing.");
68
                return 0;
69
            }
70
            if (dObj->currentJob == NULL)
71
            {
72
                return 0;
73
            }
74
            currentJob = dObj->currentJob;
75

    
76
            dObj->symbolsInProgress = 0;
77

    
78
            /* Call the operation starting function pointer.  This can be used to modify the slave select lines */
79
            if (dObj->operationStarting != NULL)
80
            {
81
                (*dObj->operationStarting)(DRV_SPI_BUFFER_EVENT_PROCESSING, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
82
            }
83

    
84
            /* List the new job as processing*/
85
            currentJob->status = DRV_SPI_BUFFER_EVENT_PROCESSING;
86
            /* Flush out the Receive buffer */
87
            PLIB_SPI_BufferClear(SPI_ID_1);
88
        }
89

    
90

    
91
        continueLoop = false;
92
        
93
        /* Execute the sub tasks */
94
            if
95
            (currentJob->dataLeftToTx +currentJob->dummyLeftToTx != 0)
96
        {
97
            DRV_SPI0_MasterRMSend8BitPolled(dObj);
98
        }
99
        
100
        DRV_SPI0_PolledErrorTasks(dObj);
101
        
102
        /* Figure out how many bytes are left to be received */
103
        volatile size_t bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
104
        
105
        // Check to see if we have any data left to receive and update the bytes left.
106
        if (bytesLeft != 0)
107
        {
108
            DRV_SPI0_MasterRMReceive8BitPolled(dObj);
109
            bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
110
        }
111
        if (bytesLeft == 0)
112
        {
113
                    /* Job is complete*/
114
                    currentJob->status = DRV_SPI_BUFFER_EVENT_COMPLETE;
115
                    /* Call the job complete call back*/
116
                    if (currentJob->completeCB != NULL)
117
                    {
118
                        (*currentJob->completeCB)(DRV_SPI_BUFFER_EVENT_COMPLETE, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
119
                    }
120

    
121
                    /* Call the operation complete call back.  This is different than the
122
                       job complete callback.  This can be used to modify the Slave Select line.*/
123

    
124
                    if (dObj->operationEnded != NULL)
125
                    {
126
                        (*dObj->operationEnded)(DRV_SPI_BUFFER_EVENT_COMPLETE, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
127
                    }
128

    
129
                    /* Return the job back to the free queue*/
130
                    if (DRV_SPI_SYS_QUEUE_FreeElementLock(dObj->queue, currentJob) != DRV_SPI_SYS_QUEUE_SUCCESS)
131
                    {
132
                        SYS_ASSERT(false, "\r\nSPI Driver: Queue free element error.");
133
                        return 0;
134
                    }
135
                    /* Clean up */
136
                    dObj->currentJob = NULL;
137
                }
138

    
139

    
140
        counter ++;
141
        if ((counter < numPolled) && (result != 0))
142
        {
143
            continueLoop = true;
144
        }
145

    
146
    } while(continueLoop);
147
    return 0;
148
}
149

    
150