From f05b1911452f8867c9fc0a17012ad52ec2c2565c Mon Sep 17 00:00:00 2001 From: Zachary Crockett Date: Thu, 17 Jul 2014 10:01:59 -0700 Subject: [PATCH] Only whitespace changes, to clarify the real code changes --- CC3000_Host_Driver/evnt_handler.c | 64 +++++++++---------- CC3000_Host_Driver/socket.c | 19 +++--- SPARK_Firmware_Driver/inc/spi_bus.h | 6 +- SPARK_Firmware_Driver/inc/sst25vf_spi.h | 2 +- SPARK_Firmware_Driver/src/cc3000_spi.c | 81 +++++++++++++------------ SPARK_Firmware_Driver/src/debug.c | 1 + SPARK_Firmware_Driver/src/hw_config.c | 19 +++--- SPARK_Firmware_Driver/src/spi_bus.c | 20 +++--- SPARK_Firmware_Driver/src/sst25vf_spi.c | 10 +-- 9 files changed, 111 insertions(+), 111 deletions(-) diff --git a/CC3000_Host_Driver/evnt_handler.c b/CC3000_Host_Driver/evnt_handler.c index 62eb611..a2ea785 100644 --- a/CC3000_Host_Driver/evnt_handler.c +++ b/CC3000_Host_Driver/evnt_handler.c @@ -121,7 +121,7 @@ // GLOBAL VARAIABLES //***************************************************************************** -static volatile UINT32 socket_active_status = SOCKET_STATUS_INIT_VAL; +static volatile UINT32 socket_active_status = SOCKET_STATUS_INIT_VAL; uint32_t cc3000__event_timeout_ms = 0; //***************************************************************************** @@ -639,22 +639,24 @@ INT32 hci_unsol_event_handler(CHAR *event_hdr) { switch(event_type) { - case HCI_EVNT_DATA_UNSOL_FREE_BUFF: - { - hci_event_unsol_flowcontrol_handler(event_hdr); - - NumberOfReleasedPackets = tSLInformation.NumberOfReleasedPackets; - NumberOfSentPackets = tSLInformation.NumberOfSentPackets; - - if (NumberOfReleasedPackets == NumberOfSentPackets) - { - if (tSLInformation.InformHostOnTxComplete) - { - tSLInformation.sWlanCB(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0); - } - } - return 1; - } + + case HCI_EVNT_DATA_UNSOL_FREE_BUFF: + { + hci_event_unsol_flowcontrol_handler(event_hdr); + + NumberOfReleasedPackets = tSLInformation.NumberOfReleasedPackets; + NumberOfSentPackets = tSLInformation.NumberOfSentPackets; + + if (NumberOfReleasedPackets == NumberOfSentPackets) + { + if (tSLInformation.InformHostOnTxComplete) + { + tSLInformation.sWlanCB(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0); + } + } + return 1; + + } } } @@ -831,22 +833,20 @@ INT32 hci_unsolicited_event_handler(void) //! accordingly the global socket status // //***************************************************************************** - void set_socket_active_status(INT32 Sd, INT32 Status) { //DEBUG("Sd=%d, Status %s",Sd, Status == SOCKET_STATUS_ACTIVE ? "SOCKET_STATUS_ACTIVE" : "SOCKET_STATUS_INACTIVE"); - - if(M_IS_VALID_SD(Sd) && M_IS_VALID_STATUS(Status)) - { - for (;;) { - INT32 oldStatus = socket_active_status; - INT32 newStatus = oldStatus; - newStatus &= ~(1 << Sd); /* clean socket's mask */ - newStatus |= (Status << Sd); /* set new socket's mask */ - if (__sync_bool_compare_and_swap(&socket_active_status, oldStatus, newStatus)) - break; - } - } + if(M_IS_VALID_SD(Sd) && M_IS_VALID_STATUS(Status)) + { + for (;;) { + INT32 oldStatus = socket_active_status; + INT32 newStatus = oldStatus; + newStatus &= ~(1 << Sd); /* clean socket's mask */ + newStatus |= (Status << Sd); /* set new socket's mask */ + if (__sync_bool_compare_and_swap(&socket_active_status, oldStatus, newStatus)) + break; + } + } } //***************************************************************************** @@ -881,8 +881,8 @@ INT32 hci_event_unsol_flowcontrol_handler(CHAR *pEvent) temp += value; pReadPayload += FLOW_CONTROL_EVENT_SIZE; } - - __sync_add_and_fetch(&tSLInformation.usNumberOfFreeBuffers, temp); + + __sync_add_and_fetch(&tSLInformation.usNumberOfFreeBuffers, temp); __sync_add_and_fetch(&tSLInformation.NumberOfReleasedPackets, temp); return(ESUCCESS); diff --git a/CC3000_Host_Driver/socket.c b/CC3000_Host_Driver/socket.c index 64a9d1d..268a31e 100644 --- a/CC3000_Host_Driver/socket.c +++ b/CC3000_Host_Driver/socket.c @@ -118,7 +118,8 @@ INT16 HostFlowControlConsumeBuff(INT16 sd) #ifndef SEND_NON_BLOCKING /* wait in busy loop */ volatile system_tick_t start = GetSystem1MsTick(); - bool stop = false; + + bool stop = false; do { // In case last transmission failed then we will return the last failure @@ -144,16 +145,16 @@ INT16 HostFlowControlConsumeBuff(INT16 sd) ERROR("Timeout waiting on on buffers now %ld start %ld elapsed %ld cc3000__event_timeout_ms %ld",now,start,elapsed,cc3000__event_timeout_ms); return -1; } - - // Do an atomic decrement if > 0 - UINT16 freeBuffers = tSLInformation.usNumberOfFreeBuffers; - if (0 < freeBuffers) { - stop = __sync_bool_compare_and_swap(&tSLInformation.usNumberOfFreeBuffers, freeBuffers, freeBuffers-1); - } + + // Do an atomic decrement if > 0 + UINT16 freeBuffers = tSLInformation.usNumberOfFreeBuffers; + if (0 < freeBuffers) { + stop = __sync_bool_compare_and_swap(&tSLInformation.usNumberOfFreeBuffers, freeBuffers, freeBuffers-1); + } } while (!stop); return 0; #else -#error not here + // In case last transmission failed then we will return the last failure // reason here. // Note that the buffer will not be allocated in this case @@ -1053,7 +1054,7 @@ INT16 simple_link_send(INT32 sd, const void *buf, INT32 len, INT32 flags, args = UINT32_TO_STREAM(args, addr_offset); args = UINT32_TO_STREAM(args, addrlen); } - + // Copy the data received from user into the TX Buffer ARRAY_TO_STREAM(pDataPtr, ((UINT8 *)buf), len); diff --git a/SPARK_Firmware_Driver/inc/spi_bus.h b/SPARK_Firmware_Driver/inc/spi_bus.h index dd5d55e..41477a5 100644 --- a/SPARK_Firmware_Driver/inc/spi_bus.h +++ b/SPARK_Firmware_Driver/inc/spi_bus.h @@ -1,4 +1,4 @@ -/* +/* * File: spi_bus.h * Author: mat * @@ -13,9 +13,9 @@ extern "C" { #endif void reset_bus(); - + int try_acquire_spi_bus(int owner); - + void acquire_spi_bus(int owner); void release_spi_bus(int owner); diff --git a/SPARK_Firmware_Driver/inc/sst25vf_spi.h b/SPARK_Firmware_Driver/inc/sst25vf_spi.h index 6e122e2..e5de4a6 100644 --- a/SPARK_Firmware_Driver/inc/sst25vf_spi.h +++ b/SPARK_Firmware_Driver/inc/sst25vf_spi.h @@ -62,7 +62,7 @@ extern "C" { void sFLASH_Init(void); void sFLASH_EraseSector(uint32_t SectorAddr); void sFLASH_EraseBulk(void); -void sFLASH_WriteBuffer(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite); +void sFLASH_WriteBuffer(const uint8_t *pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite); void sFLASH_ReadBuffer(uint8_t *pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead); uint32_t sFLASH_ReadID(void); diff --git a/SPARK_Firmware_Driver/src/cc3000_spi.c b/SPARK_Firmware_Driver/src/cc3000_spi.c index ec8c8e4..06ed13b 100644 --- a/SPARK_Firmware_Driver/src/cc3000_spi.c +++ b/SPARK_Firmware_Driver/src/cc3000_spi.c @@ -50,7 +50,7 @@ typedef enum eSPI_STATE_WRITE_WAIT_IRQ, eSPI_STATE_WRITE_PROCEED, eSPI_STATE_WRITE_DONE, - eSPI_STATE_READ_IRQ, + eSPI_STATE_READ_IRQ, eSPI_STATE_READ_PROCEED, eSPI_STATE_READ_READY, eSPI_STATE_READ_PREP_IRQ @@ -122,14 +122,15 @@ static inline eCC3000States SetState(eCC3000States ns, eCSActions cs) intState save = DISABLE_INT(); eCC3000States os = sSpiInformation.ulSpiState; sSpiInformation.ulSpiState = ns; - switch (cs) { - case eAssert: - ASSERT_CS(); - break; - case eDeAssert: - DEASSERT_CS(); - break; - } + switch (cs) + { + case eAssert: + ASSERT_CS(); + break; + case eDeAssert: + DEASSERT_CS(); + break; + } ENABLE_INT(save); return os; } @@ -241,7 +242,7 @@ void SpiPauseSpi(void) int SpiIO(eSPIOperation op, const uint8_t *ptrData, uint32_t ulDataSize, int waitOnCompletion) { - eCC3000States current = State(); + eCC3000States current = State(); /* Disable DMA Channels */ CC3000_SPI_DMA_Channels(DISABLE); @@ -263,6 +264,7 @@ int SpiIO(eSPIOperation op, const uint8_t *ptrData, uint32_t ulDataSize, int wai /* Enable DMA Channels */ CC3000_SPI_DMA_Channels(ENABLE); return waitOnCompletion ? Still(current) : 0; + } long SpiSetUp(unsigned char *pUserBuffer, unsigned short usLength) @@ -329,7 +331,7 @@ long SpiWrite(unsigned char *ucBuf, unsigned short usLength) if(NotAborted) { NotAborted = Reserve(eSPI_STATE_WRITE_WAIT_IRQ); - //WARN("CC3000 SpiWrite acquire bus"); + //WARN("CC3000 SpiWrite acquire bus"); if(NotAborted) { usLength = SpiSetUp(ucBuf, usLength); @@ -431,8 +433,8 @@ void SPI_DMA_IntHandler(void) } else { - SetState(eSPI_STATE_IDLE, eDeAssert); - //WARN("CC3000 DmaHandler release write spi bus"); + SetState(eSPI_STATE_IDLE, eDeAssert); + //WARN("CC3000 DmaHandler release write spi bus"); } } break; @@ -444,8 +446,9 @@ void SPI_DMA_IntHandler(void) } } -void handle_spi_request() { - if (State()==eSPI_STATE_READ_PREP_IRQ && try_acquire_spi_bus(BUS_OWNER_CC3000)) +void handle_spi_request() +{ + if (State() == eSPI_STATE_READ_PREP_IRQ && try_acquire_spi_bus(BUS_OWNER_CC3000)) { DEBUG("Handling CC3000 request on main thread"); SetState(eSPI_STATE_READ_IRQ, eAssert); @@ -462,29 +465,29 @@ void handle_spi_request() { */ void SPI_EXTI_IntHandler(void) { - //Pending is cleared in first level of ISR handler - if (!tSLInformation.ReadWlanInterruptPin()) - { - switch(sSpiInformation.ulSpiState) - { - case eSPI_STATE_POWERUP: - sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED; - break; - case eSPI_STATE_IDLE: - if (try_acquire_spi_bus(BUS_OWNER_CC3000)) { - SetState(eSPI_STATE_READ_IRQ, eAssert); - SpiIO(eRead, sSpiInformation.pRxPacket, arraySize(spi_readCommand), FALSE); - } else { - SetState(eSPI_STATE_READ_PREP_IRQ, eNone); - WARN("CC3000 cannot lock bus - scheduling later (owner=%d)", current_bus_owner()); - } - break; - case eSPI_STATE_WRITE_WAIT_IRQ: - sSpiInformation.ulSpiState = eSPI_STATE_WRITE_PROCEED; - break; - default: - break; - } - } + //Pending is cleared in first level of ISR handler + if (!tSLInformation.ReadWlanInterruptPin()) + { + switch(sSpiInformation.ulSpiState) + { + case eSPI_STATE_POWERUP: + sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED; + break; + case eSPI_STATE_IDLE: + if (try_acquire_spi_bus(BUS_OWNER_CC3000)) { + SetState(eSPI_STATE_READ_IRQ, eAssert); + SpiIO(eRead, sSpiInformation.pRxPacket, arraySize(spi_readCommand), FALSE); + } else { + SetState(eSPI_STATE_READ_PREP_IRQ, eNone); + WARN("CC3000 cannot lock bus - scheduling later (owner=%d)", current_bus_owner()); + } + break; + case eSPI_STATE_WRITE_WAIT_IRQ: + sSpiInformation.ulSpiState = eSPI_STATE_WRITE_PROCEED; + break; + default: + break; + } + } } diff --git a/SPARK_Firmware_Driver/src/debug.c b/SPARK_Firmware_Driver/src/debug.c index 2067146..a2de809 100644 --- a/SPARK_Firmware_Driver/src/debug.c +++ b/SPARK_Firmware_Driver/src/debug.c @@ -14,6 +14,7 @@ #include "spark_macros.h" #include "debug.h" + uint32_t log_level_at_run_time = LOG_LEVEL_AT_RUN_TIME; void log_print_(int level, int line, const char *func, const char *file, const char *msg, ...) diff --git a/SPARK_Firmware_Driver/src/hw_config.c b/SPARK_Firmware_Driver/src/hw_config.c index c436e2d..6315481 100644 --- a/SPARK_Firmware_Driver/src/hw_config.c +++ b/SPARK_Firmware_Driver/src/hw_config.c @@ -32,7 +32,6 @@ #include "debug.h" #include "cc3000_spi.h" - /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ @@ -956,7 +955,7 @@ void CC3000_SPI_DMA_Channels(FunctionalState NewState) /* Select CC3000: ChipSelect pin low */ void CC3000_CS_LOW(void) { - acquire_spi_bus(BUS_OWNER_CC3000); + acquire_spi_bus(BUS_OWNER_CC3000); CC3000_SPI->CR1 &= ((uint16_t)0xFFBF); CC3000_SPI->CR1 = CC3000_SPI_CR | ((uint16_t)0x0040); GPIO_ResetBits(CC3000_WIFI_CS_GPIO_PORT, CC3000_WIFI_CS_GPIO_PIN); @@ -966,7 +965,7 @@ void CC3000_CS_LOW(void) void CC3000_CS_HIGH(void) { GPIO_SetBits(CC3000_WIFI_CS_GPIO_PORT, CC3000_WIFI_CS_GPIO_PIN); - release_spi_bus(BUS_OWNER_CC3000); + release_spi_bus(BUS_OWNER_CC3000); } /* CC3000 Hardware related callbacks passed to wlan_init */ @@ -1138,18 +1137,18 @@ void sFLASH_SPI_Init(void) /* Select sFLASH: Chip Select pin low */ void sFLASH_CS_LOW(void) { - acquire_spi_bus(BUS_OWNER_SFLASH); - sFLASH_SPI->CR1 &= ((uint16_t)0xFFBF); - sFLASH_SPI->CR1 = sFLASH_SPI_CR | ((uint16_t)0x0040); - GPIO_ResetBits(sFLASH_MEM_CS_GPIO_PORT, sFLASH_MEM_CS_GPIO_PIN); + acquire_spi_bus(BUS_OWNER_SFLASH); + sFLASH_SPI->CR1 &= ((uint16_t)0xFFBF); + sFLASH_SPI->CR1 = sFLASH_SPI_CR | ((uint16_t)0x0040); + GPIO_ResetBits(sFLASH_MEM_CS_GPIO_PORT, sFLASH_MEM_CS_GPIO_PIN); } /* Deselect sFLASH: Chip Select pin high */ void sFLASH_CS_HIGH(void) { - GPIO_SetBits(sFLASH_MEM_CS_GPIO_PORT, sFLASH_MEM_CS_GPIO_PIN); - release_spi_bus(BUS_OWNER_SFLASH); - handle_spi_request(); + GPIO_SetBits(sFLASH_MEM_CS_GPIO_PORT, sFLASH_MEM_CS_GPIO_PIN); + release_spi_bus(BUS_OWNER_SFLASH); + handle_spi_request(); } /******************************************************************************* diff --git a/SPARK_Firmware_Driver/src/spi_bus.c b/SPARK_Firmware_Driver/src/spi_bus.c index 82e8742..55ccafb 100644 --- a/SPARK_Firmware_Driver/src/spi_bus.c +++ b/SPARK_Firmware_Driver/src/spi_bus.c @@ -1,12 +1,10 @@ - #include #include #include "spi_bus.h" #include "debug.h" #include "hw_config.h" - -#ifndef SPI_BUS_ARBITER +#ifndef SPI_BUS_ARBITER #define SPI_BUS_ARBITER 1 #endif @@ -17,33 +15,31 @@ void reset_bus() { spi_bus_lock = 0; } int try_acquire_spi_bus(int owner) { #if SPI_BUS_ARBITER __sync_synchronize(); - return spi_bus_lock==owner || __sync_bool_compare_and_swap(&spi_bus_lock, 0, owner); + return spi_bus_lock==owner || __sync_bool_compare_and_swap(&spi_bus_lock, 0, owner); #else return 1; #endif } void acquire_spi_bus(int owner) { -#if SPI_BUS_ARBITER +#if SPI_BUS_ARBITER while (!try_acquire_spi_bus(owner)); -#endif +#endif } int try_release_spi_bus(int owner) { -#if SPI_BUS_ARBITER +#if SPI_BUS_ARBITER __sync_synchronize(); return spi_bus_lock==0 || __sync_bool_compare_and_swap(&spi_bus_lock, owner, 0); #else return 1; -#endif +#endif } -void release_spi_bus(int owner) { +void release_spi_bus(int owner) { #if SPI_BUS_ARBITER while (!try_release_spi_bus(owner)); -#endif - +#endif } int current_bus_owner() { return spi_bus_lock; } - diff --git a/SPARK_Firmware_Driver/src/sst25vf_spi.c b/SPARK_Firmware_Driver/src/sst25vf_spi.c index 86d7cad..17016ec 100644 --- a/SPARK_Firmware_Driver/src/sst25vf_spi.c +++ b/SPARK_Firmware_Driver/src/sst25vf_spi.c @@ -199,10 +199,10 @@ static void sFLASH_WriteBytes(const uint8_t *pBuffer, uint32_t WriteAddr, uint32 /* while there is data to be written on the FLASH */ while (NumByteToWrite) { - /* Select the FLASH: Chip Select low */ - sFLASH_CS_LOW(); - /* Send "Auto Address Increment Word-Program" instruction */ - sFLASH_SendByte(sFLASH_CMD_AAIP); + /* Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + /* Send "Auto Address Increment Word-Program" instruction */ + sFLASH_SendByte(sFLASH_CMD_AAIP); /* Send the next byte and point on the next byte */ sFLASH_SendByte(*pBuffer++); /* Send the next byte and point on the next byte */ @@ -231,7 +231,7 @@ static void sFLASH_WriteBytes(const uint8_t *pBuffer, uint32_t WriteAddr, uint32 * @param NumByteToWrite: number of bytes to write to the FLASH. * @retval None */ -void sFLASH_WriteBuffer(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite) +void sFLASH_WriteBuffer(const uint8_t *pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite) { uint32_t evenBytes;