Example #1
0
static int read_pwm(struct inode *inode, struct file *file)
{

        if (Device_Open)
                return -EBUSY;

        try_module_get(THIS_MODULE);            //Increase use count

        Device_Open++;

        // Take data low for min 18mS to start up DHT11

        GPIO_DIR_INPUT(gpio_pin);   // Change to read

        // Set up interrupts
        setup_interrupts();
 
        mdelay(20);
        sprintf(msg, "pwm : %d\n", pwm_data);
        msg_Ptr = msg;



        return SUCCESS;
}
Example #2
0
/**
 *	Where the magic starts.
 */
void main() {
	WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer.
	//BCSCTL1 = CALBC1_1MHZ;     // Set range.
	//DCOCTL = CALDCO_1MHZ;      // SMCLK = DCO = 1MHz
	//BCSCTL2 &= ~(DIVS_3);

	// Setup the PWM stuff, ADC, and interrupts.
	setup_pwm();
	setup_interrupts();
	_BIS_SR(GIE);  // TODO: Do (LPMX + GIE) for low-power + interrupts.
	//__enable_interrupt();

	// Initialize the shift register driver.
	shift_register_setup();
	shift_out(shift_default_on);
	
	// Setup the LCD driver.
	lcd_init(TRUE, TRUE);

	// Initilalize the voltage regulator driver.
	vreg_init();

	// Go to the home screen.
	print_screen(HOME_SCREEN);

	while (TRUE) {
	}
}
Example #3
0
File: spu.c Project: E-LLP/n900
static int __init enable_spu(struct spu *spu)
{
	int result;

	result = lv1_enable_logical_spe(spu_pdata(spu)->spe_id,
		spu_pdata(spu)->resource_id);

	if (result) {
		pr_debug("%s:%d: lv1_enable_logical_spe failed: %s\n",
			__func__, __LINE__, ps3_result(result));
		goto fail_enable;
	}

	result = setup_areas(spu);

	if (result)
		goto fail_areas;

	result = setup_interrupts(spu);

	if (result)
		goto fail_interrupts;

	return 0;

fail_interrupts:
	spu_unmap(spu);
fail_areas:
	lv1_disable_logical_spe(spu_pdata(spu)->spe_id, 0);
fail_enable:
	return result;
}
Example #4
0
/*
 * kmain
 * 
 * This is the first thing that executes when the kernel starts. Any
 * initialisation e.g. interrupt handlers must be done at the start of
 * the function. This function should never return.
 */
void kmain(multiboot * mb)
{
	setup_segmentation();
	setup_interrupts();
	kmalloc_init();

	/*
	 * Clear the screen 
	 */
	unsigned int x;
	unsigned int y;
	for (y = 0; y < SCREEN_HEIGHT; y++)
		for (x = 0; x < SCREEN_WIDTH; x++)
			screen[y * SCREEN_WIDTH + x].c = ' ';

	/*
	 * Place the cursor on line 0 to start with 
	 */
	move_cursor(xpos, ypos);

	kprintf("%s\n%s\n%s\n\n\n\n", VERSION, COPYRIGHT, DISCLAIMER);

	assert(1 == mb->mods_count);
	assert(mb->mods_addr[0].mod_end < 2 * MB);
	filesystem = (char *)mb->mods_addr[0].mod_start;
	/*
	 * Check here for the size of the RAM disk. Because we use a
	 * hard-coded value of 2MB for the start of the kernel's private
	 * data area, we can't safely work with filesystems that extend
	 * into this area. This is really just a hack to avoid the
	 * additional complexity of computing the right place to start
	 * the kernel and page memory regions, but suffices for our
	 * purposes.
	 */
	if (mb->mods_addr[0].mod_end >= 2 * MB)
		assert
		    (!"Filesystem goes beyond 2Mb limit. Please use smaller filesystem.");

	pid_t pid = start_process(launch_shell);
	input_pipe = processes[pid].filedesc[STDIN_FILENO]->p;

	/*
	 * Go in to user mode and enable interrupts
	 */
	enter_user_mode();

	/*
	 * Loop indenitely... we should never return from this function
	 */

	/*
	 * Pretty soon a context switch will occur, and the processor
	 * will jump out of this loop and start executing the first
	 * scheduled process
	 */
	while (1) ;
}
Example #5
0
void freq_main(void) 
{
	cli();
    counter_init();
	gate_init();
	stop();
	reset();
	ff_clr();
	key_init();
	
	setup_timers();

	setup_interrupts();
	adc_init();
	sti();

	/*clear counter*/
	TCNT2= 0;
	TCNT0= 0;
	TCNT1= 0xFF00;
	T0_ovc = T1_ovc =0;
	start();
	//fast clear screen...
	post_display(filter());//really result
	
	while(1) {

		key_process();	

		keep_live();
		
		mode = read_adc_mode();
	
		update_lcd_status();
	
	    if(is_stop()&&soft_stop){
		  	calc_freq();
			post_display(filter());//really result
				c_live() ; //mark succeufull ..
			if(loop>=(ST)){  //never clear
				reset();
			
			}
			loop=0;
		
		    start();
		}
  	}



}
Example #6
0
void main()
{
	delay_ms(100);
	// Setup ADC's and Timers
	setup_peripherals();

	// Initializes and reads external EEPROM. Loads default DEVICE_CONFIG if necessary
	device_boot();
	
	// Reset amplifier and DSP then load values into DSP
	softboot();

	// Enable/disable interrupts based on DEVICE_CONFIG parameters
	setup_interrupts();
	
	if(DEBUG) {
		fprintf(RS232,"[DEBUG] Saving addresses into FLASH [R&D only]...");
	}

	default_addr();

	FLASH_ADDR_WRITE(14);

	if(DEBUG) {
		fprintf(RS232,"Done!\r\n");
	}

	if(DEBUG) {
		fprintf(RS232,"[DEBUG] Disabling 100Hz High-Pass since we're a DSP 4x4...");
	}

	send_prefixed_dsp_command(DSP_ADDRESS_WRITE_PREFIX,SEVENTYVHP_BYPASS,0x00000001);

	if(DEBUG) {
		fprintf(RS232,"Done!\r\n");
	}

	while(true)	
	{	
		//if(IS_USB_CONNECTED) {
			process_usb_data();
		//}

		if(rs232_data_available) {
			
			process_rs232_data();
			
		}
	}
}
Example #7
0
void kmain(void)
{

    setup_interrupts();
    init_terminal();
    if((rc = init_fs()) > 0)
        puts("[KERNEL] FS INIT ERROR\r\n");
    
    while(1)
    {       
        puts_attrib("$", color_entry(COLOR_GREEN, COLOR_BLACK));
        get_string(buffer, 30, true);
        if(strcmp(buffer, "ls") == 0){
            print_files();
            continue;
        }
        if(strcmp(buffer, "kk") == 0){
            //int8_t r;
            //get_string(buffer, 11, false);
            //r = create_file(buffer, 0, strlen(msg) );
            //if(r != DISK_OP_OK)
            //  print_int(r, 10, 0);
            continue;
            
        }
        if(strcmp(buffer, "dd") == 0){
            int8_t r;
            get_string(buffer, 11, false);
            r = delete_file(buffer);
            if(r != DISK_OP_OK){
                print_int(r, 10, 0);
            }
            continue;
        }
        if(strcmp(buffer, "run") == 0)
        {
            if((rc = run_program("RAW.BIN")) != EXEC_OP_OK){
                puts("Exec error c:"); print_int(rc, 10, 0); eol();
            }
        }
        
        
        puts("\r\n");
    }
    
}
Example #8
0
void kernel_main(void)
{
	terminal_init();
	puts("This is BermudOS!");
	if(!is_apic_compatible())
		puts("Hardware is not APIC compatible");
	if(!has_MSR())
		puts("CPU has no MSR");
	if(!gdt_setup())
		puts("Error while setting up GDT");
	setup_interrupts();
	if(!keyboard_setup())
		puts("Error while setting up the keyboard");
	wait_sec(4);
	char bfr[KEYBOARD_BUFFER_SIZE+1];
	int i;
	for(i = 0; i < 4; ++i)
	{
		read_keyboard_buffer(bfr);
		printf("The buffer contained: %s", bfr);
	}
}
Example #9
0
//**********************************************************************************************
//**********************************************************************************************
//**********************************************************************************************
int main(void)
{
	volatile unsigned char data, pos;

	WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer


	//if (CALBC1_12MHZ==0xFF || CALDCO_12MHZ == 0xFF)
	 //   while(1);                               // If calibration constants erased do not load - trap CPU
	BCSCTL1 = CALBC1_12MHZ;	// Set DCO
	DCOCTL = CALDCO_12MHZ;


	//**********************************************
	//DO NOT CHANGE THE ORDER OF THE FOLLOWING CODE!
	port_init();

	initLCD();
	P4OUT |= BIT1; //LCD backlight on
	writecom(0x01, 0);//mode=0 instruction/command,    mode=1 data  clear display
	writecom(0x02, 0);//mode=0 instruction/command,    mode=1 data  position cursor home home
	write_string_to_LCD("DLP Design      ", 16);
	writecom(0xC0, 0);//mode=0 instruction/command,    mode=1 data  position cursor to start of second row
	write_string_to_LCD("DLP-RFID2 Demo  ", 16);

	keep_local=0;//if high, keep data returned to demo board (from reader) local instead of forwarding to host PC via USB.  if low, send to host PC.
	rx_index=0;//init the receive buffer index
	run_mode=0;//disable inventories
	blkaddr=0;
	currentantswstate = ANTSWINT;//init to internal

	/*	Code showing how to use J2, "SEL"  User Defined Jumper
	//pullup resistor enabled for P6.7 in port_init();
	data = P6IN;	    //read port 6
	data = data & 0x80;	//mask off other port bits
	if(data>0)          //if P6.7 is high (default)
	*/

	uart_init();

	setup_interrupts();
	//ping reader twice to sync and stop transmitting 'D's
	short_dly(50000);//pause for remainder of packet
	ping_reader();//ping for presence of reader and update display
	short_dly(50000);//pause for remainder of packet
	ping_reader();//ping for presence of reader and update display
	short_dly(50000);//pause for remainder of packet
	//**********************************************

	set_output_mode();


	for (;;)
	{
		if(light_pressed())
			P4OUT ^= 0x02; //toggle P4.1
		if(ping_pressed())
			ping_reader();//ping for presence of reader and update display
		if(antsw_pressed())
			toggle_antenna_switch();//toggle between internal and external antenna
		if(run_pressed())
			enter_run_mode();//setup for reading UIDs and set run flag for continuous inventories
		if(stop_pressed())
			exit_run_mode();//setup for reading UIDs and set run flag for continuous inventories
		if(rfoff_pressed())
			turn_rf_off();
		if(rdblk_pressed())
			read_block();

		if(run_mode==1)
			single_slot_inventory();
	}
}
Example #10
0
/*
 * DANG_BEGIN_FUNCTION memory_init
 *
 * description:
 *  Set up all memory areas as would be present on a typical i86 during
 * the boot phase.
 *
 * DANG_END_FUNCTION
 */
void memory_init(void)
{
  map_custom_bios();           /* map the DOSEMU bios */
  setup_interrupts();          /* setup interrupts */
  bios_setup_init();
}
Example #11
0
void main()
{
  unsigned char value, lastValue, CANdata[8];
  /* These variables are used to check that the rear node and the
    temperature sensing node are active. */
  signed char WaitingPeriods, state202, state50, stateLight;
  unsigned char c; /* A counter for doing things several times */
  unsigned long Brake_light; /* 1 if brake light should be on, off=0  */
  unsigned char error_flag=0;
  long id;
  unsigned short send_flag, dt, len, read_flag;
  unsigned int total, V0,V1,V2,V3,tempX10;

  
  send_flag = _CAN_TX_PRIORITY_0          &
                 _CAN_TX_NO_RTR_FRAME;

/* The state of the CANbus Messages can be:
 0 or less : Message not received in the last WaitingPeriods periods
 x [x from 520 to 1] : Message received (WaitingPeriods-x) periods ago
   The states begin at 20:  */
  WaitingPeriods = 5;
  state202 = 0;
  state50 = 0;
  stateLight = 0;


  /* Get the CANbus ready    */
  CANbus_setup();
  /* Set up and start the timing interrupts   */
  setup_interrupts();

TRISA =0xFF;  /* PORTA is input    */
ADCON1=0x80; /* Use supply as Vref.   */


TRISC = 0;   /* PORT C is for output */
PORTC= 0x10; /* Turn on a LED to show life  */

/* Program loop.
*/
  Brake_light=0;

  for(;;)     /* Endless loop   */
  {

     if (Tcount20Hz>50){  /* Do this at 20 Hz, roughly  */
     
        /* Read the ADC channels
           Channels 0 and 1 first  */
        V0=Adc_Read(0);
        V1=Adc_Read(1);
        total=V0+V1;
        /* Now Channel 2, brake pedal */
        V2=Adc_Read(2);
        /* Repeat for Channel 3, brake light level setting pot. */
        V3=Adc_Read(3);

          /* Now decide if Brake light should be on.  */
        if (V2>V3) Brake_light=1;
           else Brake_light=0;
        /* Switch on-board LED for diagnostics      */
        PORTC.F5=Brake_light;

        /* Transmit the accelerator and brake pedal settings   */
        value=V0/5; /* Scale to 0 to 200 from 0 to 1023 */
        if (value>200) value=200;
        if ((value==lastValue)&&(value>60)) c++;
           else c=0;
        /* If the throttle pos is stuck, and over 30% for more than
           5*20= 120 loops, i.e. 5 seconds, then assume stuck. */
        if (c>120) error_flag.F1=1;
            else error_flag.F1=0;
        if (c>130) c=130; /* Stop c reseting to 0 by going over 255 */
        lastValue=value;
         
        /* Now check pedals are not stuck. The total reading from both
          pots should be 1023, as one falls as the other rises. Initially
          allow 300 either side of this. */
        if ((total<723)||(total>1323)) error_flag.F0=1;
            else error_flag.F0=0;
         
        /* Now set up the data for message 0x80 */
        CANdata[0]=value;
        /* Scale the brake pedal setting to 0-200 */
        value=V2/5;
        CANdata[1]=value;
        CANdata[2]=error_flag;
        id=0x80;
        CANWrite(id, CANdata, 3, send_flag);
        /* Transmit brake light message, which has id 0x200 */
        CANdata[0]=Brake_light;
        id=0x200;
        CANWrite(id, CANdata, 1, send_flag);
         
        Tcount20Hz=0;
    } /* End of things done at 20Hz    */

    if (Tcount1Hz>1000){  /* Do this at 1 Hz, roughly    */
        if (state202==0){
            error_flag.F6=1;
        }
        else{
            state202--;
            error_flag.F6=0;
        }
        if (state50==0){
            error_flag.F7=1;
        }
        else{
            state50--;
            error_flag.F7=0;
        }
                
        if (stateLight==0)
            error_flag.F3=1;
        else{
            stateLight--;
            error_flag.F3=0;
        }
                
                
                Tcount1Hz=0;
        }
                


        dt = CANRead(&id, CANdata, &len, &read_flag);
                
        if (dt>0){ /*Message received     */
                      if (id==0x202){
                            state202=WaitingPeriods;
                            error_flag.F4=CANdata[0].F1;
                            error_flag.F5=CANdata[0].F2;
                            if (Brake_light == CANdata[0].F0)
                                 stateLight=WaitingPeriods;
                      }
                            
                      if (id==0x50){
                            state50=WaitingPeriods;
                            tempX10= (CANdata[0]<<8) + CANdata[1];
                            if  (tempX10>600) error_flag.F2=1;
                                else error_flag.F2=0;
                      }
                   }


    } /* End of endless loop    */
}   /* End of void main()   */
Example #12
0
// Now we have the main procedure.
void main()
{
  unsigned char CANdata[8];
  unsigned char A, B; // scratch-pad variables
  long id;
  unsigned short send_flag, dt, len, read_flag;
  float chargeInc=0;
  float energyInc=0;
  float x,y,E,Q;  // floats used for energy and charge calcs.
 
  // Set up the structures for the CANbus messages that are transmitted
  // by this node. See manual. These relate to its the system status, and
  // the total charge and energy used.
  struct CAN
  {
         long id;
         short len;
         unsigned char mdata[8];
  }errors, totals;
   errors.id=1024;
   errors.len=2;
   totals.id=1025;
   totals.len=3;
   
// Get the CANbus ready
send_flag = _CAN_TX_PRIORITY_0 & _CAN_TX_NO_RTR_FRAME;
CANbus_setup();
// Set up and start the timing interrupts
setup_interrupts();
// setup the ports
TRISA =0xFF;  // PORTA is input
ADCON1 =0x07;  // Configure AN pins 0-3 as digital I/O, page 242
TRISC = 0;   // PORT C is for output

// Read the energy and charge values out of EEPROM.
charge=EEPROM_Read(1);
delay_ms(20);
A = EEPROM_Read(2); //LSB of energy value
delay_ms(20);
B = EEPROM_Read(3); //MSB of energy value
energy = (B*256) + A;

E=energy;   // Convert charge and energy to float
Q=charge;


  for(;;)     /* Endless loop   */
  {
     WhatState();
     IndicateState();
     SetErrorFlags();
     OperateRL3();
     // See if any CAN messages in.
     dt = CANRead(&id, CANdata, &len, &read_flag);
            if (dt>0) { /*Message received     */
                   if (id==128){
                   FN_flags= CANdata[2]; // Map Fn errors
                   Accel = CANdata[0];  // Accel postion, 0-200
                   }
                   if (id==150){
                      I=(CANdata[0] + (CANdata[1]<<8));   // NB V and I are x10
                      V=(CANdata[2] + (CANdata[3]<<8));
                   }
                   if (id==512) brakelight=CANdata[0];
                   if  (id==1026){
                      T1=CANdata[0];
                      T2=CANdata[1];
                   }
                   if (id==1280){
                      energy=0, E=0, energyInc=0;
                      charge=0, Q=0, chargeInc=0;
                   }
             } // end of dealing with messages.
             
     if (Tcount1Hz>1000){   // Do this at 1 Hz
        Tcount1Hz=0;
        // Update float values of energy and charge totals.
        // E is in 10th of Watt hours, and Q is in 10th of Ah.
        E = E + (energyInc/360);
        energyInc=0;
        Q = Q + ((chargeInc/100)/360);
        chargeInc=0;
        // And udate low res integer values as well
        energy=E;
        charge=Q;
        // Send out the two CAN messages.
        errors.mdata[1]=state;
        errors.mdata[0]=ERR_FLAG;
        CANWrite(errors.id, errors.mdata, errors.len, send_flag);
        // Now set up the CAN charge and energy message, and write the data
        // to EEPROM.
        totals.mdata[0]=charge;
        EEPROM_write(1,charge);
        totals.mdata[1]=energy;
        EEPROM_write(2,totals.mdata[1]);
        totals.mdata[2]=energy>>8; // MS byte second
        EEPROM_write(3,totals.mdata[2]);
        CANWrite(totals.id, totals.mdata, totals.len, send_flag);
          } // end of 1 Hz actions
     if (Tcount10Hz>100) { // Do this at 10Hz
        Tcount10Hz=0;
        x = I;  // Be careful to do anything tricky while float
        chargeInc = (chargeInc + x);
        // chargeInc is in coulombs, and x100
        // Remember that I and V are both x10
        y = V;
        energyInc = (energyInc + ((x*y/1000)));
        // energyInc is the energy in Joules
        } // end of 10Hz energy and charge calculations.
     } /* End of endless loop    */
/******************************************************************************
* Name:        main
* Description: Program entry point
* 
* Returns:     int   - returns 0 if no errors
******************************************************************************/
int main() {

   /* declare a network interface and network addresses */
   struct netif *netif, server_netif;  
   struct ip_addr ipaddr, netmask, gw;

   /* specify a unique MAC address for the board */
   #ifdef XPAR_CPU_PPC440_CORE_CLOCK_FREQ_HZ    /* set MAC on ML507 board */
   unsigned char mac_ethernet_address[] = {0x00, 0x0a, 0x35, 0x01, 0xC9, 0x76};
   #else                                        /* set MAC on ML410 board */
   unsigned char mac_ethernet_address[] = {0x00, 0x0a, 0x35, 0x01, 0x9A, 0xFE};
   #endif

   /* set the network interface pointer */
   netif = &server_netif;

   /* enable caches */
   XCache_EnableICache( INSTR_CACHE );
   XCache_EnableDCache( DATA_CACHE );

   /* setup interrupts */
   setup_interrupts();

   /* initliaze network addresses to be used */
   IP4_ADDR( &ipaddr,  192, 168,  1, 15 );
   IP4_ADDR( &netmask, 255, 255, 255, 0 );
   IP4_ADDR( &gw,      192, 168,  1,  1 );

   /* print the application header and IP settings */
   print_app_header();
   print_ip_settings(&ipaddr, &netmask, &gw);

   /* initialize lwip */
   lwip_init();

   /* add network interface to the netif_list, and set it as default */
   if( !xemac_add( netif, &ipaddr, &netmask, &gw,
                   mac_ethernet_address, EMAC_BASEADDR ) ) {
      xil_printf( "Error adding N/W interface\n\r" );
      return -1;
   }
   netif_set_default( netif );

   /* now enable interrupts */
   enable_interrupts();

   /* specify that the network if is up */
   netif_set_up( netif );

   /* start the application */
   start_application();
   
   /* print debug header if debug mode set */
   #ifdef QMFIR_DEBUG
   debug_menu();
	while( 1) {
		qmfir_debug();
	}
   #endif   

   /* receive and process packets */
   while( 1 ) {
      xemacif_input( netif );
   }

   /* disable caches */
   XCache_DisableDCache();
   XCache_DisableICache();

   return 0;

} /* main */