forked from stancecoke/BMSBattery_S_controllers_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrake.c
executable file
·64 lines (57 loc) · 1.24 KB
/
brake.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* EGG OpenSource EBike firmware
*
* Copyright (C) Casainho, 2015, 2106, 2017.
*
* Released under the GPL License, Version 3
*/
#include <stdint.h>
#include "stm8s.h"
#include "stm8s_it.h"
#include "gpio.h"
#include "main.h"
#include "interrupts.h"
#include "brake.h"
#include "cruise_control.h"
#include "motor.h"
#include "pwm.h"
// Brake signal
void EXTI_PORTA_IRQHandler(void) __interrupt(EXTI_PORTA_IRQHANDLER)
{
if (brake_is_set())
{
//brake_coast_enable ();
//stop_cruise_control ();
}
else
{
//brake_coast_disable ();
//pwm_set_duty_cycle (0);
//stop_cruise_control ();
}
}
void brake_init (void)
{
//hall sensors pins as external input pin interrupt
GPIO_Init(BRAKE__PORT,
BRAKE__PIN,
GPIO_MODE_IN_FL_IT); // with external interrupt
//initialize the Interrupt sensitivity
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOA,
EXTI_SENSITIVITY_RISE_FALL);
}
BitStatus brake_is_set (void)
{
if (GPIO_ReadInputPin(BRAKE__PORT, BRAKE__PIN) == 0)
return 1;
else
return 0;
}
void brake_coast_enable (void)
{
TIM1->BKR &= (uint8_t) ~(TIM1_BKR_MOE);
}
void brake_coast_disable (void)
{
TIM1->BKR |= (uint8_t) (TIM1_BKR_MOE);
}