コード例 #1
0
ファイル: WSNDemo.c プロジェクト: amedhiou/pinoccio-ide
static void APP_TaskHandler(void)
{
  switch (appState)
  {
    case APP_STATE_INITIAL:
    {
      appInit();
    } break;

    case APP_STATE_SEND:
    {
      appSendData();
    } break;

    case APP_STATE_SENDING_DONE:
    {
#if APP_ENDDEVICE
      appState = APP_STATE_PREPARE_TO_SLEEP;
#else
      SYS_TimerStart(&appDataSendingTimer);
      appState = APP_STATE_WAIT_SEND_TIMER;
#endif
    } break;

    case APP_STATE_PREPARE_TO_SLEEP:
    {
      if (!NWK_Busy())
      {
        NWK_SleepReq();
        appState = APP_STATE_SLEEP;
      }
    } break;

    case APP_STATE_SLEEP:
    {
      ledsClose();

      PHY_SetRxState(false);

      HAL_Sleep(APP_SENDING_INTERVAL);
      appState = APP_STATE_WAKEUP;
    } break;

    case APP_STATE_WAKEUP:
    {
      NWK_WakeupReq();

      ledsInit();
      ledOn(LED_NETWORK);

      PHY_SetRxState(true);

      appState = APP_STATE_SEND;
    } break;

    default:
      break;
  }
}
コード例 #2
0
ファイル: bsp.c プロジェクト: dweb-x/CaseAlarm
void bspInit(void) {
  lowLevelInit();
  ledsInit();
  buttonsInit();
  accelerometerInit();
  potentiometerInit();
  lcdInit();
}
コード例 #3
0
ファイル: dimmer.c プロジェクト: strangecontraption/dimmer
//-----------------------------------------------------------------
// Main
//-----------------------------------------------------------------
int main(void)
{
    uint8_t uiResult;
    
    pllInit();

    // Turn off analogue inputs
    ANSELB = PORTB_ANSEL;
    ANSELC = 0x0000;
    ANSELD = PORTD_ANSEL;
    ANSELE = 0x0000;
    ANSELG = 0x0000;

    memset(lastestDmxBuffer, 0, NUM_DIMMER_CHANNELS);
    memset(lastOutputBuffer, 0, NUM_DIMMER_CHANNELS);

    // Startup
    ioMuxInit();
    eepromInit();
    eepromLoad();
    lcdInit();
    buttonsInit();
    uiInit();
    ledsInit();
    phaseAngleInit();
    dmxInit(eepromGetDmxAddress());

    // Timer 1 setup - overflow at 100Hz
    TMR1  = 0;
    PR1   = 25000;
    T1CON = 0x8010;     // 1:8 prescale (2.5MHz)
    _T1IF = 0;

    while(1)
    {
        if(_T1IF)
        {   // 100 Hz Timer stuff
            _T1IF = 0;
            buttonsCheck();
            ledsCheck();
            uiResult = uiCheck();
        }
        else
        {
            uiResult = 0;
        }

        if(uiResult || dmxCheck())
        {
            updateDimmers();
        }

        lcdCheck();
    }
}
コード例 #4
0
int main(void) {
  u08 c;
  char buffer[7];
  int  num=1;
  bool isFlowControlOn = true;
  bool isHexModeOn = false;

  ledsSet(1);
  ledsInit();
  
  ledsSet(2);
  uartInit( UART_BAUD_SELECT( 9600, F_CPU ) );
  
  ledsSet(3);
  uartFlowControlOn( true );
  
  ledsSet(4);
  uartPutString("String stored in SRAM\n");
  
  ledsSet(5);    
  uartPutString("String stored in FLASH\n");
  
  ledsSet(6);        
  itoa( num, buffer, 10);       // convert interger into string (decimal format)         
  uartPutString(buffer);        // and transmit string to UART
  uartPutString( "\n" );
  
  ledsSet(7);    
  //while ( !uartIsCharAvailable() ) {
    //do nothing
  //}
  //c = uartBlockingGetChar();
  uartPutString( "You pressed: " );
  //uartPutChar( c );
  uartPutString( "\n" );
  
  for(;;) {
    ledsSet(11);    
    c = uartBlockingGetChar();
    //_delay_ms( 100 );
    ledsSet(12);    
    
    if ( c == 'V' ) {
      uartPutString( "testSerial: " );
      uartPutString( __DATE__ );
      uartPutString( " " );
      uartPutString( __TIME__ );
      uartPutString( "\n" );
    } else if ( c == 'B' ) {
      MCUCR = _BV(IVCE);
      MCUCR = _BV(IVSEL);               //move interruptvectors to the boot sector sector
      asm volatile("jmp 0x3800");
    } else if ( c == 'F' ) {
コード例 #5
0
int main(void) {
  ledsInit();
  timerInit();

  //move interruptvectors to the Boot sector
  // this strange sequence ( two separate lines ) is necessary
  MCUCR = _BV(IVCE); 
  MCUCR = _BV(IVSEL);

  sei();
  motorsInit();

  uartInit( UART_BAUD_SELECT( 115200, F_CPU ) );
  uartFlowControlOn( 0 );

  uartPutStringCRLF( PROMPT );
  while(1) {   

    // if more than a second has elapsed
    if ( s_timeoutExpired  && !s_stayInBootLoader ) {
      jumpToApplication();
    }

    if ( getLine() ) {
      if ( !strcmp( s_buffer, UPLOAD_PAGE_COMMAND ) ) {
	s_stayInBootLoader = 1;
	uploadPage();
      } else if ( !strcmp( s_buffer, CHECK_PAGE_COMMAND ) ) {
	s_stayInBootLoader = 1;
	checkPage();
      } else if ( !strcmp( s_buffer, QUIT_COMMAND ) ) {
	jumpToApplication();
      } else if ( !strcmp( s_buffer, "" ) ) {
	s_stayInBootLoader = 1;
	// don't do anything for blank lines
      } else {
	uartPutStringCRLF( CMD_UNKNOWN );
      }
      uartPutStringCRLF( PROMPT );      
    }
  }
  
  return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: KuanYuChen/mansos
int main(void)
{
    // Make sure all interrupts are disabled.
    // This must be the first step, because in some cases interupt vectors are totally wrong
    // (e.g. when we get here after a soft reboot from another application)
    msp430ClearAllInterruptsNosave();

    msp430WatchdogStop();

    ledsInit();

    flashLeds(LEDS_BOOTLOADER_START);

    BootParams_t bootParams;
    intFlashRead(BOOT_PARAMS_ADDRESS, &bootParams, sizeof(bootParams));

    ++bootParams.bootRetryCount;
    if (bootParams.bootRetryCount > MAX_RETRY_COUNT) {
        bootParams.bootRetryCount = 0;
        bootParams.extFlashAddress = GOLDEN_IMAGE_ADDRESS;
        bootParams.doReprogramming = 1;
    }

    // make sure internal flash address is sane
    if (bootParams.intFlashAddress == 0xffff || bootParams.intFlashAddress < BOOTLOADER_END) {
        bootParams.intFlashAddress = SYSTEM_CODE_START;
    }

    // read voltage, and quit if not enough for writing in flash
    if (readVoltage() < THRESHOLD_VOLTAGE) {
        flashLeds(LEDS_LOW_BATTERY);
        goto exec;
    }

    // write the updated info back in flash
    intFlashErase(BOOT_PARAMS_ADDRESS, sizeof(bootParams));
    intFlashWrite(BOOT_PARAMS_ADDRESS, &bootParams, sizeof(bootParams));

    if (bootParams.doReprogramming) {
        redLedOn();

        // will be using external flash
        extFlashInit();
        extFlashWake();

        uint32_t extAddress = bootParams.extFlashAddress;

        // read number of blocks
        uint16_t imageBlockCount;
        extFlashRead(extAddress, &imageBlockCount, sizeof(uint16_t));
        extAddress += 2;

        while (imageBlockCount) {
            // read a block from external flash
            ExternalFlashBlock_t block;
            extFlashRead(extAddress, &block, sizeof(block));

            if (block.crc != crc16((uint8_t *)&block, sizeof(block) - 2)) {
                // the best we can do is to reboot now;
                // after a few tries the golden image will be loaded
                flashLeds(LEDS_CRC_ERROR);
                // no need to disable all of the interrupts (they already are),
                // just write in watchdog timer wihout password, it will generate reset.
                watchdogRebootSimple();
            }

            bool firstBlockInChunk = block.address & 0x1;
            block.address &= ~0x1;
            if (firstBlockInChunk) {
                // prepare internal flash to be written
                intFlashErase(block.address, INT_FLASH_SEGMENT_SIZE);
            }

            // program internal flash
            COMPILE_TIME_ASSERT(sizeof(block.data) == INT_FLASH_BLOCK_SIZE, ifs);
            intFlashWriteBlock(block.address, block.data, INT_FLASH_BLOCK_SIZE);

            --imageBlockCount;
            extAddress += sizeof(ExternalFlashBlock_t);
        }

        extFlashSleep();
        redLedOff();
    }

#if ENABLE_BOOT_DELAY
    // delay for a second or so to allow the user to interrupt booting (by pressing the reset button)
    flashLeds(LEDS_BOOTLOADER_END);
#endif

    // execute the program
  exec:
    ((ApplicationStartExec)bootParams.intFlashAddress)();
}
コード例 #7
0
void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.print(SELF_NAME);
  Serial.println(F(" started..."));

  #ifdef ETHERNET_FEATURE
    ethernetInit();
  #endif

  sdCardInit();

  #ifdef RTC_FEATURE
    rtcInit();
  #endif

  #ifdef SERVER_FEATURE
    serverInit();
  #endif

  timersInit();

  #ifdef MAJORDOMO_FEATURE
    majordomoInit();
    majordomoMegaLive();
  #endif

  #ifdef LAURENT_FEATURE
    laurentInit();
  #endif

  #ifdef SD_INFO_FEATURE
    sdInfoInit();
  #endif

  #ifdef SD_FILES_FEATURE
    sdFilesInit();
  #endif

  #ifdef PING_FEATURE
    pingInit();
  #endif

  #ifdef UPLOAD_FEATURE
    uploadInit();
  #endif

  #ifdef PIRS_FEATURE
    pirsInit();
  #endif

  #ifdef CONTACTS_FEATURE
    contactsInit();
  #endif

  #ifdef TEMP_FEATURE
    tempInit();
  #endif

  #ifdef ELECTRO_FEATURE
    electroInit();
  #endif

  #ifdef KEYS_FEATURE
    keysInit();
  #endif

  #ifdef LEDS_FEATURE
    ledsInit();
  #endif

  #ifdef NOO_FEATURE
    nooInit();
  #endif

  timeStamp();
  Serialprint("GLOBAL Init DONE\n");
  Serial.println();
  timeStamp();
  Serialprint("AMS WORK\n");
} // setup
コード例 #8
0
ファイル: WSNDemo.c プロジェクト: amedhiou/pinoccio-ide
static void appInit(void)
{
  msg.messageType          = 1;
  msg.nodeType             = APP_NODE_TYPE;
  msg.extAddr              = APP_ADDR;
  msg.shortAddr            = APP_ADDR;
  msg.softVersion          = 0x01010100;
  msg.channelMask          = (1L << APP_CHANNEL);
  msg.panId                = APP_PANID;
  msg.workingChannel       = APP_CHANNEL;
  msg.parentShortAddr      = 0;
  msg.lqi                  = 0;
  msg.rssi                 = 0;

  msg.sensors.type        = 1;
  msg.sensors.size        = sizeof(int32_t) * 3;
  msg.sensors.battery     = 0;
  msg.sensors.temperature = 0;
  msg.sensors.light       = 0;

  msg.caption.type         = 32;
  msg.caption.size         = APP_CAPTION_SIZE;
  memcpy(msg.caption.text, APP_CAPTION, APP_CAPTION_SIZE);

#if APP_COORDINATOR
  // Enable RCB_BB RS232 level converter
  #if defined(PLATFORM_RCB128RFA1)
    DDRD = (1 << 4) | (1 << 6) | (1 << 7);
    PORTD = (0 << 4) | (1 << 6) | (1 << 7);
  #endif

  #if defined(PLATFORM_RCB231)
    DDRC = (1 << 4) | (1 << 6) | (1 << 7);
    PORTC = (0 << 4) | (1 << 6) | (1 << 7);
  #endif
#endif

  ledsInit();

  NWK_SetAddr(APP_ADDR);
  NWK_SetPanId(APP_PANID);
  PHY_SetChannel(APP_CHANNEL);
  PHY_SetRxState(true);

#ifdef NWK_ENABLE_SECURITY
  NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
#endif

  NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

  appDataSendingTimer.interval = APP_SENDING_INTERVAL;
  appDataSendingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appDataSendingTimer.handler = appDataSendingTimerHandler;

#if APP_ROUTER || APP_ENDDEVICE
  appNetworkStatus = false;
  appNetworkStatusTimer.interval = 500;
  appNetworkStatusTimer.mode = SYS_TIMER_PERIODIC_MODE;
  appNetworkStatusTimer.handler = appNetworkStatusTimerHandler;
  SYS_TimerStart(&appNetworkStatusTimer);
#else
  ledOn(LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  PHY_RandomReq();
#endif

  appState = APP_STATE_SEND;
}
コード例 #9
0
ファイル: MySensorCore.cpp プロジェクト: skatun/Openhab
void _begin() {
	#if !defined(MY_DISABLED_SERIAL)
	    hwInit();
	#endif

	// Call before() in sketch (if it exists)
	if (before) 
		before();

	debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILITIES ", " LIBRARY_VERSION ")\n"));

	signerInit();

	#if defined(MY_RADIO_FEATURE)
		_failedTransmissions = 0;

		// Setup radio
		if (!transportInit()) {
			debug(PSTR("Radio init failed. Check wiring.\n"));
			// Nothing more we can do
			_infiniteLoop();
		} else {
			debug(PSTR("Radio init successful.\n"));
		}
	#endif

	#if defined(MY_GATEWAY_FEATURE)
		#if defined(MY_INCLUSION_BUTTON_FEATURE)
	    	inclusionInit();
		#endif

	    // initialize the transport driver
		if (!gatewayTransportInit()) {
			debug(PSTR("Transport driver init fail\n"));
			// Nothing more we can do
			_infiniteLoop();
		}

	#endif


	#if defined(MY_LEDS_BLINKING_FEATURE)
		ledsInit();
	#endif

	// Read latest received controller configuration from EEPROM
	hwReadConfigBlock((void*)&_cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
	if (_cc.isMetric == 0xff) {
		// Eeprom empty, set default to metric
		_cc.isMetric = 0x01;
	}

	#if defined(MY_GATEWAY_FEATURE)
		// Set configuration for gateway
		_nc.parentNodeId = GATEWAY_ADDRESS;
		_nc.distance = 0;
		_nc.nodeId = GATEWAY_ADDRESS;
	#elif defined(MY_RADIO_FEATURE)
		// Read settings from eeprom
		hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
		#ifdef MY_OTA_FIRMWARE_FEATURE
			// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
			hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
		#endif

		_autoFindParent = MY_PARENT_NODE_ID == AUTO;
		if (!_autoFindParent) {
			_nc.parentNodeId = MY_PARENT_NODE_ID;
			// Save static parent id in eeprom (used by bootloader)
			hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);
			// We don't actually know the distance to gw here. Let's pretend it is 1.
			// If the current node is also repeater, be aware of this.
			_nc.distance = 1;
		} else if (!isValidParent(_nc.parentNodeId)) {
			// Auto find parent, but parent in eeprom is invalid. Try find one.
			transportFindParentNode();
		}

		if (MY_NODE_ID != AUTO) {
			// Set static id
			_nc.nodeId = MY_NODE_ID;
			// Save static id in eeprom
			hwWriteConfig(EEPROM_NODE_ID_ADDRESS, MY_NODE_ID);
		} else if (_nc.nodeId == AUTO && isValidParent(_nc.parentNodeId)) {
			// Try to fetch node-id from gateway
			transportRequestNodeId();
		}
	#endif

#ifdef MY_NODE_LOCK_FEATURE
	// Check if node has been locked down
	if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0) {
		// Node is locked, check if unlock pin is asserted, else hang the node
		pinMode(MY_NODE_UNLOCK_PIN, INPUT_PULLUP);
		// Make a short delay so we are sure any large external nets are fully pulled
		unsigned long enter = hwMillis();
		while (hwMillis() - enter < 2);
		if (digitalRead(MY_NODE_UNLOCK_PIN) == 0) {
			// Pin is grounded, reset lock counter
			hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX);
			// Disable pullup
			pinMode(MY_NODE_UNLOCK_PIN, INPUT);
			debug(PSTR("Node is unlocked.\n"));
		} else {
			// Disable pullup
			pinMode(MY_NODE_UNLOCK_PIN, INPUT);
			nodeLock("LDB"); //Locked during boot
		}
	} else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0xFF) {
		// Reset walue
		hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX);
	}
#endif

	// Call sketch setup
	if (setup)
		setup();


	#if defined(MY_RADIO_FEATURE)
		transportPresentNode();
	#endif
	if (presentation)
		presentation();

	debug(PSTR("Init complete, id=%d, parent=%d, distance=%d\n"), _nc.nodeId, _nc.parentNodeId, _nc.distance);
}
コード例 #10
0
ファイル: kernelmain.c プロジェクト: Paolo-Maffei/mansos
//----------------------------------------------------------
//      System initialization
//----------------------------------------------------------
static inline void initSystem(void)
{
    bool success;
    (void)success;

    // disable interrupts: disabled on msp430 by default, but other systems might need this
    DISABLE_INTS();

    // stop the watchdog: GCC disables it by default, but other compilers might not be so helpful
    watchdogStop();

    // TODO: init dynamic memory
    // platformMemInit();

    // basic, platform-specific initialization: timers, platform-specific drivers (?)
    initPlatform();

    // start energy accounting (as soon as timers are initialized)
    energyConsumerOn(ENERGY_CONSUMER_MCU);

#ifdef USE_PRINT
    // init printing to serial (makes sense only after clock has been calibrated)
    if (printInit != NULL) printInit();
#endif

    INIT_PRINTF("starting MansOS...\n");

#ifdef USE_LEDS
    INIT_PRINTF("init LED(s)...\n");
    ledsInit();
#endif
#ifdef USE_BEEPER
    beeperInit();
#endif
#ifdef RAMTEXT_START
    if ((MemoryAddress_t)&_end > RAMTEXT_START) {
        // Panic right aways on RAM overflow.
        // In case this happens, you might want to increase the address
        // specified by CONST_RAMTEXT_START in config file
        assertionFailed("Overflow between .data and .ramtext sections", __FILE__, __LINE__);
    }
#endif
#ifdef USE_ADC
    if (adcInit != NULL) {
        INIT_PRINTF("init ADC...\n");
        adcInit();
    }
#endif
#ifdef USE_RANDOM
    INIT_PRINTF("init RNG...\n");
    randomInit();
#endif
#if USE_ALARMS
    INIT_PRINTF("init alarms...\n");
    initAlarms();
#endif
#ifdef USE_RADIO
    INIT_PRINTF("init radio...\n");
    radioInit();
#endif
#ifdef USE_ADDRESSING
    INIT_PRINTF("init communication stack...\n");
    networkingInit();
#endif
#ifdef USE_EXT_FLASH
    INIT_PRINTF("init external flash...\n");
    extFlashInit();
#endif
#ifdef USE_SDCARD
    INIT_PRINTF("init SD card...\n");
    sdcardInit();
#endif
#ifdef USE_EEPROM
    INIT_PRINTF("init EEPROM...\n");
    eepromInit();
#endif
#ifdef USE_ISL29003
    INIT_PRINTF("init ISL light sensor...\n");
    success = islInit();
    if (!success) {
        INIT_PRINTF("ISL init failed!\n");
    }
#endif
#ifdef USE_ADS1115
    INIT_PRINTF("init ADS111x ADC converter chip...\n");
    adsInit();
#endif
#if USE_ADS8638
    INIT_PRINTF("init ADS8638 ADC converter chip...\n");
    ads8638Init();
#endif
#if USE_ADS8328
    INIT_PRINTF("init ADS8328 ADC converter chip...\n");
    ads8328Init();
#endif
#if USE_AD5258
    INIT_PRINTF("init AD5258 digital potentiometer...\n");
    ad5258Init();
#endif
#if USE_DAC7718
    INIT_PRINTF("init DAC7718 DAC converter chip...\n");
    dac7718Init();
#endif
#if USE_ISL1219
    INIT_PRINTF("init ISL1219 real-time clock chip...\n");
    isl1219Init();
#endif
#ifdef USE_HUMIDITY
    INIT_PRINTF("init humidity sensor...\n");
    humidityInit();
#endif
#ifdef USE_ACCEL
    INIT_PRINTF("init accelerometer...\n");
    accelInit();
#endif
#ifdef USE_TIMESYNC
    INIT_PRINTF("init base station time sync...\n");
    timesyncInit();
#endif
#ifdef USE_SMP
    INIT_PRINTF("init SSMP...\n");
    smpInit();
#endif
#ifdef USE_REPROGRAMMING
    INIT_PRINTF("init reprogramming...\n");
    bootParamsInit();
#endif
#ifdef USE_DCO_RECALIBRATION
    extern void dcoRecalibrationInit(void);
    INIT_PRINTF("init DCO recalibration...\n");
    dcoRecalibrationInit();
#endif
#ifdef USE_FS
    INIT_PRINTF("init file system...\n");
    fsInit();
#endif
#ifdef USE_FATFS
    INIT_PRINTF("init FAT file system...\n");
    fatFsInit();
    INIT_PRINTF("init POSIX-like file routines...\n");
    posixStdioInit();
#endif
#ifdef USE_WMP
    INIT_PRINTF("init WMP...\n");
    wmpInit();
#endif
#ifdef USE_SEAL_NET
    INIT_PRINTF("init SEAL networking...\n");
    sealNetInit();
#endif

    INIT_PRINTF("starting the application...\n");
}