Modified initialization of RTC.

Tried to test UDP server/client
This commit is contained in:
Alexei 2023-02-27 09:26:55 +07:00
parent 4539074520
commit 411afb72ab
8 changed files with 198 additions and 162 deletions

View File

@ -136,7 +136,7 @@ static void prvServerConnectionInstance( void *pvParameters );
/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be
reused when the server listening task creates tasks to handle connections. */
static uint16_t usUsedStackSize = 0;
static TaskHandle_t prvServerConnectionInstance_Handle = NULL;
/*-----------------------------------------------------------*/
void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority )
@ -157,7 +157,7 @@ Socket_t xListeningSocket, xConnectedSocket;
socklen_t xSize = sizeof( xClient );
static const TickType_t xReceiveTimeOut = portMAX_DELAY;
const BaseType_t xBacklog = 20;
TaskHandle_t prvServerConnectionInstance_Handle = NULL;
#if( ipconfigUSE_TCP_WIN == 1 )
WinProperties_t xWinProps;
@ -197,15 +197,24 @@ TaskHandle_t prvServerConnectionInstance_Handle = NULL;
FreeRTOS_listen( xListeningSocket, xBacklog );
for( ;; )
{
{
/* Wait for a client to connect. */
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
/* Spawn a task to handle the connection. */
if (prvServerConnectionInstance_Handle)
vTaskDelete( prvServerConnectionInstance_Handle );
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY + 1, &prvServerConnectionInstance_Handle );
configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
FreeRTOS_debug_printf(("Heap size TCP 0 = %d\n", xPortGetFreeHeapSize()));
/* Delete previous suspended EchoServer task if it was created. */
if (prvServerConnectionInstance_Handle && eSuspended == eTaskGetState( prvServerConnectionInstance_Handle) )
{
/* Pause for a short while to ensure the network is not too
* congested. */
vTaskDelay( 150 );
vTaskDelete( prvServerConnectionInstance_Handle );
}
FreeRTOS_debug_printf(("Heap size TCP 1 = %d\n", xPortGetFreeHeapSize()));
/* Spawn a task to handle the connection. */
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY + 1, &prvServerConnectionInstance_Handle );
}
}
/*-----------------------------------------------------------*/
@ -220,11 +229,7 @@ TickType_t xTimeOnShutdown;
uint8_t *pucRxBuffer;
xConnectedSocket = ( Socket_t ) pvParameters;
HeapStats_t pxHeapStats;
vPortGetHeapStats( &pxHeapStats );
FreeRTOS_debug_printf(("xAvailableHeapSpaceInBytes1 = %d\n", pxHeapStats.xAvailableHeapSpaceInBytes));
FreeRTOS_debug_printf(("xNumberOfSuccessfulAllocations1 = %d\n", pxHeapStats.xNumberOfSuccessfulAllocations));
FreeRTOS_debug_printf(("xNumberOfSuccessfulFrees1 = %d\n", pxHeapStats.xNumberOfSuccessfulFrees));
/* Attempt to create the buffer used to receive the string to be echoed
back. This could be avoided using a zero copy interface that just returned
the same buffer. */
@ -287,15 +292,10 @@ uint8_t *pucRxBuffer;
/* Finished with the socket, buffer, the task. */
vPortFree( pucRxBuffer );
FreeRTOS_closesocket( xConnectedSocket );
#ifdef DEBUG_TASK_DELETE
vPortGetHeapStats( &pxHeapStats );
FreeRTOS_debug_printf(("xAvailableHeapSpaceInBytes2 = %d\n", pxHeapStats.xAvailableHeapSpaceInBytes));
FreeRTOS_debug_printf(("xNumberOfSuccessfulAllocations2 = %d\n", pxHeapStats.xNumberOfSuccessfulAllocations));
FreeRTOS_debug_printf(("xNumberOfSuccessfulFrees2 = %d\n", pxHeapStats.xNumberOfSuccessfulFrees));
//FreeRTOS_debug_printf(("Heap size after TCP = %d\n", xPortGetFreeHeapSize()));
vTaskDelete( NULL );
#endif
BaseType_t xReturned = FreeRTOS_closesocket( xConnectedSocket );
configASSERT( xReturned > FREERTOS_SOCKET_ERROR );
vTaskSuspend(NULL);
}
/*-----------------------------------------------------------*/

View File

@ -79,11 +79,11 @@ void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulPort, UB
/* Create the client and server tasks that do not use the zero copy
interface. */
xTaskCreate( prvSimpleClientTask, "SimpCpyClnt", usStackSize, ( void * ) ulPort, uxPriority, NULL );
xTaskCreate( prvSimpleServerTask, "SimpCpySrv", usStackSize, ( void * ) ulPort, uxPriority + 1, NULL );
xTaskCreate( prvSimpleServerTask, "SimpCpySrv", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority, NULL );
/* Create the client and server tasks that do use the zero copy interface. */
xTaskCreate( prvSimpleZeroCopyUDPClientTask, "SimpZCpyClnt", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority, NULL );
xTaskCreate( prvSimpleZeroCopyServerTask, "SimpZCpySrv", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority + 1, NULL );
xTaskCreate( prvSimpleZeroCopyUDPClientTask, "SimpZCpyClnt", usStackSize, ( void * ) ( ulPort + 2 ), uxPriority, NULL );
xTaskCreate( prvSimpleZeroCopyServerTask, "SimpZCpySrv", usStackSize, ( void * ) ( ulPort + 3 ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
@ -127,7 +127,7 @@ const TickType_t x150ms = 150UL / portTICK_PERIOD_MS;
do
{
/* Create the string that is sent to the server. */
printf( ( char * ) cString, "Server received (not zero copy): Message number %lu\r\n", ulCount );
sprintf( ( char * ) cString, "Server received (not zero copy): Message number %ul\r\n", ulCount );
/* Send the string to the socket. ulFlags is set to 0, so the zero
copy option is not selected. That means the data from cString[] is
@ -190,6 +190,7 @@ Socket_t xListeningSocket;
/* Error check. */
configASSERT( lBytes == ( BaseType_t ) strlen( ( const char * ) cReceivedString ) );
FreeRTOS_debug_printf( ("Received string: %s, on port %d\r\n", cReceivedString, xBindAddress.sin_port ) );
}
}
/*-----------------------------------------------------------*/
@ -255,7 +256,7 @@ const size_t xStringLength = strlen( pcStringToSend ) + 15;
end. Note that the string is being written directly into the buffer
obtained from the IP stack above. */
memset( ( void * ) pucUDPPayloadBuffer, 0x00, xStringLength );
printf( ( char * ) pucUDPPayloadBuffer, "%s%lu\r\n", pcStringToSend, ulCount );
sprintf( ( char * ) pucUDPPayloadBuffer, "%s%ul\r\n", pcStringToSend, ulCount );
/* Pass the buffer into the send function. ulFlags has the
FREERTOS_ZERO_COPY bit set so the IP stack will take control of the
@ -343,7 +344,7 @@ Socket_t xListeningSocket;
the NULL terminator is also transmitted. */
configASSERT( lBytes == ( ( BaseType_t ) strlen( ( const char * ) pucUDPPayloadBuffer ) + 1 ) );
}
FreeRTOS_debug_printf( ("Received string: %s, with ZERO_COPY on port %d\r\n", pucUDPPayloadBuffer, xBindAddress.sin_port ) );
if( lBytes >= 0 )
{
/* The buffer *must* be freed once it is no longer needed. */

View File

@ -78,13 +78,9 @@
#include "Driver_ETH_MAC.h"
#include "Driver_ETH_PHY.h"
#include "gd32f10x_enet.h"
//#include "RTE_Components.h"
//#ifdef RTE_Drivers_PHY_DP83848C /* Driver PHY DP83848C */
//#endif
//#ifdef DEBUG
//#define BKPT __asm volatile("BKPT #0\n") ;
//#endif
static void receiveHandlerTask( void *pvParameters );
static TaskHandle_t receiveHandler = NULL;
@ -98,6 +94,8 @@ static ARM_ETH_MAC_CAPABILITIES capabilities;
extern ARM_DRIVER_ETH_PHY ARM_Driver_ETH_PHY_(0);
#define Driver_ETH_PHY0 ARM_Driver_ETH_PHY_(0)
extern TaskHandle_t vTaskHelloWorld_Handle, vTaskToggleLed_Handle;
/**
\fn void ENET_IRQHandler(void)
\brief Ethernet IRQ Handler
@ -110,6 +108,25 @@ void ENET_IRQHandler(void)
enet_interrupt_flag_clear(ENET_DMA_INT_FLAG_RS_CLR);
vTaskNotifyGiveFromISR(receiveHandler, &pxHigherPriorityTaskWoken );
}
#ifdef DEBUG_RBU_IRQ
if (SET == enet_interrupt_flag_get(ENET_DMA_INT_FLAG_RBU))
{
enet_interrupt_flag_clear(ENET_DMA_INT_FLAG_RBU_CLR);
vTaskNotifyGiveIndexedFromISR(vTaskToggleLed_Handle, 0, &pxHigherPriorityTaskWoken );
}
#elif defined (DEBUG_TBU_IRQ)
if (SET == enet_interrupt_flag_get(ENET_DMA_INT_FLAG_TBU))
{
enet_interrupt_flag_clear(ENET_DMA_INT_FLAG_TBU_CLR);
vTaskNotifyGiveFromISR(vTaskHelloWorld_Handle, &pxHigherPriorityTaskWoken );
}
#elif defined (DEBUG_RBU_IRQ)
if (SET == enet_interrupt_flag_get(ENET_DMA_INT_FLAG_ET))
{
enet_interrupt_flag_clear(ENET_DMA_INT_FLAG_ET_CLR);
vTaskNotifyGiveIndexedFromISR(vTaskHelloWorld_Handle, 1, &pxHigherPriorityTaskWoken );
}
#endif
if( pxHigherPriorityTaskWoken == pdTRUE)
{
taskYIELD();
@ -171,11 +188,47 @@ int32_t ARM_ETH_MAC_Initialize (ARM_ETH_MAC_SignalEvent_t cb_event)
xResult = ARM_DRIVER_OK;
enet_interrupt_enable( ENET_DMA_INT_RIE );
/* enet_interrupt_enable( ENET_DMA_INT_TIE );
#ifdef DEBUG_TI_IRQ
enet_interrupt_enable( ENET_DMA_INT_TIE );
#elif defined DEBUG_TBU_IRQ
enet_interrupt_enable( ENET_DMA_INT_TBUIE );
enet_interrupt_enable( ENET_DMA_INT_ERIE );*/
#elif defined DEBUG_ER_IRQ
enet_interrupt_enable( ENET_DMA_INT_ERIE );
#endif
enet_interrupt_enable( ENET_DMA_INT_NIE );
#ifdef DEBUG_TJT_IRQ
enet_interrupt_enable( ENET_DMA_INT_TJTIE );
#elif defined DEBUG_TPS_IRQ
enet_interrupt_enable( ENET_DMA_INT_TPSIE );
#elif defined DEBUG_TU_IRQ
enet_interrupt_enable( ENET_DMA_INT_TUIE );
#elif defined DEBUG_RBU_IRQ
enet_interrupt_enable( ENET_DMA_INT_RBUIE );
#elif defined DEBUG_RPS_IRQ
enet_interrupt_enable( ENET_DMA_INT_RPSIE );
#elif defined DEBUG_RO_IRQ
enet_interrupt_enable( ENET_DMA_INT_ROIE );
#elif defined DEBUG_RWT_IRQ
enet_interrupt_enable( ENET_DMA_INT_RWTIE );
#elif defined DEBUG_ET_IRQ
enet_interrupt_enable( ENET_DMA_INT_ETIE );
#elif defined DEBUG_FBE_IRQ
enet_interrupt_enable( ENET_DMA_INT_FBEIE );
#endif
#if defined ( DEBUG_TJT_IRQ ) || \
defined ( DEBUG_TPS_IRQ ) || \
defined ( DEBUG_TU_IRQ ) || \
defined ( DEBUG_RBU_IRQ ) || \
defined ( DEBUG_RPS_IRQ ) || \
defined ( DEBUG_RO_IRQ ) || \
defined ( DEBUG_RWT_IRQ ) || \
defined ( DEBUG_ET_IRQ ) || \
defined ( DEBUG_FBE_IRQ )
enet_interrupt_enable( ENET_DMA_INT_AIE );
#endif
return xResult;
}
@ -358,16 +411,18 @@ int32_t ARM_ETH_MAC_GetTxFrameTime (ARM_ETH_MAC_TIME *time)
\return \ref execution_status
*/
int32_t ARM_ETH_MAC_Control (uint32_t control, uint32_t arg)
{
FreeRTOS_debug_printf(("ARM_ETH_MAC_Control\n"));
{
if((control >= 0) & (arg >= 0))
{
if(SUCCESS == enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, control, (uint16_t*)&arg))
return ARM_DRIVER_OK;
else
{
FreeRTOS_debug_printf(("ARM_ETH_MAC_Control_ERROR\n"));
return ARM_DRIVER_ERROR;
}
}else
FreeRTOS_debug_printf(("ARM_ETH_MAC_Control_ERROR_PARAMETER\n"));
return ARM_DRIVER_ERROR_PARAMETER;
}

View File

@ -50,7 +50,7 @@ extern uint32_t SystemCoreClock;
/* Constants that describe the hardware and memory usage. */
#define configCPU_CLOCK_HZ (SystemCoreClock)
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configTOTAL_HEAP_SIZE ((size_t)5*8192)
#define configTOTAL_HEAP_SIZE ((size_t)40*1024)
#define configMINIMAL_STACK_SIZE ((uint16_t)256)
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configSUPPORT_STATIC_ALLOCATION 0
@ -99,6 +99,7 @@ extern uint32_t SystemCoreClock;
#define configENABLE_TRUSTZONE 1
#define configMINIMAL_SECURE_STACK_SIZE ((uint32_t)1024)
#define configRUN_FREERTOS_SECURE_ONLY 0
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 2
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
@ -237,14 +238,14 @@ void vAssertCalled(const char* pcFile,
#define configIP_ADDR0 192
#define configIP_ADDR1 168
#define configIP_ADDR2 1
#define configIP_ADDR3 2
#define configIP_ADDR3 3
/* Default gateway IP address configuration. Used in ipconfigUSE_DHCP is set to
* 0, or ipconfigUSE_DHCP is set to 1 but a DNS server cannot be contacted. */
#define configGATEWAY_ADDR0 192
#define configGATEWAY_ADDR1 168
#define configGATEWAY_ADDR2 1
#define configGATEWAY_ADDR3 2
#define configGATEWAY_ADDR3 1
/* Default DNS server configuration. OpenDNS addresses are 208.67.222.222 and
* 208.67.220.220. Used in ipconfigUSE_DHCP is set to 0, or ipconfigUSE_DHCP is

View File

@ -24,6 +24,8 @@
#define RTE_RTOS_FreeRTOS_EVENTGROUPS /* RTOS FreeRTOS Event Groups */
/* ARM.FreeRTOS::RTOS:Heap:Heap_4:10.5.1 */
#define RTE_RTOS_FreeRTOS_HEAP_4 /* RTOS FreeRTOS Heap 4 */
/* GigaDevice::Device:GD32F10x_StdPeripherals:BKP:2.0.2 */
#define RTE_DEVICE_STDPERIPHERALS_BKP
/* GigaDevice::Device:GD32F10x_StdPeripherals:DMA:2.0.2 */
#define RTE_DEVICE_STDPERIPHERALS_DMA
/* GigaDevice::Device:GD32F10x_StdPeripherals:ENET:2.0.2 */

View File

@ -125,7 +125,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGTARM</Key>
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)</Name>
<Name>(1010=83,112,533,669,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -153,56 +153,7 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0GD32F10x_CL -FS08000000 -FL040000 -FP0($$Device:GD32F107VC$Flash\GD32F10x_CL.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>206</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134220272</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\DemoTasks\SimpleTCPEchoServer.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Test_project_for_GD32107C_EVAL\DemoTasks/SimpleTCPEchoServer.c\206</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>511</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134230238</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\FreeRTOS\source\FreeRTOS_DHCP.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Test_project_for_GD32107C_EVAL\FreeRTOS/source/FreeRTOS_DHCP.c\511</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>6</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
@ -274,6 +225,11 @@
<WinNumber>1</WinNumber>
<ItemText>pxSocket</ItemText>
</Ww>
<Ww>
<count>14</count>
<WinNumber>1</WinNumber>
<ItemText>prvServerConnectionInstance_Handle</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
<Mm>
@ -415,18 +371,6 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\printf-stdarg.c</PathWithFileName>
<FilenameWithoutPath>printf-stdarg.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
@ -437,7 +381,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>7</FileNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -449,7 +393,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>8</FileNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -461,7 +405,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>9</FileNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -473,7 +417,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>10</FileNumber>
<FileNumber>9</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -485,7 +429,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>11</FileNumber>
<FileNumber>10</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -497,7 +441,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>12</FileNumber>
<FileNumber>11</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -509,7 +453,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>13</FileNumber>
<FileNumber>12</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -521,7 +465,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>14</FileNumber>
<FileNumber>13</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -533,7 +477,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>15</FileNumber>
<FileNumber>14</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -545,7 +489,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>16</FileNumber>
<FileNumber>15</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -557,7 +501,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>17</FileNumber>
<FileNumber>16</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -569,7 +513,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>18</FileNumber>
<FileNumber>17</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -581,7 +525,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>19</FileNumber>
<FileNumber>18</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -593,7 +537,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>20</FileNumber>
<FileNumber>19</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -605,7 +549,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>21</FileNumber>
<FileNumber>20</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -617,7 +561,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>22</FileNumber>
<FileNumber>21</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -629,7 +573,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>23</FileNumber>
<FileNumber>22</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -641,7 +585,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>24</FileNumber>
<FileNumber>23</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -653,7 +597,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>25</FileNumber>
<FileNumber>24</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -665,7 +609,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>26</FileNumber>
<FileNumber>25</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -677,7 +621,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>27</FileNumber>
<FileNumber>26</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -689,7 +633,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>28</FileNumber>
<FileNumber>27</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -701,7 +645,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>29</FileNumber>
<FileNumber>28</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -713,7 +657,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>30</FileNumber>
<FileNumber>29</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -759,7 +703,7 @@
<Group>
<GroupName>::RTOS</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>1</RteFlg>

View File

@ -339,7 +339,7 @@
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls>-D DEBUG -Wno-pragma-pack -Wno-macro-redefined</MiscControls>
<Define>DEBUG_TASK_DELETE</Define>
<Define></Define>
<Undefine></Undefine>
<IncludePath>.\FreeRTOS\source\portable\NetworkInterface\include;.\FreeRTOS\source\include;.\FreeRTOS\source\portable\Compiler\Keil;.\DemoTasks\include;..\GigaDevice_test</IncludePath>
</VariousControls>
@ -410,11 +410,6 @@
<FileType>1</FileType>
<FilePath>.\PHY\PHY_DP83848C.c</FilePath>
</File>
<File>
<FileName>printf-stdarg.c</FileName>
<FileType>1</FileType>
<FilePath>.\printf-stdarg.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -820,6 +815,12 @@
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Device" Cgroup="GD32F10x_StdPeripherals" Csub="BKP" Cvendor="GigaDevice" Cversion="2.0.2" condition="GD32F10x STDPERIPHERALS RCU">
<package name="GD32F10x_DFP" schemaVersion="1.2" url="https://gd32mcu.com/data/documents/pack/" vendor="GigaDevice" version="2.0.3"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Device" Cgroup="GD32F10x_StdPeripherals" Csub="DMA" Cvendor="GigaDevice" Cversion="2.0.2" condition="GD32F10x STDPERIPHERALS RCU">
<package name="GD32F10x_DFP" schemaVersion="1.2" url="https://gd32mcu.com/data/documents/pack/" vendor="GigaDevice" version="2.0.3"/>
<targetInfos>
@ -908,6 +909,14 @@
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="source" name="Device\Firmware\Peripherals\src\gd32f10x_bkp.c" version="2.0.2">
<instance index="0">RTE\Device\GD32F107VC\gd32f10x_bkp.c</instance>
<component Cclass="Device" Cgroup="GD32F10x_StdPeripherals" Csub="BKP" Cvendor="GigaDevice" Cversion="2.0.2" condition="GD32F10x STDPERIPHERALS RCU"/>
<package name="GD32F10x_DFP" schemaVersion="1.2" url="https://gd32mcu.com/data/documents/pack/" vendor="GigaDevice" version="2.0.3"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="source" name="Device\Firmware\Peripherals\src\gd32f10x_dbg.c" version="2.0.2">
<instance index="0" removed="1">RTE\Device\GD32F107VC\gd32f10x_dbg.c</instance>
<component Cclass="Device" Cgroup="GD32F10x_StdPeripherals" Csub="DBG" Cvendor="GigaDevice" Cversion="2.0.2" condition="GD32F10x STDPERIPHERALS RCU"/>

78
main.c
View File

@ -1,5 +1,7 @@
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "gd32f107c_eval.h"
#include "gd32f10x_gpio.h"
#include "stdio.h"
@ -26,6 +28,9 @@
#define TASK_HELLO_WORLD_DELAY 500
#define TASK_TOGGLE_LED_DELAY 125
#define OSC32_PORT GPIOC
#define OSC32_IN GPIO_PIN_14
#define OSC32_OUT GPIO_PIN_15
/*
* RMII interface port & pin definitions
*/
@ -57,12 +62,12 @@
#define TEST_RUNNER_TASK_STACK_SIZE 512
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 0
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 1
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 0
#define mainCREATE_TCP_ECHO_SERVER_TASK 1
#define mainCREATE_TCP_ECHO_SERVER_TASK 0
/* Simple UDP client and server task parameters. */
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
/* Echo client task parameters - used for both TCP and UDP echo clients. */
@ -78,15 +83,12 @@
//#define mainDEVICE_NICK_NAME "windows_demo"
#ifdef DEBUG
#define BKPT_DEBUG()\
__BKPT(); \
// NVIC_SystemReset(); \
// while(TRUE){}; \
#define BKPT_DEBUG() __BKPT();
#else
#define BKPT_DEBUG()
#endif
TaskHandle_t vTaskHelloWorld_Handle, vTaskToggleLed_Handle;
/* Default MAC address configuration. The demo creates a virtual network
* connection that uses this MAC address by accessing the raw Ethernet data
* to and from a real network connection on the host PC. See the
@ -199,19 +201,32 @@ static void vInitMCU(void)
rcu_periph_clock_enable(RCU_AF);
rcu_periph_clock_enable(RCU_ENET);
rcu_periph_clock_enable(RCU_ENETTX);
rcu_periph_clock_enable(RCU_ENETRX);
rcu_periph_clock_enable(RCU_ENETRX);
rcu_periph_clock_enable(RCU_BKPI);
rcu_periph_clock_enable(RCU_PMU);
rcu_periph_clock_enable(RCU_RTC);
/* Configure RTC */
#ifdef RTC_ENABLE
rcu_rtc_clock_config(RCU_RTCSRC_LXTAL);
rtc_configuration_mode_enter();
rtc_lwoff_wait();
rtc_counter_set(0xA5A5A5A5);
//rtc_lwoff_wait();
rtc_configuration_mode_exit();
#endif
gpio_init(OSC32_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_2MHZ, OSC32_IN);
gpio_init(OSC32_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_2MHZ, OSC32_OUT);
if (FALSE == rtc_counter_get() & FALSE == rtc_flag_get(RTC_CTL_OVIF))
{
pmu_backup_write_enable();
rcu_rtc_clock_config(RCU_RTCSRC_LXTAL);
while (RESET == (RCU_BDCTL & RCU_BDCTL_LXTALSTB)) {}
rtc_lwoff_wait();
rtc_counter_set(0xA5A5);
rtc_lwoff_wait();
rtc_prescaler_set(0);
rtc_lwoff_wait();
}
else if (TRUE == rtc_flag_get(RTC_CTL_OVIF))
rtc_flag_clear(RTC_CTL_OVIF);
/* Configure GPIO Alternate UART function */
gd_eval_com_init(EVAL_COM1);
@ -248,9 +263,9 @@ static void vInitMCU(void)
/* Enable Ethernet MAC */
enet_descriptors_chain_init(ENET_DMA_TX);
enet_descriptors_chain_init(ENET_DMA_RX);
//enet_desc_receive_complete_bit_enable(dma_current_rxdesc);
enet_descriptors_chain_init(ENET_DMA_RX); //enet_desc_receive_complete_bit_enable(dma_current_rxdesc);
enet_enable();
//nvic_irq_enable(ENET_IRQn, ipconfigMAC_INTERRUPT_PRIORITY, 0xFF);
__disable_irq();
NVIC_ClearPendingIRQ(ENET_IRQn);
NVIC_SetPriority(ENET_IRQn, ipconfigMAC_INTERRUPT_PRIORITY);
@ -266,14 +281,19 @@ void vTaskHelloWorld( void *pvParameters)
{
char ButtonState = 0;
for( ;; )
{
{
#ifdef DEBUG_ET_IRQ
ulTaskNotifyTakeIndexed(1, pdFALSE, portMAX_DELAY );
FreeRTOS_debug_printf(("ENET_DMA_INT_FLAG_ET\n"));
#else
ButtonState = !gpio_input_bit_get(GPIOB, BUTTON_USER);
if (ButtonState)
{
FreeRTOS_debug_printf(("Key pressed\n"));
fflush( stdout );
vTaskDelay(TASK_HELLO_WORLD_DELAY);
}
}
#endif
}
}
/**! \brief vTaskToggleLed procedure
@ -285,6 +305,10 @@ void vTaskToggleLed( void *pvParameters)
char toggle = 1;
for( ;; )
{
#ifdef DEBUG_RBU_IRQ
ulTaskNotifyTakeIndexed(0, pdFALSE, portMAX_DELAY );
FreeRTOS_debug_printf(("ENET_DMA_INT_FLAG_RBU\n"));
#else
if (toggle)
{
gpio_bit_reset(LED2_USER_PORT, LED2_USER);
@ -294,7 +318,8 @@ void vTaskToggleLed( void *pvParameters)
gpio_bit_set(LED2_USER_PORT, LED2_USER);
}
toggle = !toggle;
vTaskDelay(TASK_TOGGLE_LED_DELAY);
vTaskDelay(TASK_TOGGLE_LED_DELAY);
#endif
}
}
@ -309,7 +334,7 @@ static void prvMiscInitialisation( void )
/* Seed the random number generator. */
xTimeNow = rtc_counter_get();
FreeRTOS_debug_printf( ("Seed for randomiser: %lu\r\n", xTimeNow ) );
FreeRTOS_debug_printf( ("Seed for randomiser: %d\r\n", (unsigned)xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 0 ] );
@ -327,8 +352,8 @@ int main(void)
{
vInitMCU();
prvMiscInitialisation();
xTaskCreate( vTaskToggleLed, "ToggleLed", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
xTaskCreate( vTaskHelloWorld, "HelloWorld", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
xTaskCreate( vTaskToggleLed, "ToggleLed", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &vTaskToggleLed_Handle);
xTaskCreate( vTaskHelloWorld, "HelloWorld", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &vTaskHelloWorld_Handle);
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
vTaskStartScheduler();
@ -425,8 +450,7 @@ static void prvSRand( UBaseType_t ulSeed )
}
UBaseType_t uxRand( void )
{
static UBaseType_t ulNextRand;
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
/* Utility function to generate a pseudo random number. */