gpio toggle works
This commit is contained in:
parent
067dd1d3e5
commit
073f5093dd
@ -6,25 +6,48 @@
|
|||||||
#ifndef BSP_STM32F4_DISCOVERY_H_
|
#ifndef BSP_STM32F4_DISCOVERY_H_
|
||||||
#define BSP_STM32F4_DISCOVERY_H_
|
#define BSP_STM32F4_DISCOVERY_H_
|
||||||
|
|
||||||
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#if 0
|
||||||
#include "driver.h"
|
#include "../../../../../kernel/include/sys_tick.h"
|
||||||
#include "gpio.h"
|
#include "../../../driver/include/stm32_sys_tick.h"
|
||||||
|
#include "../../../driver/include/stm32f4_pwm.h"
|
||||||
|
#include "../../../driver/include/stm32f4_uart.h"
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
#include "sys_tick.h"
|
#endif
|
||||||
#include "stm32f4xx.h"
|
#include "stm32f4xx.h"
|
||||||
|
#include "gpio.h"
|
||||||
#include "stm32f4_gpio.h"
|
#include "stm32f4_gpio.h"
|
||||||
#include "stm32f4_pwm.h"
|
#include "driver.h"
|
||||||
#include "stm32f4_uart.h"
|
|
||||||
#include "stm32_sys_tick.h"
|
// GPIO_D12
|
||||||
|
static const GPIO_InitTypeDef port_cfg_d12 = {
|
||||||
|
.Pin = GPIO_PIN_12,
|
||||||
|
.Mode = GPIO_MODE_OUTPUT_PP,
|
||||||
|
.Speed = GPIO_SPEED_FREQ_HIGH,
|
||||||
|
.Pull = GPIO_PULLUP,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct stm32f4_gpio stm32_f4_gpio_d12 = {
|
||||||
|
.port = GPIOD,
|
||||||
|
.pin = &port_cfg_d12,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct gpio __gpio_d12 = {
|
||||||
|
(void*)&stm32_f4_gpio_d12,
|
||||||
|
&gpio_fp
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct driver gpio_d12 = {
|
||||||
|
DRIVER_TYPE_GPIO,
|
||||||
|
&__gpio_d12,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
// SYSTEM TICK
|
// SYSTEM TICK
|
||||||
static const enum stm32_sys_tick_time_base stm23_sys_tick_time_base =
|
static const enum stm32_sys_tick_time_base stm23_sys_tick_time_base =
|
||||||
STM32_SYS_TICK_TIME_BASE_MS;
|
STM32_SYS_TICK_TIME_BASE_MS;
|
||||||
@ -38,7 +61,8 @@ static const struct loki_timer timer_1 = {
|
|||||||
(void*)&stm32_sys_tick,
|
(void*)&stm32_sys_tick,
|
||||||
&timer_fp
|
&timer_fp
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// PWM CHANNEL 4
|
// PWM CHANNEL 4
|
||||||
/* apb1 clock = 84MHz */
|
/* apb1 clock = 84MHz */
|
||||||
/* period_reg = src_clk / presc / cnt_clk */
|
/* period_reg = src_clk / presc / cnt_clk */
|
||||||
@ -93,7 +117,8 @@ const struct driver pwm_4 = {
|
|||||||
DRIVER_TYPE_PWM,
|
DRIVER_TYPE_PWM,
|
||||||
&pwm_ch4,
|
&pwm_ch4,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// PWM Channel 3
|
// PWM Channel 3
|
||||||
static const GPIO_InitTypeDef port_cfg_D14 = {
|
static const GPIO_InitTypeDef port_cfg_D14 = {
|
||||||
.GPIO_Pin = GPIO_Pin_14,
|
.GPIO_Pin = GPIO_Pin_14,
|
||||||
@ -126,7 +151,8 @@ const struct driver pwm_3 = {
|
|||||||
DRIVER_TYPE_PWM,
|
DRIVER_TYPE_PWM,
|
||||||
&pwm_ch3,
|
&pwm_ch3,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// PWM Channel 2
|
// PWM Channel 2
|
||||||
static const GPIO_InitTypeDef port_cfg_D13 = {
|
static const GPIO_InitTypeDef port_cfg_D13 = {
|
||||||
.GPIO_Pin = GPIO_Pin_13,
|
.GPIO_Pin = GPIO_Pin_13,
|
||||||
@ -159,7 +185,8 @@ const struct driver pwm_2 = {
|
|||||||
DRIVER_TYPE_PWM,
|
DRIVER_TYPE_PWM,
|
||||||
&pwm_ch2,
|
&pwm_ch2,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// PWM Channel 1
|
// PWM Channel 1
|
||||||
static const GPIO_InitTypeDef port_cfg_D12 = {
|
static const GPIO_InitTypeDef port_cfg_D12 = {
|
||||||
.GPIO_Pin = GPIO_Pin_12,
|
.GPIO_Pin = GPIO_Pin_12,
|
||||||
@ -192,7 +219,8 @@ const struct driver pwm_1 = {
|
|||||||
DRIVER_TYPE_PWM,
|
DRIVER_TYPE_PWM,
|
||||||
&pwm_ch1,
|
&pwm_ch1,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// UART 1
|
// UART 1
|
||||||
static char console_linear_buffer[80];
|
static char console_linear_buffer[80];
|
||||||
static struct ringbuffer console_buffer = {
|
static struct ringbuffer console_buffer = {
|
||||||
@ -252,7 +280,8 @@ const struct driver uart_1 = {
|
|||||||
DRIVER_TYPE_UART,
|
DRIVER_TYPE_UART,
|
||||||
&__uart_1,
|
&__uart_1,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// GPIOC0
|
// GPIOC0
|
||||||
static const GPIO_InitTypeDef port_cfg_C0 = {
|
static const GPIO_InitTypeDef port_cfg_C0 = {
|
||||||
GPIO_Pin_0,
|
GPIO_Pin_0,
|
||||||
@ -284,7 +313,8 @@ const struct driver gpio_c0 = {
|
|||||||
DRIVER_TYPE_GPIO,
|
DRIVER_TYPE_GPIO,
|
||||||
&__gpio_c0,
|
&__gpio_c0,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// GPIO_C1
|
// GPIO_C1
|
||||||
static const GPIO_InitTypeDef port_cfg_C1 = {
|
static const GPIO_InitTypeDef port_cfg_C1 = {
|
||||||
GPIO_Pin_1,
|
GPIO_Pin_1,
|
||||||
@ -316,7 +346,8 @@ const struct driver gpio_c1 = {
|
|||||||
DRIVER_TYPE_GPIO,
|
DRIVER_TYPE_GPIO,
|
||||||
&__gpio_c1,
|
&__gpio_c1,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// GPIO_C2
|
// GPIO_C2
|
||||||
static const GPIO_InitTypeDef port_cfg_C2 = {
|
static const GPIO_InitTypeDef port_cfg_C2 = {
|
||||||
GPIO_Pin_2,
|
GPIO_Pin_2,
|
||||||
@ -348,7 +379,8 @@ const struct driver gpio_c2 = {
|
|||||||
DRIVER_TYPE_GPIO,
|
DRIVER_TYPE_GPIO,
|
||||||
&__gpio_c2,
|
&__gpio_c2,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
// GPIO_C3
|
// GPIO_C3
|
||||||
static const GPIO_InitTypeDef port_cfg_C3 = {
|
static const GPIO_InitTypeDef port_cfg_C3 = {
|
||||||
GPIO_Pin_3,
|
GPIO_Pin_3,
|
||||||
@ -380,7 +412,7 @@ const struct driver gpio_c3 = {
|
|||||||
DRIVER_TYPE_GPIO,
|
DRIVER_TYPE_GPIO,
|
||||||
&__gpio_c3,
|
&__gpio_c3,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
//! \brief Setup the hardware of the stm32f4-discovery board.
|
//! \brief Setup the hardware of the stm32f4-discovery board.
|
||||||
void board_init(void);
|
void board_init(void);
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
//! \file stm32_sys_tick.h
|
|
||||||
//! \author tkl
|
|
||||||
//! \date Feb 15, 2012
|
|
||||||
//! \brief Header file of the stm32f10x architecture dependent sys tick timer implementation.
|
|
||||||
#ifndef STM32_SYS_TICK_H_
|
|
||||||
#define STM32_SYS_TICK_H_
|
|
||||||
|
|
||||||
#include "timer.h"
|
|
||||||
|
|
||||||
typedef void* (*stm32_sys_tick_cb_t)(void*); //!< callback for the external interrupt
|
|
||||||
|
|
||||||
//! \brief Type of sys tick base time.
|
|
||||||
enum stm32_sys_tick_time_base {
|
|
||||||
STM32_SYS_TICK_TIME_BASE_NONE = 0, //!< Not init
|
|
||||||
STM32_SYS_TICK_TIME_BASE_US, //!< Tick time = 1 us.
|
|
||||||
STM32_SYS_TICK_TIME_BASE_MS //!< Tick time = 1 ms.
|
|
||||||
};
|
|
||||||
|
|
||||||
//! \brief The sys tick device.
|
|
||||||
struct stm32_sys_tick {
|
|
||||||
const enum stm32_sys_tick_time_base *tick_time_base; //!< time base for the system tick
|
|
||||||
stm32_sys_tick_cb_t sys_tick_cb; //!< callback for the sys tick interrupt
|
|
||||||
void *sys_tick_cb_param; //!< parameter for the callback
|
|
||||||
};
|
|
||||||
|
|
||||||
//! \brief Open a sys tick timer.
|
|
||||||
//! \param sys_tick The sys tick to open. Must be of type const stm32_sys_tick_t*.
|
|
||||||
//! \return -1 in error case.
|
|
||||||
int stm32_sys_tick_open(const void *sys_tick);
|
|
||||||
|
|
||||||
//! \brief Close a sys tick timer.
|
|
||||||
//! \param sys_tick The sys tick to close. Must be of type const stm32_sys_tick_t*.
|
|
||||||
//! \return -1 in error case.
|
|
||||||
int stm32_sys_tick_close(const void *sys_tick);
|
|
||||||
|
|
||||||
//! \brief Set the call back for a sys tick timer.
|
|
||||||
//! \param sys_tick The sys tick to open. Mus be of type const stm32_sys_tick_t*.
|
|
||||||
//! \param callback The function pointer of the call back function.
|
|
||||||
//! \param param The parameter for the call back function.
|
|
||||||
//! \return -1 in error case.
|
|
||||||
int stm32_sys_tick_set_cb(const void *sys_tick, const void *callback, const void *param);
|
|
||||||
|
|
||||||
static const struct timer_fp timer_fp = {
|
|
||||||
stm32_sys_tick_open,
|
|
||||||
stm32_sys_tick_close,
|
|
||||||
stm32_sys_tick_set_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* STM32_SYS_TICK_H_ */
|
|
@ -12,8 +12,6 @@ typedef void* (*gpio_ext_it_cb_t)(void*);
|
|||||||
struct stm32f4_gpio {
|
struct stm32f4_gpio {
|
||||||
GPIO_TypeDef *port; //!< Gpio port
|
GPIO_TypeDef *port; //!< Gpio port
|
||||||
const GPIO_InitTypeDef *pin; //!< Gpio pin
|
const GPIO_InitTypeDef *pin; //!< Gpio pin
|
||||||
gpio_ext_it_cb_t ext_it_cb; //!< Gpio ext it callback (could be NULL)
|
|
||||||
void *param; //!< Parameter for the callback
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \brief Open a gpio.
|
//! \brief Open a gpio.
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* stm32f4_pwm.h
|
|
||||||
*
|
|
||||||
* Created on: Aug 9, 2016
|
|
||||||
* Author: tkl
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_INCLUDE_STM32F4_PWM_H_
|
|
||||||
#define SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_INCLUDE_STM32F4_PWM_H_
|
|
||||||
|
|
||||||
enum stm32f4_pwm_channel {
|
|
||||||
channel_1 = 1,
|
|
||||||
channel_2,
|
|
||||||
channel_3,
|
|
||||||
channel_4
|
|
||||||
};
|
|
||||||
|
|
||||||
struct stm32f4_pwm {
|
|
||||||
TIM_TypeDef *timer;
|
|
||||||
const TIM_TimeBaseInitTypeDef *timer_cfg;
|
|
||||||
const TIM_OCInitTypeDef *output_compare_cfg;
|
|
||||||
const TIM_BDTRInitTypeDef *bdtr_cfg;
|
|
||||||
GPIO_TypeDef *port;
|
|
||||||
uint8_t pin_src;
|
|
||||||
const GPIO_InitTypeDef *port_cfg;
|
|
||||||
enum stm32f4_pwm_channel channel;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int stm32f4_pwm_open(const void *pwm);
|
|
||||||
int stm32f4_pwm_close(const void *pwm);
|
|
||||||
int stm32f4_pwm_set_duty_cycle(const void *pwm, unsigned int duty_cycle_percent);
|
|
||||||
|
|
||||||
static const struct pwm_fp stm32f4_pwm_fp = {
|
|
||||||
.open = stm32f4_pwm_open,
|
|
||||||
.close = stm32f4_pwm_close,
|
|
||||||
.set_duty_cycle = stm32f4_pwm_set_duty_cycle,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_INCLUDE_STM32F4_PWM_H_ */
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* stm32_uart.h
|
|
||||||
*
|
|
||||||
* Created on: Jul 24, 2016
|
|
||||||
* Author: tkl
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_
|
|
||||||
#define SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_
|
|
||||||
|
|
||||||
#include "driver.h"
|
|
||||||
#include "uart.h"
|
|
||||||
|
|
||||||
//! \brief Stm32f4 uart device.
|
|
||||||
struct stm32f4_uart {
|
|
||||||
const GPIO_InitTypeDef *gpio_init;
|
|
||||||
GPIO_TypeDef *gpio_port;
|
|
||||||
uint8_t pin_src_rx;
|
|
||||||
uint8_t pin_src_tx;
|
|
||||||
const USART_InitTypeDef *usart_init;
|
|
||||||
USART_TypeDef *usart_port;
|
|
||||||
uint16_t usart_it_select;
|
|
||||||
const NVIC_InitTypeDef *nvic_init;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! \brief Open an uart device.
|
|
||||||
//! \param this The uart to open.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int stm32f4_uart_open(const void *this);
|
|
||||||
|
|
||||||
//! \brief Close an uart device.
|
|
||||||
//! \param this The uart to close.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int stm32f4_uart_close(const void *this);
|
|
||||||
|
|
||||||
//! \brief Read from an uart device.
|
|
||||||
//! \param this The uart to read from.
|
|
||||||
//! \param buffer The buffer to read to.
|
|
||||||
//! \param len The length of the buffer.
|
|
||||||
//! \retval -1 in error case, otherwise number of read characters.
|
|
||||||
int stm32f4_uart_read(const void *this, char *buffer, int len);
|
|
||||||
|
|
||||||
//! \brief Write to an uart device.
|
|
||||||
//! \param this The uart to write to.
|
|
||||||
//! \param buffer The buffer to write.
|
|
||||||
//! \param len The number of characters to write.
|
|
||||||
//! \retval -1 in error case, otherwise number of written characters.
|
|
||||||
int stm32f4_uart_write(const void *this, const char *buffer, int len);
|
|
||||||
|
|
||||||
//! \brief Set a callback for interrupt handling of the uart.
|
|
||||||
//! \param this The uart.
|
|
||||||
//! \param callback The callback to execute in interrupt case.
|
|
||||||
//! \param param The argument for the callback.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int stm32f4_uart_set_cb(const void *this, const void *callback, const void *param);
|
|
||||||
|
|
||||||
static const struct uart_fp stm32f4_uart_fp = {
|
|
||||||
stm32f4_uart_open,
|
|
||||||
stm32f4_uart_close,
|
|
||||||
stm32f4_uart_read,
|
|
||||||
stm32f4_uart_write,
|
|
||||||
stm32f4_uart_set_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_ */
|
|
@ -16,7 +16,7 @@
|
|||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
||||||
int open(const struct driver *driver)
|
int drv_open(const struct driver *driver)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if(NULL == driver)
|
if(NULL == driver)
|
||||||
@ -35,19 +35,19 @@ int open(const struct driver *driver)
|
|||||||
ret = pwm_open((const struct pwm *)(driver->device_driver));
|
ret = pwm_open((const struct pwm *)(driver->device_driver));
|
||||||
break;
|
break;
|
||||||
case DRIVER_TYPE_RTC:
|
case DRIVER_TYPE_RTC:
|
||||||
ret = rtc_open((const struct rtc *)(driver->device_driver));
|
// ret = rtc_open((const struct rtc *)(driver->device_driver));
|
||||||
break;
|
break;
|
||||||
case DRIVER_TYPE_SPI:
|
case DRIVER_TYPE_SPI:
|
||||||
ret = spi_open((const struct spi *)(driver->device_driver));
|
ret = spi_open((const struct spi *)(driver->device_driver));
|
||||||
break;
|
break;
|
||||||
case DRIVER_TYPE_UART:
|
case DRIVER_TYPE_UART:
|
||||||
ret = uart_open((const struct uart *)(driver->device_driver));
|
// ret = uart_open((const struct uart *)(driver->device_driver));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int close(const struct driver *driver)
|
int drv_close(const struct driver *driver)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if(NULL == driver)
|
if(NULL == driver)
|
||||||
@ -78,7 +78,7 @@ int close(const struct driver *driver)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read(const struct driver *driver, char *buffer, int len)
|
int drv_read(const struct driver *driver, char *buffer, int len)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if(NULL == driver)
|
if(NULL == driver)
|
||||||
@ -109,7 +109,7 @@ int read(const struct driver *driver, char *buffer, int len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write(const struct driver *driver, const char *buffer, int len)
|
int drv_write(const struct driver *driver, const char *buffer, int len)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if(NULL == driver)
|
if(NULL == driver)
|
||||||
@ -136,13 +136,13 @@ int write(const struct driver *driver, const char *buffer, int len)
|
|||||||
case DRIVER_TYPE_SPI:
|
case DRIVER_TYPE_SPI:
|
||||||
break;
|
break;
|
||||||
case DRIVER_TYPE_UART:
|
case DRIVER_TYPE_UART:
|
||||||
ret = uart_write((const struct uart *)(driver->device_driver), buffer, len);
|
// ret = uart_write((const struct uart *)(driver->device_driver), buffer, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ioctl(const struct driver *driver, unsigned int cmd, const void *data)
|
int drv_ioctl(const struct driver *driver, unsigned int cmd, const void *data)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if(NULL == driver)
|
if(NULL == driver)
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
CHECK_FOLDER += source/firmware/kernel/driver
|
SRC_DIR += source/firmware/kernel/driver
|
||||||
SUB_FOLDER += source/firmware/kernel/driver
|
|
||||||
INCLUDES += source/firmware/kernel/driver/include
|
INCLUDES += source/firmware/kernel/driver/include
|
||||||
DOC_SRC += source/firmware/kernel/driver
|
|
||||||
|
@ -1,161 +0,0 @@
|
|||||||
//! \file rtc.h
|
|
||||||
//! \author tkl
|
|
||||||
//! \date Jul 8, 2012
|
|
||||||
//! \brief Header file of the architecture independent rtc implementation.
|
|
||||||
#ifndef RTC_H_
|
|
||||||
#define RTC_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Loki time container.
|
|
||||||
struct loki_time {
|
|
||||||
uint32_t sec; //!< Seconds. [0-60]
|
|
||||||
uint32_t min; //!< Minutes. [0-59]
|
|
||||||
uint32_t hour; //!< Hours. [0-23]
|
|
||||||
uint32_t day; //!< Day. [1-31]
|
|
||||||
uint32_t mon; //!< Month. [0-11]
|
|
||||||
uint32_t year; //!< Year.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Rtc interrupt interval.
|
|
||||||
enum rtc_interval {
|
|
||||||
RTC_INTERVAL_MINUTE = 0, //!< rtc interrupt every minute.
|
|
||||||
RTC_INTERVAL_HOUR, //!< rtc interrupt every hour.
|
|
||||||
RTC_INTERVAL_MIDNIGHT, //!< rtc interrupt every day at 00:00.
|
|
||||||
RTC_INTERVAL_NOON //!< rtc interrupt every day at 12:00.
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Rtc alarm mask.
|
|
||||||
enum rtc_alarm_mask {
|
|
||||||
RTC_ALARM_DISABLED = 0x00, //!< Alarm mask disabled.
|
|
||||||
RTC_ALARM_MINUTE = 0x01, //!< Alarm mask minute.
|
|
||||||
RTC_ALARM_HOUR = 0x02, //!< Alarm mask hour.
|
|
||||||
RTC_ALARM_DAY_OF_WEEK = 0x04, //!< Alarm mask day of week.
|
|
||||||
RTC_ALARM_DAY_OF_MONTH = 0x08 //!< Alarm mask day of month.
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! Callback for the open function of the arch depended rtc driver.
|
|
||||||
typedef int (*rtc_fp_open_t)(const void*);
|
|
||||||
|
|
||||||
//! Callback for the close function of the arch depended rtc driver.
|
|
||||||
typedef int (*rtc_fp_close_t)(const void*);
|
|
||||||
|
|
||||||
//! Callback for the time set function of the arch depended rtc driver.
|
|
||||||
typedef void (*rtc_fp_set_time_t)(const void*, const struct loki_time*);
|
|
||||||
|
|
||||||
//! Callback for the time get function of the arch depended rtc driver.
|
|
||||||
typedef struct loki_time *(*rtc_fp_get_time_t)(const void*, struct loki_time*);
|
|
||||||
|
|
||||||
//! Callback for the start interval event function.
|
|
||||||
typedef int (*rtc_fp_start_interval_event)
|
|
||||||
(const void *, enum rtc_interval, const void *, const void *);
|
|
||||||
|
|
||||||
//! Callback for the stop interval event.
|
|
||||||
typedef int (*rtc_fp_stop_interval_event)(const void *);
|
|
||||||
|
|
||||||
//! Callback for the start alarm event.
|
|
||||||
typedef int (*rtc_fp_start_alarm_event)
|
|
||||||
(const void *, const struct loki_time*, enum rtc_alarm_mask, const void *, const void *);
|
|
||||||
|
|
||||||
//! Callback for the stop alarm event.
|
|
||||||
typedef int (*rtc_fp_stop_alarm_event)(const void *);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Function pointer to access the rct driver.
|
|
||||||
struct rtc_fp {
|
|
||||||
const rtc_fp_open_t open; //!< Function pointer to the open function.
|
|
||||||
const rtc_fp_close_t close; //!< Function pointer to the close function.
|
|
||||||
const rtc_fp_set_time_t set_time; //!< Function pointer to the set_time function.
|
|
||||||
const rtc_fp_get_time_t get_time; //!< Function pointer to the get_time function.
|
|
||||||
const rtc_fp_start_interval_event start_interval; //!< Function pointer to the start_interval function.
|
|
||||||
const rtc_fp_stop_interval_event stop_interval; //!< Function pointer to the stop_interval function.
|
|
||||||
const rtc_fp_start_alarm_event start_alarm; //!< Function pointer to the start_alarm function.
|
|
||||||
const rtc_fp_stop_alarm_event stop_alarm; //!< Function pointer to the stop_alarm function.
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Contains the architecture depended device and the access functions to the rtc driver.
|
|
||||||
struct rtc {
|
|
||||||
const void *arch_dep_device; //!< Architecture depended rtc device (i.e. msp430_rtc_t).
|
|
||||||
const struct rtc_fp *fp; //!< Function pointer for the rtc driver access.
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Open a rtc device.
|
|
||||||
//! \param device The rtc device to open.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int rtc_open(const struct rtc *device);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Close a rtc device.
|
|
||||||
//! \param device The rtc device to close.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int rtc_close(const struct rtc *device);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Set rtc time.
|
|
||||||
//! \param device The rtc device.
|
|
||||||
//! \param time The time to set.
|
|
||||||
void rtc_set_time(const struct rtc *device, const struct loki_time *time);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Get rtc time.
|
|
||||||
//! \param device The rtc device.
|
|
||||||
//! \param time The time to get.
|
|
||||||
//! \retval NULL in error case, otherwise points to time.
|
|
||||||
struct loki_time *rtc_get_time(const struct rtc *device,
|
|
||||||
struct loki_time *time);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Converts a Unix timestamp to a loki_time.
|
|
||||||
//! \param tick The Unix timestamp.
|
|
||||||
//! \return the converted time.
|
|
||||||
struct loki_time tick_to_time(uint32_t tick);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Converts a loki_time to aunix timestamp.
|
|
||||||
//! \param time The time to convert.
|
|
||||||
//! \return The converted unix timestamp.
|
|
||||||
uint32_t time_to_tick(const struct loki_time *time);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Starts a rtc interval event.
|
|
||||||
//! On every occurance of interval the rtc event gets fired.
|
|
||||||
//! \param device The rtc device.
|
|
||||||
//! \param interval The interval of rtc event occurance.
|
|
||||||
//! \param callback The callback is executed in case of interval event.
|
|
||||||
//! \param argument The argument for the callback.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int rtc_start_interval_event(const struct rtc *device, enum rtc_interval interval,
|
|
||||||
const void * callback, const void *argument);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Stops a rtc interval event.
|
|
||||||
//! \param device The rtc device.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int rtc_stop_interval_event(const struct rtc *device);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Starts a rtc alarm event.
|
|
||||||
//! \param device The rtc device.
|
|
||||||
//! \param alarm_time The time to fire the alarm.
|
|
||||||
//! \param alarm_mask The mask to filter the alarm time.
|
|
||||||
//! \param callback The callback is executed in case of alarm.
|
|
||||||
//! \param argument The argument for the callback.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int rtc_start_alarm_event(const struct rtc *device,
|
|
||||||
const struct loki_time *alarm_time, enum rtc_alarm_mask alarm_mask,
|
|
||||||
const void * callback, const void *argument);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//! \brief Stops a rtc alarm.
|
|
||||||
//! \param device The rtc device.
|
|
||||||
//! \retval -1 in error case.
|
|
||||||
int rtc_stop_alarm_event(const struct rtc *device);
|
|
||||||
|
|
||||||
#endif /* RTC_H_ */
|
|
@ -1,218 +0,0 @@
|
|||||||
//! \file rtc.c
|
|
||||||
//! \author tkl
|
|
||||||
//! \date Jul 8, 2012
|
|
||||||
//! \brief Source file of the architecture independent rtc implementation.
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "rtc.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int rtc_open(const struct rtc *device) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_fp_open_t open = device->fp->open;
|
|
||||||
return (open(device->arch_dep_device));
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int rtc_close(const struct rtc *device) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_fp_close_t close = device->fp->close;
|
|
||||||
return (close(device->arch_dep_device));
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
void rtc_set_time(const struct rtc *device, const struct loki_time *time) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_fp_set_time_t set_time = device->fp->set_time;
|
|
||||||
set_time(device->arch_dep_device, time);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
struct loki_time *rtc_get_time(const struct rtc *device, struct loki_time *time) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_fp_get_time_t get_time = device->fp->get_time;
|
|
||||||
return (get_time(device->arch_dep_device, time));
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef __isleap
|
|
||||||
//! Nonzero if YEAR is a leap year (every 4 years, except every 100th isn't, and every 400th is).
|
|
||||||
#define __isleap(year) \
|
|
||||||
((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//! Seconds per hour.
|
|
||||||
#define SECS_PER_HOUR (long)(60 * 60)
|
|
||||||
|
|
||||||
//! Seconds per day.
|
|
||||||
#define SECS_PER_DAY (long)(SECS_PER_HOUR * 24)
|
|
||||||
|
|
||||||
//! Clocks per sec.
|
|
||||||
#define CLOCKS_PER_SEC 1000
|
|
||||||
|
|
||||||
|
|
||||||
static const uint8_t __mon_lengths[2][12] = {
|
|
||||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, /* Normal years. */
|
|
||||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } /* Leap years. */
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
uint32_t time_to_tick(const struct loki_time *time) {
|
|
||||||
if(NULL == time) {
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
uint32_t ret = 0;
|
|
||||||
uint32_t year = time->year - 1970;
|
|
||||||
ret = time->sec + time->min * 60 + time->hour * 3600;
|
|
||||||
uint32_t days_in_year = 0;
|
|
||||||
switch(time->mon) {
|
|
||||||
case 1:
|
|
||||||
days_in_year = time->day;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
days_in_year = time->day + 31;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
days_in_year = time->day + 31 + 28;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(days_in_year > 0) {
|
|
||||||
days_in_year--;
|
|
||||||
}
|
|
||||||
uint32_t leap_days = 0;
|
|
||||||
uint32_t y = time->year;
|
|
||||||
while(y >= 1970) {
|
|
||||||
leap_days += __isleap(y) ? 1 : 0;
|
|
||||||
y--;
|
|
||||||
}
|
|
||||||
if(__isleap(time->year)) {
|
|
||||||
if(days_in_year < 59) {
|
|
||||||
if(leap_days > 0) {
|
|
||||||
leap_days--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret += (days_in_year + leap_days) * 60 * 60 * 24;
|
|
||||||
ret += (year * 60 * 60 * 24 * 365);
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
struct loki_time tick_to_time(uint32_t tick) {
|
|
||||||
struct loki_time ret;
|
|
||||||
uint32_t days, rem;
|
|
||||||
uint32_t y;
|
|
||||||
char *ip;
|
|
||||||
|
|
||||||
days = tick / SECS_PER_DAY;
|
|
||||||
rem = tick % SECS_PER_DAY;
|
|
||||||
while (rem < 0) {
|
|
||||||
rem += SECS_PER_DAY;
|
|
||||||
--days;
|
|
||||||
}
|
|
||||||
while (rem >= SECS_PER_DAY) {
|
|
||||||
rem -= SECS_PER_DAY;
|
|
||||||
++days;
|
|
||||||
}
|
|
||||||
ret.hour = rem / SECS_PER_HOUR;
|
|
||||||
rem %= SECS_PER_HOUR;
|
|
||||||
ret.min = rem / 60;
|
|
||||||
ret.sec = rem % 60;
|
|
||||||
y = 1970;
|
|
||||||
while (days >= (rem = __isleap(y) ? 366 : 365)) {
|
|
||||||
++y;
|
|
||||||
days -= rem;
|
|
||||||
}
|
|
||||||
while (days < 0) {
|
|
||||||
--y;
|
|
||||||
days += __isleap(y) ? 366 : 365;
|
|
||||||
}
|
|
||||||
ret.year = y;
|
|
||||||
ip = (char *)__mon_lengths[__isleap(y)];
|
|
||||||
for (y = 0; days >= ip[y]; ++y)
|
|
||||||
days -= ip[y];
|
|
||||||
ret.mon = y + 1;
|
|
||||||
ret.day = days + 1;
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int rtc_start_interval_event(const struct rtc *device, enum rtc_interval interval,
|
|
||||||
const void *callback, const void *argument) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
rtc_fp_start_interval_event start_interval = device->fp->start_interval;
|
|
||||||
return (start_interval(device->arch_dep_device, interval, callback, argument));
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int rtc_stop_interval_event(const struct rtc *device) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
rtc_fp_stop_interval_event stop_interval = device->fp->stop_interval;
|
|
||||||
return (stop_interval(device->arch_dep_device));
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int rtc_start_alarm_event(const struct rtc *device,
|
|
||||||
const struct loki_time *alarm_time, enum rtc_alarm_mask alarm_mask,
|
|
||||||
const void *callback, const void *argument)
|
|
||||||
{
|
|
||||||
if(NULL == device) {
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
rtc_fp_start_alarm_event start_alarm = device->fp->start_alarm;
|
|
||||||
return (start_alarm(device->arch_dep_device, alarm_time, alarm_mask,
|
|
||||||
callback, argument));
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
int rtc_stop_alarm_event(const struct rtc *device) {
|
|
||||||
if(NULL == device) {
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
rtc_fp_stop_alarm_event stop_alarm = device->fp->stop_alarm;
|
|
||||||
return (stop_alarm(device->arch_dep_device));
|
|
||||||
}
|
|
@ -8,6 +8,6 @@
|
|||||||
#ifndef SYS_TICK_H_
|
#ifndef SYS_TICK_H_
|
||||||
#define SYS_TICK_H_
|
#define SYS_TICK_H_
|
||||||
|
|
||||||
void sys_tick_init(const struct loki_timer *hw_timer);
|
//void sys_tick_init(const struct loki_timer *hw_timer);
|
||||||
|
|
||||||
#endif /* SYS_TICK_H_ */
|
#endif /* SYS_TICK_H_ */
|
||||||
|
@ -20,15 +20,18 @@ enum driver_type {
|
|||||||
DRIVER_TYPE_UART
|
DRIVER_TYPE_UART
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#pragma pack(push)
|
||||||
|
#pragma pack(1)
|
||||||
struct driver {
|
struct driver {
|
||||||
enum driver_type driver_type;
|
enum driver_type driver_type;
|
||||||
const void *device_driver;
|
const void *device_driver;
|
||||||
};
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
int open(const struct driver *driver);
|
int drv_open(const struct driver *driver);
|
||||||
int close(const struct driver *driver);
|
int drv_close(const struct driver *driver);
|
||||||
int read(const struct driver *driver, char *buffer, int len);
|
int drv_read(const struct driver *driver, char *buffer, int len);
|
||||||
int write(const struct driver *driver, const char *buffer, int len);
|
int drv_write(const struct driver *driver, const char *buffer, int len);
|
||||||
int ioctl(const struct driver *driver, unsigned int cmd, const void *data);
|
int drv_ioctl(const struct driver *driver, unsigned int cmd, const void *data);
|
||||||
|
|
||||||
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
||||||
|
@ -43,20 +43,20 @@ static void rx_func(void *arg)
|
|||||||
char buffer[81];
|
char buffer[81];
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
open(shell_object.shell_device);
|
drv_open(shell_object.shell_device);
|
||||||
while(1) {
|
while(1) {
|
||||||
ret = read(shell_object.shell_device, &buffer[index],
|
ret = drv_read(shell_object.shell_device, &buffer[index],
|
||||||
sizeof(buffer) / sizeof(buffer[0]) - index - 1);
|
sizeof(buffer) / sizeof(buffer[0]) - index - 1);
|
||||||
if(ret) {
|
if(ret) {
|
||||||
if(shell_object.echo_on) {
|
if(shell_object.echo_on) {
|
||||||
if((buffer[index + ret - 1] == '\n') && (buffer[index + ret -2] != '\r')) {
|
if((buffer[index + ret - 1] == '\n') && (buffer[index + ret -2] != '\r')) {
|
||||||
write(shell_object.shell_device, "\r\n", 2);
|
drv_write(shell_object.shell_device, "\r\n", 2);
|
||||||
}
|
}
|
||||||
else if((buffer[index + ret - 1] == '\r') && (buffer[index + ret -2] != '\n')) {
|
else if((buffer[index + ret - 1] == '\r') && (buffer[index + ret -2] != '\n')) {
|
||||||
write(shell_object.shell_device, "\r\n", 2);
|
drv_write(shell_object.shell_device, "\r\n", 2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write(shell_object.shell_device, &buffer[index], ret); // echo
|
drv_write(shell_object.shell_device, &buffer[index], ret); // echo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((buffer[index + ret - 1] == '\n') || (buffer[index + ret - 1] == '\r')) {
|
if((buffer[index + ret - 1] == '\n') || (buffer[index + ret - 1] == '\r')) {
|
||||||
|
@ -49,14 +49,14 @@ static void *cmd_kosmos_version_cb(const char *cmd)
|
|||||||
{
|
{
|
||||||
char *greeter = "Kosmos Version: ";
|
char *greeter = "Kosmos Version: ";
|
||||||
|
|
||||||
write(shell_object.shell_device, greeter, strlen(greeter));
|
drv_write(shell_object.shell_device, greeter, strlen(greeter));
|
||||||
write(shell_object.shell_device, KERNEL_VERSION, strlen(KERNEL_VERSION));
|
drv_write(shell_object.shell_device, KERNEL_VERSION, strlen(KERNEL_VERSION));
|
||||||
write(shell_object.shell_device, ".", 1);
|
drv_write(shell_object.shell_device, ".", 1);
|
||||||
write(shell_object.shell_device, MAJOR_VERSION, strlen(MAJOR_VERSION));
|
drv_write(shell_object.shell_device, MAJOR_VERSION, strlen(MAJOR_VERSION));
|
||||||
write(shell_object.shell_device, ".", 1);
|
drv_write(shell_object.shell_device, ".", 1);
|
||||||
write(shell_object.shell_device, MINOR_VERSION, strlen(MINOR_VERSION));
|
drv_write(shell_object.shell_device, MINOR_VERSION, strlen(MINOR_VERSION));
|
||||||
write(shell_object.shell_device, ".", 1);
|
drv_write(shell_object.shell_device, ".", 1);
|
||||||
write(shell_object.shell_device, BUILD_NUMBER, strlen(BUILD_NUMBER));
|
drv_write(shell_object.shell_device, BUILD_NUMBER, strlen(BUILD_NUMBER));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,14 +66,14 @@ static void *cmd_list_all_commands_cb(const char *cmd)
|
|||||||
struct list_node *it = shell_object.command_list.front;
|
struct list_node *it = shell_object.command_list.front;
|
||||||
int i, len = list_get_len(&shell_object.command_list);
|
int i, len = list_get_len(&shell_object.command_list);
|
||||||
|
|
||||||
write(shell_object.shell_device, greeter, strlen(greeter));
|
drv_write(shell_object.shell_device, greeter, strlen(greeter));
|
||||||
for(i = 0; i < (len - 1); i++) {
|
for(i = 0; i < (len - 1); i++) {
|
||||||
if(NULL != it) {
|
if(NULL != it) {
|
||||||
struct command *cmd = (struct command *)it->data;
|
struct command *cmd = (struct command *)it->data;
|
||||||
write(shell_object.shell_device, cmd->command, strlen(cmd->command));
|
drv_write(shell_object.shell_device, cmd->command, strlen(cmd->command));
|
||||||
write(shell_object.shell_device, " - ", 3);
|
drv_write(shell_object.shell_device, " - ", 3);
|
||||||
write(shell_object.shell_device, cmd->description, strlen(cmd->description));
|
drv_write(shell_object.shell_device, cmd->description, strlen(cmd->description));
|
||||||
write(shell_object.shell_device, "\r\n", 2);
|
drv_write(shell_object.shell_device, "\r\n", 2);
|
||||||
it = it->next;
|
it = it->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
* Created on: Sep 25, 2015
|
* Created on: Sep 25, 2015
|
||||||
* Author: tkl
|
* Author: tkl
|
||||||
*/
|
*/
|
||||||
|
#include "include/sys_tick.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@ -14,7 +16,6 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "schedule.h"
|
#include "schedule.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "sys_tick.h"
|
|
||||||
|
|
||||||
struct sys_tick_obj
|
struct sys_tick_obj
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "BlinkLed.h"
|
#include "BlinkLed.h"
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
#include "driver.h"
|
||||||
|
|
||||||
// Keep the LED on for 2/3 of a second.
|
// Keep the LED on for 2/3 of a second.
|
||||||
#define BLINK_ON_TICKS (TIMER_FREQUENCY_HZ * 3 / 4)
|
#define BLINK_ON_TICKS (TIMER_FREQUENCY_HZ * 3 / 4)
|
||||||
#define BLINK_OFF_TICKS (TIMER_FREQUENCY_HZ - BLINK_ON_TICKS)
|
#define BLINK_OFF_TICKS (TIMER_FREQUENCY_HZ - BLINK_ON_TICKS)
|
||||||
@ -26,12 +29,16 @@ int main(int argc, char* argv[])
|
|||||||
trace_puts("Hello ARM World!");
|
trace_puts("Hello ARM World!");
|
||||||
trace_printf("System clock: %u Hz\n", SystemCoreClock);
|
trace_printf("System clock: %u Hz\n", SystemCoreClock);
|
||||||
timer_start();
|
timer_start();
|
||||||
blink_led_init();
|
// blink_led_init();
|
||||||
uint32_t seconds = 0;
|
uint32_t seconds = 0;
|
||||||
|
drv_open(&gpio_d12);
|
||||||
|
drv_write(&gpio_d12, "1", 1);
|
||||||
while(1) {
|
while(1) {
|
||||||
blink_led_on();
|
// blink_led_on();
|
||||||
|
drv_write(&gpio_d12, "1", 1);
|
||||||
timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);
|
timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);
|
||||||
blink_led_off();
|
// blink_led_off();
|
||||||
|
drv_write(&gpio_d12, "0", 1);
|
||||||
timer_sleep(BLINK_OFF_TICKS);
|
timer_sleep(BLINK_OFF_TICKS);
|
||||||
++seconds;
|
++seconds;
|
||||||
trace_printf("Second %u\n", seconds);
|
trace_printf("Second %u\n", seconds);
|
||||||
|
Loading…
Reference in New Issue
Block a user