STM32 F7: Add heap initializatino logic; Clone the STM32 CCM allocator as the F7 DTCM allocator

This commit is contained in:
Gregory Nutt 2015-07-18 12:52:24 -06:00
parent 5c76329d2e
commit 8fa67213c1
10 changed files with 919 additions and 16 deletions

View File

@ -100,10 +100,10 @@
# define STM32F7_NLCDTFT 1 /* One LCD-TFT */
#endif
# define STM32F7_SRAM1 (240*1024) /* 240Kb SRAM1 on AHB bus Matrix */
# define STM32F7_SRAM2 (16*1024) /* 16Kb SRAM2 on AHB bus Matrix */
# define STM32F7_DTCM_SRAM (64*1024) /* 64Kb DTCM SRAM on TCM inerface */
# define STM32F7_ITCM_SRAM (16*1024) /* 16Kb ITCM SRAM on TCM inerface */
# define STM32F7_SRAM1_SIZE (240*1024) /* 240Kb SRAM1 on AHB bus Matrix */
# define STM32F7_SRAM2_SIZE (16*1024) /* 16Kb SRAM2 on AHB bus Matrix */
# define STM32F7_DTCM_SRAM_SIZE (64*1024) /* 64Kb DTCM SRAM on TCM inerface */
# define STM32F7_ITCM_SRAM_SIZE (16*1024) /* 16Kb ITCM SRAM on TCM inerface */
# define STM32F7_NFSMC 1 /* Have FSMC memory controller */
# define STM32F7_NETHERNET 1 /* 100/100 Ethernet MAC */

View File

@ -416,4 +416,20 @@ config STM32F7_WWDG
select WATCHDOG
endmenu
config STM32F7_CUSTOM_CLOCKCONFIG
bool "Custom clock configuration"
default n
---help---
Enables special, board-specific STM32 clock configuration.
config STM32F7_DTCM_PROCFS
bool "DTCM SRAM PROCFS support"
default n
depends on ARMV7M_DTCM && FS_PROCFS
---help---
Select to build in support for /proc/dtcm. Reading from /proc/dtcm
will provide statistics about DTCM memory use similar to what you
would get from mallinfo() for the user heap.
endif # ARCH_CHIP_STM32F7

View File

@ -107,8 +107,15 @@ endif
# Required STM32F7 files
CHIP_ASRCS =
CHIP_CSRCS = stm32_exti_gpio.c stm32_gpio.c stm32_irq.c stm32_rcc.c
CHIP_CSRCS += stm32_start.c stm32_timerisr.c
CHIP_CSRCS = stm32_allocateheap.c stm32_exti_gpio.c stm32_gpio.c
CHIP_CSRCS += stm32_irq.c stm32_rcc.c stm32_start.c stm32_timerisr.c
ifeq ($(CONFIG_ARMV7M_DTCM),y)
CHIP_CSRCS += stm32_dtcm.c
ifeq ($(CONFIG_STM32F7_DTCM_PROCFS),y)
CHIP_CSRCS += stm32_procfs_dtcm.c
endif
endif
ifeq ($(CONFIG_DEBUG),y)
CHIP_CSRCS += stm32_dumpgpio.c

View File

@ -0,0 +1,358 @@
/****************************************************************************
* arch/arm/src/stm32f7/up_allocateheap.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name NuttX 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/kmalloc.h>
#include <nuttx/userspace.h>
#include <arch/stm32f7/chip.h>
#include <arch/board/board.h>
#include "mpu.h"
#include "up_arch.h"
#include "up_internal.h"
#include "stm32_mpuinit.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Internal SRAM is available in all members of the STM32 family. The
* following definitions must be provided to specify the size and
* location of internal(system) SRAM:
*
* CONFIG_RAM_END : End address (+1) of SRAM (F1 family only, the
* : F4 family uses the a priori end of SRAM)
*
* In addition to internal SRAM, SRAM may also be available through the FSMC.
* In order to use FSMC SRAM, the following additional things need to be
* present in the NuttX configuration file:
*
* CONFIG_STM32F7_FSMC=y : Enables the FSMC
* CONFIG_STM32F7_FSMC_SRAM=y : Indicates that SRAM is available via the
* FSMC (as opposed to an LCD or FLASH).
* CONFIG_HEAP2_BASE : The base address of the SRAM in the FSMC
* address space
* CONFIG_HEAP2_SIZE : The size of the SRAM in the FSMC
* address space
* CONFIG_MM_REGIONS : Must be set to a large enough value to
* include the FSMC SRAM (as determined by
* the rules provided below)
*/
/* Set the start and end of SRAM1 and SRAM2 */
#define SRAM1_START STM32_SRAM1_BASE
#define SRAM1_END (SRAM1_START + STM32F7_SRAM1_SIZE)
#define SRAM2_START STM32_SRAM2_BASE
#define SRAM2_END (SRAM2_START + STM32F7_SRAM2_SIZE)
/* We can't possibly have FSMC SRAM if the FSMC is not enabled */
#ifndef CONFIG_STM32F7_FSMC
# undef CONFIG_STM32F7_FSMC_SRAM
#endif
/* If FSMC SRAM is going to be used as heap, then verify that the starting
* address and size of the external SRAM region has been provided in the
* configuration (as CONFIG_HEAP2_BASE and CONFIG_HEAP2_SIZE).
*/
#ifdef CONFIG_STM32F7_FSMC_SRAM
# if !defined(CONFIG_HEAP2_BASE) || !defined(CONFIG_HEAP2_SIZE)
# error CONFIG_HEAP2_BASE and CONFIG_HEAP2_SIZE must be provided
# undef CONFIG_STM32F7_FSMC_SRAM
# endif
#endif
/* There are 3 possible heap configurations:
*
* Configuration 1. System SRAM1 (only)
* CONFIG_MM_REGIONS == 1
* CONFIG_STM32F7_FSMC_SRAM NOT defined
* Configuration 2. System SRAM1 and SRAM2
* CONFIG_MM_REGIONS == 2
* CONFIG_STM32F7_FSMC_SRAM NOT defined
* Configuration 3. System SRAM1 and SRAM2 and FSMC SRAM
* CONFIG_MM_REGIONS == 3
* CONFIG_STM32F7_FSMC_SRAM defined
*
* Let's make sure that all definitions are consistent before doing
* anything else
*/
#if CONFIG_MM_REGIONS < 2
# ifdef CONFIG_STM32F7_FSMC_SRAM
# warning FSMC SRAM and SRAM2 excluded from the heap
# else
# warning "SRAM2 excluded from the heap"
# endif
#elif CONFIG_MM_REGIONS < 3
# ifdef CONFIG_STM32F7_FSMC_SRAM
# warning FSMC SRAM excluded from the heap
# endif
#elif CONFIG_MM_REGIONS < 4
# ifndef CONFIG_STM32F7_FSMC_SRAM
# error CONFIG_MM_REGIONS > 2 but I do not know what some of the region(s) are
# undef CONFIG_MM_REGIONS
# define CONFIG_MM_REGIONS 2
# endif
#else
# error CONFIG_MM_REGIONS > 3 but I do not know what some of the region(s) are
# undef CONFIG_MM_REGIONS
# ifdef CONFIG_STM32F7_FSMC_SRAM
# define CONFIG_MM_REGIONS 3
# else
# define CONFIG_MM_REGIONS 2
# endif
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: up_heap_color
*
* Description:
* Set heap memory to a known, non-zero state to checking heap usage.
*
****************************************************************************/
#ifdef CONFIG_DEBUG_HEAP
static inline void up_heap_color(FAR void *start, size_t size)
{
memset(start, HEAP_COLOR, size);
}
#else
# define up_heap_color(start,size)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_allocate_heap
*
* Description:
* This function will be called to dynamically set aside the heap region.
*
* For the kernel build (CONFIG_BUILD_PROTECTED=y) with both kernel- and
* user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the
* size of the unprotected, user-space heap.
*
* If a protected kernel-space heap is provided, the kernel heap must be
* allocated (and protected) by an analogous up_allocate_kheap().
*
* The following memory map is assumed for the flat build:
*
* .data region. Size determined at link time.
* .bss region Size determined at link time.
* IDLE thread stack. Size determined by CONFIG_IDLETHREAD_STACKSIZE.
* Heap. Extends to the end of SRAM.
*
* The following memory map is assumed for the kernel build:
*
* Kernel .data region. Size determined at link time.
* Kernel .bss region Size determined at link time.
* Kernel IDLE thread stack. Size determined by CONFIG_IDLETHREAD_STACKSIZE.
* Padding for alignment
* User .data region. Size determined at link time.
* User .bss region Size determined at link time.
* Kernel heap. Size determined by CONFIG_MM_KERNEL_HEAPSIZE.
* User heap. Extends to the end of SRAM.
*
****************************************************************************/
void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
{
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
/* Get the unaligned size and position of the user-space heap.
* This heap begins after the user-space .bss section at an offset
* of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment).
*/
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + CONFIG_MM_KERNEL_HEAPSIZE;
size_t usize = SRAM1_END - ubase;
int log2;
DEBUGASSERT(ubase < (uintptr_t)SRAM1_END);
/* Adjust that size to account for MPU alignment requirements.
* NOTE that there is an implicit assumption that the SRAM1_END
* is aligned to the MPU requirement.
*/
log2 = (int)mpu_log2regionfloor(usize);
DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0);
usize = (1 << log2);
ubase = SRAM1_END - usize;
/* Return the user-space heap settings */
board_led_on(LED_HEAPALLOCATE);
*heap_start = (FAR void*)ubase;
*heap_size = usize;
/* Colorize the heap for debug */
up_heap_color((FAR void*)ubase, usize);
/* Allow user-mode access to the user heap memory */
stm32_mpu_uheap((uintptr_t)ubase, usize);
#else
/* Return the heap settings */
board_led_on(LED_HEAPALLOCATE);
*heap_start = (FAR void*)g_idle_topstack;
*heap_size = SRAM1_END - g_idle_topstack;
/* Colorize the heap for debug */
up_heap_color(*heap_start, *heap_size);
#endif
}
/****************************************************************************
* Name: up_allocate_kheap
*
* Description:
* For the kernel build (CONFIG_BUILD_PROTECTED=y) with both kernel- and
* user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates
* (and protects) the kernel-space heap.
*
****************************************************************************/
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
{
/* Get the unaligned size and position of the user-space heap.
* This heap begins after the user-space .bss section at an offset
* of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment).
*/
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + CONFIG_MM_KERNEL_HEAPSIZE;
size_t usize = SRAM1_END - ubase;
int log2;
DEBUGASSERT(ubase < (uintptr_t)SRAM1_END);
/* Adjust that size to account for MPU alignment requirements.
* NOTE that there is an implicit assumption that the SRAM1_END
* is aligned to the MPU requirement.
*/
log2 = (int)mpu_log2regionfloor(usize);
DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0);
usize = (1 << log2);
ubase = SRAM1_END - usize;
/* Return the kernel heap settings (i.e., the part of the heap region
* that was not dedicated to the user heap).
*/
*heap_start = (FAR void*)USERSPACE->us_bssend;
*heap_size = ubase - (uintptr_t)USERSPACE->us_bssend;
}
#endif
/****************************************************************************
* Name: up_addregion
*
* Description:
* Memory may be added in non-contiguous chunks. Additional chunks are
* added by calling this function.
*
****************************************************************************/
#if CONFIG_MM_REGIONS > 1
void up_addregion(void)
{
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
/* Allow user-mode access to the STM32F20xxx/STM32F40xxx SRAM2 heap */
stm32_mpu_uheap((uintptr_t)SRAM2_START, SRAM2_END-SRAM2_START);
#endif
/* Colorize the heap for debug */
up_heap_color((FAR void*)SRAM2_START, SRAM2_END-SRAM2_START);
/* Add the STM32F20xxx/STM32F40xxx SRAM2 user heap region. */
kumm_addregion((FAR void*)SRAM2_START, SRAM2_END-SRAM2_START);
#ifdef CONFIG_STM32F7_FSMC_SRAM
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
/* Allow user-mode access to the FSMC SRAM user heap memory */
stm32_mpu_uheap((uintptr_t)CONFIG_HEAP2_BASE, CONFIG_HEAP2_SIZE);
#endif
/* Colorize the heap for debug */
up_heap_color((FAR void*)CONFIG_HEAP2_BASE, CONFIG_HEAP2_SIZE);
/* Add the external FSMC SRAM user heap region. */
kumm_addregion((FAR void*)CONFIG_HEAP2_BASE, CONFIG_HEAP2_SIZE);
#endif
}
#endif

View File

@ -0,0 +1,64 @@
/****************************************************************************
* arch/arm/src/stm32f7/stm32_dtcm.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name NuttX 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "stm32_dtcm.h"
#ifdef HAVE_DTCM_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
struct mm_heap_s g_dtcm_heap;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* HAVE_DTCM_HEAP */

View File

@ -0,0 +1,135 @@
/****************************************************************************
* arch/arm/src/stm32f7/stm32_dtcm.h
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name NuttX 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.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32F7_STM32_DTCM_H
#define __ARCH_ARM_SRC_STM32F7_STM32_DTCM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mm/mm.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Assume that we can support the DTCM heap */
#define HAVE_DTCM_HEAP 1
/* Only the STM32 F2, F3, and F4 have DTCM memory */
#if defined(CONFIG_STM32_STM32F30XX)
# define DTCM_START 0x10000000
# define DTCM_END 0x10002000
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
# define DTCM_START 0x10000000
# define DTCM_END 0x10010000
#else
# undef HAVE_DTCM_HEAP
#endif
/* In order to use the DTCM heap, it had to have been excluded from the main
* heap.
*/
#ifndef CONFIG_STM32_DTCMEXCLUDE
# undef HAVE_DTCM_HEAP
#endif
/* Can we support the DTCM heap? */
#ifdef HAVE_DTCM_HEAP
/* dtcm_initialize must be called early in initialization in order to
* initialize the DTCM heap.
*/
#define dtcm_initialize() \
mm_initialize(&g_dtcm_heap, (FAR void *)DTCM_START, DTCM_END-DTCM_START)
/* The dtcm_addregion interface could be used if, for example, you want to
* add some other memory region to the DTCM heap. I don't really know why
* you might want to do that, but the functionality is essentially free.
*/
#define dtcm_addregion(b,s) mm_addregion(&g_dtcm_heap, b, s);
/* Then, once g_dtcm_heap has been setup by dtcm_initialize(), these memory
* allocators can be used just like the standard memory allocators.
*/
#define dtcm_malloc(s) mm_malloc(&g_dtcm_heap, s)
#define dtcm_zalloc(s) mm_zalloc(&g_dtcm_heap, s)
#define dtcm_calloc(n,s) mm_calloc(&g_dtcm_heap, n,s)
#define dtcm_free(p) mm_free(&g_dtcm_heap, p)
#define dtcm_realloc(p,s) mm_realloc(&g_dtcm_heap, p, s)
#define dtcm_memalign(a,s) mm_memalign(&g_dtcm_heap, a, s)
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
EXTERN struct mm_heap_s g_dtcm_heap;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* HAVE_DTCM_HEAP */
#endif /* __ARCH_ARM_SRC_STM32F7_STM32_DTCM_H */

View File

@ -0,0 +1,323 @@
/****************************************************************************
* arch/arm/src/stm32f7/stm32_procfs_dtcm.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Based on STM32 CCM code contributed by Pelle Windestam:
*
* Copyright (C) 2014 Pelle Windestam. All rights reserved.
* Author: Pelle Windestam (pelle@windestam.se)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name NuttX 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/procfs.h>
#include <nuttx/fs/dirent.h>
#include <arch/irq.h>
#include "stm32_dtcm.h"
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DTCM_LINELEN 64
/****************************************************************************
* Private Types
****************************************************************************/
/* This enumeration identifies all of the thread attributes that can be
* accessed via the procfs file system.
*/
/* This structure describes one open "file" */
struct dtcm_file_s
{
struct procfs_file_s base; /* Base open file structure */
unsigned int linesize; /* Number of valid characters in line[] */
char line[DTCM_LINELEN]; /* Pre-allocated buffer for formatted lines */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* File system methods */
static int dtcm_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode);
static int dtcm_close(FAR struct file *filep);
static ssize_t dtcm_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static int dtcm_dup(FAR const struct file *oldp,
FAR struct file *newp);
static int dtcm_stat(FAR const char *relpath, FAR struct stat *buf);
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
/* See include/nutts/fs/procfs.h
* We use the old-fashioned kind of initializers so that this will compile
* with any compiler.
*/
const struct procfs_operations dtcm_procfsoperations =
{
dtcm_open, /* open */
dtcm_close, /* close */
dtcm_read, /* read */
NULL, /* write */
dtcm_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */
NULL, /* readdir */
NULL, /* rewinddir */
dtcm_stat /* stat */
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: dtcm_open
****************************************************************************/
static int dtcm_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode)
{
FAR struct dtcm_file_s *priv;
fvdbg("Open '%s'\n", relpath);
/* PROCFS is read-only. Any attempt to open with any kind of write
* access is not permitted.
*
* REVISIT: Write-able proc files could be quite useful.
*/
if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
{
fdbg("ERROR: Only O_RDONLY supported\n");
return -EACCES;
}
/* "cpuload" is the only acceptable value for the relpath */
if (strcmp(relpath, "dtcm") != 0)
{
fdbg("ERROR: relpath is '%s'\n", relpath);
return -ENOENT;
}
/* Allocate a container to hold the task and attribute selection */
priv = (FAR struct dtcm_file_s *)kmm_zalloc(sizeof(struct dtcm_file_s));
if (!priv)
{
fdbg("ERROR: Failed to allocate file attributes\n");
return -ENOMEM;
}
/* Save the index as the open-specific state in filep->f_priv */
filep->f_priv = (FAR void *)priv;
return OK;
}
/****************************************************************************
* Name: dtcm_close
****************************************************************************/
static int dtcm_close(FAR struct file *filep)
{
FAR struct dtcm_file_s *priv;
/* Recover our private data from the struct file instance */
priv = (FAR struct dtcm_file_s *)filep->f_priv;
DEBUGASSERT(priv);
/* Release the file attributes structure */
kmm_free(priv);
filep->f_priv = NULL;
return OK;
}
/****************************************************************************
* Name: dtcm_read
****************************************************************************/
static ssize_t dtcm_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct dtcm_file_s *priv;
size_t linesize;
size_t copysize;
size_t remaining;
size_t totalsize;
struct mallinfo mem;
off_t offset = filep->f_pos;
fvdbg("buffer=%p buflen=%d\n", buffer, (int)buflen);
/* Recover our private data from the struct file instance */
priv = (FAR struct dtcm_file_s *)filep->f_priv;
DEBUGASSERT(priv);
mm_mallinfo(&g_dtcm_heap, &mem);
remaining = buflen;
totalsize = 0;
linesize = snprintf(priv->line,
DTCM_LINELEN,
" total used free largest\n");
copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset);
totalsize += copysize;
buffer += copysize;
remaining -= copysize;
if (totalsize >= buflen)
{
return totalsize;
}
linesize = snprintf(priv->line,
DTCM_LINELEN,
"Mem: %11d%11d%11d%11d\n",
mem.arena,
mem.uordblks,
mem.fordblks,
mem.mxordblk);
copysize = procfs_memcpy(priv->line, linesize, buffer, remaining, &offset);
totalsize += copysize;
/* Update the file offset */
if (totalsize > 0)
{
filep->f_pos += totalsize;
}
return totalsize;
}
/****************************************************************************
* Name: dtcm_dup
*
* Description:
* Duplicate open file data in the new file structure.
*
****************************************************************************/
static int dtcm_dup(FAR const struct file *oldp, FAR struct file *newp)
{
FAR struct dtcm_file_s *oldpriv;
FAR struct dtcm_file_s *newpriv;
fvdbg("Dup %p->%p\n", oldp, newp);
/* Recover our private data from the old struct file instance */
oldpriv = (FAR struct dtcm_file_s *)oldp->f_priv;
DEBUGASSERT(oldpriv);
/* Allocate a new container to hold the task and attribute selection */
newpriv = (FAR struct dtcm_file_s *)kmm_zalloc(sizeof(struct dtcm_file_s));
if (!newpriv)
{
fdbg("ERROR: Failed to allocate file attributes\n");
return -ENOMEM;
}
/* The copy the file attributes from the old attributes to the new */
memcpy(newpriv, oldpriv, sizeof(struct dtcm_file_s));
/* Save the new attributes in the new file structure */
newp->f_priv = (FAR void *)newpriv;
return OK;
}
static int dtcm_stat(const char *relpath, struct stat *buf)
{
if (strcmp(relpath, "dtcm") != 0)
{
fdbg("ERROR: relpath is '%s'\n", relpath);
return -ENOENT;
}
buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR;
buf->st_size = 0;
buf->st_blksize = 0;
buf->st_blocks = 0;
return OK;
}
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */

View File

@ -92,7 +92,7 @@
* and enable peripheral clocking for all peripherals enabled in the NuttX
* configurationfile.
*
* If CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is defined, then clocking
* If CONFIG_STM32F7_CUSTOM_CLOCKCONFIG is defined, then clocking
* will be enabled by an externally provided, board-specific function called
* stm32_board_clockconfig().
*
@ -110,7 +110,7 @@ void stm32_clockconfig(void)
rcc_reset();
#if defined(CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG)
#if defined(CONFIG_STM32F7_CUSTOM_CLOCKCONFIG)
/* Invoke Board Custom Clock Configuration */
@ -142,8 +142,8 @@ void stm32_clockconfig(void)
* stm32_clockconfig(): It does not reset any devices, and it does not reset the
* currenlty enabled peripheral clocks.
*
* If CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is defined, then clocking will
* be enabled by an externally provided, board-specific function called
* If CONFIG_STM32F7_CUSTOM_CLOCKCONFIG is defined, then clocking will be enabled
* by an externally provided, board-specific function called
* stm32_board_clockconfig().
*
* Input Parameters:
@ -157,7 +157,7 @@ void stm32_clockconfig(void)
#ifdef CONFIG_PM
void stm32_clockenable(void)
{
#if defined(CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG)
#if defined(CONFIG_STM32F7_CUSTOM_CLOCKCONFIG)
/* Invoke Board Custom Clock Configuration */

View File

@ -151,8 +151,8 @@ static inline void stm32_mco2config(uint32_t source, uint32_t div)
* peripheral clocking for all peripherals enabled in the NuttX configuration
* file.
*
* If CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is defined, then clocking will
* be enabled by an externally provided, board-specific function called
* If CONFIG_STM32F7_CUSTOM_CLOCKCONFIG is defined, then clocking will be enabled
* by an externally provided, board-specific function called
* stm32_board_clockconfig().
*
* Input Parameters:
@ -174,7 +174,7 @@ void stm32_clockconfig(void);
*
************************************************************************************/
#ifdef CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
#ifdef CONFIG_STM32F7_CUSTOM_CLOCKCONFIG
void stm32_board_clockconfig(void);
#endif
@ -191,7 +191,7 @@ void stm32_board_clockconfig(void);
* stm32_clockconfig(): It does not reset any devices, and it does not reset the
* currently enabled peripheral clocks.
*
* If CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is defined, then clocking will
* If CONFIG_STM32F7_CUSTOM_CLOCKCONFIG is defined, then clocking will
* be enabled by an externally provided, board-specific function called
* stm32_board_clockconfig().
*

View File

@ -655,7 +655,7 @@ static inline void rcc_enableapb2(void)
* power clocking modes!
****************************************************************************/
#ifndef CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
#ifndef CONFIG_STM32F7_CUSTOM_CLOCKCONFIG
static void stm32_stdclockconfig(void)
{
uint32_t regval;