robototechnik wrote on Wednesday, February 06, 2013:
Ok ive read all you have wrote, now i have more questions as at the beginning=)
1) I have added void vApplicationMallocFailedHook (void) task to my main code, i dont know if it works. What will show me this task? When will it work?
2) When i am adding this line to the config file, there are some warnings and errors by compiling, so the code doesnt compiles. Why does it happen and wherefor do i need this line? How can I use it?
3) I have some problems with tasks again…=( The RAM of my ATmega32 is 2K, so as i understand the max HEAP Size can be 2K*1024 so 2048 byte? I added some more tasks and now I am trying to run 7 at the ame time. Of course it doesn work. I have counted this way: i have maximum HEAP SIZE of 2048 bytes so 2048/7tasks=295,6bytes for each of tasks? It doesnt work!=(
4) I didnt undestand how can I use the function uxTaskGetStackHighWaterMark (taskHandle). What will this give me and what can I do with this?
Here are all the changes I have made in config file and in main.c
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <avr/io.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 16000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 290 )
#define configTOTAL_HEAP_SIZE ( (size_t ) ( 2048 ) )
#define configMAX_TASK_NAME_LEN ( 10 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1
#define configQUEUE_REGISTRY_SIZE 1
#define configUSE_MALLOC_FAILED_HOOK 1 //new added
#define INCLUDE_uxTaskGetStackHighWaterMark 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 1
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#endif /* FREERTOS_CONFIG_H */
and the main.c
#include "FreeRTOS.h"
#include "task.h"
#include <avr/io.h>
#include <avr/interrupt.h>
ISR (TIMER0_COMP_vect)
{
PORTB &= ~(1<<PB3); //clear output
}
ISR (TIMER0_OVF_vect)
{
PORTB |= (1<<PB3); //set output
}
ISR (TIMER2_COMP_vect)
{
PORTD &= ~(1<<PD7); //clear output
}
ISR (TIMER2_OVF_vect)
{
PORTD |= (1<<PD7); //set output
}
///////////////////////////////////////////////////////////////////////////////////////
void vApplicationMallocFailedHook (void)
{
for (;;)
{
PORTC ^= (1 << PC1);
}
}
//////////////////////////////////////////////////////////////////////////////////////
void vServo1( void *pvParameters )
{
for (;;)
{
OCR0 = 35;
vTaskDelay( 500 / portTICK_RATE_MS);
OCR0 = 22;
vTaskDelay( 500 / portTICK_RATE_MS);
OCR0 = 10;
vTaskDelay( 500 / portTICK_RATE_MS);
}
}
/////////////////////////////////////////////////////////////////////////////////////
void vServo2( void *pvParameters )
{
for (;;)
{
OCR2 = 35;
vTaskDelay( 500 / portTICK_RATE_MS);
OCR2 = 22;
vTaskDelay( 500 / portTICK_RATE_MS);
OCR2 = 10;
vTaskDelay( 500 / portTICK_RATE_MS);
}
}
/////////////////////////////////////////////////////////////////////////////////////
void vMotor1( void *pvParameters )
{
PORTC |= _BV(PC2);
PORTC &= ~_BV(PC3);
PORTC &= ~_BV(PC4);
for (;;)
{
PORTC |= _BV(PC3);
vTaskDelay( 1000 / portTICK_RATE_MS);
PORTC &= ~_BV(PC3);
vTaskDelay(1000 / portTICK_RATE_MS);
PORTC |= _BV(PC4);
vTaskDelay( 1000 / portTICK_RATE_MS);
PORTC &= ~_BV(PC4);
vTaskDelay( 1000 / portTICK_RATE_MS);
}
}
////////////////////////////////////////////////////////////////////////////////////////
void vMotor2( void *pvParameters )
{
PORTC |= _BV(PC6);
PORTC &= ~_BV(PC5);
PORTC &= ~_BV(PC7);
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount;
for (;;)
{
PORTC |= _BV(PC5);
vTaskDelayUntil(&xLastWakeTime, 500 / portTICK_RATE_MS);
PORTC &= ~_BV(PC5);
vTaskDelayUntil(&xLastWakeTime, 500 / portTICK_RATE_MS);
PORTC |= _BV(PC7);
vTaskDelayUntil(&xLastWakeTime, 500 / portTICK_RATE_MS);
PORTC &= ~_BV(PC7);
vTaskDelayUntil(&xLastWakeTime, 500 / portTICK_RATE_MS);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void vRedLED( void *pvParameters )
{
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount;
for (;;)
{
PORTC ^= (1 << PC1);
vTaskDelayUntil(&xLastWakeTime, 200 / portTICK_RATE_MS);
}
}
///////////////////////////////////////////////////////////////////////////////////////
void vGreenLED( void *pvParameters )
{
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount;
for (;;)
{
PORTC ^= (1 << PC0);
vTaskDelayUntil(&xLastWakeTime, 100 / portTICK_RATE_MS);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
void vBeep( void *pvParameters )
{
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount;
for (;;)
{
PORTB ^= (1 << PB4);
vTaskDelayUntil(&xLastWakeTime, 100 / portTICK_RATE_MS);
}
}
//////////////////////////////////////////////////////////////////////////////////////
int main( void )
{
DDRB = 0b00011000;
DDRC = 0b11111111;
DDRD = 0b10000000;
TCCR0 = (1<<WGM00)|(1<<WGM01)|(1<<CS02)|(1<<CS00)|(1<<COM01); //fast pwm,TOP=0xff presc 1024
TIMSK = (1<<OCIE0)|(1<<TOIE0); //Enable interrupts
TCCR2 = (1<<WGM20)|(1<<WGM21)|(1<<CS22)|(1<<CS21)|(1<<CS20)|(1<<COM21); //fast pwm,TOP=0xff presc 1024
TIMSK = (1<<OCIE2)|(1<<TOIE2); //Enable interrupts
ICR1 = 160; //period 20 ms
sei(); //set global interrupt bit
xTaskCreate( vServo1,
(signed char * ) "Servo1",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
xTaskCreate( vServo2,
(signed char * ) "Servo2",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
xTaskCreate( vMotor1,
(signed char *) "Motor1",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
xTaskCreate( vMotor2,
(signed char *) "Motor2",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
xTaskCreate( vRedLED,
(signed char *) "RedLED",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
xTaskCreate( vGreenLED,
(signed char * ) "GreenLED",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
xTaskCreate( vBeep,
(signed char * ) "Beep",
configMINIMAL_STACK_SIZE,
NULL,
1,
NULL );
vTaskStartScheduler();
return 0;
}
Excuse me please for huge amount of questions, I am 15 and C with FreeRTOS is something new for me=)
I will be very grateful for your answer=)
Regards.