Ejemplo n.º 1
0
Archivo: AD.c Proyecto: mgsit/Hand
int main(void) {
    unsigned int wait = 0;
    int readcount = 0;
    SERIAL_Init();
    INTEnableSystemMultiVectoredInt();
    mJTAGPortEnable(0);
    printf("\r\nUno A/D Test Harness\r\nThis will initialize all A/D pins and read them %d times", TIMES_TO_READ);
    printf("Value of pcfg before test: %X",AD1PCFG);


    AD_Init(AD_PORTV3 | AD_PORTV4 | AD_PORTV5 | AD_PORTV6 | AD_PORTW4 | AD_PORTW3 | BAT_VOLTAGE | PINA);
    unsigned char cur = 0;
    while (readcount <= TIMES_TO_READ) {
        for (wait = 0; wait <= 100000; wait++)
            asm("nop");
        printf("\r\nAN0\tAN1\tAN2\tAN3\tAN4\tAN5\tAN11\tAN10\n");
        printf("%d\t", ReadADPin(PINA));
        printf("%d\t", ReadADPin(BAT_VOLTAGE));
        printf("%d\t", ReadADPin(AD_PORTV3));
        printf("%d\t", ReadADPin(AD_PORTV4));
        printf("%d\t", ReadADPin(AD_PORTV5));
        printf("%d\t", ReadADPin(AD_PORTV6));
        printf("%d\t", ReadADPin(AD_PORTW4));
        printf("%d\t", ReadADPin(AD_PORTW3));
        readcount++;
    }
    printf("Done Reading Them\r\n");
    AD_End();
    printf("Value of pcfg after test: %X",AD1PCFG);
    return 0;
}
Ejemplo n.º 2
0
Archivo: AD.c Proyecto: mgsit/Hand
int main(void) {
    unsigned int wait = 0;
    int readcount = 0;
    SERIAL_Init();
    INTEnableSystemMultiVectoredInt();
    mJTAGPortEnable(0);
    printf("\r\nUno A/D Test Harness\r\nThis will initialize all A/D pins and read them %d times", TIMES_TO_READ);
    printf("Value of pcfg before test: %X",AD1PCFG);


    AD_Init(AD_PORTV3 | AD_PORTV4 | AD_PORTV5 | AD_PORTV6 | AD_PORTV7 | AD_PORTV8 | AD_PORTW3 | AD_PORTW4 | AD_PORTW5 | AD_PORTW6 | AD_PORTW7 | AD_PORTW8 | BAT_VOLTAGE);
    char numtoread = 13;
    unsigned char cur = 0;
    while (readcount <= TIMES_TO_READ) {
        for (wait = 0; wait <= 100000; wait++)
            asm("nop");
//        printf("\r\nAN2\tAN3\tAN4\tAN5\tAN8\tAN9\tAN11\tAN10\tAN13\tAN12\tAN15\tAN14\tAN1\n");
        for (cur = 0; cur < numtoread; cur++) {
            printf("%d\t", ReadADPin(1 << cur));
        }
        printf("\r\n");
        readcount++;
    }
    printf("Done Reading Them\r\n");
    AD_End();
    printf("Value of pcfg after test: %X",AD1PCFG);
    return 0;
}
Ejemplo n.º 3
0
int main(void) {
    // Initialize LED, sound and the program button pins.
    maximite_init();

    // Initial setup of the I/O ports.
    AD1PCFG = 0xFFFF;               // Default all pins to digital.
    mJTAGPortEnable(0);             // Turn off JTAG.

    // Setup the CPU.
    // System config performance.
    SYSTEMConfigPerformance(CLOCKFREQ);
    // Fix the peripheral bus to the main clock speed.
    mOSCSetPBDIV(OSC_PB_DIV_1);

    INTEnableSystemMultiVectoredInt();  // Allow vectored interrupts.

    usb_init();
    keyboard_init();       // Initialise and startup the keyboard routines.

    rk86_video_init();     // Start the video state machine.

    delay_us(1000);
    while (keyboard_inkey() != -1);

    i8080_pic32_run();

    panic(PANIC_EMULATION_TERMINATED);

    return 0;
}
Ejemplo n.º 4
0
int main(void)
{
	int i;

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Configure the device for maximum performance but do not change the PBDIV
	// Given the options, this function will change the flash wait states, RAM
	// wait state and enable prefetch cache but will not change the PBDIV.
	// The PBDIV value is already set via the pragma FPBDIV option above..
	SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);


	// Explorer16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
	mJTAGPortEnable(DEBUG_JTAGPORT_OFF);

	// Make all lower 8-bits of PORTA as output. Turn them off before changing
	// direction so that we don't have unexpected flashes
	mPORTAClearBits(BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
							 BIT_3 | BIT_2 | BIT_1 | BIT_0 );

	mPORTASetPinsDigitalOut( BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
							 BIT_3 | BIT_2 | BIT_1 | BIT_0 );

	// Now blink all LEDs ON/OFF forever.
	while(1)
	{
		mPORTAToggleBits(BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
							 BIT_3 | BIT_2 | BIT_1 | BIT_0 );

		// Insert some delay
		i = 1024*1024*10;
		while(i--);
	}
}
Ejemplo n.º 5
0
// *--------------------------------------------------------------------------------*
int main(){
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	AD1PCFG = 0xFFFF;
	LED1_OUTPUT();
	LED2_OUTPUT();
	SW1_INPUT();
	SW2_INPUT();
	
	buttonCount = 0;
    buttonPressed = FALSE;
    stringPrinted = TRUE;
	
	USBDeviceInit();	
	while(1){
		#if defined(USB_INTERRUPT)
		if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE)){
			USBDeviceAttach();
		}
		#endif
		#if defined(USB_POLLING)
			// Check bus status and service USB interrupts.
			USBDeviceTasks();
		#endif
		ProcessIO();
	}
}
Ejemplo n.º 6
0
int main()
{
	mJTAGPortEnable(0);
	mPORTASetPinsDigitalOut(BIT_0|BIT_1|BIT_2|BIT_3|BIT_4|BIT_5|BIT_6|BIT_7);
	mPORTAClearBits(BIT_0|BIT_1|BIT_2|BIT_3|BIT_4|BIT_5|BIT_6|BIT_7);
	INTCONSET=0x1000;
	INTEnableSystemMultiVectoredInt();
	IEC0 =0;
	IFS0 = 0;
	INTCONCLR = 0x00000018;
	IEC0SET = 0x00088000;
	IPC3 = 0x1F000000;
	IPC4 = 0X17000000;
	lcdconfig();

while(1)
{
	if(IFS0 & 0x8000==1)
	{
		lcddata('3');
		PORTA=0X0F;
	}
	if(IFS0 & 0x80000==1)
	{
		lcddata('4');
		PORTA=0XFF;
	}
}
}
Ejemplo n.º 7
0
void vParTestInitialise( void )
{
	/* All LEDs output. */	
	TRISA = ptOUTPUT;	
	PORTA = ptALL_OFF;
	
	mJTAGPortEnable( 0 );
}
Ejemplo n.º 8
0
/********************************************************************
 * Function:        static void InitializeSystem(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        InitializeSystem is a centralize initialization
 *                  routine. All required USB initialization routines
 *                  are called from here.
 *
 *                  User application initialization routine should
 *                  also be called from here.                  
 *
 * Note:            None
 *******************************************************************/
static void InitializeSystem(void)
{
    AD1PCFG = 0xFFFF;

//	The USB specifications require that USB peripheral devices must never source
//	current onto the Vbus pin.  Additionally, USB peripherals should not source
//	current on D+ or D- when the host/hub is not actively powering the Vbus line.
//	When designing a self powered (as opposed to bus powered) USB peripheral
//	device, the firmware should make sure not to turn on the USB module and D+
//	or D- pull up resistor unless Vbus is actively powered.  Therefore, the
//	firmware needs some means to detect when Vbus is being powered by the host.
//	A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and
// 	can be used to detect when Vbus is high (host actively powering), or low
//	(host is shut down or otherwise not supplying power).  The USB firmware
// 	can then periodically poll this I/O pin to know when it is okay to turn on
//	the USB module/D+/D- pull up resistor.  When designing a purely bus powered
//	peripheral device, it is not possible to source current on D+ or D- when the
//	host is not actively providing power on Vbus. Therefore, implementing this
//	bus sense feature is optional.  This firmware can be made to use this bus
//	sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the
//	HardwareProfile.h file.    
    #if defined(USE_USB_BUS_SENSE_IO)
    tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h
    #endif
    
//	If the host PC sends a GetStatus (device) request, the firmware must respond
//	and let the host know if the USB peripheral device is currently bus powered
//	or self powered.  See chapter 9 in the official USB specifications for details
//	regarding this request.  If the peripheral device is capable of being both
//	self and bus powered, it should not return a hard coded value for this request.
//	Instead, firmware should check if it is currently self or bus powered, and
//	respond accordingly.  If the hardware has been configured like demonstrated
//	on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the
//	currently selected power source.  On the PICDEM FS USB Demo Board, "RA2" 
//	is used for	this purpose.  If using this feature, make sure "USE_SELF_POWER_SENSE_IO"
//	has been defined in HardwareProfile.h, and that an appropriate I/O pin has been mapped
//	to it in HardwareProfile.h.
    #if defined(USE_SELF_POWER_SENSE_IO)
    tris_self_power = INPUT_PIN;	// See HardwareProfile.h
    #endif
    
    UserInit();

    USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    					//variables to known states.

    // Configure the proper PB frequency and the number of wait states
	SYSTEMConfigWaitStatesAndPB(80000000L);

    // Enable the cache for the best performance
	CheKseg0CacheOn();	

 	mJTAGPortEnable(0);
	PMCONbits.ON = 0;

}//end InitializeSystem
Ejemplo n.º 9
0
Archivo: gpio.c Proyecto: ChakChel/Ix
/**
 * @fn      void gpioInit( void );
 * @brief   Configuration des GPIO
 */
void gpioInit( void ) {
    
    // Désactivation du JTAG pour accéder aux LEDs
    mJTAGPortEnable( DEBUG_JTAGPORT_OFF );

    // RD1 en sortie
    PORTSetPinsDigitalOut( IOPORT_D, BIT_1 );

    // Initialisation de RD1 au niveau bas
    mPORTDClearBits( BIT_1 );
}
Ejemplo n.º 10
0
// *--------------------------------------------------------------------------------*
int main(){
	UINT16 Count=0;
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	LED1_OUTPUT();
	LED2_OUTPUT();
	INTEnableSystemMultiVectoredInt();
	deviceAttached = FALSE;
    //Initialize the stack
    USBInitialize(0);
    
	while(1){
		//USB stack process function
        USBTasks();
		if(++Count==0){
			LED1_TOGGLE();
		}
        //if thumbdrive is plugged in
        if(USBHostMSDSCSIMediaDetect()){
            deviceAttached = TRUE;
            LED1_OFF();
            //now a device is attached
            //See if the device is attached and in the right format
            if(FSInit()){
                //Opening a file in mode "w" will create the file if it doesn't
                //  exist.  If the file does exist it will delete the old file
                //  and create a new one that is blank.
                myFile = FSfopen("test.txt","w");

                //Write some data to the new file.
                FSfwrite("This is a test.",1,15,myFile);                

                //Always make sure to close the file so that the data gets
                //  written to the drive.
                FSfclose(myFile);

                //Just sit here until the device is removed.
                while(deviceAttached == TRUE){
                    USBTasks();
                    if(++Count==0){
						LED2_TOGGLE();
					}
                }
                LED2_OFF();
            }
        }
	}
}
Ejemplo n.º 11
0
void InitializeSystem()
{
	SYSTEMConfigWaitStatesAndPB(CLOCK_FREQ);
	mOSCSetPBDIV(OSC_PB_DIV_4);  // Set to get 20MHz PB clock
  //mOSCSetPBDIV(OSC_PB_DIV_2);
	CheKseg0CacheOn();
	mJTAGPortEnable(0);

	// Initialize the pins to all digital output and driven to ground.
	// Exception is RE7 and RE6 which are switch inputs
	PORTSetPinsDigitalIn(IOPORT_E, BIT_6);
	PORTSetPinsDigitalIn(IOPORT_E, BIT_7);

	mPORTASetPinsDigitalOut(0xFFFF);
	mPORTBSetPinsDigitalOut(0xFFFF);
	mPORTCSetPinsDigitalOut(0xFFFF);
	mPORTDSetPinsDigitalOut(0xFFFF);
	mPORTESetPinsDigitalOut(0xFF3F);
	mPORTFSetPinsDigitalOut(0xFFFF);
	mPORTGSetPinsDigitalOut(0xFFFF);

	mPORTAClearBits(0xFFFF);
	mPORTBClearBits(0xFFFF);
	mPORTCClearBits(0xFFFF);
	mPORTDClearBits(0xFFFF);
	mPORTEClearBits(0xFF3F);
	mPORTESetBits(0x000F);		// LED latches need to be set high for off
	mPORTFClearBits(0xFFFF);
	mPORTGClearBits(0xFFFF);

	INTEnableSystemMultiVectoredInt();

  #ifdef SANITY_CHECK
  mLED_Green_On();
  #endif
	
	//LCD_Initialize();
	//WIFI_Initialize();
	//SPRINKLER_Initialize();
	//RTCC_Initialize(); 
  //SERIALUSB_Initialize();
	SDCARD_Initialize();

  TCPIP_Initialize();
}
void SYS_Initialize ( void* data )
{

    SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    
    /* Disable JTAG to free up PORTA pins */
    mJTAGPortEnable(DEBUG_JTAGPORT_OFF);

    BSP_Initialize();
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableInterrupts();
    BSP_WriteString("*** UART Interrupt-driven Application Example ***\r\n");
    BSP_WriteString("*** Type some characters and observe echo ***\r\n");


    /* Initialize the Application */
    APP_Initialize ( );

}
Ejemplo n.º 13
0
int main()
{
	mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
	mPORTFClearBits(BIT_0);

	// Make all lower 8-bits of PORTA as output
	mPORTFSetPinsDigitalOut( BIT_0 );

	// Start timer1, Fpb/256, max period
	OpenTimer1(T1_ON | T1_PS_1_256 | T1_SOURCE_INT, 0xFFFF);

	// The main loop
	while( 1)
	{
		WriteTimer1(0);
		while ( TMR1 < LONG_DELAY);
		PORTF ^= BIT_0;
		
	} 
}
Ejemplo n.º 14
0
int main()
{
    mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
    mPORTFClearBits(BIT_0);

    // Make all lower 8-bits of PORTA as output
    mPORTFSetPinsDigitalOut( BIT_0 );
    TRISE=0x0;
    PORTE = 0x0f;

    // Start timer1, Fpb/256, max period
    OpenTimer1(T1_ON | T1_PS_1_256 | T1_SOURCE_INT, 0xFFFF);

    // The main loop

    PORTSetPinsDigitalIn(IOPORT_D, BIT_5);
    mCNOpen(CN_ON, CN14_ENABLE, 0);

    // Read the port to clear any mismatch on change notice pins
    int dummy = PORTD;

    // Clear change notice interrupt flag
    ConfigIntCN(CHANGE_INT_ON | CHANGE_INT_PRI_2);

    INTEnableSystemMultiVectoredInt();

    uart1_init(115200);
    setbuf(stdin, NULL); //no input buffer (for scanf)
    setbuf(stdout, NULL); //no output buffer (for printf)

    printf ("Hello World!\r\n");


    while( 1)
    {
        putchar(getchar());
        WriteTimer1(0);
        while ( TMR1 < LONG_DELAY);
        PORTE+=1;
    }
}
Ejemplo n.º 15
0
int main()
	{	
		char arry[255]={0};
		mJTAGPortEnable(0);
		lcd_config();
		lcd_ini();
		chip_select();			       //select the slavehhjhjkhk
		
unsigned short address=0x0000;
unsigned char da_ta=0x20;
unsigned char loc=0x80;


		for(i=0x0000,n=0;n<255;i++,n++)	
		{
			lcd_ini();
			arry[n]=read_ext_eeprom(i);
			
			
		}
			
	}
Ejemplo n.º 16
0
// *--------------------------------------------------------------------------------*
int main(){
	UINT8 k=0;
	UINT16 Conversion;
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	LED1_OUTPUT();
	LED2_OUTPUT();
	LED3_OUTPUT();
	LED4_OUTPUT();
	SW1_INPUT();
	SW2_INPUT();
	
	PORTSetPinsDigitalOut(IOPORT_D, BIT_1);		// Backlight del TFT
	mPORTDSetBits(BIT_1);
	vLCDTFTInit();
	vLCDTFTFillScreen(ColorWhite);
	vADC_Init();
	while(1){
		if(SW1_STATUS()==0){
			vLCDTFTRectangle(0,0,200,319,1,Colores[k]);
			if(++k==6){k=0;}
			DelayMs(250);
		}
		if(SW2_STATUS()==0){
			LED2_TOGGLE();
			LED4_TOGGLE();
			DelayMs(250);
		}
		Conversion=ADC_Conversion();
		vLCDTFTRectangle(201,0,239,319,1,ColorWhite);
		// 1023 -> 0; 0 -> 239
		vLCDTFTRectangle(202,((-0.31183*Conversion)+319.0),238,319,1,ColorRed);
		DelayMs(50);
	}
}
Ejemplo n.º 17
0
Archivo: main.c Proyecto: ChakChel/Ix
/**
 * @fn      void userInit( void );
 * @brief   Configuration des périphériques
 */
void userInit( void ) {

    unsigned int    periphBusClk;

    // Config Système
    // Cache (wait states) et bus périphériques
    // retourne la vitesse de travail du bus périphérque (non utilisée)
    periphBusClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    // Désactivation du JTAG pour accéder aux LEDs
    mJTAGPortEnable( DEBUG_JTAGPORT_OFF );

    // Config UART
    uartInit();
//    uartPutString("UART configured\r\n");

    //Config GPIO
    gpioInit();
//    uartPutString("GPIO configured\r\n");

    // Config PWM
    timerInit();
    pwmInit();
//    uartPutString("PWM configured\r\n");

    // Config SPI
    spiChannel  = ads7885Pic32Open( CHN_SPI, 20 );
//    uartPutString("SPI configured\r\n");

    // Init du l'algorithme de commande
    mesure[2][pMesure]=ads7885Pic32Read( CHN_SPI,3);//data_VO;
    init_stockage(mesure[2][pMesure],pwm,ref);

    // Config CAN1
    CAN1Init();
//    uartPutString("CAN configured\r\n");
}
Ejemplo n.º 18
0
int main(void) {
    // Initial setup of the I/O ports.
    AD1PCFG = 0xFFFF;               // Default all pins to digital.
    mJTAGPortEnable(0);             // Turn off JTAG.

    // Setup the CPU.
    // System config performance.
    SYSTEMConfigPerformance(CLOCKFREQ);
#if defined(MAXIMITE) || (defined(UBW32) && defined(__DEBUG)) || \
    defined(DUINOMITE)
    // Fix the peripheral bus to the main clock speed.
    mOSCSetPBDIV(OSC_PB_DIV_1);
#endif

    INTEnableSystemMultiVectoredInt();  // Allow vectored interrupts.

    keyboard_init();       // Initialise and startup the keyboard routines.
    video_init();          // Start the video state machine.
    video_clear_screen();  // Clear the video buffer.

    DelayUs(1*1000*1000);
    while (keyboard_inkey() != -1);

    video_display_string("MAXIMITE console\r\n");

    while (1) {
      int ch = input_key();
      video_put_char(ch);
      {
          static char buf[10];
          sprintf(buf, "<%02X>", ch);
          video_display_string(buf);
      }
      if (ch == '\n') video_put_char('\r');
    }
}
Ejemplo n.º 19
0
int main(void)
{
    unsigned int wait = 0;
    int readcount = 0;
    unsigned int CurPin = 0;
    unsigned int PinListing = 0;
    char FunctionResponse = 0;
    char TestFailed = FALSE;
    //SERIAL_Init();
    //INTEnableSystemMultiVectoredInt();
    BOARD_Init();
    mJTAGPortEnable(0);
    printf("\r\nUno A/D Test Harness\r\nThis will initialize all A/D pins and read them %d times\r\n", TIMES_TO_READ);
    //printf("Value of pcfg before test: %X\r\n", AD1PCFG);
    // while(!IsTransmitEmpty());
    //AD_Init(BAT_VOLTAGE);
    //AD_Init();
    printf("Testing functionality before initialization\r\n");

    /*adding pins individually */
    printf("AD_AddPins on each pin indvidually which results in failure: ");
    for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) {
        FunctionResponse = AD_AddPins(CurPin);
        if (FunctionResponse != ERROR) {
            TestFailed = TRUE;
            break;
        }
    }
    if (TestFailed) {
        printf("FAIL\r\n");
    } else {
        printf("PASSED\r\n");
    }
    TestFailed = FALSE;
    /*removing pins individually*/
    printf("AD_RemovePins on each pin indvidually which results in failure: ");
    for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) {
        FunctionResponse = AD_RemovePins(CurPin);
        if (FunctionResponse != ERROR) {
            TestFailed = TRUE;
            break;
        }
    }
    if (TestFailed) {
        printf("FAIL\r\n");
    } else {
        printf("PASSED\r\n");
    }
    TestFailed = FALSE;
    /*listing pins while inactive*/
    printf("AD_ActivePins which should return 0: ");
    PinListing = AD_ActivePins();
    if (PinListing != 0x0) {
        printf("FAILED\r\n");

    } else {
        printf("PASSED\r\n");
    }
    //    /*calling ned when inactive*/
    //        printf("AD_End which should fail: ");
    //        FunctionResponse = AD_End();
    //        if (FunctionResponse != ERROR) {
    //            printf("FAILED\r\n");
    //        } else {
    //            printf("PASSED\r\n");
    //        }
    /*activating module*/
    printf("initializing using AD_Init: ");
    FunctionResponse = AD_Init();
    if (FunctionResponse != SUCCESS) {
        printf("FAILED\r\n");
    } else {
        printf("PASSED\r\n");
    }
    /*attempting to reactivate*/
    printf("initializing using AD_Init again returns error: ");
    FunctionResponse = AD_Init();
    if (FunctionResponse != ERROR) {
        printf("FAILED\r\n");
    } else {
        printf("PASSED\r\n");
    }
    printf("Testing Functionality after initialization\r\n");
    /*active pins after activation only has battery*/
    printf("Ad_ActivePins should only return BAT_VOLTAGE: ");
    PinListing = AD_ActivePins();
    if (PinListing == BAT_VOLTAGE) {
        printf("PASSED\r\n");
    } else {
        printf("FAILED\r\n");
    }
    /*each pin added should succeed*/
    printf("Adding each pin using AD_AddPins indivdually: ");
    for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) {
        PinListing = AD_ActivePins();
        FunctionResponse = AD_AddPins(CurPin);
        if (FunctionResponse != SUCCESS) {
            TestFailed = TRUE;
            break;
        }
        while (AD_ActivePins() != (PinListing | CurPin));
    }
    if (TestFailed) {
        printf("FAIL\r\n");
    } else {
        printf("PASSED\r\n");
    }
    /*removing each pin should succeed */
    printf("Removing each pin using AD_RemovePins indivdually: ");
    for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) {
        PinListing = AD_ActivePins();
        FunctionResponse = AD_AddPins(CurPin);
        if (FunctionResponse != SUCCESS) {
            TestFailed = TRUE;
            break;
        }
        while (AD_ActivePins() != (PinListing | CurPin));
    }
    if (TestFailed) {
        printf("FAIL: %X\r\n", 0xFEED);
    } else {
        printf("PASSED\r\n");
    }
    while (1);
    printf("We will now add the odd pins and wait for them to be activated");
    AD_AddPins(ODD_ACTIVE);
    while (!(AD_ActivePins() & ODD_ACTIVE)) {
        if (IsTransmitEmpty()) {
            printf("%X\r\n", AD_ActivePins());
        }
    }
    printf("The Odd pins are now active as shown by Active pins: %X\r\n", AD_ActivePins());
    printf("We will now enable the even pins and wait for them to be activated");
    AD_AddPins(EVEN_ACTIVE);
    while (!(AD_ActivePins() & EVEN_ACTIVE));
    printf("The Even pins are now active as shown by Active pins: %X\r\n", AD_ActivePins());


    char numtoread = NUM_AD_PINS;
    unsigned char cur = 0;
    DELAY(400000)
    while (readcount <= TIMES_TO_READ) {
        DELAY(100000);
        printf("\r\n");
        for (cur = 0; cur < numtoread; cur++) {
            printf("%d\t", AD_ReadADPin(1 << cur));
        }
        printf("\r\n");
        readcount++;
    }
    printf("Done Reading Them\r\n");
    AD_End();
    printf("Value of pcfg after test: %X", AD1PCFG);
    return 0;
}
Ejemplo n.º 20
0
int main(int argc, char *argv[]) {
    register char *s, *p;
    register char *pn = argv[0];

    // configure the I/O ports
    AD1PCFG = 0xFFFF; // Default all pins to digital
    mJTAGPortEnable(0); // turn off jtag

    // setup the CPU
    SYSTEMConfigPerformance(CLOCKFREQ); // System config performance
    mOSCSetPBDIV(OSC_PB_DIV_1); // fix the peripheral bus to half main clock speed
    INTEnableSystemMultiVectoredInt();

    TRISBbits.TRISB15 = 0;
 //   TRISDbits.TRISD11 = 0;
 //   ODCDbits.ODCD11 = 1;
 //   LATDbits.LATD11=0;

    TRISBbits.TRISB13 = 0;
    ODCBbits.ODCB13 = 1;
    PORTBbits.RB13=0;
#ifdef UARTConsole
    UARTInit();
#endif
    initKeyboard();

#ifdef UseVideo
    initVideo();
#endif



#ifdef CPU_SPEED
    f_flag = CPU_SPEED;
    tmax = CPU_SPEED * 10000;
#endif
    argc = 0;
    while (--argc > 0 && (*++argv)[0] == '-')
        for (s = argv[0] + 1; *s != '\0'; s++)
            switch (*s) {
                case 's': /* save core and CPU on exit */
                    s_flag = 1;
                    break;
                case 'l': /* load core and CPU from file */
                    l_flag = 1;
                    break;
#ifdef Z80_UNDOC
                case 'z': /* trap undocumented Z80 ops */
                    z_flag = 1;
                    break;
#endif
                case 'i': /* trap I/O on unused ports */
                    i_flag = 1;
                    break;
                case 'm': /* initialize Z80 memory */
                    m_flag = exatoi(s + 1);
                    s += strlen(s + 1);
                    break;
                case 'f': /* set emulation speed */
                    f_flag = atoi(s + 1);
                    s += strlen(s + 1);
                    tmax = f_flag * 10000;
                    break;
                case 'x': /* get filename with Z80 executable */
                    x_flag = 1;
                    s++;
                    p = xfn;
                    while (*s)
                        *p++ = *s++;
                    *p = '\0';
                    s--;
                    break;
                case '?':
                    goto usage;
                default:
                    printf("illegal option %c\n", *s);
#ifndef Z80_UNDOC
usage:
                    printf("usage:\t%s -s -l -i -mn -fn -xfilename\n", pn);
#else
usage:
                    printf("usage:\t%s -s -l -i -z -mn -fn -xfilename\n", pn);
#endif
                    puts("\ts = save core and cpu");
                    puts("\tl = load core and cpu");
                    puts("\ti = trap on I/O to unused ports");
#ifdef Z80_UNDOC
                    puts("\tz = trap on undocumented Z80 ops");
#endif
                    puts("\tm = init memory with n");
                    puts("\tf = CPU frequenzy n in MHz");
                    puts("\tx = load and execute filename");
                    exit(1);
            }

    putchar('\n');
    puts("#######  #####    ###            #####    ###   #     #");
    puts("     #  #     #  #   #          #     #    #    ##   ##");
    puts("    #   #     # #     #         #          #    # # # #");
    puts("   #     #####  #     #  #####   #####     #    #  #  #");
    puts("  #     #     # #     #               #    #    #     #");
    puts(" #      #     #  #   #          #     #    #    #     #");
    puts("#######  #####    ###            #####    ###   #     #");
    printf("\nRelease %s, %s\n", RELEASE, COPYR);
    printf("\nPort to PIC32 By kenseglerdesigns.com\n");
    if (f_flag > 0)
        printf("\nCPU speed is %d MHz\n", f_flag);
    else
        printf("\nCPU speed is unlimited\n");
#ifdef	USR_COM
    printf("\n%s Release %s, %s\n", USR_COM, USR_REL, USR_CPR);
#endif
    fflush(stdout);

    wrk_ram = PC = ram;
    STACK = ram +0xffff;
    memset((char *) ram, m_flag, 65536);
    if (l_flag)
        if (load_core())
            return (1);
    int_on();
    init_io();
    mon();
    if (s_flag)
        save_core();
    exit_io();
    int_off();
    return (0);
}
Ejemplo n.º 21
0
/*******************************************************************************
 * Function:    BoardInit(void)
 * PreCondition:None
 * Input:       None
 * Output:      None
 * Overview:    SPI pins and SFR, Maintenance Tasks Timer, External Interrupts,
 *              and other board issues initialization.
 * Note:        This routine needs to be called before initialising MiWi stack
 *              or invoking other function that operates on MiWi stack.
 ******************************************************************************/
void BoardInit(void){
    #if defined(__PIC32MX__)

    // RADIO INTERFACES & SPI INIT -------------------------------------------//
        #if defined HARDWARE_SPI
            /* Peripheral Bus Frequency = System Clock / PB Divider */
            unsigned int pbFreq;
            pbFreq = (DWORD) CLOCK_FREQ/(1 << mOSCGetPBDIV());

            unsigned int SPI_Clk_Freq;
            unsigned char SPI_Brg;
        #endif

        #if defined MRF24J40
            PHY_CS_TRIS = OUTPUT_PIN;
            PHY_CS = 1;
            PHY_RESETn_TRIS = OUTPUT_PIN;
            PHY_RESETn = 1;

            MRF24J40_INT_TRIS = INPUT_PIN;

            SDI_TRIS = INPUT_PIN;
            SDO_TRIS = OUTPUT_PIN;
            SCK_TRIS = OUTPUT_PIN;
            SPI_SDO = 0;
            SPI_SCK = 0;

            PHY_WAKE_TRIS = OUTPUT_PIN;
            PHY_WAKE = 1;

            MRF24J40_PWR_TRIS = OUTPUT_PIN;
            MRF24J40_PWR = 1;

            SPICONCLR = 0xFFFFFFFF;             // Clear SPIxCON register

            #ifdef HARDWARE_SPI
                /* Enable SPI, Set to Master Mode & Set CKE bit : Serial output
                 * data changes on transition from active clock state to Idle
                 * clock state */
                SPICON = 0x00008120;

                /* PB Frequency can be maximum 40 MHz */
                if(pbFreq > (2 * MAX_SPI_CLK_FREQ_FOR_P2P)){
                    SPI_Brg = 1;
                    /* Continue the loop till you find SPI Baud Rate Reg Value */
                    while(1){
                        /* SPI Clock Calculation as per PIC32 Manual */
                        SPI_Clk_Freq = pbFreq / (2 * (SPI_Brg + 1));

                        if(SPI_Clk_Freq <= MAX_SPI_CLK_FREQ_FOR_P2P){
                            break;
                        }
                        SPI_Brg++;
                    }
                    #if defined MRF24J40_IN_SPI1
                    mSpiChnSetBrg (1, SPI_Brg);
                    #elif defined MRF24J40_IN_SPI2
                    mSpiChnSetBrg (2, SPI_Brg);
                    #elif defined MRF24J40_IN_SPI3
                        mSpiChnSetBrg (1A, SPI_Brg);
                    #elif defined MRF24J40_IN_SPI4
                        mSpiChnSetBrg (3A, SPI_Brg);
                    #endif
               }
               else{
                    #if defined MRF24J40_IN_SPI1
                    mSpiChnSetBrg (1, 0);
                    #elif defined MRF24J40_IN_SPI2
                    mSpiChnSetBrg (2, 0);
                    #elif defined MRF24J40_IN_SPI3
                        mSpiChnSetBrg (1A, 0);
                    #elif defined MRF24J40_IN_SPI4
                        mSpiChnSetBrg (3A, SPI_Brg);
                    #endif
               }
            #endif
        #endif
        #if defined(MRF49XA_1)
            // pruebas de funcionamiento
   /*        MRF49XA_1_PHY_CS_TRIS    = OUTPUT_PIN;
             MRF49XA_1_PHY_CS = 0;
             MRF49XA_1_PHY_CS = 1;

             MRF49XA_1_PHY_RESETn_TRIS  = OUTPUT_PIN;
             MRF49XA_1_PHY_RESETn = 0;
             MRF49XA_1_PHY_RESETn = 1;

             MRF49XA_1_INT_TRIS = OUTPUT_PIN;
             MRF49XA_1_INT_PIN = 0;
             MRF49XA_1_INT_PIN = 1;

             MRF49XA_1_SDI_TRIS = OUTPUT_PIN;
             MRF49XA_1_SPI_SDI = 0;
             MRF49XA_1_SPI_SDI = 1;

             MRF49XA_1_SDO_TRIS = OUTPUT_PIN;
             MRF49XA_1_SPI_SDO = 0;
             MRF49XA_1_SPI_SDO = 1;

             MRF49XA_1_SCK_TRIS = OUTPUT_PIN;
             MRF49XA_1_SPI_SCK = 0;
             MRF49XA_1_SPI_SCK = 1;

             MRF49XA_1_nFSEL_TRIS = OUTPUT_PIN;
             MRF49XA_1_nFSEL = 0;
             MRF49XA_1_nFSEL = 1;

             MRF49XA_1_FINT_TRIS = OUTPUT_PIN;
             MRF49XA_1_FINT = 0;
             MRF49XA_1_FINT = 1;
*/
            // configuration.   Juan: Added; Agus: Modified to a standard way
            MRF49XA_1_PHY_CS_TRIS = OUTPUT_PIN;
            MRF49XA_1_PHY_CS = 1;
            MRF49XA_1_PHY_RESETn_TRIS = OUTPUT_PIN;
            MRF49XA_1_PHY_RESETn = 1;

            MRF49XA_1_INT_TRIS = INPUT_PIN;

            MRF49XA_1_SDI_TRIS = INPUT_PIN;
            MRF49XA_1_SDO_TRIS = OUTPUT_PIN;
            MRF49XA_1_SCK_TRIS = OUTPUT_PIN;
            MRF49XA_1_SPI_SDO = 0;
            MRF49XA_1_SPI_SCK = 0;

            MRF49XA_1_nFSEL_TRIS = OUTPUT_PIN;
            MRF49XA_1_FINT_TRIS = INPUT_PIN;
            MRF49XA_1_nFSEL = 1;          // nFSEL inactive





            #ifdef cNGD_PLATFORM
//                MRF49XA_1_PWR_TRIS = OUTPUT_PIN;
//                MRF49XA_1_PWR = 1;
            #endif

            MRF49XA_1_SPICONCLR = 0xFFFFFFFF;       //Clear SPIxCON register

            #ifdef HARDWARE_SPI
                /* Enable SPI1, Set to Master Mode & Set CKE bit : Serial output
                * data changes on transition from active clock state to Idle
                * clock state */
                MRF49XA_1_SPICON = 0x00008120;

                /* PB Frequency can be maximum 40 MHz */
                if(pbFreq > (2 * MAX_SPI_CLK_FREQ_FOR_P2P)){
                    SPI_Brg = 1;
                    /* Continue the loop till you find SPI Baud Rate Reg Value */
                    while(1){
                        /* SPI Clock Calculation as per PIC32 Manual */
                        SPI_Clk_Freq = pbFreq / (2 * (SPI_Brg + 1));
                        if(SPI_Clk_Freq <= MAX_SPI_CLK_FREQ_FOR_P2P){
                            break;
                        }
                        SPI_Brg++;
                    }
                    #if defined MRF49XA_1_IN_SPI1
                    mSpiChnSetBrg (1, SPI_Brg);
                    #elif defined MRF49XA_1_IN_SPI2
                    mSpiChnSetBrg (2, SPI_Brg);
                    #elif defined MRF49XA_1_IN_SPI3
                        mSpiChnSetBrg (1A, SPI_Brg);
                    #endif
               }
               else{
                    #if defined MRF49XA_1_IN_SPI1
                    mSpiChnSetBrg (1, 0);
                    #elif defined MRF49XA_1_IN_SPI2
                    mSpiChnSetBrg (2, 0);
                    #elif defined MRF49XA_1_IN_SPI3
                        mSpiChnSetBrg (1A, 0);
                    #endif
               }
            #endif
        #endif
        #if defined(MRF49XA_2)

            MRF49XA_2_PHY_CS_TRIS = OUTPUT_PIN;
            MRF49XA_2_PHY_CS = 1;
            MRF49XA_2_PHY_RESETn_TRIS = OUTPUT_PIN;
            MRF49XA_2_PHY_RESETn = 1;

            MRF49XA_2_INT_TRIS = 1;

            MRF49XA_2_SDI_TRIS = INPUT_PIN;
            MRF49XA_2_SDO_TRIS = OUTPUT_PIN;
            MRF49XA_2_SCK_TRIS = OUTPUT_PIN;
            MRF49XA_2_SPI_SDO = 0;
            MRF49XA_2_SPI_SCK = 0;

            MRF49XA_2_nFSEL_TRIS = OUTPUT_PIN;
            MRF49XA_2_FINT_TRIS = INPUT_PIN;
            MRF49XA_2_nFSEL = 1;          // nFSEL inactive

            #ifdef cNGD_PLATFORM
                MRF49XA_2_PWR_TRIS = OUTPUT_PIN;
                MRF49XA_2_PWR = 1;
            #endif

            MRF49XA_2_SPICONCLR = 0xFFFFFFFF;       // Clear SPIxCON register

            #ifdef HARDWARE_SPI
                /* Enable SPI1, Set to Master Mode & Set CKE bit : Serial output
                * data changes on transition from active clock state to Idle
                * clock state */
                MRF49XA_2_SPICON = 0x00008120;

                /* PB Frequency can be maximum 40 MHz */
                if(pbFreq > (2 * MAX_SPI_CLK_FREQ_FOR_P2P)){
                    SPI_Brg = 1;
                    /* Continue the loop till you find SPI Baud Rate Reg Value */
                    while(1){
                        /* SPI Clock Calculation as per PIC32 Manual */
                        SPI_Clk_Freq = pbFreq / (2 * (SPI_Brg + 1));
                        if(SPI_Clk_Freq <= MAX_SPI_CLK_FREQ_FOR_P2P){
                            break;
                        }
                        SPI_Brg++;
                    }
                    #if defined MRF49XA_2_IN_SPI1
                    mSpiChnSetBrg (1, SPI_Brg);
                    #elif defined MRF49XA_2_IN_SPI2
                    mSpiChnSetBrg (2, SPI_Brg);
                    #elif defined MRF49XA_2_IN_SPI3
                        mSpiChnSetBrg (1A, SPI_Brg);
                    #endif
               }
               else{
                    #if defined MRF49XA_2_IN_SPI1
                    mSpiChnSetBrg (1, 0);
                    #elif defined MRF49XA_2_IN_SPI2
                    mSpiChnSetBrg (2, 0);
                    #elif defined MRF49XA_2_IN_SPI3
                        mSpiChnSetBrg (1A, 0);
                    #endif
               }
            #endif
        #endif
        #if defined MRF89XA
            Data_nCS_TRIS = 0;
            Config_nCS_TRIS = 0;
            Data_nCS = 1;
            Config_nCS = 1;
            PHY_IRQ1_TRIS = 1;

            //... REVIEW...
        #endif

    // SPI & EXTERNAL INTERRUPTS PINS AND CONFIGURATION ----------------------//
        /* Set the SPI Port Directions (SDO, SDI, SCK) for every SPI module.*/
            #if defined SPI1_IN_USE
  
                SDI1_TRIS = INPUT_PIN;   //DIGITAL IN
                SDO1_TRIS = OUTPUT_PIN;  //DIGITAL OUT
                SCK1_TRIS = OUTPUT_PIN;  //DIGITAL OUT

            #endif

            #if defined SPI2_IN_USE

                SDI2_TRIS = INPUT_PIN;   //DIGITAL IN
                SDO2_TRIS = OUTPUT_PIN;  //DIGITAL OUT
                SCK2_TRIS = OUTPUT_PIN;  //DIGITAL OUT

            #endif

            #if defined SPI3_IN_USE

                SDI3_TRIS = INPUT_PIN;   //DIGITAL IN
                SDO3_TRIS = OUTPUT_PIN;  //DIGITAL OUT
                SCK3_TRIS = OUTPUT_PIN;  //DIGITAL OUT

            #endif

            #if defined SPI4_IN_USE

                SDI4_TRIS = INPUT_PIN;   //DIGITAL IN
                SDO4_TRIS = OUTPUT_PIN;  //DIGITAL OUT
                SCK4_TRIS = OUTPUT_PIN;  //DIGITAL OUT

            #endif

        /* Set the external interrups Pin Directions and Priority*/
            #if defined INT1_IN_USE

                INT1_TRIS = INPUT_PIN; // DIGITAL IN
                mINT1SetIntPriority(4);
                mINT1SetIntSubPriority(2);
                mINT1SetEdgeMode(0);                //0: Falling Edge.
                // Enable INT1
                mINT1IntEnable(1); 
            #endif
            #if defined INT2_IN_USE
                
                INT2_TRIS = INPUT_PIN; // DIGITAL IN
                mINT2SetIntPriority(4);
                mINT2SetIntSubPriority(2);
                mINT2SetEdgeMode(0);                //0: Falling Edge.
                /* Enable INT2 */
                mINT2IntEnable(1);
            #endif
            #if defined INT3_IN_USE
                
                INT3_TRIS = INPUT_PIN; // DIGITAL IN
                mINT3SetIntPriority(4);
                mINT3SetIntSubPriority(2);
                mINT3SetEdgeMode(0);                //0: Falling Edge.
                /* Enable INT3 */
                mINT3IntEnable(1);
            #endif
            #if defined INT4_IN_USE
               
                INT4_TRIS = INPUT_PIN; // DIGITAL IN
                mINT4SetIntPriority(4);
                mINT4SetIntSubPriority(2);
                mINT4SetEdgeMode(0);                //0: Falling Edge.
                /* Enable INT4 */
                mINT4IntEnable(1);
            #endif

     // LEDs
        #ifdef cNGD_PLATFORM
               mJTAGPortEnable(0); //Needed due to multiplexed pins
            
               LED1_TRIS = OUTPUT_PIN;
               LED2_TRIS = OUTPUT_PIN;
               LED3_TRIS = OUTPUT_PIN;
               LED1 = 0;
               LED2 = 0;
               LED3 = 0;
                              
        #endif


    // TIMER 1 FOR TIME_SYNC -------------------------------------------------//
        #if defined(ENABLE_TIME_SYNC)   
        //TIMER 1 MAY BE USED FOR SLEEP MODE AND/OR FOR STACKS MAINTENANCE. IT
        //NEEDS ADAPTATION BEFORE ENABLING TIME_SYNC WITH TIMER 1 TOO!
            T1CON = 0;
            T1CON = 0x0012;
            T1CONSET = 0x8000;
            PR1 = 0xFFFF;
            IFS0bits.T1IF = 0;

            mT1IntEnable(1);
            mT1SetIntPriority(4);

            while(T1CONbits.TWIP);
            TMR1 = 0;
        #endif
    // TIMER 1 FOR NODE STACKS AUTO-MAINTENANCE ------------------------------//
        #if defined NODE_DOES_MAINTENANCE_TASKS
            T1CON = 0x0070;             //Disable timer, PBCLK source, PS=256
            TMR1  = 0x0000;             //Reset count
            PR1   = MAINTENANCE_PERIOD; //Set period.

            IPC1SET = 0x00000005;   //Set Priority level 1, Subpriority level 1
            IFS0CLR = 0x00000010;   //Clear T1IF
            IEC0SET = 0x00000010;   //Set T1IE
            //Timer will be triggered after initialization.
        #endif
//************************************* TODO
    // IOPORT CN - For waking up the node manually. --------------------------//
        mPORTDSetPinsDigitalIn(BIT_5); // CN14
        CNCON = 0x8000;         //Module enabled.
        CNEN = 0x00004000;      //Enable CN14
        CNPUE = 0x00004000;     //Enable CN14 weak pull-up.
        ReadBUTTONS();          //Clear PORT mismatch condition.
        IFS1CLR = 0x00000001;   //Clear the CN interrupt flag status bit
        IPC6SET = 0x00180000;   //Set CN priority 6, subpriority 0.
        //It will be enabled only during sleep mode time interval
    //------------------------------------------------------------------------//
																										// Lo modifico en el wifi config
        #if defined(ENABLE_NVM)     //REVIEW
            //EE_nCS_TRIS = 0;//FERNANDO, CUIDADO NO SE SI LA PILA REALMENTE FUNCIONA CON FLASH MEMORY
            //EE_nCS = 1;
        #endif

    // INTERRUPTION FLAGS AND EXT_INT PIN FINAL SETTINGS ---------------------//
        #if defined MRF49XA_1
            MRF49XA_1_IF = 0;
            if(MRF49XA_1_INT_PIN == 0){
                MRF49XA_1_IF = 1;
            }
        #endif
        #if defined MRF49XA_2
            MRF49XA_2_IF = 0;
            if(MRF49XA_2_INT_PIN == 0){
                MRF49XA_2_IF = 1;
            }
        #endif
        #if defined MRF89XA
            PHY_IRQ1 = 0;
        #endif
        #if defined MRF24J40
            MRF24J40_IF = 0;
            if(MRF24J40_INT_PIN == 0){
                MRF24J40_IF = 1;
            }
        #endif

    #else   //Not PIC32.
        #error "Unknown target board."
    #endif
}
Ejemplo n.º 22
0
void InitializeSystem() {

#ifdef BOARD_UBW32
    // Disable ADC port (allows PORTB to be used for digital I/O)
    AD1PCFG = 0xFFFF;

    TRISE = 0x0000;
    TRISB = 0x0000;
    TRISC = 0x0000;
    TRISD = 0x0000;
    LATE = 0x0000;
    LATB = 0x0000;
    LATC = 0x0000;
    LATD = 0x0000;
#endif
#ifdef BOARD_HEXLIGHT
    ANSELA = 0x0000;
    ANSELB = 0x0000;
#endif
    LATA = 0x0000;
    LATB = 0x0000;

    // Ensure LED drivers are driven low as soon as possible
//    _TRIS(PIO_OC1) = 0;
//    _TRIS(PIO_OC2) = 0;
//    _TRIS(PIO_OC3) = 0;
//    _TRIS(PIO_OC4) = 0;
//    _LAT(PIO_OC1) = OUTPUT;
//    _LAT(PIO_OC2) = OUTPUT;
//    _LAT(PIO_OC3) = OUTPUT;
//    _LAT(PIO_OC4) = OUTPUT;

    // Force disconnect of USB bootloader
    U1CON = 0x00000000;
    U1PWRC = 0x00000000;

    // LEDs
//    _TRIS(PIO_LED1) = OUTPUT;
//    _TRIS(PIO_LED2) = OUTPUT;
#ifdef BOARD_UBW32
    _TRIS(PIO_LED3) = OUTPUT;
    _TRIS(PIO_LED_USB) = OUTPUT;
    _TRIS(PIO_BTN_PGM) = 1;
    _TRIS(PIO_BTN_USR) = 1;
#elif BOARD_HEXLIGHT
    _TRIS(PIO_BTN1) = INPUT;
    _TRIS(PIO_BTN2) = INPUT;
#endif

//    _TRIS(PIO_USBP) = INPUT;
//    _TRIS(PIO_USBN) = INPUT;

//    _LAT(PIO_LED1) = LOW;
//    _LAT(PIO_LED2) = LOW;
#ifdef BOARD_UBW32
    _LAT(PIO_LED3) = HIGH;
    _LAT(PIO_LED_USB) = LOW;
#endif

    mJTAGPortEnable(0);

    // Initializethe PIC32 core
    //OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_2, OSC_FRC_POST_2);
    sys_clock = F_SYSCLK;
    mOSCSetPBDIV(OSC_PB_DIV_1);
    pb_clock = SYSTEMConfig(sys_clock, SYS_CFG_ALL);


    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableInterrupts();

    // Initialize core time base
    SystickInit();
}
Ejemplo n.º 23
0
main()
{
    // Disable JTAG (on RA0 and RA1 )
    mJTAGPortEnable( DEBUG_JTAGPORT_OFF );

    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    initializeUART();
    initializeADC();
    initializeLCD();
    initializeRPG();
    
    /* Initialize SD card */
    setup_SDSPI();
    SD_setStart();
    /* Fill tempBuffer[] with int 0 to 63
     * Write it to the current block.
     * Empty tempBuffer[] to all 0.
     * Read from the current block to make sure that it returns the right value.
     */
    fillTempBuffer();
    testSDReadWrite(tempBuffer);

    curr_read_block = curr_block;
    
    ConfigTimer1(); // Enable Timer1 for second counts
    configureInterrupts();

    // T2CON = 0x8030; // TMR1 on, prescale 1:256 PB

    mPORTASetPinsDigitalOut( LED_MASK ); // LEDs = output
    mPORTDSetPinsDigitalIn( PB_MASK_D ); // PBs on D = input

    curr_state = READY;
    // enable interrupts
    INTEnableInterrupts();
    int i = 0;
    while( 1 )
    {
        if (getPrintToUARTFlag() == 1){
            LCDMenuControl();
        
            //mPORTAToggleBits( LED_MASK );
            convertAndPrintIntegerToString("i => ", i++);
            convertAndPrintIntegerToString("timeElapse => ", timeElapsed);
            convertAndPrintIntegerToString("timeElapsedLEDSample => ", timeElapsedLEDSample);
            convertAndPrintIntegerToString("timeElapsedLEDTurnedOff => ", timeElapsedLEDTurnedOff);
            convertAndPrintIntegerToString("sampleLEDNow => ", sampleLEDNow);

            convertAndPrintIntegerToString(" ADC Value => ", getChannel5Value());
            printShadowDetect();
            printLightLevel();
            drawLightDetectedBar();
            controlPowerRelay();

            switch(curr_state) {
            case READY : WriteString("State => READY     ");
                        break;
            case SLEEP : WriteString("State => SLEEP    ");
                        break;
            case HIBERNATE : WriteString("State => HIBERNATE");
                        break;
            case BUSY : WriteString("State => BUSY     ");
                        break;
            }

            WriteString("\r");
            
            setPrintToUARTFlag(0);
        }
        if (NEW_BYTE_RECEIVED == 1){
            curr_state = READY;
            NEW_BYTE_RECEIVED = 0;
            //mPORTAToggleBits( LED_MASK );
            char tempArray[] = "g";
            tempArray[0] = characterByteReceived;
            WriteString(tempArray);
            if(curr_state = HIBERNATE) {
                addByteToBuffer(characterByteReceived);
            }
            else {
                PutCharacter(characterByteReceived);
            }
        }
        if(bufferIndex == 512) {
            SDWriteBlock(currBlock);
            currBlock++;
            bufferIndex = 0;
        }
         if((curr_state == READY) && (timeElapsed >= SLEEP_TIMEOUT) && (timeElapsed < HIBERNATE_TIMEOUT)) {
             curr_state = SLEEP;
         }
         else if((curr_state == SLEEP) && (timeElapsed >= HIBERNATE_TIMEOUT)) {
             curr_state = HIBERNATE;
             timeElapsed = 0;
         }
        if (transmitDataFromSDCard == 1) {
            transmitDataFromSDCard = 0;
            forwardDataToPrinter();
        }
    } // main (while) loop

    return 0;

} // main
Ejemplo n.º 24
0
//******************************************************************************
//******************************************************************************
// Main
//******************************************************************************
//******************************************************************************
int main (void)
{
	BYTE i;
	DWORD temp;

	int  value;

	value = SYSTEMConfigWaitStatesAndPB( GetSystemClock() );

	mJTAGPortEnable(DEBUG_JTAGPORT_OFF);

	// Enable the cache for the best performance
	CheKseg0CacheOn();

	value = OSCCON;
	while (!(value & 0x00000020))
	{
		value = OSCCON;    // Wait for PLL lock to stabilize
	}

	InitKeyboardDriver();

	INTEnableSystemMultiVectoredInt();

	// Init status LED
	mPORTCSetBits(BIT_0);
	mPORTCSetPinsDigitalOut(BIT_0);

	//DBINIT();

	// Initialize USB layers
	USBInitialize(0);

	while (1)
	{
		USBTasks();
		App_Detect_Device();
		switch (App_State_Keyboard)
		{
			case DEVICE_NOT_CONNECTED:
				mPORTCSetBits(BIT_0);
				USBTasks();
				if (DisplayDeatachOnce == FALSE)
				{
					DBPRINTF("Device Detached\n");
					DisplayDeatachOnce = TRUE;
				}
				if (USBHostHID_ApiDeviceDetect()) /* True if report descriptor is parsed with no error */
				{
					DBPRINTF("Device Attached\n");
					App_State_Keyboard = DEVICE_CONNECTED;
					DisplayConnectOnce = FALSE;
				}
				break;
			case DEVICE_CONNECTED:
				mPORTCClearBits(BIT_0);
				App_State_Keyboard = READY_TO_TX_RX_REPORT;
				if (DisplayConnectOnce == FALSE)
				{
					DisplayConnectOnce = TRUE;
					DisplayDeatachOnce = FALSE;
				}
				InitializeTimer(); // start 10ms timer to schedule input reports

				break;
			case READY_TO_TX_RX_REPORT:
				if (!USBHostHID_ApiDeviceDetect())
				{
					App_State_Keyboard = DEVICE_NOT_CONNECTED;
					//                                DisplayOnce = FALSE;
				}
				break;
			case GET_INPUT_REPORT:
				if (USBHostHID_ApiGetReport(Appl_raw_report_buffer.Report_ID, Appl_ModifierKeysDetails.interfaceNum,
																		Appl_raw_report_buffer.ReportSize, Appl_raw_report_buffer.ReportData))
				{
					/* Host may be busy/error -- keep trying */
				}
				else
				{
					App_State_Keyboard = INPUT_REPORT_PENDING;
				}
				USBTasks();
				break;
			case INPUT_REPORT_PENDING:
				if (USBHostHID_ApiTransferIsComplete(&ErrorDriver, &NumOfBytesRcvd))
				{
					if (ErrorDriver || (NumOfBytesRcvd !=     Appl_raw_report_buffer.ReportSize ))
					{
						ErrorCounter++ ;
						if (MAX_ERROR_COUNTER <= ErrorDriver)
							App_State_Keyboard = ERROR_REPORTED;
						else
							App_State_Keyboard = READY_TO_TX_RX_REPORT;
					}
					else
					{
						ErrorCounter = 0;
						ReportBufferUpdated = TRUE;
						App_State_Keyboard = READY_TO_TX_RX_REPORT;

						if (DisplayConnectOnce == TRUE)
						{
							for (i = 0; i < Appl_raw_report_buffer.ReportSize; i++)
							{
								if (Appl_raw_report_buffer.ReportData[i] != 0)
								{
									//LCDClear();
									//LCDL1Home();
									DisplayConnectOnce = FALSE;
								}
							}
						}

						App_ProcessInputReport();
						App_PrepareOutputReport();
					}
				}
				break;

			case SEND_OUTPUT_REPORT: /* Will be done while implementing Keyboard */
				if (USBHostHID_ApiSendReport(Appl_LED_Indicator.reportID, Appl_LED_Indicator.interfaceNum, Appl_LED_Indicator.reportLength,
																		(BYTE*) & Appl_led_report_buffer))
				{
					/* Host may be busy/error -- keep trying */
				}
				else
				{
					App_State_Keyboard = OUTPUT_REPORT_PENDING;
				}
				USBTasks();

				break;
			case OUTPUT_REPORT_PENDING:
				if (USBHostHID_ApiTransferIsComplete(&ErrorDriver, &NumOfBytesRcvd))
				{
					if (ErrorDriver)
					{
						ErrorCounter++ ;
						if (MAX_ERROR_COUNTER <= ErrorDriver)
							App_State_Keyboard = ERROR_REPORTED;

						//                                App_State_Keyboard = READY_TO_TX_RX_REPORT;
					}
					else
					{
						ErrorCounter = 0;
						App_State_Keyboard = READY_TO_TX_RX_REPORT;
					}
				}
				break;

			case ERROR_REPORTED:
				break;
			default:
				break;
		}
	}
}