Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

SWI strenght occurance

Posted by Volovique on May 29, 2010
Hello all,

I want to run Freertos on my AT91Sam7S128 but I encounter a problem. For current moment I remove all freertos files and only want to invoke assembler line "asm volatile ("SWI 0") and after perform this line code my soft hang up. I add all assembler line come from eclipse

503 asm volatile ( "SWI 0" );
00100264: svc 0x00000000
00100268: b 0x100278

My Boot.S file has

.extern vPortYieldProcessor

//------------------------------------------------------------------------------
// 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

/* Exception vectors
*******************/
.section .vectors, "ax"

resetVector:
ldr pc, =resetHandler /* Reset */
undefVector:
b undefVector /* Undefined instruction */
swiVector:// This function was save and exits in flash memory (declaration and definition is in portISR.c
b vPortYieldProcessor
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

I suposed that this software work fine with arm-elf-gcc but I use arm-none-eabi-gcc come from code_sourcery.

Do anybody can help me ?

RE: SWI strenght occurance

Posted by Dave on May 31, 2010
How can you install vPortYieldProcessor in the vector table if you have removed the FreeRTOS files from your build?

RE: SWI strenght occurance

Posted by Volovique on May 31, 2010
Hello,

I change all my script, boot.s and makefile. For current moment I a little bit change original FreeRtos files form "ARM7_AT91SAM7X256_Eclipse" template. I remove from this project TCPIP stack and USB support. I also change in script file a memory section proper for AT91SAM7S128. A a little bit change directory setup in makefile to proper for eclipse ide. Now in main.c I apply pwm software without any freertos file (I comment it). Project compile well. After compilation I have a 3 output file in bin directory *.elf,*.bin,*.hex. When I upload firmware to microcontroller everything hung up. Obviously I try compile freertos function but without positive result. Below I listed 4 files boot.S, makefile, at91sam7s128.ld and main.c

1. makefile

#/*
# FreeRTOS V6.0.5 - Copyright (C) 2010 Real Time Engineers Ltd.
#
# ***************************************************************************
# * *
# * If you are: *
# * *
# * + New to FreeRTOS, *
# * + Wanting to learn FreeRTOS or multitasking in general quickly *
# * + Looking for basic training, *
# * + Wanting to improve your FreeRTOS skills and productivity *
# * *
# * then take a look at the FreeRTOS eBook *
# * *
# * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
# * http://www.FreeRTOS.org/Documentation *
# * *
# * A pdf reference manual is also available. Both are usually delivered *
# * to your inbox within 20 minutes to two hours when purchased between 8am *
# * and 8pm GMT (although please allow up to 24 hours in case of *
# * exceptional circumstances). Thank you for your support! *
# * *
# ***************************************************************************
#
# This file is part of the FreeRTOS distribution.
#
# FreeRTOS is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License (version 2) as published by the
# Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
# ***NOTE*** The exception to the GPL is included to allow you to distribute
# a combined work that includes FreeRTOS without being obliged to provide the
# source code for proprietary components outside of the FreeRTOS kernel.
# FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. You should have received a copy of the GNU General Public
# License and the FreeRTOS license exception along with FreeRTOS; if not it
# can be viewed here: http://www.freertos.org/a00114.html and also obtained
# by writing to Richard Barry, contact details for whom are available on the
# FreeRTOS WEB site.
#
# 1 tab == 4 spaces!
#
# http://www.FreeRTOS.org - Documentation, latest information, license and
# contact details.
#
# http://www.SafeRTOS.com - A version that is certified for use in safety
# critical systems.
#
# http://www.OpenRTOS.com - Commercial support, development, porting,
# licensing and training services.
#*/



CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
LDSCRIPT=./Ldscript/at91sam7s128.ld

LINKER_FLAGS=-mthumb -nostartfiles -Xlinker -o./bin/RTOSDemo.elf -Xlinker -M -Xlinker -Map=./bin/rtosdemo.map

DEBUG=-g
OPTIM=-O2


CFLAGS= $(DEBUG) \
$(OPTIM) \
-T$(LDSCRIPT) \
-I . \
-I ./Common/include \
-I ./Source/portable/GCC/ARM7_AT91SAM7S \
-I ./Source/include \
-I ./at91lib/boards/at91sam7se-ek/ \
-I ./at91lib/boards/at91sam7se-ek/at91sam7s128/ \
-I ./at91lib/peripherals \
-I ./at91lib/utility \
-D SAM7_GCC \
-D THUMB_INTERWORK \
-mcpu=arm7tdmi \
-D PACK_STRUCT_END=__attribute\(\(packed\)\) \
-D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) \
-fomit-frame-pointer \
-mthumb-interwork \
-fno-strict-aliasing \
-fno-dwarf2-cfi-asm

THUMB_SOURCE= \
main.c \
./ParTest/ParTest.c \
./Common/Minimal/BlockQ.c \
./Common/Minimal/blocktim.c \
./Common/Minimal/flash.c \
./Common/Minimal/integer.c \
./Common/Minimal/GenQTest.c \
./Common/Minimal/QPeek.c \
./Common/Minimal/dynamic.c \
./Source/list.c \
./Source/queue.c \
./Source/tasks.c \
./Source/portable/GCC/ARM7_AT91SAM7S/port.c \
./portable/MemMang/heap_2.c \
syscalls.c

ARM_SOURCE= \
./Source/portable/GCC/ARM7_AT91SAM7S/portISR.c \
./at91lib/boards/at91sam7se-ek/board_lowlevel.c \
./at91lib/boards/at91sam7se-ek/board_memories.c \
./at91lib/peripherals/pio/pio.c \
./at91lib/peripherals/pit/pit.c \
./at91lib/peripherals/pwmc/pwmc.c \
./at91lib/peripherals/aic/aic.c
#./SrcAtmel/Cstartup_SAM7.c \


THUMB_OBJS = $(THUMB_SOURCE:.c=.o)
ARM_OBJS = $(ARM_SOURCE:.c=.o)


all: RTOSDemo.bin

RTOSDemo.bin : RTOSDemo.hex
$(OBJCOPY) ./bin/RTOSDemo.elf -O binary ./bin/RTOSDemo.bin

RTOSDemo.hex : RTOSDemo.elf
$(OBJCOPY) ./bin/RTOSDemo.elf -O ihex ./bin/RTOSDemo.hex

RTOSDemo.elf : $(THUMB_OBJS) $(ARM_OBJS) ./at91lib/boards/at91sam7se-ek/boot.s Makefile
$(CC) $(CFLAGS) $(ARM_OBJS) $(THUMB_OBJS) $(LIBS) ./at91lib/boards/at91sam7se-ek/boot.s $(LINKER_FLAGS)

$(THUMB_OBJS) : %.o : %.c Makefile FreeRTOSConfig.h
$(CC) -c $(CFLAGS) -mthumb $< -o $@

$(ARM_OBJS) : %.o : %.c Makefile FreeRTOSConfig.h
$(CC) -c $(CFLAGS) $< -o $@

clean :
rm $(THUMB_OBJS)
rm $(ARM_OBJS)
touch Makefile
rm ./bin/RTOSDemo.elf
rm ./bin/RTOSDemo.hex


2. boot.S

/* Sample initialization file */

.extern main
.extern exit
.extern AT91F_LowLevelInit
.extern vPortYieldProcessor

.text
.code 32


.align 0

.extern __stack_end__
.extern __bss_beg__
.extern __bss_end__
.extern __data_beg__
.extern __data_end__
.extern __data+beg_src__

.global start
.global endless_loop

/* Stack Sizes */
.set UND_STACK_SIZE, 0x00000004
.set ABT_STACK_SIZE, 0x00000004
.set FIQ_STACK_SIZE, 0x00000004
.set IRQ_STACK_SIZE, 0X00000400
.set SVC_STACK_SIZE, 0x00000400

/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs */
.set MODE_USR, 0x10 /* User Mode */
.set MODE_FIQ, 0x11 /* FIQ Mode */
.set MODE_IRQ, 0x12 /* IRQ Mode */
.set MODE_SVC, 0x13 /* Supervisor Mode */
.set MODE_ABT, 0x17 /* Abort Mode */
.set MODE_UND, 0x1B /* Undefined Mode */
.set MODE_SYS, 0x1F /* System Mode */

.equ I_BIT, 0x80 /* when I bit is set, IRQ is disabled */
.equ F_BIT, 0x40 /* when F bit is set, FIQ is disabled */


start:
_start:
_mainCRTStartup:

/* Setup a stack for each mode - note that this only sets up a usable stack
for system/user, SWI and IRQ modes. Also each mode is setup with
interrupts initially disabled. */
ldr r0, .LC6
msr CPSR_c, #MODE_UND|I_BIT|F_BIT /* Undefined Instruction Mode */
mov sp, r0
sub r0, r0, #UND_STACK_SIZE
msr CPSR_c, #MODE_ABT|I_BIT|F_BIT /* Abort Mode */
mov sp, r0
sub r0, r0, #ABT_STACK_SIZE
msr CPSR_c, #MODE_FIQ|I_BIT|F_BIT /* FIQ Mode */
mov sp, r0
sub r0, r0, #FIQ_STACK_SIZE
msr CPSR_c, #MODE_IRQ|I_BIT|F_BIT /* IRQ Mode */
mov sp, r0
sub r0, r0, #IRQ_STACK_SIZE
msr CPSR_c, #MODE_SVC|I_BIT|F_BIT /* Supervisor Mode */
mov sp, r0
sub r0, r0, #SVC_STACK_SIZE
msr CPSR_c, #MODE_SYS|I_BIT|F_BIT /* System Mode */
mov sp, r0

/* We want to start in supervisor mode. Operation will switch to system
mode when the first task starts. */
msr CPSR_c, #MODE_SVC|I_BIT|F_BIT

blAT91F_LowLevelInit

/* Clear BSS. */

mov a2, #0/* Fill value */
movfp, a2/* Null frame pointer */
movr7, a2/* Null frame pointer for Thumb */

ldrr1, .LC1/* Start of memory block */
ldrr3, .LC2/* End of memory block */
subsr3, r3, r1 /* Length of block */
beq.end_clear_loop
movr2, #0

.clear_loop:
strbr2, [r1], #1
subsr3, r3, #1
bgt.clear_loop

.end_clear_loop:

/* Initialise data. */

ldrr1, .LC3/* Start of memory block */
ldrr2, .LC4/* End of memory block */
ldrr3, .LC5
subsr3, r3, r1/* Length of block */
beq.end_set_loop

.set_loop:
ldrbr4, [r2], #1
strbr4, [r1], #1
subsr3, r3, #1
bgt.set_loop

.end_set_loop:

movr0, #0 /* no arguments */
movr1, #0 /* no argv either */

ldr lr, =main
bxlr

endless_loop:
b endless_loop


.align 0

.LC1:
.word __bss_beg__
.LC2:
.word __bss_end__
.LC3:
.word __data_beg__
.LC4:
.word __data_beg_src__
.LC5:
.word __data_end__
.LC6:
.word __stack_end__


/* Setup vector table. Note that undf, pabt, dabt, fiq just execute
a null loop. */

.section .startup,"ax"
.code 32
.align 0

b _start/* reset - _start*/
ldr pc, _undf/* undefined - _undf*/
ldr pc, _swi/* SWI - _swi*/
ldr pc, _pabt/* program abort - _pabt*/
ldr pc, _dabt/* data abort - _dabt*/
nop/* reserved*/
ldr pc, [pc,#-0xF20]/* IRQ - read the AIC*/
ldr pc, _fiq/* FIQ - _fiq*/

_undf: .word __undf /* undefined*/
_swi: .word vPortYieldProcessor /* SWI*/
_pabt: .word __pabt /* program abort*/
_dabt: .word __dabt /* data abort*/
_fiq: .word __fiq /* FIQ*/

__undf: b . /* undefined*/
__pabt: b . /* program abort*/
__dabt: b . /* data abort*/
__fiq: b . /* FIQ*/


3. ld script


MEMORY
{
ram (W!RX) : ORIGIN = 0x200000, LENGTH = 0x8000
flash (RX) : ORIGIN = 0x100000, LENGTH = 0x20000
}

__stack_end__ = 0x00200000 + 0x8000 - 4;

SECTIONS
{
. = 0;
startup :
{
*(.startup)
} >flash

prog :
{
*(.text)
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
} >flash

__end_of_text__ = .;

.data :
{
__data_beg__ = .;
__data_beg_src__ = __end_of_text__;
*(.data)
__data_end__ = .;
} >ram AT>flash

.bss :
{
__bss_beg__ = .;
*(.bss)
} >ram

. = ALIGN(4);
.eh_frame :
{
KEEP (*(.eh_frame))
} > ram

/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections. */
. = ALIGN(32 / 8);
}
. = ALIGN(32 / 8);
_end = .;
_bss_end__ = . ; __bss_end__ = . ; __end__ = . ;
PROVIDE (end = .);


4. main section

/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/

//------------------------------------------------------------------------------
/// \dir "Basic PWM Project"
///
/// !!!Purpose
///
/// This example demonstrates a simple configuration of two PWM channels to generate
/// variable duty cycle signals. This will cause one or more LEDs the evaluation kit to
/// glow repeatedly.
///
/// !!!See
/// - pwmc: Pulse width modulation controller driver
///
/// !!!Requirements
///
/// This package can be used with all Atmel evaluation kits that have PWMC
/// interface, the package runs at SDRAM or SRAM.
///
/// !!!Description
///
/// Two PWM channels (channel #1 and channel #2) are configured to generate
/// a 100kHz PWM signal. On channel #1, the signal is configured as left-aligned.
/// On channel #2, the signal is center-aligned and the polarity is inverted.
///
/// On most Atmel evaluation kits, PWM signals for channels #1 and #2 are connected
/// to two LEDs on the board. Since the duty cycle of the PWM signals varies continuously,
/// the two LEDs will alternate between their minimum and maximum intensity. Note that
/// on some boards, only one LED will be connected.
///
/// !!!Usage
///
/// -# Build the program and download it inside the evaluation board. Please refer to the
///
/// SAM-BA User Guide
, the
///
/// GNU-Based Software Development
application note or to the
///
/// IAR EWARM User Guide
, depending on your chosen solution.
/// -# Optionally, on the computer, open the DBGU port with a terminal application
/// (e.g. HyperTerminal on Microsoft Windows) with these settings:
/// - 115200 bauds
/// - 8 bits of data
/// - No parity
/// - 1 stop bit
/// - No flow control
/// -# Start the application.
/// -# Depending on the board being used, either one or two LEDs will start glowing.
/// If two LEDs are glowing, their states will be inverted (since channel #2
/// uses a reversed polarity).
///
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// \unit
///
/// !Purpose
///
/// This file contains all the specific code for the basic-pwm-project
///
/// !Contents
/// The code can be roughly broken down as follows:
/// - Interrupt handler for the PWM controller
/// - The main function, which implements the program behavior
/// - Configure PWM clock
/// - Configure PWM channel #1 and channel #2 to generate a 100kHz PWM signal
/// - Enalbe PWM interrupt on channel #1
/// - Enable channel #1 and channel #2
///
/// Please refer to the list of functions in the #Overview# tab of this unit
/// for more detailed information.
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------

#include
#include
#include
#include
#include
#include
#include
#include


#include


/* Standard includes. */
#include

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"

/* Demo application includes. */
#include "partest.h"

#include "BlockQ.h"
#include "blocktim.h"
#include "flash.h"
#include "QPeek.h"
#include "dynamic.h"
#include "GenQTest.h"

//------------------------------------------------------------------------------
// Local definitions
//------------------------------------------------------------------------------

/// PWM frequency in Hz.
#define PWM_FREQUENCY 40000

/// Maximum duty cycle value.
#define MAX_DUTY_CYCLE 512


/// Delay for pushbutton debouncing (in milliseconds).
#define DEBOUNCE_TIME 500

/// PIT period value in useconds.
#define PIT_PERIOD 1000


/// Minimum duty cycle value (cannot be 0 or 1 for the SAM7S, c.f. errata)
#if defined(at91sam7s16) || defined(at91sam7s161) || defined(at91sam7s32) \
|| defined(at91sam7s321) || defined(at91sam7s64) || defined(at91sam7s128) \
|| defined(at91sam7s256) || defined(at91sam7s512) || defined(at91sam7a3)

#define MIN_DUTY_CYCLE 2
#else

#define MIN_DUTY_CYCLE 0
#endif



/* Priorities for the demo application tasks. */
#define mainBLOCK_Q_PRIORITY( tskIDLE_PRIORITY + 1 )
#define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainGEN_QUEUE_TASK_PRIORITY( tskIDLE_PRIORITY )


//------------------------------------------------------------------------------
// Local variables
//------------------------------------------------------------------------------

/// Pio pins to configure.
static const Pin pins[] = {
//xxxPINS_DBGU,
PIN_PWM_LED0,
PIN_PWM_LED1,
PIN_LED_1
};

/// Global timestamp in milliseconds since start of application.
volatile unsigned int timestamp = 0;


//------------------------------------------------------------------------------
// Local functions
//------------------------------------------------------------------------------



/*
//Deklaracja funkcji przerwania SWI
void SwiIntHandler(void) __attribute__ ((interrupt("SWI")));

//Funkcja przerwania SWI
void SwiIntHandler(void)
{
//Rejestr R14-1 zawiera adres instrukcji SWI
register unsigned int* link_ptr asm ("r14");
//Rejestr R0 zawiera parametr przekazany do SWI
register unsigned int param asm ("r0");
param &= 0xff;
param <<= 16;
switch(*(link_ptr-1) & 0x00FFFFFF)
{
//Zalacz Ledy
case 0x01:
//xxxLEDSET = param;
break;
//Wylacz Ledy
case 0x02:
//xxxLEDCLR = param;
break;
}
}
*/
















static void prvSetupHardware( void )
{
portDISABLE_INTERRUPTS();

/* When using the JTAG debugger the hardware is not always initialised to
the correct default state. This line just ensures that this does not
cause all interrupts to be masked at the start. */
AT91C_BASE_AIC->AIC_EOICR = 0;

/* Most setup is performed by the low level init function called from the
startup asm file. */

/* Enable the peripheral clock. */
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
//xxxAT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
/* Modified by M.Wolowik 26-05-2010 */
//xxxAT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;

/* Initialise the LED outputs for use by the demo application tasks. */
vParTestInitialise();
}
/*-----------------------------------------------------------*/






void vApplicationTickHook( void )
{
static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;

/* The rate at which LED D4 will toggle if an error has been found in one or
more of the standard demo tasks. */
const unsigned long ulErrorFlashRate = 500 / portTICK_RATE_MS;

/* The rate at which LED D4 will toggle if no errors have been found in any
of the standard demo tasks. */
const unsigned long ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;

ulCallCount++;

if( ulErrorFound != pdFALSE )
{
/* We have already found an error, so flash the LED with the appropriate
frequency. */
if( ulCallCount > ulErrorFlashRate )
{
ulCallCount = 0;
//xxxvParTestToggleLED( mainERROR_LED );
}
}
else
{
if( ulCallCount > ulNoErrorCheckRate )
{
ulCallCount = 0;

/* We have not yet found an error. Check all the demo tasks to ensure
this is still the case. */

if( xAreBlockingQueuesStillRunning() != pdTRUE )
{
ulErrorFound |= 0x01;
}

if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
{
ulErrorFound |= 0x02;
}

if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
{
ulErrorFound |= 0x04;
}

if( xAreGenericQueueTasksStillRunning() != pdTRUE )
{
ulErrorFound |= 0x08;
}

if( xAreQueuePeekTasksStillRunning() != pdTRUE )
{
ulErrorFound |= 0x10;
}

//xxxvParTestToggleLED( mainERROR_LED );
}
}
}







//------------------------------------------------------------------------------
/// Handler for PIT interrupt. Increments the timestamp counter.
//------------------------------------------------------------------------------
void ISR_Pit(void)
{
unsigned int status;
static char i = 0;

i ^= 1;


if(i != 0)
PIO_Clear(pins+2);
else
PIO_Set(pins+2);


// Read the PIT status register
status = PIT_GetStatus() & AT91C_PITC_PITS;
if (status != 0) {

// Read the PIVR to acknowledge interrupt and get number of ticks
timestamp += (PIT_GetPIVR() >> 20);
}
}




//------------------------------------------------------------------------------
/// Configure the periodic interval timer 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
AIC_DisableIT(AT91C_ID_SYS);
AIC_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit);
AIC_EnableIT(AT91C_ID_SYS);
PIT_EnableIT();

// Enable the pit
PIT_Enable();
}




//------------------------------------------------------------------------------
/// Wait time in ms
//------------------------------------------------------------------------------
void UTIL_Loop(volatile unsigned int loop)
{
while(loop--)
{
asm volatile ("nop");
}
}


void UTIL_WaitTimeInMs(unsigned int mck, unsigned int time_ms)
{
register unsigned int i = 0;
i = (mck / 1000) * time_ms;
i = i / 3;
UTIL_Loop(i);
}

//------------------------------------------------------------------------------
/// Wait time in us
//------------------------------------------------------------------------------
void UTIL_WaitTimeInUs(unsigned int mck, unsigned int time_us)
{
volatile unsigned int i = 0;
i = (mck / 1000000) * time_us;
i = i / 3;
UTIL_Loop(i);
}

//------------------------------------------------------------------------------
/// Interrupt handler for the PWM controller. Counts the number of periods and
/// updates the duty cycle after a given number.
//------------------------------------------------------------------------------
/*
static void ISR_Pwmc(void)
{

static unsigned int count = 0;
static unsigned int duty = MIN_DUTY_CYCLE;
static unsigned char fadeIn = 1;

// Interrupt on channel #1
if ((AT91C_BASE_PWMC->PWMC_ISR & AT91C_PWMC_CHID1) == AT91C_PWMC_CHID1) {

count++;

// Fade in/out
if (count == (PWM_FREQUENCY / (MAX_DUTY_CYCLE - MIN_DUTY_CYCLE))) {

// Fade in
if (fadeIn) {

duty++;
if (duty == MAX_DUTY_CYCLE) {

fadeIn = 0;
}
}
// Fade out
else {

duty--;
if (duty == MIN_DUTY_CYCLE) {

fadeIn = 1;
}
}

// Set new duty cycle
count = 0;
//xxxPWMC_SetDutyCycle(CHANNEL_PWM_LED0, duty);
//xxxPWMC_SetDutyCycle(CHANNEL_PWM_LED1, duty);
}
}

}
*/
//------------------------------------------------------------------------------
// Global functions
//------------------------------------------------------------------------------


/*

//Funkcja wlaczajaca LEDY poprzez SWI
static inline void SwiLedOn(unsigned int LedSt)
{
asm volatile
(
"mov r0,%[ledon]\n"
"swi #1\n"
::[ledon]"r"(LedSt):"r0"
);
}

//Funkcja wylaczajaca LEDY poprzez SWI
static inline void SwiLedOff(unsigned int LedSt)
{
asm volatile
(
"mov r0,%[ledon]\n"
"swi #2\n"
::[ledon]"r"(LedSt):"r0"
);
}

*/

//------------------------------------------------------------------------------
/// Outputs a PWM on LED1 & LED2 to makes it fade in and out.
//------------------------------------------------------------------------------
int main(void)
{

volatile unsigned int i = 0;
unsigned char fade_in_out = 1;

//xxxprvSetupHardware();

PIO_Configure(pins, PIO_LISTSIZE(pins));

//xxxConfigurePit();

// Enable PWMC peripheral clock
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PWMC;

// Settings:
// - 100kHz PWM period (PWM_FREQUENCY)
// - 1s rise/fall time for the LED intensity

// Set clock A to run at 100kHz * MAX_DUTY_CYCLE (clock B is not used)
PWMC_ConfigureClocks(PWM_FREQUENCY * MAX_DUTY_CYCLE, 0, BOARD_MCK);

// Configure PWMC channel for LED0 (left-aligned)
PWMC_ConfigureChannel(CHANNEL_PWM_LED0, AT91C_PWMC_CPRE_MCKA, 0, 0);
PWMC_SetPeriod(CHANNEL_PWM_LED0, MAX_DUTY_CYCLE);
PWMC_SetDutyCycle(CHANNEL_PWM_LED0, MIN_DUTY_CYCLE);

// Configure PWMC channel for LED1 (center-aligned, inverted polarity)
PWMC_ConfigureChannel(CHANNEL_PWM_LED1, AT91C_PWMC_CPRE_MCKA, AT91C_PWMC_CALG, AT91C_PWMC_CPOL);
PWMC_SetPeriod(CHANNEL_PWM_LED1, MAX_DUTY_CYCLE);
PWMC_SetDutyCycle(CHANNEL_PWM_LED1, MIN_DUTY_CYCLE);

// Configure interrupt on channel #1
//xxxAIC_ConfigureIT(AT91C_ID_PWMC, 0, ISR_Pwmc);
//xxxAIC_EnableIT(AT91C_ID_PWMC);
//xxxPWMC_EnableChannelIt(CHANNEL_PWM_LED0);



// Enable channel #1 and #2
PWMC_EnableChannel(CHANNEL_PWM_LED0);
PWMC_EnableChannel(CHANNEL_PWM_LED1);





/* Start the standard demo tasks. */
//xxxvStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
//xxxvCreateBlockTimeTasks();
//xxxvStartLEDFlashTasks( mainFLASH_PRIORITY );
//xxxvStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
//xxxvStartQueuePeekTasks();
//xxxvStartDynamicPriorityTasks();

/* Start the scheduler.

NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
The processor MUST be in supervisor mode when vTaskStartScheduler is
called. The demo applications included in the FreeRTOS.org download switch
to supervisor mode prior to main being called. If you are not using one of
these demo application projects then ensure Supervisor mode is used here. */

//xxxvTaskStartScheduler();
//xxxportYIELD_WITHIN_API();

//xxxasm volatile ( "SWI 0x10" );
//xxxSwiLedOn(0x93);

// Infinite loop
while (1)
{
//xxxPIO_Clear(pins+2);
UTIL_WaitTimeInUs(BOARD_MCK, 600);
//xxxPIO_Set(pins+2);
//xxxUTIL_WaitTimeInMs(BOARD_MCK, 1000);

PWMC_SetDutyCycle(CHANNEL_PWM_LED0, i); // Green Led
PWMC_SetDutyCycle(CHANNEL_PWM_LED1, i); // Yellow Led

if(fade_in_out != 0)
{
i++;
if(i == 511)
fade_in_out ^= 1;
}
else
{
i--;
if(i == 1)
fade_in_out ^= 1;
}

/*
if(fade_in_out != 0)
PIO_Set(pins+2);
else
PIO_Clear(pins+2);
*/
}
}



And startupt C routine

/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
* ----------------------------------------------------------------------------
*/

//------------------------------------------------------------------------------
/// \unit
///
/// !Purpose
///
/// Provides the low-level initialization function that gets called on chip
/// startup.
///
/// !Usage
///
/// LowLevelInit() is called in #board_cstartup.S#.
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------

#include "board.h"
#include "board_memories.h"
#include

//------------------------------------------------------------------------------
// Internal definitions
//------------------------------------------------------------------------------
// Startup time of main oscillator (in number of slow clock ticks).
#define BOARD_OSCOUNT (AT91C_CKGR_OSCOUNT & (0x40 << 8))

// USB PLL divisor value to obtain a 48MHz clock.
#define BOARD_USBDIV AT91C_CKGR_USBDIV_1

// PLL frequency range.
#define BOARD_CKGR_PLL AT91C_CKGR_OUT_0

// PLL startup time (in number of slow clock ticks).
#define BOARD_PLLCOUNT (16 << 8)

// PLL MUL value.
#define BOARD_MUL (AT91C_CKGR_MUL & (72 << 16))

// PLL DIV value.
#define BOARD_DIV (AT91C_CKGR_DIV & 14)

// Master clock prescaler value.
#define BOARD_PRESCALER AT91C_PMC_PRES_CLK_2

//------------------------------------------------------------------------------
// Internal functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// 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);
}


//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Performs the low-level initialization of the chip. This includes EFC, master
/// clock, AIC & watchdog configuration, as well as memory remapping.
//------------------------------------------------------------------------------
void AT91F_LowLevelInit( void )
{
unsigned char i;

BOARD_ConfigureFlash48MHz();

//#if !defined(sdram)
/* Initialize main oscillator
****************************/
AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));

/* Initialize PLL at 96MHz (96.109) and USB clock to 48MHz */
AT91C_BASE_PMC->PMC_PLLR = BOARD_USBDIV | BOARD_CKGR_PLL | BOARD_PLLCOUNT
| BOARD_MUL | BOARD_DIV;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK));

/* Wait for the master clock if it was already initialized */
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

/* Switch to fast clock
**********************/
/* Switch to slow clock + prescaler */
AT91C_BASE_PMC->PMC_MCKR = BOARD_PRESCALER;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

/* Switch to fast clock + prescaler */
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
//#endif //#if !defined(sdram)

/* Initialize AIC
****************/
AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) defaultFiqHandler;
for (i = 1; i < 31; i++) {

AT91C_BASE_AIC->AIC_SVR = (unsigned int) defaultIrqHandler;
}
AT91C_BASE_AIC->AIC_SPU = (unsigned int) defaultSpuriousHandler;

// Unstack nested interrupts
for (i = 0; i < 8 ; i++) {

AT91C_BASE_AIC->AIC_EOICR = 0;
}

// Enable Debug mode
AT91C_BASE_AIC->AIC_DCR = AT91C_AIC_DCR_PROT;

/* Watchdog initialization
*************************/
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;

/* Remap
*******/
BOARD_RemapRam();

// Disable RTT and PIT interrupts (potential problem when program A
// configures RTT, then program B wants to use PIT only, interrupts
// from the RTT will still occur since they both use AT91C_ID_SYS)
AT91C_BASE_RTTC->RTTC_RTMR &= ~(AT91C_RTTC_ALMIEN | AT91C_RTTC_RTTINCIEN);
AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
}









RE: SWI strenght occurance

Posted by Volovique on May 31, 2010
Problem resolve.

Due to At91SAM7S128 have a diferent AT91_Lowlevel that AT91Sam7S256 used in FreeRtos template. The problem was minor because I toke this At91_Lowlevel form one of template of Atmel site.

Solve:

remove from code

/* Remap *******/ BOARD_RemapRam();

because in *.S vector is in flash and again remap to ram made error occurance destory internal ram structure.

for this moment Freertos work very well I'm satisfied.

If anyone have a in future a similar problem please ask me or take this file which I shared in this poste obviously remove this BOARD_RemapRam(); !!!! .

This subject in my opinion shall be colsed due resolve problem.

Thx and best regards for all participant.
Volovique.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner