kosmos threading running

This commit is contained in:
tkl 2016-08-16 13:08:49 +02:00
parent 39f10bd4ba
commit caa360625b
17 changed files with 93 additions and 247 deletions

View File

@ -9,16 +9,18 @@
#include <stddef.h>
#include <stdint.h>
#if 0
#include "../../../../../kernel/include/sys_tick.h"
#include "../../../driver/include/stm32_sys_tick.h"
#include "../../../driver/include/stm32f4_pwm.h"
#include "../../../driver/include/stm32f4_uart.h"
#include "pwm.h"
#include "timer.h"
#include "uart.h"
#include "ringbuffer.h"
#endif
#include "stm32f4xx.h"
#include "timer.h"
#include "stm32_sys_tick.h"
#include "sys_tick.h"
#include "gpio.h"
#include "stm32f4_gpio.h"
#include "driver.h"
@ -41,27 +43,27 @@ static const struct gpio __gpio_d12 = {
&gpio_fp
};
const struct driver gpio_d12 = {
static const struct driver gpio_d12 = {
DRIVER_TYPE_GPIO,
&__gpio_d12,
};
#if 0
// SYSTEM TICK
static const enum stm32_sys_tick_time_base stm23_sys_tick_time_base =
STM32_SYS_TICK_TIME_BASE_MS;
static const struct stm32_sys_tick stm32_sys_tick = {
&stm23_sys_tick_time_base,
NULL,
NULL
.tick_time_base = &stm23_sys_tick_time_base,
.sys_tick_cb = NULL,
.sys_tick_cb_param = NULL,
};
static const struct loki_timer timer_1 = {
(void*)&stm32_sys_tick,
&timer_fp
.arch_dep_device = (void*)&stm32_sys_tick,
.fp = &timer_fp
};
#endif
#if 0
// PWM CHANNEL 4
/* apb1 clock = 84MHz */

View File

@ -7,10 +7,12 @@
#include "board.h"
void board_init(void) {
void board_init(void)
{
#if 0
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
SysTick_CLKSourceConfig(RCC_SYSCLKSource_PLLCLK);
#endif
sys_tick_init(&timer_1);
}

View File

@ -1,4 +1,2 @@
CHECK_FOLDER += source/firmware/arch/stm32f4xx/board/stm32f4-discovery
SUB_FOLDER += source/firmware/arch/stm32f4xx/board/stm32f4-discovery
SRC_DIR += source/firmware/arch/stm32f4xx/board/stm32f4-discovery
INCLUDES += source/firmware/arch/stm32f4xx/board/stm32f4-discovery/include
DOC_SRC += source/firmware/arch/stm32f4xx/board/stm32f4-discovery

View File

@ -0,0 +1,47 @@
//! \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_
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_ */

View File

@ -8,6 +8,7 @@
#include "stm32f4xx.h"
#include "timer.h"
#include "stm32_sys_tick.h"
#include "stm32f4xx_isr.h"

View File

@ -2,9 +2,10 @@
//! \author tkl
//! \date Jul 5, 2012
//! \brief Source file of the architecture independent timer implementation.
#include "include/timer.h"
#include <stddef.h>
#include "timer.h"
int timer_open(const struct loki_timer *device)
{

View File

@ -8,6 +8,6 @@
#ifndef 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_ */

View File

@ -4,13 +4,12 @@
* Created on: Sep 25, 2015
* Author: tkl
*/
#include "include/sys_tick.h"
#include <stddef.h>
#include <stdbool.h>
#include "irq.h"
#include "timer.h"
#include "sys_tick.h"
#include "irq.h"
#include "stack.h"
#include "queue.h"
#include "thread.h"

View File

@ -1,29 +0,0 @@
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
#include "BlinkLed.h"
// ----------------------------------------------------------------------------
void
blink_led_init()
{
// Enable GPIO Peripheral clock
RCC->AHB1ENR |= BLINK_RCC_MASKx(BLINK_PORT_NUMBER);
GPIO_InitTypeDef GPIO_InitStructure;
// Configure pin in output push/pull mode
GPIO_InitStructure.Pin = BLINK_PIN_MASK(BLINK_PIN_NUMBER);
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(BLINK_GPIOx(BLINK_PORT_NUMBER), &GPIO_InitStructure);
// Start with led turned off
blink_led_off();
}
// ----------------------------------------------------------------------------

View File

@ -1,64 +0,0 @@
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
#include "Timer.h"
#include "cortexm/ExceptionHandlers.h"
// ----------------------------------------------------------------------------
#if defined(USE_HAL_DRIVER)
void HAL_IncTick(void);
#endif
// Forward declarations.
void
timer_tick (void);
// ----------------------------------------------------------------------------
volatile timer_ticks_t timer_delayCount;
// ----------------------------------------------------------------------------
void
timer_start (void)
{
// Use SysTick as reference for the delay loops.
SysTick_Config (SystemCoreClock / TIMER_FREQUENCY_HZ);
}
void
timer_sleep (timer_ticks_t ticks)
{
timer_delayCount = ticks;
// Busy wait until the SysTick decrements the counter to zero.
while (timer_delayCount != 0u)
;
}
void
timer_tick (void)
{
// Decrement to zero the counter used by the delay routine.
if (timer_delayCount != 0u)
{
--timer_delayCount;
}
}
// ----- SysTick_Handler() ----------------------------------------------------
void
SysTick_Handler (void)
{
#if defined(USE_HAL_DRIVER)
HAL_IncTick();
#endif
timer_tick ();
}
// ----------------------------------------------------------------------------

View File

@ -1,84 +0,0 @@
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
#ifndef BLINKLED_H_
#define BLINKLED_H_
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
// ----- LED definitions ------------------------------------------------------
// Adjust these definitions for your own board.
#if defined(BOARD_OLIMEX_STM32_E407)
// STM32-E407 definitions (the GREEN led, C13, active low)
// Port numbers: 0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, ...
#define BLINK_PORT_NUMBER (2)
#define BLINK_PIN_NUMBER (13)
#define BLINK_ACTIVE_LOW (1)
#else
// STM32F4DISCOVERY definitions (the GREEN led, D12, active high)
// (SEGGER J-Link device name: STM32F407VG).
#define BLINK_PORT_NUMBER (3)
#define BLINK_PIN_NUMBER (12)
#define BLINK_ACTIVE_LOW (0)
#endif
#define BLINK_GPIOx(_N) ((GPIO_TypeDef *)(GPIOA_BASE + (GPIOB_BASE-GPIOA_BASE)*(_N)))
#define BLINK_PIN_MASK(_N) (1 << (_N))
#define BLINK_RCC_MASKx(_N) (RCC_AHB1ENR_GPIOAEN << (_N))
// ----------------------------------------------------------------------------
extern
void
blink_led_init(void);
// ----------------------------------------------------------------------------
inline void
blink_led_on(void);
inline void
blink_led_off(void);
// ----------------------------------------------------------------------------
inline void
__attribute__((always_inline))
blink_led_on(void)
{
#if (BLINK_ACTIVE_LOW)
HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_RESET);
#else
HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_SET);
#endif
}
inline void
__attribute__((always_inline))
blink_led_off(void)
{
#if (BLINK_ACTIVE_LOW)
HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_SET);
#else
HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_RESET);
#endif
}
// ----------------------------------------------------------------------------
#endif // BLINKLED_H_

View File

@ -1,27 +0,0 @@
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
#ifndef TIMER_H_
#define TIMER_H_
#include "cmsis_device.h"
// ----------------------------------------------------------------------------
#define TIMER_FREQUENCY_HZ (1000u)
typedef uint32_t timer_ticks_t;
extern volatile timer_ticks_t timer_delayCount;
extern void
timer_start (void);
extern void
timer_sleep (timer_ticks_t ticks);
// ----------------------------------------------------------------------------
#endif // TIMER_H_

View File

@ -1 +0,0 @@
INCLUDES += include

View File

@ -3,20 +3,16 @@
// Copyright (c) 2014 Liviu Ionescu.
//
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "diag/Trace.h"
#include "Timer.h"
#include "BlinkLed.h"
#include "stack.h"
#include "queue.h"
#include "kernel.h"
#include "board.h"
#include "driver.h"
// Keep the LED on for 2/3 of a second.
#define BLINK_ON_TICKS (TIMER_FREQUENCY_HZ * 3 / 4)
#define BLINK_OFF_TICKS (TIMER_FREQUENCY_HZ - BLINK_ON_TICKS)
// Sample pragmas to cope with warnings. Please note the related line at
// the end of this function, used to pop the compiler diagnostics status.
#pragma GCC diagnostic push
@ -24,25 +20,30 @@
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"
int main(int argc, char* argv[])
#define TH_STACK_SIZE 256
stack_t th_stack[TH_STACK_SIZE];
struct thread_context th_ctx;
static void th_func(void *arg)
{
trace_puts("Hello ARM World!");
trace_printf("System clock: %u Hz\n", SystemCoreClock);
timer_start();
// blink_led_init();
uint32_t seconds = 0;
drv_open(&gpio_d12);
drv_write(&gpio_d12, "1", 1);
drv_write(&gpio_d12, "0", 1);
while(1) {
// blink_led_on();
sleep_ms(1000);
drv_write(&gpio_d12, "1", 1);
timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);
// blink_led_off();
sleep_ms(1000);
drv_write(&gpio_d12, "0", 1);
timer_sleep(BLINK_OFF_TICKS);
++seconds;
trace_printf("Second %u\n", seconds);
}
}
int main(int argc, char* argv[])
{
board_init();
thread_create(&th_ctx, th_stack, TH_STACK_SIZE, th_func, NULL, THREAD_PRIO_LOW);
schedule_start();
return 0;
}
#pragma GCC diagnostic pop