50 lines
985 B
C
50 lines
985 B
C
#include <stdio.h>
|
|
#include "altera_avalon_sem_regs.h"
|
|
#include "alt_types.h"
|
|
#include "system.h"
|
|
|
|
#define TIME_SETS 4
|
|
#define TIME_STATES 4
|
|
const alt_u32 divisors[TIME_SETS][TIME_STATES] = {
|
|
{0x100000, 0x100000, 0x50000, 0x10000},
|
|
{0x100000, 0x200000, 0x100000, 0x10000},
|
|
{0x150000, 0x250000, 0x200000, 0x10000},
|
|
{0x250000, 0x250000, 0x250000, 0x10000}
|
|
};
|
|
|
|
int main()
|
|
{
|
|
int i,j;
|
|
volatile alt_u32 *p;
|
|
alt_u32 tmp;
|
|
|
|
//program divisors
|
|
p = (alt_u32*) SEM_RAM_SLAVE_BASE;
|
|
for (i=0; i<TIME_SETS; i++)
|
|
{
|
|
tmp = 0;
|
|
for (j=TIME_STATES; j>0; j--)
|
|
{
|
|
tmp = (tmp << 8) | divisors[i][j-1];
|
|
}
|
|
*p=tmp;
|
|
p++;
|
|
}
|
|
//since we use pointers (cached data access) to write divisor RAM,
|
|
//and not direct i/o access with IOWR, we need to flush cache
|
|
alt_dcache_flush();
|
|
|
|
//select timeset and run semafor
|
|
IOWR_ALTERA_AVALON_SEM_DIVSET(SEM_CTL_SLAVE_BASE,0x00);
|
|
IOWR_ALTERA_AVALON_SEM_CTL(SEM_CTL_SLAVE_BASE,0x01);
|
|
|
|
printf("Ready\n");
|
|
|
|
while (1)
|
|
{
|
|
;
|
|
}
|
|
|
|
return 0;
|
|
}
|