Esempio n. 1
0
 void flashFirmware(uint8_t* source, uint32_t size){
   __disable_irq(); // Disable ALL interrupts. Can only be executed in Privileged modes.
   setLed(RED);
   eeprom_unlock();
   if(size > (16+16+64+128)*1024){
     eeprom_erase_sector(FLASH_Sector_6);
     toggleLed(); // inline
   }
   if(size > (16+16+64)*1024){
     eeprom_erase_sector(FLASH_Sector_5);
     toggleLed();
   }
   if(size > (16+16)*1024){
     eeprom_erase_sector(FLASH_Sector_4);
     toggleLed();
   }
   if(size > 16*1024){
     eeprom_erase_sector(FLASH_Sector_3);
     toggleLed();
   }
   eeprom_erase_sector(FLASH_Sector_2);
   toggleLed();
   eeprom_write_block(ADDR_FLASH_SECTOR_2, source, size);
   eeprom_lock();
   eeprom_wait();
   NVIC_SystemReset(); // (static inline)
 }
Esempio n. 2
0
/**********************************************************************
 *
 * Function:    main()
 *
 * Description: Blink the green LED once a second.
 * 
 * Notes:       This outer loop is hardware-independent.  However, it
 *              calls the hardware-dependent function toggleLed().
 *
 * Returns:     This routine contains an infinite loop.
 *
 **********************************************************************/
int
main(void)
{
    Timer  timer1;
    Timer  timer2;

    DDRC |= LED_GREEN;  /* PC2 will now be the output pin */
    DDRC |= LED_RED;  /* PC3 will now be the output pin */


//    timer.start(500, Periodic);     // Start a periodic 500-ms timer.
    timer1.start(4, Periodic);     // Start a periodic 500-ms timer.
    timer2.start(2, Periodic);     // Start a periodic 500-ms timer.

    while (1)
    {
#if 0		
		timer2.waitfor();
      	toggleLed(LED_GREEN);       // Toggle the green GREEN.
#endif 
        if (timer1.isDone() == 1)
        	toggleLed(LED_GREEN);       // Toggle the green GREEN.
        if (timer2.isDone() == 1)
        	toggleLed(LED_RED);       // Toggle the green LED.		
    }

	return 0;
}   /* main() */
Esempio n. 3
0
  /*
   * re-program firmware: this entire function and all subroutines must run from RAM
   * (don't make this static!)
   */
  __attribute__ ((section (".coderam")))
  void flashFirmware(uint8_t* source, uint32_t size){
    __disable_irq(); // Disable ALL interrupts. Can only be executed in Privileged modes.
    setLed(RED);
    eeprom_unlock();
    if(size > (16+16+64+128)*1024){
      eeprom_erase_sector(FLASH_Sector_6);
      toggleLed(); // inline
    }
    if(size > (16+16+64)*1024){
      eeprom_erase_sector(FLASH_Sector_5);
      toggleLed();
    }
    if(size > (16+16)*1024){
      eeprom_erase_sector(FLASH_Sector_4);
      toggleLed();
    }
    if(size > 16*1024){
      eeprom_erase_sector(FLASH_Sector_3);
      toggleLed();
    }
    eeprom_erase_sector(FLASH_Sector_2);
    toggleLed();
    eeprom_write_block(ADDR_FLASH_SECTOR_2, source, size);
    eeprom_lock();
    eeprom_wait();
    NVIC_SystemReset(); // (static inline)
  }

  void programFlashTask(void* p){
    int sector = flashSectorToWrite;
    uint32_t size = flashSizeToWrite;
    uint8_t* source = (uint8_t*)flashAddressToWrite;
    if(sector >= 0 && sector < MAX_USER_PATCHES && size <= 128*1024){
      uint32_t addr = getFlashAddress(sector);
      eeprom_unlock();
      int ret = eeprom_erase(addr);
      if(ret == 0)
	ret = eeprom_write_block(addr, source, size);
      eeprom_lock();
      registry.init();
      if(ret == 0){
	// load and run program
	int pc = registry.getNumberOfPatches()-MAX_USER_PATCHES+sector;
	program.loadProgram(pc);
	// program.loadDynamicProgram(source, size);
	program.resetProgram(false);
      }else{
	setErrorMessage(PROGRAM_ERROR, "Failed to write program to flash");
      }
    }else if(sector == 0xff && size < MAX_SYSEX_FIRMWARE_SIZE){
      flashFirmware(source, size);
    }else{
      setErrorMessage(PROGRAM_ERROR, "Invalid flash program command");
    }
    vTaskDelete(NULL);
  }

  void eraseFlashTask(void* p){
    int sector = flashSectorToWrite;
    if(sector == 0xff){
      for(int i=0; i<MAX_USER_PATCHES; ++i)
	eraseFlashProgram(i);
      settings.clearFlash();
    }else if(sector >= 0 && sector < MAX_USER_PATCHES){
      eraseFlashProgram(sector);
    }else{
      setErrorMessage(PROGRAM_ERROR, "Invalid flash erase command");
    }
    registry.init();
    vTaskDelete(NULL);
  }

  // static int midiMessagesToSend = 0;
  // void sendMidiDataTask(void* p){
  //   switch(midiMessagesToSend){
  //   case SYSEX_PRESET_NAME_COMMAND:
  //     midi.sendPatchNames();
  //     break;
  //   // case 0:
  //   //   midi.sendDeviceInfo();
  //   //   break;
  //   // case SYSEX_PARAMETER_NAME_COMMAND:
  //   //   midi.sendPatchParameterNames();
  //   //   break;
  //   // case SYSEX_FIRMWARE_VERSION:
  //   //   midi.sendFirmwareVersion();
  //   //   break;
  //   // case SYSEX_DEVICE_ID:
  //   //   midi.sendDeviceId();
  //   //   break;
  //   // case SYSEX_DEVICE_STATS:
  //   //   midi.sendDeviceStats();
  //   //   break;
  //   // case SYSEX_PROGRAM_MESSAGE:
  //   //   midi.sendProgramMessage();
  //   //   break;
  //   // case SYSEX_PROGRAM_STATS:
  //   //   midi.sendProgramStats();
  //   //   break;
  //   // case PATCH_BUTTON:
  //   //   midi.sendCc(PATCH_BUTTON, isPushButtonPressed() ? 127 : 0);
  //   //   break;
  //   // case LED:
  //   //   midi.sendCc(LED, getLed() == NONE ? 0 : getLed() == GREEN ? 42 : 84);
  //   //   break;
  //   // case 127:
  //   //   midi.sendSettings();
  //   //   break;
  //   }
  //   midiMessagesToSend = -1;
  //   vTaskDelete(NULL);    
  // }

#ifdef BUTTON_PROGRAM_CHANGE
#ifndef abs
#define abs(x) ((x)>0?(x):-(x))
#endif /* abs */
  void programChangeTask(void* p){
    setLed(RED);
    int pc = settings.program_index;
    int bank = getAnalogValue(0)*5/4096;
    int prog = getAnalogValue(1)*8/4096+1;
    do{
      float a = getAnalogValue(0)*5/4096.0 - 0.5/5;
      float b = getAnalogValue(1)*8/4096.0 - 0.5/8;
      //      if(a - (int)a < 0.8) // deadband each segment: [0.8-1.0)
      if(a > 0 && abs(a - (int)a - 0.1) > 0.2) // deadband each segment: [0.9-1.1]
	bank = (int)a;
      if(b > 0 && abs(b-(int)b - 0.1) > 0.2)
	prog = (int)b+1;
      if(pc != bank*8+prog){
	toggleLed();
	pc = bank*8+prog;
	updateProgramIndex(pc);
	vTaskDelay(20);
      }
    }while(isPushButtonPressed() || pc < 1 || pc >= (int)registry.getNumberOfPatches());
    setLed(RED);
    program.loadProgram(pc);
    program.resetProgram(false);
    for(;;); // wait for program manager to delete this task
  }
Esempio n. 4
0
int main(void)
{ 
	UINT32 startAddr, endAddr, lenght;
    
    initLed(LED_BIT);

    SystemInit();
    SystemCoreClockUpdate();
    
    /* Generate interrupt each 1 ms   */
    SysTick_Config(SystemCoreClock/1000 - 1);


	/** Please see the ranges in LPC1114 or LPC1227 linker script !! */
	startAddr = 0x10000000;
	endAddr = 0x10000014;
	lenght = endAddr - startAddr;

    while(1)
    {
		
		/* note that for the sake of demonstration the table is pointing to unused ram */
		/* if used ram needs to be tested, user must backup content first ! */      
		if(IEC60335_RAMtest_BIST(startAddr, lenght) == IEC60335_testFailed)
		{
		  /* RAM BIST test failed */
		  while (1);
		}  
		
		Delay(500);
		toggleLed(LED_BIT);
	}
}
int main( void )
{
    halInit();
    moduleInit();
    printf("\r\nWriting NV Items\r\n");
    result = moduleReset();
    if (result == MODULE_SUCCESS)
    {
        displaySysResetInd();  // Display the contents of the received SYS_RESET_IND message
    } else {
        printf("Module Reset ERROR 0x%02X\r\n", result);
    }
    debugConsoleIsr = &handleDebugConsoleInterrupt;   //call method handleDebugConsoleInterrupt() when a byte is received    
    HAL_ENABLE_INTERRUPTS();              //Enable Interrupts

    while (1)
    {
        uint8_t whichNvItem = getWhichNvItemToWrite();  
        if (whichNvItem != NO_CHARACTER_RECEIVED)
        {
            uint8_t nvItemSize = getNvItemSize(whichNvItem);
            printf("\r\nWriting to NV item %u, L%u:", whichNvItem, nvItemSize);    
            printHexBytes(dataToWrite, nvItemSize);
            result = sysNvWrite(whichNvItem, dataToWrite);
            if (result != MODULE_SUCCESS)
            {
                printf("sysNvWrite ERROR 0x%02X\r\n", result);
            }
        }
        toggleLed(1);        
    }
}
Esempio n. 6
0
int main(void)
{
    // set port B pin 1 to output
    DDRB  = 0x01;
    // set port b pin 1 to LOW
    PORTB = 0x00;

    // Time/Counter Control Register A Timer 0,
    // We don't want CTC or PWM
    TCCR0A = 0;
    // Set prescaler to 1024
    TCCR0B = 1<<CS02;
    TCCR0B |= 1<<CS02;

    // Initialize counter
    counter = 0;

    // Enable Overflow Interrupt
    TIMSK0 |= 1<<TOIE0;

    // Activate global interrupts
    sei();

    while (1) {
	// Every 256 cycles, reset counter and toggle LED on Port B Pin 1
	if (counter % 0x80 == 0) {
	    counter = 0;
	    toggleLed();
	}
    }

    return 0;   /* never reached */
}
/** Accelerometer interrupt service routine.
@note application must ensure that other operations are not accessing the accelerometer when interrupt fires. 
(Disable accelerometer interrupt during other communications with accelerometer, or even better, set a flag in the ISR that gets polled by your main application)
@pre accelerometerIsr function pointer points here; e.g. <code>accelerometerIsr = &handleAccelerometer;</code>
@pre global interrupts enabled
@pre accelerometer interrupt enabled; e.g. <code>halEnableAccelerometerInterrupt(NO_WAKEUP);</code>
@post interrupt is cleared
*/
void handleAccelerometer()
{
    toggleLed(0); 
    unsigned char interruptStatus = readAccelerometerRegister(ACCEL_INT_STATUS);  //will clear the interrupt
    printf("Interrupt: %s(%02X)\r\n", getAccelerometerInterruptReason(interruptStatus),interruptStatus);
    delayUs(ACCELEROMETER_DELAY_BETWEEN_OPERATIONS_US); //in case this interrupt is immediately followed by another one
}
Esempio n. 8
0
int main(void)
{
   
  

    /* Ejercicio : Completar este programa ejemplo para habilitar/deshabilitar
     * un GPIO (blink de un led conectado al puerto B de un atmega328p)
     *
     * Paso 1 : Establecer el 5to bit del puerto B como salida
     * (el puerto se puede utilizar como entrada o salida). 
     * Para esto se debe poner en '1' el 5to bit de la dirección 0x24, que 
     * es el la dirección del registro de dirección de los datos del puerto B
     * DDRB (Data Direction Register). El 5to bit estable como entrada o salida
     * el pin del atmega328p que tiene conectado un led en una board arduino
     *
     * Paso 2:
     * Luego, para habilitar/deshabilitar (poner en ALTO/BAJO HIGH/LOW)
     * esa salida específica del puerto B
     * se debe poner en '1' el 5to bit de la dirección 0x25, que es la 
     * dirección del registro que controla el estado HIGH o LOW del 
     * pin de salida. En '1' ese bit enciende el led en una board arduino
     *
     * Poniendo en 0 la dirección anterior pone en LOW el pin de salida (apaga
     * el led)
     */

     /* Escribir un bucle infinito que repita los pasos 1 y 2, con un delay
      * entre el HIGH y LOW, de modo que pueda apreciarse el blink.
      */

     /* Utilice el ejemplo para el mr3020 como referencia de ayuda */
toggleInit();


while (1)
 {
 
toggleLed (1);
 
delay_ms(200);
toggleLed(0);
 delay_ms(200);
 }


}
Esempio n. 9
0
//*****************************************************************************
//
//! bootmain
//!
//!  \param  None
//!
//!  \return uint8
//!
//!  \brief : all the board peripherals will be initialized here .
//  debug console will also be initialized for debugging info.
//
//*****************************************************************************
void  bootMain()
{
	//int status;
	//void (*p)(void);

	//
	//  Board  Initialization .
	//
					gpio_init();

					#ifdef RUN_APP
					misc_init_r(); 						//currently blank.
					#endif

				  //init drivers.

			         //  init_SYSLeds();
			         //  DispatcherUARTConfigure();
			         //  init_console(); //

			         init_wifiDriver();

			         turnLedOn(SYSLED1); 				//to indicate that we are active and initiated WLAN successfully

					#ifdef RUN_APP
			         misc_init_s();						//currently blank.
					#endif

			         //unsolicicted_events_timer_init();	// not required in the newer service packs of cc3000.


			         //__bis_SR_register(GIE);

					#ifdef RUN_APP
			         appMain();
					#else
			        systest_app();
					#endif


			         while(1)
			         {
			        	 //__bis_SR_register(LPM2_bits + GIE);

			        	 toggleLed(SYSLED1);
			        	 __no_operation();
			        	 __delay_cycles(12000000);

						#ifdef SERVICE_PACK_OLDER_THAN_
			        	 //hci_unsolicited_event_handler();		// ---- will call the function ------->    CC3000_AsyncEventCallback() { CC3000.c}
						#endif

			        	 //status=wlan_ioctl_statusget();

			         }


}
Esempio n. 10
0
  void timeExpired()
  {
    toggleLed(LED_BUILTIN);

    if (0 != blinkTimerControl)
    {
      blinkTimerControl->timeExpired();
    }
  }
Esempio n. 11
0
/** Use this to verify that putchar() is working. printf() requires a working putchar() method. 
You should see a steady stream of 'U' output to your terminal.
This test is also useful if you are implementing a software UART and need to verify bit timing */
int main( void )
{
    halInit();
    while (1)
    {
        toggleLed(0);
        printf("U");
        delayMs(1000);
    }
}
void readMessage() {
    uint8_t msg[2] = { 0x00 };
    uint16_t len = sizeof(msg);
    adk.RcvData(&len, msg);
    if(len > 0) {
        if (msg[0] == 0xf) {
            toggleLed();
        }
    }
}
Esempio n. 13
0
int main( void )
{
    halInit();                          //Initialize hardware
    unsigned char counter = 0;
    while (1) 
    {
        printf("Hello World %u\r\n", counter++);  
        toggleLed(1);         
        delayMs(1000);          
    }
}
int main( void )
{
    halInit();
    moduleInit();    
    printf("\r\n****************************************************\r\n");    
    printf("Secure Communications Example - ROUTER - using AFZDO\r\n");
    HAL_ENABLE_INTERRUPTS();

#define MODULE_START_DELAY_IF_FAIL_MS 5000

    struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER;
    defaultConfiguration.securityMode = SECURITY_MODE_PRECONFIGURED_KEYS;
    defaultConfiguration.securityKey = key;
    start:
    while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS)
    {
        printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result);
        delayMs(MODULE_START_DELAY_IF_FAIL_MS);
    }

    printf("On Network!\r\n");
    setLed(0);

    /* On network, display info about this network */
#ifdef DISPLAY_NETWORK_INFORMATION     
    displayNetworkConfigurationParameters();
    displayDeviceInformation();
#endif  

    /* Now the network is running - send a message to the coordinator every few seconds.*/
#define TEST_CLUSTER 0x77    

    while (1)
    {
        printf("Sending Message %u  ", counter++);
        result = afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 5);
        if (result == MODULE_SUCCESS)
        {
            printf("Success\r\n");
        } else {
            printf("ERROR %02X ", result);
#ifdef RESTART_AFTER_ZM_FAILURE
            printf("\r\nRestarting\r\n");
            goto start;
#else        
            printf("stopping\r\n");
            while(1);
#endif
        }
        toggleLed(1);
        delayMs(2000);
    }
}
Esempio n. 15
0
/*
 * LED Toggle Test
 */
void testToggleLed() {
	u8 mask[] = { 0xFF, INT_MASK, IMU_MASK, ROBOT_MASK, UWB_MASK };
	int number = sizeof(mask);
	int i, j;

	for (i = 0; i < number; i++) {
		for (j = 0; j < 10; j++) {
			toggleLed(mask[i]);
			usleep(100000);
		}
	}

}
Esempio n. 16
0
int main() 
{
	UART0_Init(57600);
	UART0_PrintString("Hello, world!\n");

	initLed();
	while (1) {
		toggleLed();
		UART0_Sendchar('+');
		wasteSomeTime(500);
	}

	return 0;
}
//*****************************************************************************
//
//!  \brief  Resets the State Machine
//!  
//!  \param  None
//!
//!  \return none
//!  
//
//*****************************************************************************
void resetCC3000StateMachine()
{
    cc3000state = CC3000_UNINIT;
    
    // Turn off all Board LEDs
    turnLedOff(CC3000_ON_IND);
    turnLedOff(CC3000_ASSOCIATED_IND);
    turnLedOff(CC3000_IP_ALLOC_IND);
    turnLedOff(CC3000_SERVER_INIT_IND);
    turnLedOff(CC3000_CLIENT_CONNECTED_IND);
    toggleLed(CC3000_SENDING_DATA_IND);
    turnLedOff(CC3000_UNUSED1_IND);
    turnLedOff(CC3000_FTC_IND);
}
Esempio n. 18
0
int main(void)
{
    initLed(LED_BIT);

    SystemInit();
    SystemCoreClockUpdate();

	/* Generate IRQ each 10 ms */
	SysTick_Config(SystemCoreClock/100);

	/* generate Timer32_0 interrput every 1 msec */
    CT32B0_Init(12000);

	/*********************************************
	void IEC60335_InitInterruptTest(type_InterruptTest *pIRQ, UINT32 lowerBound, UINT32 upperBound, UINT32 individualValue)

	  Used:
	    SysTick timer  : every 10 msec
		Timer32_0:       every 1 msec (this is the interrupt we want to test)

	  Main loop Timer32_0 Interrupt check is called every ~100 msec (derived from SysTick)
	  Within 100 msec, 100 Timer32_0 interrupts should have occurred
	  So:
	    lowerBound      = 99  (check for more interrupts than lower bound)
	    upperBound      = 101 (check for less interrupts than upper bound)
	    individualValue = 1   (interrupt up-counting value)

	********************************************/
    IEC60335_InitInterruptTest(&CT32B0_IntTest, 99, 101, 1);

    while (1)
    {
	    if (clock_100ms)
        {
            clock_100ms = 0;
            /* toggle green LED P0.7 */
			toggleLed(LED_BIT);

            /* Periodic IEC60335 Class B testing */
            if (IEC60335_InterruptCheck(&CT32B0_IntTest) == IEC60335_testFailed)
            {
                setLed(LED_BIT);
				while(1);
            }
        }
    }
}
Esempio n. 19
0
/**
 * This function applies an operation on a LED.
 * It is assumed that the parameters are ordered as denoted below.
 * @param uLedParams Includes the LED parameters: LED number and LED action
 * @return no return value
 */
void HttpDynamicHandler_ActOnLED(inputParams uLedInParams, outputParams *uLedOutParams)
{
    switch(uLedInParams.uLedParam.uLedAction)
    {
      case OFF:
	  turnLedOff(uLedInParams.uLedParam.uLedNumber);
	  break;
     	case ON:
	  turnLedOn(uLedInParams.uLedParam.uLedNumber);
	  break;
       case toggle:
	  toggleLed(uLedInParams.uLedParam.uLedNumber);
	  break;
      default:
	  break;
    }
}
/** Waits for messages; increments a counter when a packet was received.*/
void waitForPackets()
{
znpBuf[0] = 0;    
    packetCounter = 0;  
    while (packetCounter < NUMBER_OF_PACKETS_TO_RECEIVE) 
    {
        while (SRDY_IS_HIGH());         
        spiPoll();      
        if ((znpBuf[0] > 0) && (znpBuf[1] == 0x44) && (znpBuf[2] == 0x81))  //only increment counter if it was a AF_INCOMING_MSG
        {
            toggleLed(0);
            packetCounter++;
            znpBuf[0] = 0;  
        }
    }
    printf("%u packets received!\r\n", NUMBER_OF_PACKETS_TO_RECEIVE);    
}
Esempio n. 21
0
int main(void)
{
	initLed(LED_BIT);

    SystemInit();
    SystemCoreClockUpdate();

    /* Generate interrupt each 1 ms   */
    SysTick_Config(SystemCoreClock/1000 - 1);

    /* code will get here if test passed */
    while(1)
    {
		Delay(500);
		toggleLed(LED_BIT);
    };
}
Esempio n. 22
0
/*
 * Timer Test
 */
int timerTest(u32 int_freq) {
	//Variables
	int status;

	//Init Timer
	status = initTmrInt(int_freq);
	if (status != XST_SUCCESS) {
		myprintf("timer_int.c Could not initialize AXI Timer.\r\n");
	}

	while (1) {
		if (isTimerExpired() == BOOL_TRUE) {
			toggleLed(INT_MASK);
		}
	}

	//Return
	return status;
}
int main( void )
{
    halInit();
    moduleInit();    
    printf("\r\nResetting Module, then getting MAC Address\r\n");
    HAL_ENABLE_INTERRUPTS();
    
    result = moduleReset();
    if (result == MODULE_SUCCESS)
    {
        /* Display the contents of the received SYS_RESET_IND message */
        displaySysResetInd();  
    } else {
        printf("ERROR 0x%02X\r\n", result);
    }    
    
    while (1)
    {
        result = zbGetDeviceInfo(DIP_MAC_ADDRESS);
        if (result == MODULE_SUCCESS)
        {
            uint8_t* mac = zmBuf+SRSP_DIP_VALUE_FIELD;
            printf("MAC (as sent, LSB first):");
            printHexBytes(mac, 8);
            
            /* Note: the MAC address comes over the wire in reverse order (LSB first)
            So we swap the order of the bytes so we can display it correctly. */
            uint8_t temp[8];
            int i;
            for (i=0; i<8; i++)
            {
                temp[i] = mac[7-i];
            }
            printf("MAC (correct, MSB first):");
            printHexBytes(temp, 8);
            printf("\r\n");
        } else {
            printf("ERROR 0x%02X\r\n", result);
        }
        toggleLed(1);
        delayMs(1000);
    }
}
Esempio n. 24
0
/**
 Debug console interrupt service routine, called when a byte is received on UART.
 @pre In startup_ccs.c, UARTIntHandler is set as the ISR for the UART0 Rx and Tx interrupt
 @pre In startup_ccs.c, this function is declared, e.g:
 <pre>
 extern void UARTIntHandler(void);
 </pre>
 @pre Interrupts have been enabled, e.g:
 <pre>
 IntMasterEnable();
 IntEnable(INT_UART0);
 UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
 </pre>
 @pre UART has been configured
 @post a byte received on the UART will result in debugConsoleIsr() function pointer called
 */
void UARTIntHandler(void)
{
    toggleLed(4);
    //printf("$");
    unsigned long ulStatus;

    // Get the interrupt status.
    ulStatus = UARTIntStatus(UART0_BASE, true);

    // Clear the asserted interrupts.
    UARTIntClear(UART0_BASE, ulStatus);

    // Loop while there are characters in the receive FIFO.
    while(UARTCharsAvail(UART0_BASE))
    {
        // Read the next character from the UART and write it back to the UART.
        uint8_t c = (uint8_t) UARTCharGetNonBlocking(UART0_BASE);
        debugConsoleIsr(c);    //reading this register clears the interrupt flag
    }
}
int main( void )
{
    structInit();
    halInit();
    moduleInit();
    buttonIsr = &handleButtonPress;    
    printf("\r\n****************************************************\r\n");
    printf("Simple Application Example - COORDINATOR\r\n");
    
    routers[0].MAC_address[0] = 0x5E;
    routers[0].MAC_address[1] = 0xD2;
    routers[0].MAC_address[2] = 0x5D;
    routers[0].MAC_address[3] = 0x02;
    routers[0].MAC_address[4] = 0x00;
    routers[0].MAC_address[5] = 0x4B;
    routers[0].MAC_address[6] = 0x12;
    routers[0].MAC_address[7] = 0x00;
    
    routers[1].MAC_address[0] = 0xD3;
    routers[1].MAC_address[1] = 0xD3;
    routers[1].MAC_address[2] = 0x5D;
    routers[1].MAC_address[3] = 0x02;
    routers[1].MAC_address[4] = 0x00;
    routers[1].MAC_address[5] = 0x4B;
    routers[1].MAC_address[6] = 0x12;
    routers[1].MAC_address[7] = 0x00;
    
    HAL_ENABLE_INTERRUPTS();
    clearLeds();
    
    halRgbLedPwmInit();
    
    while (1) {
        stateMachine();    //run the state machine
        if (alarm_sounding == 1 && !alarm_silenced) {
          delayMs(2);
          toggleLed(0);
        }
    }
}
Esempio n. 26
0
int main( void )
{
    halInit();
    moduleInit();  
    printf("\r\nResetting Radio, then getting Random Number\r\n");
    moduleReset();   
    while (1)
    {
        /* Get a random number from the module */
        result = sysRandom();
        if (result == MODULE_SUCCESS)                  
        {
            /* Random number is in zmBuf. Now we use a convenience macro to read result from zmBuf */
            uint16_t randomNumber = SYS_RANDOM_RESULT();    
            printf("Random Number = %u (0x%04X)\r\n", randomNumber, randomNumber);
        } else {
            printf("ERROR 0x%02X\r\n", result);
        }
        toggleLed(1);
        delayMs(1000);
    }
}
Esempio n. 27
0
int main(void)
{
	/* PLEASE NOTE! **
	 * The _CPUregTestPOST() function is called from the ResetISR function
	 * in the cr_startup_lpc11.c file
	 */

	initLed(LED_BIT);

    SystemInit();
    SystemCoreClockUpdate();

    /* Generate interrupt each 1 ms   */
    SysTick_Config(SystemCoreClock/1000 - 1);

    /* code will get here if test passed */
    while(1)
    {
        Delay(500);
        toggleLed(LED_BIT);
    };
}
Esempio n. 28
0
/** \brief Interrupt Routine Service of the RIT timer used in ... */
void RIT_IRQHandler(void)
{
	/** \details
	 *	RIT timer interrupt to acquire a signal of 10 HZ
	 * */
	uint16_t adc_valueRead = 0;
	uint16_t dac_valueOut = 0;
	static uint16_t gain = 1<<8;

	RITCleanInterrupt();
	adc_valueRead = read_ADC_value_pooling();

	toggleLed(YELLOW_LED);

	switch(option)
	{
		case OPTION1:
			gain += 1;
			break;
		case OPTION2:
			gain -= 1;
			break;
		case OPTION3:
			gain = 0;
			break;
		case OPTION4:
			gain = adc_valueRead;
			break;
	}
	dac_valueOut = gain * adc_valueRead/(1<<8);
	if (dac_valueOut > DAC_MAX_VALUE)
	{
		dac_valueOut = DAC_MAX_VALUE;
	}
	update_DAC_value(dac_valueOut);


}
Esempio n. 29
0
int main(void)
{ 
#ifdef LPC1114
    UINT32  begin, *end;
    UINT32 length;
#endif
  
    SystemInit();
    SystemCoreClockUpdate();
  
    /* Initialize the LED indicator */  
    initLed(LED_BIT);
    
    /* Generate interrupt each 1 ms   */
    SysTick_Config(SystemCoreClock/1000 - 1);
    
#ifdef LPC1114
    end = IEC60335_TOP_ROM_POST;
    begin = (UINT32) &IEC60335_BOTTOM_ROM_POST;
    length = (UINT32) end - begin;
    StartSoftSignatureGen( begin,                         /* Start address */
                           length, /* Length */
                           &SoftflashSignature );         /* Result structure pointer */
#endif
    
    /* code will get here if test passed */
    while(1)
    {
      /* Execute the ASM version of the Flash BIST test 
       * If the test fails, it will hook to _flashPostTestFailureHook
       */
      _FLASHTestBIST();
     
      Delay(500);
      toggleLed(LED_BIT);     
    };
}
Esempio n. 30
0
/**
 * Send a file over the serial port.
 * @param file file to send
 */
int Xmodem::send(File* file) {
  _file = file;
  _packetNumber = 1;
  beginLed();

  while (true) {
    int c = serialRead();
    if (c != -1) {
      resetTimer();
      break;
    }
    delay(100);
  }

  int status = 0;
  while (true) {
    size_t bytesRead = readPacket();
    resetTimer();
    if (bytesRead > 0) {
      status = sendPacket();
      if (_packetNumber % 20 == 0) {
        toggleLed();
      }
      if (status < 0) {
        break;
      }
    }
    if (bytesRead < PACKET_SIZE) {
      break;
    }
  }
  serialWrite(EOT);
  while (serialRead() == -1);
  endLed();
  return status;
}