-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy paths_port_stm8s.inc.h
86 lines (67 loc) · 2.5 KB
/
s_port_stm8s.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
static void TIM2_Config(void){
/* clock rate from 16M */
/* Time base configuration */
TIM2_TimeBaseInit(TIM2_PRESCALER_1, 0xFFFF);
/* Prescaler configuration */
TIM2_PrescalerConfig(TIM2_PRESCALER_16384, TIM2_PSCRELOADMODE_IMMEDIATE);
TIM2_ARRPreloadConfig(ENABLE);
TIM2_ClearFlag(TIM2_FLAG_UPDATE);
/* TIM2_ITConfig(TIM2_IT_UPDATE,ENABLE); */
/* TIM2_UpdateDisableConfig(ENABLE); */
/* TIM2 enable counter */
TIM2_Cmd(ENABLE);
}
static void CLK_Config(void){
CLK_DeInit();
/* Configure the Fcpu to DIV1*/
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
/* Configure the HSI prescaler to the optimal value */
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
/* Configure the system clock to use HSI clock source and to run at 16Mhz */
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
}
#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() {
uint16_t count;
count = ((uint16_t)TIM2->CNTRH << 8);
count = (uint16_t)( count| (uint16_t)(TIM2->CNTRL));
return 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;
}