Ejemplo n.º 1
0
void sensorsInit(void)
{
	//Turn off TMP007
    configure_tmp_007(0);

	//Power down Gyro
	IOCPinTypeGpioOutput(BOARD_IOID_MPU_POWER);
	GPIOPinClear(BOARD_MPU_POWER);

	//Power down Mic
	IOCPinTypeGpioOutput(BOARD_IOID_MIC_POWER);
	GPIOPinClear(1 << BOARD_IOID_MIC_POWER);

	//Turn off external flash
	ext_flash_init(); //includes power down instruction

	//Turn off OPT3001
	configure_opt_3001(0);

	configure_bmp_280(0);

	//Power off Serial domain (Powered on in sensor configurations!)
	PRCMPowerDomainOff(PRCM_DOMAIN_SERIAL);
	while((PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_OFF));

	//Shut down I2C
	board_i2c_shutdown();
}
Ejemplo n.º 2
0
void initSPI(void){

	// power on
	powerEnableAuxForceOn(); 								// WUC domain
	powerEnableXtalInterface(); 							// clk WUC
	powerEnablePeriph();
	powerEnableGPIOClockRunMode();
	while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); /* Wait for domains to power on */

}
Ejemplo n.º 3
0
Void Timer_enableCC26xx(Int id)
#endif
{
    UInt gpt = INVALID_TIMER_ID;

    /* map timer ID to the appropriate driverlib ID */
    switch (id) {
        case 0: gpt = PRCM_PERIPH_TIMER0;
                break;

        case 1: gpt = PRCM_PERIPH_TIMER1;
                break;

        case 2: gpt = PRCM_PERIPH_TIMER2;
                break;

        case 3: gpt = PRCM_PERIPH_TIMER3;
                break;

        default:
                break;
    }

    /* if a valid GPT timer ID, enable the GPT ... */
    if (gpt != INVALID_TIMER_ID) {

        /* if it is not already on, turn on the PERIPH domain */
        if (PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) !=
            PRCM_DOMAIN_POWER_ON) {
            PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
            while (PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) !=
                PRCM_DOMAIN_POWER_ON) {};
        }

        /* now enable the GPT clocks */
        PRCMPeripheralRunEnable(gpt);
        PRCMPeripheralSleepEnable(gpt);
        PRCMPeripheralDeepSleepEnable(gpt);
        PRCMLoadSet();
        while(!PRCMLoadGet()){};
    }
}
Ejemplo n.º 4
0
void powerEnableSPIdomain(void){

	// power on GPIO (CS und andere Pins sind GPIO PIns)
	powerEnablePeriph();
	powerEnableGPIOClockRunMode();
		while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON));

	PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL); 		// power on in MCU power domain  -> prcm.cS
	uint32_t debug = HWREG(PRCM_BASE + PRCM_O_SSICLKGR) & PRCM_SSICLKGR_CLK_EN_SSI0; // enable clock for SSI
	HWREG(PRCM_BASE + PRCM_O_SSICLKGR) = 1;
}
Ejemplo n.º 5
0
void setLED2(void){

	// Enable Power for the IOC to clear the interrupt flag
   powerEnablePeriph();
   powerEnableGPIOClockRunMode();

	/* Wait for domains to power on */
	while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH)
		 != PRCM_DOMAIN_POWER_ON));

	GPIOPinWrite(BOARD_IOID_LED_2,1);
	//while(1);
}
Ejemplo n.º 6
0
Archivo: radio.c Proyecto: 0xBADCA7/lk
void radio_init(void) {
#if !RADIO_POLLED_MODE
	// route all IRQs to CPE0
	HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEISL) = 0;
	HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEIEN) = CPE0_MASK;

	// clear any pending
	HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEIFG) = 0;
	HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFACKIFG) = 0;

	//NVIC_EnableIRQ(rfc_cpe_0_IRQn);
	//NVIC_EnableIRQ(rfc_cpe_1_IRQn);
	NVIC_EnableIRQ(rfc_cmd_ack_IRQn);
#endif

	// Power RF domain
	PRCMPowerDomainOn(PRCM_DOMAIN_RFCORE);
	while (PRCMPowerDomainStatus(PRCM_DOMAIN_RFCORE) != PRCM_DOMAIN_POWER_ON) ;
	dprintf(INFO, "power on\n");

	// enable the RF top clock
	PRCMDomainEnable(PRCM_DOMAIN_RFCORE);
	PRCMLoadSet();
	dprintf(INFO, "top clock on\n");

	// enable all RF sub clocks
	RFCClockEnable();
	dprintf(INFO, "clocks on\n");

	thread_sleep(1000);
	rf_patch_cpe_genfsk();
	dprintf(INFO, "patched\n");

	unsigned n = radio_send_cmd(IMM_CMD(CMD_PING, 0, 0));
	dprintf(INFO, "RESPONSE %08x\n", n);
	n = radio_send_cmd(IMM_CMD(CMD_PING, 0, 0));
	dprintf(INFO, "RESPONSE %08x\n", n);

	rf_op_fw_info_t fwinfo;
	memset(&fwinfo, 0, sizeof(fwinfo));
	fwinfo.cmd = CMD_GET_FW_INFO;
	n = radio_send_cmd((uint32_t) &fwinfo);
	dprintf(INFO, "FW %d %04x %04x %04x %04x\n",
		n, fwinfo.version, fwinfo.free_ram_start,
		fwinfo.free_ram_size, fwinfo.avail_rat_ch);

	n = radio_send_cmd(IMM_CMD(CMD_START_RAT, 0, 0));
	dprintf(INFO, "START RAT %d\n", n);
}
Ejemplo n.º 7
0
// interrupts -----------------------------------------------------------
void GPIOIntHandler(void){

  uint32_t event_flags;
  static uint32_t time1 = 0,time2 = 0;

  powerEnablePeriph();
  powerEnableGPIOClockRunMode();
  /* Wait for domains to power on */
  while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON));

  time1 = time2;
  time2=AONRTCCurrentCompareValueGet();
  g_diff=time2-time1;

  /*Disable interrupts while clearing flags*/
  IntDisable(INT_EDGE_DETECT);
  /* Read interrupt flags */
  event_flags = (HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) & GPIO_PIN_MASK);
  if(event_flags){//Is an event flag set? (should always be set)
    /* Clear the interrupt flags*/
    HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) = event_flags;
    /*Wait until the flag is cleared, no new flag possible because interrupt disabled*/
    //while((HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) & GPIO_PIN_MASK));  // CRASH
  }
  /*Enable after flags cleared*/
  IntEnable(INT_EDGE_DETECT);




  powerDisablePeriph();
  // Disable clock for GPIO in CPU run mode
  HWREGBITW(PRCM_BASE + PRCM_O_GPIOCLKGR, PRCM_GPIOCLKGR_CLK_EN_BITN) = 0;
  // Load clock settings
  HWREGBITW(PRCM_BASE + PRCM_O_CLKLOADCTL, PRCM_CLKLOADCTL_LOAD_BITN) = 1;

  //To avoid second interupt with register = 0 (its not fast enough!!)
  __asm(" nop");
  __asm(" nop");
  __asm(" nop");
  __asm(" nop");
  __asm(" nop");
  __asm(" nop");
}
Ejemplo n.º 8
0
/**
 * Function documented in platform/uart.h
 */
otError otPlatUartEnable(void)
{
    PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL);

    while (PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON);

    PRCMPeripheralRunEnable(PRCM_PERIPH_UART0);
    PRCMPeripheralSleepEnable(PRCM_PERIPH_UART0);
    PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_UART0);
    PRCMLoadSet();

    while (!PRCMLoadGet());

    IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3, IOID_UNUSED, IOID_UNUSED);

    UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200,
                        UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    UARTIntRegister(UART0_BASE, UART0_intHandler);
    UARTEnable(UART0_BASE);
    return OT_ERROR_NONE;
}
Ejemplo n.º 9
0
/*
 *  ======== Power_sleep ========
 */
Power_Status Power_sleep(Power_SleepState sleepState, UArg arg0, UArg arg1)
{
    Power_Status status = Power_SOK;
    UInt xosc_hf_active = FALSE;
    Power_Event postEventLate;
    UInt32 poweredDomains = 0;
    Bool exitNow = FALSE;
    Power_Event preEvent;
    Power_Event postEvent;
    UInt32 constraints;
    Bool retainCache = FALSE;
    UInt32 modeVIMS;
    UInt taskKey;
    UInt swiKey;
    UInt hwiKey;

    /* first validate the sleep code */
    if ( sleepState != Power_STANDBY) {
        status = Power_EFAIL;
    }

    if (status == Power_SOK) {

        /* make sure Power is not still busy with a previous transition */
        hwiKey = Hwi_disable();

        if (Power_module->state == Power_ACTIVE) {

            /* set transition state to entering sleep */
            Power_module->state = Power_ENTERING_SLEEP;
        }
        else {
            exitNow = TRUE;
        }

        Hwi_restore(hwiKey);

        if (exitNow == TRUE) {
            status = Power_EBUSY;
        }

        else {

            /* setup sleep vars */
            if (sleepState == Power_STANDBY) {
                preEvent = Power_ENTERING_STANDBY;
                postEvent = Power_AWAKE_STANDBY;
                postEventLate = Power_AWAKE_STANDBY_LATE;
            }

            /* disable Task scheduling; allow Swis and Hwis for notifications */
            taskKey = Task_disable();

            /* signal all clients registered for pre-sleep notification */
            status = Power_notify(preEvent);

            /* check for any error */
            if (status != Power_SOK) {
                Power_module->state = Power_ACTIVE;
                Task_restore(taskKey);          /* re-enable scheduler */
                return (status);
            }

            /* now disable Swi scheduling */
            swiKey = Swi_disable();

            /* freeze the IOs on the boundary between MCU and AON */
            AONIOCFreezeEnable();

            /* if XOSC_HF is active, force it off */
            if(OSCClockSourceGet(OSC_SRC_CLK_HF) == OSC_XOSC_HF) {
                xosc_hf_active = TRUE;
                ti_sysbios_family_arm_cc26xx_Power_XOSC_HF(DISABLE);
            }

            /* allow AUX to power down */
            AONWUCAuxWakeupEvent(AONWUC_AUX_ALLOW_SLEEP);

            /* make sure writes take effect */
            SysCtrlAonSync();

            /* invoke specific sequences to activate sleep states... */

            if (sleepState == Power_STANDBY) {

                /* query and save domain states before powering them off */
                if (Power_getDependencyCount(DOMAIN_RFCORE)) {
                    poweredDomains |= PRCM_DOMAIN_RFCORE;
                }
                if (Power_getDependencyCount(DOMAIN_SERIAL)){
                    poweredDomains |= PRCM_DOMAIN_SERIAL;
                }
                if (Power_getDependencyCount(DOMAIN_PERIPH)) {
                    poweredDomains |= PRCM_DOMAIN_PERIPH;
                }

                /* gate running deep sleep clocks for Crypto and DMA */
                if (Power_getDependencyCount(PERIPH_CRYPTO)) {
                    PRCMPeripheralDeepSleepDisable(
                        ti_sysbios_family_arm_cc26xx_Power_db[
                            PERIPH_CRYPTO].driverlibID);
                }
                if (Power_getDependencyCount(PERIPH_UDMA)) {
                    PRCMPeripheralDeepSleepDisable(
                        ti_sysbios_family_arm_cc26xx_Power_db[
                            PERIPH_UDMA].driverlibID);
                }
                /* make sure clock settings take effect */
                PRCMLoadSet();

                /* request power off of domains in the MCU voltage domain */
                PRCMPowerDomainOff(poweredDomains | PRCM_DOMAIN_CPU);

                /* request uLDO during standby */
                PRCMMcuUldoConfigure(true);

                /* query constraints to determine if cache should be retained */
                constraints = Power_getConstraintInfo();
                if ((constraints & Power_SB_VIMS_CACHE_RETAIN) != 0) {
                    retainCache = TRUE;
                }

                /* if don't want retention in standby, disable it now ... */
                if (retainCache == FALSE) {
                    modeVIMS = VIMSModeGet(VIMS_BASE);
                    /* wait if invalidate in progress... */
                    while (modeVIMS == VIMS_MODE_CHANGING) {
                        modeVIMS = VIMSModeGet(VIMS_BASE);
                    }
                    PRCMCacheRetentionDisable();
                    VIMSModeSet(VIMS_BASE, VIMS_MODE_OFF);
                }

                /* setup recharge parameters */
                SysCtrlSetRechargeBeforePowerDown(XoscInHighPowerMode);

                /* make sure all writes have taken effect */
                SysCtrlAonSync();

                /* invoke deep sleep to go to STANDBY */
                PRCMDeepSleep();

                /* if didn't retain cache in standby, re-enable retention now */
                if (retainCache == FALSE) {
                    VIMSModeSet(VIMS_BASE, modeVIMS);
                    PRCMCacheRetentionEnable();
                }

                /* force power on of AUX to keep it on when system is not
                 * sleeping; this also counts as a write to the AON interface
                 * ensuring that a following sync of the AON interface will
                 * force an update of all registers
                 */
                AONWUCAuxWakeupEvent(AONWUC_AUX_WAKEUP);
                while(!(AONWUCPowerStatusGet() & AONWUC_AUX_POWER_ON)) {};

                /* if XOSC_HF was forced off above, initiate switch back */
                if (xosc_hf_active == TRUE) {
                    ti_sysbios_family_arm_cc26xx_Power_XOSC_HF(ENABLE);
                }

                /* restore power domain states in effect before standby */
                PRCMPowerDomainOn(poweredDomains);
                while (PRCMPowerDomainStatus(poweredDomains) !=
                    PRCM_DOMAIN_POWER_ON){};

                /* restore deep sleep clocks of Crypto and DMA */
                if (Power_getDependencyCount(PERIPH_CRYPTO)) {
                    PRCMPeripheralDeepSleepEnable(
                        ti_sysbios_family_arm_cc26xx_Power_db[
                            PERIPH_CRYPTO].driverlibID);
                }
                if (Power_getDependencyCount(PERIPH_UDMA)) {
                    PRCMPeripheralDeepSleepEnable(
                        ti_sysbios_family_arm_cc26xx_Power_db[
                            PERIPH_UDMA].driverlibID);
                }
                /* make sure clock settings take effect */
                PRCMLoadSet();
            }

            /* release request for uLDO */
            PRCMMcuUldoConfigure(false);

            /* set transition state to EXITING_SLEEP */
            Power_module->state = Power_EXITING_SLEEP;

            /*
             * signal clients registered for early post-sleep notification;
             * this should be used to initialize any timing critical or IO
             * dependent hardware
             */
            status = Power_notify(postEvent);

            /* disable IO freeze and ensure RTC shadow value is updated */
            AONIOCFreezeDisable();
            SysCtrlAonSync();

            /* re-enable interrupts */
            CPUcpsie();

            /* signal all clients registered for late post-sleep notification */
            status = Power_notify(postEventLate);

            /* now clear the transition state before re-enabling scheduler */
            Power_module->state = Power_ACTIVE;

            /* re-enable Swi scheduling */
            Swi_restore(swiKey);

            /* adjust recharge parameters */
            SysCtrlAdjustRechargeAfterPowerDown();

            /* re-enable Task scheduling */
            Task_restore(taskKey);

            /* check for any notification error */
            if (status != Power_SOK) {
                return (status);
            }
        }
    }

    return (status);
}
Ejemplo n.º 10
0
/*
 *  ======== Power_setDependency ========
 *  Declare a dependency upon a resource.
 */
Bool Power_setDependency(Power_Resource resourceID)
{
    UInt8 parent;
    UInt8 count;
    UInt32 id;
    UInt key;

    /* disable interrupts */
    key = Hwi_disable();

    /* read and increment reference count */
    count = ti_sysbios_family_arm_cc26xx_Power_refCount[resourceID]++;

    /* if resource was NOT activated previously ... */
    if (count == 0) {

        /* propagate set up the dependency tree ... */

        /* check for a first parent */
        parent = ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags
          & PARENTMASK;

        /* if first parent, make recursive call to set that dependency */
        if (parent != NOPARENT) {
            Power_setDependency(parent);
        }

        /* check for a second parent */
        parent = ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags2
          & PARENTMASK;

        /* if second parent, make recursive call to set that dependency */
        if (parent != NOPARENT) {
            Power_setDependency(parent);
        }

        /* now activate this resource ... */
        id = ti_sysbios_family_arm_cc26xx_Power_db[resourceID].driverlibID;

        /* is resource a peripheral?... */
        if (ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags & PERIPH) {
            PRCMPeripheralRunEnable(id);
            PRCMPeripheralSleepEnable(id);
            PRCMPeripheralDeepSleepEnable(id);
            PRCMLoadSet();
            while(!PRCMLoadGet()){};
        }

        /* else, does resource require a special handler?... */
        else if (ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags
            & SPECIAL) {

            /* call the special handler */
            ti_sysbios_family_arm_cc26xx_Power_resourceHandlers[id](ENABLE);
        }

        /* else resource is a power domain */
        else {
            PRCMPowerDomainOn(id);
            while (PRCMPowerDomainStatus(id) != PRCM_DOMAIN_POWER_ON) {};
        }
    }

    /* re-enable interrupts */
    Hwi_restore(key);

    /* return the resource's activation status */
    return (ti_sysbios_family_arm_cc26xx_Power_isDependencyActive(resourceID));
}
Ejemplo n.º 11
0
/*
 *  ======== Power_releaseDependency ========
 *  Release a previously declared dependency.
 */
Void Power_releaseDependency(Power_Resource resourceID)
{
    UInt8 parent;
    UInt8 count;
    UInt32 id;
    UInt key;

    /* disable interrupts */
    key = Hwi_disable();

    /* read and decrement the reference count */
    count = ti_sysbios_family_arm_cc26xx_Power_refCount[resourceID];

    Assert_isTrue(count != 0, Power_A_tooManyCallsReleaseDependency);

    ti_sysbios_family_arm_cc26xx_Power_refCount[resourceID] = count - 1;

    /* if this was the last dependency being released.., */
    if (count == 1) {

        /* deactivate this resource ... */
        id = ti_sysbios_family_arm_cc26xx_Power_db[resourceID].driverlibID;

        /* is resource a peripheral?... */
        if (ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags
            & PERIPH) {
            PRCMPeripheralRunDisable(id);
            PRCMPeripheralSleepDisable(id);
            PRCMPeripheralDeepSleepDisable(id);
            PRCMLoadSet();
            while(!PRCMLoadGet()){};
        }

        /* else, does resource require a special handler?... */
        else if (ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags
            & SPECIAL) {

            /* call the special handler */
            ti_sysbios_family_arm_cc26xx_Power_resourceHandlers[id](DISABLE);
        }

        /* else resource is a power domain */
        else {
            PRCMPowerDomainOff(id);
            while (PRCMPowerDomainStatus(id) != PRCM_DOMAIN_POWER_OFF) {};
        }

        /* propagate release up the dependency tree ... */

        /* check for a first parent */
        parent = ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags
          & PARENTMASK;

        /* if 1st parent, make recursive call to release that dependency */
        if (parent != NOPARENT) {
            Power_releaseDependency(parent);
        }

        /* check for a second parent */
        parent = ti_sysbios_family_arm_cc26xx_Power_db[resourceID].flags2
          & PARENTMASK;

        /* if 2nd parent, make recursive call to release that dependency */
        if (parent != NOPARENT) {
            Power_releaseDependency(parent);
        }
    }

    /* re-enable interrupts */
    Hwi_restore(key);
}
Ejemplo n.º 12
0
 int main(void) {

  uint8_t payload[ADVLEN];

  //Disable JTAG to allow for Standby
  AONWUCJtagPowerOff();

  //Force AUX on
  powerEnableAuxForceOn();
  powerEnableRFC();

  powerEnableXtalInterface();
  

  // Divide INF clk to save Idle mode power (increases interrupt latency)
  powerDivideInfClkDS(PRCM_INFRCLKDIVDS_RATIO_DIV32);

  initRTC();

  powerEnablePeriph();
  powerEnableGPIOClockRunMode();
  /* Wait for domains to power on */
  while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON));

  sensorsInit();
  ledInit();

  //Config IOID4 for external interrupt on rising edge and wake up
  //IOCPortConfigureSet(BOARD_IOID_KEY_RIGHT, IOC_PORT_GPIO, IOC_IOMODE_NORMAL | IOC_FALLING_EDGE | IOC_INT_ENABLE | IOC_IOPULL_UP | IOC_INPUT_ENABLE | IOC_WAKE_ON_LOW);

  // Config reedSwitch as input
  IOCPortConfigureSet(BOARD_IOID_DP0, IOC_PORT_GPIO, IOC_IOMODE_NORMAL | IOC_RISING_EDGE | IOC_INT_ENABLE | IOC_IOPULL_DOWN | IOC_INPUT_ENABLE | IOC_WAKE_ON_HIGH);
  //Set device to wake MCU from standby on PIN 4 (BUTTON1)
  HWREG(AON_EVENT_BASE + AON_EVENT_O_MCUWUSEL) = AON_EVENT_MCUWUSEL_WU0_EV_PAD;  //Does not work with AON_EVENT_MCUWUSEL_WU0_EV_PAD4 --> WHY??

  IntEnable(INT_EDGE_DETECT);

  powerDisablePeriph();
  //Disable clock for GPIO in CPU run mode
  HWREGBITW(PRCM_BASE + PRCM_O_GPIOCLKGR, PRCM_GPIOCLKGR_CLK_EN_BITN) = 0;
  // Load clock settings
  HWREGBITW(PRCM_BASE + PRCM_O_CLKLOADCTL, PRCM_CLKLOADCTL_LOAD_BITN) = 1;

  initInterrupts();
  initRadio();




  // baek: before while
      powerEnablePeriph();
      powerEnableGPIOClockRunMode();

       /* Wait for domains to power on */
     while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); // CRASH !!!!!!!!!!!!!!

       sensorsInit();
       ledInit();
  // end baek:


  // Turn off FLASH in idle mode
  powerDisableFlashInIdle();

  // Cache retention must be enabled in Idle if flash domain is turned off (to avoid cache corruption)
  powerEnableCacheRetention();

  //AUX - request to power down (takes no effect since force on is set)
  powerEnableAUXPdReq();
  powerDisableAuxRamRet();

  //Clear payload buffer
  memset(payload, 0, ADVLEN);

  while(1) {

  //if((g_count& 0x04)== 1){

    rfBootDone  = 0;
    rfSetupDone = 0;
    rfAdvertisingDone = 0;

	select_bmp_280();     				// activates I2C for bmp-sensor
	enable_bmp_280(1);					// works

    //Wait until RF Core PD is ready before accessing radio
    waitUntilRFCReady();
    initRadioInts();
    runRadio();

    //Wait until AUX is ready before configuring oscillators
    waitUntilAUXReady();

    //Enable 24MHz XTAL
    OSCHF_TurnOnXosc();

    //IDLE until BOOT_DONE interrupt from RFCore is triggered
    while( ! rfBootDone) {
      powerDisableCPU();
      PRCMDeepSleep();
    }

    //This code runs after BOOT_DONE interrupt has woken up the CPU again
    // ->
    //Request radio to keep on system bus
    radioCmdBusRequest(true);

    //Patch CM0 - no RFE patch needed for TX only
    radioPatch();

    //Start radio timer
    radioCmdStartRAT();

    //Enable Flash access while doing radio setup
    powerEnableFlashInIdle();

    //Switch to XTAL
    while( !OSCHF_AttemptToSwitchToXosc())
    {}
  
/* baek: before while
    powerEnablePeriph();
    powerEnableGPIOClockRunMode();

     /* Wait for domains to power on */
 /*    while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); // CRASH !!!!!!!!!!!!!!

     sensorsInit();
     ledInit();
*/
/*****************************************************************************************/
// Read sensor values


     uint32_t pressure = 0;  			// only 3 Bytes used
	//uint32_t temp = 0;
	select_bmp_280();     				// activates I2C for bmp-sensor
	enable_bmp_280(1);					// works

	do{
		pressure = value_bmp_280(BMP_280_SENSOR_TYPE_PRESS);  //  read and converts in pascal (96'000 Pa)
		//temp = value_bmp_280(BMP_280_SENSOR_TYPE_TEMP);
	}while(pressure == 0x80000000);
		if(pressure == 0x80000000){
			CPUdelay(100);

			pressure = value_bmp_280(BMP_280_SENSOR_TYPE_PRESS);  //  read and converts in pascal (96'000 Pa)

		}


    //Start Temp measurement
    uint16_t temperature;
    enable_tmp_007(1);

   //Wait for, read and calc temperature
    {
    int count = 0;
    do{
    	temperature = value_tmp_007(TMP_007_SENSOR_TYPE_AMBIENT);
    	//g_count++;
    }while( ((temperature == 0x80000000) || (temperature == 0)) && (count <=5) );
    count++;
	count--;
    }
    enable_tmp_007(0);
    char char_temp[2];



   //start hum measurement
        configure_hdc_1000();
        start_hdc_1000();
//    //Wait for, read and calc humidity
    while(!read_data_hdc_1000());
   int humidity = value_hdc_1000(HDC_1000_SENSOR_TYPE_HUMIDITY);
//    char char_hum[5];



//END read sensor values
/*****************************************************************************************/

    powerDisablePeriph();
	// Disable clock for GPIO in CPU run mode
	HWREGBITW(PRCM_BASE + PRCM_O_GPIOCLKGR, PRCM_GPIOCLKGR_CLK_EN_BITN) = 0;
	// Load clock settings
	HWREGBITW(PRCM_BASE + PRCM_O_CLKLOADCTL, PRCM_CLKLOADCTL_LOAD_BITN) = 1;

/*****************************************************************************************/
// Set payload and transmit
	uint8_t p;
    p = 0;

    /*jedes 5.te mal senden*/


		payload[p++] = ADVLEN-1;        /* len */
		payload[p++] = 0x03;
		payload[p++] = 0xde;
		payload[p++] = 0xba;
		payload[p++] =(sequenceNumber >> 8);				// laufnummer
		payload[p++] = sequenceNumber;

		// Speed
		payload[p++] = g_diff >> 24;						// higher seconds
		payload[p++] = g_diff >> 16;						// lower  seconds
		payload[p++] = g_diff >> 8;							// higher subseconds
		payload[p++] = g_diff;								// lower  subseconds

		//pressure
		payload[p++] = 0;
		payload[p++] = 0; //(pressure >> 16);
		payload[p++] = 0; //(pressure >> 8);
		payload[p++] = 0; //pressure;

		//temperature
		payload[p++] = 0;
		payload[p++] = 0; // char_temp[2];
		payload[p++] = 0;//temperature >> 8; // char_temp[1];
		payload[p++] = 0; //temperature; //char_temp[0];

		// huminity
		payload[p++] = 0;
		payload[p++] = 0;//char_hum[0];
		payload[p++] = 0;//char_hum[1];
		payload[p++] = 0;//char_hum[2];

		payload[p++] = 0;
		payload[p++] = 0;



		//Start radio setup and linked advertisment
		radioUpdateAdvData(ADVLEN, payload);

		//Start radio setup and linked advertisment
		radioSetupAndTransmit();
	//}


//END: Transmit
/*****************************************************************************************/


    //Wait in IDLE for CMD_DONE interrupt after radio setup. ISR will disable radio interrupts
    while( ! rfSetupDone) {
      powerDisableCPU();
      PRCMDeepSleep();
    }

    //Disable flash in IDLE after CMD_RADIO_SETUP is done (radio setup reads FCFG trim values)
    powerDisableFlashInIdle();

    //Wait in IDLE for LAST_CMD_DONE after 3 adv packets
    while( ! rfAdvertisingDone) {
      powerDisableCPU();
      PRCMDeepSleep();
    }

    //Request radio to not force on system bus any more
    radioCmdBusRequest(false);

 // } // end if
 // g_count++;

    //
    // Standby procedure
    //

    powerDisableXtal();

    // Turn off radio
    powerDisableRFC();

    // Switch to RCOSC_HF
    OSCHfSourceSwitch();

    // Allow AUX to turn off again. No longer need oscillator interface
    powerDisableAuxForceOn();

    // Goto Standby. MCU will now request to be powered down on DeepSleep
    powerEnableMcuPdReq();

    // Disable cache and retention
    powerDisableCache();
    powerDisableCacheRetention();

    //Calculate next recharge
    SysCtrlSetRechargeBeforePowerDown(XOSC_IN_HIGH_POWER_MODE);

    // Synchronize transactions to AON domain to ensure AUX has turned off
    SysCtrlAonSync();

    //
    // Enter Standby
    //

    powerDisableCPU();
    PRCMDeepSleep();

    SysCtrlAonUpdate();

    SysCtrlAdjustRechargeAfterPowerDown();

    SysCtrlAonSync();

    //
	// Wakeup from RTC, code starts execution from here
	//
   
    powerEnableRFC();

    powerEnableAuxForceOn();

    //Re-enable cache and retention
    powerEnableCache();
    powerEnableCacheRetention();

    //MCU will not request to be powered down on DeepSleep -> System goes only to IDLE
    powerDisableMcuPdReq();
  }
}