/* Lab-specific initialization goes here */
void labinit( void )
{
  // defining the int pointer, trise, volatile because you 
  //don't want the c compiler to optimise
  volatile int * E = (volatile int *) 0xbf886100;
  // 
  volatile int * portE = (volatile int *) 0xbf886110;
  * portE = 0x0; // for LED outputs
  // only for the last 8 bits
  * E = * E & 0xFF00;
  // initialising port D as input
  // using the pic32mx system
  TRISD = TRISD & 0x0FE0;

  PR2 = TMR2PERIOD;
  T2CON = 0x0; // clearing the clock
  T2CONSET = 0x70; // setting the prescale
  TMR2 = 0; // reset timer to 0
  T2CONSET = 0x8000; // turn timer on, set bit 15 to 1

  // enabling interupts from Timer 2
  // IPC(2) = 7;
  IPC(2) = IPC(2) | 0x10;
  // set bit no 8 to enable interupt
  IEC(0) = 0x100;
  // calling interupt from labwork.S
  enable_interrupt();
  
  return;
}
/* Lab-specific initialization goes here */
void labinit( void )
{
  * portE = 0x0; // for LED outputs
  // only for the last 8 bits
  * E = * E & 0xFF00;
  // initialising port D as input
  // using the pic32mx system
  TRISD = TRISD & 0x0FE0;

  PR2 = TMR2PERIOD;
  T2CON = 0x0; // clearing the clock
  T2CONSET = 0x70; // setting the prescale
  TMR2 = 0; // reset timer to 0
  T2CONSET = 0x8000; // turn timer on, set bit 15 to 1


  // configuring the priority level
  IPC(2) = 7;
  // enabling bit 8 for the interupt
  IEC(0) = 0x100;

  // configuring the priority
  IPC(1) = 0x1C000000 ;
  // enabling bit 7 fot interrupt
  IEC(0) = IEC(0) | 0x80;


  // calling interupt from labwork.S
  enable_interrupt();
  
  return;
}
/* 
 * Checks of a valid pipes and calls IPC to launch childs and commands
 *
 * @param pl pipeline created by the command line phraser 
 * @return exit status of the last child forked in the pipeline
 */
int process( pipeline pl )
{
  int totalP, status;
  Child *myChilds;      /* Child ARRAY */


  if(pl->cline == NULL) /* check if the cmd arg is not empty , should never happened by main */
    return -1;

  totalP = pl->length;

  /* perform the build in commands */


  /* children info array */
  FATALCALL( (myChilds = (Child *) malloc (sizeof(Child) * totalP)) == NULL, "Invalid Malloc");

  /* inialize child struct to EMPTY */
  FATAL( (newChild( myChilds, totalP)) == -1, "Error")

    /* create the pipes */
    status = IPC( pl, myChilds );

  /* free the id's and return status */
  free ( myChilds );
  return status;
}
Example #4
0
/* Lab-specific initialization goes here */
void labinit( void )
{
    volatile int* trise = (volatile int*) 0xbf886100;
    *trise = *trise & 0xff00;
    TRISD = TRISD | 0x0fe0;

    //initialize timer 2
    T2CON = 0x70; //sätt 1:256 prescale !!! bit 5-4 ska vara 11, bit 6 oklar
    //men den måste vara 1
    PR2 = (80000000/256)/10; //sätt perioden till en tiondel av en sekund
    PR2 = PR2*2; // <------- surprise assignment
    TMR2 = 0; //reseting counter for timer 2
    T2CONSET = 0x8000; // start timer (ON bit is bit 15)

    //enable interrupts
    IEC(0) = IEC(0) | 0x0100; //sätt bit 8 till 1 för att enable interrupts

    IPC(2) = 7; //ta emot interrupts från Timer 2, högsta prioritet
    //7 är högsta med 3 bitar

    enable_interrupts(); //kalla assembler metod för att enabla globala interrupts


    return;
}
Example #5
0
/* initialization routine */
void init (void) {
  /* turn spi off and clear interrupts */
  SPI2CON = 0;
  IEC(1) = 0;
  IPC(7) = 0;
  IFS(1) = 0;

  /* set interrupts */
  IPC(7) = (7<<24);
  IEC(1) = (1<<7);

  /* set spi */
  SPI2BRG = 0x1FF;      // Set SCK ~78kHz
  SPI2STATCLR = 0x40;   // Clear SPIROV bit
  SPI2CON = 0x8060;     // Set ON, CKE = 0, CKP = 1, MSTEN = 1
  asm("ei");
}
Example #6
0
/* This function is called before main() is called, you can do setup here */
void _on_bootstrap() {
	inputinit();
	display_init();
	IEC(0) = 0x100;			/* Interrupt Enable Control */
	IPC(2) = 0b111110100;		/* Interrupt Priority Control */
	TMR2 = 0;			/* Reset Timer Value */
	PR2 = 31250;			/* Set period register */
	T2CON = 0b1000000001110000;	/* Set internal 16-bit timer. Prescaling 1:256 */
	__asm__ volatile("ei");		/* Enable interrupt */	
	
}
Example #7
0
/* Lab-specific initialization goes here */
void labinit( void )
{
  volatile int* trise = (volatile int*) 0xbf886100; // 8 sista satta till 0 (Output)
  TRISD = 0xfe0; // [11:5] Som input. Resten output
  
  PR2 = TIMER2PERIOD;
  TMR2 = 0;
  T2CON = 0x70; // Sätter prescale till 1:256
  
  IEC(0) = 0x100; // Sätter tmr2 interrupt enable
  IPC(2) = 0x4; // Sätter icke-noll prio till de tre bitarna.
  T2CONSET = 0x8000; // Startar timern
  enable_interrupt();
  return;
}
int main(void) {
	int i;
	
	delay(10000000);
	ODCE = 0;
	TRISECLR = 0xFF;

	_enable_int_number(7, (void *) IPC(1), 1, 0);
	_enable_interrupt();


	for (i = 0;; i++) {
		PORTE = i & 0xFF;
		delay(1000000);
	}

	return 0;
}
Example #9
0
/* Lab-specific initialization goes here */
void labinit( void ) 	// Enable interrupts from Timer 2
{
    volatile unsigned int* trise = (unsigned int*) 0xbf886100;
    *trise = *trise & ~0xff;
    
    // It's possible to use TRISDSET here as well but then it wouldn't be defined
    // if the bits not in use are 0 or 1. TRISDCLEAR can be used to clear specific
    // bits without affecting other bits.
    TRISDSET = 0x7f << 5;
    
	T2CON = 0x0; 			// Stop timer2
    T2CONSET = 0x0070; 		// Prescale 1:256 Surprise: change 256 to 32 (7 -> 5)
    TMR2 = 0; 				// Timer2 value starts at 0
    PR2 = 31250;			// Timer2 value ticks to a suitable number
	IPC(2) = 1 << 2;	// Set priority to 2, sub priority to 3
	
	// We enable interrupts to check the time-out event-flag.
	IECSET(0) = 0x0100; 	// Enable Timer 2 interrupt
	enable_interrupt();		// Enable interrupts globaly
    T2CONSET = 0x8000; 		// Start timer2

    
    return;
}