Перейти к содержанию
    

den_krom

Участник
  • Постов

    11
  • Зарегистрирован

  • Посещение

Репутация

0 Обычный
  1. PIT на AT91SAM9G45

    GCC 4.6.0. Пробовал строить их оригинальный проект с PIT - те же проблемы. От среды разработки тоже не зависит, пробовал собирать проект в GNU, Keil, IAR. Кстати в Keil и IAR интегрированы свои компиляторы, так что думаю версия в данном случае ни при чем. Буду писать в службу поддержки atmel.
  2. PIT на AT91SAM9G45

    Мне вот интересно. Я взял пример кода с официального сайта atmel конкретно для своего контроллера. Получается они не тестировали примеры на нем перед размещением?
  3. PIT на AT91SAM9G45

    Я в курсе, что на самом деле происходит. При обработке прерывания вывожу значения счетчика pit в порт usart и фиксирую с помощью терминала.
  4. PIT на AT91SAM9G45

    Пробовал размещать инструкцию (ldr pc, [pc, #-0xF20]) - не помогло. Замаскировал все прерывания кроме SYS (AIC_IDCR = 0xFFFFFFFD). Результат тот же - из прерывания не выходит. Ниче понять не могу. Jtag emulator может как-то влиять на ситуацию?
  5. PIT на AT91SAM9G45

    Попробовал выключить оптимизацию и убрать автомат AIC - как говорится те же яйца. PIT считает, в исх. точку программы не выходит. AIC_EOICR + аттрибуты добавлял. Если программу выполнять полностью в пошаговом режиме, то все работает как и должно. Кстати в board_lowlevel.c при инициализации чипа всем прерываниям присваивается обработчик по умолчанию с бесконечным циклом: //------------------------------------------------------------------------------ /// Default spurious interrupt handler. Infinite loop. //------------------------------------------------------------------------------ void defaultSpuriousHandler( void ) { while (1); } //------------------------------------------------------------------------------ /// Default handler for fast interrupt requests. Infinite loop. //------------------------------------------------------------------------------ void defaultFiqHandler( void ) { while (1); } //------------------------------------------------------------------------------ /// Default handler for standard interrupt requests. Infinite loop. //------------------------------------------------------------------------------ void defaultIrqHandler( void ) { while (1); } Пробовал туда вместо while (1) ставить AIC_EOICR = 0 - результат все тот же. Как замаскировать все прерывания кроме PIT? Пробовал AIC_DCR = AT91C_AIC_DCR_GMSK, но в этом случае маскируются все прерывания.
  6. PIT на AT91SAM9G45

    Отладчиком пользуюсь. Protection Mode не активирован. Если его активировать, то прерывания в принципе не случаются и не выходит в исходную точку программы, попросту "висит". Если в обработчик прерывания от PIT добавить чтение регистра AIC_IVR, то происходит одно прерывание от PIT и выходит в исходную точку программы, но прерываний больше не происходит.
  7. PIT на AT91SAM9G45

    У меня в программе больше ни кем не используется. Но такое ощущение, что кто-то еще его пользует. #include <board.h> #include <pio/pio.h> #include <pio/pio_it.h> #include <usart/usart.h> #include <tc/tc.h> #include <irq/irq.h> #include <pmc/pmc.h> #include <utility/trace.h> #include <pit/pit.h> #include <stdio.h> //------------------------------------------------------------------------------ // Local definition //------------------------------------------------------------------------------ /// PIT period value in µseconds. #define PIT_PERIOD 1000 //------------------------------------------------------------------------------ // Local variables //------------------------------------------------------------------------------ const Pin outpins[] = { PIN_OUT_1, PIN_OUT_2, PIN_OUT_3, PIN_OUT_4, PIN_OUT_5 }; /// Global timestamp in milliseconds since start of application. volatile unsigned int timestamp = 0; /// SYS registers AT91PS_PITC pitregs = AT91C_BASE_PITC; AT91PS_AIC aicregs = AT91C_BASE_AIC; //------------------------------------------------------------------------------ // Local functions //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ /// Handler for PIT interrupt. Increments the timestamp counter. //------------------------------------------------------------------------------ void ISR_Pit(void) { unsigned int status; // Read the PIT status register status = PIT_GetStatus() & AT91C_PITC_PITS; if (status != 0) { // 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR. // Read the PIVR to acknowledge interrupt and get number of ticks //Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR. timestamp += (PIT_GetPIVR() >> 20); } } //------------------------------------------------------------------------------ /// Configure the periodic interval timer (PIT) to generate an interrupt every /// millisecond. //------------------------------------------------------------------------------ void ConfigurePit(void) { // Initialize the PIT to the desired frequency PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000); // Configure interrupt on PIT IRQ_DisableIT(AT91C_ID_SYS); IRQ_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit); IRQ_EnableIT(AT91C_ID_SYS); PIT_EnableIT(); // Enable the pit PIT_Enable(); } //------------------------------------------------------------------------------ /// Waits for the given number of milliseconds (using the timestamp generated /// by the SAM7 & SAM9 microcontrollers's PIT, or SAM3's microcontrollers's system tick). /// \param delay Delay to wait for, in milliseconds. //------------------------------------------------------------------------------ void Wait(unsigned long delay) { volatile unsigned int start = timestamp; unsigned int elapsed; do { elapsed = timestamp; elapsed -= start; } while (elapsed < delay); } //------------------------------------------------------------------------------ // Global functions //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ /// Application entry point. Configures USART0 in hardware handshaking mode and /// Timer Counter 0 to generate an interrupt every second. Then, starts the first /// transfer on the USART and wait in an endless loop. /// \return Unused. //------------------------------------------------------------------------------ int main(void) { // Configure pins PIO_Configure(outpins, PIO_LISTSIZE(outpins)); // Configure PIT ConfigurePit(); // Infinite loop while (1) { PIO_Set(&outpins[0]); Wait(10); PIO_Clear(&outpins[0]); Wait(50); } }
  8. PIT на AT91SAM9G45

    Если процедуру обработки прерывания описать следующим образом: __attribute__((interrupt("IRQ"))) void ISR_Pit(void) { unsigned int status; // Read the PIT status register status = PIT_GetStatus() & AT91C_PITC_PITS; if (status != 0) { // 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR. // Read the PIVR to acknowledge interrupt and get number of ticks //Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR. timestamp += (PIT_GetPIVR() >> 20); } aicregs->AIC_EOICR = 0; } то прерываний от PIT не происходит и не выходит в исходную точку программы. Если убрать aicregs->AIC_EOICR = 0; либо атрибут __attribute__((interrupt("IRQ"))) - прерывания происходят, но все равно не выходит в исходную точку программы. Уже не знаю куда копать, может в board_cstartup.S что-то поменять: #include "board.h" //------------------------------------------------------------------------------ // Definitions //------------------------------------------------------------------------------ #define IRQ_STACK_SIZE 8*3*4 #define ARM_MODE_ABT 0x17 #define ARM_MODE_FIQ 0x11 #define ARM_MODE_IRQ 0x12 #define ARM_MODE_SVC 0x13 #define I_BIT 0x80 #define F_BIT 0x40 //------------------------------------------------------------------------------ // Startup routine //------------------------------------------------------------------------------ .align 4 .arm /* Exception vectors *******************/ .section .vectors, "a", %progbits resetVector: ldr pc, =resetHandler /* Reset */ undefVector: b undefVector /* Undefined instruction */ swiVector: b swiVector /* Software interrupt */ prefetchAbortVector: b prefetchAbortVector /* Prefetch abort */ dataAbortVector: b dataAbortVector /* Data abort */ reservedVector: b reservedVector /* Reserved for future use */ irqVector: b irqHandler /* Interrupt */ fiqVector: /* Fast interrupt */ //------------------------------------------------------------------------------ /// Handles a fast interrupt request by branching to the address defined in the /// AIC. //------------------------------------------------------------------------------ fiqHandler: b fiqHandler //------------------------------------------------------------------------------ /// Handles incoming interrupt requests by branching to the corresponding /// handler, as defined in the AIC. Supports interrupt nesting. //------------------------------------------------------------------------------ irqHandler: /* Save interrupt context on the stack to allow nesting */ sub lr, lr, #4 stmfd sp!, {lr} mrs lr, SPSR stmfd sp!, {r0, lr} /* Write in the IVR to support Protect Mode */ ldr lr, =AT91C_BASE_AIC ldr r0, [lr, #AIC_IVR] str lr, [lr, #AIC_IVR] /* Branch to interrupt handler in Supervisor mode */ msr CPSR_c, #ARM_MODE_SVC stmfd sp!, {r1-r3, r4, r12, lr} blx r0 /* Restore scratch/used registers and LR from User Stack */ /* Disable Interrupt and switch back in IRQ mode */ ldmia sp!, {r1-r3, r4, r12, lr} msr CPSR_c, #ARM_MODE_IRQ | I_BIT /* Acknowledge interrupt */ ldr lr, =AT91C_BASE_AIC str lr, [lr, #AIC_EOICR] /* Restore interrupt context and branch back to calling code */ ldmia sp!, {r0, lr} msr SPSR_cxsf, lr ldmia sp!, {pc}^ //------------------------------------------------------------------------------ /// Initializes the chip and branches to the main() function. //------------------------------------------------------------------------------ .section .text .global entry entry: resetHandler: /* Useless instruction for referencing the .vectors section */ ldr r0, =resetVector /* Set pc to actual code location (i.e. not in remap zone) */ ldr pc, =1f /* Initialize the prerelocate segment */ 1: ldr r0, =_efixed ldr r1, =_sprerelocate ldr r2, =_eprerelocate 1: cmp r1, r2 ldrcc r3, [r0], #4 strcc r3, [r1], #4 bcc 1b /* Perform low-level initialization of the chip using LowLevelInit() */ ldr sp, =_sstack stmfd sp!, {r0} ldr r0, =LowLevelInit blx r0 /* Initialize the postrelocate segment */ ldmfd sp!, {r0} ldr r1, =_spostrelocate ldr r2, =_epostrelocate 1: cmp r1, r2 ldrcc r3, [r0], #4 strcc r3, [r1], #4 bcc 1b /* Clear the zero segment */ ldr r0, =_szero ldr r1, =_ezero mov r2, #0 1: cmp r0, r1 strcc r2, [r0], #4 bcc 1b /* Setup stacks **************/ /* IRQ mode */ msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT ldr sp, =_sstack sub r4, sp, #IRQ_STACK_SIZE /* Supervisor mode (interrupts enabled) */ msr CPSR_c, #ARM_MODE_SVC | F_BIT mov sp, r4 /* Branch to main() ******************/ ldr r0, =main blx r0 /* Loop indefinitely when program is finished */ 1: b 1b
  9. PIT на AT91SAM9G45

    Я использую компилятор - arm-none-eabi-gcc. Может в директивах компилятора чего-то не хватает? Вот makefile: #------------------------------------------------------------------------------- # User-modifiable options #------------------------------------------------------------------------------- # Chip & board used for compilation # (can be overriden by adding CHIP=chip and BOARD=board to the command-line) CHIP = at91sam9g45 BOARD = at91sam9g45-ek # Trace level used for compilation # (can be overriden by adding TRACE_LEVEL=#number to the command-line) # TRACE_LEVEL_DEBUG 5 # TRACE_LEVEL_INFO 4 # TRACE_LEVEL_WARNING 3 # TRACE_LEVEL_ERROR 2 # TRACE_LEVEL_FATAL 1 # TRACE_LEVEL_NO_TRACE 0 TRACE_LEVEL = 4 # Optimization level, put in comment for debugging OPTIMIZATION = -Os # AT91 library directory AT91LIB = ../at91lib # External library EXT_LIBS= ../external_libs # Output file basename OUTPUT = basic-usart-serial-project-$(BOARD)-$(CHIP) # Compile with chip specific features include $(AT91LIB)/boards/$(BOARD)/$(CHIP)/chip.mak # Compile for all memories available on the board (this sets $(MEMORIES)) include $(AT91LIB)/boards/$(BOARD)/board.mak # Output directories BIN = bin OBJ = obj #------------------------------------------------------------------------------- # Tools #------------------------------------------------------------------------------- # Tool suffix when cross-compiling CROSS_COMPILE = arm-none-eabi- # Compilation tools CC = $(CROSS_COMPILE)gcc SIZE = $(CROSS_COMPILE)size STRIP = $(CROSS_COMPILE)strip OBJCOPY = $(CROSS_COMPILE)objcopy # Flags INCLUDES += -I$(AT91LIB)/boards/$(BOARD) INCLUDES += -I$(AT91LIB)/peripherals INCLUDES += -I$(AT91LIB)/components INCLUDES += -I$(AT91LIB) INCLUDES += -I$(EXT_LIBS)/cmsis ifeq ($(CHIP_CORE), cortexm3) TARGET_OPTS = -mcpu=cortex-m3 -mthumb else TARGET_OPTS = endif CFLAGS += $(TARGET_OPTS) CFLAGS += -Wall -mlong-calls -ffunction-sections CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) ASFLAGS = $(TARGET_OPTS) -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__ LDFLAGS = -g $(OPTIMIZATION) -nostartfiles $(TARGET_OPTS) -Wl,--gc-sections #------------------------------------------------------------------------------- # Files #------------------------------------------------------------------------------- # Directories where source files can be found PERIPH = $(AT91LIB)/peripherals BOARDS = $(AT91LIB)/boards UTILITY = $(AT91LIB)/utility VPATH += $(UTILITY) VPATH += $(PERIPH)/usart VPATH += $(PERIPH)/pio VPATH += $(PERIPH)/pit VPATH += $(PERIPH)/irq VPATH += $(PERIPH)/tc VPATH += $(PERIPH)/pmc VPATH += $(PERIPH)/cp15 VPATH += $(BOARDS)/$(BOARD) VPATH += $(BOARDS)/$(BOARD)/$(CHIP) VPATH += $(EXT_LIBS)/cmsis # Objects built from C source files C_OBJECTS += main.o C_OBJECTS += printf_usart.o C_OBJECTS += stdio.o C_OBJECTS += usart.o C_OBJECTS += pio.o C_OBJECTS += pio_it.o C_OBJECTS += tc.o C_OBJECTS += pmc.o C_OBJECTS += board_lowlevel.o C_OBJECTS += board_memories.o ifeq ($(CHIP_CORE), cortexm3) C_OBJECTS += nvic.o C_OBJECTS += exceptions.o C_OBJECTS += board_cstartup_gnu.o C_OBJECTS += core_cm3.o else C_OBJECTS += aic.o C_OBJECTS += cp15.o C_OBJECTS += pit.o endif # Objects built from Assembly source files ifneq ($(CHIP_CORE), cortexm3) ASM_OBJECTS += board_cstartup.o ASM_OBJECTS += cp15_asm_gcc.o endif # Append OBJ and BIN directories to output filename OUTPUT := $(BIN)/$(OUTPUT) #------------------------------------------------------------------------------- # Rules #------------------------------------------------------------------------------- all: $(BIN) $(OBJ) $(MEMORIES) $(BIN) $(OBJ): mkdir $@ define RULES C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS)) ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS)) $(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1)) $(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/[email protected]" -o $(OUTPUT)[email protected] $$^ $(OBJCOPY) -O binary $(OUTPUT)[email protected] $(OUTPUT)[email protected] $(SIZE) $$^ $(OUTPUT)[email protected] $$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN) $(CC) $(CFLAGS) -D$(1) -c -o $$@ $$< $$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN) $(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$< debug_$(1): $(1) perl ../resources/gdb/debug.pl $(OUTPUT)-$(1).elf endef $(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY)))) clean: -rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf
  10. PIT на AT91SAM9G45

    Добавил эту строчку в обработчик прерывания. Прерывания от PIT происходят, счетчик насчитывает как положено. Но кроме прерываний больше ничего не происходит, т.е. после прерывания не возвращается в исходную точку программы. Может нужно как-то восстанавливать регистры при выходе из прерывания?
  11. PIT на AT91SAM9G45

    Понадобилось организовать в программе функцию таймерной паузы. Решил попробовать сделать это на PITе (Periodic Interval Timer). Для этих целей взял с сайта atmel следующий пример кода: //------------------------------------------------------------------------------ /// Handler for PIT interrupt. Increments the timestamp counter. //------------------------------------------------------------------------------ void ISR_Pit(void) { unsigned int status; // Read the PIT status register status = PIT_GetStatus() & AT91C_PITC_PITS; if (status != 0) { // 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR. // Read the PIVR to acknowledge interrupt and get number of ticks //Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR. timestamp += (PIT_GetPIVR() >> 20); } } //------------------------------------------------------------------------------ /// Configure the periodic interval timer (PIT) to generate an interrupt every /// millisecond. //------------------------------------------------------------------------------ void ConfigurePit(void) { // Initialize the PIT to the desired frequency PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000); // Configure interrupt on PIT IRQ_DisableIT(AT91C_ID_SYS); IRQ_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit); IRQ_EnableIT(AT91C_ID_SYS); PIT_EnableIT(); // Enable the pit PIT_Enable(); } //------------------------------------------------------------------------------ /// Waits for the given number of milliseconds (using the timestamp generated /// by the SAM7 & SAM9 microcontrollers's PIT, or SAM3's microcontrollers's system tick). /// \param delay Delay to wait for, in milliseconds. //------------------------------------------------------------------------------ void Wait(unsigned long delay) { volatile unsigned int start = timestamp; unsigned int elapsed; do { elapsed = timestamp; elapsed -= start; } while (elapsed < delay); } Собственно здесь: ISR_Pit - обработчик прерывания, ConfigurePit - конфигурирование PIT и System Controller, Wait - процедура таймерной задержки. При выполнении данного кода, а точнее при выполнении процедуры IRQ_EnableIT(AT91C_ID_SYS), контроллер "виснет", т.е. постоянно уходит в прерывание (прерывания обрабатываются) и не выполняется дальнейший код. Пробовал запускать программу в режиме отладки через jtag emulator в sram, так же пробовал грузить и запускать через SAM-BA по jtag-у в sram. Где в данном случае подвох? Подскажите пожалуйста знающие люди.
×
×
  • Создать...