From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14311 invoked by alias); 10 Feb 2009 22:31:25 -0000 Received: (qmail 14303 invoked by uid 22791); 10 Feb 2009 22:31:25 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Feb 2009 22:31:19 +0000 Received: from localhost (hagrid.ecoscentric.com [127.0.0.1]) by mail.ecoscentric.com (Postfix) with ESMTP id 6547360B8014 for ; Tue, 10 Feb 2009 22:31:16 +0000 (GMT) Received: from mail.ecoscentric.com ([127.0.0.1]) by localhost (hagrid.ecoscentric.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8KEySlSERf9C; Tue, 10 Feb 2009 22:31:15 +0000 (GMT) Date: Tue, 10 Feb 2009 22:31:00 -0000 Message-Id: From: Bart Veer To: ecos-patches@sourceware.org Subject: tidy STM32 SPI driver Mailing-List: contact ecos-patches-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: ecos-patches-owner@ecos.sourceware.org X-SW-Source: 2009-02/txt/msg00060.txt.bz2 This SPI driver did not use linker garbage collection the way I intended for SPI drivers. It created a C++ object in src/spi_stm32_init.cxx which was places in libextras.a. Hence the C++ object was always part of any application link, and because of the KEEP(*.ctors) in the linker script its constructor would never get garbage-collected. Net result: all applications would end up with the C++ object, the constructor, and the cyg_spi_cortexm_stm32_init() function, even if SPI was never used. This patch should fix this. src/spi_stm32_init.cxx is eliminated completely. cyg_spi_cortexm_stm32_init() is declared as a prioritized constructor, and made static because it is no longer accessed from the outside the module. If the application does not make use of any SPI functions then there will be no references to any of the SPI bus objects and the linker will not pull in spi_stm32.o from libtarget.a. So the linker never sees any of the driver code, including the constructor, and there are no overheads. If the application does make use of SPI then it will reference one of the SPI bus objects and the linker will pull in spi_stm32.o from the library. The module is still subject to linker garbage collection, although that won't have much effect because of the table of function pointers. The init function is a constructor so the linker will keep it because of the KEEP(*.ctors). And everything should work as intended. I also looked at moving the three SPI buses into separate modules, built unconditionally. Again linker magic would ensure that only buses actually used by the application would end up in the application, with no need for developers to enable the relevant CDL components. This does not look entirely feasible right now, there are too many per-bus configuration options. Bart 2009-02-10 Bart Veer * src/spi_stm32.c (cyg_spi_cortexm_stm32_init): mark as prioritized constructor and rename. * cdl/spi_stm32.cdl: stop building spi_stm32_init.cxx * src/spi_stm32_init.cxx: removed, no longer needed. Index: cdl/spi_stm32.cdl =================================================================== RCS file: /cvs/ecos/ecos/packages/devs/spi/cortexm/stm32/current/cdl/spi_stm32.cdl,v retrieving revision 1.2 diff -u -p -r1.2 spi_stm32.cdl --- cdl/spi_stm32.cdl 10 Feb 2009 16:12:53 -0000 1.2 +++ cdl/spi_stm32.cdl 10 Feb 2009 22:29:42 -0000 @@ -59,7 +59,6 @@ cdl_package CYGPKG_DEVS_SPI_CORTEXM_STM3 hardware include_dir cyg/io compile spi_stm32.c - compile -library=libextras.a spi_stm32_init.cxx cdl_option CYGNUM_DEVS_SPI_CORTEXM_STM32_PIN_TOGGLE_RATE { display "Pin toggle rate" Index: src/spi_stm32.c =================================================================== RCS file: /cvs/ecos/ecos/packages/devs/spi/cortexm/stm32/current/src/spi_stm32.c,v retrieving revision 1.4 diff -u -p -r1.4 spi_stm32.c --- src/spi_stm32.c 10 Feb 2009 16:12:54 -0000 1.4 +++ src/spi_stm32.c 10 Feb 2009 22:29:56 -0000 @@ -611,8 +611,8 @@ static void spi_transaction_dma //----------------------------------------------------------------------------- // Initialise SPI interfaces on startup. -void cyg_spi_cortexm_stm32_init - (void) +static void CYGBLD_ATTRIB_C_INIT_PRI(CYG_INIT_BUS_SPI) +stm32_spi_init(void) { #if defined(CYGHWR_DEVS_SPI_CORTEXM_STM32_BUS3) && \ defined(CYGHWR_DEVS_SPI_CORTEXM_STM32_BUS3_DISABLE_DEBUG_PORT)