- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
@@ -0,0 +1,442 @@
|
||||
/* Application_task
|
||||
*
|
||||
* This routine is as an example of an application task which
|
||||
* prints a message including its RTEMS task id. This task
|
||||
* then invokes exit to return to the monitor.
|
||||
*
|
||||
* Input parameters: NONE
|
||||
*
|
||||
* Output parameters: NONE
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id: apptask.c,v 1.12 2003/09/04 18:53:41 joel Exp $
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
rtems_isr user_isr(rtems_vector_number vector)
|
||||
{
|
||||
volatile uint32_t *pReg = (uint32_t*)J3K_GPIO_0_BASE;
|
||||
rtems_interrupt_level level = 1;
|
||||
|
||||
/* rtems_interrupt_disable(level);*/
|
||||
printk("Interrupt %d\n", vector);
|
||||
while(*pReg);
|
||||
|
||||
/* rtems_interrupt_enable(level);*/
|
||||
}
|
||||
|
||||
#define PI_SCALE 10000
|
||||
#define PI_MAXARR 2800
|
||||
#define PI_ARRINIT 2000
|
||||
int Test15_pi_calc()
|
||||
{
|
||||
int i, j, k;
|
||||
int carry = 0;
|
||||
int arr[PI_MAXARR+1];
|
||||
uint32_t int_part, result;
|
||||
uint16_t pi_res[200] = {0};
|
||||
uint16_t pi_ref[200] =
|
||||
{
|
||||
3141,5926,5358,9793,2384,6264,3383,2795, 288,4197,1693,9937,5105,8209,7494,4592,3078,1640,6286,2089,9862,8034,8253,4211,
|
||||
7067,9821,4808,6513,2823, 664,7093,8446, 955, 582,2317,2535,9408,1284,8111,7450,2841, 270,1938,5211, 555,9644,6229,4895,
|
||||
4930,3819,6442,8810,9756,6593,3446,1284,7564,8233,7867,8316,5271,2019, 914,5648,5669,2346, 348,6104,5432,6648,2133,9360,
|
||||
7260,2491,4127,3724,5870, 660,6315,5881,7488,1520,9209,6282,9254, 917,1536,4367,8925,9036, 11,3305,3054,8820,4665,2138,
|
||||
4146,9519,4151,1609,4330,5727, 365,7595,9195,3092,1861,1738,1932,6117,9310,5118,5480,7446,2379,9627,4956,7351,8857,5272,
|
||||
4891,2279,3818,3011,9491,2983,3673,3624,4065,6643, 860,2139,4946,3952,2473,7190,7021,7986, 943,7027,7053,9217,1762,9317,
|
||||
6752,3846,7481,8467,6694, 513,2000,5681,2714,5263,5608,2778,5771,3427,5778,9609,1736,3717,8721,4684,4090,1224,9534,3014,
|
||||
6549,5853,7105, 792,2796,8925,8923,5420,1995,6112,1290,2196, 864, 344,1815,9813,6297,7477,1309,9605,1870,7211,3499,9999,
|
||||
8372,9780,4995,1059,7317,3281,6096,3185
|
||||
};
|
||||
|
||||
// setbuf(stdout, NULL);
|
||||
k = 0;
|
||||
for (i = 0; i <= PI_MAXARR; ++i)
|
||||
arr[i] = PI_ARRINIT;
|
||||
|
||||
for (i = PI_MAXARR; i; i -= 14)
|
||||
{
|
||||
int sum = 0;
|
||||
for (j = i; j > 0; --j)
|
||||
{
|
||||
sum = sum*j + PI_SCALE*arr[j];
|
||||
arr[j] = sum % (j*2-1);
|
||||
sum /= (j*2-1);
|
||||
}
|
||||
result = carry + sum/PI_SCALE;
|
||||
int_part = PI_SCALE * (result / PI_SCALE);
|
||||
pi_res[k] = (uint16_t)(result - int_part);
|
||||
carry = sum % PI_SCALE;
|
||||
k++;
|
||||
}
|
||||
|
||||
for (k=0; k < sizeof(pi_ref)/sizeof(uint16_t); k++)
|
||||
{
|
||||
printf("%d", pi_res[k]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if(memcmp(pi_res, pi_ref, sizeof(pi_ref)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define TEST_SIZE (16*1024*1024) // Bytes
|
||||
#define SMALL_TEST_SIZE (8192) // Bytes
|
||||
uint32_t clock_us(void)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
rtems_clock_time_value val;
|
||||
|
||||
sc = rtems_clock_get(RTEMS_CLOCK_GET_TIME_VALUE, &val);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
fprintf(stderr, "rtems_clock_get(): Error %08X\n", sc);
|
||||
|
||||
return 1000000*val.seconds + val.microseconds;
|
||||
}
|
||||
|
||||
void mem_test(void)
|
||||
{
|
||||
int result, i, j, cnt, size;
|
||||
uint32_t start, end;
|
||||
FILE *pFile;
|
||||
|
||||
uint8_t *ram8 = NULL;
|
||||
uint16_t *ram16 = NULL;
|
||||
uint32_t *ram32 = NULL;
|
||||
|
||||
uint32_t *pSrc32, *pDst32;
|
||||
|
||||
pFile = fopen("/dev/psaux0", "w+");
|
||||
if (!pFile)
|
||||
{
|
||||
fprintf(stderr, "Error opening /dev/ttyS0\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Memtest BEGIN
|
||||
fprintf(pFile, "SDRAM Memory Test\n");
|
||||
fprintf(pFile, "Test size %d kByte\n\n", TEST_SIZE/1024);
|
||||
|
||||
ram8 = (uint8_t*)calloc(TEST_SIZE,sizeof(uint8_t));
|
||||
fprintf(pFile, "Zeroize Memory (memset)...");
|
||||
start = clock_us();
|
||||
memset(ram8, 0, TEST_SIZE);
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
free(ram8);
|
||||
|
||||
ram8 = (uint8_t*)calloc(TEST_SIZE,sizeof(uint8_t));
|
||||
fprintf(pFile, "Zeroize Memory (8-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=0; i < TEST_SIZE; i++)
|
||||
ram8[i] = (uint8_t)0;
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
free(ram8);
|
||||
|
||||
ram16 = (uint16_t*)calloc(TEST_SIZE/2,sizeof(uint16_t));
|
||||
fprintf(pFile, "Zeroize Memory (16-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=0; i < TEST_SIZE/2; i++)
|
||||
ram16[i] = (uint16_t)0;
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
free(ram16);
|
||||
|
||||
ram32 = (uint32_t*)calloc(TEST_SIZE/4,sizeof(uint32_t));
|
||||
fprintf(pFile, "Zeroize Memory (32-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=0; i < TEST_SIZE/4; i++)
|
||||
ram32[i] = (uint32_t)0;
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
free(ram32);
|
||||
|
||||
ram8 = (uint8_t*)calloc(TEST_SIZE,sizeof(uint8_t));
|
||||
fprintf(pFile, "Write (8-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=0; i < TEST_SIZE; i++)
|
||||
ram8[i] = (uint8_t)i;
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
fprintf(pFile, "Verify (8-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=TEST_SIZE-1; i >= 0; i--)
|
||||
if (ram8[i] != (uint8_t)i)
|
||||
break;
|
||||
|
||||
end = clock_us();
|
||||
i++;
|
||||
if (i)
|
||||
fprintf(pFile, "failed\r\n");
|
||||
else
|
||||
fprintf(pFile, "passed (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
free(ram8);
|
||||
|
||||
ram16 = (uint16_t*)calloc(TEST_SIZE/2,sizeof(uint16_t));
|
||||
fprintf(pFile, "Write (16-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=0; i < TEST_SIZE/2; i++)
|
||||
ram16[i] = (uint16_t)i;
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
fprintf(pFile, "Verify (16-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=TEST_SIZE/2-1; i >= 0; i--)
|
||||
if (ram16[i] != (uint16_t)i)
|
||||
break;
|
||||
|
||||
end = clock_us();
|
||||
i++;
|
||||
if (i)
|
||||
fprintf(pFile, "failed\r\n");
|
||||
else
|
||||
fprintf(pFile, "passed (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
|
||||
free(ram16);
|
||||
|
||||
ram32 = (uint32_t*)calloc(TEST_SIZE/4,sizeof(uint32_t));
|
||||
fprintf(pFile, "Write (32-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=0; i < TEST_SIZE/4; i++)
|
||||
{
|
||||
ram32[i] = (uint32_t)i;
|
||||
}
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
fprintf(pFile, "Verify (32-Bit access)...");
|
||||
start = clock_us();
|
||||
for (i=TEST_SIZE/4-1; i >= 0; i--)
|
||||
{
|
||||
if (ram32[i] != (uint32_t)i)
|
||||
break;
|
||||
}
|
||||
|
||||
end = clock_us();
|
||||
i++;
|
||||
if (i)
|
||||
fprintf(pFile, "failed\r\n");
|
||||
else
|
||||
fprintf(pFile, "passed (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
free(ram32);
|
||||
|
||||
fprintf(pFile, "Memcpy() Test \n");
|
||||
pSrc32 = (uint32_t*)calloc(TEST_SIZE/8,sizeof(uint32_t));
|
||||
pDst32 = (uint32_t*)calloc(TEST_SIZE/8,sizeof(uint32_t));
|
||||
fprintf(pFile, "Copying %d kBytes...", TEST_SIZE/(2*1024));
|
||||
start = clock_us();
|
||||
memcpy(pDst32, pSrc32, TEST_SIZE/2);
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(2*(end-start)));
|
||||
|
||||
free(pSrc32);
|
||||
free(pDst32);
|
||||
|
||||
fprintf(pFile, "Memmove() Test \n");
|
||||
pSrc32 = (uint32_t*)calloc(TEST_SIZE/8,sizeof(uint32_t));
|
||||
pDst32 = (uint32_t*)calloc(TEST_SIZE/8,sizeof(uint32_t));
|
||||
fprintf(pFile, "Moving %d kBytes...", TEST_SIZE/(2*1024));
|
||||
start = clock_us();
|
||||
memmove(pDst32, pSrc32, TEST_SIZE/2);
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(2*(end-start)));
|
||||
|
||||
free(pSrc32);
|
||||
free(pDst32);
|
||||
|
||||
fprintf(pFile, "Small data test\r\n");
|
||||
fprintf(pFile, "Test size %d kByte\n\n", SMALL_TEST_SIZE/1024);
|
||||
fprintf(pFile, "Write (32-Bit access)...");
|
||||
ram32 = (uint32_t*)calloc(SMALL_TEST_SIZE/4,sizeof(uint32_t));
|
||||
start = clock_us();
|
||||
for (j=0; j < TEST_SIZE/SMALL_TEST_SIZE; j++)
|
||||
for (i=0; i < SMALL_TEST_SIZE/4; i++)
|
||||
ram32[i] = (uint32_t)i;
|
||||
|
||||
end = clock_us();
|
||||
fprintf(pFile, "done (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Verify
|
||||
fprintf(pFile, "Verify (32-Bit access)...");
|
||||
start = clock_us();
|
||||
for (j=0; j < TEST_SIZE/SMALL_TEST_SIZE; j++)
|
||||
for (i=SMALL_TEST_SIZE/4-1; i >= 0; i--)
|
||||
if (ram32[i] != (uint32_t)i)
|
||||
break;
|
||||
|
||||
end = clock_us();
|
||||
i++;
|
||||
if (i)
|
||||
fprintf(pFile, "failed\r\n");
|
||||
else
|
||||
fprintf(pFile, "passed (%.2f MByte/s)\n", (double)TEST_SIZE/(end-start));
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
free(ram32);
|
||||
|
||||
fprintf(pFile, "Boot code read \n");
|
||||
size = 0x2000;
|
||||
pSrc32 = (uint32_t*)0xBFC00000;
|
||||
pDst32 = (uint32_t*)calloc(size,sizeof(uint32_t));
|
||||
memcpy(pDst32, pSrc32, size);
|
||||
fprintf(pFile, "Verify Boot code...");
|
||||
for (i=size/4-1; i >= 0; i--)
|
||||
if (pDst32[i] != pSrc32[i])
|
||||
break;
|
||||
i++;
|
||||
if (i)
|
||||
fprintf(pFile, "failed\r\n");
|
||||
else
|
||||
fprintf(pFile, "passed\r\n");
|
||||
|
||||
free(pDst32);
|
||||
|
||||
fclose(pFile);
|
||||
|
||||
// Memtest END
|
||||
// ----------------------------------------------------------
|
||||
}
|
||||
|
||||
extern void PrintConsoleInfo(int minor);
|
||||
rtems_task Application_task1(rtems_task_argument argument)
|
||||
{
|
||||
rtems_id tid;
|
||||
rtems_status_code status;
|
||||
rtems_time_of_day time;
|
||||
int lastmin = 0;
|
||||
status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
|
||||
|
||||
printf( "Application task was invoked with argument (%d) "
|
||||
"and has id of 0x%x\n", argument, tid );
|
||||
|
||||
rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
|
||||
lastmin = time.minute;
|
||||
while(1)
|
||||
{
|
||||
Test15_pi_calc();
|
||||
rtems_cpu_usage_report_with_plugin(stdout, (rtems_printk_plugin_t)fprintf);
|
||||
rtems_stack_checker_report_usage_with_plugin(stdout, (rtems_printk_plugin_t)fprintf);
|
||||
rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
|
||||
printf( "%02d:%02d:%02d %02d/%02d/%04d\n", time.hour, time.minute, time.second, time.month, time.day, time.year);
|
||||
if (((lastmin) <= time.minute) || !time.minute)
|
||||
{
|
||||
status = rtems_task_ident(rtems_build_name( 'L', 'I', 'F', 'E' ), RTEMS_SEARCH_ALL_NODES, &tid);
|
||||
if (status == RTEMS_SUCCESSFUL)
|
||||
{
|
||||
if (RTEMS_ALREADY_SUSPENDED == rtems_task_is_suspended(tid))
|
||||
{
|
||||
printf("Trying to restart task 0x%08x..", tid);
|
||||
status = rtems_task_restart(tid, 0);
|
||||
if (status == RTEMS_SUCCESSFUL)
|
||||
printf("success\n");
|
||||
else
|
||||
printf("failed\n");
|
||||
|
||||
lastmin = (time.minute + 5) % 60;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Trying to suspend task 0x%08x..", tid);
|
||||
status = rtems_task_suspend(tid);
|
||||
if (status == RTEMS_SUCCESSFUL)
|
||||
printf("success\n");
|
||||
else
|
||||
printf("failed\n");
|
||||
|
||||
lastmin = (time.minute + 1) % 60;
|
||||
}
|
||||
}
|
||||
}
|
||||
rtems_cpu_usage_reset();
|
||||
rtems_task_wake_after(1000);
|
||||
}
|
||||
}
|
||||
|
||||
rtems_task Application_task2(rtems_task_argument argument)
|
||||
{
|
||||
rtems_id tid;
|
||||
rtems_status_code status;
|
||||
|
||||
status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
|
||||
|
||||
printf( "Application task was invoked with argument (%d) "
|
||||
"and has id of 0x%x\n", argument, tid );
|
||||
|
||||
while(1)
|
||||
{
|
||||
mem_test();
|
||||
rtems_task_wake_after(10000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void raytrace(void);
|
||||
|
||||
rtems_task Application_task3(rtems_task_argument argument)
|
||||
{
|
||||
rtems_id tid;
|
||||
rtems_status_code status;
|
||||
rtems_isr_entry old;
|
||||
|
||||
status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
|
||||
|
||||
status = rtems_interrupt_catch(user_isr, J3K_IRQ_DEBUG, &old);
|
||||
if (status != RTEMS_SUCCESSFUL)
|
||||
fprintf(stderr, "rtems_interrupt_catch(): Error %08X\n", status);
|
||||
|
||||
printf( "Application task was invoked with argument (0x%x) "
|
||||
"and has id of 0x%x\n", argument, tid );
|
||||
|
||||
while(1)
|
||||
{
|
||||
raytrace();
|
||||
rtems_task_wake_after(30000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void life(uint32_t seed);
|
||||
|
||||
rtems_task Application_task4(rtems_task_argument argument)
|
||||
{
|
||||
rtems_id tid;
|
||||
rtems_status_code status;
|
||||
|
||||
status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
|
||||
|
||||
printf( "Application task was invoked with argument (0x%x) "
|
||||
"and has id of 0x%x\n", argument, tid );
|
||||
|
||||
life(clock_us());
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user