Пример #1
0
/**
 * send the bluetooth link state query to KW40
 */
void watch_SendGetLinkStateReq()
{
	static hostInterface_packet_t dataPacket =
	{
		.start1 = gHostInterface_startByte1,
		.start2 = gHostInterface_startByte2,
		.length = 0,
		.data[0] = gHostInterface_trailerByte
	};

	dataPacket.type = packetType_linkStateGet;
	while(HostInterface_TxQueueMsgPut((hostInterface_packet_t *)&dataPacket, true) != kStatus_OSA_Success);
}

/**
 * wait for the bluetooth link state query response from KW40
 * @param  timeout timeout value in [ms]
 * @return         status flag
 */
osa_status_t watch_WaitForLinkStateUpdate( uint32_t timeout )
{
	osa_status_t status;
	event_flags_t setFlags;

	status = OSA_EventWait( &watch_event, linkStateUpdate_eventFlag, false, timeout, &setFlags );

	if ( kStatus_OSA_Success != status )
	{
		return kStatus_OSA_Error;
	}

	return (osa_status_t)status;
}
uint32_t OS_Event_wait(os_event_handle handle, uint32_t bitmask, uint32_t flag, uint32_t timeout)
{
    osa_status_t status = kStatus_OSA_Idle;
    event_flags_t event_bit;
    uint32_t re;
    event_t* event = (event_t*) handle;
    // flag will always be false, so wait any bits
#if (USE_RTOS)
    if (0 == timeout)
    {
        timeout = OSA_WAIT_FOREVER;
    }
#endif
    // Block or timeout mode
    do
    {
        status = OSA_EventWait(event, bitmask, flag, timeout, &event_bit);
    } while (kStatus_OSA_Idle == status);

    switch(status)
    {
    case kStatus_OSA_Success:
        re = (uint32_t) OS_EVENT_OK;
        break;
    case kStatus_OSA_Timeout:
        re = (uint32_t) OS_EVENT_TIMEOUT;
        break;
    default:
        re = (uint32_t) OS_EVENT_ERROR;
        break;
    }
    return re;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : I2C_DRV_SlaveSendDataBlocking
 * Description   : Send the data using a blocking method.
 * This function set buffer pointer and length to Tx buffer & Tx Size.
 * Then wait until the transmission is end ( NAK is detected)
 *
 *END**************************************************************************/
i2c_status_t I2C_DRV_SlaveSendDataBlocking(uint32_t instance,
                                           const uint8_t * txBuff,
                                           uint32_t txSize,
                                           uint32_t timeout_ms)
{
    assert(txBuff);
    assert(instance < HW_I2C_INSTANCE_COUNT);

    i2c_slave_state_t * i2cSlaveState = (i2c_slave_state_t *)g_i2cStatePtr[instance];

    if(!i2cSlaveState->slaveListening)
    {
        event_flags_t i2cIrqSetFlags;
        osa_status_t syncStatus;

        if (i2cSlaveState->isTxBusy)
        {
            return kStatus_I2C_Busy;
        }

        /* Initialize the module driver state structure. */
        i2cSlaveState->txBuff = txBuff;
        i2cSlaveState->txSize = txSize;
        i2cSlaveState->isTxBusy = true;
        i2cSlaveState->isTxBlocking = true;

#if FSL_FEATURE_I2C_HAS_START_STOP_DETECT
        I2C_HAL_ClearStartFlag(g_i2cBaseAddr[instance]);
#endif
        I2C_HAL_ClearInt(g_i2cBaseAddr[instance]);
        I2C_HAL_SetIntCmd(g_i2cBaseAddr[instance], true);

        /* Wait until the transmit is complete. */
        do
        {
            syncStatus = OSA_EventWait(&i2cSlaveState->irqEvent,
                                       kI2CSlaveTxNAK | kI2CSlaveAbort,
                                       false,
                                       timeout_ms,
                                       &i2cIrqSetFlags);
        } while(syncStatus == kStatus_OSA_Idle);

        if (syncStatus != kStatus_OSA_Success)
        {
            I2C_HAL_SetIntCmd(g_i2cBaseAddr[instance], false);
            i2cSlaveState->status = kStatus_I2C_Timeout;
        }

        i2cSlaveState->isTxBlocking = false;

        return i2cSlaveState->status;
    }
    else /* i2cSlaveState->slaveListening */
    {
        return kStatus_I2C_Fail;
    }
}
/*FUNCTION**********************************************************************
 *
 * Function Name : SPI_DRV_DmaSlaveTransferBlocking
 * Description   : Transfer data with the master, using blocking call and DMA
 * driven.
 *
 *END**************************************************************************/
spi_status_t SPI_DRV_DmaSlaveTransferBlocking(uint32_t instance,
                                           const uint8_t *sendBuffer,
                                           uint8_t *receiveBuffer,
                                           uint32_t transferByteCount,
                                           uint32_t timeout)
{
    spi_dma_slave_state_t * spiState = (spi_dma_slave_state_t *)g_spiStatePtr[instance];
    spi_status_t errorStatus = kStatus_SPI_Success;
    event_flags_t setFlags = 0;

    /* fill in members of the run-time state struct */
    spiState->isSync = true;
    spiState->sendBuffer = (const uint8_t *)sendBuffer;
    spiState->receiveBuffer = (uint8_t *)receiveBuffer;
    spiState->remainingSendByteCount = transferByteCount;
    spiState->remainingReceiveByteCount = transferByteCount;

    /* Clear the event flags */
    OSA_EventClear(&spiState->event, kSpiDmaTransferDone);

    errorStatus = SPI_DRV_DmaSlaveStartTransfer(instance);
    if (errorStatus != kStatus_SPI_Success)
    {
        return errorStatus;
    }

    /* As this is a synchronous transfer, wait until the transfer is complete. */
    osa_status_t syncStatus;

    do
    {
        syncStatus = OSA_EventWait(&spiState->event, kSpiDmaTransferDone, true, timeout, &setFlags);
    }while(syncStatus == kStatus_OSA_Idle);

    if (syncStatus != kStatus_OSA_Success)
    {
        /* Abort the transfer so it doesn't continue unexpectedly. */
        SPI_DRV_DmaSlaveAbortTransfer(instance);

        errorStatus = kStatus_SPI_Timeout;
    }

    return errorStatus;
}
Пример #5
0
/**
 * update GUI upon analyzing data
 * @param param optional parameter
 */
static void watch_GuiUpdateTask(task_param_t param)
{
	osa_status_t status;
	event_flags_t setFlags;

	// Read active button group
	//watch_SendGetLinkStateReq();

	// check once in the beginning
	watch_CheckBatteryStatus();

	while(1)
	{
		status = OSA_EventWait(
								&watch_event,
								( linkStateUpdate_eventFlag | timeUpdate_eventFlag | dateUpdate_eventFlag |
							    tempUpdate_eventFlag | batteryUpdate_eventFlag | chargDetect_eventFlag | notifDetect_eventFlag ),
							    false,
								OSA_WAIT_FOREVER,
								&setFlags
							  );

		if ( kStatus_OSA_Success != status )
		{
			continue;
		}

		if(setFlags & timeUpdate_eventFlag)
		{
			GuiDriver_LabelDraw(&watch_labelTime);
		}

		if(setFlags & dateUpdate_eventFlag)
		{
			GuiDriver_LabelDraw(&watch_labelDate);
		}

		if(setFlags & batteryUpdate_eventFlag)
		{
			watch_UpdateBatteryLevel(batteryLevel);
		}

		if(setFlags & chargDetect_eventFlag)
		{
			if ( true == watch_IsBatteryCharging() )
			{
				watch_imgBattery.img = (const uint8_t*)battery_charge_bmp;
				GuiDriver_ImageDraw( &watch_imgBattery );
			}
			else
			{
				sensor_ResetPacketcounter( PACKET_BAT );
			}
		}

		if(setFlags & tempUpdate_eventFlag)
		{
			GuiDriver_LabelDraw(&watch_labelTemp);
		}

		if(setFlags & linkStateUpdate_eventFlag)
		{
			if(watch_linkState == linkState_connected)
			{
				watch_imgBluetoothLogo.img = watch_bluetooth_logo_blue_bmp;
			}
			else
			{
				watch_imgBluetoothLogo.img = watch_bluetooth_logo_white_bmp;
			}
			GuiDriver_ImageDraw(&watch_imgBluetoothLogo);
		}

		if ( setFlags & notifDetect_eventFlag )
		{
			  // Check for notifications
			  if( 0 != Notification_GetUnreadCounter( NOTIF_TYPE_CALL ) )
			  {
			      watch_imgCall.img = watch_phone_call_bmp;
			  }
			  else
			  {
				  watch_imgCall.img = watch_phone_call_gray_bmp;
			  }

			  if( 0 != Notification_GetUnreadCounter( NOTIF_TYPE_MAIL) )
			  {
				  watch_imgMail.img = watch_mail_bmp;
			  }
			  else
			  {
				  watch_imgMail.img = watch_mail_gray_bmp;
			  }

			  if( 0 != Notification_GetUnreadCounter( NOTIF_TYPE_SMS ) )
			  {
				  watch_imgSms.img = watch_sms_bmp;
			  }
			  else
			  {
				  watch_imgSms.img = watch_sms_gray_bmp;
			  }

			GuiDriver_ImageDraw( &watch_imgCall );
			GuiDriver_ImageDraw( &watch_imgMail);
		    GuiDriver_ImageDraw( &watch_imgSms );
		}
	}
}
Пример #6
0
/*FUNCTION**********************************************************************
 *
 * Function Name : I2C_DRV_SlaveReceiveDataBlocking
 * Description   : Receive the data using a blocking method.
 * This function set buffer pointer and length to Rx buffer &Rx Size. Then wait
 * until the transmission is end (all data are received or STOP signal is
 * detected)
 *
 *END*/
i2c_status_t I2C_DRV_SlaveReceiveDataBlocking(uint32_t instance,
                                              uint8_t * rxBuff,
                                              uint32_t rxSize,
                                              uint32_t timeout_ms)
{
    assert(rxBuff);
    assert(instance < I2C_INSTANCE_COUNT);

    i2c_slave_state_t * i2cSlaveState = (i2c_slave_state_t *)g_i2cStatePtr[instance];

    if(!i2cSlaveState->slaveListening)
    {
        event_flags_t i2cIrqSetFlags;
        osa_status_t syncStatus;

        if (i2cSlaveState->isRxBusy)
        {
            return kStatus_I2C_Busy;
        }

        i2cSlaveState->rxBuff = rxBuff;
        i2cSlaveState->rxSize = rxSize;
        i2cSlaveState->isRxBusy = true;
        i2cSlaveState->isRxBlocking = true;

         /** If IAAS event already comes, read dummy to release the bus.*/
        if(I2C_HAL_GetStatusFlag(g_i2cBase[instance], kI2CAddressAsSlave))
        {
             /** Switch to RX mode.*/
            I2C_HAL_SetDirMode(g_i2cBase[instance], kI2CReceive);
            I2C_HAL_ReadByte(g_i2cBase[instance]);
        }

        I2C_HAL_SetIntCmd(g_i2cBase[instance], true);

         /** Wait until the transmit is complete. */
        do
        {
            syncStatus = OSA_EventWait(&i2cSlaveState->irqEvent,
                                       #if (FSL_FEATURE_I2C_HAS_START_STOP_DETECT || FSL_FEATURE_I2C_HAS_STOP_DETECT)
                                       kI2CSlaveStopDetect |
                                       #endif
                                       kI2CSlaveRxFull | kI2CSlaveAbort,
                                       false,
                                       timeout_ms,
                                       &i2cIrqSetFlags);
        } while(syncStatus == kStatus_OSA_Idle);

        if (syncStatus != kStatus_OSA_Success)
        {
            I2C_HAL_SetIntCmd(g_i2cBase[instance], false);
            i2cSlaveState->status = kStatus_I2C_Timeout;
        }

        i2cSlaveState->isRxBlocking = false;

        return i2cSlaveState->status;
    }
    else  /** i2cSlaveState->slaveListening */
    {
        return kStatus_I2C_Fail;
    }
}
Пример #7
0
void bluetooth_SendGetAdvModeReq(void)
{
	static hostInterface_packet_t dataPacket =
	{
		.start1 = gHostInterface_startByte1,
		.start2 = gHostInterface_startByte2,
		.length = 0,
		.data[0] = gHostInterface_trailerByte
	};

	dataPacket.type = packetType_advModeGet;
	while(HostInterface_TxQueueMsgPut((hostInterface_packet_t *)&dataPacket, true) != kStatus_OSA_Success);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void bluetooth_SendToggleAdvModeReq(void)
{
	static hostInterface_packet_t dataPacket =
	{
		.start1 = gHostInterface_startByte1,
		.start2 = gHostInterface_startByte2,
		.length = 0,
		.data[0] = gHostInterface_trailerByte
	};

	dataPacket.type = packetType_advModeToggle;
	while(HostInterface_TxQueueMsgPut((hostInterface_packet_t *)&dataPacket, true) != kStatus_OSA_Success);
	haptic_Vibrate();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * [buttonsGroup_DestroyTasks description]
 * @param param [description]
 */

osa_status_t bluetooth_WaitForAdvModeUpdate(uint32_t timeout)
{
	osa_status_t status;
	event_flags_t setFlags;

	status = OSA_EventWait(&advModeUpdate_event, advModeUpdate_eventFlag, false, timeout, &setFlags);

	if ( kStatus_OSA_Success != status )
	{
		return kStatus_OSA_Error;
	}

	return (osa_status_t)status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * [buttonsGroup_DestroyTasks description]
 * @param param [description]
 */

osa_status_t bluetooth_AdvModeUpdate(bluetooth_advMode_t bluetooth_advMode)
{
	OSA_EventSet( &advModeUpdate_event, (event_flags_t)advModeUpdate_eventFlag);
	bluetoothCurrentAdvMode = bluetooth_advMode;

	return kStatus_OSA_Success;
}