Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

nombre réponses : 25

#0 -1 »  [C] petite question de culture sur les types.. » Le 11/08/2011, à 16:23

gilbert
Réponses : 3

Bonjour tout le monde,

voilà, je me posais la question suivante : Comment peut-ton manipuler des nombres décimaux à virgule fixe en C standard?

Imaginons que l'on travaille sur un processeur qui dispose d'une fixed point unit mais pas de floating point unit (ceci pour économiser de la surface de silicium par exemple, ou tout autre raison...)

Si l'on souhaite programmer en C sur ce processeur, on pourra définir des variables de type float, mais à la compilation les opérations sur ces variables seront traduites par toute une suite d'instructions qui font que le calcul risque d'être lent (j'entends par là plus d'une instruction machine pour réaliser une addition ou une multiplication par exemple).

Hors, si le processeur a une unité à point fixe disponible, ça ne prendrait qu'une instruction pour réaliser ladite addition. (je ne parle pas ici de la précision du résultat, ça n'est pas la question).

Enfin le C standard permet de travailler directement avec des variables de type entier (signé ou non, et de magnitude différentes) ainsi que flottants avec là aussi plusieurs variantes, mais qu'en est-il pour les points-fixe ?

Merci d'avance pour vos éclaircissements.

#1 Re : -1 »  [C] petite question de culture sur les types.. » Le 11/08/2011, à 22:40

gilbert
Réponses : 3

hello,

merci bien pour ces réponses smile Elles ne me surprennent pas trop en fait... c'est ce que je m'attendais à lire même si j'espérais autre chose.

En fait si on veut porter linux sur un SoC, on risque de croiser pas mal de problèmes et la tâche n'a rien d'aisé.

Je pensais à cela en fait aux Linux sur OMAP : http://focus.ti.com/general/docs/wtbu/w … entId=4752

Si on développe des applications spécifiques, il y a de fortes chances qu'elles soient totalement incompatibles avec du Linux conventionnel.

#2 -1 »  [bitmap/écran] cherche script » Le 19/12/2010, à 01:44

gilbert
Réponses : 0

Bonjour,

dans le cadre de tests d'écrans TFT, je suis à la recherche d'un script qui puisse transformer des images bitmaps en tableau qui soient directement insérable dans un code en C.

Je teste un contrôleur pour écran et j'ai écrit un code vite fait mal fait en C qui peut afficher des mires ou diverses autres générations de séquences sur l'écran.

J'aimerais bien afficher des images, mais je n'ai pas vraiment le temps de développer un petit script qui ferait la conversion. Je pense que ça doit exister et que ça se trouve ?

Question spécifications, mes écrans peuvent afficher 262'144 couleurs (6 bits par couleur, soit 64 x 64 x 64 couleurs). J'envoie des entiers de 32 bits. Les bits 5 à 0 contiennent le bleu, les bits 13 à 8 le vert; et les bits 21 à 16 le rouge. Les autres bits sont à 0.

L'idéal serait donc de prendre une image bitmap (et la tronquer si elle a plus de bits par couleur) et remplir un array avec les valeurs des couleurs pour chaque pixel.

La sortie du script est donc du texte que l'on peut directement copier-coller dans un programme en C.

Quelqu'un connaitrait-il ce genre d'outil ?

Merci pour votre aide.

#3 -1 »  [C et Linux] adressage » Le 03/12/2010, à 20:24

gilbert
Réponses : 5

Bonjour,

Est-il possible sous Linux (je dis bien Linux, pas besoin d'être forcément POSIX compliant), d'accéder à des adresses absolues du plan mémoire avec une application écrite en user-level ??

Il y a des fonctions comme mmap(2) mais je pense que ça ne fonctionne qu'en root ?

Et si cela est possible. Admettons que j'aie un pointeur myMemoryPtr qui pointe sur mon endroit désiré. Lorsque je l'incrémente de 1, il augmente d'une unité du type d'objet sur lequel il pointe ou d'une position mémoire ?

En fait mon but est de savoir lorsque j'exécute une ligne de code comme cela :

myData1 = *myMemoryPtr ;
myMemoryPtr ++;
myData2 = *myMemoryPtr ;

Comment sont affectés les bits sur le bus d'adresse afin de savoir s'il faut faire des décalages (adressage octet, mot, double mot, etc) ou bien si c'est fait automatiquement par l'unité en charge des accès mémoires ??

Merci pour votre aide.

Salutations.

#4 Re : -1 »  [C et Linux] adressage » Le 03/12/2010, à 23:19

gilbert
Réponses : 5
chopinhauer a écrit :

gilbert, tu n'as jamais accès aux adresses absolus en mémoire. Linux (et Windows aussi) utilise le paging pour offrir à chaque processus un espace d'adressage séparé et laisser le processeur (la MMU en particulier) faire la traduction de l'adresse virtuel dans l'adresse réel.

Sûr de ça ??? ça serait embêtant..

En fait l'OS doit tourner sur une IP ARM implémentée dans un SoC atmel SAM9M10. Mon but c'est de pouvoir adresser une autre IP personnelle qui est sur le bus du processeur.

#5 Re : -1 »  [C et Linux] adressage » Le 03/12/2010, à 23:50

gilbert
Réponses : 5

bon.. je vais voir tout ça et je vous redis.

merci pour l'info.

#6 -1 »  [Résolu] [C] problème de compilation » Le 03/11/2010, à 23:02

gilbert
Réponses : 8

Bonjour à tous,

voilà j'ai écrit une application assez triviale sur un système nios2. J'ai un problème de compilation. Le bsp se construit bien, mais lorsque je veux construire mon application, j'ai le message d'erreur suivant :

[...]/software/I2C_Master_Unit_bsp/HAL/src/alt_main.c:152: undefined reference to `main'

le fichier alt_main.c, qui a été automatiquement généré lors de la synthèse de mon processeur, contient le binary loader qui est chargé d'appeler la fonction main de l'application que j'écris.. Bien entendu, j'ai un main dans mon application..

La ligne qui pose problème est l'appel au main :
 

main (alt_argc, alt_argv, alt_envp); /* ligne à problème */

mon main est conforme à ce format (int, char**, char**)

Je ne sais pas trop où est l'erreur, quelle est-elle et donc comment la résoudre.

Merci pour votre aide.

#7 Re : -1 »  [Résolu] [C] problème de compilation » Le 03/11/2010, à 23:20

gilbert
Réponses : 8

oui je sais que ce n'est pas standard.. mais de toutes façons j'ai juste un hardware abstraction layer.. J'évite d'utiliser un système d'exploitation dans la mesure du possible (et ici je n'en n'ai pas besoin)

En fait le fichier alt_main.c gère aussi les [int,void] main([void,autres fantaisies]) mais je ne pense pas que le problème soit là..

c'est juste qu'à l'édition de lien, il ne trouve pas d'objet avec une fonction main... Je peux poster tout ce que vous voulez (makefile, fichier c etc) mais je ne sais pas ce qui peux vous être utile pour m'aider...

#8 Re : -1 »  [Résolu] [C] problème de compilation » Le 03/11/2010, à 23:53

gilbert
Réponses : 8

En fait non, je découvre cette plateforme, donc premier problème :-p y'a pas mal de doc mais bon, je suis sûr que c'est un truc tout bête.. (comme souvent)

Voilà mon makefile. Bon c'est la version cygwin, parce que mon interface jtag ne fonctionne pas sous ubuntu.. mais ça change rien..

#------------------------------------------------------------------------------
#              VARIABLES APPENDED TO BY INCLUDED MAKEFILE FRAGMENTS
#------------------------------------------------------------------------------

# List of include directories for -I compiler option (-I added when used).
# Includes the BSP.
ALT_INCLUDE_DIRS :=

# List of library directories for -L linker option (-L added when used).
# Includes the BSP.
ALT_LIBRARY_DIRS :=

# List of library names for -l linker option (-l added when used).
# Includes the BSP.
ALT_LIBRARY_NAMES :=

# List of library names for -msys-lib linker option (-msys-lib added when used).
# These are libraries that might be located in the BSP and depend on the BSP
# library, or vice versa
ALT_BSP_DEP_LIBRARY_NAMES :=

# List of dependencies for the linker.  This is usually the full pathname
# of each library (*.a) file.
# Includes the BSP.
ALT_LDDEPS :=

# List of root library directories that support running make to build them.
# Includes the BSP and any ALT libraries.
MAKEABLE_LIBRARY_ROOT_DIRS :=

# Generic flags passed to the compiler for different types of input files.
ALT_CFLAGS :=
ALT_CXXFLAGS :=
ALT_CPPFLAGS :=
ALT_ASFLAGS :=
ALT_LDFLAGS :=


#------------------------------------------------------------------------------
#                         The adjust-path macro
# 
# If COMSPEC/ComSpec is defined, Make is launched from Windows through
# Cygwin.  The adjust-path macro converts absolute windows paths into
# unix style paths (Example: c:/dir -> /c/dir). This will ensture
# paths are readable by GNU Make.
#
# If COMSPEC/ComSpec is not defined, Make is launched from linux, and no 
# adjustment is necessary
#
#------------------------------------------------------------------------------

ifndef COMSPEC
ifdef ComSpec
COMSPEC = $(ComSpec)
endif # ComSpec
endif # COMSPEC

ifdef COMSPEC # if Windows OS

ifeq ($(MAKE_VERSION),3.81) 
#
# adjust-path/adjust-path-mixed for Mingw Gnu Make on Windows
#
# Example Usage:
# $(call adjust-path,c:/aaa/bbb) => /c/aaa/bbb
# $(call adjust-path-mixed,/c/aaa/bbb) => c:/aaa/bbb
# $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) => c:/aaa/bbb
#

#
# adjust-path
#  - converts bask slash chars into forward slashes 
#  - if input arg ($1) is an empty string then return the empty string
#  - if input arg ($1) does not contain the string ":/", then return input arg
#  - using sed, convert mixed path [c:/...] into mingw path [/c/...] 
define adjust-path
$(strip \
$(if $1,\
$(if $(findstring :/,$(subst \,/,$1)),\
$(shell echo $(subst \,/,$1) | sed -e 's,^\([a-zA-Z]\):/,/\1/,'),\
$(subst \,/,$1))))
endef

#
# adjust-path-mixed
#  - converts bask slash chars into forward slashes 
#  - if input arg ($1) is an empty string then return the empty string
#  - if input arg ($1) does not begin with a forward slash '/' char, then 
#    return input arg
#  - using sed, convert mingw path [/c/...] or cygwin path [/c/cygdrive/...] 
#    into a mixed path [c:/...] 
define adjust-path-mixed 
$(strip \
$(if $1,\
$(if $(findstring $(subst \,/,$1),$(patsubst /%,%,$(subst \,/,$1))),\
$(subst \,/,$1),\
$(shell echo $(subst \,/,$1) | sed -e 's,^/cygdrive/\([a-zA-Z]\)/,\1:/,' -e 's,^/\([a-zA-Z]\)/,\1:/,'))))
endef

else # MAKE_VERSION != 3.81 (MAKE_VERSION == 3.80 or MAKE_VERSION == 3.79) 
#
#  adjust-path for Cygwin Gnu Make
# $(call adjust-path,c:/aaa/bbb) = /cygdrive/c/aaa/bbb
# $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) = c:/aaa/bbb
#
adjust-path = $(if $1,$(shell cygpath -u "$1"),)
adjust-path-mixed = $(if $1,$(shell cygpath -m "$1"),)
endif

else # !COMSPEC

adjust-path = $1
adjust-path-mixed = $1

endif # COMSPEC


#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#                           GENERATED SETTINGS START                         v
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

#START GENERATED

# The following TYPE comment allows tools to identify the 'type' of target this 
# makefile is associated with. 
# TYPE: APP_MAKEFILE

# This following VERSION comment indicates the version of the tool used to 
# generate this makefile. A makefile variable is provided for VERSION as well. 
# ACDS_VERSION: 10.0sp1
ACDS_VERSION := 10.0sp1

# This following BUILD_NUMBER comment indicates the build number of the tool 
# used to generate this makefile. 
# BUILD_NUMBER: 262


# Define path to the application ELF. 
# It may be used by the makefile fragments so is defined before including them. 
# 
ELF := I2C_Master_Unit.elf

# Paths to C, C++, and assembly source files.
C_SRCS :=
CXX_SRCS :=
ASM_SRCS :=


# Path to root of object file tree.
OBJ_ROOT_DIR := obj

# Options to control objdump.
CREATE_OBJDUMP := 1
OBJDUMP_INCLUDE_SOURCE := 0
OBJDUMP_FULL_CONTENTS := 0

# Options to enable/disable optional files.
CREATE_ELF_DERIVED_FILES := 0
CREATE_LINKER_MAP := 1

# Common arguments for ALT_CFLAGSs
APP_CFLAGS_DEFINED_SYMBOLS :=
APP_CFLAGS_UNDEFINED_SYMBOLS :=
APP_CFLAGS_OPTIMIZATION := -Os
APP_CFLAGS_DEBUG_LEVEL := -g
APP_CFLAGS_WARNINGS := -Wall
APP_CFLAGS_USER_FLAGS :=

APP_ASFLAGS_USER :=

# Linker options that have default values assigned later if not
# assigned here.
LINKER_SCRIPT :=
CRT0 :=
SYS_LIB :=

# Define path to the root of the BSP.
BSP_ROOT_DIR := /home/gilbert/quartus/AvalonSystemI2C/software/I2C_Master_Unit_bsp

# List of application specific include directories, library directories and library names
APP_INCLUDE_DIRS :=
APP_LIBRARY_DIRS :=
APP_LIBRARY_NAMES :=

# Pre- and post- processor settings.
BUILD_PRE_PROCESS :=
BUILD_POST_PROCESS :=



#END GENERATED

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#                            GENERATED SETTINGS END                           ^
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


#------------------------------------------------------------------------------
#                           DEFAULT TARGET
#------------------------------------------------------------------------------

# Define the variable used to echo output if not already defined.
ifeq ($(ECHO),)
ECHO := echo
endif

# Put "all" rule before included makefile fragments because they may
# define rules and we don't want one of those to become the default rule.
.PHONY : all

all:
    @$(ECHO) [$(APP_NAME) build complete]

all : build_pre_process libs app build_post_process 


#------------------------------------------------------------------------------
#                 VARIABLES DEPENDENT ON GENERATED CONTENT
#------------------------------------------------------------------------------

ifeq ($(BSP_ROOT_DIR),)
$(error Edit Makefile and provide a value for BSP_ROOT_DIR)
endif

ifeq ($(wildcard $(BSP_ROOT_DIR)),)
$(error BSP directory does not exist: $(BSP_ROOT_DIR))
endif

# Define absolute path to the root of the BSP.
ABS_BSP_ROOT_DIR := $(call adjust-path-mixed,$(shell cd "$(BSP_ROOT_DIR)"; pwd))

# Include makefile fragments.  Define variable ALT_LIBRARY_ROOT_DIR before
# including each makefile fragment so that it knows the path to itself.
BSP_INCLUDE_FILE := $(BSP_ROOT_DIR)/public.mk
ALT_LIBRARY_ROOT_DIR := $(BSP_ROOT_DIR)
include $(BSP_INCLUDE_FILE)
# C2H will need this to touch the BSP public.mk and avoid the sopc file out-of-date error during a BSP make
ABS_BSP_INCLUDE_FILE := $(ABS_BSP_ROOT_DIR)/public.mk


# If the BSP public.mk indicates that ALT_SIM_OPTIMIZE is set, rename the ELF 
# by prefixing it with RUN_ON_HDL_SIMULATOR_ONLY_.  
ifneq ($(filter -DALT_SIM_OPTIMIZE,$(ALT_CPPFLAGS)),)
ELF := RUN_ON_HDL_SIMULATOR_ONLY_$(ELF)
endif


# If the BSP public.mk indicates that ALT_PROVIDE_GMON is set, add option to download_elf target
ifneq ($(filter -DALT_PROVIDE_GMON,$(ALT_CPPFLAGS)),)
GMON_OUT_FILENAME := gmon.out
WRITE_GMON_OPTION := --write-gmon $(GMON_OUT_FILENAME)
endif

# Name of ELF application.
APP_NAME := $(basename $(ELF))

# Set to defaults if variables not already defined in settings.
ifeq ($(LINKER_SCRIPT),)
LINKER_SCRIPT := $(BSP_LINKER_SCRIPT)
endif
ifeq ($(CRT0),)
CRT0 := $(BSP_CRT0)
endif
ifeq ($(SYS_LIB),)
SYS_LIB := $(BSP_SYS_LIB)
endif

OBJDUMP_NAME := $(APP_NAME).objdump
OBJDUMP_FLAGS := --disassemble --syms --all-header
ifeq ($(OBJDUMP_INCLUDE_SOURCE),1)
OBJDUMP_FLAGS += --source
endif
ifeq ($(OBJDUMP_FULL_CONTENTS),1)
OBJDUMP_FLAGS += --full-contents
endif

# Create list of linker dependencies (*.a files).
APP_LDDEPS := $(ALT_LDDEPS) $(LDDEPS)

# Take lists and add required prefixes.
APP_INC_DIRS := $(addprefix -I, $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS))
ASM_INC_PREFIX := -Wa,-I
APP_ASM_INC_DIRS := $(addprefix $(ASM_INC_PREFIX), $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS))
APP_LIB_DIRS := $(addprefix -L, $(ALT_LIBRARY_DIRS) $(APP_LIBRARY_DIRS) $(LIB_DIRS))
APP_LIBS := $(addprefix -l, $(ALT_LIBRARY_NAMES) $(APP_LIBRARY_NAMES) $(LIBS))

ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)

#
# Avoid Nios II GCC 3.X options.
#

# Detect if small newlib C library is requested.
# If yes, remove the -msmallc option because it is
# now handled by other means.
ifneq ($(filter -msmallc,$(ALT_LDFLAGS)),)
    ALT_LDFLAGS := $(filter-out -msmallc,$(ALT_LDFLAGS))
    ALT_C_LIBRARY := smallc
else
    ALT_C_LIBRARY := c
endif

# Put each BSP dependent library in a group to avoid circular dependencies.
APP_BSP_DEP_LIBS := $(foreach l,$(ALT_BSP_DEP_LIBRARY_NAMES),-Wl,--start-group -l$(ALT_C_LIBRARY) -lgcc -l$(l) -Wl,--end-group)

else # !AVOID_NIOS2_GCC3_OPTIONS

#
# Use Nios II GCC 3.X options.
#
APP_BSP_DEP_LIBS := $(addprefix -msys-lib=, $(ALT_BSP_DEP_LIBRARY_NAMES))

endif # !AVOID_NIOS2_GCC3_OPTIONS

# Arguments for the C preprocessor, C/C++ compiler, assembler, and linker.
APP_CFLAGS := $(APP_CFLAGS_DEFINED_SYMBOLS) \
              $(APP_CFLAGS_UNDEFINED_SYMBOLS) \
              $(APP_CFLAGS_OPTIMIZATION) \
              $(APP_CFLAGS_DEBUG_LEVEL) \
              $(APP_CFLAGS_WARNINGS) \
              $(APP_CFLAGS_USER_FLAGS) \
              $(ALT_CFLAGS) \
              $(CFLAGS)

# Arguments only for the C++ compiler.
APP_CXXFLAGS := $(ALT_CXXFLAGS) $(CXXFLAGS)

# Arguments only for the C preprocessor.
# Prefix each include directory with -I.
APP_CPPFLAGS := $(APP_INC_DIRS) \
                $(ALT_CPPFLAGS) \
                $(CPPFLAGS)

# Arguments only for the assembler.
APP_ASFLAGS := $(APP_ASM_INC_DIRS) \
               $(ALT_ASFLAGS) \
               $(APP_ASFLAGS_USER) \
               $(ASFLAGS)

# Arguments only for the linker.
APP_LDFLAGS := 

ifneq ($(LINKER_SCRIPT),)
APP_LDFLAGS += -T'$(LINKER_SCRIPT)'
endif

ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)

# Avoid Nios II GCC 3.x options.
ifneq ($(CRT0),)
APP_LDFLAGS += $(CRT0)
endif

# The equivalent of the -msys-lib option is provided
# by the GROUP() command in the linker script.
# Note this means the SYS_LIB variable is now ignored.

else # !AVOID_NIOS2_GCC3_OPTIONS

# Use Nios II GCC 3.x options.
ifneq ($(CRT0),)
APP_LDFLAGS += -msys-crt0='$(CRT0)'
endif
ifneq ($(SYS_LIB),)
APP_LDFLAGS += -msys-lib=$(SYS_LIB)
endif

endif # !AVOID_NIOS2_GCC3_OPTIONS

APP_LDFLAGS += \
           $(APP_LIB_DIRS) \
           $(ALT_LDFLAGS) \
           $(LDFLAGS)

LINKER_MAP_NAME := $(APP_NAME).map
ifeq ($(CREATE_LINKER_MAP), 1)
APP_LDFLAGS += -Wl,-Map=$(LINKER_MAP_NAME)
endif

# QUARTUS_PROJECT_DIR and SOPC_NAME need to be defined if you want the mem_init_install target of the mem_init.mk
# (located in the associated BSP) to know how to copy memory initialization files (e.g. .dat, .hex)
# into directories required for Quartus compilation or RTL simulation.

# Defining QUARTUS_PROJECT_DIR causes mem_init_install to copy memory initialization files into your
# Quartus project directory. This is required to provide the initial memory contents of
# FPGA memories that can be initialized by the programming file (.sof) or Hardcopy ROMs.
# It is also used for VHDL simulation of on-chip memories.

# Defining SOPC_NAME causes the mem_init_install target to copy memory initialization files into your
# RTL simulation directory.  This is required to provide the initial memory contents of all
# memories that can be initialized by RTL simulation.
# This variable should be set to the same name as your SOPC Builder system name.
# For example, if you have a system called "foo.sopc", this variable should be set to "foo".

# If SOPC_NAME is not set and QUARTUS_PROJECT_DIR is set, then derive SOPC_NAME.
ifeq ($(SOPC_NAME),)
ifneq ($(QUARTUS_PROJECT_DIR),)
SOPC_NAME := $(basename $(notdir $(wildcard $(QUARTUS_PROJECT_DIR)/*.sopcinfo)))
endif
endif

# Defining JDI_FILE is required to specify the JTAG Debug Information File path. This file is generated by Quartus,
# and is needed to resolve processor instance ID's from names in a multi-CPU SOPC Information file.
# For multi-CPU systems, the processor instance ID is used to select from multiple CPU's during ELF download.

# If JDI_FILE is not set and QUARTUS_PROJECT_DIR is set, then derive JDI_FILE.
ifeq ($(JDI_FILE),)
ifneq ($(QUARTUS_PROJECT_DIR),)
JDI_FILE := $(wildcard $(QUARTUS_PROJECT_DIR)/*.jdi)
endif
endif


#------------------------------------------------------------------------------
#           MAKEFILE INCLUDES DEPENDENT ON GENERATED CONTENT
#------------------------------------------------------------------------------
# mem_init.mk is a generated makefile fragment. This file defines all targets
# used to generate HDL initialization simulation files and pre-initialized
# onchip memory files.
MEM_INIT_FILE :=  $(BSP_ROOT_DIR)/mem_init.mk
include $(MEM_INIT_FILE)

# Create list of object files to be built using the list of source files.
# The source file hierarchy is preserved in the object tree.
# The supported file extensions are:
#
# .c            - for C files
# .cxx .cc .cpp - for C++ files
# .S .s         - for assembler files
#
# Handle source files specified by --src-dir & --src-rdir differently, to
# save some processing time in calling the adjust-path macro.

OBJ_LIST_C         := $(patsubst %.c,%.o,$(filter %.c,$(C_SRCS)))
OBJ_LIST_CPP    := $(patsubst %.cpp,%.o,$(filter %.cpp,$(CXX_SRCS)))
OBJ_LIST_CXX     := $(patsubst %.cxx,%.o,$(filter %.cxx,$(CXX_SRCS)))
OBJ_LIST_CC     := $(patsubst %.cc,%.o,$(filter %.cc,$(CXX_SRCS)))
OBJ_LIST_S         := $(patsubst %.S,%.o,$(filter %.S,$(ASM_SRCS)))
OBJ_LIST_SS        := $(patsubst %.s,%.o,$(filter %.s,$(ASM_SRCS)))

OBJ_LIST := $(sort $(OBJ_LIST_C) $(OBJ_LIST_CPP) $(OBJ_LIST_CXX) \
                $(OBJ_LIST_CC) $(OBJ_LIST_S) $(OBJ_LIST_SS))

SDIR_OBJ_LIST_C        := $(patsubst %.c,%.o,$(filter %.c,$(SDIR_C_SRCS)))
SDIR_OBJ_LIST_CPP    := $(patsubst %.cpp,%.o,$(filter %.cpp,$(SDIR_CXX_SRCS)))
SDIR_OBJ_LIST_CXX     := $(patsubst %.cxx,%.o,$(filter %.cxx,$(SDIR_CXX_SRCS)))
SDIR_OBJ_LIST_CC     := $(patsubst %.cc,%.o,$(filter %.cc,$(SDIR_CXX_SRCS)))
SDIR_OBJ_LIST_S        := $(patsubst %.S,%.o,$(filter %.S,$(SDIR_ASM_SRCS)))
SDIR_OBJ_LIST_SS    := $(patsubst %.s,%.o,$(filter %.s,$(SDIR_ASM_SRCS)))

SDIR_OBJ_LIST := $(sort $(SDIR_OBJ_LIST_C) $(SDIR_OBJ_LIST_CPP) \
                $(SDIR_OBJ_LIST_CXX) $(SDIR_OBJ_LIST_CC) $(SDIR_OBJ_LIST_S) \
                $(SDIR_OBJ_LIST_SS))

# Relative-pathed objects that being with "../" are handled differently.
#
# Regular objects are created as 
#   $(OBJ_ROOT_DIR)/<path>/<filename>.o
# where the path structure is maintained under the obj directory.  This
# applies for both absolute and relative paths; in the absolute path
# case this means the entire source path will be recreated under the obj
# directory.  This is done to allow two source files with the same name
# to be included as part of the project.
#
# Note: On Cygwin, the path recreated under the obj directory will be 
# the cygpath -u output path.
#
# Relative-path objects that begin with "../" cause problems under this 
# scheme, as $(OBJ_ROOT_DIR)/../<rest of path>/ can potentially put the object
# files anywhere in the system, creating clutter and polluting the source tree.
# As such, their paths are flattened - the object file created will be 
# $(OBJ_ROOT_DIR)/<filename>.o.  Due to this, two files specified with 
# "../" in the beginning cannot have the same name in the project.  VPATH 
# will be set for these sources to allow make to relocate the source file 
# via %.o rules.
#
# The following lines separate the object list into the flatten and regular
# lists, and then handles them as appropriate.

FLATTEN_OBJ_LIST := $(filter ../%,$(OBJ_LIST))
FLATTEN_APP_OBJS := $(addprefix $(OBJ_ROOT_DIR)/,$(notdir $(FLATTEN_OBJ_LIST)))

REGULAR_OBJ_LIST         := $(filter-out $(FLATTEN_OBJ_LIST),$(OBJ_LIST))
REGULAR_OBJ_LIST_C         := $(filter $(OBJ_LIST_C),$(REGULAR_OBJ_LIST))
REGULAR_OBJ_LIST_CPP    := $(filter $(OBJ_LIST_CPP),$(REGULAR_OBJ_LIST))
REGULAR_OBJ_LIST_CXX     := $(filter $(OBJ_LIST_CXX),$(REGULAR_OBJ_LIST))
REGULAR_OBJ_LIST_CC     := $(filter $(OBJ_LIST_CC),$(REGULAR_OBJ_LIST))
REGULAR_OBJ_LIST_S         := $(filter $(OBJ_LIST_S),$(REGULAR_OBJ_LIST))
REGULAR_OBJ_LIST_SS        := $(filter $(OBJ_LIST_SS),$(REGULAR_OBJ_LIST))

FLATTEN_SDIR_OBJ_LIST := $(filter ../%,$(SDIR_OBJ_LIST))
FLATTEN_SDIR_APP_OBJS := $(addprefix $(OBJ_ROOT_DIR)/,$(notdir $(FLATTEN_SDIR_OBJ_LIST)))

REGULAR_SDIR_OBJ_LIST         := $(filter-out $(FLATTEN_SDIR_OBJ_LIST),$(SDIR_OBJ_LIST))
REGULAR_SDIR_OBJ_LIST_C     := $(filter $(SDIR_OBJ_LIST_C),$(REGULAR_SDIR_OBJ_LIST))
REGULAR_SDIR_OBJ_LIST_CPP    := $(filter $(SDIR_OBJ_LIST_CPP),$(REGULAR_SDIR_OBJ_LIST))
REGULAR_SDIR_OBJ_LIST_CXX     := $(filter $(SDIR_OBJ_LIST_CXX),$(REGULAR_SDIR_OBJ_LIST))
REGULAR_SDIR_OBJ_LIST_CC     := $(filter $(SDIR_OBJ_LIST_CC),$(REGULAR_SDIR_OBJ_LIST))
REGULAR_SDIR_OBJ_LIST_S     := $(filter $(SDIR_OBJ_LIST_S),$(REGULAR_SDIR_OBJ_LIST))
REGULAR_SDIR_OBJ_LIST_SS    := $(filter $(SDIR_OBJ_LIST_SS),$(REGULAR_SDIR_OBJ_LIST))

VPATH := $(sort $(dir $(FLATTEN_OBJ_LIST)) $(dir $(FLATTEN_SDIR_OBJ_LIST)))

APP_OBJS_C := $(addprefix $(OBJ_ROOT_DIR)/,\
    $(REGULAR_SDIR_OBJ_LIST_C) \
    $(foreach s,$(REGULAR_OBJ_LIST_C),$(call adjust-path,$s)))

APP_OBJS_CPP := $(addprefix $(OBJ_ROOT_DIR)/,\
    $(REGULAR_SDIR_OBJ_LIST_CPP) \
    $(foreach s,$(REGULAR_OBJ_LIST_CPP),$(call adjust-path,$s)))

APP_OBJS_CXX := $(addprefix $(OBJ_ROOT_DIR)/,\
    $(REGULAR_SDIR_OBJ_LIST_CXX) \
    $(foreach s,$(REGULAR_OBJ_LIST_CXX),$(call adjust-path,$s)))

APP_OBJS_CC := $(addprefix $(OBJ_ROOT_DIR)/,\
    $(REGULAR_SDIR_OBJ_LIST_CC) \
    $(foreach s,$(REGULAR_OBJ_LIST_CC),$(call adjust-path,$s)))

APP_OBJS_S := $(addprefix $(OBJ_ROOT_DIR)/,\
    $(REGULAR_SDIR_OBJ_LIST_S) \
    $(foreach s,$(REGULAR_OBJ_LIST_S),$(call adjust-path,$s)))

APP_OBJS_SS := $(addprefix $(OBJ_ROOT_DIR)/,\
    $(REGULAR_SDIR_OBJ_LIST_SS) \
    $(foreach s,$(REGULAR_OBJ_LIST_SS),$(call adjust-path,$s)))

APP_OBJS := $(APP_OBJS_C) $(APP_OBJS_CPP) $(APP_OBJS_CXX) $(APP_OBJS_CC) \
    $(APP_OBJS_S) $(APP_OBJS_SS) \
    $(FLATTEN_APP_OBJS) $(FLATTEN_SDIR_APP_OBJS)

# Add any extra user-provided object files.
APP_OBJS += $(OBJS)

# Create list of dependancy files for each object file.
APP_DEPS := $(APP_OBJS:.o=.d)

# Patch the Elf file with system specific information

# Patch the Elf with the name of the sopc system
ifneq ($(SOPC_NAME),)
ELF_PATCH_FLAG += --sopc_system_name $(SOPC_NAME)
endif

# Patch the Elf with the absolute path to the Quartus Project Directory
ifneq ($(QUARTUS_PROJECT_DIR),)
ABS_QUARTUS_PROJECT_DIR := $(call adjust-path-mixed,$(shell cd "$(QUARTUS_PROJECT_DIR)"; pwd))
ELF_PATCH_FLAG += --quartus_project_dir "$(ABS_QUARTUS_PROJECT_DIR)"
endif

# Patch the Elf and download args with the JDI_FILE if specified
ifneq ($(wildcard $(JDI_FILE)),)
ELF_PATCH_FLAG += --jdi $(JDI_FILE)
DOWNLOAD_JDI_FLAG := --jdi $(JDI_FILE)
endif

# Use the DOWNLOAD_CABLE variable to specify which JTAG cable to use. 
# This is not needed if you only have one cable.
ifneq ($(DOWNLOAD_CABLE),)
DOWNLOAD_CABLE_FLAG := --cable '$(DOWNLOAD_CABLE)'
endif


#------------------------------------------------------------------------------
#                           BUILD PRE/POST PROCESS
#------------------------------------------------------------------------------
build_pre_process :
    $(BUILD_PRE_PROCESS)

build_post_process :
    $(BUILD_POST_PROCESS)

.PHONY: build_pre_process build_post_process


#------------------------------------------------------------------------------
#                                 TOOLS
#------------------------------------------------------------------------------

#
# Set tool default variables if not already defined.
# If these are defined, they would typically be defined in an
# included makefile fragment.
#
ifeq ($(DEFAULT_CROSS_COMPILE),)
DEFAULT_CROSS_COMPILE := nios2-elf-
endif

ifeq ($(DEFAULT_STACK_REPORT),)
DEFAULT_STACKREPORT := nios2-stackreport
endif

ifeq ($(DEFAULT_DOWNLOAD),)
DEFAULT_DOWNLOAD := nios2-download
endif

ifeq ($(DEFAULT_FLASHPROG),)
DEFAULT_FLASHPROG := nios2-flash-programmer
endif

ifeq ($(DEFAULT_ELFPATCH),)
DEFAULT_ELFPATCH := nios2-elf-insert
endif

ifeq ($(DEFAULT_RM),)
DEFAULT_RM := rm -f
endif

ifeq ($(DEFAULT_MKDIR),)
DEFAULT_MKDIR := mkdir -p
endif

#
# Set tool variables to defaults if not already defined.
# If these are defined, they would typically be defined by a
# setting in the generated portion of this makefile.
#
ifeq ($(CROSS_COMPILE),)
CROSS_COMPILE := $(DEFAULT_CROSS_COMPILE)
endif

ifeq ($(origin CC),default)
CC := $(CROSS_COMPILE)gcc -xc
endif

ifeq ($(origin CXX),default)
CXX := $(CROSS_COMPILE)gcc -xc++
endif

ifeq ($(origin AS),default)
AS := $(CROSS_COMPILE)gcc
endif

ifeq ($(origin AR),default)
AR := $(CROSS_COMPILE)ar
endif

ifeq ($(origin LD),default)
LD := $(CROSS_COMPILE)g++
endif

ifeq ($(origin NM),default)
NM := $(CROSS_COMPILE)nm
endif

ifeq ($(origin RM),default)
RM := $(DEFAULT_RM)
endif

ifeq ($(OBJDUMP),)
OBJDUMP := $(CROSS_COMPILE)objdump
endif

ifeq ($(OBJCOPY),)
OBJCOPY := $(CROSS_COMPILE)objcopy
endif

ifeq ($(STACKREPORT),)
STACKREPORT := $(DEFAULT_STACKREPORT)
endif

ifeq ($(DOWNLOAD),)
DOWNLOAD := $(DEFAULT_DOWNLOAD)
endif

ifeq ($(FLASHPROG),)
FLASHPROG := $(DEFAULT_FLASHPROG)
endif

ifeq ($(ELFPATCH),)
ELFPATCH := $(DEFAULT_ELFPATCH)
endif

ifeq ($(MKDIR),)
MKDIR := $(DEFAULT_MKDIR)
endif

#------------------------------------------------------------------------------
#                     PATTERN RULES TO BUILD OBJECTS
#------------------------------------------------------------------------------

define compile.c
@$(ECHO) Info: Compiling $< to $@
@$(MKDIR) $(@D)
$(CC) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
$(CC_POST_PROCESS)
endef

define compile.cpp
@$(ECHO) Info: Compiling $< to $@
@$(MKDIR) $(@D)
$(CXX) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
$(CXX_POST_PROCESS)
endef

define compile.s
@$(ECHO) Info: Assembling $< to $@
@$(MKDIR) $(@D)
$(AS) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) $(APP_ASFLAGS) -o $@ $<
$(AS_POST_PROCESS)
endef

ifeq ($(MAKE_VERSION),3.81) 
.SECONDEXPANSION:

$(APP_OBJS_C): $(OBJ_ROOT_DIR)/%.o: $$(call adjust-path-mixed,%.c)
    $(compile.c)

$(APP_OBJS_CPP): $(OBJ_ROOT_DIR)/%.o: $$(call adjust-path-mixed,%.cpp)
    $(compile.cpp)

$(APP_OBJS_CC): $(OBJ_ROOT_DIR)/%.o: $$(call adjust-path-mixed,%.cc)
    $(compile.cpp)

$(APP_OBJS_CXX): $(OBJ_ROOT_DIR)/%.o: $$(call adjust-path-mixed,%.cxx)
    $(compile.cpp)

$(APP_OBJS_S): $(OBJ_ROOT_DIR)/%.o: $$(call adjust-path-mixed,%.S)
    $(compile.s)

$(APP_OBJS_SS): $(OBJ_ROOT_DIR)/%.o: $$(call adjust-path-mixed,%.s)
    $(compile.s)

endif # MAKE_VERSION != 3.81

$(OBJ_ROOT_DIR)/%.o: %.c
    $(compile.c)

$(OBJ_ROOT_DIR)/%.o: %.cpp
    $(compile.cpp)

$(OBJ_ROOT_DIR)/%.o: %.cc
    $(compile.cpp)

$(OBJ_ROOT_DIR)/%.o: %.cxx
    $(compile.cpp)

$(OBJ_ROOT_DIR)/%.o: %.S
    $(compile.s)

$(OBJ_ROOT_DIR)/%.o: %.s
    $(compile.s)


#------------------------------------------------------------------------------
#                     PATTERN RULES TO INTERMEDIATE FILES
#------------------------------------------------------------------------------

$(OBJ_ROOT_DIR)/%.s: %.c
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CC) -S $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.s: %.cpp
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.s: %.cc
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.s: %.cxx
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.i: %.c
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CC) -E $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.i: %.cpp
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.i: %.cc
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<

$(OBJ_ROOT_DIR)/%.i: %.cxx
    @$(ECHO) Info: Compiling $< to $@
    @$(MKDIR) $(@D)
    $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<


#------------------------------------------------------------------------------
#                        TARGET RULES
#------------------------------------------------------------------------------

.PHONY : help
help :
    @$(ECHO) "Summary of Makefile targets"
    @$(ECHO) "  Build targets:"
    @$(ECHO) "    all (default)     - Application and all libraries (including BSP)"
    @$(ECHO) "    bsp               - Just the BSP"
    @$(ECHO) "    libs              - All libraries (including BSP)"
    @$(ECHO) "    flash             - All flash files"    
    @$(ECHO) "    mem_init_generate - All memory initialization files"
    @$(ECHO) "    mem_init_install  - All memory initialization files (copy files to Quartus II project)"
    @$(ECHO) "  Clean targets:"
    @$(ECHO) "    clean_all         - Application and all libraries (including BSP)"
    @$(ECHO) "    clean             - Just the application"
    @$(ECHO) "    clean_bsp         - Just the BSP"
    @$(ECHO) "    clean_libs        - All libraries (including BSP)"
    @$(ECHO) "  Run targets:"
    @$(ECHO) "    download-elf      - Download and run your elf executable"
    @$(ECHO) "    program-flash     - Program flash contents to the board"

# Handy rule to skip making libraries and just make application.
.PHONY : app
app : $(ELF)

ifeq ($(CREATE_OBJDUMP), 1)
app : $(OBJDUMP_NAME)
endif

ifeq ($(CREATE_ELF_DERIVED_FILES),1)
app : elf_derived_files
endif

.PHONY: elf_derived_files
elf_derived_files: mem_init_install

# Handy rule for making just the BSP.
.PHONY : bsp
bsp :
    @$(ECHO) Info: Building $(BSP_ROOT_DIR)
    @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR)


# Make sure all makeable libraries (including the BSP) are up-to-date.
LIB_TARGETS := $(patsubst %,%-recurs-make-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS))

.PHONY : libs
libs : $(LIB_TARGETS)

ifneq ($(strip $(LIB_TARGETS)),)
$(LIB_TARGETS): %-recurs-make-lib:
    @$(ECHO) Info: Building $*
    $(MAKE) --no-print-directory -C $*
endif

ifneq ($(strip $(APP_LDDEPS)),)
$(APP_LDDEPS): libs
    @true
endif

# Rules to force your project to rebuild or relink
# .force_relink file will cause any application that depends on this project to relink 
# .force_rebuild file will cause this project to rebuild object files
# .force_rebuild_all file will cause this project and any project that depends on this project to rebuild object files

FORCE_RELINK_DEP  := .force_relink
FORCE_REBUILD_DEP := .force_rebuild
FORCE_REBUILD_ALL_DEP := .force_rebuild_all
FORCE_REBUILD_DEP_LIST := $(FORCE_RELINK_DEP) $(FORCE_REBUILD_DEP) $(FORCE_REBUILD_ALL_DEP)

$(FORCE_REBUILD_DEP_LIST):

$(APP_OBJS): $(wildcard $(FORCE_REBUILD_DEP)) $(wildcard $(addsuffix /$(FORCE_REBUILD_ALL_DEP), . $(ALT_LIBRARY_DIRS)))

$(ELF): $(wildcard $(addsuffix /$(FORCE_RELINK_DEP), . $(ALT_LIBRARY_DIRS)))


# Clean just the application.
.PHONY : clean
ifeq ($(CREATE_ELF_DERIVED_FILES),1)
clean : clean_elf_derived_files
endif

clean :
    @$(RM) -r $(ELF) $(OBJDUMP_NAME) $(LINKER_MAP_NAME) $(OBJ_ROOT_DIR) $(FORCE_REBUILD_DEP_LIST)
    @$(ECHO) [$(APP_NAME) clean complete]

# Clean just the BSP.
.PHONY : clean_bsp
clean_bsp :
    @$(ECHO) Info: Cleaning $(BSP_ROOT_DIR)
    @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR) clean

# Clean all makeable libraries including the BSP.
LIB_CLEAN_TARGETS := $(patsubst %,%-recurs-make-clean-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS))

.PHONY : clean_libs
clean_libs : $(LIB_CLEAN_TARGETS)

ifneq ($(strip $(LIB_CLEAN_TARGETS)),)
$(LIB_CLEAN_TARGETS): %-recurs-make-clean-lib:
    @$(ECHO) Info: Cleaning $*
    $(MAKE) --no-print-directory -C $* clean
endif

# Clean application and all makeable libraries including the BSP.
.PHONY : clean_all
clean_all : clean mem_init_clean clean_libs


# Include the dependency files unless the make goal is performing a clean
# of the application.
ifneq ($(firstword $(MAKECMDGOALS)),clean)
ifneq ($(firstword $(MAKECMDGOALS)),clean_all)
-include $(APP_DEPS)
endif
endif

.PHONY : download-elf
download-elf : $(ELF)
    @if [ "$(DOWNLOAD)" = "none" ]; \
    then \
        $(ECHO) Downloading $(ELF) not supported; \
    else \
        $(ECHO) Info: Downloading $(ELF); \
        $(DOWNLOAD) --go --cpu_name=$(CPU_NAME) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) $(DOWNLOAD_JDI_FLAG) $(WRITE_GMON_OPTION) $(ELF); \
    fi    

# Delete the target of a rule if it has changed and its commands exit 
# with a nonzero exit status.
.DELETE_ON_ERROR:

# Rules for flash programming commands
PROGRAM_FLASH_SUFFIX := -program
PROGRAM_FLASH_TARGET := $(addsuffix $(PROGRAM_FLASH_SUFFIX), $(FLASH_FILES))

.PHONY : program-flash
program-flash : $(PROGRAM_FLASH_TARGET)

.PHONY : $(PROGRAM_FLASH_TARGET)
$(PROGRAM_FLASH_TARGET) : flash
    @if [ "$(FLASHPROG)" = "none" ]; \
    then \
        $(ECHO) Programming flash not supported; \
    else \
        $(ECHO) Info: Programming $(basename $@).flash; \
        if [ -z "$($(basename $@)_EPCS_FLAGS)" ]; \
        then \
            $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \
            $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \
        else \
            $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \
            $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \
        fi \
    fi

#------------------------------------------------------------------------------
#                         ELF TARGET RULE
#------------------------------------------------------------------------------
# Rule for constructing the executable elf file.
$(ELF) : $(APP_OBJS) $(LINKER_SCRIPT) $(APP_LDDEPS)
    @$(ECHO) Info: Linking $@
    $(LD) $(APP_LDFLAGS) $(APP_CFLAGS) -o $@ $(filter-out $(CRT0),$(APP_OBJS)) $(APP_LIBS) $(APP_BSP_DEP_LIBS)
ifneq ($(DISABLE_ELFPATCH),1)
    $(ELFPATCH) $@ $(ELF_PATCH_FLAG)
endif
ifneq ($(DISABLE_STACKREPORT),1)
    @$(STACKREPORT) $@
endif

$(OBJDUMP_NAME) : $(ELF)
    @$(ECHO) Info: Creating $@
    $(OBJDUMP) $(OBJDUMP_FLAGS) $< >$@

# Rule for printing the name of the elf file
.PHONY: print-elf-name
print-elf-name:
    @$(ECHO) $(ELF)

#9 Re : -1 »  [Résolu] [C] problème de compilation » Le 04/11/2010, à 16:45

gilbert
Réponses : 8

hello,

non je ne pense pas que cela soit normal. Enfin.. Oui l'interface NIOS 2 est un IDE basé sur eclipse... C'est lui qui a généré automatiquement tous les makefile et autres fichiers de configuration.. ma fonction main est en C. Je vais essayer de modifier le makefile et voir ce que cela donne...

merci pour l'hint.

Je vous redis tout cela ce soir.

#10 Re : -1 »  [Résolu] [C] problème de compilation » Le 04/11/2010, à 22:13

gilbert
Réponses : 8

hello,

alors bon voilà. Le problème était stupide, comme je le pensais dès le début...

J'ai installé la version linux et là comme de par hasard, tout compile bien et tout fonctionne correctement. Reste que mon interface jtag ne fonctionne pas sous linux. C'est pour ça que j'avais pensé développer sous w..

Et en fait c'était un problème de droit. Si je démarre l'application en tant qu'administrateur sous w, ça fonctionne. Je trouve ça particulièrement sale..

Enfin, sous ubuntu avec mon compte normal, avec mes droits normaux tout fonctionne correctement, ce qui est beaucoup plus propre. donc je ne cherchais effectivement pas au bon endroit.

Enfin, merci à tous pour votre aide.

++

#11 Re : -1 »  [Résolu x2] Problème d'encodage de caractères » Le 21/06/2010, à 22:55

gilbert
Réponses : 10
Link31 a écrit :
echo "h%E9h%E9%2C+%E7a+marche+!" | perl -pe "s/\%([A-Fa-f0-9]{2})/pack('C', hex(\$1))/eg;s/\+/ /sg"

Presque.. Ton exemple est mal choisi le point d'exclamation est interprété par le shell...


$ echo "h%E9h%E9%2C+%E7a+marche+!" | perl -pe "s/\%([A-Fa-f0-9]{2})/pack('C', hex(\$1))/eg;s/\+/ /sg"
bash: !": event not found

Il devrait commencer par protéger les caractères spéciaux par des backslash... C'est un peu gênant non ?

#12 -1 »  problème contrôleur réseau » Le 25/06/2010, à 23:16

gilbert
Réponses : 3

Hello,

voilà j'ai une carte mère Asus P7P55D Pro avec un contrôleur réseau Realtek 8112L Gigabit LAN intégré. La plupart du temps tout fonctionne bien.

Toutefois, depuis quelques jours (1 semaine à la date du post) lorsque je démarre j'ai un avertissement au BIOS qui me dit que le contrôleur réseau n'est pas prêt. Si je continue de booter, l'OS ne trouve pas de carte réseau => pas de connexion internet ni de réseau tout court.. Je suis alors obligé d'éteindre mon ordinateur, de débrancher la prise secteur, d'attendre que les capa soient bien déchargées puis je rebranche ma machine au secteur et lorsque je la redémarre tout fonctionne correctement.

Ce problème n'apparaît pas systématiquement, mais j'ai peur qu'il devienne de plus en plus fréquent.

Je pense que le problème est essentiellement hardware. Néanmoins quelqu'un aurait-il lui aussi rencontré ce genre de problèmes avec cette carte ? Avez-vous des pistes de solutions ? Une mise à jour du firmware du BIOS peut-elle apporter quelque amélioration ? (autre que de changer de carte mère qui serait un peu la solution du désespoir..)

Merci pour votre aide

#13 Re : -1 »  problème contrôleur réseau » Le 26/06/2010, à 19:53

gilbert
Réponses : 3

hello,

ouais non ce n'est pas un ordinateur portable donc c'est encore plus simple. Je peux en effet mettre une carte réseau dans un slot PCI, mais ça ne ferait que contourner mon problème.. Je cherche à en connaître la cause..

Y'a-t-il un moyen de procéder méthodiquement pour trouver les raisons de ce dysfonctionnement ?

#14 Re : -1 »  Besoin d'aide pour un script (petit nouveau linuxien) [résolu] » Le 20/06/2010, à 22:15

gilbert
Réponses : 21

devoir à rendre pour quand ?? lol

pour récupérer le (n+1)è caractère de la variable $VAR : echo ${VAR:n:1} si je mets 3 à la place de n ça me retournera le 4è caractère, le 1er étant à 0.

pour incrémenter le caractère tu peux utiliser tr(1)

exemple pour linux :

$read -p "Entrez votre mot : " MOT
Entrez votre mot : linux
$ echo $MOT | tr "[\040-\376]" "[\041-\377]"
mjovy
$

EDIT : dans tr j'ai commencé à partir de 40 pour ne pas convertir les caractères spéciaux... mais tu peux commencer à partir de 0..

#15 Re : -1 »  Besoin d'aide pour un script (petit nouveau linuxien) [résolu] » Le 23/06/2010, à 13:39

gilbert
Réponses : 21

salut,

voici tes erreurs :

if [ $ascii=123 ]
then
            ascii = "97"
fi

à remplacer par :

if [ $ascii == "123" ]
then
            ascii="97"
fi

Ta 1ère erreur :
dans la condition, si tu compares l'égalité de deux chaînes de caractères il faut utiliser l'oprateur == (qui est plus un argument ici), si tu veux comparer deux nombres il faut utiliser l'opérateur -eq. Ici, dans ton cas, que tu utilises == ou -eq ça fonctionnera pareillement. mais le = simple est un opérateur d'affectation.

Ta 2è erreur :
Quand on affecte une valeur à une variable, on ne met pas d'espace entre avanet et après le = en bash : variable=valeur.

A+

#16 Re : -1 »  Besoin d'aide pour un script (petit nouveau linuxien) [résolu] » Le 23/06/2010, à 21:38

gilbert
Réponses : 21
lovasoa a écrit :

@gilbert: il me semble que test (les crochets après le if sont automatiquement remplacés par la commande test) accepte = comme opérateur de comparaison. En effet, test ne permet pas de définir une variable, il n'y a donc pas la même ambiguité que dans la plupart des langages de programmation.
http://www.laboiteaprog.com/article-79- … conditions

il fait même plus que te sembler car c'est totalement vrai ce que tu dis.

Mais ouais, ok ma réponse est un peu malhabile. Disons que si l'on s'habitue à utiliser le simple = on peut prendre de mauvaises habitudes et les traîner ailleurs. Pour des raisons de concordance mentale, je pense, mais ce n'est qu'un avis personnel, qu'il est préférable de rester cohérent avec les autres langages et de préférer le == au simple =.

mais si on arrive à jongler facilement alors oui, pas de soucis à utiliser le simple =.

#17 Re : -1 »  programme avec gestion usb » Le 20/06/2010, à 19:36

gilbert
Réponses : 2

salut,

vegas85 a écrit :

J'aimerais savoir si vous auriez de la doc en français afin que je modifie mon programme pour utiliser un port parallel 9broche , et si c'est plus compliquer ??? et si le nombre de sortie est le meme, car avec un DB25 je dispose de 8 sortie et ceux très simplement ^^.

Le port auquel tu fais allusion est un port série et non un port parallèle. De la doc ici [1].

vegas85 a écrit :

Ou mieux, s'il y a possibilités d'utiliser le port usb, cependant le peu que j'ai pu lire au sujet de la programmation etait soit en anglais soit complexe. Est-ce possible d'envoyer simplement 0/1 sans passé par un tas de manipe???
De plus il n'y a pas 8 mais 2 sortie sur le port usb, donc quel circuit integrer ou manipe a effectuer pour que en fonction de ce qui sort du port usb , retrouver un nombre compris en 0 et 2^8???

Quel intérêt de chercher de la doc en français... C'est compliqué et ça n'apporte rien. Tout est très bien documenté en anglais et c'est normal d'ailleurs. Je pense qu'on trouve suffisamment de documentation pour se passer du français.

Il n'y a pas 2 sorties sur le port USB mais bel est bien une seule entrée/sortie. Le signal est différentiel. Et là aussi, USB signifie Universal Serial Bus. C'est donc un bus sériel et non parallèle.

Il existe des circuits spécialisés pour transformer des données USB vers tout autre bus : I2C, SPI, JTAG, parallèle, etc..

Les circuits FTDI [2] sont réputés pour cela car simple d'utilisation.

Dans tous les cas il ne faut pas trop rêver... Si tu veux apprendre à programmer tu peux t'orienter plutôt vers les microcontrôleurs. Leur prise en main est beaucoup plus simple que d'essayer de lier du matériel sur un ordinateur.

Quoi qu'il en soit, si tu veux programmer des périphériques sous Linux, il faudra décider si tu veux programmer au niveau kernel ou user. Si tu n'es pas un guru barbu de Linux, je te conseille plutôt de programmer en user level. Cela signifie que tu n'aura pas un contrôle précis de ton périphérique. (ce n'est pas parce que ton processeur est un 3GHz qu'il faut espérer pouvoir sortir des impulsions de 300 ps.. Au plus rapide compte les 100 Hz ). Néanmoins tu passeras par une API qui elle contient l'ensemble des fonctions nécessaires à la communication entre ton périphérique et ton logiciel. La programmation est donc relativement simple. Un exemple concret de réalisation d'un périphérique USB vers ce que tu veux : [3]. L'ensemble est open-source, tu peux y apprendre.

Quoi qu'il en soit, tu risques d'être pas mal déçu et vite rebuté car le hardware pour les PC c'est pas si simple que ce que l'on croit... À toi de voir ce que tu recherches vraiment.

Si tu as des questions plus précises n'hésite pas. wink


[1] : http://www.aurel32.net/elec/port_serie.php
[2] : http://www.ftdichip.com
[3] : http://www.embedded-projects.net/index.php?page_id=165

#18 -1 »  son : activer 5.1 surround » Le 20/06/2010, à 11:54

gilbert
Réponses : 2

Bonjour,

voilà, je sais qu'il existe déjà une quantité énorme de topic sur le sujet mais je ne trouve pas la solution à mon problème.

J'ai la carte son suivante :

$ lspci | grep -i audio
00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 05)

et lorsque je test le son avec cette commande :

speaker-test -Dplug:surround51 -c6 -l1 -twav

Je n'ai que l'avant gauche et l'avant droite qui fonctionnent. Tous les autres canaux restent muet.

Ma question est comment configurer le son pour pouvoir bénéficier du son 5.1 ?

Merci pour votre aide.

EDIT : je suis sous lucid lynx 10.04. Mon chipset audio est un VIA VT1828S 8-channel High Definition Audio CODEC implanté sur une carte mère Asus P7P55D Pro.

#19 Re : -1 »  son : activer 5.1 surround » Le 21/06/2010, à 22:51

gilbert
Réponses : 2

hello,

le script fait bien ce qu'on lui demande, le seul problème c'est que je n'ai que 2 canaux : Master et Capture.

Comme il n'y a pas d'autres canaux je n'ai toujours pas de son sur mes autres enceintes.. Mon problème serait plutôt de savoir comment faire pour que mon système trouve les autres canaux de la carte.

#20 Re : -1 »  comment copier les x derniers fichiers? » Le 20/06/2010, à 21:51

gilbert
Réponses : 8
greg2007 a écrit :

Comment copier (du verbe copier permettant de faire une sauvegarde à l'identique ) les x (abréviation voulant dire un nombre) derniers fichiers (document numérique sauvegardé sur un ordinateur appelé aussi pc)

on a compris ta phrase.. c'est juste qu'elle n'a pas beaucoup de sens...

for FILE in $(find . -maxdepth 1 -type f -name "[[:alnum:]]*" | tail -n LIMIT); do cp "$FILE" DEST; done

où tu remplaces LIMIT par le nombre correspondant à tes derniers fichiers et DEST par le dossier de destination...

#21 Re : -1 »  [Resolu] Langage C, fichiers.h, ou sont les .c correspondants ? » Le 20/06/2010, à 22:28

gilbert
Réponses : 5

salut,

les fonctions prototypées dans les header files "standards" que tu appelles dans ton code sont déjà compilées et sont présentes dans la librairie libc.. Il n'y a donc pas besoin du code. (Gain de temps précieux à la compilation).

Mais si tu veux lire leur code tu peux installer les sources de libc.

plus d'info sur la librairie : http://www.gnu.org/software/libc/

EDIT : si tu veux créer une nouvelle fonction. Alors tu peux la compiler par exemple

gcc maNouvelleFonction.c -o maNouvelleFonction.o

et tu as un objet... ensuite tu peux lier cet objet avec le linker ou bien créer une librairie qui contiendra ton objet (statique .a dynamique .so)

Les include par défaut sont dans /usr/include et les librairies sont dans /use/lib

mais si tu ne veux pas les mettre dans ces dossier (ce qui est recommandé) tu peux toujours préciser le dossier où l'objet se trouve à la compilation avec le paramètre -I dossier et ainsi quand tu inclueras ton header file il ira regarder dans ton dossier en plus. Ce qui est préférable.

#22 Re : -1 »  [Resolu] Langage C, fichiers.h, ou sont les .c correspondants ? » Le 20/06/2010, à 22:45

gilbert
Réponses : 5

Un petit exemple. une fonction qui affiche hello world.

ton header file :

/* fichier helloWorld.h */
#ifndef __HELLO_WORLD_H__
#define __HELLO_WORLD_H__

#include <stdio.h>

void helloWorld(void);

# endif /* __HELLO_WORLD_H__ */

ton fichier c :

/* fichier helloWorld.c */
#include "helloWorld.h"

void helloWorld(void) {
    printf("hello world!\n");
}

après tu compiles ton fichier helloWorld.c

gcc -c helloWorld.c -o helloWorld.o

Ensuite tu l'ajoute dans une librairie, faisons un .a

ar -q libHelloWorld.a helloWorld.o

Ensuite dans le fichier de ton projet où tu veux appeler ta fonction helloWorld() :

#include <helloWorld.h>
/* ... */

/* appel de la fonction */
helloWorld();

et quand tu vas compiler :

gcc -c programme.c -I/chemin/vers/ton/header -o programme.o
gcc -o programme programme.o -L/chemin/vers/ta/lib -lHelloWorld

et ça devrait marcher... (je dis ça de tête)

#23 Re : -1 »  Enchainement de commandes et récupérer une variable » Le 19/06/2010, à 15:53

gilbert
Réponses : 9

commande1 && commande2 exécutera commande2 si et seulement si commande1 réussi (c'est-à-dire retourne 0). de même on peut faire commande1 || commande2 qui exécutera commande2 si et seulement si commande1 échoue (retourne toute autre valeur que 0).

Si tu veux exécuter une commande2 après commande1 indépendamment du code de retour de commande1 tu peux faire commande1; commande2

Ravi d'avoir pu t'aider.

#24 Re : -1 »  Enchainement de commandes et récupérer une variable » Le 19/06/2010, à 18:16

gilbert
Réponses : 9
Watael a écrit :

NB: les ` au lieu de $(), parce que c'est du Bourne Shell (pareil pour le if). na!

moi j'aurais plutôt dit : NB: #!/bin/bash au lieu de #!/bin/sh afin d'éviter de prendre des habitudes surannées... big_smile