//*****************************************************************************
//
// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************
//*****************************************************************************
//
// Application Name - Getting started with WLAN AP
// Application Overview - This application aims to exhibit the CC3200 device as
// AP. Developers/users can refer the function or re-use
// them while writing new application.
// Application Details -
// http://processors.wiki.ti.com/index.php/CC32xx_Getting_Started_with_WLAN_AP
// or
// docs\examples\CC32xx_Getting_Started_with_WLAN_AP.pdf
//
//*****************************************************************************
//****************************************************************************
//
//! \addtogroup getting_started_ap
//! @{
//
//****************************************************************************
#include <stdlib.h>
#include <string.h>
// Simplelink includes
#include "simplelink.h"
// driverlib includes
#include "hw_types.h"
#include "hw_ints.h"
#include "rom.h"
#include "rom_map.h"
#include "interrupt.h"
#include "prcm.h"
#include "utils.h"
// free_rtos/ti-rtos includes
#include "osi.h"
// common interface includes
#include "common.h"
#ifndef NOTERM
#include "uart_if.h"
#endif
#include "pinmux.h"
#include "hw_memmap.h"
#include "hw_mcspi.h"
#include "spi.h"
#include "udma.h"
#include "udma_if.h"
#include "gpio_if.h"
#define OSI_STACK_SIZE 4096
#define SPI_IF_BIT_RATE 8000000
#define TR_BUFF_SIZE 1024
static unsigned char Rx1Buff[TR_BUFF_SIZE]="123456789";
static unsigned char Rx2Buff[TR_BUFF_SIZE];
static unsigned char TxFlag=0,switch_flag=1;
// Application specific status/error codes
typedef enum{
// Choosing this number to avoid overlap w/ host-driver's error codes
LAN_CONNECTION_FAILED = -0x7D0,
CLIENT_CONNECTION_FAILED = LAN_CONNECTION_FAILED - 1,
DEVICE_NOT_IN_STATION_MODE = CLIENT_CONNECTION_FAILED - 1,
STATUS_CODE_MAX = -0xBB8
}e_AppStatusCodes;
//*****************************************************************************
// GLOBAL VARIABLES -- Start
//*****************************************************************************
unsigned char g_ulStatus = 0;
unsigned long g_ulStaIp = 0;
unsigned long g_ulPingPacketsRecv = 0;
unsigned long g_uiGatewayIP = 0;
#if defined(gcc)
extern void (* const g_pfnVectors[])(void);
#endif
#if defined(ewarm)
extern uVectorEntry __vector_table;
#endif
//*****************************************************************************
// GLOBAL VARIABLES -- End
//*****************************************************************************
//****************************************************************************
// LOCAL FUNCTION PROTOTYPES
//****************************************************************************
static long ConfigureSimpleLinkToDefaultState();
static void InitializeAppVariables();
static int GetSsidName(char *pcSsidName, unsigned int uiMaxLen);
int BsdTcpServer(unsigned short usPort);
//*****************************************************************************
// SimpleLink Asynchronous Event Handlers -- Start
//*****************************************************************************
//*****************************************************************************
//
//! SPI Slave Interrupt handler
//!
//! This function is invoked when SPI slave has its receive register full or
//! transmit register empty.
//!
//! \return None.
//
//*****************************************************************************
static void SlaveIntHandler()
{
unsigned long ulStatus;
ulStatus = MAP_SPIIntStatus(GSPI_BASE,true);
MAP_SPIIntClear(GSPI_BASE,SPI_INT_EOW);
MAP_SPIDisable(GSPI_BASE);
if(switch_flag==1)
{
UDMASetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
Rx2Buff,UDMA_DST_INC_8);
}
else
{
UDMASetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
Rx1Buff,UDMA_DST_INC_8);
}
MAP_SPIEnable(GSPI_BASE);
TxFlag=1;
}
//*****************************************************************************
//
//! SPI Slave mode main loop
//!
//! This function configures SPI modelue as slave and enables the channel for
//! communication
//!
//! \return None.
//
//*****************************************************************************
void SlaveMain(void *pvParameters )
{
//
// Reset SPI
//
MAP_PRCMPeripheralClkEnable(PRCM_GSPI,PRCM_RUN_MODE_CLK);
// MAP_PRCMPeripheralReset(PRCM_GSPI);
MAP_SPIReset(GSPI_BASE);
UDMAInit();
MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI),
SPI_IF_BIT_RATE,SPI_MODE_SLAVE,SPI_SUB_MODE_0,
(SPI_HW_CTRL_CS|
SPI_4PIN_MODE |
SPI_TURBO_OFF |
SPI_CS_ACTIVEHIGH |
SPI_WL_8));
MAP_SPIIntRegister(GSPI_BASE,SlaveIntHandler);
MAP_SPIWordCountSet(GSPI_BASE, 1024);
MAP_SPIFIFOLevelSet(GSPI_BASE, 1, 1);
MAP_SPIFIFOEnable(GSPI_BASE, SPI_RX_FIFO);
MAP_SPIFIFOEnable(GSPI_BASE, SPI_TX_FIFO);
MAP_SPIDmaEnable(GSPI_BASE,SPI_RX_DMA);
MAP_SPIDmaEnable(GSPI_BASE,SPI_TX_DMA);
MAP_SPIIntEnable(GSPI_BASE, SPI_INT_EOW);
MAP_SPIEnable(GSPI_BASE);
MAP_SPIDisable(GSPI_BASE);
UDMASetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
Rx1Buff,UDMA_DST_INC_8);
MAP_SPIEnable(GSPI_BASE);
}
//***********************************