diff options
| author | yygg_you <[email protected]> | 2017-10-06 08:58:24 +0800 |
|---|---|---|
| committer | yygg_you <[email protected]> | 2017-10-06 08:58:24 +0800 |
| commit | 2e01bafa71dc0309abfca352edae8872d27038fc (patch) | |
| tree | a4208429d31866a5938ee6484ae25b525d0180d7 /bsp/samd21/applications | |
| parent | ad1d3375f222c5746514ab16003dc18c0df83dad (diff) | |
| parent | a15d90a6865fa05e2420205556df7cece5f5c134 (diff) | |
Merge branch 'master' of https://github.com/yygg/rt-thread
Diffstat (limited to 'bsp/samd21/applications')
| -rw-r--r-- | bsp/samd21/applications/SConscript | 14 | ||||
| -rw-r--r-- | bsp/samd21/applications/application.c | 119 | ||||
| -rw-r--r-- | bsp/samd21/applications/startup.c | 121 |
3 files changed, 254 insertions, 0 deletions
diff --git a/bsp/samd21/applications/SConscript b/bsp/samd21/applications/SConscript new file mode 100644 index 0000000000..3c69933a88 --- /dev/null +++ b/bsp/samd21/applications/SConscript @@ -0,0 +1,14 @@ +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd, str(Dir('#'))] + +#remove other no use files +#SrcRemove(src, '*.c') + +group = DefineGroup('Application', src, depend = [''], CPPPATH = CPPPATH) + +Return('group')
\ No newline at end of file diff --git a/bsp/samd21/applications/application.c b/bsp/samd21/applications/application.c new file mode 100644 index 0000000000..d311cb23fc --- /dev/null +++ b/bsp/samd21/applications/application.c @@ -0,0 +1,119 @@ +#include <rtthread.h> +#include <rthw.h> + +#include "board.h" + +#include "port.h" +#include "extint.h" + +#include "sleep_timer.h" + +void LED_Init(void) +{ + struct port_config config_port_pin; + + port_get_config_defaults(&config_port_pin); + config_port_pin.direction = PORT_PIN_DIR_INPUT; + config_port_pin.input_pull = PORT_PIN_PULL_UP; + port_pin_set_config(PIN_PA15, &config_port_pin); + + config_port_pin.direction = PORT_PIN_DIR_OUTPUT; + port_pin_set_config(PIN_PB30, &config_port_pin); +} + +void LED_ON(void) +{ + port_pin_set_output_level(PIN_PB30, false); +} + +void LED_OFF(void) +{ + port_pin_set_output_level(PIN_PB30, true); +} + +void extint_detection_callback(void); + +void configure_extint_channel(void) +{ +//! [setup_1] + struct extint_chan_conf config_extint_chan; +//! [setup_1] +//! [setup_2] + extint_chan_get_config_defaults(&config_extint_chan); +//! [setup_2] + +//! [setup_3] + config_extint_chan.gpio_pin = PIN_PA15A_EIC_EXTINT15; + config_extint_chan.gpio_pin_mux = MUX_PA15A_EIC_EXTINT15; + config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP; + config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH; +//! [setup_3] +//! [setup_4] + extint_chan_set_config(15, &config_extint_chan); +//! [setup_4] +} + +void configure_extint_callbacks(void) +{ +//! [setup_5] + extint_register_callback(extint_detection_callback, 15, EXTINT_CALLBACK_TYPE_DETECT); +//! [setup_5] +//! [setup_6] + extint_chan_enable_callback(15, EXTINT_CALLBACK_TYPE_DETECT); +//! [setup_6] +} + +//! [setup_7] +void extint_detection_callback(void) +{ + bool pin_state = port_pin_get_input_level(PIN_PA15); + port_pin_set_output_level(PIN_PB30, pin_state); +} + +static struct rt_semaphore _rx_sem; + +static rt_err_t _rx_ind(rt_device_t dev, rt_size_t size) +{ + return rt_sem_release(&_rx_sem); +} + +void rt_init_thread_entry(void* parameter) +{ + rt_thread_t thread; + rt_device_t dev; + + rt_kprintf("SYSTEM running at %uhz\n", SystemCoreClock); + +#ifdef RT_USING_FINSH + /* init finsh */ + finsh_system_init(); + finsh_set_device("uart1"); +#endif + + LED_Init(); + configure_extint_channel(); + configure_extint_callbacks(); + + sleep_timer_init(); + // sleep_timer_start(1500); + + while (1) + { + rt_kprintf("init thread running tick:%u\n", rt_tick_get()); + rt_thread_delay(2*RT_TICK_PER_SECOND); + } +} + +int rt_application_init(void) +{ + rt_thread_t tid; + + tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, + 512, RT_THREAD_PRIORITY_MAX / 3, 20); + + if (tid != RT_NULL) + rt_thread_startup(tid); + + return 0; +} + diff --git a/bsp/samd21/applications/startup.c b/bsp/samd21/applications/startup.c new file mode 100644 index 0000000000..b8c2c83d0d --- /dev/null +++ b/bsp/samd21/applications/startup.c @@ -0,0 +1,121 @@ +/* + * File : startup.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://openlab.rt-thread.com/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2006-08-31 Bernard first implementation + */ + +#include <rthw.h> +#include <rtthread.h> + +#include "board.h" + +/** + * @addtogroup STM32 + */ + +/*@{*/ + +extern int rt_application_init(void); +#ifdef RT_USING_FINSH +extern void finsh_system_init(void); +extern void finsh_set_device(const char* device); +#endif + +#ifdef __CC_ARM +extern int Image$$RW_IRAM1$$ZI$$Limit; +#elif __ICCARM__ +#pragma section="HEAP" +#else +extern int __bss_end; +#endif + +#ifdef DEBUG +/******************************************************************************* +* Function Name : assert_failed +* Description : Reports the name of the source file and the source line number +* where the assert error has occurred. +* Input : - file: pointer to the source file name +* - line: assert error line source number +* Output : None +* Return : None +*******************************************************************************/ +void assert_failed(uint8_t* file, uint32_t line) +{ + rt_kprintf("\n\r Wrong parameter value detected on\r\n"); + rt_kprintf(" file %s\r\n", file); + rt_kprintf(" line %d\r\n", line); + + while (1) ; +} +#endif + +/** + * This function will startup RT-Thread RTOS. + */ +void rtthread_startup(void) +{ + /* init board */ + rt_board_init(); + + /* show version */ + rt_show_version(); + + /* init tick */ + rt_system_tick_init(); + + /* init kernel object */ + rt_system_object_init(); + + /* init timer system */ + rt_system_timer_init(); + +#ifdef RT_USING_HEAP + #ifdef __CC_ARM + rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)CHIP_SRAM_END); + #elif __ICCARM__ + rt_system_heap_init(__segment_end("HEAP"), (void*)CHIP_SRAM_END); + #else + /* init memory system */ + rt_system_heap_init((void*)&__bss_end, (void*)CHIP_SRAM_END); + #endif +#endif + + /* init scheduler system */ + rt_system_scheduler_init(); + + /* init application */ + rt_application_init(); + + /* init timer thread */ + rt_system_timer_thread_init(); + + /* init idle thread */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; +} + +int main(void) +{ + /* disable interrupt first */ + rt_hw_interrupt_disable(); + + /* startup RT-Thread RTOS */ + rtthread_startup(); + + return 0; +} + +/*@}*/ |
