-
-
Save tetrodoxin/34c8a2ef9af80b0d3e30c4d213b5ca40 to your computer and use it in GitHub Desktop.
da14695 FreeRTOS blinky example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <string.h> | |
#include "osal.h" | |
#include "sdk_list.h" | |
#include "bas.h" | |
#include "ias.h" | |
#include "lls.h" | |
#include "tps.h" | |
#include "sys_power_mgr.h" | |
#include "ad_nvparam.h" | |
#include "ad_gpadc.h" | |
#include "hw_gpio.h" | |
#include "sys_watchdog.h" | |
#include "app_nvparam.h" | |
#include "blinker_config.h" | |
#include "platform_devices.h" | |
/* | |
* Notification bits reservation | |
* | |
* Bit #0 is always assigned to BLE event queue notification. | |
*/ | |
#define BLINK_TMO_NOTIF (1 << 4) | |
/* Timer used to blink led */ | |
__RETAINED static OS_TIMER led_blink_tim; | |
static void led_blink_tim_cb(OS_TIMER timer) | |
{ | |
OS_TASK task = (OS_TASK) OS_TIMER_GET_TIMER_ID(timer); | |
OS_TASK_NOTIFY(task, BLINK_TMO_NOTIF, OS_NOTIFY_SET_BITS); | |
} | |
void blinker_task(void *params) | |
{ | |
int8_t wdog_id; | |
uint8_t blink_sw = 1; | |
wdog_id = sys_watchdog_register(false); | |
led_blink_tim = OS_TIMER_CREATE("led", OS_MS_2_TICKS(300), OS_TIMER_FAIL, | |
(void *) OS_GET_CURRENT_TASK(), led_blink_tim_cb); | |
OS_TIMER_START(led_blink_tim, OS_TIMER_FOREVER); | |
for (;;) { | |
OS_BASE_TYPE ret __UNUSED; | |
uint32_t notif; | |
sys_watchdog_notify(wdog_id); | |
sys_watchdog_suspend(wdog_id); | |
ret = OS_TASK_NOTIFY_WAIT(0, OS_TASK_NOTIFY_ALL_BITS, ¬if, OS_TASK_NOTIFY_FOREVER); | |
OS_ASSERT(ret == OS_OK); | |
sys_watchdog_notify_and_resume(wdog_id); | |
if (notif & BLINK_TMO_NOTIF) { | |
BaseType_t rs = OS_TIMER_START(led_blink_tim, OS_TIMER_FOREVER); | |
/* if (hw_gpio_get_pin_status(HW_GPIO_PORT_1, HW_GPIO_PIN_1)) */ | |
if (blink_sw == 1){ | |
hw_gpio_set_inactive(HW_GPIO_PORT_1, HW_GPIO_PIN_1); | |
blink_sw = 0; | |
} | |
else { | |
hw_gpio_set_active(HW_GPIO_PORT_1, HW_GPIO_PIN_1); | |
blink_sw = 1; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdbool.h> | |
#include "osal.h" | |
#include "resmgmt.h" | |
#include "hw_gpio.h" | |
#include "sys_clock_mgr.h" | |
#include "sys_power_mgr.h" | |
#include "sys_watchdog.h" | |
#include "platform_devices.h" | |
#if (dg_configUSE_SYS_USB == 1) | |
#include "sys_usb.h" | |
#endif /* (dg_configUSE_SYS_USB == 1) */ | |
#if (dg_configUSE_SYS_CHARGER == 1) | |
#include "sys_charger.h" | |
#include "custom_charging_profile.h" | |
#endif /* dg_configUSE_SYS_CHARGER */ | |
/* Task priorities */ | |
#define mainBLINKER_TASK_PRIORITY ( OS_TASK_PRIORITY_NORMAL ) | |
#if dg_configUSE_WDOG | |
__RETAINED_RW int8_t idle_task_wdog_id = -1; | |
#endif | |
static void prvSetupHardware( void ); | |
void blinker_task( void *pvParameters); | |
static void system_init( void *pvParameters ) | |
{ | |
OS_TASK handle; | |
cm_sys_clk_init(sysclk_XTAL32M); | |
cm_apb_set_clock_divider(apb_div1); | |
cm_ahb_set_clock_divider(ahb_div1); | |
cm_lp_clk_init(); | |
sys_watchdog_init(); | |
#if dg_configUSE_WDOG | |
idle_task_wdog_id = sys_watchdog_register(false); | |
ASSERT_WARNING(idle_task_wdog_id != -1); | |
sys_watchdog_configure_idle_id(idle_task_wdog_id); | |
#endif | |
/* Prepare the hardware to run this demo. */ | |
prvSetupHardware(); | |
hw_gpio_set_active(HW_GPIO_PORT_1, HW_GPIO_PIN_1); | |
/* Set the desired sleep mode */ | |
pm_set_wakeup_mode(true); | |
pm_sleep_mode_set(pm_mode_active); | |
#if defined CONFIG_RETARGET | |
retarget_init(); | |
#endif | |
#if (dg_configUSE_SYS_CHARGER == 1) | |
sys_usb_init(); | |
sys_charger_init(&sys_charger_conf); | |
#endif /* dg_configUSE_SYS_CHARGER */ | |
OS_TASK_CREATE("Blinker", /* The text name assigned to the task, for | |
debug only; not used by the kernel. */ | |
blinker_task, /* The function that implements the task. */ | |
NULL, /* The parameter passed to the task. */ | |
756, /* The number of bytes to allocate to the | |
stack of the task. */ | |
mainBLINKER_TASK_PRIORITY, /* The priority assigned to the task. */ | |
handle); /* The task handle. */ | |
OS_ASSERT(handle); | |
/* the work of the SysInit task is done */ | |
OS_TASK_DELETE(OS_GET_CURRENT_TASK()); | |
} | |
int main( void ) | |
{ | |
OS_TASK handle; | |
OS_BASE_TYPE status __UNUSED; | |
status = OS_TASK_CREATE("SysInit", /* The text name assigned to the task, for | |
debug only; not used by the kernel. */ | |
system_init, /* The System Initialization task. */ | |
( void * ) 0, /* The parameter passed to the task. */ | |
1200, /* The number of bytes to allocate to the | |
stack of the task. */ | |
OS_TASK_PRIORITY_HIGHEST, /* The priority assigned to the task. */ | |
handle ); /* The task handle */ | |
OS_ASSERT(status == OS_TASK_CREATE_SUCCESS); | |
vTaskStartScheduler(); | |
for ( ;; ) | |
{ | |
} | |
} | |
static void periph_init(void) | |
{ | |
#if defined CONFIG_RETARGET | |
#endif | |
#if (dg_configUSE_SYS_CHARGER == 1) | |
/* USB data pin configuration */ | |
hw_gpio_set_pin_function(HW_GPIO_PORT_0, HW_GPIO_PIN_14, HW_GPIO_MODE_INPUT, | |
HW_GPIO_FUNC_USB); | |
hw_gpio_set_pin_function(HW_GPIO_PORT_0, HW_GPIO_PIN_15, HW_GPIO_MODE_INPUT, | |
HW_GPIO_FUNC_USB); | |
#endif /* dg_configUSE_SYS_CHARGER */ | |
hw_gpio_set_pin_function(HW_GPIO_PORT_1, HW_GPIO_PIN_1, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO); | |
hw_gpio_pad_latch_enable(HW_GPIO_PORT_1, HW_GPIO_PIN_1); | |
} | |
static void prvSetupHardware( void ) | |
{ | |
/* Init hardware */ | |
pm_system_init(periph_init); | |
} | |
/** | |
* @brief Malloc fail hook | |
*/ | |
void vApplicationMallocFailedHook( void ) | |
{ | |
ASSERT_ERROR(0); | |
} | |
/** | |
* @brief Application idle task hook | |
*/ | |
void vApplicationIdleHook( void ) | |
{ | |
#if dg_configUSE_WDOG | |
sys_watchdog_notify(idle_task_wdog_id); | |
#endif | |
} | |
void vApplicationStackOverflowHook( OS_TASK pxTask, char *pcTaskName ) | |
{ | |
( void ) pcTaskName; | |
( void ) pxTask; | |
ASSERT_ERROR(0); | |
} | |
void vApplicationTickHook( void ) | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment