Implementaremos el sistema operativo en tiempo real FreeRTOS el MCU R5F562N8 de la tarjeta de evaluación YRDKRX62N. Utilizaremos los leds de la tarjeta para la manifestación de diversas tareas en ejecución.
- Configuraremos stack FreeRTOS
- Ampliaremos la memoria del stack del MCU
- Crearemos algunas tareas de demostración
DESARROLLO:
- Del documento Renesas RX62N RDK User's Manual ubicamos los leds 6, 8, 10 y 14.
PASOS:
- Creación de un proyecto:
2.- New/ C Project / Renesas RXC ToolChain
3.- Seleccionar el target R5F562N8, debug hardware Segger jLink, después next
4.- Seleccionar C/C++ Source file y por ultimo Finish.
5.- Cambiar el valor del stack del archivo sbrk.h:
/* size of area managed by sbrk
*/
#define HEAPSIZE
0xD000
6.- Configurar el archivo de arranque hardware_setup.c:
#include <stdint.h>
#include "iodefine.h"
#include "FreeRTOS/FreeRTOS.h"
void io_set_cpg(void);
void ConfigurePortPins(void);
void EnablePeripheralModules(void);
void HardwareSetup(void)
{
/* CPG setting */
io_set_cpg();
/* Enables peripherals */
EnablePeripheralModules();
}
void EnablePeripheralModules(void)
{
/*
Module standby clear */
/* SYSTEM.MSTPCRB.BIT.MSTPB15 = 0; */ /* EtherC, EDMAC */
SYSTEM.MSTPCRA.BIT.MSTPA15 = 0; /* CMT0 動作可*/
}
void io_set_cpg(void)
{
/* Set CPU PLL operating frequencies.
Changes to the peripheral clock will require
changes to the debugger and flash kernel
BRR settings. */
/* ==== CPG setting ==== */
/*SYSTEM.SCKCR.LONG = 0x00020100;*/ /* Clockin = 12MHz */
/* I Clock = 96MHz, B Clock = 24MHz, */
/* P Clock = 48MHz */
SYSTEM.SCKCR.BIT.ICK = 0x00; // x16 96MHz
SYSTEM.SCKCR.BIT.PCK = 0x01; // x4 48MHz
SYSTEM.SCKCR.BIT.BCK = 0x01; // x4 48MHz
}
/* This variable is not used by this
simple Blinky example. It is
defined
purely to allow the project to link as
it is used by the full build
configuration. */
volatile unsigned long ulHighFrequencyTickCount = 0UL;
void vApplicationSetupTimerInterrupt( void )
{
/* Enable compare match timer 0. */
MSTP(
CMT0 ) = 0;
/* Interrupt on compare match. */
CMT0.CMCR.BIT.CMIE = 1;
/* Set the compare match value. */
CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ /
configTICK_RATE_HZ ) -1 ) / 8 );
/* Divide the PCLK by 8. */
CMT0.CMCR.BIT.CKS = 0;
/* Enable the interrupt... */
_IEN(
_CMT0_CMI0 ) = 1;
/* ...and set its priority to the
application defined kernel priority. */
_IPR(
_CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
/* Start the timer. */
CMT.CMSTR0.BIT.STR0 = 1;
}
// ICU SWINT
//#pragma interrupt
(Excep_ICU_SWINT(vect=27))
//void Excep_ICU_SWINT(void);
// CMT0 CMI0
//#pragma interrupt
(Excep_CMT0_CMI0(vect=28))
//void
Excep_CMT0_CMI0(void);
#include <stdio.h>
#include "iodefine.h"
/* Kernel includes. */
#include "FreeRTOS/FreeRTOS.h"
#include "FreeRTOS/task.h"
#include "FreeRTOS/queue.h"
/* Priorities at which the tasks are
created. */
#define configQUEUE_TASK_1_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define configQUEUE_TASK_2_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define configQUEUE_TASK_3_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define configQUEUE_TASK_4_PRIORITY ( tskIDLE_PRIORITY + 4 )
void vTask1(void *pvParameters)
{
while(1) {
PORTD.DR.BIT.B1 = ~PORTD.DR.BIT.B1;
vTaskDelay(100/portTICK_PERIOD_MS);
}
}
void vTask2(void *pvParameters)
{
while(1) {
PORTD.DR.BIT.B2 = ~PORTD.DR.BIT.B2;
vTaskDelay(200/portTICK_PERIOD_MS);
}
}
void vTask3(void *pvParameters)
{
while(1) {
PORTD.DR.BIT.B3 = ~PORTD.DR.BIT.B3;
vTaskDelay(300/portTICK_PERIOD_MS);
}
}
void vTask4(void *pvParameters)
{
while(1) {
PORTD.DR.BIT.B0 = ~PORTD.DR.BIT.B0;
vTaskDelay(400/portTICK_PERIOD_MS);
}
}
void main(void)
{
/* Renesas provided CPU
configuration routine. The clocks are
configured in
here.
*/
/* Turn all LEDs off. */
PORTD.DDR.BYTE = 0xFF;
PORTD.DR.BYTE = 0xFF;
xTaskCreate(vTask1,"Task1",configMINIMAL_STACK_SIZE,NULL,configQUEUE_TASK_1_PRIORITY,NULL);
xTaskCreate(vTask2,"Task2",configMINIMAL_STACK_SIZE,NULL,configQUEUE_TASK_2_PRIORITY,NULL);
xTaskCreate(vTask3,"Task3",configMINIMAL_STACK_SIZE,NULL,configQUEUE_TASK_3_PRIORITY,NULL);
xTaskCreate(vTask4,"Task4",configMINIMAL_STACK_SIZE,NULL,configQUEUE_TASK_4_PRIORITY,NULL);
/* Create the queue. */
vTaskStartScheduler();
/* If all is well the next line of code
will not be reached as the scheduler
will
be running. If the next line is reached then it is likely
that there was
insufficient
heap available for the idle task to be created. */
for( ;; );
}
- Agregar código, compilar y debug:
--> Practica 18
2.- Compilar con el icono del martillo y debug con el icono del insecto:
VÍDEO:
No hay comentarios.:
Publicar un comentario