-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy paths_port_stm8l15x.inc.h
110 lines (83 loc) · 3.07 KB
/
s_port_stm8l15x.inc.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
static void TIM2_Config(void){
/* Enable TIM2 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
/* Time Base configuration */
#define TIM2_PERIOD 0xFFFF
TIM2_TimeBaseInit(TIM2_Prescaler_1, TIM2_CounterMode_Up, TIM2_PERIOD);
TIM2_UpdateRequestConfig(TIM2_UpdateSource_Global);
/* Clear TIM2 update flag */
TIM2_ClearFlag(TIM2_FLAG_Update);
TIM2_ITConfig(TIM2_IT_Update, ENABLE);
/* TIM2 counter enable */
TIM2_Cmd(ENABLE);
}
static void CLK_Config(void){
/* Select HSI as system clock source */
CLK->SWCR |= CLK_SWCR_SWEN;
/* CLK->ICKCR |= (CLK_ICKCR_HSION | CLK_ICKCR_LSION); */
CLK->ICKCR |= (CLK_ICKCR_HSION);
/* while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == RESET); */
while((CLK->ICKCR & CLK_ICKCR_HSIRDY) == 0);
/* CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); */
CLK->SWR = CLK_SYSCLKSource_HSI;
/* system clock prescaler: 16*/
/* CLK->CKDIVR = CLK_SYSCLKDiv_128; */
/* CLK->CKDIVR = CLK_SYSCLKDiv_8; */
CLK->CKDIVR = CLK_SYSCLKDiv_1;
while (CLK->SCSR != CLK_SYSCLKSource_HSI){
}
/* CLK->ICKCR &= (uint8_t)(~CLK_ICKCR_LSION); */
CLK->SWCR &= (uint8_t)(~CLK_SWCR_SWEN);
}
volatile uint32_t g_tim2_count = 0;
INTERRUPT_HANDLER(TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler,19)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
++g_tim2_count;
/* Clear the IT pending Bit */
TIM2->SR1 = (uint8_t)(~(uint8_t)TIM2_IT_Update);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/* 3. Implement the initilization function for clock. Leave it blank if not required. */
void my_clock_init(){
CLK_Config();
TIM2_Config();
enableInterrupts();
}
/* 4. Implement the function of getting current clock ticks. */
my_clock_t my_clock() {
return g_tim2_count;
}
/* 5. Implement the idle delay function. */
void my_on_idle(uint32_t max_idle_ms) {
}
extern void swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
static void create_context(ucontext_t *oucp, void *stack, size_t stack_size) {
/* stm8 stack structure, 1. fill sp, 2, decrease sp
6 bytes: (high address) CC,Y,X,A
16 bytes: b0 ~ b15 (low address)
*/
int top_sp = (int)((char *)stack + stack_size);
*(int *)(top_sp - 2) = (int)&s_task_context_entry;
*(char *)(top_sp - 3) = 0x20; /* default CC */
oucp->sp = top_sp - 2 - 22 - 1;
}