refine peripherals processing. Use libs

This commit is contained in:
e.gavrin
2014-07-30 21:57:41 +04:00
parent e540590ddd
commit c25db6d7b9
7 changed files with 97 additions and 69 deletions
+6 -2
View File
@@ -269,12 +269,16 @@ CFLAGS_THIRDPARTY =
ifeq ($(TARGET_SYSTEM),stm32f4) ifeq ($(TARGET_SYSTEM),stm32f4)
SOURCES_THIRDPARTY += \ SOURCES_THIRDPARTY += \
./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \ ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \
./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s \
./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_tim.c \
./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c \
./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
INCLUDES_THIRDPARTY += \ INCLUDES_THIRDPARTY += \
-I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include \ -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include \
-I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc \ -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc \
-I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include \
-I third-party/STM32F4-Discovery_FW_V1.1.0/
#-I third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration \ #-I third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration \
+1 -1
View File
@@ -24,7 +24,7 @@ static const char* generated_source = ""
"a = tmp + g;\n" "a = tmp + g;\n"
"d = tmp * e + a;\n" "d = tmp * e + a;\n"
"\n" "\n"
"var waitTime = 600000;\n" "var waitTime = 50;\n"
"var numOfIterations = 10;\n" "var numOfIterations = 10;\n"
"\n" "\n"
"while (1)\n" "while (1)\n"
+11 -32
View File
@@ -17,9 +17,8 @@
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
#include "stm32f4xx_conf.h"
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
@@ -36,8 +35,6 @@ led_toggle (uint32_t led_id)
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
init_led (led_id);
GPIOD->ODR ^= (uint16_t) (1 << led_id); GPIOD->ODR ^= (uint16_t) (1 << led_id);
#endif #endif
} }
@@ -51,10 +48,7 @@ led_on (uint32_t led_id)
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
init_led (led_id); GPIO_WriteBit(GPIOD, (uint16_t) (1 << led_id), Bit_SET);
GPIOD->BSRRH = (uint16_t) (1 << led_id);
GPIOD->BSRRL = (uint16_t) (1 << led_id);
#endif #endif
} }
@@ -66,10 +60,7 @@ led_off (uint32_t led_id)
#endif #endif
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
init_led (led_id); GPIO_WriteBit(GPIOD, (uint16_t) (1 << led_id), Bit_RESET);
GPIOD->BSRRL = (uint16_t) (1 << led_id);
GPIOD->BSRRH = (uint16_t) (1 << led_id);
#endif #endif
} }
@@ -81,8 +72,6 @@ led_blink_once (uint32_t led_id)
#endif #endif
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
init_led (led_id);
uint32_t dot = 300000; uint32_t dot = 300000;
GPIOD->BSRRL = (uint16_t) (1 << led_id); GPIOD->BSRRL = (uint16_t) (1 << led_id);
@@ -92,26 +81,16 @@ led_blink_once (uint32_t led_id)
} }
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
void void initialize_leds()
init_led (uint32_t led_id)
{ {
uint32_t pin = led_id; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
uint32_t mode = (uint32_t) GPIO_Mode_OUT << (pin * 2);
uint32_t speed = (uint32_t) GPIO_Speed_100MHz << (pin * 2);
uint32_t type = (uint32_t) GPIO_OType_PP << pin;
uint32_t pullup = (uint32_t) GPIO_PuPd_NOPULL << (pin * 2);
TODO (INITIALIZE ONCE); GPIO_InitTypeDef gpioStructure;
gpioStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
gpioStructure.GPIO_Mode = GPIO_Mode_OUT;
gpioStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &gpioStructure);
// Initialise the peripheral clock. GPIO_WriteBit(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, Bit_RESET);
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
// Initilaise the GPIO port.
volatile GPIO_TypeDef* gpio = GPIOD;
gpio->MODER |= mode;
gpio->OSPEEDR |= speed;
gpio->OTYPER |= type;
gpio->PUPDR |= pullup;
} }
#endif #endif
+1 -1
View File
@@ -24,7 +24,7 @@ void led_off(uint32_t);
void led_blink_once(uint32_t); void led_blink_once(uint32_t);
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
void init_led (uint32_t); void initialize_leds(void);
#endif #endif
#endif /* ACTUATORS_H */ #endif /* ACTUATORS_H */
+65 -33
View File
@@ -13,19 +13,18 @@
* limitations under the License. * limitations under the License.
*/ */
#include "common-io.h"
#include "jerry-libc.h"
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
#include "stm32f4xx_conf.h"
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#ifdef __HOST
#include <time.h>
#endif
// STM32 F4 // STM32 F4
#define LED_GREEN 12 #define LED_GREEN 12
#define LED_ORANGE 13 #define LED_ORANGE 13
@@ -34,9 +33,6 @@
#endif #endif
#include "common-io.h"
#include "jerry-libc.h"
int int
digital_read (uint32_t arg1 __unused, uint32_t arg2 __unused) digital_read (uint32_t arg1 __unused, uint32_t arg2 __unused)
{ {
@@ -76,40 +72,36 @@ wait_ms (uint32_t time_ms)
#endif #endif
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
volatile uint32_t index; while (time_ms--)
for (index = 0; index < time_ms; index++); {
wait_1ms ();
}
#endif #endif
} }
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
void initialize_timer()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseInitTypeDef timerInitStructure;
timerInitStructure.TIM_Prescaler = 40000;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 500;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &timerInitStructure);
TIM_Cmd(TIM2, ENABLE);
}
void void
fake_exit (void) fake_exit (void)
{ {
uint32_t pin = LED_ORANGE; uint32_t pin = LED_ORANGE;
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
uint32_t pullup = (uint32_t)GPIO_PuPd_NOPULL << (pin * 2);
//
// Initialise the peripheral clock.
//
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
//
// Initilaise the GPIO port.
//
volatile GPIO_TypeDef* gpio = GPIOD; volatile GPIO_TypeDef* gpio = GPIOD;
gpio->MODER |= mode;
gpio->OSPEEDR |= speed;
gpio->OTYPER |= type;
gpio->PUPDR |= pullup;
//
// Toggle the selected LED indefinitely.
//
volatile int index; volatile int index;
// SOS
int dot = 600000; int dot = 600000;
int dash = dot * 3; int dash = dot * 3;
@@ -130,4 +122,44 @@ fake_exit (void)
for (index = 0; index < dash * 7; index++); for (index = 0; index < dash * 7; index++);
} }
} }
static __IO uint32_t sys_tick_counter;
void
initialize_sys_tick (void)
{
/****************************************
*SystemFrequency/1000 1ms *
*SystemFrequency/100000 10us *
*SystemFrequency/1000000 1us *
*****************************************/
while (SysTick_Config (SystemCoreClock / 1000000) != 0)
{
} // One SysTick interrupt now equals 1us
}
void SysTick_Handler(void) {
time_tick_decrement();
}
void
time_tick_decrement (void)
{
if (sys_tick_counter != 0x00)
{
sys_tick_counter--;
}
}
void
wait_1ms (void)
{
sys_tick_counter = 1000;
while (sys_tick_counter != 0)
{
}
}
#endif #endif
+7
View File
@@ -29,6 +29,13 @@ void wait_ms(uint32_t);
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
void fake_exit(void); void fake_exit(void);
void initialize_timer(void);
void initialize_sys_tick(void);
void SysTick_Handler(void);
void time_tick_decrement(void);
void wait_1ms(void);
#endif #endif
#endif /* COMMON_IO_H */ #endif /* COMMON_IO_H */
+6
View File
@@ -15,6 +15,8 @@
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
#include "common-io.h" #include "common-io.h"
#include "actuators.h"
#include "sensors.h"
#include "generated.h" #include "generated.h"
#endif #endif
@@ -186,6 +188,10 @@ main (int argc __unused,
int int
main(void) main(void)
{ {
initialize_sys_tick();
initialize_leds();
initialize_timer();
const char *source_p = generated_source; const char *source_p = generated_source;
const size_t source_size = sizeof(generated_source); const size_t source_size = sizeof(generated_source);