From b24866225a6301d3a663f874725e83c012dc25d3 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:36:00 +0100 Subject: digital/beacon: add bitcloud stack into common directory digital/zigbit --- .../stack/Components/BSP/RCB/src/bspTaskManager.c | 86 +++++ .../stack/Components/BSP/RCB/src/buttons.c | 187 +++++++++++ .../stack/Components/BSP/RCB/src/fakeBSP.c | 356 +++++++++++++++++++++ .../bitcloud/stack/Components/BSP/RCB/src/leds.c | 124 +++++++ 4 files changed, 753 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/bspTaskManager.c create mode 100644 digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/buttons.c create mode 100644 digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/fakeBSP.c create mode 100644 digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/leds.c (limited to 'digital/zigbit/bitcloud/stack/Components/BSP/RCB/src') diff --git a/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/bspTaskManager.c b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/bspTaskManager.c new file mode 100644 index 00000000..65c80e55 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/bspTaskManager.c @@ -0,0 +1,86 @@ +/**************************************************************************//** +\file bspTaskManager.c + +\brief Implemenattion of BSP task manager. + +\author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + +\internal + History: + 26.08.09 A. Taradov - Created +******************************************************************************/ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/**************************************************************************//** +\brief BSP button handler. +******************************************************************************/ +void bspButtonsHandler(void); + +/**************************************************************************//** +\brief BSP temperature sensor handler. +******************************************************************************/ +void bspTemperatureSensorHandler(void); + +/**************************************************************************//** +\brief BSP light sensor handler. +******************************************************************************/ +void bspLightSensorHandler(void); + +/**************************************************************************//** +\brief BSP battery handler. +******************************************************************************/ +void bspEmptyBatteryHandler(void); + +/****************************************************************************** + Global variables section +******************************************************************************/ +volatile uint8_t bspTaskFlags = 0; + +/****************************************************************************** + Implementations section +******************************************************************************/ +/**************************************************************************//** +\brief BSP task handler. +******************************************************************************/ +void BSP_TaskHandler(void) +{ +#if APP_DISABLE_BSP != 1 + if (bspTaskFlags & BSP_BUTTONS) + { + bspTaskFlags &= ~BSP_BUTTONS; + bspButtonsHandler(); + } +#endif //APP_DISABLE_BSP != 1 + if (bspTaskFlags & BSP_TEMPERATURE) + { + bspTaskFlags &= (~BSP_TEMPERATURE); + bspTemperatureSensorHandler(); + } + if (bspTaskFlags & BSP_LIGHT) + { + bspTaskFlags &= (~BSP_LIGHT); + bspLightSensorHandler(); + } + if (bspTaskFlags & BSP_BATTERY) + { + bspTaskFlags &= (~BSP_BATTERY); + bspEmptyBatteryHandler(); + } + if (bspTaskFlags) + SYS_PostTask(BSP_TASK_ID); +} + +// eof bspTaskManager.c diff --git a/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/buttons.c b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/buttons.c new file mode 100644 index 00000000..8139394a --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/buttons.c @@ -0,0 +1,187 @@ +/**************************************************************************//** +\file buttons.c + +\brief Implementation of buttons interface. + +\author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + +\internal + History: + 21.08.09 A. Taradov - Created +*******************************************************************************/ +#if APP_DISABLE_BSP != 1 + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include +#include +#include +#include +#include + +/****************************************************************************** + Define(s) section +******************************************************************************/ +#define BSP_readKEY0() GPIO_E5_read() +#define PRESSED 1 +#define RELEASED 0 +#define BSP_BUTTONS_IDLE 0 +#define BSP_BUTTONS_BUSY 1 + +/****************************************************************************** + Types section +******************************************************************************/ +typedef struct +{ + uint8_t currentState0 : 1; + uint8_t wasPressed0 : 1; + uint8_t waitReleased0 : 1; +} BSP_buttonsAction_t; + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/**************************************************************************//** +\brief HAL's event handlers about KEY 0 has changed state. +******************************************************************************/ +void bspKey0InterruptHandler(void); + +/****************************************************************************** + Global variables section +******************************************************************************/ +static uint8_t state = BSP_BUTTONS_IDLE; +static volatile BSP_buttonsAction_t buttonsAction; +static BSP_ButtonsEventFunc_t bspButtonPressHandle; // callback +static BSP_ButtonsEventFunc_t bspButtonReleaseHandle; // callback + +/****************************************************************************** + Implementations section +******************************************************************************/ +/**************************************************************************//** +\brief Initializes buttons module. +******************************************************************************/ +static void bspInitButtons(void) +{ + GPIO_E5_make_in(); + GPIO_E5_make_pullup(); + + HAL_RegisterIrq(IRQ_5, IRQ_LOW_LEVEL, bspKey0InterruptHandler); + + if (BSP_readKEY0()) + buttonsAction.currentState0 = RELEASED; + else + buttonsAction.currentState0 = PRESSED; + + HAL_EnableIrq(IRQ_5); +} + +/**************************************************************************//** +\brief Registers handlers for button events. + +\param[in] + pressed - the handler to process pressing the button +\param[in] + released - the handler to process releasing the button +\param[in] + bn - button number. +\return + BC_FAIL - buttons module is busy, \n + BC_SUCCESS in other case. +******************************************************************************/ +result_t BSP_OpenButtons(void (*pressed)(uint8_t bn), void (*released)(uint8_t bn)) +{ + if (state != BSP_BUTTONS_IDLE) + return BC_FAIL; + state = BSP_BUTTONS_BUSY; + bspButtonPressHandle = pressed; + bspButtonReleaseHandle = released; + bspInitButtons(); + return BC_SUCCESS; +}; + +/**************************************************************************//** +\brief Cancel buttons handlers. +\return + BC_FAIL - buttons module was not opened, \n + BC_SUCCESS in other case. +******************************************************************************/ +result_t BSP_CloseButtons(void) +{ + if (state != BSP_BUTTONS_BUSY) + return BC_FAIL; + HAL_UnregisterIrq(IRQ_5); + bspButtonPressHandle = NULL; + bspButtonReleaseHandle = NULL; + state = BSP_BUTTONS_IDLE; + return BC_SUCCESS; +}; + +/**************************************************************************//** +\brief Reads state of buttons. + +\return + Current buttons state in a binary way. \n + Bit 0 defines state of the button 1, \n + bit 1 defines state of the button 2. +******************************************************************************/ +uint8_t BSP_ReadButtonsState(void) +{ + uint8_t state = 0; + + if (buttonsAction.currentState0) + state = 0x01; + + return state; +} + +/**************************************************************************//** +\brief HAL's event about KEY has changed state. +******************************************************************************/ +void bspKey0InterruptHandler(void) +{ + HAL_DisableIrq(IRQ_5); + buttonsAction.currentState0 = PRESSED; + buttonsAction.wasPressed0 = 1; + bspPostTask(BSP_BUTTONS); +} + +/**************************************************************************//** +\brief BSP's event about KEY has changed state. +******************************************************************************/ +void bspButtonsHandler(void) +{ + if (buttonsAction.wasPressed0) + { + buttonsAction.wasPressed0 = 0; + buttonsAction.waitReleased0 = 1; + if (NULL != bspButtonPressHandle) + bspButtonPressHandle(BSP_KEY0); + } + + if (buttonsAction.waitReleased0) + { + if (BSP_readKEY0()) + { + buttonsAction.waitReleased0 = 0; + buttonsAction.currentState0 = RELEASED; + if (NULL != bspButtonReleaseHandle) + bspButtonReleaseHandle(BSP_KEY0); + HAL_EnableIrq(IRQ_5); + } + else + { + bspPostTask(BSP_BUTTONS); + } + } +} + +#endif // APP_DISABLE_BSP != 1 + +// end of buttons.c diff --git a/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/fakeBSP.c b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/fakeBSP.c new file mode 100644 index 00000000..b7454d82 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/fakeBSP.c @@ -0,0 +1,356 @@ +/***************************************************************************//** +\file fakeBSP.c + +\brief Implementation of fake board-specific periphery. + +\author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + +\internal + History: + 05/05/11 A. Malkin - Created +*******************************************************************************/ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include +#include + +/****************************************************************************** + Global variables section +******************************************************************************/ +void(* readTemperatureDataCallback)(bool error, int16_t data); +void(* readLightDataCallback)(bool error, int16_t data); +void(* readBatteryDataCallback)(int16_t data); + +#if APP_DISABLE_BSP == 1 + +/****************************************************************************** + Implementations section +******************************************************************************/ +/****************************************************************************** + Leds +******************************************************************************/ +/**************************************************************************//** +\brief Opens leds module to use. + +\return + operation state +******************************************************************************/ +result_t BSP_OpenLeds(void) +{ + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Closes leds module. + +\return + operation state +******************************************************************************/ +result_t BSP_CloseLeds(void) +{ + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Turns on the LED. + +\param[in] + id - number of led +******************************************************************************/ +void BSP_OnLed(uint8_t id) +{ + (void)id; +} + +/**************************************************************************//** +\brief Turns off the LED. + +\param[in] + id - number of led +******************************************************************************/ +void BSP_OffLed(uint8_t id) +{ + (void)id; +} + +/**************************************************************************//** +\brief Changes the LED state to opposite. + +\param[in] + id - number of led +******************************************************************************/ +void BSP_ToggleLed(uint8_t id) +{ + (void)id; +} + +/****************************************************************************** + Buttons +******************************************************************************/ +/**************************************************************************//** +\brief Registers handlers for button events. + +\param[in] + pressed - the handler to process pressing the button +\param[in] + released - the handler to process releasing the button +\param[in] + bn - button number. + +\return + BC_SUCCESS - always. +******************************************************************************/ +result_t BSP_OpenButtons(void (*pressed)(uint8_t bn), void (*released)(uint8_t bn)) +{ + (void)pressed; + (void)released; + + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Cancel buttons handlers. + +\return + BC_SUCCESS - always. +******************************************************************************/ +result_t BSP_CloseButtons(void) +{ + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Reads state of buttons. + +\return + Current buttons state in a binary way. \n + Bit 0 defines state of the button 1, \n + bit 1 defines state of the button 2. +******************************************************************************/ +uint8_t BSP_ReadButtonsState(void) +{ + return 0; +} + +#endif // APP_DISABLE_BSP == 1 + +/****************************************************************************** + Sensors +******************************************************************************/ +/***************************************************************************//** +\brief Opens temperature sensor. + +\return + BC_SUCCESS - always. +*******************************************************************************/ +result_t BSP_OpenTemperatureSensor(void) +{ + return BC_SUCCESS; +} + +/***************************************************************************//** +\brief Closes the temperature sensor. + +\return + BC_SUCCESS - always. +*******************************************************************************/ +result_t BSP_CloseTemperatureSensor(void) +{ + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Reads data from the temperature sensor. +\param[in] + result - the result of the requested operation. + true - operation finished successfully, false - some error has + occured. +\param[in] + data - sensor data. + +\return + BC_SUCCESS - always. +******************************************************************************/ +result_t BSP_ReadTemperatureData(void (*f)(bool result, int16_t data)) +{ + readTemperatureDataCallback = f; + + bspPostTask(BSP_TEMPERATURE); + + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief BSP task handler for temperature sensor. +******************************************************************************/ +void bspTemperatureSensorHandler(void) +{ + readTemperatureDataCallback(true, 0); +} + +/***************************************************************************//** +\brief Opens the light sensor. + +\return + BC_SUCCESS - always. +*******************************************************************************/ +result_t BSP_OpenLightSensor(void) +{ + return BC_SUCCESS; +} + +/***************************************************************************//** +\brief Closes the light sensor. + +\return + BC_SUCCESS - always. +*******************************************************************************/ +result_t BSP_CloseLightSensor(void) +{ + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Reads data from the light sensor. +\param[in] + result - the result of the requested operation. + true - operation finished successfully, false - some error has + occured. +\param[in] + data - sensor data. + +\return + BC_SUCCESS - always. +******************************************************************************/ +result_t BSP_ReadLightData(void (*f)(bool result, int16_t data)) +{ + readLightDataCallback = f; + + bspPostTask(BSP_LIGHT); + + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief BSP task handler for light sensor. +******************************************************************************/ +void bspLightSensorHandler(void) +{ + readLightDataCallback(true, 0); +} + +/***************************************************************************//** +\brief Opens the battery sensor. + +\return + BC_SUCCESS - always. +*******************************************************************************/ +result_t BSP_OpenBatterySensor(void) +{ + return BC_SUCCESS; +} + +/***************************************************************************//** +\brief Closes the battery sensor. + +\return + BC_SUCCESS - always. +*******************************************************************************/ +result_t BSP_CloseBatterySensor(void) +{ + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Reads data from battery sensor. + +\param[in] + data - sensor data. + +\return + BC_SUCCESS - always. +******************************************************************************/ +result_t BSP_ReadBatteryData(void (*f)(int16_t data)) +{ + readBatteryDataCallback = f; + + bspPostTask(BSP_BATTERY); + + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief BSP task handler for battery sensor. +******************************************************************************/ +void bspEmptyBatteryHandler(void) +{ + readBatteryDataCallback(0); +} + +/****************************************************************************** + Sliders +******************************************************************************/ +/**************************************************************************//** +\brief Reads the sliders. + +\return + state of 3 on-board DIP-switches.User can uses SLIDER0, SLIDER1, SLIDER2 + defines to test state. Value 1 indicates that slider is on. +******************************************************************************/ +uint8_t BSP_ReadSliders(void) +{ + return 0; +} + +/****************************************************************************** + Joystick +******************************************************************************/ +/****************************************************************************** +\brief Registers handler for joystick events. + +\param[in] + state - joystick state. + +\return + BC_FAIL - joystick module is busy, + BC_SUCCESS in other cases. +******************************************************************************/ +result_t BSP_OpenJoystick(void (*generalHandler)(BSP_JoystickState_t state)) +{ + (void)generalHandler; + + return BC_SUCCESS; +} + +/****************************************************************************** +\brief Cancel joystick handlers. + +\return + BC_FAIL - joystick module was not opened, + BC_SUCCESS in other cases. +******************************************************************************/ +result_t BSP_CloseJoystick(void) +{ + return BC_SUCCESS; +} + +/****************************************************************************** +\brief Reads state of joystick. + +\return + Current joystick state. +******************************************************************************/ +BSP_JoystickState_t BSP_ReadJoystickState(void) +{ + return 0; +} + +// eof fakeBSP.c diff --git a/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/leds.c b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/leds.c new file mode 100644 index 00000000..48a26fd3 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/BSP/RCB/src/leds.c @@ -0,0 +1,124 @@ +/***************************************************************************//** +\file leds.c + +\brief The module to access to the leds. + +\author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + +\internal + History: + 05.08.09 A. Taradov - Created +*******************************************************************************/ +#if APP_DISABLE_BSP != 1 + +/****************************************************************************** + Includes section +******************************************************************************/ +#include + +/****************************************************************************** + Implementations section +******************************************************************************/ + +/**************************************************************************//** +\brief Opens leds module to use. + +\return + operation state +******************************************************************************/ +result_t BSP_OpenLeds(void) +{ + halInitFirstLed(); + halInitSecondLed(); + halInitThirdLed(); + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Closes leds module. + +\return + operation state +******************************************************************************/ +result_t BSP_CloseLeds(void) +{ + halUnInitFirstLed(); + halUnInitSecondLed(); + halUnInitThirdLed(); + return BC_SUCCESS; +} + +/**************************************************************************//** +\brief Turns the LED on. + +\param[in] + id - number of led +******************************************************************************/ +void BSP_OnLed(uint8_t id) +{ + switch (id) + { + case LED_FIRST: + halOnFirstLed(); + break; + case LED_SECOND: + halOnSecondLed(); + break; + case LED_THIRD: + halOnThirdLed(); + break; + } +} + +/**************************************************************************//** +\brief Turns the LED off. + +\param[in] + id - number of led +******************************************************************************/ +void BSP_OffLed(uint8_t id) +{ + switch (id) + { + case LED_FIRST: + halOffFirstLed(); + break; + case LED_SECOND: + halOffSecondLed(); + break; + case LED_THIRD: + halOffThirdLed(); + break; + } +} + +/**************************************************************************//** +\brief Toggles LED state. + +\param[in] + id - number of led +******************************************************************************/ +void BSP_ToggleLed(uint8_t id) +{ + switch (id) + { + case LED_FIRST: + halToggleFirstLed(); + break; + case LED_SECOND: + halToggleSecondLed(); + break; + case LED_THIRD: + halToggleThirdLed(); + break; + } +} + +#endif // APP_DISABLE_BSP != 1 + +// eof leds.c -- cgit v1.2.3