forked from ROMEO/obsw
thread safety in newlib, newer lwip, optimized ISR for UART, some more stuff
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "lwip/sio.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <cstring>
|
||||
@ -12,8 +13,6 @@
|
||||
#include <xscugic.h>
|
||||
#include <xuartps.h>
|
||||
|
||||
|
||||
|
||||
#undef XUARTPS_IXR_RXOVR
|
||||
#define XUARTPS_IXR_RXOVR 0x00000020U /**< Rx Overrun error interrupt */
|
||||
#define XUARTPS_IXR_RTRIG 0x00000001U /**< RX FIFO trigger interrupt. */
|
||||
@ -21,51 +20,38 @@
|
||||
#define UART_INT_NR XPAR_XUARTPS_0_INTR
|
||||
|
||||
extern "C" {
|
||||
#include <lwip/apps/tftp_server.h>
|
||||
#include <lwip/apps/tftp_server.h>
|
||||
|
||||
static void*
|
||||
tftp_open(const char* fname, const char* mode, u8_t is_write)
|
||||
{
|
||||
void slipif_rxbyte_input(struct netif *netif, u8_t c);
|
||||
|
||||
static void *tftp_open(const char *fname, const char *mode, u8_t is_write) {
|
||||
LWIP_UNUSED_ARG(mode);
|
||||
return (void*)13;
|
||||
return (void *)13;
|
||||
}
|
||||
|
||||
static void
|
||||
tftp_close(void* handle)
|
||||
{}
|
||||
static void tftp_close(void *handle) {}
|
||||
|
||||
static int
|
||||
tftp_read(void* handle, void* buf, int bytes)
|
||||
{
|
||||
static int tftp_read(void *handle, void *buf, int bytes) {
|
||||
memset(buf, 'x', bytes);
|
||||
return bytes - 60;
|
||||
}
|
||||
|
||||
static int
|
||||
tftp_write(void* handle, struct pbuf* p)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static int tftp_write(void *handle, struct pbuf *p) { return 0; }
|
||||
|
||||
/* For TFTP client only */
|
||||
static void
|
||||
tftp_error(void* handle, int err, const char* msg, int size)
|
||||
{}
|
||||
static void tftp_error(void *handle, int err, const char *msg, int size) {}
|
||||
|
||||
static const struct tftp_context tftp = {
|
||||
tftp_open,
|
||||
tftp_close,
|
||||
tftp_read,
|
||||
tftp_write,
|
||||
tftp_error
|
||||
};
|
||||
static const struct tftp_context tftp = {tftp_open, tftp_close, tftp_read,
|
||||
tftp_write, tftp_error};
|
||||
|
||||
void slipif_rxbyte_input(struct netif *netif, u8_t c);
|
||||
|
||||
|
||||
void myInitDone(void *arg) { puts("init done"); }
|
||||
|
||||
struct netif netif;
|
||||
|
||||
QueueHandle_t uartIsrQueue;
|
||||
|
||||
extern XScuGic xInterruptController; /* Interrupt controller instance */
|
||||
|
||||
/** this is based on XUartPs_InterruptHandler() in xuartps_intr.c*/
|
||||
@ -83,20 +69,28 @@ void handleUARTInt(void *) {
|
||||
// Onlx RX intterupts are enabled
|
||||
// We do not care which interrupt actually triggered, just get all bytes
|
||||
// available into the stack
|
||||
u32 RecievedByte;
|
||||
uint8_t RecievedByte;
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
while (XUartPs_IsReceiveData(STDIN_BASEADDRESS)) {
|
||||
RecievedByte = XUartPs_ReadReg(STDIN_BASEADDRESS, XUARTPS_FIFO_OFFSET);
|
||||
slipif_received_byte(&netif, (u8)RecievedByte);
|
||||
xQueueSendToBackFromISR(uartIsrQueue, &RecievedByte,
|
||||
&xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
/* Clear the interrupt status. */
|
||||
XUartPs_WriteReg(STDIN_BASEADDRESS, XUARTPS_ISR_OFFSET, IsrStatus);
|
||||
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
void forwardPackets(void *) {
|
||||
uint8_t byte;
|
||||
BaseType_t result;
|
||||
while (1) {
|
||||
slipif_process_rxqueue(&netif);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
result = xQueueReceive(uartIsrQueue, &byte, portMAX_DELAY);
|
||||
if (result == pdTRUE) {
|
||||
slipif_rxbyte_input(&netif, byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,11 +104,13 @@ void sio_send(u8_t c, sio_fd_t fd) { XUartPs_SendByte(STDOUT_BASEADDRESS, c); }
|
||||
|
||||
void testIp() {
|
||||
|
||||
uartIsrQueue = xQueueCreate(512, 1); // TODO check
|
||||
|
||||
tcpip_init(myInitDone, nullptr);
|
||||
|
||||
ip_addr_t slip_addr = IPADDR4_INIT_BYTES(10, 0, 0, 32),
|
||||
slip_mask = IPADDR4_INIT_BYTES(255, 255, 255, 0),
|
||||
slip_gw = IPADDR4_INIT_BYTES(10, 25, 0, 1);
|
||||
ip4_addr_t slip_addr = {PP_HTONL(LWIP_MAKEU32(10, 0, 0, 32))},
|
||||
slip_mask = {PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0))},
|
||||
slip_gw = {PP_HTONL(LWIP_MAKEU32(10, 0, 0, 1))};
|
||||
|
||||
netifapi_netif_add(&netif, &slip_addr, &slip_mask, &slip_gw, NULL,
|
||||
slipif_init, netif_input);
|
||||
@ -140,7 +136,8 @@ void testIp() {
|
||||
XUartPs_WriteReg(STDIN_BASEADDRESS, XUARTPS_RXTOUT_OFFSET, 50);
|
||||
|
||||
// enable UART Interrupts
|
||||
u32 mask = XUARTPS_IXR_RTRIG | XUARTPS_IXR_RXOVR | XUARTPS_IXR_RXFULL | XUARTPS_IXR_TOUT;
|
||||
u32 mask = XUARTPS_IXR_RTRIG | XUARTPS_IXR_RXOVR | XUARTPS_IXR_RXFULL |
|
||||
XUARTPS_IXR_TOUT;
|
||||
/* Write the mask to the IER Register */
|
||||
XUartPs_WriteReg(STDIN_BASEADDRESS, XUARTPS_IER_OFFSET, mask);
|
||||
/* Write the inverse of the Mask to the IDR register */
|
||||
@ -153,7 +150,7 @@ void testIp() {
|
||||
xTaskCreate(forwardPackets, /* The function that implements the task. */
|
||||
"slip forward", /* The text name assigned to the task - for debug
|
||||
only as it is not used by the kernel. */
|
||||
1024, /* The size of the stack to allocate to the task. */
|
||||
1024, /* The size of the stack to allocate to the task. */
|
||||
nullptr, /* The parameter passed to the task - not used in this
|
||||
simple case. */
|
||||
4, /* The priority assigned to the task. */
|
||||
|
Reference in New Issue
Block a user