Commit f5a28576 authored by Alexander Alashkin's avatar Alexander Alashkin Committed by Cesanta Bot

Add PIC32/Harmony http_server example

PUBLISHED_FROM=c393396605d5418fda4ff386170bb9a6d6658a93
parent 2ef6f724
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk
#
#Wed Oct 26 16:05:10 EEST 2016
pic32mx_eth_sk2_encx24j600.languagetoolchain.dir=/opt/microchip/xc32/v1.42/bin
pic32mx_eth_sk2_encx24j600.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=7787462309de955deefcc6f5508f88a9
pic32mx_eth_sk2_encx24j600.languagetoolchain.version=1.42
configurations-xml=2f70242829ecb692b68d01a3f7c4e1e7
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=02b44c60b7ea0aab28d65f169487b894
host.platform=linux
conf.ids=pic32mx_eth_sk2_encx24j600
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
# Project Name
PROJECTNAME=http_server.X
# Active Configuration
DEFAULTCONF=pic32mx_eth_sk2_encx24j600
CONF=${DEFAULTCONF}
# All Configurations
ALLCONFS=pic32mx_eth_sk2_encx24j600
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=pic32mx_eth_sk2_encx24j600 clean
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=pic32mx_eth_sk2_encx24j600 build
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
PATH_TO_IDE_BIN=/opt/microchip/mplabx/v3.40/mplab_ide/platform/../mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=/opt/microchip/mplabx/v3.40/mplab_ide/platform/../mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="/opt/microchip/mplabx/v3.40/sys/java/jre1.8.0_91/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="/opt/microchip/xc32/v1.42/bin/xc32-gcc"
MP_CPPC="/opt/microchip/xc32/v1.42/bin/xc32-g++"
# MP_BC is not defined
MP_AS="/opt/microchip/xc32/v1.42/bin/xc32-as"
MP_LD="/opt/microchip/xc32/v1.42/bin/xc32-ld"
MP_AR="/opt/microchip/xc32/v1.42/bin/xc32-ar"
DEP_GEN=${MP_JAVA_PATH}java -jar "/opt/microchip/mplabx/v3.40/mplab_ide/platform/../mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="/opt/microchip/xc32/v1.42/bin"
MP_CPPC_DIR="/opt/microchip/xc32/v1.42/bin"
# MP_BC_DIR is not defined
MP_AS_DIR="/opt/microchip/xc32/v1.42/bin"
MP_LD_DIR="/opt/microchip/xc32/v1.42/bin"
MP_AR_DIR="/opt/microchip/xc32/v1.42/bin"
# MP_BC_DIR is not defined
This source diff could not be displayed because it is too large. You can view the blob instead.
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# pic32mx_eth_sk2_encx24j600 configuration
CND_ARTIFACT_DIR_pic32mx_eth_sk2_encx24j600=dist/pic32mx_eth_sk2_encx24j600/production
CND_ARTIFACT_NAME_pic32mx_eth_sk2_encx24j600=http_server.X.production.hex
CND_ARTIFACT_PATH_pic32mx_eth_sk2_encx24j600=dist/pic32mx_eth_sk2_encx24j600/production/http_server.X.production.hex
CND_PACKAGE_DIR_pic32mx_eth_sk2_encx24j600=${CND_DISTDIR}/pic32mx_eth_sk2_encx24j600/package
CND_PACKAGE_NAME_pic32mx_eth_sk2_encx24j600=httpserver.x.tar
CND_PACKAGE_PATH_pic32mx_eth_sk2_encx24j600=${CND_DISTDIR}/pic32mx_eth_sk2_encx24j600/package/httpserver.x.tar
#!/bin/bash -x
#
# Generated - do not edit!
#
# Macros
TOP=`pwd`
CND_CONF=pic32mx_eth_sk2_encx24j600
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/http_server.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=http_server.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=httpserver.x/
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/httpserver.x/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/httpserver.x.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/httpserver.x.tar *
checkReturnCode
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="pic32mx_eth_sk2_encx24j600" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>8107:=&lt;rev>0002:=&lt;man>Microchip Technology Incorporated:=&lt;prod>Explorer 16/32 PICkit on Board:=&lt;sn>BUR162971352:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>/opt/microchip/xc32/v1.42/bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/alex/go/src/cesanta.com/mongoose/examples/PIC32/http_server/firmware/src/app.c</file>
<file>file:/home/alex/go/src/cesanta.com/mongoose/examples/PIC32/http_server/firmware/src/app.h</file>
</group>
</open-files>
</project-private>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>com.microchip.mplab.nbide.embedded.makeproject</type>
<configuration>
<Harmony xmlns="Harmony" MHC="true"/>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>http_server</name>
<creation-uuid>e54023e9-3948-44ef-bf6f-29d8b223e555</creation-uuid>
<make-project-type>0</make-project-type>
<c-extensions>c</c-extensions>
<cpp-extensions/>
<header-extensions>h</header-extensions>
<asminc-extensions/>
<sourceEncoding>ISO-8859-1</sourceEncoding>
<make-dep-projects/>
</data>
</configuration>
</project>
#
# Application configuration file generated by
# Microchip Harmony Configurator (MHC) from Harmony version: 1.04
#
mainmenu "MPLAB Harmony & Application Configuration"
menu "Application Configuration"
config APP_INSTANCES
int "Number of Applications"
default 1
range 1 10 # Must limit to 10 or application templates will need to be updated.
config APP_AUTO_GENERATE_CODE # Used by MHC internally to selectively auto-generate app.h, app.c, and main.c
bool
default n
source "$HARMONY_VERSION_PATH/utilities/mhc/config/gencode/framework/global_event/config/global_event_gencode.hconfig"
source "$HARMONY_VERSION_PATH/utilities/mhc/config/app_name_idx_gencode.ftl" 10 instances
menu "Exception Handling"
config USE_EXCEPTION_HANDLER
bool "Use MPLAB Harmony Exception Handler Template?"
default y
---help---
Enter 'Y' if you want to include an exception handler template
(system_exceptions.c) in this system configuration. Enter 'N' if
you do not.
---endhelp---
config EXCEPTION_USE_SYS_DEBUG
bool "Use debug services in exception handler?"
depends on USE_EXCEPTION_HANDLER
default y
---help---
Enter 'Y' if you want the exception handler to use the SYS_DEBUG service to
report exception information. Enter 'N' if you do not.
---endhelp---
config EXCEPTION_BREAKPOINT
bool "Hit breakpoint when an exception occurs?"
depends on USE_EXCEPTION_HANDLER && EXCEPTION_USE_SYS_DEBUG
default y
---help---
Enter 'Y' if you want the exception handler to hit a breakpoint when
an exception occurs. Enter 'N' if you do not.
Note: Only works if debugging is enabled.
---endhelp---
endmenu # Exception Handling
#insert application specific configuration here
endmenu # Application Configuration
source "$HARMONY_VERSION_PATH/config/harmony.hconfig"
This diff is collapsed.
/* clang-format off */
/*******************************************************************************
MPLAB Harmony Application Header File
Company:
Microchip Technology Inc.
File Name:
app.h
Summary:
This header file provides prototypes and definitions for the application.
Description:
This header file provides function prototypes and data type definitions for
the application. Some of these are required by the system (such as the
"APP_Initialize" and "APP_Tasks" prototypes) and some of them are only used
internally by the application (such as the "APP_STATES" definition). Both
are defined here for convenience.
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2014 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
#ifndef _APP_H
#define _APP_H
// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include "system_config.h"
#include "system_definitions.h"
// *****************************************************************************
// *****************************************************************************
// Section: Type Definitions
// *****************************************************************************
// *****************************************************************************
// *****************************************************************************
/* Application States
Summary:
Application states enumeration
Description:
This enumeration defines the valid application states. These states
determine the behavior of the application at various times.
*/
typedef enum
{
/* Application's state machine's initial state. */
APP_STATE_INIT=0,
APP_TCPIP_WAIT_FOR_IP,
APP_START_LISTENING,
APP_DONE,
APP_EMPTY,
APP_POLL
} APP_STATES;
// *****************************************************************************
/* Application Data
Summary:
Holds application data
Description:
This structure holds the application's data.
Remarks:
Application strings and buffers are be defined outside this structure.
*/
typedef struct
{
/* The application's current state */
APP_STATES state;
/* TODO: Define any additional data used by the application. */
TCP_SOCKET socket;
char * host;
char * path;
uint16_t port;
} APP_DATA;
// *****************************************************************************
// *****************************************************************************
// Section: Application Callback Routines
// *****************************************************************************
// *****************************************************************************
/* These routines are called by drivers when certain events occur.
*/
// *****************************************************************************
// *****************************************************************************
// Section: Application Initialization and State Machine Functions
// *****************************************************************************
// *****************************************************************************
/*******************************************************************************
Function:
void APP_Initialize ( void )
Summary:
MPLAB Harmony application initialization routine.
Description:
This function initializes the Harmony application. It places the
application in its initial state and prepares it to run so that its
APP_Tasks function can be called.
Precondition:
All other system initialization routines should be called before calling
this routine (in "SYS_Initialize").
Parameters:
None.
Returns:
None.
Example:
<code>
APP_Initialize();
</code>
Remarks:
This routine must be called from the SYS_Initialize function.
*/
void APP_Initialize ( void );
/*******************************************************************************
Function:
void APP_Tasks ( void )
Summary:
MPLAB Harmony Demo application tasks function
Description:
This routine is the Harmony Demo application's tasks function. It
defines the application's state machine and core logic.
Precondition:
The system and application initialization ("SYS_Initialize") should be
called before calling this.
Parameters:
None.
Returns:
None.
Example:
<code>
APP_Tasks();
</code>
Remarks:
This routine must be called from SYS_Tasks() routine.
*/
void APP_Tasks ( void );
#endif /* _APP_H */
/*******************************************************************************
End of File
*/
/* clang-format off */
/*******************************************************************************
MPLAB Harmony Project Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This file contains the "main" function for an MPLAB Harmony project.
Description:
This file contains the "main" function for an MPLAB Harmony project. The
"main" function calls the "SYS_Initialize" function to initialize the state
machines of all MPLAB Harmony modules in the system and it calls the
"SYS_Tasks" function from within a system-wide "super" loop to maintain
their correct operation. These two functions are implemented in
configuration-specific files (usually "system_init.c" and "system_tasks.c")
in a configuration-specific folder under the "src/system_config" folder
within this project's top-level folder. An MPLAB Harmony project may have
more than one configuration, each contained within it's own folder under
the "system_config" folder.
*******************************************************************************/
// DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2014 released Microchip Technology Inc. All rights reserved.
//Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
// DOM-IGNORE-END
// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
#include <stddef.h> // Defines NULL
#include <stdbool.h> // Defines true
#include <stdlib.h> // Defines EXIT_FAILURE
#include "system/common/sys_module.h" // SYS function prototypes
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
int main ( void )
{
/* Initialize all MPLAB Harmony modules, including application(s). */
SYS_Initialize ( NULL );
while ( true )
{
/* Maintain state machines of all polled MPLAB Harmony modules. */
SYS_Tasks ( );
}
/* Execution should not come here during normal operation */
return ( EXIT_FAILURE );
}
/*******************************************************************************
End of File
*/
/* clang-format off */
/*******************************************************************************
SPI Driver Functions for Dynamic Standard Buffer Driver Tasks Functions
Company:
Microchip Technology Inc.
File Name:
drv_spi_dynamic_master_dma_tasks.c
Summary:
SPI driver tasks functions
Description:
The SPI device driver provides a simple interface to manage the SPI
modules on Microchip microcontrollers. This file contains implemenation
for the SPI driver.
Remarks:
This file is generated from framework/driver/spi/template/drv_spi_dynamic_ebm_tasks.c.ftl
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
#include "driver/spi/src/dynamic/drv_spi_internal.h"
#include <stdbool.h>
void DRV_SPI_MasterDMASendDummy8BitISR(SYS_DMA_TRANSFER_EVENT event, SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle)
{
if (event != SYS_DMA_TRANSFER_EVENT_COMPLETE)
{
// Ignore for now
return;
}
struct DRV_SPI_DRIVER_OBJECT * pDrvInstance = (struct DRV_SPI_DRIVER_OBJECT *)contextHandle;
DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
if (currentJob->dummyLeftToTx != 0)
{
uint8_t * ptr = sDrvSpiTxDummy;
uint32_t len = MIN(MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, currentJob->dummyLeftToTx), DRV_SPI_DMA_TXFER_SIZE), DRV_SPI_DMA_DUMMY_BUFFER_SIZE);
void * spiPtr = PLIB_SPI_BufferAddressGet(pDrvInstance->spiId);
SYS_DMA_ChannelTransferAdd(pDrvInstance->txDmaChannelHandle, ptr, len, spiPtr, 1, 1);
currentJob->txDMAProgressStage = DRV_SPI_DMA_DUMMY_INPROGRESS;
currentJob->dummyLeftToTx -= len;
}
else
{
// Job is done
currentJob->txDMAProgressStage = DRV_SPI_DMA_COMPLETE;
}
}
void DRV_SPI_MasterDMASendData8BitISR(SYS_DMA_TRANSFER_EVENT event, SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle)
{
if (event != SYS_DMA_TRANSFER_EVENT_COMPLETE)
{
// Ignore for now
return;
}
struct DRV_SPI_DRIVER_OBJECT * pDrvInstance = (struct DRV_SPI_DRIVER_OBJECT *)contextHandle;
DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
if (currentJob->dataLeftToTx != 0)
{
uint8_t * ptr = &(currentJob->txBuffer[currentJob->dataTxed]);
uint32_t len = MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, currentJob->dataLeftToTx), DRV_SPI_DMA_TXFER_SIZE);
void * spiPtr = PLIB_SPI_BufferAddressGet(pDrvInstance->spiId);
SYS_DMA_ChannelTransferAdd(pDrvInstance->txDmaChannelHandle, ptr, len, spiPtr, 1, 1);
currentJob->txDMAProgressStage = DRV_SPI_DMA_DATA_INPROGRESS;
currentJob->dataLeftToTx -= len;
currentJob->dataTxed += len;
}
else
{
// Job is done
currentJob->txDMAProgressStage = DRV_SPI_DMA_COMPLETE;
}
}
void DRV_SPI_ISRDMAMasterSendEventHandler8bit(SYS_DMA_TRANSFER_EVENT event, SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle)
{
struct DRV_SPI_DRIVER_OBJECT * pDrvInstance = (struct DRV_SPI_DRIVER_OBJECT * )contextHandle;
register DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
switch(currentJob->txDMAProgressStage)
{
case DRV_SPI_DMA_DATA_INPROGRESS:
DRV_SPI_MasterDMASendData8BitISR(event, handle, contextHandle);
break;
case DRV_SPI_DMA_DUMMY_INPROGRESS:
DRV_SPI_MasterDMASendDummy8BitISR(event, handle, contextHandle);
break;
default:
break;
}
}
void DRV_SPI_MasterDMAReceiveDummy8BitISR(SYS_DMA_TRANSFER_EVENT event, SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle)
{
if (event != SYS_DMA_TRANSFER_EVENT_COMPLETE)
{
// Ignore for now
return;
}
struct DRV_SPI_DRIVER_OBJECT * pDrvInstance = (struct DRV_SPI_DRIVER_OBJECT *)contextHandle;
DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
if (currentJob->dummyLeftToRx != 0)
{
uint8_t * ptr = sDrvSpiRxDummy;
uint32_t len = MIN(MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, currentJob->dummyLeftToRx), DRV_SPI_DMA_TXFER_SIZE), DRV_SPI_DMA_DUMMY_BUFFER_SIZE);
void * spiPtr = PLIB_SPI_BufferAddressGet(pDrvInstance->spiId);
SYS_DMA_ChannelTransferAdd(pDrvInstance->rxDmaChannelHandle, spiPtr, 1, ptr, len, 1);
currentJob->rxDMAProgressStage = DRV_SPI_DMA_DUMMY_INPROGRESS;
currentJob->dummyLeftToRx -= len;
}
else
{
// Job is done
currentJob->rxDMAProgressStage = DRV_SPI_DMA_COMPLETE;
SYS_INT_SourceEnable(pDrvInstance->rxInterruptSource);
}
}
void DRV_SPI_MasterDMAReceiveData8BitISR(SYS_DMA_TRANSFER_EVENT event, SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle)
{
if (event != SYS_DMA_TRANSFER_EVENT_COMPLETE)
{
// Ignore for now
return;
}
struct DRV_SPI_DRIVER_OBJECT * pDrvInstance = (struct DRV_SPI_DRIVER_OBJECT *)contextHandle;
DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
if (currentJob->dataLeftToRx != 0)
{
uint8_t * ptr = &(currentJob->rxBuffer[currentJob->dataRxed]);
uint32_t len = MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, currentJob->dataLeftToRx), DRV_SPI_DMA_TXFER_SIZE);
void * spiPtr = PLIB_SPI_BufferAddressGet(pDrvInstance->spiId);
SYS_DMA_ChannelTransferAdd(pDrvInstance->rxDmaChannelHandle, spiPtr, 1, ptr, len, 1);
currentJob->rxDMAProgressStage = DRV_SPI_DMA_DATA_INPROGRESS;
currentJob->dataLeftToRx -= len;
currentJob->dataRxed += len;
}
else
{
// Job is done
currentJob->rxDMAProgressStage = DRV_SPI_DMA_COMPLETE;
SYS_INT_SourceEnable(pDrvInstance->rxInterruptSource);
}
}
void DRV_SPI_ISRDMAMasterReceiveEventHandler8bit(SYS_DMA_TRANSFER_EVENT event, SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle)
{
struct DRV_SPI_DRIVER_OBJECT * pDrvInstance = (struct DRV_SPI_DRIVER_OBJECT * )contextHandle;
register DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
switch(currentJob->rxDMAProgressStage)
{
case DRV_SPI_DMA_DATA_INPROGRESS:
DRV_SPI_MasterDMAReceiveData8BitISR(event, handle, contextHandle);
break;
case DRV_SPI_DMA_DUMMY_INPROGRESS:
DRV_SPI_MasterDMAReceiveDummy8BitISR(event, handle, contextHandle);
break;
default:
break;
}
}
/* clang-format off */
/*******************************************************************************
SPI Driver Functions for Dynamic Enhanced Buffer Driver Tasks Functions
Company:
Microchip Technology Inc.
File Name:
drv_spi_dynamic_ebm_tasks.c
Summary:
SPI driver tasks functions
Description:
The SPI device driver provides a simple interface to manage the SPI
modules on Microchip microcontrollers. This file contains implemenation
for the SPI driver.
Remarks:
This file is generated from framework/driver/spi/template/drv_spi_dynamic_ebm_tasks.c.ftl
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
#include "driver/spi/src/dynamic/drv_spi_internal.h"
#include <stdbool.h>
int32_t DRV_SPI_MasterEBMSend8BitISR( struct DRV_SPI_DRIVER_OBJECT * pDrvInstance )
{
register SPI_MODULE_ID spiId = pDrvInstance->spiId;
register DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
/* Determine the maximum number of bytes we can send to the FIFO*/
uint8_t symbolsInTransit = MAX(pDrvInstance->symbolsInProgress, PLIB_SPI_FIFOCountGet(spiId, SPI_FIFO_TYPE_TRANSMIT));
uint8_t bufferBytes = PLIB_SPI_TX_8BIT_FIFO_SIZE(spiId) - symbolsInTransit;
/* Figure out how much data we can send*/
size_t dataUnits = MIN(currentJob->dataLeftToTx, bufferBytes);
size_t counter;
if (dataUnits != 0)
{
/* Adjust the maximum buffer size downwards based on how much data we'll be sending*/
bufferBytes -= dataUnits;
currentJob->dataLeftToTx -= dataUnits;
/* Set the location in the buffer of where to start sending from*/
uint8_t *bufferLoc = &(currentJob->txBuffer[currentJob->dataTxed]);
for (counter = 0; counter < dataUnits; counter++)
{
/* Send a unit/symbol of data*/
PLIB_SPI_BufferWrite(spiId, bufferLoc[counter]);
}
/* Update the number of bytes transmitted*/
currentJob->dataTxed += dataUnits;
/* Adjust the symbols in progress */
pDrvInstance->symbolsInProgress += dataUnits;
}
size_t dummyUnits = MIN(currentJob->dummyLeftToTx, bufferBytes);
if (dummyUnits != 0)
{
currentJob->dummyLeftToTx -= dummyUnits;
/* Adjust the symbols in progress */
pDrvInstance->symbolsInProgress += dummyUnits;
for (counter = 0; counter < dummyUnits; counter++)
{
PLIB_SPI_BufferWrite(spiId, 0xff);
}
}
if (currentJob->dataLeftToTx + currentJob->dummyLeftToTx == 0)
{
/* We have no more data to send, turn off the TX interrupt*/
PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_TRANSMIT_BUFFER_IS_COMPLETELY_EMPTY);
pDrvInstance->txEnabled = false;
/* Turn on the RX Interrupt*/
pDrvInstance->rxEnabled = true;
}
return 0;
}
int32_t DRV_SPI_MasterEBMReceive8BitISR( struct DRV_SPI_DRIVER_OBJECT * pDrvInstance )
{
register SPI_MODULE_ID spiId = pDrvInstance->spiId;
register DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
/* Figure out how many bytes are waiting to be received."*/
uint8_t bufferBytes = PLIB_SPI_FIFOCountGet(spiId, SPI_FIFO_TYPE_RECEIVE);
/* Calculate the maximum number of data bytes that can be received*/
size_t dataUnits = MIN(currentJob->dataLeftToRx, bufferBytes);
size_t counter;
if (dataUnits != 0)
{
bufferBytes -= dataUnits;
currentJob->dataLeftToRx -= dataUnits;
/* Set the buffer location to receive bytes from the SPI to*/
uint8_t *bufferLoc = &(currentJob->rxBuffer[currentJob->dataRxed]);
for (counter = 0; counter < dataUnits; counter++)
{
/* Receive the data from the SPI */
bufferLoc[counter] = PLIB_SPI_BufferRead(spiId);
}
/* Adjust the amount of data that has been received */
currentJob->dataRxed += dataUnits;
/* Update the symbols in progress so we can send more units later */
pDrvInstance->symbolsInProgress -= dataUnits;
}
/* Figure out the maximum number of dummy data to be received */
size_t dummyUnits = MIN(currentJob->dummyLeftToRx, bufferBytes);
if (dummyUnits != 0)
{
/* Lower the number of dummy bytes to be received */
currentJob->dummyLeftToRx -= dummyUnits;
pDrvInstance->symbolsInProgress -= dummyUnits;
for (counter = 0; counter < dummyUnits; counter++)
{
/* Receive and throw away the byte. Note: We cannot just clear the
buffer because we have to keep track of how many symbols/units we
have received, and the number may have increased since we checked
how full the buffer is.*/
PLIB_SPI_BufferRead(spiId);
}
}
/* Figure out how many bytes are left to be received */
size_t bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
/* If the bytes left are smaller than the HW mark we have to change the interrupt mode */
if (bytesLeft < PLIB_SPI_RX_8BIT_HW_MARK(spiId))
{
PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_RECEIVE_BUFFER_IS_NOT_EMPTY);
}
return 0;
}
/* clang-format off */
/*******************************************************************************
SPI Driver Functions for Dynamic Driver Tasks Functions
Company:
Microchip Technology Inc.
File Name:
drv_spi_dynamic_tasks.c
Summary:
SPI driver tasks functions
Description:
The SPI device driver provides a simple interface to manage the SPI
modules on Microchip microcontrollers. This file contains implemenation
for the SPI driver.
Remarks:
This file is generated from framework/driver/spi/template/drv_spi_dynamic_tasks.c.ftl
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
#include "driver/spi/src/dynamic/drv_spi_internal.h"
#include <stdbool.h>
int32_t DRV_SPI_ISRMasterEBM8BitTasks ( struct DRV_SPI_DRIVER_OBJECT * pDrvInstance )
{
volatile bool continueLoop;
/* Disable the interrupts */
SYS_INT_SourceDisable(pDrvInstance->rxInterruptSource);
SYS_INT_SourceDisable(pDrvInstance->txInterruptSource);
SYS_INT_SourceDisable(pDrvInstance->errInterruptSource);
do {
DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
SPI_MODULE_ID spiId = pDrvInstance->spiId;
/* Check for a new task */
if (pDrvInstance->currentJob == NULL)
{
if (DRV_SPI_SYS_QUEUE_Dequeue(pDrvInstance->queue, (void *)&(pDrvInstance->currentJob)) != DRV_SPI_SYS_QUEUE_SUCCESS)
{
SYS_ASSERT(false, "\r\nSPI Driver: Error in dequeing.");
return 0;
}
if (pDrvInstance->currentJob == NULL)
{
pDrvInstance->txEnabled = false;
return 0;
}
currentJob = pDrvInstance->currentJob;
pDrvInstance->symbolsInProgress = 0;
/* Call the operation starting function pointer. This can be used to modify the slave select lines */
DRV_SPI_CLIENT_OBJECT * pClient = (DRV_SPI_CLIENT_OBJECT*)currentJob->pClient;
if (pClient->operationStarting != NULL)
{
(*pClient->operationStarting)(DRV_SPI_BUFFER_EVENT_PROCESSING, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
}
/* Check the baud rate. If its different set the new baud rate*/
if (pClient->baudRate != pDrvInstance->currentBaudRate)
{
PLIB_SPI_BaudRateSet( spiId , SYS_CLK_PeripheralFrequencyGet(pDrvInstance->spiClk), pClient->baudRate );
pDrvInstance->currentBaudRate = pClient->baudRate;
}
/* List the new job as processing*/
currentJob->status = DRV_SPI_BUFFER_EVENT_PROCESSING;
if (currentJob->dataLeftToTx +currentJob->dummyLeftToTx > PLIB_SPI_RX_8BIT_FIFO_SIZE(spiId))
{
PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_TRANSMIT_BUFFER_IS_1HALF_EMPTY_OR_MORE);
PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_RECEIVE_BUFFER_IS_1HALF_FULL_OR_MORE);
}
/* Flush out the Receive buffer */
PLIB_SPI_BufferClear(spiId);
}
continueLoop = false;
/* Execute the sub tasks */
if
(currentJob->dataLeftToTx +currentJob->dummyLeftToTx != 0)
{
DRV_SPI_MasterEBMSend8BitISR(pDrvInstance);
}
DRV_SPI_ISRErrorTasks(pDrvInstance);
/* Figure out how many bytes are left to be received */
volatile size_t bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
// Check to see if we have any data left to receive and update the bytes left.
if (bytesLeft != 0)
{
DRV_SPI_MasterEBMReceive8BitISR(pDrvInstance);
bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
}
if (bytesLeft == 0)
{
// Disable the interrupt, or more correctly don't re-enable it later*/
pDrvInstance->rxEnabled = false;
/* Job is complete*/
currentJob->status = DRV_SPI_BUFFER_EVENT_COMPLETE;
/* Call the job complete call back*/
if (currentJob->completeCB != NULL)
{
(*currentJob->completeCB)(DRV_SPI_BUFFER_EVENT_COMPLETE, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
}
/* Call the operation complete call back. This is different than the
job complete callback. This can be used to modify the Slave Select line.
The job complete callback can be used to free a client that is blocked
waiting for complete*/
DRV_SPI_CLIENT_OBJECT * pClient = (DRV_SPI_CLIENT_OBJECT*)currentJob->pClient;
if (pClient->operationEnded != NULL)
{
(*pClient->operationEnded)(DRV_SPI_BUFFER_EVENT_COMPLETE, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
}
/* Return the job back to the free queue*/
if (DRV_SPI_SYS_QUEUE_FreeElement(pDrvInstance->queue, currentJob) != DRV_SPI_SYS_QUEUE_SUCCESS)
{
SYS_ASSERT(false, "\r\nSPI Driver: Queue free element error.");
return 0;
}
/* Clean up */
pDrvInstance->currentJob = NULL;
if (!DRV_SPI_SYS_QUEUE_IsEmpty(pDrvInstance->queue))
{
continueLoop = true;
continue;
}
else
{
break;
}
}
/* Check to see if the interrupts would fire again if so just go back into
the loop instead of suffering the interrupt latency of exiting and re-entering*/
if (pDrvInstance->currentJob != NULL)
{
/* Clear the Interrupts */
SYS_INT_SourceStatusClear(pDrvInstance->rxInterruptSource);
SYS_INT_SourceStatusClear(pDrvInstance->txInterruptSource);
SYS_INT_SourceStatusClear(pDrvInstance->errInterruptSource);
/* Interrupts should immediately become active again if they're in a fired condition */
if ((SYS_INT_SourceStatusGet(pDrvInstance->rxInterruptSource)) ||
(SYS_INT_SourceStatusGet(pDrvInstance->txInterruptSource)) ||
(SYS_INT_SourceStatusGet(pDrvInstance->errInterruptSource)))
{
/* Interrupt would fire again anyway so we should just go back to the start*/
continueLoop = true;
continue;
}
/* If we're here then we know that the interrupt should not be firing again immediately, so re-enable them and exit*/
SYS_INT_SourceEnable(pDrvInstance->rxInterruptSource);
SYS_INT_SourceEnable(pDrvInstance->txInterruptSource);
return 0;
}
} while(continueLoop);
/* if we're here it means that we have no more jobs in the queue, tx and rx interrupts will be re-enabled by the BufferAdd* functions*/
SYS_INT_SourceStatusClear(pDrvInstance->rxInterruptSource);
SYS_INT_SourceStatusClear(pDrvInstance->txInterruptSource);
return 0;
}
/* clang-format off */
/*******************************************************************************
SYS CLK Static Functions for Clock System Service
Company:
Microchip Technology Inc.
File Name:
sys_clk_static.c
Summary:
SYS CLK static function implementations for the Clock System Service.
Description:
The Clock System Service provides a simple interface to manage the oscillators
on Microchip microcontrollers. This file defines the static implementation for the
Clock System Service.
Remarks:
Static functions incorporate all system clock configuration settings as
determined by the user via the Microchip Harmony Configurator GUI. It provides
static version of the routines, eliminating the need for an object ID or
object handle.
Static single-open interfaces also eliminate the need for the open handle.
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2014 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
// *****************************************************************************
// *****************************************************************************
// Section: Include Files
// *****************************************************************************
// *****************************************************************************
#include "system_config.h"
#include "system_definitions.h"
#include "peripheral/osc/plib_osc.h"
#include "system/devcon/sys_devcon.h"
// *****************************************************************************
// *****************************************************************************
// Section: File Scope Functions
// *****************************************************************************
// *****************************************************************************
// *****************************************************************************
/* Function:
void SYS_CLK_Static_Initialize ( const SYS_CLK_INIT const * clkInit )
Summary:
Initializes hardware and internal data structure of the System Clock.
Description:
This function initializes the hardware and internal data structure of System
Clock Service.
Remarks:
This is configuration values for the static version of the Clock System Service
module is determined by the user via the Microchip Harmony Configurator GUI.
This template will build a sys_clk_static.h and sys_clk_static.c file with
the configuration per the user's choice.
The objective is to eliminate the user's need to be knowledgeable in the function of
the 'configuration bits' to configure the system oscillators.
*/
void SYS_CLK_Initialize( const SYS_CLK_INIT const * clkInit )
{
SYS_DEVCON_SystemUnlock ( );
PLIB_OSC_FRCDivisorSelect( OSC_ID_0, OSC_FRC_DIV_2);
/* Enable Peripheral Bus 1 */
PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 0, 1 );
SYS_DEVCON_SystemLock ( );
}
//******************************************************************************
/* Function:
inline uint32_t SYS_CLK_SystemFrequencyGet ( void )
Summary:
Gets the system clock frequency in Hertz.
Description:
This function gets the System clock frequency in Hertz.
Precondition:
None.
Parameters:
None.
Returns:
System clock frequency in Hertz.
Example:
<code>
uint32_t sysClockHz;
sysClockHz = SYS_CLK_SystemFrequencyGet ( );
</code>
Remarks:
*/
inline uint32_t SYS_CLK_SystemFrequencyGet ( void )
{
return SYS_CLK_FREQ;
}
//******************************************************************************
/* Function:
inline uint32_t SYS_CLK_PeripheralFrequencyGet ( CLK_BUSES_PERIPHERAL peripheralBus )
Summary:
Gets the selected clock peripheral bus frequency in Hertz.
Description:
This function gets the selected peripheral bus clock frequency in Hertz.
Precondition:
None.
Parameters:
peripheralBus - Reference clock bus selection. One of the possible value from
CLK_BUSES_PERIPHERAL enum. For devices that do not have multiple
clock channels for Reference clock, CLK_BUS_PERIPHERAL_1 should be
the selection.
Returns:
Clock frequency in Hertz.
Example:
<code>
unsigned long peripheralClockHz;
peripheralClockHz = SYS_CLK_PeripheralFrequencyGet ( CLK_BUS_PERIPHERAL_5 );
</code>
Remarks:
Most of the devices doesn't have multiple Peripheral clock buses. In that case,
pass CLK_USB_PERIPHERAL_1 as the bus number.
*/
inline uint32_t SYS_CLK_PeripheralFrequencyGet ( CLK_BUSES_PERIPHERAL peripheralBus )
{
return SYS_CLK_BUS_PERIPHERAL_1;
}
//******************************************************************************
/* Function:
inline uint32_t SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUSES_REFERENCE referenceBus )
Summary:
Gets the selected Reference clock bus frequency in Hertz.
Description:
This function gets frequency of the selected Reference clock bus in Hertz.
Precondition:
None.
Parameters:
peripheralBus - Reference clock bus selection. One of the possible value from
CLK_BUSES_REFERENCE enum. For devices that do not have multiple
clock channels for Reference clock, CLK_BUS_REFERENCE_1 should be
the selection.
Returns:
Clock frequency in Hz.
Example:
<code>
unsigned long sysClockOutputHz;
sysClockOutputHz = SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUS_REFERENCE_3 );
</code>
Remarks:
*/
inline uint32_t SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUSES_REFERENCE referenceBus )
{
return 0;
}
/******************************************************************************
Function:
void SYS_CLK_SecondaryOscillatorEnable ( void )
Summary:
Enables the secondary oscillator.
Description:
This function enables the secondary oscillator.
Remarks:
For more details refer sys_clk.h.
*/
void SYS_CLK_SecondaryOscillatorEnable ( void )
{
/* Check for secondary oscillator status */
if (!PLIB_OSC_SecondaryIsEnabled(OSC_ID_0))
{
/* Unlock and enable secondary oscillator */
SYS_DEVCON_SystemUnlock();
PLIB_OSC_SecondaryEnable(OSC_ID_0);
SYS_DEVCON_SystemLock();
}
}
/******************************************************************************
Function:
void SYS_CLK_SecondaryOscillatorDisable ( void )
Summary:
Disables the secondary oscillator.
Description:
This function disables the secondary oscillator.
Remarks:
For more details refer sys_clk.h.
*/
void SYS_CLK_SecondaryOscillatorDisable ( void )
{
/* Check for secondary oscillator status */
if (PLIB_OSC_SecondaryIsEnabled(OSC_ID_0))
{
/* Unlock and disable secondary oscillator*/
SYS_DEVCON_SystemUnlock();
PLIB_OSC_SecondaryDisable(OSC_ID_0);
SYS_DEVCON_SystemLock();
}
}
/******************************************************************************
Function:
bool SYS_CLK_SecondaryOscillatorIsEnabled ( void )
Summary:
Identifies whether secondary oscillator is enabled or disabled.
Description:
This function identifies whether the secondary oscillator is enabled or
disabled.
Remarks:
For more details refer sys_clk.h.
*/
bool SYS_CLK_SecondaryOscillatorIsEnabled ( void )
{
return (PLIB_OSC_SecondaryIsEnabled(OSC_ID_0));
}
/* clang-format off */
/*******************************************************************************
SYS CLK Static Interface Declarations for Clock System Service
Company:
Microchip Technology Inc.
File Name:
sys_clk_static.h
Summary:
SYS CLK interface declarations for the static system service.
Description:
The Clock System Service provides a simple interface to manage the oscillators
on Microchip microcontrollers. This file defines the interface
Declarations for the SYS CLK system service.
Remarks:
Static interfaces incorporate all system clock configuration settings as
determined by the user via the Microchip Harmony Configurator GUI. It provides
static version of the routines, eliminating the need for an object ID or
object handle.
Static single-open interfaces also eliminate the need for the open handle.
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2014 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
// DOM-IGNORE-BEGIN
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
// DOM-IGNORE-END
#ifndef _SYS_CLK_STATIC_H
#define _SYS_CLK_STATIC_H
// *****************************************************************************
// *****************************************************************************
// Section: SYS CLK Module Initialization Routine (Static Version)
// *****************************************************************************
// *****************************************************************************
#endif // #ifndef _SYS_CLK_STATIC_H
//DOM-IGNORE-BEGIN
#ifdef __cplusplus
}
#endif
//DOM-IGNORE-END
/*******************************************************************************
End of File
*/
/* clang-format off */
/*******************************************************************************
System Definitions
File Name:
system_definitions.h
Summary:
MPLAB Harmony project system definitions.
Description:
This file contains the system-wide prototypes and definitions for an MPLAB
Harmony project.
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2014 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
#ifndef _SYS_DEFINITIONS_H
#define _SYS_DEFINITIONS_H
// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "system/common/sys_common.h"
#include "system/common/sys_module.h"
#include "system/clk/sys_clk.h"
#include "system/clk/sys_clk_static.h"
#include "system/devcon/sys_devcon.h"
#include "system/int/sys_int.h"
#include "system/console/sys_console.h"
#include "system/random/sys_random.h"
#include "system/tmr/sys_tmr.h"
#include "system/reset/sys_reset.h"
#include "driver/tmr/drv_tmr.h"
#include "driver/usart/drv_usart.h"
#include "system/ports/sys_ports.h"
#include "driver/spi/drv_spi.h"
#include "driver/encx24j600/drv_encx24j600.h"
#include "system/debug/sys_debug.h"
#include "system/command/sys_command.h"
#include "tcpip/tcpip.h"
#include "driver/ethmac/drv_ethmac.h"
#include "app.h"
// DOM-IGNORE-BEGIN
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
// DOM-IGNORE-END
// *****************************************************************************
// *****************************************************************************
// Section: Type Definitions
// *****************************************************************************
// *****************************************************************************
// *****************************************************************************
/* System Objects
Summary:
Structure holding the system's object handles
Description:
This structure contains the object handles for all objects in the
MPLAB Harmony project's system configuration.
Remarks:
These handles are returned from the "Initialize" functions for each module
and must be passed into the "Tasks" function for each module.
*/
typedef struct
{
SYS_MODULE_OBJ sysDevcon;
SYS_MODULE_OBJ sysTmr;
SYS_MODULE_OBJ drvTmr0;
SYS_MODULE_OBJ drvUsart0;
SYS_MODULE_OBJ sysDebug;
SYS_MODULE_OBJ sysConsole0;
/*** SPI Object for Index 0 ***/
SYS_MODULE_OBJ spiObjectIdx0;
SYS_MODULE_OBJ tcpip;
} SYSTEM_OBJECTS;
// *****************************************************************************
// *****************************************************************************
// Section: extern declarations
// *****************************************************************************
// *****************************************************************************
extern SYSTEM_OBJECTS sysObj;
//DOM-IGNORE-BEGIN
#ifdef __cplusplus
}
#endif
//DOM-IGNORE-END
#endif /* _SYS_DEFINITIONS_H */
/*******************************************************************************
End of File
*/
#
# Application configuration file generated by
# Microchip Harmony Configurator (MHC) from Harmony version: 1.04
#
mainmenu "MPLAB Harmony & Application Configuration"
menu "Application Configuration"
config APP_INSTANCES
int "Number of Applications"
default 1
range 1 10 # Must limit to 10 or application templates will need to be updated.
source "$HARMONY_VERSION_PATH/utilities/mhc/config/app_name_idx.ftl" 10 instances
menu "Exception Handling"
config USE_EXCEPTION_HANDLER
bool "Use MPLAB Harmony Exception Handler Template?"
default y
---help---
Enter 'Y' if you want to include an exception handler template
(system_exceptions.c) in this system configuration. Enter 'N' if
you do not.
---endhelp---
config EXCEPTION_USE_SYS_DEBUG
bool "Use debug services in exception handler?"
depends on USE_EXCEPTION_HANDLER
default y
---help---
Enter 'Y' if you want the exception handler to use the SYS_DEBUG service to
report exception information. Enter 'N' if you do not.
---endhelp---
config EXCEPTION_BREAKPOINT
bool "Hit breakpoint when an exception occurs?"
depends on USE_EXCEPTION_HANDLER && EXCEPTION_USE_SYS_DEBUG
default y
---help---
Enter 'Y' if you want the exception handler to hit a breakpoint when
an exception occurs. Enter 'N' if you do not.
Note: Only works if debugging is enabled.
---endhelp---
endmenu # Exception Handling
#insert application specific configuration here
endmenu # Application Configuration
source "$HARMONY_VERSION_PATH/config/harmony.hconfig"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment