Modified pin driver and some format

This commit is contained in:
lin committed 2017-09-18 17:45:46 +08:00
1 parent c19fb2ab58
commit 19fcea5229
11 files changed
+516 -651

No files matched your search

@@ -1,22 +1,27 @@
/*
* File : application.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
/**
* @addtogroup APOLLO2
*/
/*@{*/
#include <rtthread.h>
#include <stdint.h>
#ifdef RT_USING_FINSH
@@ -24,9 +29,8 @@
#include <shell.h>
#endif
#include "hw_led.h"
#include "led.h"
ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t led_stack[ 512 ];
static struct rt_thread led_thread;
@@ -34,9 +38,6 @@ static void led_thread_entry(void* parameter)
{
unsigned int count=0;
rt_hw_led_init(0);
rt_hw_led_init(1);
while (1)
{
/* led1 on */
@@ -56,18 +57,8 @@ static void led_thread_entry(void* parameter)
}
}
void rt_init_thread_entry(void* parameter)
int main(void)
{
#ifdef RT_USING_COMPONENTS_INIT
/* initialization RT-Thread Components */
rt_components_init();
#endif
}
int rt_application_init(void)
{
rt_thread_t init_thread;
rt_err_t result;
/* init led thread */
@@ -77,17 +68,12 @@ int rt_application_init(void)
RT_NULL,
(rt_uint8_t*)&led_stack[0],
sizeof(led_stack),
7,
RT_THREAD_PRIORITY_MAX/3,
5);
if (result == RT_EOK)
{
rt_thread_startup(&led_thread);
}
init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024,
RT_THREAD_PRIORITY_MAX / 3, 20);
if (init_thread != RT_NULL)
rt_thread_startup(init_thread);
return 0;
}
-93
View File
@@ -1,93 +0,0 @@
/*
* File : startup.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, 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
* 2017-09-11 Haley the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
/**
* @addtogroup Apollo2
*/
/*@{*/
extern int rt_application_init(void);
#ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define AM_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="HEAP"
#define AM_SRAM_BEGIN (__segment_end("HEAP"))
#else
extern int __bss_end;
#define NRF_SRAM_BEGIN (&__bss_end)
#endif
/**
* This function will startup RT-Thread RTOS.
*/
void rtthread_startup(void)
{
/* init board */
rt_hw_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
rt_system_heap_init((void*)AM_SRAM_BEGIN, (void*)AM_SRAM_END);
#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;
}
/*@}*/
+99
View File
@@ -0,0 +1,99 @@
/*
* File : gpio.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-16 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#ifdef RT_USING_PIN
void am_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
{
if (mode == PIN_MODE_OUTPUT)
{
/* output setting */
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_OUTPUT);
}
else if (mode == PIN_MODE_INPUT)
{
/* input setting: not pull. */
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_INPUT);
}
else if (mode == PIN_MODE_INPUT_PULLUP)
{
/* input setting: pull up. */
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_OPENDRAIN);
}
else
{
/* input setting:default. */
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_INPUT);
}
}
void am_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
{
if (value == PIN_LOW)
{
am_hal_gpio_out_bit_clear(pin);
}
else
{
am_hal_gpio_out_bit_set(pin);
}
}
int am_pin_read(rt_device_t dev, rt_base_t pin)
{
int value = PIN_LOW;
if (am_hal_gpio_input_bit_read(pin) == 0)
{
value = PIN_LOW;
}
else
{
value = PIN_HIGH;
}
return value;
}
const static struct rt_pin_ops _am_pin_ops =
{
am_pin_mode,
am_pin_write,
am_pin_read,
};
int hw_pin_init(void)
{
rt_device_pin_register("pin", &_am_pin_ops, RT_NULL);
return 0;
}
INIT_BOARD_EXPORT(hw_pin_init);
#endif
/*@}*/
+30
View File
@@ -0,0 +1,30 @@
/*
* File : gpio.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-16 Haley the first version
*/
#ifndef __GPIO_H
#define __GPIO_H
int hw_pin_init(void);
#endif // __GPIO_H
File diff suppressed because it is too large. Load diff
-60
View File
@@ -1,60 +0,0 @@
/*
* File : hw_led.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __HW_LED_H
#define __HW_LED_H
#include <rtthread.h>
/**
* @brief LED polarity macros
*
*/
#define AM_LED_POL_POLARITY_M 0x1
#define AM_LED_ON_HIGH 0x1
#define AM_LED_ON_LOW 0x0
/**
* @brief LED direct drive indicator macro
* Or this in with the polarity value to use the GPIO DATA register instead of
* the GPIO DATA ENABLE register to directly drive an LED buffer.
*/
#define AM_LED_POL_DIRECT_DRIVE_M 0x2
/**
* @brief Structure for keeping track of LEDs
*
*/
typedef struct
{
rt_uint32_t GPIONumber;
rt_uint32_t Polarity;
}
rt_hw_led_t;
/**
* @brief External function definitions
*
*/
void rt_hw_led_init(rt_uint32_t LEDNum);
void rt_hw_led_array_init(rt_uint32_t NumLEDs);
void rt_hw_led_array_disable(rt_uint32_t NumLEDs);
void rt_hw_led_on(rt_uint32_t LEDNum);
void rt_hw_led_off(rt_uint32_t LEDNum);
void rt_hw_led_toggle(rt_uint32_t LEDNum);
int rt_hw_led_get(rt_uint32_t LEDNum);
void rt_hw_led_array_out(rt_uint32_t NumLEDs, rt_uint32_t Value);
#endif // __HW_LED_H
-23
View File
@@ -1,23 +0,0 @@
/*
* File : hw_uart.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __HW_UART_H_
#define __HW_UART_H_
#include <rtthread.h>
void rt_hw_uart_init(void);
void rt_hw_uart_send_string(char *pcString);
#endif // __HW_UART_H_
+152
View File
@@ -0,0 +1,152 @@
/*
* File :_led.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#include "board.h"
#define AM_GPIO_LED0 46
#define AM_GPIO_LED1 47
#define AM_GPIO_LED2 48
#define AM_GPIO_LED3 49
/**
* @brief Turns on the requested LED.
*
* @param LEDNum is the LED number for the light to turn on.
*
* This function turns on a single LED.
*
* @return None.
*/
void rt_hw_led_on(rt_uint8_t LEDNum)
{
if(LEDNum == 0)
rt_pin_write(AM_GPIO_LED0, PIN_LOW);
else if(LEDNum == 1)
rt_pin_write(AM_GPIO_LED1, PIN_LOW);
else if(LEDNum == 2)
rt_pin_write(AM_GPIO_LED2, PIN_LOW);
else if(LEDNum == 3)
rt_pin_write(AM_GPIO_LED3, PIN_LOW);
}
/**
* @brief Turns off the requested LED.
*
* @param LEDNum is the LED number for the light to turn off.
*
* This function turns off a single LED.
*
* @return None.
*/
void rt_hw_led_off(rt_uint8_t LEDNum)
{
if(LEDNum == 0)
rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
else if(LEDNum == 1)
rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
else if(LEDNum == 2)
rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
else if(LEDNum == 3)
rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
}
/**
* @brief Configures the necessary pins for an array of LEDs
*
* @param None.
*
* This function configures a GPIO to drive an LED in a low-power way.
*
* @return None.
*/
int rt_hw_led_init(void)
{
#if defined(RT_USING_LED0)
/* config led */
rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(0);
#endif /* RT_USING_LED0 */
#if defined(RT_USING_LED1)
/* config led */
rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(1);
#endif /* RT_USING_LED1 */
#if defined(RT_USING_LED2)
/* config led */
rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(2);
#endif /* RT_USING_LED0 */
#if defined(RT_USING_LED3)
/* config led */
rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(3);
#endif /* RT_USING_LED1 */
return 0;
}
#ifdef RT_USING_PIN
INIT_BOARD_EXPORT(rt_hw_led_init);
#endif
#ifdef RT_USING_FINSH
#include <finsh.h>
void led(rt_uint32_t led, rt_uint32_t state)
{
/* set led status */
switch (state)
{
case 0:
rt_hw_led_off(led);
break;
case 1:
rt_hw_led_on(led);
break;
default:
break;
}
}
FINSH_FUNCTION_EXPORT(led, turn led (0 - 3) on (1) or off (0).)
#endif
/*@}*/
+38
View File
@@ -0,0 +1,38 @@
/*
* File : led.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __HW_LED_H
#define __HW_LED_H
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
void rt_hw_led_init(void);
void rt_hw_led_on(rt_uint8_t LEDNum);
void rt_hw_led_off(rt_uint8_t LEDNum);
#endif // __HW_LED_H
File diff suppressed because it is too large. Load diff
+30
View File
@@ -0,0 +1,30 @@
/*
* File : uart.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __UART_H_
#define __UART_H_
void rt_hw_uart_init(void);
#endif // __UART_H_