BMSTU/src/sem.c

48 lines
1.1 KiB
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] = {
{0x00000010, 0x00000010, 0x00000005, 0x00000010},
{0x00000010, 0x00000020, 0x00000010, 0x00000010},
{0x000000f1, 0x000000f1, 0x000000f1, 0x00000011},
{0x000000d1, 0x000000f1, 0x000000f1, 0x00000011}
};
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 << 32) | 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;
}