Fix MMC/SD support for Wildfire board; Granule allocator can now be used from intrrupt handler

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5134 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-09-12 15:18:56 +00:00
parent 1b7dad5a76
commit eac15a4720
11 changed files with 62 additions and 59 deletions

View File

@ -3948,6 +3948,13 @@ build
are a few optimizations that can can be done and (2) the GRAN_HANDLE
is not needed.
</li>
<li>
<code>CONFIG_GRAN_INTR</code>:
Normally mutual exclusive access to granule allocator data is assured using a semaphore.
If this option is set then, instead, mutual exclusion logic will disable interrupts.
While this options is more invasive to system performance, it will also support use of the
granule allocator from interrupt level logic.
</li>
<li>
<code>CONFIG_DEBUG_GRAM</code>:
Just like <code>CONFIG_DEBUG_MM</code>, but only generates ouput from the gran

View File

@ -299,6 +299,11 @@ defconfig -- This is a configuration file similar to the Linux
gran_initialize will be called only once. In this case, (1) there
are a few optimizations that can can be done and (2) the GRAN_HANDLE
is not needed.
CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator
data is assured using a semaphore. If this option is set then, instead,
mutual exclusion logic will disable interrupts. While this options is
more invasive to system performance, it will also support use of the
granule allocator from interrupt level logic.
CONFIG_DEBUG_GRAM
Just like CONFIG_DEBUG_MM, but only generates ouput from the gran
allocation logic.

View File

@ -296,7 +296,7 @@ void stm32_selectlcd(void);
*
* Description:
* Initialize the SPI-based SD card. Requires CONFIG_DISABLE_MOUNTPOINT=n
* and CONFIG_STM32_SPI1=y
* and CONFIG_STM32_SDIO=y
*
****************************************************************************/

View File

@ -65,7 +65,7 @@
/* Can't support MMC/SD features if mountpoints are disabled */
#ifndef CONFIG_DISABLE_MOUNTPOINT
#ifdef CONFIG_DISABLE_MOUNTPOINT
# undef HAVE_MMCSD
#endif
@ -78,7 +78,7 @@
*
* Description:
* Initialize the SPI-based SD card. Requires CONFIG_DISABLE_MOUNTPOINT=n
* and CONFIG_STM32_SPI1=y
* and CONFIG_STM32_SDIO=y
*
****************************************************************************/
@ -93,7 +93,7 @@ int stm32_sdinitialize(int minor)
sdio = sdio_initialize(STM32_MMCSDSLOTNO);
if (!sdio)
{
message("Failed to initialize SDIO slot %d\n", STM32_MMCSDSLOTNO);
fdbg("Failed to initialize SDIO slot %d\n", STM32_MMCSDSLOTNO);
return -ENODEV;
}
@ -104,7 +104,7 @@ int stm32_sdinitialize(int minor)
ret = mmcsd_slotinitialize(minor, sdio);
if (ret != OK)
{
message("Failed to bind SDIO slot %d to the MMC/SD driver, minor=%d\n",
fdbg("Failed to bind SDIO slot %d to the MMC/SD driver, minor=%d\n",
STM32_MMCSDSLOTNO, minor);
}

View File

@ -2,7 +2,7 @@
* include/nuttx/gran.h
* General purpose granule memory allocator.
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -57,6 +57,11 @@
* granule allocator (i.e., gran_initialize will be called only once.
* In this case, (1) there are a few optimizations that can can be done
* and (2) the GRAN_HANDLE is not needed.
* CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator
* data is assured using a semaphore. If this option is set then, instead,
* mutual exclusion logic will disable interrupts. While this options is
* more invasive to system performance, it will also support use of the
* granule allocator from interrupt level logic.
* CONFIG_DEBUG_GRAN - Just like CONFIG_DEBUG_MM, but only generates ouput
* from the gran allocation logic.
*/

View File

@ -65,6 +65,17 @@ config GRAN_SINGLE
are a few optimizations that can can be done and (2) the GRAN_HANDLE
is not needed.
config GRAN_INTR
bool "Interrupt level support"
default n
depends on GRAN
---help---
Normally mutual exclusive access to granule allocator data is assured
using a semaphore. If this option is set then, instead, mutual
exclusion logic will disable interrupts. While this options is more
invasive to system performance, it will also support use of the granule
allocator from interrupt level logic.
config DEBUG_GRAN
bool "Granule Allocator Debug"
default n

View File

@ -1,7 +1,7 @@
############################################################################
# mm/Makefile
#
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
# Copyright (C) 2007, 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -41,7 +41,7 @@ CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk
mm_memalign.c mm_free.c mm_mallinfo.c
ifeq ($(CONFIG_GRAN),y)
CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c
CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c mm_grancritical.c
endif
AOBJS = $(ASRCS:.S=$(OBJEXT))

View File

@ -45,6 +45,7 @@
#include <stdint.h>
#include <semaphore.h>
#include <arch/types.h>
#include <nuttx/gran.h>
/****************************************************************************
@ -88,7 +89,11 @@ struct gran_s
{
uint8_t log2gran; /* Log base 2 of the size of one granule */
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
#ifdef CONFIG_GRAN_INTR
irqstate_t irqstate; /* For exclusive access to the GAT */
#else
sem_t exclsem; /* For exclusive access to the GAT */
#endif
uintptr_t heapstart; /* The aligned start of the granule heap */
uint32_t gat[1]; /* Start of the granule allocation table */
};
@ -108,11 +113,10 @@ extern FAR struct gran_s *g_graninfo;
****************************************************************************/
/****************************************************************************
* Name: gran_semtake and gran_semgive
* Name: gran_enter_critical and gran_leave_critical
*
* Description:
* Managed semaphore for the granule allocator. gran_semgive is
* implemented as a macro.
* Critical section management for the granule allocator.
*
* Input Parameters:
* priv - Pointer to the gran state
@ -122,7 +126,7 @@ extern FAR struct gran_s *g_graninfo;
*
****************************************************************************/
void gran_semtake(FAR struct gran_s *priv);
#define gran_semgive(p) sem_post(&(p)->exclsem);
void gran_enter_critical(FAR struct gran_s *priv);
void gran_leave_critical(FAR struct gran_s *priv);
#endif /* __MM_MM_GRAN_H */

View File

@ -127,12 +127,12 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
{
unsigned int ngranules;
size_t tmpmask;
uintptr_t alloc;
uint32_t curr;
uint32_t next;
uint32_t mask;
int i;
int j;
uintptr_t alloc;
uint32_t curr;
uint32_t next;
uint32_t mask;
int i;
int j;
DEBUGASSERT(priv && size <= 32 * (1 << priv->log2gran));
@ -140,7 +140,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
{
/* Get exclusive access to the GAT */
gran_semtake(priv);
gran_enter_critical(priv);
/* How many contiguous granules we we need to find? */
@ -199,7 +199,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
/* And return the allocation address */
gran_semgive(priv);
gran_leave_critical(priv);
return (FAR void *)alloc;
}
@ -221,7 +221,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
}
}
gran_semgive(priv);
gran_leave_critical(priv);
return NULL;
}

View File

@ -75,13 +75,13 @@ static inline void gran_common_free(FAR struct gran_s *priv,
unsigned int granmask;
unsigned int ngranules;
unsigned int avail;
uint32_t gatmask;
uint32_t gatmask;
DEBUGASSERT(priv && memory && size <= 32 * (1 << priv->log2gran));
/* Get exclusive access to the GAT */
gran_semtake(priv);
gran_enter_critical(priv);
/* Determine the granule number of the first granule in the allocation */
@ -121,7 +121,7 @@ static inline void gran_common_free(FAR struct gran_s *priv,
priv->gat[gatidx] &= ~(gatmask << gatbit);
}
gran_semgive(priv);
gran_leave_critical(priv);
}
/****************************************************************************

View File

@ -119,7 +119,12 @@ static inline FAR struct gran_s *gran_common_initialize(FAR void *heapstart,
priv->log2gran = log2gran;
priv->ngranules = ngranules;
priv->heapstart = alignedstart;
/* Initialize mutual exclusion support */
#ifndef CONFIG_GRAN_INTR
sem_init(&priv->exclsem, 0, 1);
#endif
}
return priv;
@ -172,38 +177,4 @@ GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gr
}
#endif
/****************************************************************************
* Name: gran_semtake and gran_semgive
*
* Description:
* Managed semaphore for the granule allocator. gran_semgive is
* implemented as a macro.
*
* Input Parameters:
* priv - Pointer to the gran state
*
* Returned Value:
* None
*
****************************************************************************/
void gran_semtake(FAR struct gran_s *priv)
{
int ret;
/* Continue waiting if we are awakened by a signal */
do
{
ret = sem_wait(&priv->exclsem);
if (ret < 0)
{
DEBUGASSERT(errno == EINTR);
}
}
while (ret < 0);
}
#endif /* CONFIG_GRAN */