예제 #1
0
void Alarm()
{
	char message[24];
	if(alarm == 0x01&& alarm_en == 0x01)
	{
		Uart_send_n("AT+CIPSEND=0,24",15);
		Uart_send(0x0d);
    	Uart_send(0x0a);
    	usleep(1000000);
		strcpy(message,"Someone Has Broken In!!!");
		Uart_send_n(message,24);
		Uart_send(0x0d);
		Uart_send(0x0a);
		puts("f**k!!\n");

		IOWR_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE,0x03);
	}
	else
	{
		unsigned int status = IORD_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE);
		IOWR_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE, status&0x01);
		puts("nothing!\n");

	}
}
예제 #2
0
tEplKernel PUBLIC AppCbSync(void)
{
	tEplKernel EplRet = kEplSuccessful;
    int        nIdx;

#ifdef DIN_PIO_BASE
    bButtonInputs_l = IORD_ALTERA_AVALON_PIO_DATA(DIN_PIO_BASE);
#else
	bButtonInputs_l++;
#endif

#ifdef DOUT_PIO_BASE
    IOWR_ALTERA_AVALON_PIO_DATA(DOUT_PIO_BASE, bLedOutputs_l);
#endif

#ifdef LED_PIO_BASE
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~wDigitalOutputs_l);
#endif

    for (nIdx = 0; nIdx < 15; nIdx++)
    {
        abVirtualInputs_l[nIdx] = (~abVirtualOutputs_l[nIdx])-1;
    }
    abVirtualInputs_l[15] = (~bButtonInputs_l)-1;
    abVirtualInputs_l[16] = (~bLedOutputs_l)-1;

    for (nIdx = 0; nIdx < 8; nIdx++)
    {
        adwVirtualInputs_l[nIdx] = (~adwVirtualOutputs_l[nIdx])-1;
    }

    return EplRet;
}
int main()
{ 


	volatile uint16_t t;
	volatile uint16_t buff[2] = {0,0};

	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x0);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0x7);
	//alt_putstr("Hello from Nios II!\n");
	/* Event loop never exits. */

	while (1) {
		t = alt_getchar();
		//alt_printf("%x",t);
		buff[1] = buff[0];
		buff[0] = t;

		if(buff[1] == 'W' && buff[0] == 'R'){
			//alt_putstr("write start\n");
			write_program();
		}
		else if(buff[1] == 'R' && buff[0] == 'D'){
			//alt_putstr("read start\n");
			read_program();
		}

	}
	return 0;
}
예제 #4
0
void UpdateChannels(void) 
{
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, trigger[0]);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_1_BASE, trigger[1]);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_2_BASE, trigger[2]);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_3_BASE, trigger[3]);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_CTL_BASE, freq);
}
예제 #5
0
void drawRect(int x,int y,int color){
    graphicsFlag = 0;
    while(!graphicsFlag);
    IOWR_ALTERA_AVALON_PIO_DATA(XVALUE_BASE, x+9);
    IOWR_ALTERA_AVALON_PIO_DATA(YVALUE_BASE, y+7);
    IOWR_ALTERA_AVALON_PIO_DATA(COLOR_BASE, color);
    while(!graphicsFlag);
}
예제 #6
0
파일: iniche_init.c 프로젝트: keskella/omat
int main (int argc, char* argv[], char* envp[])
{
  
  INT8U error_code;
  int rc;

  /* Clear the RTOS timer */
  OSTimeSet(0);

  /* Flash LEDs and reset ethernet PHY - $M$*/
#ifdef LED_PIO_BASE
   IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);
   printf("LEDs set to 0xAA\n");
#endif
   rc = usleep(1000000);  // Delay 1 sec

#ifdef NENET_REG_RESET_BASE
  /* Reset the Ethernet PHY */
   printf("Reseting Ethernet PHY...");
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x1);  // Be sure it's hi first
   rc = usleep(250000);  // Delay .25 sec
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x0);  // Go low for reset
   rc = usleep(250000);  // Delay .25 sec
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x1);  // Back to hi - inactive
   printf(" Done\n");
   rc = usleep(250000);  // Delay .25 sec
#endif
#ifdef LED_PIO_BASE
   IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);
   printf("LEDs set to 0x55\n");
#endif

  /* SSSInitialTask will initialize the NicheStack
   * TCP/IP Stack and then initialize the rest of the Simple Socket Server example 
   * RTOS structures and tasks. 
   */  
  error_code = OSTaskCreateExt(SSSInitialTask,
                             NULL,
                             (void *)&SSSInitialTaskStk[TASK_STACKSIZE],
                             SSS_INITIAL_TASK_PRIORITY,
                             SSS_INITIAL_TASK_PRIORITY,
                             SSSInitialTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);

  /*
   * As with all MicroC/OS-II designs, once the initial thread(s) and 
   * associated RTOS resources are declared, we start the RTOS. That's it!
   */
  OSStart();

  
  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
예제 #7
0
int getAngle(int right,int left){
      angleFlag = 0;
      IOWR_ALTERA_AVALON_PIO_DATA(ANGLE_START_BASE, 0);
      IOWR_ALTERA_AVALON_PIO_DATA(DIST_LOUT_BASE, left);
      IOWR_ALTERA_AVALON_PIO_DATA(DIST_ROUT_BASE, right);
      IOWR_ALTERA_AVALON_PIO_DATA(ANGLE_START_BASE, 1);
      while (!angleFlag);
      return IORD_ALTERA_AVALON_PIO_DATA(ANGLE_BASE);
}
예제 #8
0
void trigger_reset()
{
  /* Drive a 0 out to the configuration PLD reconfig_request pin. */
  IOWR_ALTERA_AVALON_PIO_DATA( RECONFIG_REQUEST_PIO_BASE, 0x0 );
  /* Set BIDIR PIO to drive out. */
  IOWR_ALTERA_AVALON_PIO_DIRECTION( RECONFIG_REQUEST_PIO_BASE, 1 );
  usleep ( 1000000 );
  /* Drive out a 1....probably won't reach this point!!! */
  IOWR_ALTERA_AVALON_PIO_DATA( RECONFIG_REQUEST_PIO_BASE, 0x1 );
}
예제 #9
0
static void TestButtons( void )
{
  volatile alt_u8 led;
  int read_result = 0;
  _Bool flag = true;
  /* Variable which holds the last value of edge_capture to avoid
   * "double counting" button/switch presses
   */
  /* Initialize the Buttons/Switches (SW0-SW3) */
  init_button_pio();
  edge_capture = 0;
  led = 0x0;

  while (1 == 1)
  {
	  read_result = IORD(LED_PIO_BASE,0);

      switch (edge_capture)
      {
        case 0x1:
        	//if flag == true
        	if(read_result && flag){
        		printf("1pressed button1 and edge_capture = %d.\n",edge_capture);
        		led = 0x0;
        		edge_capture = 0;
        		IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
        		flag = false;
        	}

        	else if(flag){
        		printf("2pressed button1 and edge_capture = %d.\n",edge_capture);
        		led = 0x1;
        		IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
        		edge_capture = 0;
        		flag = false;
        	//	usleep(1000000);
        	}
        	else{
        		flag = true;
        		edge_capture = 0;
        	}

          break;
          /*You can add other button controllers here
           *  with case 0x2, case 0x4, case 0x8
           * */
      }
  }
  /* Disable the button pio. */
  disable_button_pio();
  usleep(2000000);
  return;
}
예제 #10
0
/*System initialization function. Should be called before your while(1)*/
void system_initialization(){
	/*Hard-code to 1 right here, you can use ISR
	 *to change the value by yourself
	*/
	uartStartRecvFlag = 1;

	 /*Open Uart port and ready to transmit and receive*/
	 uart = open(UART_NAME, O_ACCMODE);
	 if(!uart){
		 printf("failed to open uart\n");
		 //return 0;
	 } else {
		 printf("Uart ready!\n");
	 }

	 //Interrupts Registrations
	 alt_irq_register(switch0_id, (void *)&switch0, handle_switch0_interrupt);
	 alt_irq_register(switch1_id, (void *)&switch1, handle_switch1_interrupt);
	 alt_irq_register(key0_id, (void *)&key0, handle_key0_interrupt);
	 alt_irq_register(key1_id, (void *)&key1, handle_key1_interrupt);
	 alt_irq_register(key2_id, (void *)&key2, handle_key2_interrupt);
	 alt_irq_register(key3_id, (void *)&key3, handle_key3_interrupt);
	 alt_irq_register(leftready_id, (void *)&leftready, handle_leftready_interrupt_test);
	 alt_irq_register(rightready_id, (void *)&rightready, handle_rightready_interrupt_test);

	 /*Interrupt enable -> mask to enable it*/
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SWITCH0_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SWITCH1_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY0_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY1_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY2_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY3_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(LEFTREADY_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(RIGHTREADY_BASE, 1);

	 /*Reset edge capture bit*/
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCH0_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCH1_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY0_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY1_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY2_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY3_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(LEFTREADY_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(RIGHTREADY_BASE, 0);

	 /*turn off all LEDs*/
	 IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, 0x00);

	 /*initialize SPI transmission*/
	 IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1); // ~CS low
	 IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 0); // Initialize SCLK to high
}
예제 #11
0
void hexOutputGeneric(int location, int value) {
	switch (location) {
		case 0:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX0_BASE, value);
			break;
		case 1:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX1_BASE, value);
			break;
		case 2:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX2_BASE, value);
			break;
		case 3:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX3_BASE, value);
			break;
		case 4:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX4_BASE, value);
			break;
		case 5:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX5_BASE, value);
			break;
		case 6:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX6_BASE, value);
			break;
		case 7:
			IOWR_ALTERA_AVALON_PIO_DATA(HEX7_BASE, value);
			break;
	}
}
예제 #12
0
int main(void) {
	 system_initialization();
     // set frequency
	 // sampleFrequency = 0x000C; //8k
	 sampleFrequency = 0x0019; //32k
	 //sampleFrequency = 0x0023; //44.1k
	 //sampleFrequency = 0x0001; //48k
	 aic23_demo[8] = sampleFrequency;
	 AIC23_demo();
	 int i;

	 /*Your main infinity while loop*/
	 while(1){
		 IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, IORD_ALTERA_AVALON_PIO_DATA(SWITCH0_BASE));
		 // send 512 data to matlab
		 if(uartStartSendFlag){
			for (i = 0; i < UART_BUFFER_SIZE; i++){
				uart_sendInt16(datatest[i]);
			}
			uartStartSendFlag = 0;
		 }
	 }

	 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
	 /*!!!!!!!YOUR CODE SHOULD NEVER REACH HERE AND BELOW!!!!!!!*/
	 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
	 return 0;
}
/*
 * indicates the position of the vehicle on the track with the four leftmost red LEDs
 * LEDR17: [0m, 400m)
 * LEDR16: [400m, 800m)
 * LEDR15: [800m, 1200m)
 * LEDR14: [1200m, 1600m)
 * LEDR13: [1600m, 2000m)
 * LEDR12: [2000m, 2400m]
 */
void show_position(INT16U position)
{
    int range = position / 4000, led_out = 0;
       
    switch(range){
        case 0:                                 // 0m - 400m
            led_out = led_out | 131072;       // Enable 17th bit
            break;
        case 1:                             // 400m - 800m
            led_out = led_out | 196608;    //  Enable 17, 16th bit
            break;
        case 2:                             // 800m - 1200m
            led_out = led_out | 229376;     //  Enable 17, 16, 15th bit
            break;
        case 3:                                // 1200m - 1600m
            led_out = led_out | 245760;         //  Enable 17, 16, 15, 14th bit
            break;
        case 4:                                // 1600m - 2000m
            led_out = led_out | 253952;       //  Enable 17, 16, 15, 14, 13th bit
            break;
        case 5:                           // 2000m - 2400m
            led_out = led_out | 258048;  //Enable 17, 16, 15, 14, 13, 12th bit
            break;
        default:
            printf("----- Error in Show_Position LED display -----");
            break;
    }
    led_out = led_out + switchIO_out;                           
    IOWR_ALTERA_AVALON_PIO_DATA(DE2_PIO_REDLED18_BASE,led_out);
}
예제 #14
0
파일: cpu_0.c 프로젝트: johangas/IL2212
int main(void) {
	int i=0, x, y, j, value = 0;
	unsigned char* shared;
	int dim = 40*40*3;
     	while(1){
		for (i = 8; i <= 16; i=i+4){ 
			generate_p3(i, i, 7*i);
//			 Just to see that the task compiles correctly 
			IOWR_ALTERA_AVALON_PIO_DATA(LEDS_GREEN_BASE, value++);

			shared = (unsigned char*) SHARED_ONCHIP_BASE + 4 * (3 + dim);
			while(IORD_32DIRECT(shared, 0) > 0) {}
				//delay
	
			//Read from cpu4 and print to hex
			x = IORD_32DIRECT(shared++, 0)%40;
			y = IORD_32DIRECT(shared++, 0)%40;
			shared++;
			for(i = 0; i < y; i++){
				for(j = 0; j < x; j++){
					printf("%c", (unsigned char)IORD_32DIRECT(shared++, 0));
				 }
				printf("\n");
			}
			shared = (unsigned char*) SHARED_ONCHIP_BASE ;
			while(IORD_32DIRECT(shared, 0) != 0) {}
				//delay
		}

	}

  return 0;
}
예제 #15
0
static void LED_off(void)
{
  volatile alt_u8 led;
  /* Turn the LEDs on. */
  led = 0x0;
  IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
  usleep(1000000);
}
예제 #16
0
void setAlien(int pSramAliens, int x, int y, struct Alien a) {
    /*sram[(pSramAliens + 0) + (sizeof(struct Alien) * ((x * 8) + y))] = a.alive;
    sram[(pSramAliens + 1) + (sizeof(struct Alien) * ((x * 8) + y))] = a.type;
    sram[(pSramAliens + 2) + (sizeof(struct Alien) * ((x * 8) + y))] = a.rowId;*/
		
		*sram_enable = 1;
		*sram_readWrite = 1;

		*sram_address = (pSramAliens + 0) + (sizeof(struct Alien) * ((x * 8) + y));
		IOWR_ALTERA_AVALON_PIO_DATA(sram_data, a.alive);
		
		*sram_address = (pSramAliens + 1) + (sizeof(struct Alien) * ((x * 8) + y));
		IOWR_ALTERA_AVALON_PIO_DATA(sram_data, a.type);
    
		*sram_address = (pSramAliens + 2) + (sizeof(struct Alien) * ((x * 8) + y));
		IOWR_ALTERA_AVALON_PIO_DATA(sram_data, a.rowId);
}
예제 #17
0
void checkKeypad()
{
	memset(button, 0, sizeof(int)*17); //quickley resets the  button array
	int temp = 0;
	int temp2 = 0;
	button[PRESSED] = 0;

	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x01); // enable first colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] =  1;	// check if any butons pressed.
		button[M1] = CHECK_BIT(temp, 0);
		button[UPLEFT] = CHECK_BIT(temp, 1);
		button[LEFT] = CHECK_BIT(temp, 2);
		button[DOWNLEFT] = CHECK_BIT(temp, 3);
	}
	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x02); // enable 2nd colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] = 1;	// check if any butons pressed.
		button[M2] = CHECK_BIT(temp, 0);
		button[UP] = CHECK_BIT(temp, 1);
		button[STOP] = CHECK_BIT(temp, 2);
		button[DOWN] = CHECK_BIT(temp, 3);
	}
	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x04); // enable 3rd colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] = 1;	// check if any butons pressed.
		button[M3] = CHECK_BIT(temp, 0);
		button[UPRIGHT] = CHECK_BIT(temp, 1);
		button[RIGHT] = CHECK_BIT(temp, 2);
		button[DOWNRIGHT] = CHECK_BIT(temp, 3);
	}
	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x08); // enable last colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] = 1;	// check if any butons pressed.
		button[DELETE] = CHECK_BIT(temp, 0);
		button[PLAY] = CHECK_BIT(temp, 1);
		button[RECORD] = CHECK_BIT(temp, 2);
		button[SHIFT] = CHECK_BIT(temp, 3);
	}
	return;
}
예제 #18
0
파일: MT9M031.c 프로젝트: wzw/D3
//Function: MT9M031_trigger
//return: 0=success; 1=fail
uchar MT9M031_trigger(void)
{
    uchar gpi_status_h, gpi_status_l;
    uint ii;

    gpi_status_h = 0;
    gpi_status_l = 0;
    if(rdMT9M031Reg(0x30, 0x1A, 2, &gpi_status_h, &gpi_status_l)) return 1;
    printf("reset reg = 0x%02X%02X\n", gpi_status_h, gpi_status_l);
    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_SHUTTER_BASE,1);
    for(ii=0x0100; ii>0; ii--);
	if(rdMT9M031Reg(0x30, 0x26, 2, &gpi_status_h, &gpi_status_l)) return 1;
    printf("gpi_status = 0x%02X%02X\n", gpi_status_h, gpi_status_l);
    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_SHUTTER_BASE,0);
	if(rdMT9M031Reg(0x30, 0x26, 2, &gpi_status_h, &gpi_status_l)) return 1;
    printf("gpi_status = 0x%02X%02X\n", gpi_status_h, gpi_status_l);
    return 0;
}
예제 #19
0
/**
 * Creates a new motor handler.
 * @throw UARTOpenException if the handler cannot open the UART device used to talk to the motors
 */
MotorHandler::MotorHandler() {
	// Enable the motor controller.
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MOTOR_RESET_N_BASE, MOTOR_ENABLE);
	// Open the serial device to send commands to the motor controller.
	motor_dev = alt_up_rs232_open_dev(UART_MOTOR_NAME);
	if (motor_dev == NULL) {
		throw new UARTOpenException();
	}
}
int main() {
    IOWR_ALTERA_AVALON_PIO_DATA(LED_COLOR_BASE, LED_COLOR_RESET_VALUE);
    initBuffer(&b0);
    createProcess(producer, STACK_SIZE);
    createProcess(consumer, STACK_SIZE);
    createProcess(countAndDisplay, STACK_SIZE);

    start();
    return 0;
}
예제 #21
0
void getDistances(int * right,int * left,int * back){
  
  do{
      distFlag = 0;
      //set start timing line low
      IOWR_ALTERA_AVALON_PIO_DATA(START_TIME_BASE, 0);
      //send ping command and wait for transfer to complete
      sendChar('P');
      //start timing
      IOWR_ALTERA_AVALON_PIO_DATA(ANGLE_START_BASE, 1);
      //wait for distance measure to finish
      while (!distFlag);
      // Store the distance values
      *left = IORD_ALTERA_AVALON_PIO_DATA(DIST_L_BASE);
      *right = IORD_ALTERA_AVALON_PIO_DATA(DIST_R_BASE);
      *back = IORD_ALTERA_AVALON_PIO_DATA(DIST_B_BASE);
  }while(!(*left&&*right&&*back));
  
}   
예제 #22
0
int main()
{
printf("Hello from Nios II!\n");
int count = 0;
int delay;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 0xFF);        // Turn LEDs Off
while(1)
{
//    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, count & 0x01);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, count);
    delay = 0;
    while(delay < 2000000)
        {
        delay++;
        }
    count++;
}
return 0;
}
예제 #23
0
파일: lab0.c 프로젝트: eriknore/il2206
alt_u32 show (void* context)
{
    /* This function will be called once/second */
    if (run)
        tick (&timeloc);
    puttime (&timeloc);
    IOWR_ALTERA_AVALON_PIO_DATA(DE2_PIO_REDLED18_BASE,timeloc);
    puthex(timeloc);
    return alt_ticks_per_second();
}
예제 #24
0
struct Alien getAlien(int pSramAliens, int x, int y) {
    struct Alien a;
    /*a.alive = sram[(pSramAliens + 0) + (sizeof(struct Alien) * ((x * 8) + y))];
    a.type = sram[(pSramAliens + 1) + (sizeof(struct Alien) * ((x * 8) + y))];
    a.rowId = sram[(pSramAliens + 2) + (sizeof(struct Alien) * ((x * 8) + y))];*/
		*sram_enable = 1;
		*sram_readWrite = 0;
		
		*sram_address = (pSramAliens + 0) + (sizeof(struct Alien) * ((x * 8) + y));
		a.alive = IOWR_ALTERA_AVALON_PIO_DATA(sram_data);
		
		*sram_address = (pSramAliens + 1) + (sizeof(struct Alien) * ((x * 8) + y));
    a.type = IOWR_ALTERA_AVALON_PIO_DATA(sram_data);
    
		*sram_address = (pSramAliens + 2) + (sizeof(struct Alien) * ((x * 8) + y));
		a.rowId = IOWR_ALTERA_AVALON_PIO_DATA(sram_data);
		
    return a;
}
예제 #25
0
int main() {
	alt_u32 current_value=1;
	alt_u32 current_state=3;
	alt_u8 current_direction=0;
	alt_u32 keys;

	printf("Program running (UART)...\n");
	fprintf(stderr, "Program running (LCD)...\n");

	while (1) {
		//reading the current state of the keys
		keys = IORD_ALTERA_AVALON_PIO_DATA(KEYS_BASE);

		//switching speeds if necessary
		if ((keys != 7) && (keys != current_state)) {
			if (keys == 3){
				printf("speed set to 250 ms\n");
				fprintf(stderr, "\nSpeed set 250 ms");
			}
			else if (keys == 5){
				printf("speed set to 150 ms\n");
				fprintf(stderr, "\nSpeed set 150 ms");
			}
			else if (keys == 6){
				printf("speed set to 50 ms\n");
				fprintf(stderr, "\nSpeed set 50 ms");
			}
			else
				printf("keys != 3, 5, or 6. Stop hitting multiple buttons.");
			current_state = keys;
		}

		//switching direction if necessary
		if ((current_direction == 0) && (current_value == (1 << 25)))
			current_direction = 1;
		else if ((current_direction == 1) && (current_value == 1))
			current_direction = 0;
		//moving the light
		else if (current_direction == 0)
			current_value = current_value << 1;
		else
			current_value = current_value >> 1;
		//updating the lights
		IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, current_value);

		//sleep
		if (current_state == 3)
			usleep(250000);
		else if (current_state == 5)
			usleep(125000);
		else
			usleep(50000);
	}
	return 0;
}
예제 #26
0
파일: MT9M031.c 프로젝트: wzw/D3
//Function: MT9M031_init
//return: 0=success; 1=fail
uchar MT9M031_init(void)
{
    uchar chip_version_reg_h, chip_version_reg_l;
    uchar revision;
    
    printf("Start init MT9M031\n");

    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_RESETN_BASE,0);
	delay_ms(200);
    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_RESETN_BASE,1);
	delay_ms(200);

    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_SHUTTER_BASE,1);
    usleep(200);
    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_SHUTTER_BASE,0);

    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_STANDBY_BASE,1);
    usleep(200);
    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_STANDBY_BASE,0);

    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_OEN_BASE,1);
    usleep(200);
    IOWR_ALTERA_AVALON_PIO_DATA(MT9M031_OEN_BASE,0);
	delay_ms(200);

    printf("Reset MT9M031\n");
    while(MT9M031_reset()){
        delay_ms(200);
    }
    delay_ms(200);
    
    printf("Read MT9M031 chip ID\n");
    while(rdMT9M031Reg(0x30, 0x00, 2, &chip_version_reg_h, &chip_version_reg_l));
    printf("Image sensor Chip Version = 0x%02x%02x.\n", chip_version_reg_h, chip_version_reg_l);
    while(rdMT9M031Reg(0x30, 0x0E, 1, &revision, &revision));
    printf("Image sensor Chip revision = 0x%02x.\n", revision);

    printf("Do init MT9M031\n");

	if(MT9M031_reset()) return 1;
	delay_ms(200);
	if(MT9M031_firmware_setting()) return 1;
	if(MT9M031_Column_Correction_ReTriggering()) return 1;
	if(MT9M031_A_1000GS_REV2_Optimized_Settings()) return 1;
	if(MT9M031_PLL_Settings()) return 1;
	if(MT9M031_Full_Resolution()) return 1;
	if(MT9M031_other_setting()) return 1;
	if(MT9M031_test_pattern_setting()) return 1;
  
    printf("MT9M031 Init OK!\n");
	return 0;                       //ok
} 
예제 #27
0
void spi_send(unsigned int address, unsigned int data){
	int i = 0;

	IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 0); // Begin
	delay(150);
	for(i = 0; i < 7; i++){
		if((address & 0x40) != 0){
			IOWR_ALTERA_AVALON_PIO_DATA(SDIN_BASE, 1);
			//printf("1");
		}else{
			IOWR_ALTERA_AVALON_PIO_DATA(SDIN_BASE, 0);
			//printf("0");
		}
		delay(1000);
		IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 1);
		delay(1000);
		IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 0);
		delay(1000);

		address <<= 1;
	}

	for(i = 0; i < 9; i++){
		if((data & 0x100) != 0){
			IOWR_ALTERA_AVALON_PIO_DATA(SDIN_BASE, 1);
			//printf("1");
		}else{
			IOWR_ALTERA_AVALON_PIO_DATA(SDIN_BASE, 0);
			//printf("0");
		}
		delay(1000);
		IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 1);
		delay(1000);
		IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 0);
		delay(1000);

		data <<= 1;
	}

	IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1); // Latches word to AIC
	//IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 1);
}
예제 #28
0
파일: main.c 프로젝트: gongal/ARCap
/* Controllers the IR emitter based on the value of the pushbutton. */
void ir_task_toggle(void* pdata)
{
	int status = 0;
	while (1)
	{
		status = !status;
		printf("Emitter: %d", status);
		IOWR_ALTERA_AVALON_PIO_DATA(IR_EMITTER_BASE, status);
		OSTimeDlyHMSM(0, 0, 2, 0);
	}
}
예제 #29
0
//write date to hex display
void hex_write_date(int month, int day, int year) {
	// Get the digits for the month
	int m1 = month % 10;
	int m2 = (month - m1) % 100;;
	
	// They will go in the first and second slots of the display
	uint8_t b = num_to_seven_seg(m1);
	uint8_t a = num_to_seven_seg(m2 / 10);
	
	// Get the digits of the day
	int d1 = day % 10;
	int d2 = (day - d1) % 100;
	
	// They will go in the third and fourth slots of the display
	uint8_t d = num_to_seven_seg(d1);
	uint8_t c = num_to_seven_seg(d2 / 10);

	// Concatenate them into the whole 32 bit seven seg representation
	uint32_t seven_seg_num_md = (a << 24) | (b << 16) | (c << 8) | d;
	
	// Write to the display 
	IOWR_ALTERA_AVALON_PIO_DATA(SEVENSEG74_BASE, seven_seg_num_md);
	
	// Get the digits for the date
	int y1 = year % 10;
	int y2 = (year - y1) % 100;
	int y3 = (year - y2 - y1) % 1000;
	int y4 = (year - y3 - y2 - y1) % 10000;
	
	// Change them into seven seg numbers
	uint8_t h = num_to_seven_seg(y1);
	uint8_t g = num_to_seven_seg(y2 / 10);
	uint8_t f = num_to_seven_seg(y3 / 100);
	uint8_t e = num_to_seven_seg(y4 / 1000);

	// Concatenate them into the whole 32 bit seven seg representation
	uint32_t seven_seg_num_y = (e << 24) | (f << 16) | (g << 8) | h;
	
	// Write to the display
	IOWR_ALTERA_AVALON_PIO_DATA(SEVENSEG30_BASE, seven_seg_num_y);
}
예제 #30
0
파일: main.c 프로젝트: gongal/ARCap
/* Controllers the IR emitter based on the value of the pushbutton. */
void ir_task(void* pdata)
{
	INT8U err;
	while (1)
	{
		int status = (int)OSQPend(queue, WAIT_FOREVER, &err) - IR_PUSHBUTTON_MESSAGE;
		if (err == OS_NO_ERR) {
			printf("IR: %d\n", status);
			IOWR_ALTERA_AVALON_PIO_DATA(IR_EMITTER_BASE, status);
		}
	}
}