-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
116 lines (86 loc) · 2.54 KB
/
main.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
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
111
112
113
114
115
#include "MDR32F9Qx_board.h"
#include "MDR32F9Qx_config.h"
#include "MDR32Fx.h"
#include "MDR32F9Qx_rst_clk.h"
#include "MDR32F9Qx_port.h"
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "task.h"
#include "can.h"
void vLed1(void *argument)
{
while(1)
{
/* PORT_SetBits(MDR_PORTC, PORT_Pin_0);
vTaskDelay(100);
PORT_ResetBits(MDR_PORTC, PORT_Pin_0);
vTaskDelay(100);
*/
PORT_SetBits(MDR_PORTC, PORT_Pin_0);
CAN_SendData(0x321,0,2048);
PORT_ResetBits(MDR_PORTC, PORT_Pin_0);
vTaskDelay(1000);
//CAN_Transmit(MDR_CAN1, CAN_BUFFER_2, &TxMsg);
}
}
void vLed2(void *argument)
{
while(1)
{
PORT_SetBits(MDR_PORTC, PORT_Pin_1);
vTaskDelay(100);
PORT_ResetBits(MDR_PORTC, PORT_Pin_1);
vTaskDelay(100);
}
}
void vApplicationIdleHook (void)
{
}
void Port_Init()
{
PORT_InitTypeDef PORT_InitStructure;
//Ports for LED
RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTC, ENABLE);
PORT_InitStructure.PORT_Pin = PORT_Pin_0 | PORT_Pin_1;
PORT_InitStructure.PORT_OE = PORT_OE_OUT;
PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT;
PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
PORT_Init(MDR_PORTC, &PORT_InitStructure);
//Ports for CAN
RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTA, ENABLE);
PORT_InitStructure.PORT_FUNC = PORT_FUNC_ALTER;
PORT_InitStructure.PORT_Pin = PORT_Pin_6;
PORT_InitStructure.PORT_OE = PORT_OE_OUT;
PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
PORT_InitStructure.PORT_PD = PORT_PD_DRIVER;
PORT_Init(MDR_PORTA, &PORT_InitStructure);
PORT_InitStructure.PORT_Pin = PORT_Pin_7;
PORT_InitStructure.PORT_OE = PORT_OE_IN;
PORT_Init(MDR_PORTA, &PORT_InitStructure);
}
void Clock_Init()
{
RST_CLK_DeInit();
RST_CLK_PCLKcmd(RST_CLK_PCLK_BKP,ENABLE);
RST_CLK_HSEconfig(RST_CLK_HSE_ON);
if (RST_CLK_HSEstatus() == SUCCESS){
RST_CLK_CPU_PLLconfig(RST_CLK_CPU_PLLsrcHSEdiv1, RST_CLK_CPU_PLLmul8);
RST_CLK_CPU_PLLcmd(ENABLE);
if (RST_CLK_HSEstatus() == SUCCESS){
RST_CLK_CPUclkPrescaler(RST_CLK_CPUclkDIV1);
RST_CLK_CPU_PLLuse(ENABLE);
RST_CLK_CPUclkSelection(RST_CLK_CPUclkCPU_C3);
}
}
}
int main()
{
Clock_Init();
Port_Init();
CAN_PerifInit();
xTaskCreate(vLed1, "1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
xTaskCreate(vLed2, "2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
vTaskStartScheduler();
}