Blame view

Src/main.c 6.49 KB
95ce2328   李外   完成USB移植,测试正常,
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
  /*!
      \file    main.c
      \brief   construct a USB custom HID device
  
      \version 2020-08-01, V3.0.0, firmware for GD32F30x
  */
  
  /*
      Copyright (c) 2020, GigaDevice Semiconductor Inc.
  
      Redistribution and use in source and binary forms, with or without modification, 
  are permitted provided that the following conditions are met:
  
      1. Redistributions of source code must retain the above copyright notice, this 
         list of conditions and the following disclaimer.
      2. Redistributions in binary form must reproduce the above copyright notice, 
         this list of conditions and the following disclaimer in the documentation 
         and/or other materials provided with the distribution.
      3. Neither the name of the copyright holder nor the names of its contributors 
         may be used to endorse or promote products derived from this software without 
         specific prior written permission.
  
      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
  OF SUCH DAMAGE.
  */
  
  #include "custom_hid_core.h"
  #include "usbd_hw.h"
  
  #include 	"platform.h"
  #include 	"base_core_user.h"
  #include "function_interface.h"
  #include "platform_interface.h"
  #include "HW_MCUIO.h"
88180837   李外   1、移植何工名单管理功能;
43
  #include "function.h"
95ce2328   李外   完成USB移植,测试正常,
44
45
46
47
48
  
  //????"function.h" ???"base_config.h"??????,????????1K?????,
  //???????????,????????????????????1K?????1mS,
  //??????????????20220624
  #include "function.h"//#include "base_config.h"
dcc9b193   李外   V100.0.2 完成基站升级功能。
49
50
  #define VECT_TAB_OFFSET 0x8000 //???????8K
  
95ce2328   李外   完成USB移植,测试正常,
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  usb_dev usbd_custom_hid;
  
  void TIMER1_Init(void);
  void TIMER2_Init(void);
  void GPIO_Init(void);
  
  extern hid_fop_handler fop_handler;
  
  
  
  /*!
      \brief      main routine
      \param[in]  none
      \param[out] none
      \retval     none
df8068e7   李外   其他基本完成,扩展信标还有SDK信...
66
      
95ce2328   李外   完成USB移植,测试正常,
67
68
69
70
  */
  
  int main(void)
  {
dcc9b193   李外   V100.0.2 完成基站升级功能。
71
      nvic_vector_table_set(NVIC_VECTTAB_FLASH, VECT_TAB_OFFSET);
a0293f87   李外   1、用新写法替换所有开关总中断的语句;
72
73
      __enable_irq();
      PLATFORM_DISABLE_IRQ();//__disable_irq();
95ce2328   李外   完成USB移植,测试正常,
74
      /* system clocks configuration */
0897ce2d   李外   rf 的 SPI暂未调通,还是有问题
75
      
95ce2328   李外   完成USB移植,测试正常,
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
      rcu_config();
  
  //    /* GPIO configuration */
  //    gpio_config();
  
      custom_hid_itfop_register(&usbd_custom_hid, &fop_handler);
  
      /* USB device configuration */
      usbd_init(&usbd_custom_hid, &custom_hid_desc, &custom_hid_class);
  
      /* NVIC configuration */
      nvic_config();
  
      /* GPIO configuration */
      gpio_config();
88180837   李外   1、移植何工名单管理功能;
91
      systick_config();
95ce2328   李外   完成USB移植,测试正常,
92
93
94
95
96
97
98
      
      GPIO_Init();
      /* enabled USB pull-up */
      usbd_connect(&usbd_custom_hid);
      
      HW_RF_SPI_Init();
      
4fe99ff7   李外   SPI移植完成,RF功能测试通过,...
99
100
101
102
103
      
      
      base_core.core_init();////???????????
      function.aes__init();
      
95ce2328   李外   完成USB移植,测试正常,
104
      
a0293f87   李外   1、用新写法替换所有开关总中断的语句;
105
      PLATFORM_ENABLE_IRQ();//__enable_irq();
4fe99ff7   李外   SPI移植完成,RF功能测试通过,...
106
107
      TIMER1_Init();
      TIMER2_Init();
95ce2328   李外   完成USB移植,测试正常,
108
109
110
111
      while (USBD_CONFIGURED != usbd_custom_hid.cur_status) {
          /* wait for standard USB enumeration is finished */
      }
      
4fe99ff7   李外   SPI移植完成,RF功能测试通过,...
112
      
0897ce2d   李外   rf 的 SPI暂未调通,还是有问题
113
      
95ce2328   李外   完成USB移植,测试正常,
114
115
      while(1){
          base_core.core_loop();
4872303f   李外   V100.0.7
116
  //        msg_polling();//function.msg__polling();
95ce2328   李外   完成USB移植,测试正常,
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
          //uint8_t Send_buf[64] = {0x00};
          //custom_hid_report_send (&usbd_custom_hid, Send_buf, 64U);
      }
  }
  
  void TIMER1_Init(void)
  {
      timer_parameter_struct initpara = {0};
  
      initpara.prescaler = 1200 - 1;// 120M / 1200 = 100KHz
      initpara.alignedmode = TIMER_COUNTER_EDGE;
      initpara.counterdirection = TIMER_COUNTER_UP;
      initpara.period = 250 - 1;
      initpara.clockdivision = TIMER_CKDIV_DIV1;
      initpara.repetitioncounter = 0;
      timer_init(TIMER1, &initpara);
  
aed5e827   李外   V100.0.8
134
      nvic_irq_enable(TIMER1_IRQn, 3U, 0U);//(TIMER1_IRQn, 3U, 0U);
95ce2328   李外   完成USB移植,测试正常,
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  
      timer_counter_value_config(TIMER1, 0);
      timer_prescaler_config(TIMER1, 1200 - 1, TIMER_PSC_RELOAD_NOW);
      timer_autoreload_value_config(TIMER1, 250 - 1);
      timer_interrupt_disable(TIMER1, TIMER_INT_UP);
      timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
      timer_interrupt_enable(TIMER1, TIMER_INT_UP);
      timer_enable(TIMER1);
  }
  
  void TIMER2_Init(void)
  {
      timer_parameter_struct initpara = {0};
  
      initpara.prescaler = 1200 - 1;// 120M / 1200 = 100KHz
      initpara.alignedmode = TIMER_COUNTER_EDGE;
      initpara.counterdirection = TIMER_COUNTER_UP;
      initpara.period = 2000 - 1;
      initpara.clockdivision = TIMER_CKDIV_DIV1;
      initpara.repetitioncounter = 0;
      timer_init(TIMER2, &initpara);
  
88180837   李外   1、移植何工名单管理功能;
157
      nvic_irq_enable(TIMER2_IRQn, 4U, 0U);
95ce2328   李外   完成USB移植,测试正常,
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  
      timer_counter_value_config(TIMER2, 0);
      timer_prescaler_config(TIMER2, 1200 - 1, TIMER_PSC_RELOAD_NOW);
      timer_autoreload_value_config(TIMER2, 2000 - 1);
      timer_interrupt_disable(TIMER2, TIMER_INT_UP);
      timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
      timer_interrupt_enable(TIMER2, TIMER_INT_UP);
      timer_enable(TIMER2);
  }
  
  void GPIO_Init(void)
  {
      HW_GPIO_InitTypeDef  GPIO_InitStruct;
      
       /*Configure GPIO pin Output Level */
      HW_GPIO_ResetPin(GPIOC, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
  
      /*Configure GPIO pin Output Level */
      HW_GPIO_ResetPin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_8);
  
      /*Configure GPIO pin Output Level */
      HW_GPIO_ResetPin(GPIOB, GPIO_PIN_8|GPIO_PIN_9);
      
      /*Configure GPIO pins : PC1 PC4 PC5 PC6 */
      GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
      GPIO_InitStruct.Mode = HW_GPIO_MODE_OUT_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = HW_GPIO_SPEED_VERY_HIGH;
      HW_GPIO_Init(GPIOC, &GPIO_InitStruct);
      
      /*Configure GPIO pins : PA0 PA1 PA2 PA8 */
      GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_8;
      GPIO_InitStruct.Mode = HW_GPIO_MODE_OUT_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = HW_GPIO_SPEED_VERY_HIGH;
      HW_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
      /*Configure GPIO pin : PC7 */
      GPIO_InitStruct.Pin = GPIO_PIN_7;
      GPIO_InitStruct.Mode = HW_GPIO_MODE_FLOATING;//GPIO_MODE_IT_RISING;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      HW_GPIO_Init(GPIOC, &GPIO_InitStruct);
  
      /*Configure GPIO pins : PB8 PB9 */
      GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
      GPIO_InitStruct.Mode = HW_GPIO_MODE_OUT_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = HW_GPIO_SPEED_VERY_HIGH;
      HW_GPIO_Init(GPIOB, &GPIO_InitStruct);
      
4fe99ff7   李外   SPI移植完成,RF功能测试通过,...
208
      
95ce2328   李外   完成USB移植,测试正常,
209
  }