Skip to content

Commit

Permalink
WIP #3 : Integrated CC3000 WLAN code to implement OTA DFU
Browse files Browse the repository at this point in the history
  • Loading branch information
satishgn committed May 22, 2013
1 parent 7e35e96 commit 41276d4
Show file tree
Hide file tree
Showing 29 changed files with 9,236 additions and 38 deletions.
61 changes: 61 additions & 0 deletions inc/cc3000_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
******************************************************************************
* @file cc3000_spi.h
* @author Spark Application Team
* @version V1.0.0
* @date 29-March-2013
* @brief This file contains all the functions prototypes for the
* CC3000 SPI firmware driver.
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CC3000_SPI_H
#define __CC3000_SPI_H

/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "hw_config.h"
#include "cc3000_common.h"
#include "hci.h"
#include "wlan.h"

#define FALSE 0x00
#define TRUE !FALSE

#define READ 0x03
#define WRITE 0x01

#define HI(value) (((value) & 0xFF00) >> 8)
#define LO(value) ((value) & 0x00FF)

#define ASSERT_CS() CC3000_CS_LOW()
#define DEASSERT_CS() CC3000_CS_HIGH()

/*It takes roughly 4 instruction to perform a delay*/
#define FIFTY_US_DELAY (((SystemCoreClock/1000000)*50)/4) // (24*50)/4 for 24 MHz clk
#define DMA_WINDOW_SIZE 1024
#define SPI_WINDOW_SIZE DMA_WINDOW_SIZE

#define HEADERS_SIZE_EVNT (SPI_HEADER_SIZE + 5)

// See cc3000_common.h starting around line 73
#define CC3000_RX_BUFFER_SIZE CC3000_MAXIMAL_RX_SIZE
#define CC3000_TX_BUFFER_SIZE CC3000_MAXIMAL_TX_SIZE
#define SPI_BUFFER_SIZE 1024

typedef void (*gcSpiHandleRx)(void *p);
typedef void (*gcSpiHandleTx)(void);

extern unsigned char wlan_rx_buffer[];
extern unsigned char wlan_tx_buffer[];

/* CC3000 SPI Protocol API */
extern void SpiOpen(gcSpiHandleRx pfRxHandler);
extern void SpiClose(void);
extern long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength);
extern void SpiResumeSpi(void);
extern void SPI_DMA_IntHandler(void);
extern void SPI_EXTI_IntHandler(void);

#endif /* __CC3000_SPI_H */
26 changes: 26 additions & 0 deletions inc/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/* Includes ------------------------------------------------------------------*/

#include "platform_config.h"
#include "cc3000_common.h"

/* Exported types ------------------------------------------------------------*/

Expand All @@ -32,13 +33,23 @@ typedef enum
BUTTON_MODE_GPIO = 0, BUTTON_MODE_EXTI = 1
} ButtonMode_TypeDef;

typedef enum
{
CC3000_DMA_TX = 0, CC3000_DMA_RX = 1
} CC3000_DMADirection_TypeDef;

/* Exported constants --------------------------------------------------------*/

/* Flash memory address from where user application will be loaded */
#define ApplicationAddress 0x08007000

/* Exported macro ------------------------------------------------------------*/

/* Select CC3000: ChipSelect pin low */
#define CC3000_CS_LOW() GPIO_ResetBits(CC3000_WIFI_CS_GPIO_PORT, CC3000_WIFI_CS_PIN)
/* Deselect CC3000: ChipSelect pin high */
#define CC3000_CS_HIGH() GPIO_SetBits(CC3000_WIFI_CS_GPIO_PORT, CC3000_WIFI_CS_PIN)

/* Select sFLASH: Chip Select pin low */
#define sFLASH_CS_LOW() GPIO_ResetBits(sFLASH_MEM_CS_GPIO_PORT, sFLASH_MEM_CS_PIN)
/* Deselect sFLASH: Chip Select pin high */
Expand All @@ -58,6 +69,19 @@ void BUTTON_EXTI_Config(Button_TypeDef Button, FunctionalState NewState);
uint8_t BUTTON_GetState(Button_TypeDef Button);
uint8_t BUTTON_GetDebouncedState(Button_TypeDef Button);

/* CC3000 Hardware related methods */
void CC3000_WIFI_Init(void);
void CC3000_SPI_Init(void);
void CC3000_DMA_Config(CC3000_DMADirection_TypeDef Direction, uint8_t* buffer, uint16_t NumData);
void CC3000_SPI_DMA_Init(void);
void CC3000_SPI_DMA_Channels(FunctionalState NewState);

/* CC3000 Hardware related callbacks passed to wlan_init */
long CC3000_Read_Interrupt_Pin(void);
void CC3000_Interrupt_Enable(void);
void CC3000_Interrupt_Disable(void);
void CC3000_Write_Enable_Pin(unsigned char val);

/* Serial Flash Hardware related methods */
void sFLASH_SPI_DeInit(void);
void sFLASH_SPI_Init(void);
Expand All @@ -73,5 +97,7 @@ void Reset_Device(void);
void Get_SerialNum(void);

/* External variables --------------------------------------------------------*/
extern unsigned char wlan_rx_buffer[];
extern unsigned char wlan_tx_buffer[];

#endif /*__HW_CONFIG_H*/
17 changes: 16 additions & 1 deletion inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@

/* Includes ------------------------------------------------------------------*/

#include "platform_config.h"
#include "hw_config.h"
#include "evnt_handler.h"
#include "hci.h"
#include "wlan.h"
#include "nvmem.h"
#include "socket.h"
#include "netapp.h"

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
Expand All @@ -23,4 +29,13 @@
void Timing_Decrement(void);
void Delay(__IO uint32_t nTime);

void Set_NetApp_Timeout(void);
void Start_Smart_Config(void);

/* WLAN Application related callbacks passed to wlan_init */
void WLAN_Async_Callback(long lEventType, char *data, unsigned char length);
char *WLAN_Firmware_Patch(unsigned long *length);
char *WLAN_Driver_Patch(unsigned long *length);
char *WLAN_BootLoader_Patch(unsigned long *length);

#endif /* __MAIN_H */
80 changes: 80 additions & 0 deletions inc/platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@
#define DEBOUNCE_TIMER_FLAG TIM_IT_Update
#define DEBOUNCE_TIMER_IRQn TIM1_UP_IRQn

//CC3000 Interface pins
#define CC3000_SPI SPI2
#define CC3000_SPI_CLK RCC_APB1Periph_SPI2
#define CC3000_SPI_CLK_CMD RCC_APB1PeriphClockCmd
#define CC3000_SPI_SCK_PIN GPIO_Pin_13 /* PB.13 */
#define CC3000_SPI_SCK_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOB
#define CC3000_SPI_MISO_PIN GPIO_Pin_14 /* PB.14 */
#define CC3000_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOB
#define CC3000_SPI_MOSI_PIN GPIO_Pin_15 /* PB.15 */
#define CC3000_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOB
#define CC3000_WIFI_CS_PIN GPIO_Pin_12 /* PB.12 */
#define CC3000_WIFI_CS_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_WIFI_CS_GPIO_CLK RCC_APB2Periph_GPIOB
#define CC3000_WIFI_EN_PIN GPIO_Pin_8 /* PB.08 */
#define CC3000_WIFI_EN_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_WIFI_EN_GPIO_CLK RCC_APB2Periph_GPIOB
#define CC3000_WIFI_INT_PIN GPIO_Pin_11 /* PB.11 */
#define CC3000_WIFI_INT_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_WIFI_INT_GPIO_CLK RCC_APB2Periph_GPIOB

#define CC3000_WIFI_INT_EXTI_LINE EXTI_Line11
#define CC3000_WIFI_INT_EXTI_PORT_SOURCE GPIO_PortSourceGPIOB
#define CC3000_WIFI_INT_EXTI_PIN_SOURCE GPIO_PinSource11
#define CC3000_WIFI_INT_EXTI_IRQn EXTI15_10_IRQn

#define CC3000_SPI_DMA_CLK RCC_AHBPeriph_DMA1
#define CC3000_SPI_RX_DMA_CHANNEL DMA1_Channel4
#define CC3000_SPI_TX_DMA_CHANNEL DMA1_Channel5
#define CC3000_SPI_RX_DMA_TCFLAG DMA1_FLAG_TC4
#define CC3000_SPI_TX_DMA_TCFLAG DMA1_FLAG_TC5
#define CC3000_SPI_RX_DMA_IRQn DMA1_Channel4_IRQn
#define CC3000_SPI_TX_DMA_IRQn DMA1_Channel5_IRQn

#define CC3000_SPI_DR_BASE ((uint32_t)0x4000380C) /* SPI2_BASE | 0x0C */

#define CC3000_SPI_BAUDRATE_PRESCALER SPI_BaudRatePrescaler_32

//SST25 FLASH Interface pins
#define sFLASH_SPI SPI2
#define sFLASH_SPI_CLK RCC_APB1Periph_SPI2
Expand Down Expand Up @@ -140,6 +180,46 @@
#define DEBOUNCE_TIMER_FLAG TIM_IT_Update
#define DEBOUNCE_TIMER_IRQn TIM1_UP_IRQn

//CC3000 Interface pins
#define CC3000_SPI SPI1
#define CC3000_SPI_CLK RCC_APB2Periph_SPI1
#define CC3000_SPI_CLK_CMD RCC_APB2PeriphClockCmd
#define CC3000_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */
#define CC3000_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */
#define CC3000_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOA
#define CC3000_SPI_MISO_PIN GPIO_Pin_6 /* PA.06 */
#define CC3000_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */
#define CC3000_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOA
#define CC3000_SPI_MOSI_PIN GPIO_Pin_7 /* PA.07 */
#define CC3000_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */
#define CC3000_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOA
#define CC3000_WIFI_CS_PIN GPIO_Pin_8 /* PA.08 */
#define CC3000_WIFI_CS_GPIO_PORT GPIOA /* GPIOA */
#define CC3000_WIFI_CS_GPIO_CLK RCC_APB2Periph_GPIOA
#define CC3000_WIFI_EN_PIN GPIO_Pin_1 /* PB.01 */
#define CC3000_WIFI_EN_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_WIFI_EN_GPIO_CLK RCC_APB2Periph_GPIOB
#define CC3000_WIFI_INT_PIN GPIO_Pin_0 /* PB.00 */
#define CC3000_WIFI_INT_GPIO_PORT GPIOB /* GPIOB */
#define CC3000_WIFI_INT_GPIO_CLK RCC_APB2Periph_GPIOB

#define CC3000_WIFI_INT_EXTI_LINE EXTI_Line0
#define CC3000_WIFI_INT_EXTI_PORT_SOURCE GPIO_PortSourceGPIOB
#define CC3000_WIFI_INT_EXTI_PIN_SOURCE GPIO_PinSource0
#define CC3000_WIFI_INT_EXTI_IRQn EXTI0_IRQn

#define CC3000_SPI_DMA_CLK RCC_AHBPeriph_DMA1
#define CC3000_SPI_RX_DMA_CHANNEL DMA1_Channel2
#define CC3000_SPI_TX_DMA_CHANNEL DMA1_Channel3
#define CC3000_SPI_RX_DMA_TCFLAG DMA1_FLAG_TC2
#define CC3000_SPI_TX_DMA_TCFLAG DMA1_FLAG_TC3
#define CC3000_SPI_RX_DMA_IRQn DMA1_Channel2_IRQn
#define CC3000_SPI_TX_DMA_IRQn DMA1_Channel3_IRQn

#define CC3000_SPI_DR_BASE ((uint32_t)0x4001300C) /* SPI1_BASE | 0x0C */

#define CC3000_SPI_BAUDRATE_PRESCALER SPI_BaudRatePrescaler_32

//SST25 FLASH Interface pins
#define sFLASH_SPI SPI2
#define sFLASH_SPI_CLK RCC_APB1Periph_SPI2
Expand Down
2 changes: 2 additions & 0 deletions inc/stm32_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel3_IRQHandler(void);
void DMA1_Channel5_IRQHandler(void);
void EXTI0_IRQHandler(void);
void EXTI15_10_IRQHandler(void);
void TIM1_UP_IRQHandler(void);
Expand Down
Loading

0 comments on commit 41276d4

Please sign in to comment.