Refactored: function names, coding style

This commit is contained in:
Michał Łyszczek 2016-08-17 21:34:51 +02:00
parent 44e0a837a8
commit 2ae38b6bc6
9 changed files with 185 additions and 93 deletions

View File

@ -182,14 +182,6 @@ extern "C" {
* Public Function Prototypes
******************************************************************************/
/*******************************************************************************
* Name: stm32_led_initialize
*
* Description:
* Initializes board specific LEDS
******************************************************************************/
void stm32_led_initialize(void);
/*******************************************************************************
* Name: stm32_boardinitialize
*
@ -199,6 +191,7 @@ void stm32_led_initialize(void);
* has been configured and mapped but before any devices have been
* initialized.
******************************************************************************/
EXTERN void stm32_boardinitialize(void);
#undef EXTERN

View File

@ -1,4 +1,4 @@
/*******************************************************************************
/*****************************************************************************
* configs/stm32butterfly2/src/stm32_adc.c
*
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
@ -30,22 +30,28 @@
* 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.
*
******************************************************************************/
****************************************************************************/
/*******************************************************************************
/*****************************************************************************
* Included Files
******************************************************************************/
****************************************************************************/
#include <chip.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/config.h>
#include <stm32_adc.h>
/*******************************************************************************
#include "stm32_adc.h"
/*****************************************************************************
* Public Functions
******************************************************************************/
****************************************************************************/
/*****************************************************************************
* Name: board_adc_setup
*
* Description:
* Function initializes channel 1 of adc1 and registers device as /dev/adc0
****************************************************************************/
int board_adc_setup(void)
{
@ -60,8 +66,7 @@ int board_adc_setup(void)
}
stm32_configgpio(GPIO_ADC12_IN10);
adc = stm32_adcinitialize(1, channel, 1);
if (adc == NULL)
if ((adc = stm32_adcinitialize(1, channel, 1)) == NULL)
{
aerr("ERROR: Failed to get adc interface\n");
return -ENODEV;
@ -76,3 +81,4 @@ int board_adc_setup(void)
initialized = true;
return OK;
}

View File

@ -1,4 +1,4 @@
/*******************************************************************************
/*****************************************************************************
* configs/stm32butterfly2/src/boot.c
*
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
@ -30,23 +30,28 @@
* 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.
*
******************************************************************************/
****************************************************************************/
/*******************************************************************************
/*****************************************************************************
* Included Files
******************************************************************************/
****************************************************************************/
#include <nuttx/config.h>
#include <arch/board/board.h>
#include <syslog.h>
#include "stm32_gpio.h"
#include "stm32_butterfly2.h"
/*******************************************************************************
/*****************************************************************************
* Public Functions
******************************************************************************/
****************************************************************************/
/*****************************************************************************
* Name: stm32_boardinitialize
*
* Description:
* Initializes low level pins for the drivers.
****************************************************************************/
void stm32_boardinitialize(void)
{
@ -55,20 +60,35 @@ void stm32_boardinitialize(void)
stm32_usb_initialize();
}
/*****************************************************************************
* Name: board_app_initialize
*
* Description:
* Initializes upper half drivers with board specific settings
*
* Returned value:
* 0 on sucess or errno value of failed init function.
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
int rv;
if ((rv = stm32_sdinitialize(CONFIG_NSH_MMCSDMINOR)) < 0)
int rv = 0;
#ifdef CONFIG_MMCSD
if ((rv = stm32_mmcsd_initialize(CONFIG_NSH_MMCSDMINOR)) < 0)
{
syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n");
return rv;
}
#endif
#ifdef CONFIG_USBHOST
if ((rv = stm32_usbhost_initialize()) < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", rv);
return rv;
}
#endif
return 0;
return rv;
}

View File

@ -30,7 +30,6 @@
* 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.
*
****************************************************************************/
/*****************************************************************************
@ -59,6 +58,15 @@
* Public Functions
****************************************************************************/
/*****************************************************************************
* Name: stm32_led_initialize
*
* Description:
* Initializes low level gpio pins for board LEDS
****************************************************************************/
void stm32_led_initialize(void);
/*****************************************************************************
* Name: stm32_spidev_initialize
*
@ -70,17 +78,25 @@
* itself.
****************************************************************************/
#ifdef CONFIG_STM32_SPI1
void stm32_spidev_initialize(void);
#else
static inline void stm32_spidev_initialize(void);
#endif
/*****************************************************************************
* Name: stm32_sdinitialize
* Name: stm32_mmcsd_initialize
*
* Description:
* Initializes SPI-based SD card
*
****************************************************************************/
int stm32_sdinitialize(int minor);
#ifdef CONFIG_MMCSD
int stm32_mmcsd_initialize(int minor);
#else
static inline int stm32_mmcsd_initialize(int minor);
#endif
/*****************************************************************************
* Name: stm32_usb_initialize

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* configs/stm32butterfly2/src/led.c
/*****************************************************************************
* configs/stm32butterfly2/src/stm32_led.c
*
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
* Author: Michał Łyszczek <michal.lyszczek@gmail.com>
@ -31,26 +31,22 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
****************************************************************************/
/*******************************************************************************
/*****************************************************************************
* Included Files
******************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
****************************************************************************/
#include <nuttx/board.h>
#include <arch/board/board.h>
#include <debug.h>
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdint.h>
#include "stm32_gpio.h"
/*******************************************************************************
/*****************************************************************************
* Pre-processor definitions
******************************************************************************/
****************************************************************************/
#define GPIO_LED1 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz |\
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN0)
@ -61,9 +57,9 @@
#define GPIO_LED4 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz |\
GPIO_OUTPUT_SET | GPIO_PORTC | GPIO_PIN5)
/*******************************************************************************
/*****************************************************************************
* Private Types
******************************************************************************/
****************************************************************************/
/* Identifies led state */
enum led_state
@ -72,9 +68,16 @@ enum led_state
LED_OFF = true
};
/*******************************************************************************
/*****************************************************************************
* Private Functions
******************************************************************************/
****************************************************************************/
/*****************************************************************************
* Name: led_state
*
* Description:
* Sets pack of leds to given state
****************************************************************************/
static void led_state(enum led_state state, unsigned int leds)
{
@ -87,7 +90,7 @@ static void led_state(enum led_state state, unsigned int leds)
{
stm32_gpiowrite(GPIO_LED2, state);
}
if (leds & BOARD_LED3_BIT)
{
stm32_gpiowrite(GPIO_LED3, state);
@ -99,9 +102,16 @@ static void led_state(enum led_state state, unsigned int leds)
}
}
/*******************************************************************************
/*****************************************************************************
* Public Functions
******************************************************************************/
****************************************************************************/
/*****************************************************************************
* Name: stm32_led_initialize
*
* Description:
* Initializes low level gpio pins for board LEDS
****************************************************************************/
void stm32_led_initialize(void)
{
@ -112,6 +122,17 @@ void stm32_led_initialize(void)
}
#ifdef CONFIG_ARCH_LEDS
/*****************************************************************************
* Name: board_autoled_on
*
* Description:
* Drives board leds when specific RTOS state led occurs.
*
* Input parameters:
* led - This is actually an RTOS state not led number of anything like that
****************************************************************************/
void board_autoled_on(int led)
{
switch (led)
@ -145,6 +166,16 @@ void board_autoled_on(int led)
}
}
/*****************************************************************************
* Name: board_autoled_off
*
* Description:
* Drives board leds when specific RTOS state led ends
*
* Input parameters:
* led - This is actually an RTOS state not led number of anything like that
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
@ -172,11 +203,32 @@ void board_autoled_off(int led)
}
#endif
/*****************************************************************************
* Name: board_userled_initialize
*
* Description:
* This function should initialize leds for user use, but on RTOS start we
* initialize every led for use by RTOS and at end, when RTOS is fully
* booted up, we give control of these specific leds for user. So that's why
* this function is empty.
****************************************************************************/
void board_userled_initialize(void)
{
/* Already initialized by stm32_led_initialize. */
}
/*****************************************************************************
* Name: board_userled
*
* Description:
* Sets led to ledon state.
*
* Input parameters:
* led - Led to be set, indexed from 0
* ledon - new state for the led.
****************************************************************************/
void board_userled(int led, bool ledon)
{
#ifndef CONFIG_ARCH_LEDS
@ -186,9 +238,19 @@ void board_userled(int led, bool ledon)
}
#endif
unsigned int ledbit = 1 << led;
led_state(ledon, ledbit);
led_state(ledon, ledbit);
}
/*****************************************************************************
* Name: board_userled_all
*
* Description:
* Sets whole ledset to given state.
*
* Input parameters:
* ledset - Led bits to be set on or off
****************************************************************************/
void board_userled_all(uint8_t ledset)
{
#ifdef CONFIG_ARCH_LEDS
@ -199,3 +261,4 @@ void board_userled_all(uint8_t ledset)
led_state(led_OFF, ~ledset);
#endif
}

View File

@ -37,8 +37,6 @@
* Included Files
****************************************************************************/
#include <debug.h>
#include <fcntl.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
@ -72,15 +70,15 @@ static const int SD_SLOT_NO = 0; /* There is only one SD slot */
/* Media changed callback */
static spi_mediachange_t mediachangeclbk;
static spi_mediachange_t g_chmediaclbk;
/* Argument for media changed callback */
static void *mediachangearg;
static void *chmediaarg;
/* Semafor to inform stm32_cd_thread that card was inserted or pulled out */
static sem_t cdsem;
static sem_t g_cdsem;
/*****************************************************************************
* Private Functions
@ -90,8 +88,8 @@ static sem_t cdsem;
* Name: stm32_cd_thread
*
* Description:
* Working thread to call mediachanged function when card is inserted or
* pulled out.
* Working thread to call mediachanged function when card is inserted or
* pulled out.
****************************************************************************/
static void *stm32_cd_thread(void *arg)
@ -100,16 +98,16 @@ static void *stm32_cd_thread(void *arg)
while (1)
{
sem_wait(&cdsem);
sem_wait(&g_cdsem);
if (mediachangeclbk)
if (g_chmediaclbk)
{
/* Card doesn't seem to initialize properly without letting it to
* rest for a millsecond or so.
*/
usleep(1 * 1000);
mediachangeclbk(mediachangearg);
g_chmediaclbk(chmediaarg);
}
}
@ -120,7 +118,7 @@ static void *stm32_cd_thread(void *arg)
* Name: stm32_cd
*
* Description:
* Card detect interrupt handler.
* Card detect interrupt handler.
****************************************************************************/
static int stm32_cd(int irq, FAR void *context)
@ -128,8 +126,8 @@ static int stm32_cd(int irq, FAR void *context)
static const int debounce_time = 100; /* [ms] */
static uint32_t now = 0;
static uint32_t prev = 0;
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
@ -141,7 +139,7 @@ static int stm32_cd(int irq, FAR void *context)
if (now - debounce_time > prev)
{
prev = now;
sem_post(&cdsem);
sem_post(&g_cdsem);
}
return OK;
@ -155,31 +153,32 @@ static int stm32_cd(int irq, FAR void *context)
* Name: stm32_spi1register
*
* Description:
* Registers media change callback
* Registers media change callback
****************************************************************************/
int stm32_spi1register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
FAR void *arg)
{
mediachangeclbk = callback;
mediachangearg = arg;
g_chmediaclbk = callback;
chmediaarg = arg;
return OK;
}
/*****************************************************************************
* Name: stm32_sdinitialize
* Name: stm32_mmcsd_initialize
*
* Description:
* Initialize SPI-based SD card and card detect thread.
* Initialize SPI-based SD card and card detect thread.
****************************************************************************/
int stm32_sdinitialize(int minor)
int stm32_mmcsd_initialize(int minor)
{
FAR struct spi_dev_s *spi;
struct sched_param schparam;
pthread_attr_t pattr;
int rv;
spi = stm32_spibus_initialize(SD_SPI_PORT);
if (!spi)
if ((spi = stm32_spibus_initialize(SD_SPI_PORT)) == NULL)
{
ferr("failed to initialize SPI port %d\n", SD_SPI_PORT);
return -ENODEV;
@ -193,15 +192,18 @@ int stm32_sdinitialize(int minor)
}
stm32_gpiosetevent(GPIO_SD_CD, true, true, true, stm32_cd);
sem_init(&cdsem, 0, 0);
pthread_attr_t pattr;
sem_init(&g_cdsem, 0, 0);
pthread_attr_init(&pattr);
#ifdef CONFIG_DEBUG_FS
pthread_attr_setstacksize(&pattr, 1024);
#else
pthread_attr_setstacksize(&pattr, 256);
#endif
schparam.sched_priority = 50;
pthread_attr_setschedparam(&pattr, &schedparam);
pthread_create(NULL, &pattr, stm32_cd_thread, NULL);
return OK;

View File

@ -36,8 +36,6 @@
* Included Files
****************************************************************************/
#include <debug.h>
#include <nuttx/config.h>
#include <nuttx/spi/spi.h>
#include "stm32_butterfly2.h"
@ -52,11 +50,11 @@
* Name: stm32_spidev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins.
* Called to configure SPI chip select GPIO pins.
*
* Note:
* Here only CS pins are configured as SPI pins are configured by driver
* itself.
* Here only CS pins are configured as SPI pins are configured by driver
* itself.
****************************************************************************/
void stm32_spidev_initialize(void)
@ -69,7 +67,7 @@ void stm32_spidev_initialize(void)
* Name: stm32_spi1select
*
* Description:
* Function asserts given devid based on select
* Function asserts given devid based on select
****************************************************************************/
void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
@ -85,7 +83,7 @@ void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
* Name: stm32_spi1status
*
* Description:
* Return status of devid
* Return status of devid
****************************************************************************/
uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)

View File

@ -37,8 +37,7 @@
* Include Files
****************************************************************************/
#include <stm32_gpio.h>
#include <stm32_otgfs.h>
#include "stm32_gpio.h"
#include "stm32_butterfly2.h"

View File

@ -1,5 +1,5 @@
/*****************************************************************************
* configs/stm32butterfly2/src/stm32_usb.c
* configs/stm32butterfly2/src/stm32_usbhost.c
*
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
* Author: Michał Łyszczek <michal.lyszczek@gmail.com>
@ -37,8 +37,6 @@
* Include Files
****************************************************************************/
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/config.h>
#include <nuttx/usb/usbhost.h>
@ -79,7 +77,6 @@ static struct usbhost_connection_s *g_usbconn;
static void* usbhost_detect(void *arg)
{
(void)arg;
struct usbhost_hubport_s *hport;
for (;;)
@ -176,8 +173,6 @@ int stm32_usbhost_initialize(void)
void stm32_usbhost_vbusdrive(int iface, bool enable)
{
DEBUGASSERT(iface == 0);
stm32_gpiowrite(GPIO_OTGFS_PWRON, enable);
}