Skip to content

Commit

Permalink
Added W5500 driver and OSAL timer/time
Browse files Browse the repository at this point in the history
  • Loading branch information
pimvliet committed Nov 8, 2022
1 parent d1ecf3f commit 8e514ef
Show file tree
Hide file tree
Showing 6 changed files with 546 additions and 51 deletions.
80 changes: 80 additions & 0 deletions osal/STM32F746ZG/osal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "osal.h"

#include "stm32f7xx_hal.h"

extern volatile uint32_t sec;
extern TIM_HandleTypeDef htim2;

void osal_timer_start(osal_timert *self, uint32 timeout_us)
{
ec_timet current = osal_current_time();
self->stop_time.usec = current.usec + (timeout_us % 1000000);
self->stop_time.sec = current.sec + (timeout_us / 1000000);
if (self->stop_time.usec >= 1000000)
{
self->stop_time.usec -= 1000000;
self->stop_time.sec++;
}
}

boolean osal_timer_is_expired(osal_timert *self)
{
boolean expired = FALSE;

ec_timet current = osal_current_time();
if (current.sec >= self->stop_time.sec && current.usec >= self->stop_time.usec)
expired = TRUE;
else if (current.sec > self->stop_time.sec)
expired = TRUE;

return expired;
}

int osal_usleep(uint32 usec)
{
osal_timert timer;

osal_timer_start(&timer, usec);
while(!osal_timer_is_expired(&timer));

return 0;
}

ec_timet osal_current_time(void)
{
ec_timet rval;
rval.sec = sec;
rval.usec = htim2.Instance->CNT;
if (sec != rval.sec) //timer overflow has occured since polling the seconds
{
/* since there is no way to determine whether the usec was changed before or after reading, we have to check both values again. */
rval.sec = sec;
rval.usec = htim2.Instance->CNT;
}

return rval;
}

void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
{
if (end->usec < start->usec)
{
diff->sec = end->sec - start->sec - 1;
diff->usec = end->usec + 1000000 - start->usec;
}
else
{
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
}
}

int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
{
return 1; //TODO not supported
}

int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
{
return 1; //TODO not supported
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//! THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************
#include "socket.h"
#include <socket_w5500.h>

//M20150401 : Typing Error
//#define SOCK_ANY_PORT_NUM 0xC000;
Expand Down
File renamed without changes.
13 changes: 7 additions & 6 deletions oshw/STM32F746ZG/Wiznet/w5500_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ GPIO_TypeDef* m_rstPort;
uint8_t SPIReadWrite(uint8_t data)
{
//wait until FIFO has a free slot
while ((hspi1.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE);
SPI_TypeDef* SPI = hspi1.Instance;
while (!(SPI->SR & SPI_FLAG_TXE));

*(__IO uint8_t*) &hspi1.Instance->DR = data;
*(__IO uint8_t*) &SPI->DR = data;

while ((hspi1.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE);
while (!(SPI->SR & SPI_FLAG_RXNE));

return (*(__IO uint8_t*) &hspi1.Instance->DR);
return (*(__IO uint8_t*) &SPI->DR);
}

void wizchip_select(void)
Expand Down Expand Up @@ -97,11 +98,11 @@ void W5500Init(GPIO_TypeDef* csPort, uint16_t csPin, GPIO_TypeDef* rstPort, uint

W5500IOInit();


HAL_GPIO_WritePin(m_csPort, m_csPin, GPIO_PIN_SET);

HAL_GPIO_WritePin(m_rstPort, m_rstPin, GPIO_PIN_RESET);
tmp = 0xff;
while (tmp--);
HAL_Delay(10);
HAL_GPIO_WritePin(m_rstPort, m_rstPin, GPIO_PIN_SET);

reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
Expand Down
Loading

0 comments on commit 8e514ef

Please sign in to comment.