--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// font.h - header file for font data contained in system_fixed_be_8_15.c\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+\r
+#ifndef FONT_H_\r
+#define FONT_H_\r
+\r
+extern const unsigned char font_data_table[];\r
+extern const unsigned char font_index_table[];\r
+\r
+#endif /*FONT_H_*/\r
--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// lcd.c contains various routines to plot to the LCD display on the RDB1768\r
+// development board.\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+\r
+#include "lcd_commands.h"\r
+#include "lcd.h"\r
+#include "lcd_driver.h"\r
+#include "font.h"\r
+\r
+#include <stdlib.h> // to provice abs() function\r
+\r
+// Routine to draw a filled rectangle to the LCD.\r
+// Two corners of rectangle are at (xmin,ymin) and (xmax,ymax).\r
+// The Rectangle is filled with the RGB565 color specified\r
+void LCD_FilledRect(int xmin,int xmax,int ymin,int ymax,int color)\r
+{\r
+ int i;\r
+\r
+ // Specify to LCD controller coordinates we are writing to...\r
+ LCDdriver_WriteCom(DD_CASET); // Set the column address\r
+ LCDdriver_WriteData(xmin); // min address\r
+ LCDdriver_WriteData(xmax); // max address\r
+ LCDdriver_WriteCom(DD_RASET); // Set the row address\r
+ LCDdriver_WriteData(ymin + 1); // min address\r
+ LCDdriver_WriteData(ymax + 1); // max address\r
+ LCDdriver_WriteCom(DD_RAMWR); // RAM Write command\r
+\r
+ // Plot the color data to the LCD buffer\r
+ for(i = ((xmax - xmin + 1) * (ymax - ymin + 1)); i > 0; i--)\r
+ {\r
+ LCDdriver_WriteData(color >> 8); // top 8 bits of RGB565 color\r
+ LCDdriver_WriteData(color); // bottom 8 bits of RGB565 color\r
+ }\r
+}\r
+\r
+// Routine to draw an unfilled rectangle to the LCD.\r
+// Two corners of rectangle are at (xmin,ymin) and (xmax,ymax).\r
+// The Rectangle is drawn in the RGB565 color specified\r
+void LCD_Rect(int xmin,int xmax,int ymin,int ymax,int color)\r
+{\r
+ // Draw 4 lines of rectange as 4 filled rectanges, each of 1 pixel wide\r
+ LCD_FilledRect(xmin,xmin,ymin,ymax,color);\r
+ LCD_FilledRect(xmax,xmax,ymin,ymax,color);\r
+ LCD_FilledRect(xmin,xmax,ymin,ymin,color);\r
+ LCD_FilledRect(xmin,xmax,ymax,ymax,color);\r
+}\r
+\r
+\r
+\r
+// Plot a point on the screen in the 6:5:6 color format\r
+void LCD_PlotPoint(int x,int y,int color)\r
+{\r
+ LCDdriver_WriteCom(DD_CASET); // Set the column address \r
+ LCDdriver_WriteData(x); // min address\r
+ LCDdriver_WriteData(x); // max address\r
+ LCDdriver_WriteCom(DD_RASET); // Set the row address\r
+ LCDdriver_WriteData(y + 1); // min address\r
+ LCDdriver_WriteData(y + 1); // max address\r
+ LCDdriver_WriteCom(DD_RAMWR); // RAM Write command\r
+ LCDdriver_WriteData(color >> 8); // top 8 bits of RGB565 color\r
+ LCDdriver_WriteData(color); // top 8 bits of RGB565 color\r
+}\r
+\r
+// Routine to draw a filled circle to the LCD.\r
+// The centre of the circle is at (x0,y0) and the circle has the \r
+// specifed radius. The circle is filled with the RGB565 color \r
+// The circle is drawn using the "Midpoint circle algorithm", \r
+// also known as "Bresenham's circle algorithm". In order to fill\r
+// the circle, the algorithm has been modifed to draw a line between\r
+// each two points, rather than plotting the two points individually.\r
+void LCD_FilledCircle (int x0, int y0, int radius, int color)\r
+{\r
+ int f = 1 - radius;\r
+ int ddF_x = 1;\r
+ int ddF_y = -2 * radius;\r
+ int x = 0;\r
+ int y = radius;\r
+ \r
+ LCD_FilledRect(x0, x0 ,y0 - radius,y0 + radius, color); \r
+ LCD_FilledRect(x0 - radius, x0 + radius ,y0,y0, color); \r
+ \r
+ while(x < y)\r
+ {\r
+ if(f >= 0) \r
+ {\r
+ y--;\r
+ ddF_y += 2;\r
+ f += ddF_y;\r
+ }\r
+ x++;\r
+ ddF_x += 2;\r
+ f += ddF_x; \r
+\r
+ LCD_FilledRect(x0-x, x0+x ,y0 +y, y0 + y, color); \r
+ LCD_FilledRect(x0-x, x0+x ,y0 - y, y0 - y, color); \r
+ LCD_FilledRect(x0-y, x0+y ,y0 + x, y0 + x, color); \r
+ LCD_FilledRect(x0-y, x0+y ,y0 - x, y0 - x, color); \r
+ }\r
+}\r
+\r
+// Routine to draw an unfilled circle to the LCD.\r
+// The centre of the circle is at (x0,y0) and the circle has the \r
+// specifed radius. The circle is drawn in the RGB565 color \r
+// The circle is drawn using the "Midpoint circle algorithm", \r
+// also known as "Bresenham's circle algorithm". \r
+void LCD_Circle (int x0, int y0, int radius, int color)\r
+{\r
+ int f = 1 - radius;\r
+ int ddF_x = 1;\r
+ int ddF_y = -2 * radius;\r
+ int x = 0;\r
+ int y = radius;\r
+\r
+ LCD_PlotPoint(x0, y0 + radius, color);\r
+ LCD_PlotPoint(x0, y0 - radius, color);\r
+ LCD_PlotPoint(x0 + radius, y0, color);\r
+ LCD_PlotPoint(x0 - radius, y0, color);\r
+\r
+ while(x < y)\r
+ {\r
+ if(f >= 0) \r
+ {\r
+ y--;\r
+ ddF_y += 2;\r
+ f += ddF_y;\r
+ }\r
+ x++;\r
+ ddF_x += 2;\r
+ f += ddF_x; \r
+ LCD_PlotPoint(x0 + x, y0 + y, color);\r
+ LCD_PlotPoint(x0 - x, y0 + y, color);\r
+ LCD_PlotPoint(x0 + x, y0 - y, color);\r
+ LCD_PlotPoint(x0 - x, y0 - y, color);\r
+ LCD_PlotPoint(x0 + y, y0 + x, color);\r
+ LCD_PlotPoint(x0 - y, y0 + x, color);\r
+ LCD_PlotPoint(x0 + y, y0 - x, color);\r
+ LCD_PlotPoint(x0 - y, y0 - x, color);\r
+ }\r
+}\r
+\r
+// Routine to draw a line in the RGB565 color to the LCD.\r
+// The line is drawn from (xmin,ymin) to (xmax,ymax).\r
+// The algorithm used to draw the line is "Bresenham's line\r
+// algorithm". \r
+#define SWAP(a, b) a ^= b; b ^= a; a ^= b; \r
+\r
+void LCD_Line (int xmin,int xmax,int ymin,int ymax,int color)\r
+{\r
+ int Dx = xmax - xmin; \r
+ int Dy = ymax - ymin;\r
+ int steep = (abs(Dy) >= abs(Dx));\r
+ if (steep) {\r
+ SWAP(xmin, ymin);\r
+ SWAP(xmax, ymax);\r
+ // recompute Dx, Dy after swap\r
+ Dx = xmax - xmin;\r
+ Dy = ymax - ymin;\r
+ }\r
+ int xstep = 1;\r
+ if (Dx < 0) {\r
+ xstep = -1;\r
+ Dx = -Dx;\r
+ }\r
+ int ystep = 1;\r
+ if (Dy < 0) {\r
+ ystep = -1; \r
+ Dy = -Dy; \r
+ }\r
+ int TwoDy = 2*Dy; \r
+ int TwoDyTwoDx = TwoDy - 2*Dx; // 2*Dy - 2*Dx\r
+ int E = TwoDy - Dx; //2*Dy - Dx\r
+ int y = ymin;\r
+ int xDraw, yDraw;\r
+ int x;\r
+ for (x = xmin; x != xmax; x += xstep) { \r
+ if (steep) { \r
+ xDraw = y;\r
+ yDraw = x;\r
+ } else { \r
+ xDraw = x;\r
+ yDraw = y;\r
+ }\r
+ // plot\r
+ LCD_PlotPoint(xDraw, yDraw, color);\r
+ // next\r
+ if (E > 0) {\r
+ E += TwoDyTwoDx; //E += 2*Dy - 2*Dx;\r
+ y = y + ystep;\r
+ } else {\r
+ E += TwoDy; //E += 2*Dy;\r
+ }\r
+ }\r
+}\r
+\r
+// Routine to clear the LCD.\r
+// Implemented by drawing a black rectangle across the whole screen\r
+void LCD_ClearScreen(void)\r
+{ \r
+ LCD_FilledRect (0,LCD_MAX_X,0 , LCD_MAX_Y, COLOR_BLACK);\r
+}\r
+\r
+\r
+\r
+// Routine to write a single character to screen in the font pointed\r
+// to by pBitMap. This routine is intended to be used via the \r
+// LCD_PrintChar() and LCD_PrintString() routines, rather than called\r
+// directly from user code.\r
+void LCD_WriteBitMap8x15(int x, int y, int height, int width, unsigned char *pBitMap, int color)\r
+{\r
+ int xmax = x + width - 1; // start at zero\r
+ int ymax = y + height - 1; // start at zero\r
+ int iRow, iCol;\r
+ unsigned char ucRowData;\r
+ \r
+ LCDdriver_WriteCom(DD_CASET); // Column address set\r
+ LCDdriver_WriteData(x); // Start column\r
+ LCDdriver_WriteData(xmax); // End column\r
+ LCDdriver_WriteCom(DD_RASET); // Row address set\r
+ LCDdriver_WriteData(y); // Start row\r
+ LCDdriver_WriteData(ymax); // End row\r
+ LCDdriver_WriteCom(DD_RAMWR); // Memory write\r
+ \r
+ \r
+ for(iRow=0;iRow<height;iRow++)\r
+ {\r
+ ucRowData = *pBitMap++;\r
+ \r
+ for(iCol=0;iCol<width;iCol++)\r
+ {\r
+\r
+ // Look at each input bitmap bit\r
+ // and write as a black-pixel or\r
+ // a color-pixel.\r
+ \r
+ if(ucRowData & 0x80) // 'color pixel'\r
+ {\r
+ LCDdriver_WriteData(color >> 8); \r
+ LCDdriver_WriteData(color);\r
+ }\r
+ else // black pixel\r
+ {\r
+ LCDdriver_WriteData(0x00);\r
+ LCDdriver_WriteData(0x00);\r
+ }\r
+ \r
+ ucRowData = ucRowData<<1;\r
+ }\r
+ }\r
+\r
+}\r
+\r
+\r
+// Prints the character 'c' to the LCD in the appropriate color.\r
+void LCD_PrintChar(int x, int y, unsigned char c, int color )\r
+{\r
+ const unsigned char index = font_index_table[c];\r
+ const unsigned int offset = index * 15;\r
+ unsigned char *pData = (unsigned char *)&font_data_table[offset]; \r
+\r
+ LCD_WriteBitMap8x15(x, y, 15, 8, pData, color);\r
+}\r
+\r
+// Prints the string to the LCD in the appropriate color.\r
+void LCD_PrintString(int x, int y, char *pcString, int iStrLen, int color)\r
+{\r
+ unsigned char index;\r
+ unsigned int offset;\r
+ unsigned char *pData;\r
+ unsigned char c;\r
+ int i;\r
+ \r
+ for(i=0;i<iStrLen;i++)\r
+ {\r
+ c = pcString[i];\r
+ if(c==0)\r
+ break;\r
+ index = font_index_table[c];\r
+ offset = index * 15;\r
+ pData = (unsigned char *)&font_data_table[offset];\r
+\r
+ LCD_WriteBitMap8x15(x, y, 15, 8, pData, color); \r
+ x += 8;\r
+ }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// lcd.h - Routines containing primitives for writing to the LCD\r
+//\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+\r
+\r
+#ifndef LCD_H_\r
+#define LCD_H_\r
+\r
+// Define size of LCD screen.\r
+\r
+#define LCD_MAX_X 128\r
+#define LCD_MAX_Y 128\r
+\r
+// Translates a 24-bit RGB color to RGB565\r
+#define TRANSLATE24BIT_TO_RGB565(c) ((((c) & 0x00ff0000) >> 19) | \\r
+ ((((c) & 0x0000ff00) >> 5) & 0x000007e0) | \\r
+ ((((c) & 0x000000ff) << 8) & 0x0000f800))\r
+\r
+// Define a basic set of 24bit colors, based on the standard "websafe" set\r
+#define COLOR24_AQUA 0x00FFFF\r
+#define COLOR24_GREY 0x808080\r
+#define COLOR24_NAVY 0x000080 \r
+#define COLOR24_SILVER 0xC0C0C0\r
+#define COLOR24_BLACK 0x000000 \r
+#define COLOR24_GREEN 0x008000 \r
+#define COLOR24_OLIVE 0x808000 \r
+#define COLOR24_TEAL 0x008080\r
+#define COLOR24_BLUE 0x0000FF \r
+#define COLOR24_LIME 0x00FF00 \r
+#define COLOR24_PURPLE 0x800080 \r
+#define COLOR24_WHITE 0xFFFFFF\r
+#define COLOR24_FUCHSIA 0xFF00FF \r
+#define COLOR24_MAROON 0x800000 \r
+#define COLOR24_RED 0xFF0000\r
+#define COLOR24_YELLOW 0xFFFF00\r
+\r
+// Create a set of RGB565 colors that can be used directly within code\r
+#define COLOR_AQUA TRANSLATE24BIT_TO_RGB565(COLOR24_AQUA)\r
+#define COLOR_GREY TRANSLATE24BIT_TO_RGB565(COLOR24_GREY)\r
+#define COLOR_NAVY TRANSLATE24BIT_TO_RGB565(COLOR24_NAVY) \r
+#define COLOR_SILVER TRANSLATE24BIT_TO_RGB565(COLOR24_SILVER)\r
+#define COLOR_BLACK TRANSLATE24BIT_TO_RGB565(COLOR24_BLACK) \r
+#define COLOR_GREEN TRANSLATE24BIT_TO_RGB565(COLOR24_GREEN) \r
+#define COLOR_OLIVE TRANSLATE24BIT_TO_RGB565(COLOR24_OLIVE) \r
+#define COLOR_TEAL TRANSLATE24BIT_TO_RGB565(COLOR24_TEAL)\r
+#define COLOR_BLUE TRANSLATE24BIT_TO_RGB565(COLOR24_BLUE) \r
+#define COLOR_LIME TRANSLATE24BIT_TO_RGB565(COLOR24_LIME) \r
+#define COLOR_PURPLE TRANSLATE24BIT_TO_RGB565(COLOR24_PURPLE) \r
+#define COLOR_WHITE TRANSLATE24BIT_TO_RGB565(COLOR24_WHITE)\r
+#define COLOR_FUCHSIA TRANSLATE24BIT_TO_RGB565(COLOR24_FUCHSIA) \r
+#define COLOR_MAROON TRANSLATE24BIT_TO_RGB565(COLOR24_MAROON) \r
+#define COLOR_RED TRANSLATE24BIT_TO_RGB565(COLOR24_RED)\r
+#define COLOR_YELLOW TRANSLATE24BIT_TO_RGB565(COLOR24_YELLOW)\r
+\r
+\r
+void LCD_Line (int xmin,int xmax,int ymin,int ymax,int color);\r
+void LCD_FilledRect(int xmin,int xmax,int ymin,int ymax,int color);\r
+void LCD_Rect(int xmin,int xmax,int ymin,int ymax,int color);\r
+void LCD_WriteBitMap8x15(int x, int y, int height, int width, unsigned char *pBitMap, int color);\r
+void LCD_PlotPoint(int x,int y,int color);\r
+void LCD_Circle (int x0, int y0, int radius, int color);\r
+void LCD_FilledCircle (int x0, int y0, int radius, int color);\r
+void LCD_ClearScreen(void);\r
+void LCD_WriteBitMap8x15(int x, int y, int height, int width, unsigned char *pBitMap, int color);\r
+void LCD_PrintChar(int x, int y, unsigned char c, int color );\r
+void LCD_PrintString(int x, int y, char *pcString, int iStrLen, int color);\r
+\r
+\r
+#endif /*LCD_H_*/
\ No newline at end of file
--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// lcd_commands.h contains defines mapping onto the commands accepted by the\r
+// Sitronix ST7637 LCD Controller/driver used on the RDB1768 development board.//\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+\r
+#ifndef LCD_COMMANDS_H_\r
+#define LCD_COMMANDS_H_\r
+\r
+#define DD_NOP 0x00\r
+#define DD_SWRESET 0x01 //SW reset the display\r
+#define DD_SLPIN 0x10 //Sleep in and booster off\r
+#define DD_SLPOUT 0x11 //Sleep out and booster on\r
+#define DD_NORON 0x13 //Partial mode off (Normal mode on)\r
+#define DD_DISPOFF 0x28 //Display Off\r
+#define DD_DISPON 0x29 //Display On\r
+#define DD_CASET 0x2a //Column address set\r
+#define DD_RASET 0x2b //Row address set\r
+#define DD_RAMWR 0x2c //Memory write\r
+#define DD_MADCTR 0x36 //Memory Data Access Control\r
+#define DD_COLORMOD 0x3a //Set the color mode for the display \r
+#define DD_ColScanDir 0xb7 //Set the column scanning direction\r
+#define DD_VopSet 0xc0 //LCD supply voltage set\r
+#define DD_BiasSel 0xc3 //Bias selection\r
+#define DD_BstMbpXSel 0xc4 //Booster setting\r
+#define DD_AUTOLOADSET 0xd7 //Control auto load of ROM data\r
+#define DD_EPCTIN 0xe0 //OTP control RD/WR\r
+#define DD_EPREAD 0xe3 //OTP read\r
+#define DD_EPCTOUT 0xe1 //OTP control cancel\r
+\r
+\r
+#endif /*LCD_COMMANDS_H_*/\r
--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// lcd_driver.c contains the lowest level access routines for the Sitronix\r
+// ST7637 LCD Controller/driver used on the RDB1768 development board.\r
+//\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+\r
+#include "NXP/LPC17xx/LPC17xx.h"\r
+#include "lcd_driver.h"\r
+#include "lcd_commands.h"\r
+\r
+// Bits within GPIO port 2 used for LCD driver\r
+#define LCD_CSB_PIN (1<<13)\r
+#define LCD_A0_PIN (1<<8)\r
+#define LCD_WR_PIN (1<<11)\r
+#define LCD_RD_PIN (1<<12)\r
+#define LCD_DATA_PIN 0xff\r
+\r
+// Bit within GPIO port 3 used for LCD driver\r
+#define LCD_RESB_PIN (1<<25)\r
+\r
+// Bits to configure as outputs for driving LCD\r
+#define LCD_PORT2_DIRECTIONS (LCD_CSB_PIN | LCD_A0_PIN | LCD_WR_PIN | LCD_RD_PIN | LCD_DATA_PIN)\r
+#define LCD_PORT3_DIRECTIONS (LCD_RESB_PIN)\r
+\r
+// Define names for GPIO port 2 and 3 registers to better indicate in code\r
+// the operation being carried out on the LCD driver hardware.\r
+#define LCD_DATA_CLR FIO2CLR\r
+#define LCD_DATA_SET FIO2SET\r
+\r
+#define LCD_CSB_CLR FIO2CLR\r
+#define LCD_CSB_SET FIO2SET\r
+\r
+#define LCD_RESB_CLR FIO3CLR\r
+#define LCD_RESB_SET FIO3SET\r
+\r
+#define LCD_A0_CLR FIO2CLR\r
+#define LCD_A0_SET FIO2SET\r
+\r
+#define LCD_WR_CLR FIO2CLR\r
+#define LCD_WR_SET FIO2SET\r
+\r
+#define LCD_RD_CLR FIO2CLR\r
+#define LCD_RD_SET FIO2SET\r
+\r
+// Routine to write data to LCD driver. Normally called in combination\r
+// with LCDdriver_WriteCom() routine\r
+void LCDdriver_WriteData(unsigned char LCD_Data)\r
+{\r
+ LCD_DATA_CLR = LCD_DATA_PIN; \r
+ LCD_DATA_SET = LCD_Data;\r
+ LCD_CSB_CLR = LCD_CSB_PIN;\r
+ LCD_WR_CLR = LCD_WR_PIN;\r
+ LCD_WR_SET = LCD_WR_PIN;\r
+ LCD_CSB_SET = LCD_CSB_PIN;\r
+}\r
+\r
+// Routine to configure set LCD driver to accept particular command.\r
+// A call to this routine will normally be followed by a call\r
+// to LCDdriver_WriteData() to transfer appropriate parameters to driver.\r
+void LCDdriver_WriteCom(unsigned char LCD_Command)\r
+{\r
+ LCD_DATA_CLR = LCD_DATA_PIN; \r
+ LCD_DATA_SET = LCD_Command;\r
+ LCD_A0_CLR = LCD_A0_PIN;\r
+ LCD_CSB_CLR = LCD_CSB_PIN;\r
+ LCD_WR_CLR = LCD_WR_PIN;\r
+ LCD_WR_SET = LCD_WR_PIN;\r
+ LCD_CSB_SET = LCD_CSB_PIN;\r
+ LCD_A0_SET = LCD_A0_PIN;\r
+}\r
+\r
+// Function to add short delays in writing things to the LCD.\r
+void ms_delay(int n)\r
+{\r
+ volatile int d;\r
+ for (d=0; d<n*3000; d++){}\r
+}\r
+\r
+\r
+// Initialize GPIO connection to the LCD driver\r
+void LCDdriver_ConfigGPIOtoLCD(void)\r
+{\r
+ // set direction to outputs \r
+ FIO2DIR |= LCD_PORT2_DIRECTIONS; \r
+ FIO3DIR |= LCD_PORT3_DIRECTIONS;\r
+ \r
+ // Set GPIO outputs connected to LCD to default values\r
+ LCD_CSB_SET = LCD_CSB_PIN;\r
+ LCD_A0_SET = LCD_A0_PIN;\r
+ LCD_WR_SET = LCD_WR_PIN;\r
+ LCD_RD_SET = LCD_RD_PIN;\r
+ LCD_RESB_SET = LCD_RESB_PIN;\r
+ LCD_DATA_CLR = 0xff; // data bus to zero \r
+\r
+}\r
+\r
+\r
+// Initialisation routine to set up LCD\r
+void LCDdriver_initialisation(void)\r
+{\r
+ int i; // temp loop variable\r
+ \r
+ LCDdriver_ConfigGPIOtoLCD(); // Initialize the GPIO for the display\r
+\r
+ LCDdriver_WriteCom(DD_SWRESET); // SW reset\r
+ ms_delay(120); // Small delay\r
+\r
+ LCDdriver_WriteCom(DD_AUTOLOADSET); // disable auto loading of mask rom data\r
+ LCDdriver_WriteData(0xBF);\r
+\r
+ LCDdriver_WriteCom(DD_EPCTIN); // OTP control mode=read\r
+ LCDdriver_WriteData(0x00);\r
+ ms_delay(10); // Small delay\r
+\r
+ LCDdriver_WriteCom(DD_EPREAD); // Start the OTP read.\r
+ ms_delay(20); // Small delay\r
+\r
+ LCDdriver_WriteCom(DD_EPCTOUT); // Cancel the OTP read (20ms should have been enough)\r
+\r
+ LCDdriver_WriteCom(DD_DISPOFF); // display off\r
+\r
+ LCDdriver_WriteCom(DD_SLPOUT); // Exit sleep mode.\r
+ ms_delay(50); // Small delay\r
+\r
+ LCDdriver_WriteCom(DD_VopSet); // set LCD operating voltage to 14V.\r
+ LCDdriver_WriteData(0x04);\r
+ LCDdriver_WriteData(0x01);\r
+\r
+ LCDdriver_WriteCom(DD_BiasSel); // Select an LCD bias voltage ratio of 1/12.\r
+ LCDdriver_WriteData(0x00);\r
+\r
+ LCDdriver_WriteCom(DD_BstMbpXSel); // x8 booster circuit on\r
+ LCDdriver_WriteData(0x07);\r
+\r
+ LCDdriver_WriteCom(DD_ColScanDir); // Invert the column scan direction for the panel.\r
+ LCDdriver_WriteData(0xC0);\r
+\r
+ LCDdriver_WriteCom(DD_COLORMOD); // 16bpp, 5-6-5 data input mode.\r
+ LCDdriver_WriteData(0x05);\r
+ \r
+ LCDdriver_WriteCom(DD_MADCTR); // mem scan direction\r
+ LCDdriver_WriteData(0x00);\r
+ \r
+ LCDdriver_WriteCom(DD_DISPON); // display on\r
+\r
+ // Now Clear the Screen\r
+ LCDdriver_WriteCom(DD_CASET);\r
+ LCDdriver_WriteData(0x00);\r
+ LCDdriver_WriteData(0x7F);\r
+\r
+ LCDdriver_WriteCom(DD_RASET);\r
+ LCDdriver_WriteData(0x01);\r
+ LCDdriver_WriteData(0x80);\r
+\r
+ LCDdriver_WriteCom(DD_RAMWR);\r
+ for(i = 0; i < (128 * 128); i++)\r
+ {\r
+ LCDdriver_WriteData(0x00);\r
+ LCDdriver_WriteData(0x00);\r
+ }\r
+\r
+ LCDdriver_WriteCom(DD_NORON); // normal operation mode\r
+}\r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// lcd_driver.h - Header file for driver for the lowest level access routines\r
+// for the Sitronix ST7637 LCD Controller/driver used on the RDB1768 \r
+// development board.\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+\r
+#ifndef LCD_DRIVER_H_\r
+#define LCD_DRIVER_H_\r
+\r
+void LCDdriver_WriteData(unsigned char LCD_Data);\r
+void LCDdriver_WriteCom(unsigned char LCD_Command);\r
+void LCDdriver_initialisation(void);\r
+\r
+#endif /*LCD_DRIVER_H_*/\r
--- /dev/null
+/*******************************************************************************************\r
+ Data table provides the bitmap data of each character.\r
+\r
+ To get the starting data offset of character 'A', you can use the following expression:\r
+\r
+ const unsigned char index = index_table['A'];\r
+ const unsigned int offset = offset_table[index];\r
+ const unsigned char *pData = data_table[offset];\r
+\r
+ *******************************************************************************************/\r
+const unsigned char font_data_table[] = {\r
+\r
+/* character 0x0020 (' '): (width=8, offset=0) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0021 ('!'): (width=8, offset=15) */\r
+0x00, 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x3C, 0x18, \r
+0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0022 ('"'): (width=8, offset=30) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0023 ('#'): (width=8, offset=45) */\r
+0x00, 0x00, 0x00, 0x36, 0x36, 0x7F, 0x36, 0x36, \r
+0x36, 0x7F, 0x36, 0x36, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0024 ('$'): (width=8, offset=60) */\r
+0x00, 0x18, 0x18, 0x3C, 0x66, 0x60, 0x30, 0x18, \r
+0x0C, 0x06, 0x66, 0x3C, 0x18, 0x18, 0x00, \r
+\r
+/* character 0x0025 ('%'): (width=8, offset=75) */\r
+0x00, 0x00, 0x70, 0xD8, 0xDA, 0x76, 0x0C, 0x18, \r
+0x30, 0x6E, 0x5B, 0x1B, 0x0E, 0x00, 0x00, \r
+\r
+/* character 0x0026 ('&'): (width=8, offset=90) */\r
+0x00, 0x00, 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x60, \r
+0x6F, 0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0027 ('''): (width=8, offset=105) */\r
+0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0028 ('('): (width=8, offset=120) */\r
+0x00, 0x00, 0x00, 0x0C, 0x18, 0x18, 0x30, 0x30, \r
+0x30, 0x30, 0x30, 0x18, 0x18, 0x0C, 0x00, \r
+\r
+/* character 0x0029 (')'): (width=8, offset=135) */\r
+0x00, 0x00, 0x00, 0x30, 0x18, 0x18, 0x0C, 0x0C, \r
+0x0C, 0x0C, 0x0C, 0x18, 0x18, 0x30, 0x00, \r
+\r
+/* character 0x002A ('*'): (width=8, offset=150) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x1C, 0x7F, \r
+0x1C, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x002B ('+'): (width=8, offset=165) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, \r
+0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x002C (','): (width=8, offset=180) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+0x00, 0x00, 0x1C, 0x1C, 0x0C, 0x18, 0x00, \r
+\r
+/* character 0x002D ('-'): (width=8, offset=195) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x002E ('.'): (width=8, offset=210) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+0x00, 0x00, 0x1C, 0x1C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x002F ('/'): (width=8, offset=225) */\r
+0x00, 0x00, 0x00, 0x06, 0x06, 0x0C, 0x0C, 0x18, \r
+0x18, 0x30, 0x30, 0x60, 0x60, 0x00, 0x00, \r
+\r
+/* character 0x0030 ('0'): (width=8, offset=240) */\r
+0x00, 0x00, 0x00, 0x1E, 0x33, 0x37, 0x37, 0x33, \r
+0x3B, 0x3B, 0x33, 0x1E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0031 ('1'): (width=8, offset=255) */\r
+0x00, 0x00, 0x00, 0x0C, 0x1C, 0x7C, 0x0C, 0x0C, \r
+0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0032 ('2'): (width=8, offset=270) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x06, 0x0C, \r
+0x18, 0x30, 0x60, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0033 ('3'): (width=8, offset=285) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x06, 0x1C, \r
+0x06, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0034 ('4'): (width=8, offset=300) */\r
+0x00, 0x00, 0x00, 0x30, 0x30, 0x36, 0x36, 0x36, \r
+0x66, 0x7F, 0x06, 0x06, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0035 ('5'): (width=8, offset=315) */\r
+0x00, 0x00, 0x00, 0x7E, 0x60, 0x60, 0x60, 0x7C, \r
+0x06, 0x06, 0x0C, 0x78, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0036 ('6'): (width=8, offset=330) */\r
+0x00, 0x00, 0x00, 0x1C, 0x18, 0x30, 0x7C, 0x66, \r
+0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0037 ('7'): (width=8, offset=345) */\r
+0x00, 0x00, 0x00, 0x7E, 0x06, 0x0C, 0x0C, 0x18, \r
+0x18, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0038 ('8'): (width=8, offset=360) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x76, 0x3C, \r
+0x6E, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0039 ('9'): (width=8, offset=375) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, \r
+0x3E, 0x0C, 0x18, 0x38, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x003A (':'): (width=8, offset=390) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x00, \r
+0x00, 0x00, 0x1C, 0x1C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x003B (';'): (width=8, offset=405) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x00, \r
+0x00, 0x00, 0x1C, 0x1C, 0x0C, 0x18, 0x00, \r
+\r
+/* character 0x003C ('<'): (width=8, offset=420) */\r
+0x00, 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, \r
+0x30, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x003D ('='): (width=8, offset=435) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, \r
+0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x003E ('>'): (width=8, offset=450) */\r
+0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, \r
+0x0C, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x003F ('?'): (width=8, offset=465) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x0C, 0x18, \r
+0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0040 ('@'): (width=8, offset=480) */\r
+0x00, 0x00, 0x00, 0x7E, 0xC3, 0xC3, 0xCF, 0xDB, \r
+0xDB, 0xCF, 0xC0, 0x7F, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0041 ('A'): (width=8, offset=495) */\r
+0x00, 0x00, 0x00, 0x18, 0x3C, 0x66, 0x66, 0x66, \r
+0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0042 ('B'): (width=8, offset=510) */\r
+0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, \r
+0x66, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0043 ('C'): (width=8, offset=525) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x60, 0x60, \r
+0x60, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0044 ('D'): (width=8, offset=540) */\r
+0x00, 0x00, 0x00, 0x78, 0x6C, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x6C, 0x78, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0045 ('E'): (width=8, offset=555) */\r
+0x00, 0x00, 0x00, 0x7E, 0x60, 0x60, 0x60, 0x7C, \r
+0x60, 0x60, 0x60, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0046 ('F'): (width=8, offset=570) */\r
+0x00, 0x00, 0x00, 0x7E, 0x60, 0x60, 0x60, 0x7C, \r
+0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0047 ('G'): (width=8, offset=585) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x60, 0x60, \r
+0x6E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0048 ('H'): (width=8, offset=600) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7E, \r
+0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0049 ('I'): (width=8, offset=615) */\r
+0x00, 0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, \r
+0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x004A ('J'): (width=8, offset=630) */\r
+0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, \r
+0x06, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x004B ('K'): (width=8, offset=645) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x6C, 0x6C, 0x78, \r
+0x6C, 0x6C, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x004C ('L'): (width=8, offset=660) */\r
+0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, \r
+0x60, 0x60, 0x60, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x004D ('M'): (width=8, offset=675) */\r
+0x00, 0x00, 0x00, 0x63, 0x63, 0x77, 0x6B, 0x6B, \r
+0x6B, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x004E ('N'): (width=8, offset=690) */\r
+0x00, 0x00, 0x00, 0x63, 0x63, 0x73, 0x7B, 0x6F, \r
+0x67, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x004F ('O'): (width=8, offset=705) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0050 ('P'): (width=8, offset=720) */\r
+0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, \r
+0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0051 ('Q'): (width=8, offset=735) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3C, 0x0C, 0x06, 0x00, \r
+\r
+/* character 0x0052 ('R'): (width=8, offset=750) */\r
+0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, \r
+0x6C, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0053 ('S'): (width=8, offset=765) */\r
+0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x30, 0x18, \r
+0x0C, 0x06, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0054 ('T'): (width=8, offset=780) */\r
+0x00, 0x00, 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, \r
+0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0055 ('U'): (width=8, offset=795) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0056 ('V'): (width=8, offset=810) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0057 ('W'): (width=8, offset=825) */\r
+0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x6B, 0x6B, \r
+0x6B, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0058 ('X'): (width=8, offset=840) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x34, 0x18, 0x18, \r
+0x2C, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0059 ('Y'): (width=8, offset=855) */\r
+0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, \r
+0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x005A ('Z'): (width=8, offset=870) */\r
+0x00, 0x00, 0x00, 0x7E, 0x06, 0x06, 0x0C, 0x18, \r
+0x30, 0x60, 0x60, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x005B ('['): (width=8, offset=885) */\r
+0x00, 0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, \r
+0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, \r
+\r
+/* character 0x005C ('\'): (width=8, offset=900) */\r
+0x00, 0x00, 0x00, 0x60, 0x60, 0x30, 0x30, 0x18, \r
+0x18, 0x0C, 0x0C, 0x06, 0x06, 0x00, 0x00, \r
+\r
+/* character 0x005D (']'): (width=8, offset=915) */\r
+0x00, 0x00, 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, \r
+0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, \r
+\r
+/* character 0x005E ('^'): (width=8, offset=930) */\r
+0x00, 0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x005F ('_'): (width=8, offset=945) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, \r
+\r
+/* character 0x0060 ('`'): (width=8, offset=960) */\r
+0x00, 0x38, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0061 ('a'): (width=8, offset=975) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x06, 0x06, \r
+0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0062 ('b'): (width=8, offset=990) */\r
+0x00, 0x00, 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0063 ('c'): (width=8, offset=1005) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, \r
+0x60, 0x60, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0064 ('d'): (width=8, offset=1020) */\r
+0x00, 0x00, 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0065 ('e'): (width=8, offset=1035) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, \r
+0x7E, 0x60, 0x60, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0066 ('f'): (width=8, offset=1050) */\r
+0x00, 0x00, 0x00, 0x1E, 0x30, 0x30, 0x30, 0x7E, \r
+0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0067 ('g'): (width=8, offset=1065) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x7C, \r
+\r
+/* character 0x0068 ('h'): (width=8, offset=1080) */\r
+0x00, 0x00, 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0069 ('i'): (width=8, offset=1095) */\r
+0x00, 0x00, 0x18, 0x18, 0x00, 0x78, 0x18, 0x18, \r
+0x18, 0x18, 0x18, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x006A ('j'): (width=8, offset=1110) */\r
+0x00, 0x00, 0x0C, 0x0C, 0x00, 0x3C, 0x0C, 0x0C, \r
+0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x78, \r
+\r
+/* character 0x006B ('k'): (width=8, offset=1125) */\r
+0x00, 0x00, 0x00, 0x60, 0x60, 0x66, 0x66, 0x6C, \r
+0x78, 0x6C, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x006C ('l'): (width=8, offset=1140) */\r
+0x00, 0x00, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, \r
+0x18, 0x18, 0x18, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x006D ('m'): (width=8, offset=1155) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x6B, 0x6B, \r
+0x6B, 0x6B, 0x6B, 0x63, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x006E ('n'): (width=8, offset=1170) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x006F ('o'): (width=8, offset=1185) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0070 ('p'): (width=8, offset=1200) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, \r
+\r
+/* character 0x0071 ('q'): (width=8, offset=1215) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x06, \r
+\r
+/* character 0x0072 ('r'): (width=8, offset=1230) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x6E, 0x70, \r
+0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0073 ('s'): (width=8, offset=1245) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x60, 0x60, \r
+0x3C, 0x06, 0x06, 0x7C, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0074 ('t'): (width=8, offset=1260) */\r
+0x00, 0x00, 0x00, 0x30, 0x30, 0x7E, 0x30, 0x30, \r
+0x30, 0x30, 0x30, 0x1E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0075 ('u'): (width=8, offset=1275) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0076 ('v'): (width=8, offset=1290) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0077 ('w'): (width=8, offset=1305) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6B, 0x6B, \r
+0x6B, 0x6B, 0x36, 0x36, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0078 ('x'): (width=8, offset=1320) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, \r
+0x18, 0x3C, 0x66, 0x66, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x0079 ('y'): (width=8, offset=1335) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, \r
+0x66, 0x66, 0x66, 0x3C, 0x0C, 0x18, 0xF0, \r
+\r
+/* character 0x007A ('z'): (width=8, offset=1350) */\r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x06, 0x0C, \r
+0x18, 0x30, 0x60, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x007B ('{'): (width=8, offset=1365) */\r
+0x00, 0x00, 0x00, 0x0C, 0x18, 0x18, 0x18, 0x30, \r
+0x60, 0x30, 0x18, 0x18, 0x18, 0x0C, 0x00, \r
+\r
+/* character 0x007C ('|'): (width=8, offset=1380) */\r
+0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, \r
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, \r
+\r
+/* character 0x007D ('}'): (width=8, offset=1395) */\r
+0x00, 0x00, 0x00, 0x30, 0x18, 0x18, 0x18, 0x0C, \r
+0x06, 0x0C, 0x18, 0x18, 0x18, 0x30, 0x00, \r
+\r
+/* character 0x007E ('~'): (width=8, offset=1410) */\r
+0x00, 0x00, 0x00, 0x71, 0xDB, 0x8E, 0x00, 0x00, \r
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+\r
+/* character 0x007F ('\7f'): (width=8, offset=1425) */\r
+0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, \r
+0x7E, 0x7E, 0x7E, 0x7E, 0x00, 0x00, 0x00, \r
+\r
+};\r
+\r
+\r
+/*******************************************************************************************\r
+ Index table is used to find the mapping index of a character.\r
+\r
+ If you can find a simple mathematical expression for index mapping, you can use that.\r
+ If you do not have such a mathematical expression, this index table is just for you.\r
+\r
+ To get the index of character 'A', you can use the following expression:\r
+\r
+ const unsigned char index = index_table['A'];\r
+\r
+ *******************************************************************************************/\r
+const unsigned char font_index_table[] = {\r
+/* index hexcode decimal char */\r
+/* ===== ======= ======= ==== */\r
+ 0, /* 00 0 . */\r
+ 0, /* 01 1 . */\r
+ 0, /* 02 2 . */\r
+ 0, /* 03 3 . */\r
+ 0, /* 04 4 . */\r
+ 0, /* 05 5 . */\r
+ 0, /* 06 6 . */\r
+ 0, /* 07 7 . */\r
+ 0, /* 08 8 . */\r
+ 0, /* 09 9 . */\r
+ 0, /* 0A 10 . */\r
+ 0, /* 0B 11 . */\r
+ 0, /* 0C 12 . */\r
+ 0, /* 0D 13 . */\r
+ 0, /* 0E 14 . */\r
+ 0, /* 0F 15 . */\r
+ 0, /* 10 16 . */\r
+ 0, /* 11 17 . */\r
+ 0, /* 12 18 . */\r
+ 0, /* 13 19 . */\r
+ 0, /* 14 20 . */\r
+ 0, /* 15 21 . */\r
+ 0, /* 16 22 . */\r
+ 0, /* 17 23 . */\r
+ 0, /* 18 24 . */\r
+ 0, /* 19 25 . */\r
+ 0, /* 1A 26 . */\r
+ 0, /* 1B 27 . */\r
+ 0, /* 1C 28 . */\r
+ 0, /* 1D 29 . */\r
+ 0, /* 1E 30 . */\r
+ 0, /* 1F 31 . */\r
+ 0, /* 20 32 */\r
+ 1, /* 21 33 ! */\r
+ 2, /* 22 34 " */\r
+ 3, /* 23 35 # */\r
+ 4, /* 24 36 $ */\r
+ 5, /* 25 37 % */\r
+ 6, /* 26 38 & */\r
+ 7, /* 27 39 ' */\r
+ 8, /* 28 40 ( */\r
+ 9, /* 29 41 ) */\r
+ 10, /* 2A 42 * */\r
+ 11, /* 2B 43 + */\r
+ 12, /* 2C 44 , */\r
+ 13, /* 2D 45 - */\r
+ 14, /* 2E 46 . */\r
+ 15, /* 2F 47 / */\r
+ 16, /* 30 48 0 */\r
+ 17, /* 31 49 1 */\r
+ 18, /* 32 50 2 */\r
+ 19, /* 33 51 3 */\r
+ 20, /* 34 52 4 */\r
+ 21, /* 35 53 5 */\r
+ 22, /* 36 54 6 */\r
+ 23, /* 37 55 7 */\r
+ 24, /* 38 56 8 */\r
+ 25, /* 39 57 9 */\r
+ 26, /* 3A 58 : */\r
+ 27, /* 3B 59 ; */\r
+ 28, /* 3C 60 < */\r
+ 29, /* 3D 61 = */\r
+ 30, /* 3E 62 > */\r
+ 31, /* 3F 63 ? */\r
+ 32, /* 40 64 @ */\r
+ 33, /* 41 65 A */\r
+ 34, /* 42 66 B */\r
+ 35, /* 43 67 C */\r
+ 36, /* 44 68 D */\r
+ 37, /* 45 69 E */\r
+ 38, /* 46 70 F */\r
+ 39, /* 47 71 G */\r
+ 40, /* 48 72 H */\r
+ 41, /* 49 73 I */\r
+ 42, /* 4A 74 J */\r
+ 43, /* 4B 75 K */\r
+ 44, /* 4C 76 L */\r
+ 45, /* 4D 77 M */\r
+ 46, /* 4E 78 N */\r
+ 47, /* 4F 79 O */\r
+ 48, /* 50 80 P */\r
+ 49, /* 51 81 Q */\r
+ 50, /* 52 82 R */\r
+ 51, /* 53 83 S */\r
+ 52, /* 54 84 T */\r
+ 53, /* 55 85 U */\r
+ 54, /* 56 86 V */\r
+ 55, /* 57 87 W */\r
+ 56, /* 58 88 X */\r
+ 57, /* 59 89 Y */\r
+ 58, /* 5A 90 Z */\r
+ 59, /* 5B 91 [ */\r
+ 60, /* 5C 92 \ */\r
+ 61, /* 5D 93 ] */\r
+ 62, /* 5E 94 ^ */\r
+ 63, /* 5F 95 _ */\r
+ 64, /* 60 96 ` */\r
+ 65, /* 61 97 a */\r
+ 66, /* 62 98 b */\r
+ 67, /* 63 99 c */\r
+ 68, /* 64 100 d */\r
+ 69, /* 65 101 e */\r
+ 70, /* 66 102 f */\r
+ 71, /* 67 103 g */\r
+ 72, /* 68 104 h */\r
+ 73, /* 69 105 i */\r
+ 74, /* 6A 106 j */\r
+ 75, /* 6B 107 k */\r
+ 76, /* 6C 108 l */\r
+ 77, /* 6D 109 m */\r
+ 78, /* 6E 110 n */\r
+ 79, /* 6F 111 o */\r
+ 80, /* 70 112 p */\r
+ 81, /* 71 113 q */\r
+ 82, /* 72 114 r */\r
+ 83, /* 73 115 s */\r
+ 84, /* 74 116 t */\r
+ 85, /* 75 117 u */\r
+ 86, /* 76 118 v */\r
+ 87, /* 77 119 w */\r
+ 88, /* 78 120 x */\r
+ 89, /* 79 121 y */\r
+ 90, /* 7A 122 z */\r
+ 91, /* 7B 123 { */\r
+ 92, /* 7C 124 | */\r
+ 93, /* 7D 125 } */\r
+ 94, /* 7E 126 ~ */\r
+ 95, /* 7F 127 \7f */\r
+ 0, /* 80 128 ? */\r
+ 0, /* 81 129 � */\r
+ 0, /* 82 130 ? */\r
+ 0, /* 83 131 ? */\r
+ 0, /* 84 132 ? */\r
+ 0, /* 85 133 ? */\r
+ 0, /* 86 134 ? */\r
+ 0, /* 87 135 ? */\r
+ 0, /* 88 136 ? */\r
+ 0, /* 89 137 ? */\r
+ 0, /* 8A 138 ? */\r
+ 0, /* 8B 139 ? */\r
+ 0, /* 8C 140 ? */\r
+ 0, /* 8D 141 � */\r
+ 0, /* 8E 142 ? */\r
+ 0, /* 8F 143 � */\r
+ 0, /* 90 144 � */\r
+ 0, /* 91 145 ? */\r
+ 0, /* 92 146 ? */\r
+ 0, /* 93 147 ? */\r
+ 0, /* 94 148 ? */\r
+ 0, /* 95 149 ? */\r
+ 0, /* 96 150 ? */\r
+ 0, /* 97 151 ? */\r
+ 0, /* 98 152 ? */\r
+ 0, /* 99 153 ? */\r
+ 0, /* 9A 154 ? */\r
+ 0, /* 9B 155 ? */\r
+ 0, /* 9C 156 ? */\r
+ 0, /* 9D 157 � */\r
+ 0, /* 9E 158 ? */\r
+ 0, /* 9F 159 ? */\r
+ 0, /* A0 160 � */\r
+ 0, /* A1 161 � */\r
+ 0, /* A2 162 � */\r
+ 0, /* A3 163 � */\r
+ 0, /* A4 164 � */\r
+ 0, /* A5 165 � */\r
+ 0, /* A6 166 � */\r
+ 0, /* A7 167 � */\r
+ 0, /* A8 168 � */\r
+ 0, /* A9 169 � */\r
+ 0, /* AA 170 � */\r
+ 0, /* AB 171 � */\r
+ 0, /* AC 172 � */\r
+ 0, /* AD 173 � */\r
+ 0, /* AE 174 � */\r
+ 0, /* AF 175 � */\r
+ 0, /* B0 176 � */\r
+ 0, /* B1 177 � */\r
+ 0, /* B2 178 � */\r
+ 0, /* B3 179 � */\r
+ 0, /* B4 180 � */\r
+ 0, /* B5 181 � */\r
+ 0, /* B6 182 � */\r
+ 0, /* B7 183 � */\r
+ 0, /* B8 184 � */\r
+ 0, /* B9 185 � */\r
+ 0, /* BA 186 � */\r
+ 0, /* BB 187 � */\r
+ 0, /* BC 188 � */\r
+ 0, /* BD 189 � */\r
+ 0, /* BE 190 � */\r
+ 0, /* BF 191 � */\r
+ 0, /* C0 192 � */\r
+ 0, /* C1 193 � */\r
+ 0, /* C2 194 � */\r
+ 0, /* C3 195 � */\r
+ 0, /* C4 196 � */\r
+ 0, /* C5 197 � */\r
+ 0, /* C6 198 � */\r
+ 0, /* C7 199 � */\r
+ 0, /* C8 200 � */\r
+ 0, /* C9 201 � */\r
+ 0, /* CA 202 � */\r
+ 0, /* CB 203 � */\r
+ 0, /* CC 204 � */\r
+ 0, /* CD 205 � */\r
+ 0, /* CE 206 � */\r
+ 0, /* CF 207 � */\r
+ 0, /* D0 208 � */\r
+ 0, /* D1 209 � */\r
+ 0, /* D2 210 � */\r
+ 0, /* D3 211 � */\r
+ 0, /* D4 212 � */\r
+ 0, /* D5 213 � */\r
+ 0, /* D6 214 � */\r
+ 0, /* D7 215 � */\r
+ 0, /* D8 216 � */\r
+ 0, /* D9 217 � */\r
+ 0, /* DA 218 � */\r
+ 0, /* DB 219 � */\r
+ 0, /* DC 220 � */\r
+ 0, /* DD 221 � */\r
+ 0, /* DE 222 � */\r
+ 0, /* DF 223 � */\r
+ 0, /* E0 224 � */\r
+ 0, /* E1 225 � */\r
+ 0, /* E2 226 � */\r
+ 0, /* E3 227 � */\r
+ 0, /* E4 228 � */\r
+ 0, /* E5 229 � */\r
+ 0, /* E6 230 � */\r
+ 0, /* E7 231 � */\r
+ 0, /* E8 232 � */\r
+ 0, /* E9 233 � */\r
+ 0, /* EA 234 � */\r
+ 0, /* EB 235 � */\r
+ 0, /* EC 236 � */\r
+ 0, /* ED 237 � */\r
+ 0, /* EE 238 � */\r
+ 0, /* EF 239 � */\r
+ 0, /* F0 240 � */\r
+ 0, /* F1 241 � */\r
+ 0, /* F2 242 � */\r
+ 0, /* F3 243 � */\r
+ 0, /* F4 244 � */\r
+ 0, /* F5 245 � */\r
+ 0, /* F6 246 � */\r
+ 0, /* F7 247 � */\r
+ 0, /* F8 248 � */\r
+ 0, /* F9 249 � */\r
+ 0, /* FA 250 � */\r
+ 0, /* FB 251 � */\r
+ 0, /* FC 252 � */\r
+ 0, /* FD 253 � */\r
+ 0, /* FE 254 � */\r
+ 0, /* FF 255 � */\r
+};\r
+\r
+\r
+\r
--- /dev/null
+#ifndef __LPC17xx_H\r
+#define __LPC17xx_H\r
+\r
+/* System Control Block (SCB) includes:\r
+ Flash Accelerator Module, Clocking and Power Control, External Interrupts,\r
+ Reset, System Control and Status\r
+*/\r
+#define SCB_BASE_ADDR 0x400FC000\r
+\r
+#define PCONP_PCTIM0 0x00000002\r
+#define PCONP_PCTIM1 0x00000004\r
+#define PCONP_PCUART0 0x00000008\r
+#define PCONP_PCUART1 0x00000010\r
+#define PCONP_PCPWM1 0x00000040\r
+#define PCONP_PCI2C0 0x00000080\r
+#define PCONP_PCSPI 0x00000100\r
+#define PCONP_PCRTC 0x00000200\r
+#define PCONP_PCSSP1 0x00000400\r
+#define PCONP_PCAD 0x00001000\r
+#define PCONP_PCCAN1 0x00002000\r
+#define PCONP_PCCAN2 0x00004000\r
+#define PCONP_PCGPIO 0x00008000\r
+#define PCONP_PCRIT 0x00010000\r
+#define PCONP_PCMCPWM 0x00020000\r
+#define PCONP_PCQEI 0x00040000\r
+#define PCONP_PCI2C1 0x00080000\r
+#define PCONP_PCSSP0 0x00200000\r
+#define PCONP_PCTIM2 0x00400000\r
+#define PCONP_PCTIM3 0x00800000\r
+#define PCONP_PCUART2 0x01000000\r
+#define PCONP_PCUART3 0x02000000\r
+#define PCONP_PCI2C2 0x04000000\r
+#define PCONP_PCI2S 0x08000000\r
+#define PCONP_PCGPDMA 0x20000000\r
+#define PCONP_PCENET 0x40000000\r
+#define PCONP_PCUSB 0x80000000\r
+\r
+#define PLLCON_PLLE 0x00000001\r
+#define PLLCON_PLLC 0x00000002\r
+#define PLLCON_MASK 0x00000003\r
+\r
+#define PLLCFG_MUL1 0x00000000\r
+#define PLLCFG_MUL2 0x00000001\r
+#define PLLCFG_MUL3 0x00000002\r
+#define PLLCFG_MUL4 0x00000003\r
+#define PLLCFG_MUL5 0x00000004\r
+#define PLLCFG_MUL6 0x00000005\r
+#define PLLCFG_MUL7 0x00000006\r
+#define PLLCFG_MUL8 0x00000007\r
+#define PLLCFG_MUL9 0x00000008\r
+#define PLLCFG_MUL10 0x00000009\r
+#define PLLCFG_MUL11 0x0000000A\r
+#define PLLCFG_MUL12 0x0000000B\r
+#define PLLCFG_MUL13 0x0000000C\r
+#define PLLCFG_MUL14 0x0000000D\r
+#define PLLCFG_MUL15 0x0000000E\r
+#define PLLCFG_MUL16 0x0000000F\r
+#define PLLCFG_MUL17 0x00000010\r
+#define PLLCFG_MUL18 0x00000011\r
+#define PLLCFG_MUL19 0x00000012\r
+#define PLLCFG_MUL20 0x00000013\r
+#define PLLCFG_MUL21 0x00000014\r
+#define PLLCFG_MUL22 0x00000015\r
+#define PLLCFG_MUL23 0x00000016\r
+#define PLLCFG_MUL24 0x00000017\r
+#define PLLCFG_MUL25 0x00000018\r
+#define PLLCFG_MUL26 0x00000019\r
+#define PLLCFG_MUL27 0x0000001A\r
+#define PLLCFG_MUL28 0x0000001B\r
+#define PLLCFG_MUL29 0x0000001C\r
+#define PLLCFG_MUL30 0x0000001D\r
+#define PLLCFG_MUL31 0x0000001E\r
+#define PLLCFG_MUL32 0x0000001F\r
+#define PLLCFG_MUL33 0x00000020\r
+#define PLLCFG_MUL34 0x00000021\r
+#define PLLCFG_MUL35 0x00000022\r
+#define PLLCFG_MUL36 0x00000023\r
+\r
+#define PLLCFG_DIV1 0x00000000\r
+#define PLLCFG_DIV2 0x00010000\r
+#define PLLCFG_DIV3 0x00020000\r
+#define PLLCFG_DIV4 0x00030000\r
+#define PLLCFG_DIV5 0x00040000\r
+#define PLLCFG_DIV6 0x00050000\r
+#define PLLCFG_DIV7 0x00060000\r
+#define PLLCFG_DIV8 0x00070000\r
+#define PLLCFG_DIV9 0x00080000\r
+#define PLLCFG_DIV10 0x00090000\r
+#define PLLCFG_MASK 0x00FF7FFF\r
+\r
+#define PLLSTAT_MSEL_MASK 0x00007FFF\r
+#define PLLSTAT_NSEL_MASK 0x00FF0000\r
+\r
+#define PLLSTAT_PLLE (1 << 24)\r
+#define PLLSTAT_PLLC (1 << 25)\r
+#define PLLSTAT_PLOCK (1 << 26)\r
+\r
+#define PLLFEED_FEED1 0x000000AA\r
+#define PLLFEED_FEED2 0x00000055\r
+\r
+#define NVIC_IRQ_WDT 0u // IRQ0, exception number 16\r
+#define NVIC_IRQ_TIMER0 1u // IRQ1, exception number 17\r
+#define NVIC_IRQ_TIMER1 2u // IRQ2, exception number 18\r
+#define NVIC_IRQ_TIMER2 3u // IRQ3, exception number 19\r
+#define NVIC_IRQ_TIMER3 4u // IRQ4, exception number 20\r
+#define NVIC_IRQ_UART0 5u // IRQ5, exception number 21\r
+#define NVIC_IRQ_UART1 6u // IRQ6, exception number 22\r
+#define NVIC_IRQ_UART2 7u // IRQ7, exception number 23\r
+#define NVIC_IRQ_UART3 8u // IRQ8, exception number 24\r
+#define NVIC_IRQ_PWM1 9u // IRQ9, exception number 25\r
+#define NVIC_IRQ_I2C0 10u // IRQ10, exception number 26\r
+#define NVIC_IRQ_I2C1 11u // IRQ11, exception number 27\r
+#define NVIC_IRQ_I2C2 12u // IRQ12, exception number 28\r
+#define NVIC_IRQ_SPI 13u // IRQ13, exception number 29\r
+#define NVIC_IRQ_SSP0 14u // IRQ14, exception number 30\r
+#define NVIC_IRQ_SSP1 15u // IRQ15, exception number 31\r
+#define NVIC_IRQ_PLL0 16u // IRQ16, exception number 32\r
+#define NVIC_IRQ_RTC 17u // IRQ17, exception number 33\r
+#define NVIC_IRQ_EINT0 18u // IRQ18, exception number 34\r
+#define NVIC_IRQ_EINT1 19u // IRQ19, exception number 35\r
+#define NVIC_IRQ_EINT2 20u // IRQ20, exception number 36\r
+#define NVIC_IRQ_EINT3 21u // IRQ21, exception number 37\r
+#define NVIC_IRQ_ADC 22u // IRQ22, exception number 38\r
+#define NVIC_IRQ_BOD 23u // IRQ23, exception number 39\r
+#define NVIC_IRQ_USB 24u // IRQ24, exception number 40\r
+#define NVIC_IRQ_CAN 25u // IRQ25, exception number 41\r
+#define NVIC_IRQ_GPDMA 26u // IRQ26, exception number 42\r
+#define NVIC_IRQ_I2S 27u // IRQ27, exception number 43\r
+#define NVIC_IRQ_ETHERNET 28u // IRQ28, exception number 44\r
+#define NVIC_IRQ_RIT 29u // IRQ29, exception number 45\r
+#define NVIC_IRQ_MCPWM 30u // IRQ30, exception number 46\r
+#define NVIC_IRQ_QE 31u // IRQ31, exception number 47\r
+#define NVIC_IRQ_PLL1 32u // IRQ32, exception number 48\r
+#define NVIC_IRQ_USB_ACT 33u // IRQ33, exception number 49\r
+#define NVIC_IRQ_CAN_ACT 34u // IRQ34, exception number 50\r
+\r
+\r
+#endif // __LPC17xx_H\r
+\r
+\r
+#ifndef CMSIS_17xx_H\r
+#define CMSIS_17xx_H\r
+\r
+/******************************************************************************\r
+ * @file: LPC17xx.h\r
+ * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Header File for\r
+ * NXP LPC17xx Device Series\r
+ * @version: V1.1\r
+ * @date: 14th May 2009\r
+ *----------------------------------------------------------------------------\r
+ *\r
+ * Copyright (C) 2008 ARM Limited. All rights reserved.\r
+ *\r
+ * ARM Limited (ARM) is supplying this software for use with Cortex-M3\r
+ * processor based microcontrollers. This file can be freely distributed\r
+ * within development tools that are supporting such ARM based processors.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
+ *\r
+ ******************************************************************************/\r
+\r
+\r
+#ifndef __LPC17xx_H__\r
+#define __LPC17xx_H__\r
+\r
+/*\r
+ * ==========================================================================\r
+ * ---------- Interrupt Number Definition -----------------------------------\r
+ * ==========================================================================\r
+ */\r
+\r
+typedef enum IRQn\r
+{\r
+/****** Cortex-M3 Processor Exceptions Numbers ***************************************************/\r
+ NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */\r
+ MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */\r
+ BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */\r
+ UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */\r
+ SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */\r
+ DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */\r
+ PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */\r
+ SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */\r
+\r
+/****** LPC17xx Specific Interrupt Numbers *******************************************************/\r
+ WDT_IRQn = 0, /*!< Watchdog Timer Interrupt */\r
+ TIMER0_IRQn = 1, /*!< Timer0 Interrupt */\r
+ TIMER1_IRQn = 2, /*!< Timer1 Interrupt */\r
+ TIMER2_IRQn = 3, /*!< Timer2 Interrupt */\r
+ TIMER3_IRQn = 4, /*!< Timer3 Interrupt */\r
+ UART0_IRQn = 5, /*!< UART0 Interrupt */\r
+ UART1_IRQn = 6, /*!< UART1 Interrupt */\r
+ UART2_IRQn = 7, /*!< UART2 Interrupt */\r
+ UART3_IRQn = 8, /*!< UART3 Interrupt */\r
+ PWM1_IRQn = 9, /*!< PWM1 Interrupt */\r
+ I2C0_IRQn = 10, /*!< I2C0 Interrupt */\r
+ I2C1_IRQn = 11, /*!< I2C1 Interrupt */\r
+ I2C2_IRQn = 12, /*!< I2C2 Interrupt */\r
+ SPI_IRQn = 13, /*!< SPI Interrupt */\r
+ SSP0_IRQn = 14, /*!< SSP0 Interrupt */\r
+ SSP1_IRQn = 15, /*!< SSP1 Interrupt */\r
+ PLL0_IRQn = 16, /*!< PLL0 Lock (Main PLL) Interrupt */\r
+ RTC_IRQn = 17, /*!< Real Time Clock Interrupt */\r
+ EINT0_IRQn = 18, /*!< External Interrupt 0 Interrupt */\r
+ EINT1_IRQn = 19, /*!< External Interrupt 1 Interrupt */\r
+ EINT2_IRQn = 20, /*!< External Interrupt 2 Interrupt */\r
+ EINT3_IRQn = 21, /*!< External Interrupt 3 Interrupt */\r
+ ADC_IRQn = 22, /*!< A/D Converter Interrupt */\r
+ BOD_IRQn = 23, /*!< Brown-Out Detect Interrupt */\r
+ USB_IRQn = 24, /*!< USB Interrupt */\r
+ CAN_IRQn = 25, /*!< CAN Interrupt */\r
+ DMA_IRQn = 26, /*!< General Purpose DMA Interrupt */\r
+ I2S_IRQn = 27, /*!< I2S Interrupt */\r
+ ENET_IRQn = 28, /*!< Ethernet Interrupt */\r
+ RIT_IRQn = 29, /*!< Repetitive Interrupt Timer Interrupt */\r
+ MCPWM_IRQn = 30, /*!< Motor Control PWM Interrupt */\r
+ QEI_IRQn = 31, /*!< Quadrature Encoder Interface Interrupt */\r
+ PLL1_IRQn = 32, /*!< PLL1 Lock (USB PLL) Interrupt */\r
+} IRQn_Type;\r
+\r
+\r
+/*\r
+ * ==========================================================================\r
+ * ----------- Processor and Core Peripheral Section ------------------------\r
+ * ==========================================================================\r
+ */\r
+\r
+/* Configuration of the Cortex-M3 Processor and Core Peripherals */\r
+#define __MPU_PRESENT 1 /*!< MPU present or not */\r
+#define __NVIC_PRIO_BITS 5 /*!< Number of Bits used for Priority Levels */\r
+#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */\r
+\r
+\r
+//#include "..\core_cm3.h" /* Cortex-M3 processor and core peripherals */\r
+#include "core_cm3.h"\r
+#include "system_LPC17xx.h" /* System Header */\r
+\r
+\r
+\r
+/**\r
+ * Initialize the system clock\r
+ *\r
+ * @param none\r
+ * @return none\r
+ *\r
+ * @brief Setup the microcontroller system.\r
+ * Initialize the System and update the SystemFrequency variable.\r
+ */\r
+extern void SystemInit (void);\r
+\r
+\r
+/******************************************************************************/\r
+/* Device Specific Peripheral registers structures */\r
+/******************************************************************************/\r
+\r
+/*------------- System Control (SC) ------------------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t FLASHCFG; /* Flash Accelerator Module */\r
+ uint32_t RESERVED0[31];\r
+ __IO uint32_t PLL0CON; /* Clocking and Power Control */\r
+ __IO uint32_t PLL0CFG;\r
+ __I uint32_t PLL0STAT;\r
+ __O uint32_t PLL0FEED;\r
+ uint32_t RESERVED1[4];\r
+ __IO uint32_t PLL1CON;\r
+ __IO uint32_t PLL1CFG;\r
+ __I uint32_t PLL1STAT;\r
+ __O uint32_t PLL1FEED;\r
+ uint32_t RESERVED2[4];\r
+ __IO uint32_t PCON;\r
+ __IO uint32_t PCONP;\r
+ uint32_t RESERVED3[15];\r
+ __IO uint32_t CCLKCFG;\r
+ __IO uint32_t USBCLKCFG;\r
+ __IO uint32_t CLKSRCSEL;\r
+ uint32_t RESERVED4[12];\r
+ __IO uint32_t EXTINT; /* External Interrupts */\r
+ uint32_t RESERVED5;\r
+ __IO uint32_t EXTMODE;\r
+ __IO uint32_t EXTPOLAR;\r
+ uint32_t RESERVED6[12];\r
+ __IO uint32_t RSID; /* Reset */\r
+ uint32_t RESERVED7[7];\r
+ __IO uint32_t SCS; /* Syscon Miscellaneous Registers */\r
+ __IO uint32_t IRCTRIM; /* Clock Dividers */\r
+ __IO uint32_t PCLKSEL0;\r
+ __IO uint32_t PCLKSEL1;\r
+ uint32_t RESERVED8[4];\r
+ __IO uint32_t USBIntSt; /* USB Device/OTG Interrupt Register */\r
+ uint32_t RESERVED9;\r
+ __IO uint32_t CLKOUTCFG; /* Clock Output Configuration */\r
+ } SC_TypeDef;\r
+\r
+/*------------- Pin Connect Block (PINCON) -----------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t PINSEL0;\r
+ __IO uint32_t PINSEL1;\r
+ __IO uint32_t PINSEL2;\r
+ __IO uint32_t PINSEL3;\r
+ __IO uint32_t PINSEL4;\r
+ __IO uint32_t PINSEL5;\r
+ __IO uint32_t PINSEL6;\r
+ __IO uint32_t PINSEL7;\r
+ __IO uint32_t PINSEL8;\r
+ __IO uint32_t PINSEL9;\r
+ __IO uint32_t PINSEL10;\r
+ uint32_t RESERVED0[5];\r
+ __IO uint32_t PINMODE0;\r
+ __IO uint32_t PINMODE1;\r
+ __IO uint32_t PINMODE2;\r
+ __IO uint32_t PINMODE3;\r
+ __IO uint32_t PINMODE4;\r
+ __IO uint32_t PINMODE5;\r
+ __IO uint32_t PINMODE6;\r
+ __IO uint32_t PINMODE7;\r
+ __IO uint32_t PINMODE8;\r
+ __IO uint32_t PINMODE9;\r
+ __IO uint32_t PINMODE_OD0;\r
+ __IO uint32_t PINMODE_OD1;\r
+ __IO uint32_t PINMODE_OD2;\r
+ __IO uint32_t PINMODE_OD3;\r
+ __IO uint32_t PINMODE_OD4;\r
+} PINCON_TypeDef;\r
+\r
+/*------------- General Purpose Input/Output (GPIO) --------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t FIODIR;\r
+ uint32_t RESERVED0[3];\r
+ __IO uint32_t FIOMASK;\r
+ __IO uint32_t FIOPIN;\r
+ __IO uint32_t FIOSET;\r
+ __O uint32_t FIOCLR;\r
+} GPIO_TypeDef;\r
+\r
+typedef struct\r
+{\r
+ __I uint32_t IntStatus;\r
+ __I uint32_t IO0IntStatR;\r
+ __I uint32_t IO0IntStatF;\r
+ __O uint32_t IO0IntClr;\r
+ __IO uint32_t IO0IntEnR;\r
+ __IO uint32_t IO0IntEnF;\r
+ uint32_t RESERVED0[3];\r
+ __I uint32_t IO2IntStatR;\r
+ __I uint32_t IO2IntStatF;\r
+ __O uint32_t IO2IntClr;\r
+ __IO uint32_t IO2IntEnR;\r
+ __IO uint32_t IO2IntEnF;\r
+} GPIOINT_TypeDef;\r
+\r
+/*------------- Timer (TIM) --------------------------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t IR;\r
+ __IO uint32_t TCR;\r
+ __IO uint32_t TC;\r
+ __IO uint32_t PR;\r
+ __IO uint32_t PC;\r
+ __IO uint32_t MCR;\r
+ __IO uint32_t MR0;\r
+ __IO uint32_t MR1;\r
+ __IO uint32_t MR2;\r
+ __IO uint32_t MR3;\r
+ __IO uint32_t CCR;\r
+ __I uint32_t CR0;\r
+ __I uint32_t CR1;\r
+ uint32_t RESERVED0[2];\r
+ __IO uint32_t EMR;\r
+ uint32_t RESERVED1[24];\r
+ __IO uint32_t CTCR;\r
+} TIM_TypeDef;\r
+\r
+/*------------- Pulse-Width Modulation (PWM) ---------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t IR;\r
+ __IO uint32_t TCR;\r
+ __IO uint32_t TC;\r
+ __IO uint32_t PR;\r
+ __IO uint32_t PC;\r
+ __IO uint32_t MCR;\r
+ __IO uint32_t MR0;\r
+ __IO uint32_t MR1;\r
+ __IO uint32_t MR2;\r
+ __IO uint32_t MR3;\r
+ __IO uint32_t CCR;\r
+ __I uint32_t CR0;\r
+ __I uint32_t CR1;\r
+ __I uint32_t CR2;\r
+ __I uint32_t CR3;\r
+ __IO uint32_t MR4;\r
+ __IO uint32_t MR5;\r
+ __IO uint32_t MR6;\r
+ __IO uint32_t PCR;\r
+ __IO uint32_t LER;\r
+ uint32_t RESERVED0[7];\r
+ __IO uint32_t CTCR;\r
+} PWM_TypeDef;\r
+\r
+/*------------- Universal Asynchronous Receiver Transmitter (UART) -----------*/\r
+typedef struct\r
+{\r
+ union {\r
+ __I uint8_t RBR;\r
+ __O uint8_t THR;\r
+ __IO uint8_t DLL;\r
+ uint32_t RESERVED0;\r
+ };\r
+ union {\r
+ __IO uint8_t DLM;\r
+ __IO uint32_t IER;\r
+ };\r
+ union {\r
+ __I uint32_t IIR;\r
+ __O uint8_t FCR;\r
+ };\r
+ __IO uint8_t LCR;\r
+ uint8_t RESERVED1[7];\r
+ __IO uint8_t LSR;\r
+ uint8_t RESERVED2[7];\r
+ __IO uint8_t SCR;\r
+ uint8_t RESERVED3[3];\r
+ __IO uint32_t ACR;\r
+ __IO uint8_t ICR;\r
+ uint8_t RESERVED4[3];\r
+ __IO uint8_t FDR;\r
+ uint8_t RESERVED5[7];\r
+ __IO uint8_t TER;\r
+ uint8_t RESERVED6[27];\r
+ __IO uint8_t RS485CTRL;\r
+ uint8_t RESERVED7[3];\r
+ __IO uint8_t ADRMATCH;\r
+} UART_TypeDef;\r
+\r
+typedef struct\r
+{\r
+ union {\r
+ __I uint8_t RBR;\r
+ __O uint8_t THR;\r
+ __IO uint8_t DLL;\r
+ uint32_t RESERVED0;\r
+ };\r
+ union {\r
+ __IO uint8_t DLM;\r
+ __IO uint32_t IER;\r
+ };\r
+ union {\r
+ __I uint32_t IIR;\r
+ __O uint8_t FCR;\r
+ };\r
+ __IO uint8_t LCR;\r
+ uint8_t RESERVED1[3];\r
+ __IO uint8_t MCR;\r
+ uint8_t RESERVED2[3];\r
+ __IO uint8_t LSR;\r
+ uint8_t RESERVED3[3];\r
+ __IO uint8_t MSR;\r
+ uint8_t RESERVED4[3];\r
+ __IO uint8_t SCR;\r
+ uint8_t RESERVED5[3];\r
+ __IO uint32_t ACR;\r
+ uint32_t RESERVED6;\r
+ __IO uint32_t FDR;\r
+ uint32_t RESERVED7;\r
+ __IO uint8_t TER;\r
+ uint8_t RESERVED8[27];\r
+ __IO uint8_t RS485CTRL;\r
+ uint8_t RESERVED9[3];\r
+ __IO uint8_t ADRMATCH;\r
+ uint8_t RESERVED10[3];\r
+ __IO uint8_t RS485DLY;\r
+} UART1_TypeDef;\r
+\r
+/*------------- Serial Peripheral Interface (SPI) ----------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t SPCR;\r
+ __I uint32_t SPSR;\r
+ __IO uint32_t SPDR;\r
+ __IO uint32_t SPCCR;\r
+ uint32_t RESERVED0[3];\r
+ __IO uint32_t SPINT;\r
+} SPI_TypeDef;\r
+\r
+/*------------- Synchronous Serial Communication (SSP) -----------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t CR0;\r
+ __IO uint32_t CR1;\r
+ __IO uint32_t DR;\r
+ __I uint32_t SR;\r
+ __IO uint32_t CPSR;\r
+ __IO uint32_t IMSC;\r
+ __IO uint32_t RIS;\r
+ __IO uint32_t MIS;\r
+ __IO uint32_t ICR;\r
+ __IO uint32_t DMACR;\r
+} SSP_TypeDef;\r
+\r
+/*------------- Inter-Integrated Circuit (I2C) -------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t I2CONSET;\r
+ __I uint32_t I2STAT;\r
+ __IO uint32_t I2DAT;\r
+ __IO uint32_t I2ADR0;\r
+ __IO uint32_t I2SCLH;\r
+ __IO uint32_t I2SCLL;\r
+ __O uint32_t I2CONCLR;\r
+ __IO uint32_t MMCTRL;\r
+ __IO uint32_t I2ADR1;\r
+ __IO uint32_t I2ADR2;\r
+ __IO uint32_t I2ADR3;\r
+ __I uint32_t I2DATA_BUFFER;\r
+ __IO uint32_t I2MASK0;\r
+ __IO uint32_t I2MASK1;\r
+ __IO uint32_t I2MASK2;\r
+ __IO uint32_t I2MASK3;\r
+} I2C_TypeDef;\r
+\r
+/*------------- Inter IC Sound (I2S) -----------------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t I2SDAO;\r
+ __IO uint32_t I2SDAI;\r
+ __O uint32_t I2STXFIFO;\r
+ __I uint32_t I2SRXFIFO;\r
+ __I uint32_t I2SSTATE;\r
+ __IO uint32_t I2SDMA1;\r
+ __IO uint32_t I2SDMA2;\r
+ __IO uint32_t I2SIRQ;\r
+ __IO uint32_t I2STXRATE;\r
+ __IO uint32_t I2SRXRATE;\r
+ __IO uint32_t I2STXBITRATE;\r
+ __IO uint32_t I2SRXBITRATE;\r
+ __IO uint32_t I2STXMODE;\r
+ __IO uint32_t I2SRXMODE;\r
+} I2S_TypeDef;\r
+\r
+/*------------- Repetitive Interrupt Timer (RIT) -----------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t RICOMPVAL;\r
+ __IO uint32_t RIMASK;\r
+ __IO uint8_t RICTRL;\r
+ uint8_t RESERVED0[3];\r
+ __IO uint32_t RICOUNTER;\r
+} RIT_TypeDef;\r
+\r
+/*------------- Real-Time Clock (RTC) ----------------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint8_t ILR;\r
+ uint8_t RESERVED0[3];\r
+ __IO uint8_t CCR;\r
+ uint8_t RESERVED1[3];\r
+ __IO uint8_t CIIR;\r
+ uint8_t RESERVED2[3];\r
+ __IO uint8_t AMR;\r
+ uint8_t RESERVED3[3];\r
+ __I uint32_t CTIME0;\r
+ __I uint32_t CTIME1;\r
+ __I uint32_t CTIME2;\r
+ __IO uint8_t SEC;\r
+ uint8_t RESERVED4[3];\r
+ __IO uint8_t MIN;\r
+ uint8_t RESERVED5[3];\r
+ __IO uint8_t HOUR;\r
+ uint8_t RESERVED6[3];\r
+ __IO uint8_t DOM;\r
+ uint8_t RESERVED7[3];\r
+ __IO uint8_t DOW;\r
+ uint8_t RESERVED8[3];\r
+ __IO uint16_t DOY;\r
+ uint16_t RESERVED9;\r
+ __IO uint8_t MONTH;\r
+ uint8_t RESERVED10[3];\r
+ __IO uint16_t YEAR;\r
+ uint16_t RESERVED11;\r
+ __IO uint32_t CALIBRATION;\r
+ __IO uint32_t GPREG0;\r
+ __IO uint32_t GPREG1;\r
+ __IO uint32_t GPREG2;\r
+ __IO uint32_t GPREG3;\r
+ __IO uint32_t GPREG4;\r
+ __IO uint8_t WAKEUPDIS;\r
+ uint8_t RESERVED12[3];\r
+ __IO uint8_t PWRCTRL;\r
+ uint8_t RESERVED13[3];\r
+ __IO uint8_t ALSEC;\r
+ uint8_t RESERVED14[3];\r
+ __IO uint8_t ALMIN;\r
+ uint8_t RESERVED15[3];\r
+ __IO uint8_t ALHOUR;\r
+ uint8_t RESERVED16[3];\r
+ __IO uint8_t ALDOM;\r
+ uint8_t RESERVED17[3];\r
+ __IO uint8_t ALDOW;\r
+ uint8_t RESERVED18[3];\r
+ __IO uint16_t ALDOY;\r
+ uint16_t RESERVED19;\r
+ __IO uint8_t ALMON;\r
+ uint8_t RESERVED20[3];\r
+ __IO uint16_t ALYEAR;\r
+ uint16_t RESERVED21;\r
+} RTC_TypeDef;\r
+\r
+/*------------- Watchdog Timer (WDT) -----------------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint8_t WDMOD;\r
+ uint8_t RESERVED0[3];\r
+ __IO uint32_t WDTC;\r
+ __O uint8_t WDFEED;\r
+ uint8_t RESERVED1[3];\r
+ __I uint32_t WDTV;\r
+ __IO uint32_t WDCLKSEL;\r
+} WDT_TypeDef;\r
+\r
+/*------------- Analog-to-Digital Converter (ADC) ----------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t ADCR;\r
+ __IO uint32_t ADGDR;\r
+ uint32_t RESERVED0;\r
+ __IO uint32_t ADINTEN;\r
+ __I uint32_t ADDR0;\r
+ __I uint32_t ADDR1;\r
+ __I uint32_t ADDR2;\r
+ __I uint32_t ADDR3;\r
+ __I uint32_t ADDR4;\r
+ __I uint32_t ADDR5;\r
+ __I uint32_t ADDR6;\r
+ __I uint32_t ADDR7;\r
+ __I uint32_t ADSTAT;\r
+ __IO uint32_t ADTRM;\r
+} ADC_TypeDef;\r
+\r
+/*------------- Digital-to-Analog Converter (DAC) ----------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t DACR;\r
+ __IO uint32_t DACCTRL;\r
+ __IO uint16_t DACCNTVAL;\r
+} DAC_TypeDef;\r
+\r
+/*------------- Motor Control Pulse-Width Modulation (MCPWM) -----------------*/\r
+typedef struct\r
+{\r
+ __I uint32_t MCCON;\r
+ __O uint32_t MCCON_SET;\r
+ __O uint32_t MCCON_CLR;\r
+ __I uint32_t MCCAPCON;\r
+ __O uint32_t MCCAPCON_SET;\r
+ __O uint32_t MCCAPCON_CLR;\r
+ __IO uint32_t MCTIM0;\r
+ __IO uint32_t MCTIM1;\r
+ __IO uint32_t MCTIM2;\r
+ __IO uint32_t MCPER0;\r
+ __IO uint32_t MCPER1;\r
+ __IO uint32_t MCPER2;\r
+ __IO uint32_t MCPW0;\r
+ __IO uint32_t MCPW1;\r
+ __IO uint32_t MCPW2;\r
+ __IO uint32_t MCDEADTIME;\r
+ __IO uint32_t MCCCP;\r
+ __IO uint32_t MCCR0;\r
+ __IO uint32_t MCCR1;\r
+ __IO uint32_t MCCR2;\r
+ __I uint32_t MCINTEN;\r
+ __O uint32_t MCINTEN_SET;\r
+ __O uint32_t MCINTEN_CLR;\r
+ __I uint32_t MCCNTCON;\r
+ __O uint32_t MCCNTCON_SET;\r
+ __O uint32_t MCCNTCON_CLR;\r
+ __I uint32_t MCINTFLAG;\r
+ __O uint32_t MCINTFLAG_SET;\r
+ __O uint32_t MCINTFLAG_CLR;\r
+ __O uint32_t MCCAP_CLR;\r
+} MCPWM_TypeDef;\r
+\r
+/*------------- Quadrature Encoder Interface (QEI) ---------------------------*/\r
+typedef struct\r
+{\r
+ __O uint32_t QEICON;\r
+ __I uint32_t QEISTAT;\r
+ __IO uint32_t QEICONF;\r
+ __I uint32_t QEIPOS;\r
+ __IO uint32_t QEIMAXPOS;\r
+ __IO uint32_t CMPOS0;\r
+ __IO uint32_t CMPOS1;\r
+ __IO uint32_t CMPOS2;\r
+ __I uint32_t INXCNT;\r
+ __IO uint32_t INXCMP;\r
+ __IO uint32_t QEILOAD;\r
+ __I uint32_t QEITIME;\r
+ __I uint32_t QEIVEL;\r
+ __I uint32_t QEICAP;\r
+ __IO uint32_t VELCOMP;\r
+ __IO uint32_t FILTER;\r
+ uint32_t RESERVED0[998];\r
+ __O uint32_t QEIIEC;\r
+ __O uint32_t QEIIES;\r
+ __I uint32_t QEIINTSTAT;\r
+ __I uint32_t QEIIE;\r
+ __O uint32_t QEICLR;\r
+ __O uint32_t QEISET;\r
+} QEI_TypeDef;\r
+\r
+/*------------- Controller Area Network (CAN) --------------------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t mask[512]; /* ID Masks */\r
+} CANAF_RAM_TypeDef;\r
+\r
+typedef struct /* Acceptance Filter Registers */\r
+{\r
+ __IO uint32_t AFMR;\r
+ __IO uint32_t SFF_sa;\r
+ __IO uint32_t SFF_GRP_sa;\r
+ __IO uint32_t EFF_sa;\r
+ __IO uint32_t EFF_GRP_sa;\r
+ __IO uint32_t ENDofTable;\r
+ __I uint32_t LUTerrAd;\r
+ __I uint32_t LUTerr;\r
+} CANAF_TypeDef;\r
+\r
+typedef struct /* Central Registers */\r
+{\r
+ __I uint32_t CANTxSR;\r
+ __I uint32_t CANRxSR;\r
+ __I uint32_t CANMSR;\r
+} CANCR_TypeDef;\r
+\r
+typedef struct /* Controller Registers */\r
+{\r
+ __IO uint32_t MOD;\r
+ __O uint32_t CMR;\r
+ __IO uint32_t GSR;\r
+ __I uint32_t ICR;\r
+ __IO uint32_t IER;\r
+ __IO uint32_t BTR;\r
+ __IO uint32_t EWL;\r
+ __I uint32_t SR;\r
+ __IO uint32_t RFS;\r
+ __IO uint32_t RID;\r
+ __IO uint32_t RDA;\r
+ __IO uint32_t RDB;\r
+ __IO uint32_t TFI1;\r
+ __IO uint32_t TID1;\r
+ __IO uint32_t TDA1;\r
+ __IO uint32_t TDB1;\r
+ __IO uint32_t TFI2;\r
+ __IO uint32_t TID2;\r
+ __IO uint32_t TDA2;\r
+ __IO uint32_t TDB2;\r
+ __IO uint32_t TFI3;\r
+ __IO uint32_t TID3;\r
+ __IO uint32_t TDA3;\r
+ __IO uint32_t TDB3;\r
+} CAN_TypeDef;\r
+\r
+/*------------- General Purpose Direct Memory Access (GPDMA) -----------------*/\r
+typedef struct /* Common Registers */\r
+{\r
+ __I uint32_t DMACIntStat;\r
+ __I uint32_t DMACIntTCStat;\r
+ __O uint32_t DMACIntTCClear;\r
+ __I uint32_t DMACIntErrStat;\r
+ __O uint32_t DMACIntErrClr;\r
+ __I uint32_t DMACRawIntTCStat;\r
+ __I uint32_t DMACRawIntErrStat;\r
+ __I uint32_t DMACEnbldChns;\r
+ __IO uint32_t DMACSoftBReq;\r
+ __IO uint32_t DMACSoftSReq;\r
+ __IO uint32_t DMACSoftLBReq;\r
+ __IO uint32_t DMACSoftLSReq;\r
+ __IO uint32_t DMACConfig;\r
+ __IO uint32_t DMACSync;\r
+} GPDMA_TypeDef;\r
+\r
+typedef struct /* Channel Registers */\r
+{\r
+ __IO uint32_t DMACCSrcAddr;\r
+ __IO uint32_t DMACCDestAddr;\r
+ __IO uint32_t DMACCLLI;\r
+ __IO uint32_t DMACCControl;\r
+ __IO uint32_t DMACCConfig;\r
+} GPDMACH_TypeDef;\r
+\r
+/*------------- Universal Serial Bus (USB) -----------------------------------*/\r
+typedef struct\r
+{\r
+ __I uint32_t HcRevision; /* USB Host Registers */\r
+ __IO uint32_t HcControl;\r
+ __IO uint32_t HcCommandStatus;\r
+ __IO uint32_t HcInterruptStatus;\r
+ __IO uint32_t HcInterruptEnable;\r
+ __IO uint32_t HcInterruptDisable;\r
+ __IO uint32_t HcHCCA;\r
+ __I uint32_t HcPeriodCurrentED;\r
+ __IO uint32_t HcControlHeadED;\r
+ __IO uint32_t HcControlCurrentED;\r
+ __IO uint32_t HcBulkHeadED;\r
+ __IO uint32_t HcBulkCurrentED;\r
+ __I uint32_t HcDoneHead;\r
+ __IO uint32_t HcFmInterval;\r
+ __I uint32_t HcFmRemaining;\r
+ __I uint32_t HcFmNumber;\r
+ __IO uint32_t HcPeriodicStart;\r
+ __IO uint32_t HcLSTreshold;\r
+ __IO uint32_t HcRhDescriptorA;\r
+ __IO uint32_t HcRhDescriptorB;\r
+ __IO uint32_t HcRhStatus;\r
+ __IO uint32_t HcRhPortStatus1;\r
+ __IO uint32_t HcRhPortStatus2;\r
+ uint32_t RESERVED0[40];\r
+ __I uint32_t Module_ID;\r
+\r
+ __I uint32_t OTGIntSt; /* USB On-The-Go Registers */\r
+ __IO uint32_t OTGIntEn;\r
+ __O uint32_t OTGIntSet;\r
+ __O uint32_t OTGIntClr;\r
+ __IO uint32_t OTGStCtrl;\r
+ __IO uint32_t OTGTmr;\r
+ uint32_t RESERVED1[58];\r
+\r
+ __I uint32_t USBDevIntSt; /* USB Device Interrupt Registers */\r
+ __IO uint32_t USBDevIntEn;\r
+ __O uint32_t USBDevIntClr;\r
+ __O uint32_t USBDevIntSet;\r
+\r
+ __O uint32_t USBCmdCode; /* USB Device SIE Command Registers */\r
+ __I uint32_t USBCmdData;\r
+\r
+ __I uint32_t USBRxData; /* USB Device Transfer Registers */\r
+ __O uint32_t USBTxData;\r
+ __I uint32_t USBRxPLen;\r
+ __O uint32_t USBTxPLen;\r
+ __IO uint32_t USBCtrl;\r
+ __O uint32_t USBDevIntPri;\r
+\r
+ __I uint32_t USBEpIntSt; /* USB Device Endpoint Interrupt Regs */\r
+ __IO uint32_t USBEpIntEn;\r
+ __O uint32_t USBEpIntClr;\r
+ __O uint32_t USBEpIntSet;\r
+ __O uint32_t USBEpIntPri;\r
+\r
+ __IO uint32_t USBReEp; /* USB Device Endpoint Realization Reg*/\r
+ __O uint32_t USBEpInd;\r
+ __IO uint32_t USBMaxPSize;\r
+\r
+ __I uint32_t USBDMARSt; /* USB Device DMA Registers */\r
+ __O uint32_t USBDMARClr;\r
+ __O uint32_t USBDMARSet;\r
+ uint32_t RESERVED2[9];\r
+ __IO uint32_t USBUDCAH;\r
+ __I uint32_t USBEpDMASt;\r
+ __O uint32_t USBEpDMAEn;\r
+ __O uint32_t USBEpDMADis;\r
+ __I uint32_t USBDMAIntSt;\r
+ __IO uint32_t USBDMAIntEn;\r
+ uint32_t RESERVED3[2];\r
+ __I uint32_t USBEoTIntSt;\r
+ __O uint32_t USBEoTIntClr;\r
+ __O uint32_t USBEoTIntSet;\r
+ __I uint32_t USBNDDRIntSt;\r
+ __O uint32_t USBNDDRIntClr;\r
+ __O uint32_t USBNDDRIntSet;\r
+ __I uint32_t USBSysErrIntSt;\r
+ __O uint32_t USBSysErrIntClr;\r
+ __O uint32_t USBSysErrIntSet;\r
+ uint32_t RESERVED4[15];\r
+\r
+ __I uint32_t I2C_RX; /* USB OTG I2C Registers */\r
+ __O uint32_t I2C_WO;\r
+ __I uint32_t I2C_STS;\r
+ __IO uint32_t I2C_CTL;\r
+ __IO uint32_t I2C_CLKHI;\r
+ __O uint32_t I2C_CLKLO;\r
+ uint32_t RESERVED5[823];\r
+\r
+ union {\r
+ __IO uint32_t USBClkCtrl; /* USB Clock Control Registers */\r
+ __IO uint32_t OTGClkCtrl;\r
+ } ;\r
+ union {\r
+ __I uint32_t USBClkSt;\r
+ __I uint32_t OTGClkSt;\r
+ };\r
+} USB_TypeDef;\r
+\r
+/*------------- Ethernet Media Access Controller (EMAC) ----------------------*/\r
+typedef struct\r
+{\r
+ __IO uint32_t MAC1; /* MAC Registers */\r
+ __IO uint32_t MAC2;\r
+ __IO uint32_t IPGT;\r
+ __IO uint32_t IPGR;\r
+ __IO uint32_t CLRT;\r
+ __IO uint32_t MAXF;\r
+ __IO uint32_t SUPP;\r
+ __IO uint32_t TEST;\r
+ __IO uint32_t MCFG;\r
+ __IO uint32_t MCMD;\r
+ __IO uint32_t MADR;\r
+ __O uint32_t MWTD;\r
+ __I uint32_t MRDD;\r
+ __I uint32_t MIND;\r
+ uint32_t RESERVED0[2];\r
+ __IO uint32_t SA0;\r
+ __IO uint32_t SA1;\r
+ __IO uint32_t SA2;\r
+ uint32_t RESERVED1[45];\r
+ __IO uint32_t Command; /* Control Registers */\r
+ __I uint32_t Status;\r
+ __IO uint32_t RxDescriptor;\r
+ __IO uint32_t RxStatus;\r
+ __IO uint32_t RxDescriptorNumber;\r
+ __I uint32_t RxProduceIndex;\r
+ __IO uint32_t RxConsumeIndex;\r
+ __IO uint32_t TxDescriptor;\r
+ __IO uint32_t TxStatus;\r
+ __IO uint32_t TxDescriptorNumber;\r
+ __IO uint32_t TxProduceIndex;\r
+ __I uint32_t TxConsumeIndex;\r
+ uint32_t RESERVED2[10];\r
+ __I uint32_t TSV0;\r
+ __I uint32_t TSV1;\r
+ __I uint32_t RSV;\r
+ uint32_t RESERVED3[3];\r
+ __IO uint32_t FlowControlCounter;\r
+ __I uint32_t FlowControlStatus;\r
+ uint32_t RESERVED4[34];\r
+ __IO uint32_t RxFilterCtrl; /* Rx Filter Registers */\r
+ __IO uint32_t RxFilterWoLStatus;\r
+ __IO uint32_t RxFilterWoLClear;\r
+ uint32_t RESERVED5;\r
+ __IO uint32_t HashFilterL;\r
+ __IO uint32_t HashFilterH;\r
+ uint32_t RESERVED6[882];\r
+ __I uint32_t IntStatus; /* Module Control Registers */\r
+ __IO uint32_t IntEnable;\r
+ __O uint32_t IntClear;\r
+ __O uint32_t IntSet;\r
+ uint32_t RESERVED7;\r
+ __IO uint32_t PowerDown;\r
+ uint32_t RESERVED8;\r
+ __IO uint32_t Module_ID;\r
+} EMAC_TypeDef;\r
+\r
+/******************************************************************************/\r
+/* Peripheral memory map */\r
+/******************************************************************************/\r
+/* Base addresses */\r
+#define FLASH_BASE (0x00000000UL)\r
+#define RAM_BASE (0x10000000UL)\r
+#define GPIO_BASE (0x2009C000UL)\r
+#define APB0_BASE (0x40000000UL)\r
+#define APB1_BASE (0x40080000UL)\r
+#define AHB_BASE (0x50000000UL)\r
+#define CM3_BASE (0xE0000000UL)\r
+\r
+/* APB0 peripherals */\r
+#define WDT_BASE (APB0_BASE + 0x00000)\r
+#define TIM0_BASE (APB0_BASE + 0x04000)\r
+#define TIM1_BASE (APB0_BASE + 0x08000)\r
+#define UART0_BASE (APB0_BASE + 0x0C000)\r
+#define UART1_BASE (APB0_BASE + 0x10000)\r
+#define PWM1_BASE (APB0_BASE + 0x18000)\r
+#define I2C0_BASE (APB0_BASE + 0x1C000)\r
+#define SPI_BASE (APB0_BASE + 0x20000)\r
+#define RTC_BASE (APB0_BASE + 0x24000)\r
+#define GPIOINT_BASE (APB0_BASE + 0x28080)\r
+#define PINCON_BASE (APB0_BASE + 0x2C000)\r
+#define SSP1_BASE (APB0_BASE + 0x30000)\r
+#define ADC_BASE (APB0_BASE + 0x34000)\r
+#define CANAF_RAM_BASE (APB0_BASE + 0x38000)\r
+#define CANAF_BASE (APB0_BASE + 0x3C000)\r
+#define CANCR_BASE (APB0_BASE + 0x40000)\r
+#define CAN1_BASE (APB0_BASE + 0x44000)\r
+#define CAN2_BASE (APB0_BASE + 0x48000)\r
+#define I2C1_BASE (APB0_BASE + 0x5C000)\r
+\r
+/* APB1 peripherals */\r
+#define SSP0_BASE (APB1_BASE + 0x08000)\r
+#define DAC_BASE (APB1_BASE + 0x0C000)\r
+#define TIM2_BASE (APB1_BASE + 0x10000)\r
+#define TIM3_BASE (APB1_BASE + 0x14000)\r
+#define UART2_BASE (APB1_BASE + 0x18000)\r
+#define UART3_BASE (APB1_BASE + 0x1C000)\r
+#define I2C2_BASE (APB1_BASE + 0x20000)\r
+#define I2S_BASE (APB1_BASE + 0x28000)\r
+#define RIT_BASE (APB1_BASE + 0x30000)\r
+#define MCPWM_BASE (APB1_BASE + 0x38000)\r
+#define QEI_BASE (APB1_BASE + 0x3C000)\r
+#define SC_BASE (APB1_BASE + 0x7C000)\r
+\r
+/* AHB peripherals */\r
+#define EMAC_BASE (AHB_BASE + 0x00000)\r
+#define GPDMA_BASE (AHB_BASE + 0x04000)\r
+#define GPDMACH0_BASE (AHB_BASE + 0x04100)\r
+#define GPDMACH1_BASE (AHB_BASE + 0x04120)\r
+#define GPDMACH2_BASE (AHB_BASE + 0x04140)\r
+#define GPDMACH3_BASE (AHB_BASE + 0x04160)\r
+#define GPDMACH4_BASE (AHB_BASE + 0x04180)\r
+#define GPDMACH5_BASE (AHB_BASE + 0x041A0)\r
+#define GPDMACH6_BASE (AHB_BASE + 0x041C0)\r
+#define GPDMACH7_BASE (AHB_BASE + 0x041E0)\r
+#define USB_BASE (AHB_BASE + 0x0C000)\r
+\r
+/* GPIOs */\r
+#define GPIO0_BASE (GPIO_BASE + 0x00000)\r
+#define GPIO1_BASE (GPIO_BASE + 0x00020)\r
+#define GPIO2_BASE (GPIO_BASE + 0x00040)\r
+#define GPIO3_BASE (GPIO_BASE + 0x00060)\r
+#define GPIO4_BASE (GPIO_BASE + 0x00080)\r
+\r
+\r
+/******************************************************************************/\r
+/* Peripheral declaration */\r
+/******************************************************************************/\r
+#define SC (( SC_TypeDef *) SC_BASE)\r
+#define GPIO0 (( GPIO_TypeDef *) GPIO0_BASE)\r
+#define GPIO1 (( GPIO_TypeDef *) GPIO1_BASE)\r
+#define GPIO2 (( GPIO_TypeDef *) GPIO2_BASE)\r
+#define GPIO3 (( GPIO_TypeDef *) GPIO3_BASE)\r
+#define GPIO4 (( GPIO_TypeDef *) GPIO4_BASE)\r
+#define WDT (( WDT_TypeDef *) WDT_BASE)\r
+#define TIM0 (( TIM_TypeDef *) TIM0_BASE)\r
+#define TIM1 (( TIM_TypeDef *) TIM1_BASE)\r
+#define TIM2 (( TIM_TypeDef *) TIM2_BASE)\r
+#define TIM3 (( TIM_TypeDef *) TIM3_BASE)\r
+#define RIT (( RIT_TypeDef *) RIT_BASE)\r
+#define UART0 (( UART_TypeDef *) UART0_BASE)\r
+#define UART1 (( UART1_TypeDef *) UART1_BASE)\r
+#define UART2 (( UART_TypeDef *) UART2_BASE)\r
+#define UART3 (( UART_TypeDef *) UART3_BASE)\r
+#define PWM1 (( PWM_TypeDef *) PWM1_BASE)\r
+#define I2C0 (( I2C_TypeDef *) I2C0_BASE)\r
+#define I2C1 (( I2C_TypeDef *) I2C1_BASE)\r
+#define I2C2 (( I2C_TypeDef *) I2C2_BASE)\r
+#define I2S (( I2S_TypeDef *) I2S_BASE)\r
+#define SPI (( SPI_TypeDef *) SPI_BASE)\r
+#define RTC (( RTC_TypeDef *) RTC_BASE)\r
+#define GPIOINT (( GPIOINT_TypeDef *) GPIOINT_BASE)\r
+#define PINCON (( PINCON_TypeDef *) PINCON_BASE)\r
+#define SSP0 (( SSP_TypeDef *) SSP0_BASE)\r
+#define SSP1 (( SSP_TypeDef *) SSP1_BASE)\r
+#define ADC (( ADC_TypeDef *) ADC_BASE)\r
+#define DAC (( DAC_TypeDef *) DAC_BASE)\r
+#define CANAF_RAM ((CANAF_RAM_TypeDef *) CANAF_RAM_BASE)\r
+#define CANAF (( CANAF_TypeDef *) CANAF_BASE)\r
+#define CANCR (( CANCR_TypeDef *) CANCR_BASE)\r
+#define CAN1 (( CAN_TypeDef *) CAN1_BASE)\r
+#define CAN2 (( CAN_TypeDef *) CAN2_BASE)\r
+#define MCPWM (( MCPWM_TypeDef *) MCPWM_BASE)\r
+#define QEI (( QEI_TypeDef *) QEI_BASE)\r
+#define EMAC (( EMAC_TypeDef *) EMAC_BASE)\r
+#define GPDMA (( GPDMA_TypeDef *) GPDMA_BASE)\r
+#define GPDMACH0 (( GPDMACH_TypeDef *) GPDMACH0_BASE)\r
+#define GPDMACH1 (( GPDMACH_TypeDef *) GPDMACH1_BASE)\r
+#define GPDMACH2 (( GPDMACH_TypeDef *) GPDMACH2_BASE)\r
+#define GPDMACH3 (( GPDMACH_TypeDef *) GPDMACH3_BASE)\r
+#define GPDMACH4 (( GPDMACH_TypeDef *) GPDMACH4_BASE)\r
+#define GPDMACH5 (( GPDMACH_TypeDef *) GPDMACH5_BASE)\r
+#define GPDMACH6 (( GPDMACH_TypeDef *) GPDMACH6_BASE)\r
+#define GPDMACH7 (( GPDMACH_TypeDef *) GPDMACH7_BASE)\r
+#define USB (( USB_TypeDef *) USB_BASE)\r
+\r
+#endif // __LPC17xx_H__\r
+\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it\r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
+ **NOTE** The exception to the GPL is included to allow you to distribute a\r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
+ the source code for any proprietary components. Alternative commercial\r
+ license and support terms are also available upon request. See the\r
+ licensing section of http://www.FreeRTOS.org for full details.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details.\r
+\r
+ You should have received a copy of the GNU General Public License along\r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ Please ensure to read the configuration and relevant port sections of the\r
+ online documentation.\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/* FreeRTOS.org includes. */\r
+#include "FreeRTOS.h"\r
+\r
+/* Demo application includes. */\r
+#include "partest.h"\r
+\r
+#define LED_2 ( 1UL << 24UL )\r
+#define LED_3 ( 1UL << 25UL )\r
+#define LED_4 ( 1UL << 28UL )\r
+#define LED_5 ( 1UL << 29UL )\r
+\r
+#define partstFIO1_BITS ( LED_2 | LED_3 | LED_4 | LED_5 )\r
+#define partstNUM_LEDS ( 4 )\r
+\r
+static unsigned long ulLEDs[] = { LED_3, LED_2, LED_5, LED_4 };\r
+\r
+/*-----------------------------------------------------------\r
+ * Simple parallel port IO routines.\r
+ *-----------------------------------------------------------*/\r
+\r
+void vParTestInitialise( void )\r
+{\r
+ /* LEDs on port 1. */\r
+ GPIO1->FIODIR = partstFIO1_BITS;\r
+ \r
+ /* Start will all LEDs off. */\r
+ GPIO1->FIOCLR = partstFIO1_BITS;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
+{\r
+ if( uxLED < partstNUM_LEDS )\r
+ {\r
+ /* Set of clear the output. */\r
+ if( xValue )\r
+ {\r
+ GPIO1->FIOCLR = ulLEDs[ uxLED ];\r
+ }\r
+ else\r
+ {\r
+ GPIO1->FIOSET = ulLEDs[ uxLED ];\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
+{\r
+ if( uxLED < partstNUM_LEDS )\r
+ {\r
+ if( GPIO1->FIOPIN & ulLEDs[ uxLED ] )\r
+ {\r
+ GPIO1->FIOCLR = ulLEDs[ uxLED ];\r
+ }\r
+ else\r
+ {\r
+ GPIO1->FIOSET = ulLEDs[ uxLED ];\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned portBASE_TYPE uxParTextGetLED( unsigned portBASE_TYPE uxLED )\r
+{\r
+ if( uxLED < partstNUM_LEDS )\r
+ {\r
+ return ( GPIO1->FIOPIN & ulLEDs[ uxLED ] );\r
+ }\r
+ else\r
+ {\r
+ return 0;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+/******************************************************************************\r
+ * @file: core_cm3.h\r
+ * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Header File\r
+ * @version: V1.20\r
+ * @date: 22. May 2009\r
+ *----------------------------------------------------------------------------\r
+ *\r
+ * Copyright (C) 2009 ARM Limited. All rights reserved.\r
+ *\r
+ * ARM Limited (ARM) is supplying this software for use with Cortex-Mx \r
+ * processor based microcontrollers. This file can be freely distributed \r
+ * within development tools that are supporting such ARM based processors. \r
+ *\r
+ * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
+ *\r
+ ******************************************************************************/\r
+\r
+#ifndef __CM3_CORE_H__\r
+#define __CM3_CORE_H__\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif \r
+\r
+#define __CM3_CMSIS_VERSION_MAIN (0x01) /*!< [31:16] CMSIS HAL main version */\r
+#define __CM3_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */\r
+#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */\r
+\r
+#define __CORTEX_M (0x03) /*!< Cortex core */\r
+\r
+/**\r
+ * Lint configuration \n\r
+ * ----------------------- \n\r
+ *\r
+ * The following Lint messages will be suppressed and not shown: \n\r
+ * \n\r
+ * --- Error 10: --- \n\r
+ * register uint32_t __regBasePri __asm("basepri"); \n\r
+ * Error 10: Expecting ';' \n\r
+ * \n\r
+ * --- Error 530: --- \n\r
+ * return(__regBasePri); \n\r
+ * Warning 530: Symbol '__regBasePri' (line 264) not initialized \n\r
+ * \n\r
+ * --- Error 550: --- \n\r
+ * __regBasePri = (basePri & 0x1ff); \n\r
+ * } \n\r
+ * Warning 550: Symbol '__regBasePri' (line 271) not accessed \n\r
+ * \n\r
+ * --- Error 754: --- \n\r
+ * uint32_t RESERVED0[24]; \n\r
+ * Info 754: local structure member '<some, not used in the HAL>' (line 109, file ./cm3_core.h) not referenced \n\r
+ * \n\r
+ * --- Error 750: --- \n\r
+ * #define __CM3_CORE_H__ \n\r
+ * Info 750: local macro '__CM3_CORE_H__' (line 43, file./cm3_core.h) not referenced \n\r
+ * \n\r
+ * --- Error 528: --- \n\r
+ * static __INLINE void NVIC_DisableIRQ(uint32_t IRQn) \n\r
+ * Warning 528: Symbol 'NVIC_DisableIRQ(unsigned int)' (line 419, file ./cm3_core.h) not referenced \n\r
+ * \n\r
+ * --- Error 751: --- \n\r
+ * } InterruptType_Type; \n\r
+ * Info 751: local typedef 'InterruptType_Type' (line 170, file ./cm3_core.h) not referenced \n\r
+ * \n\r
+ * \n\r
+ * Note: To re-enable a Message, insert a space before 'lint' * \n\r
+ *\r
+ */\r
+\r
+/*lint -save */\r
+/*lint -e10 */\r
+/*lint -e530 */\r
+/*lint -e550 */\r
+/*lint -e754 */\r
+/*lint -e750 */\r
+/*lint -e528 */\r
+/*lint -e751 */\r
+\r
+\r
+#include <stdint.h> /* Include standard types */\r
+\r
+#if defined (__ICCARM__)\r
+ #include <intrinsics.h> /* IAR Intrinsics */\r
+#endif\r
+\r
+\r
+#ifndef __NVIC_PRIO_BITS\r
+ #define __NVIC_PRIO_BITS 4 /*!< standard definition for NVIC Priority Bits */\r
+#endif\r
+\r
+\r
+\r
+\r
+/**\r
+ * IO definitions\r
+ *\r
+ * define access restrictions to peripheral registers\r
+ */\r
+\r
+#ifdef __cplusplus\r
+#define __I volatile /*!< defines 'read only' permissions */\r
+#else\r
+#define __I volatile const /*!< defines 'read only' permissions */\r
+#endif\r
+#define __O volatile /*!< defines 'write only' permissions */\r
+#define __IO volatile /*!< defines 'read / write' permissions */\r
+\r
+\r
+\r
+/*******************************************************************************\r
+ * Register Abstraction\r
+ ******************************************************************************/\r
+\r
+\r
+/* System Reset */\r
+#define NVIC_VECTRESET 0 /*!< Vector Reset Bit */\r
+#define NVIC_SYSRESETREQ 2 /*!< System Reset Request */\r
+#define NVIC_AIRCR_VECTKEY (0x5FA << 16) /*!< AIRCR Key for write access */\r
+#define NVIC_AIRCR_ENDIANESS 15 /*!< Endianess */\r
+\r
+/* Core Debug */\r
+#define CoreDebug_DEMCR_TRCENA (1 << 24) /*!< DEMCR TRCENA enable */\r
+#define ITM_TCR_ITMENA 1 /*!< ITM enable */\r
+\r
+\r
+\r
+\r
+/* memory mapping struct for Nested Vectored Interrupt Controller (NVIC) */\r
+typedef struct\r
+{\r
+ __IO uint32_t ISER[8]; /*!< Interrupt Set Enable Register */\r
+ uint32_t RESERVED0[24];\r
+ __IO uint32_t ICER[8]; /*!< Interrupt Clear Enable Register */\r
+ uint32_t RSERVED1[24];\r
+ __IO uint32_t ISPR[8]; /*!< Interrupt Set Pending Register */\r
+ uint32_t RESERVED2[24];\r
+ __IO uint32_t ICPR[8]; /*!< Interrupt Clear Pending Register */\r
+ uint32_t RESERVED3[24];\r
+ __IO uint32_t IABR[8]; /*!< Interrupt Active bit Register */\r
+ uint32_t RESERVED4[56];\r
+ __IO uint8_t IP[240]; /*!< Interrupt Priority Register, 8Bit wide */\r
+ uint32_t RESERVED5[644];\r
+ __O uint32_t STIR; /*!< Software Trigger Interrupt Register */\r
+} NVIC_Type;\r
+\r
+\r
+/* memory mapping struct for System Control Block */\r
+typedef struct\r
+{\r
+ __I uint32_t CPUID; /*!< CPU ID Base Register */\r
+ __IO uint32_t ICSR; /*!< Interrupt Control State Register */\r
+ __IO uint32_t VTOR; /*!< Vector Table Offset Register */\r
+ __IO uint32_t AIRCR; /*!< Application Interrupt / Reset Control Register */\r
+ __IO uint32_t SCR; /*!< System Control Register */\r
+ __IO uint32_t CCR; /*!< Configuration Control Register */\r
+ __IO uint8_t SHP[12]; /*!< System Handlers Priority Registers (4-7, 8-11, 12-15) */\r
+ __IO uint32_t SHCSR; /*!< System Handler Control and State Register */\r
+ __IO uint32_t CFSR; /*!< Configurable Fault Status Register */\r
+ __IO uint32_t HFSR; /*!< Hard Fault Status Register */\r
+ __IO uint32_t DFSR; /*!< Debug Fault Status Register */\r
+ __IO uint32_t MMFAR; /*!< Mem Manage Address Register */\r
+ __IO uint32_t BFAR; /*!< Bus Fault Address Register */\r
+ __IO uint32_t AFSR; /*!< Auxiliary Fault Status Register */\r
+ __I uint32_t PFR[2]; /*!< Processor Feature Register */\r
+ __I uint32_t DFR; /*!< Debug Feature Register */\r
+ __I uint32_t ADR; /*!< Auxiliary Feature Register */\r
+ __I uint32_t MMFR[4]; /*!< Memory Model Feature Register */\r
+ __I uint32_t ISAR[5]; /*!< ISA Feature Register */\r
+} SCB_Type;\r
+\r
+\r
+/* memory mapping struct for SysTick */\r
+typedef struct\r
+{\r
+ __IO uint32_t CTRL; /*!< SysTick Control and Status Register */\r
+ __IO uint32_t LOAD; /*!< SysTick Reload Value Register */\r
+ __IO uint32_t VAL; /*!< SysTick Current Value Register */\r
+ __I uint32_t CALIB; /*!< SysTick Calibration Register */\r
+} SysTick_Type;\r
+\r
+\r
+/* memory mapping structur for ITM */\r
+typedef struct\r
+{\r
+ __O union \r
+ {\r
+ __O uint8_t u8; /*!< ITM Stimulus Port 8-bit */\r
+ __O uint16_t u16; /*!< ITM Stimulus Port 16-bit */\r
+ __O uint32_t u32; /*!< ITM Stimulus Port 32-bit */\r
+ } PORT [32]; /*!< ITM Stimulus Port Registers */\r
+ uint32_t RESERVED0[864];\r
+ __IO uint32_t TER; /*!< ITM Trace Enable Register */\r
+ uint32_t RESERVED1[15];\r
+ __IO uint32_t TPR; /*!< ITM Trace Privilege Register */\r
+ uint32_t RESERVED2[15];\r
+ __IO uint32_t TCR; /*!< ITM Trace Control Register */\r
+ uint32_t RESERVED3[29];\r
+ __IO uint32_t IWR; /*!< ITM Integration Write Register */\r
+ __IO uint32_t IRR; /*!< ITM Integration Read Register */\r
+ __IO uint32_t IMCR; /*!< ITM Integration Mode Control Register */\r
+ uint32_t RESERVED4[43];\r
+ __IO uint32_t LAR; /*!< ITM Lock Access Register */\r
+ __IO uint32_t LSR; /*!< ITM Lock Status Register */\r
+ uint32_t RESERVED5[6];\r
+ __I uint32_t PID4; /*!< ITM Product ID Registers */\r
+ __I uint32_t PID5;\r
+ __I uint32_t PID6;\r
+ __I uint32_t PID7;\r
+ __I uint32_t PID0;\r
+ __I uint32_t PID1;\r
+ __I uint32_t PID2;\r
+ __I uint32_t PID3;\r
+ __I uint32_t CID0;\r
+ __I uint32_t CID1;\r
+ __I uint32_t CID2;\r
+ __I uint32_t CID3;\r
+} ITM_Type;\r
+\r
+\r
+/* memory mapped struct for Interrupt Type */\r
+typedef struct\r
+{\r
+ uint32_t RESERVED0;\r
+ __I uint32_t ICTR; /*!< Interrupt Control Type Register */\r
+#if ((defined __CM3_REV) && (__CM3_REV >= 0x200))\r
+ __IO uint32_t ACTLR; /*!< Auxiliary Control Register */\r
+#else\r
+ uint32_t RESERVED1;\r
+#endif\r
+} InterruptType_Type;\r
+\r
+\r
+/* Memory Protection Unit */\r
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)\r
+typedef struct\r
+{\r
+ __I uint32_t TYPE; /*!< MPU Type Register */\r
+ __IO uint32_t CTRL; /*!< MPU Control Register */\r
+ __IO uint32_t RNR; /*!< MPU Region RNRber Register */\r
+ __IO uint32_t RBAR; /*!< MPU Region Base Address Register */\r
+ __IO uint32_t RASR; /*!< MPU Region Attribute and Size Register */\r
+ __IO uint32_t RBAR_A1; /*!< MPU Alias 1 Region Base Address Register */\r
+ __IO uint32_t RASR_A1; /*!< MPU Alias 1 Region Attribute and Size Register */\r
+ __IO uint32_t RBAR_A2; /*!< MPU Alias 2 Region Base Address Register */\r
+ __IO uint32_t RASR_A2; /*!< MPU Alias 2 Region Attribute and Size Register */\r
+ __IO uint32_t RBAR_A3; /*!< MPU Alias 3 Region Base Address Register */\r
+ __IO uint32_t RASR_A3; /*!< MPU Alias 3 Region Attribute and Size Register */\r
+} MPU_Type;\r
+#endif\r
+\r
+\r
+/* Core Debug Register */\r
+typedef struct\r
+{\r
+ __IO uint32_t DHCSR; /*!< Debug Halting Control and Status Register */\r
+ __O uint32_t DCRSR; /*!< Debug Core Register Selector Register */\r
+ __IO uint32_t DCRDR; /*!< Debug Core Register Data Register */\r
+ __IO uint32_t DEMCR; /*!< Debug Exception and Monitor Control Register */\r
+} CoreDebug_Type;\r
+\r
+\r
+/* Memory mapping of Cortex-M3 Hardware */\r
+#define SCS_BASE (0xE000E000) /*!< System Control Space Base Address */\r
+#define ITM_BASE (0xE0000000) /*!< ITM Base Address */\r
+#define CoreDebug_BASE (0xE000EDF0) /*!< Core Debug Base Address */\r
+#define SysTick_BASE (SCS_BASE + 0x0010) /*!< SysTick Base Address */\r
+#define NVIC_BASE (SCS_BASE + 0x0100) /*!< NVIC Base Address */\r
+#define SCB_BASE (SCS_BASE + 0x0D00) /*!< System Control Block Base Address */\r
+\r
+#define InterruptType ((InterruptType_Type *) SCS_BASE) /*!< Interrupt Type Register */\r
+#define SCB ((SCB_Type *) SCB_BASE) /*!< SCB configuration struct */\r
+#define SysTick ((SysTick_Type *) SysTick_BASE) /*!< SysTick configuration struct */\r
+#define NVIC ((NVIC_Type *) NVIC_BASE) /*!< NVIC configuration struct */\r
+#define ITM ((ITM_Type *) ITM_BASE) /*!< ITM configuration struct */\r
+#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */\r
+\r
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)\r
+ #define MPU_BASE (SCS_BASE + 0x0D90) /*!< Memory Protection Unit */\r
+ #define MPU ((MPU_Type*) MPU_BASE) /*!< Memory Protection Unit */\r
+#endif\r
+\r
+\r
+\r
+/*******************************************************************************\r
+ * Hardware Abstraction Layer\r
+ ******************************************************************************/\r
+\r
+\r
+#if defined ( __CC_ARM )\r
+ #define __ASM __asm /*!< asm keyword for ARM Compiler */\r
+ #define __INLINE __inline /*!< inline keyword for ARM Compiler */\r
+\r
+#elif defined ( __ICCARM__ )\r
+ #define __ASM __asm /*!< asm keyword for IAR Compiler */\r
+ #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */\r
+\r
+#elif defined ( __GNUC__ )\r
+ #define __ASM __asm /*!< asm keyword for GNU Compiler */\r
+ #define __INLINE inline /*!< inline keyword for GNU Compiler */\r
+\r
+#elif defined ( __TASKING__ )\r
+ #define __ASM __asm /*!< asm keyword for TASKING Compiler */\r
+ #define __INLINE inline /*!< inline keyword for TASKING Compiler */\r
+\r
+#endif\r
+\r
+\r
+/* ################### Compiler specific Intrinsics ########################### */\r
+\r
+#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/\r
+/* ARM armcc specific functions */\r
+\r
+#define __enable_fault_irq __enable_fiq\r
+#define __disable_fault_irq __disable_fiq\r
+\r
+#define __NOP __nop\r
+#define __WFI __wfi\r
+#define __WFE __wfe\r
+#define __SEV __sev\r
+#define __ISB() __isb(0)\r
+#define __DSB() __dsb(0)\r
+#define __DMB() __dmb(0)\r
+#define __REV __rev\r
+#define __RBIT __rbit\r
+#define __LDREXB(ptr) ((unsigned char ) __ldrex(ptr))\r
+#define __LDREXH(ptr) ((unsigned short) __ldrex(ptr))\r
+#define __LDREXW(ptr) ((unsigned int ) __ldrex(ptr))\r
+#define __STREXB(value, ptr) __strex(value, ptr)\r
+#define __STREXH(value, ptr) __strex(value, ptr)\r
+#define __STREXW(value, ptr) __strex(value, ptr)\r
+\r
+\r
+/* intrinsic unsigned long long __ldrexd(volatile void *ptr) */\r
+/* intrinsic int __strexd(unsigned long long val, volatile void *ptr) */\r
+/* intrinsic void __enable_irq(); */\r
+/* intrinsic void __disable_irq(); */\r
+\r
+\r
+/**\r
+ * @brief Return the Process Stack Pointer\r
+ *\r
+ * @param none\r
+ * @return uint32_t ProcessStackPointer\r
+ *\r
+ * Return the actual process stack pointer\r
+ */\r
+extern uint32_t __get_PSP(void);\r
+\r
+/**\r
+ * @brief Set the Process Stack Pointer\r
+ *\r
+ * @param uint32_t Process Stack Pointer\r
+ * @return none\r
+ *\r
+ * Assign the value ProcessStackPointer to the MSP \r
+ * (process stack pointer) Cortex processor register\r
+ */\r
+extern void __set_PSP(uint32_t topOfProcStack);\r
+\r
+/**\r
+ * @brief Return the Main Stack Pointer\r
+ *\r
+ * @param none\r
+ * @return uint32_t Main Stack Pointer\r
+ *\r
+ * Return the current value of the MSP (main stack pointer)\r
+ * Cortex processor register\r
+ */\r
+extern uint32_t __get_MSP(void);\r
+\r
+/**\r
+ * @brief Set the Main Stack Pointer\r
+ *\r
+ * @param uint32_t Main Stack Pointer\r
+ * @return none\r
+ *\r
+ * Assign the value mainStackPointer to the MSP \r
+ * (main stack pointer) Cortex processor register\r
+ */\r
+extern void __set_MSP(uint32_t topOfMainStack);\r
+\r
+/**\r
+ * @brief Reverse byte order in unsigned short value\r
+ *\r
+ * @param uint16_t value to reverse\r
+ * @return uint32_t reversed value\r
+ *\r
+ * Reverse byte order in unsigned short value\r
+ */\r
+extern uint32_t __REV16(uint16_t value);\r
+\r
+/*\r
+ * @brief Reverse byte order in signed short value with sign extension to integer\r
+ *\r
+ * @param int16_t value to reverse\r
+ * @return int32_t reversed value\r
+ *\r
+ * Reverse byte order in signed short value with sign extension to integer\r
+ */\r
+extern int32_t __REVSH(int16_t value);\r
+\r
+\r
+#if (__ARMCC_VERSION < 400000)\r
+\r
+/**\r
+ * @brief Remove the exclusive lock created by ldrex\r
+ *\r
+ * @param none\r
+ * @return none\r
+ *\r
+ * Removes the exclusive lock which is created by ldrex.\r
+ */\r
+extern void __CLREX(void);\r
+\r
+/**\r
+ * @brief Return the Base Priority value\r
+ *\r
+ * @param none\r
+ * @return uint32_t BasePriority\r
+ *\r
+ * Return the content of the base priority register\r
+ */\r
+extern uint32_t __get_BASEPRI(void);\r
+\r
+/**\r
+ * @brief Set the Base Priority value\r
+ *\r
+ * @param uint32_t BasePriority\r
+ * @return none\r
+ *\r
+ * Set the base priority register\r
+ */\r
+extern void __set_BASEPRI(uint32_t basePri);\r
+\r
+/**\r
+ * @brief Return the Priority Mask value\r
+ *\r
+ * @param none\r
+ * @return uint32_t PriMask\r
+ *\r
+ * Return the state of the priority mask bit from the priority mask\r
+ * register\r
+ */\r
+extern uint32_t __get_PRIMASK(void);\r
+\r
+/**\r
+ * @brief Set the Priority Mask value\r
+ *\r
+ * @param uint32_t PriMask\r
+ * @return none\r
+ *\r
+ * Set the priority mask bit in the priority mask register\r
+ */\r
+extern void __set_PRIMASK(uint32_t priMask);\r
+\r
+/**\r
+ * @brief Return the Fault Mask value\r
+ *\r
+ * @param none\r
+ * @return uint32_t FaultMask\r
+ *\r
+ * Return the content of the fault mask register\r
+ */\r
+extern uint32_t __get_FAULTMASK(void);\r
+\r
+/**\r
+ * @brief Set the Fault Mask value\r
+ *\r
+ * @param uint32_t faultMask value\r
+ * @return none\r
+ *\r
+ * Set the fault mask register\r
+ */\r
+extern void __set_FAULTMASK(uint32_t faultMask);\r
+\r
+/**\r
+ * @brief Return the Control Register value\r
+ * \r
+ * @param none\r
+ * @return uint32_t Control value\r
+ *\r
+ * Return the content of the control register\r
+ */\r
+extern uint32_t __get_CONTROL(void);\r
+\r
+/**\r
+ * @brief Set the Control Register value\r
+ *\r
+ * @param uint32_t Control value\r
+ * @return none\r
+ *\r
+ * Set the control register\r
+ */\r
+extern void __set_CONTROL(uint32_t control);\r
+\r
+#else /* (__ARMCC_VERSION >= 400000) */\r
+\r
+\r
+/**\r
+ * @brief Remove the exclusive lock created by ldrex\r
+ *\r
+ * @param none\r
+ * @return none\r
+ *\r
+ * Removes the exclusive lock which is created by ldrex.\r
+ */\r
+#define __CLREX __clrex\r
+\r
+/**\r
+ * @brief Return the Base Priority value\r
+ *\r
+ * @param none\r
+ * @return uint32_t BasePriority\r
+ *\r
+ * Return the content of the base priority register\r
+ */\r
+static __INLINE uint32_t __get_BASEPRI(void)\r
+{\r
+ register uint32_t __regBasePri __ASM("basepri");\r
+ return(__regBasePri);\r
+}\r
+\r
+/**\r
+ * @brief Set the Base Priority value\r
+ *\r
+ * @param uint32_t BasePriority\r
+ * @return none\r
+ *\r
+ * Set the base priority register\r
+ */\r
+static __INLINE void __set_BASEPRI(uint32_t basePri)\r
+{\r
+ register uint32_t __regBasePri __ASM("basepri");\r
+ __regBasePri = (basePri & 0x1ff);\r
+}\r
+\r
+/**\r
+ * @brief Return the Priority Mask value\r
+ *\r
+ * @param none\r
+ * @return uint32_t PriMask\r
+ *\r
+ * Return the state of the priority mask bit from the priority mask\r
+ * register\r
+ */\r
+static __INLINE uint32_t __get_PRIMASK(void)\r
+{\r
+ register uint32_t __regPriMask __ASM("primask");\r
+ return(__regPriMask);\r
+}\r
+\r
+/**\r
+ * @brief Set the Priority Mask value\r
+ *\r
+ * @param uint32_t PriMask\r
+ * @return none\r
+ *\r
+ * Set the priority mask bit in the priority mask register\r
+ */\r
+static __INLINE void __set_PRIMASK(uint32_t priMask)\r
+{\r
+ register uint32_t __regPriMask __ASM("primask");\r
+ __regPriMask = (priMask);\r
+}\r
+\r
+/**\r
+ * @brief Return the Fault Mask value\r
+ *\r
+ * @param none\r
+ * @return uint32_t FaultMask\r
+ *\r
+ * Return the content of the fault mask register\r
+ */\r
+static __INLINE uint32_t __get_FAULTMASK(void)\r
+{\r
+ register uint32_t __regFaultMask __ASM("faultmask");\r
+ return(__regFaultMask);\r
+}\r
+\r
+/**\r
+ * @brief Set the Fault Mask value\r
+ *\r
+ * @param uint32_t faultMask value\r
+ * @return none\r
+ *\r
+ * Set the fault mask register\r
+ */\r
+static __INLINE void __set_FAULTMASK(uint32_t faultMask)\r
+{\r
+ register uint32_t __regFaultMask __ASM("faultmask");\r
+ __regFaultMask = (faultMask & 1);\r
+}\r
+\r
+/**\r
+ * @brief Return the Control Register value\r
+ * \r
+ * @param none\r
+ * @return uint32_t Control value\r
+ *\r
+ * Return the content of the control register\r
+ */\r
+static __INLINE uint32_t __get_CONTROL(void)\r
+{\r
+ register uint32_t __regControl __ASM("control");\r
+ return(__regControl);\r
+}\r
+\r
+/**\r
+ * @brief Set the Control Register value\r
+ *\r
+ * @param uint32_t Control value\r
+ * @return none\r
+ *\r
+ * Set the control register\r
+ */\r
+static __INLINE void __set_CONTROL(uint32_t control)\r
+{\r
+ register uint32_t __regControl __ASM("control");\r
+ __regControl = control;\r
+}\r
+\r
+#endif /* __ARMCC_VERSION */ \r
+\r
+\r
+\r
+#elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/\r
+/* IAR iccarm specific functions */\r
+\r
+#define __enable_irq __enable_interrupt /*!< global Interrupt enable */\r
+#define __disable_irq __disable_interrupt /*!< global Interrupt disable */\r
+\r
+static __INLINE void __enable_fault_irq() { __ASM ("cpsie f"); }\r
+static __INLINE void __disable_fault_irq() { __ASM ("cpsid f"); }\r
+\r
+#define __NOP __no_operation() /*!< no operation intrinsic in IAR Compiler */ \r
+static __INLINE void __WFI() { __ASM ("wfi"); }\r
+static __INLINE void __WFE() { __ASM ("wfe"); }\r
+static __INLINE void __SEV() { __ASM ("sev"); }\r
+static __INLINE void __CLREX() { __ASM ("clrex"); }\r
+\r
+/* intrinsic void __ISB(void) */\r
+/* intrinsic void __DSB(void) */\r
+/* intrinsic void __DMB(void) */\r
+/* intrinsic void __set_PRIMASK(); */\r
+/* intrinsic void __get_PRIMASK(); */\r
+/* intrinsic void __set_FAULTMASK(); */\r
+/* intrinsic void __get_FAULTMASK(); */\r
+/* intrinsic uint32_t __REV(uint32_t value); */\r
+/* intrinsic uint32_t __REVSH(uint32_t value); */\r
+/* intrinsic unsigned long __STREX(unsigned long, unsigned long); */\r
+/* intrinsic unsigned long __LDREX(unsigned long *); */\r
+\r
+\r
+/**\r
+ * @brief Return the Process Stack Pointer\r
+ *\r
+ * @param none\r
+ * @return uint32_t ProcessStackPointer\r
+ *\r
+ * Return the actual process stack pointer\r
+ */\r
+extern uint32_t __get_PSP(void);\r
+\r
+/**\r
+ * @brief Set the Process Stack Pointer\r
+ *\r
+ * @param uint32_t Process Stack Pointer\r
+ * @return none\r
+ *\r
+ * Assign the value ProcessStackPointer to the MSP \r
+ * (process stack pointer) Cortex processor register\r
+ */\r
+extern void __set_PSP(uint32_t topOfProcStack);\r
+\r
+/**\r
+ * @brief Return the Main Stack Pointer\r
+ *\r
+ * @param none\r
+ * @return uint32_t Main Stack Pointer\r
+ *\r
+ * Return the current value of the MSP (main stack pointer)\r
+ * Cortex processor register\r
+ */\r
+extern uint32_t __get_MSP(void);\r
+\r
+/**\r
+ * @brief Set the Main Stack Pointer\r
+ *\r
+ * @param uint32_t Main Stack Pointer\r
+ * @return none\r
+ *\r
+ * Assign the value mainStackPointer to the MSP \r
+ * (main stack pointer) Cortex processor register\r
+ */\r
+extern void __set_MSP(uint32_t topOfMainStack);\r
+\r
+/**\r
+ * @brief Reverse byte order in unsigned short value\r
+ *\r
+ * @param uint16_t value to reverse\r
+ * @return uint32_t reversed value\r
+ *\r
+ * Reverse byte order in unsigned short value\r
+ */\r
+extern uint32_t __REV16(uint16_t value);\r
+\r
+/**\r
+ * @brief Reverse bit order of value\r
+ *\r
+ * @param uint32_t value to reverse\r
+ * @return uint32_t reversed value\r
+ *\r
+ * Reverse bit order of value\r
+ */\r
+extern uint32_t __RBIT(uint32_t value);\r
+\r
+/**\r
+ * @brief LDR Exclusive\r
+ *\r
+ * @param uint8_t* address\r
+ * @return uint8_t value of (*address)\r
+ *\r
+ * Exclusive LDR command\r
+ */\r
+extern uint8_t __LDREXB(uint8_t *addr);\r
+\r
+/**\r
+ * @brief LDR Exclusive\r
+ *\r
+ * @param uint16_t* address\r
+ * @return uint16_t value of (*address)\r
+ *\r
+ * Exclusive LDR command\r
+ */\r
+extern uint16_t __LDREXH(uint16_t *addr);\r
+\r
+/**\r
+ * @brief LDR Exclusive\r
+ *\r
+ * @param uint32_t* address\r
+ * @return uint32_t value of (*address)\r
+ *\r
+ * Exclusive LDR command\r
+ */\r
+extern uint32_t __LDREXW(uint32_t *addr);\r
+\r
+/**\r
+ * @brief STR Exclusive\r
+ *\r
+ * @param uint8_t *address\r
+ * @param uint8_t value to store\r
+ * @return uint32_t successful / failed\r
+ *\r
+ * Exclusive STR command\r
+ */\r
+extern uint32_t __STREXB(uint8_t value, uint8_t *addr);\r
+\r
+/**\r
+ * @brief STR Exclusive\r
+ *\r
+ * @param uint16_t *address\r
+ * @param uint16_t value to store\r
+ * @return uint32_t successful / failed\r
+ *\r
+ * Exclusive STR command\r
+ */\r
+extern uint32_t __STREXH(uint16_t value, uint16_t *addr);\r
+\r
+/**\r
+ * @brief STR Exclusive\r
+ *\r
+ * @param uint32_t *address\r
+ * @param uint32_t value to store\r
+ * @return uint32_t successful / failed\r
+ *\r
+ * Exclusive STR command\r
+ */\r
+extern uint32_t __STREXW(uint32_t value, uint32_t *addr);\r
+\r
+\r
+\r
+#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/\r
+/* GNU gcc specific functions */\r
+\r
+static __INLINE void __enable_irq() { __ASM volatile ("cpsie i"); }\r
+static __INLINE void __disable_irq() { __ASM volatile ("cpsid i"); }\r
+\r
+static __INLINE void __enable_fault_irq() { __ASM volatile ("cpsie f"); }\r
+static __INLINE void __disable_fault_irq() { __ASM volatile ("cpsid f"); }\r
+\r
+static __INLINE void __NOP() { __ASM volatile ("nop"); }\r
+static __INLINE void __WFI() { __ASM volatile ("wfi"); }\r
+static __INLINE void __WFE() { __ASM volatile ("wfe"); }\r
+static __INLINE void __SEV() { __ASM volatile ("sev"); }\r
+static __INLINE void __ISB() { __ASM volatile ("isb"); }\r
+static __INLINE void __DSB() { __ASM volatile ("dsb"); }\r
+static __INLINE void __DMB() { __ASM volatile ("dmb"); }\r
+static __INLINE void __CLREX() { __ASM volatile ("clrex"); }\r
+\r
+\r
+/**\r
+ * @brief Return the Process Stack Pointer\r
+ *\r
+ * @param none\r
+ * @return uint32_t ProcessStackPointer\r
+ *\r
+ * Return the actual process stack pointer\r
+ */\r
+extern uint32_t __get_PSP(void);\r
+\r
+/**\r
+ * @brief Set the Process Stack Pointer\r
+ *\r
+ * @param uint32_t Process Stack Pointer\r
+ * @return none\r
+ *\r
+ * Assign the value ProcessStackPointer to the MSP \r
+ * (process stack pointer) Cortex processor register\r
+ */\r
+extern void __set_PSP(uint32_t topOfProcStack);\r
+\r
+/**\r
+ * @brief Return the Main Stack Pointer\r
+ *\r
+ * @param none\r
+ * @return uint32_t Main Stack Pointer\r
+ *\r
+ * Return the current value of the MSP (main stack pointer)\r
+ * Cortex processor register\r
+ */\r
+extern uint32_t __get_MSP(void);\r
+\r
+/**\r
+ * @brief Set the Main Stack Pointer\r
+ *\r
+ * @param uint32_t Main Stack Pointer\r
+ * @return none\r
+ *\r
+ * Assign the value mainStackPointer to the MSP \r
+ * (main stack pointer) Cortex processor register\r
+ */\r
+extern void __set_MSP(uint32_t topOfMainStack);\r
+\r
+/**\r
+ * @brief Return the Base Priority value\r
+ *\r
+ * @param none\r
+ * @return uint32_t BasePriority\r
+ *\r
+ * Return the content of the base priority register\r
+ */\r
+extern uint32_t __get_BASEPRI(void);\r
+\r
+/**\r
+ * @brief Set the Base Priority value\r
+ *\r
+ * @param uint32_t BasePriority\r
+ * @return none\r
+ *\r
+ * Set the base priority register\r
+ */\r
+extern void __set_BASEPRI(uint32_t basePri);\r
+\r
+/**\r
+ * @brief Return the Priority Mask value\r
+ *\r
+ * @param none\r
+ * @return uint32_t PriMask\r
+ *\r
+ * Return the state of the priority mask bit from the priority mask\r
+ * register\r
+ */\r
+extern uint32_t __get_PRIMASK(void);\r
+\r
+/**\r
+ * @brief Set the Priority Mask value\r
+ *\r
+ * @param uint32_t PriMask\r
+ * @return none\r
+ *\r
+ * Set the priority mask bit in the priority mask register\r
+ */\r
+extern void __set_PRIMASK(uint32_t priMask);\r
+\r
+/**\r
+ * @brief Return the Fault Mask value\r
+ *\r
+ * @param none\r
+ * @return uint32_t FaultMask\r
+ *\r
+ * Return the content of the fault mask register\r
+ */\r
+extern uint32_t __get_FAULTMASK(void);\r
+\r
+/**\r
+ * @brief Set the Fault Mask value\r
+ *\r
+ * @param uint32_t faultMask value\r
+ * @return none\r
+ *\r
+ * Set the fault mask register\r
+ */\r
+extern void __set_FAULTMASK(uint32_t faultMask);\r
+\r
+/**\r
+ * @brief Return the Control Register value\r
+* \r
+* @param none\r
+* @return uint32_t Control value\r
+ *\r
+ * Return the content of the control register\r
+ */\r
+extern uint32_t __get_CONTROL(void);\r
+\r
+/**\r
+ * @brief Set the Control Register value\r
+ *\r
+ * @param uint32_t Control value\r
+ * @return none\r
+ *\r
+ * Set the control register\r
+ */\r
+extern void __set_CONTROL(uint32_t control);\r
+\r
+/**\r
+ * @brief Reverse byte order in integer value\r
+ *\r
+ * @param uint32_t value to reverse\r
+ * @return uint32_t reversed value\r
+ *\r
+ * Reverse byte order in integer value\r
+ */\r
+extern uint32_t __REV(uint32_t value);\r
+\r
+/**\r
+ * @brief Reverse byte order in unsigned short value\r
+ *\r
+ * @param uint16_t value to reverse\r
+ * @return uint32_t reversed value\r
+ *\r
+ * Reverse byte order in unsigned short value\r
+ */\r
+extern uint32_t __REV16(uint16_t value);\r
+\r
+/*\r
+ * Reverse byte order in signed short value with sign extension to integer\r
+ *\r
+ * @param int16_t value to reverse\r
+ * @return int32_t reversed value\r
+ *\r
+ * @brief Reverse byte order in signed short value with sign extension to integer\r
+ */\r
+extern int32_t __REVSH(int16_t value);\r
+\r
+/**\r
+ * @brief Reverse bit order of value\r
+ *\r
+ * @param uint32_t value to reverse\r
+ * @return uint32_t reversed value\r
+ *\r
+ * Reverse bit order of value\r
+ */\r
+extern uint32_t __RBIT(uint32_t value);\r
+\r
+/**\r
+ * @brief LDR Exclusive\r
+ *\r
+ * @param uint8_t* address\r
+ * @return uint8_t value of (*address)\r
+ *\r
+ * Exclusive LDR command\r
+ */\r
+extern uint8_t __LDREXB(uint8_t *addr);\r
+\r
+/**\r
+ * @brief LDR Exclusive\r
+ *\r
+ * @param uint16_t* address\r
+ * @return uint16_t value of (*address)\r
+ *\r
+ * Exclusive LDR command\r
+ */\r
+extern uint16_t __LDREXH(uint16_t *addr);\r
+\r
+/**\r
+ * @brief LDR Exclusive\r
+ *\r
+ * @param uint32_t* address\r
+ * @return uint32_t value of (*address)\r
+ *\r
+ * Exclusive LDR command\r
+ */\r
+extern uint32_t __LDREXW(uint32_t *addr);\r
+\r
+/**\r
+ * @brief STR Exclusive\r
+ *\r
+ * @param uint8_t *address\r
+ * @param uint8_t value to store\r
+ * @return uint32_t successful / failed\r
+ *\r
+ * Exclusive STR command\r
+ */\r
+extern uint32_t __STREXB(uint8_t value, uint8_t *addr);\r
+\r
+/**\r
+ * @brief STR Exclusive\r
+ *\r
+ * @param uint16_t *address\r
+ * @param uint16_t value to store\r
+ * @return uint32_t successful / failed\r
+ *\r
+ * Exclusive STR command\r
+ */\r
+extern uint32_t __STREXH(uint16_t value, uint16_t *addr);\r
+\r
+/**\r
+ * @brief STR Exclusive\r
+ *\r
+ * @param uint32_t *address\r
+ * @param uint32_t value to store\r
+ * @return uint32_t successful / failed\r
+ *\r
+ * Exclusive STR command\r
+ */\r
+extern uint32_t __STREXW(uint32_t value, uint32_t *addr);\r
+\r
+\r
+#elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/\r
+/* TASKING carm specific functions */\r
+\r
+/*\r
+ * The CMSIS functions have been implemented as intrinsics in the compiler.\r
+ * Please use "carm -?i" to get an up to date list of all instrinsics,\r
+ * Including the CMSIS ones.\r
+ */\r
+\r
+#endif\r
+\r
+\r
+\r
+/* ########################## NVIC functions #################################### */\r
+\r
+\r
+/**\r
+ * @brief Set the Priority Grouping in NVIC Interrupt Controller\r
+ *\r
+ * @param uint32_t priority_grouping is priority grouping field\r
+ * @return none \r
+ *\r
+ * Set the priority grouping field using the required unlock sequence.\r
+ * The parameter priority_grouping is assigned to the field \r
+ * SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used.\r
+ * In case of a conflict between priority grouping and available\r
+ * priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.\r
+ */\r
+static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)\r
+{\r
+ uint32_t reg_value;\r
+ uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */\r
+ \r
+ reg_value = SCB->AIRCR; /* read old register configuration */\r
+ reg_value &= ~((0xFFFFU << 16) | (0x0F << 8)); /* clear bits to change */\r
+ reg_value = ((reg_value | NVIC_AIRCR_VECTKEY | (PriorityGroupTmp << 8))); /* Insert write key and priorty group */\r
+ SCB->AIRCR = reg_value;\r
+}\r
+\r
+/**\r
+ * @brief Get the Priority Grouping from NVIC Interrupt Controller\r
+ *\r
+ * @param none\r
+ * @return uint32_t priority grouping field \r
+ *\r
+ * Get the priority grouping from NVIC Interrupt Controller.\r
+ * priority grouping is SCB->AIRCR [10:8] PRIGROUP field.\r
+ */\r
+static __INLINE uint32_t NVIC_GetPriorityGrouping(void)\r
+{\r
+ return ((SCB->AIRCR >> 8) & 0x07); /* read priority grouping field */\r
+}\r
+\r
+/**\r
+ * @brief Enable Interrupt in NVIC Interrupt Controller\r
+ *\r
+ * @param IRQn_Type IRQn specifies the interrupt number\r
+ * @return none \r
+ *\r
+ * Enable a device specific interupt in the NVIC interrupt controller.\r
+ * The interrupt number cannot be a negative value.\r
+ */\r
+static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)\r
+{\r
+ NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */\r
+}\r
+\r
+/**\r
+ * @brief Disable the interrupt line for external interrupt specified\r
+ * \r
+ * @param IRQn_Type IRQn is the positive number of the external interrupt\r
+ * @return none\r
+ * \r
+ * Disable a device specific interupt in the NVIC interrupt controller.\r
+ * The interrupt number cannot be a negative value.\r
+ */\r
+static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)\r
+{\r
+ NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */\r
+}\r
+\r
+/**\r
+ * @brief Read the interrupt pending bit for a device specific interrupt source\r
+ * \r
+ * @param IRQn_Type IRQn is the number of the device specifc interrupt\r
+ * @return uint32_t 1 if pending interrupt else 0\r
+ *\r
+ * Read the pending register in NVIC and return 1 if its status is pending, \r
+ * otherwise it returns 0\r
+ */\r
+static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)\r
+{\r
+ return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */\r
+}\r
+\r
+/**\r
+ * @brief Set the pending bit for an external interrupt\r
+ * \r
+ * @param IRQn_Type IRQn is the Number of the interrupt\r
+ * @return none\r
+ *\r
+ * Set the pending bit for the specified interrupt.\r
+ * The interrupt number cannot be a negative value.\r
+ */\r
+static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)\r
+{\r
+ NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */\r
+}\r
+\r
+/**\r
+ * @brief Clear the pending bit for an external interrupt\r
+ *\r
+ * @param IRQn_Type IRQn is the Number of the interrupt\r
+ * @return none\r
+ *\r
+ * Clear the pending bit for the specified interrupt. \r
+ * The interrupt number cannot be a negative value.\r
+ */\r
+static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)\r
+{\r
+ NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */\r
+}\r
+\r
+/**\r
+ * @brief Read the active bit for an external interrupt\r
+ *\r
+ * @param IRQn_Type IRQn is the Number of the interrupt\r
+ * @return uint32_t 1 if active else 0\r
+ *\r
+ * Read the active register in NVIC and returns 1 if its status is active, \r
+ * otherwise it returns 0.\r
+ */\r
+static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)\r
+{\r
+ return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */\r
+}\r
+\r
+/**\r
+ * @brief Set the priority for an interrupt\r
+ *\r
+ * @param IRQn_Type IRQn is the Number of the interrupt\r
+ * @param priority is the priority for the interrupt\r
+ * @return none\r
+ *\r
+ * Set the priority for the specified interrupt. The interrupt \r
+ * number can be positive to specify an external (device specific) \r
+ * interrupt, or negative to specify an internal (core) interrupt. \n\r
+ *\r
+ * Note: The priority cannot be set for every core interrupt.\r
+ */\r
+static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)\r
+{\r
+ if(IRQn < 0) {\r
+ SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M3 System Interrupts */\r
+ else {\r
+ NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */\r
+}\r
+\r
+/**\r
+ * @brief Read the priority for an interrupt\r
+ *\r
+ * @param IRQn_Type IRQn is the Number of the interrupt\r
+ * @return uint32_t priority is the priority for the interrupt\r
+ *\r
+ * Read the priority for the specified interrupt. The interrupt \r
+ * number can be positive to specify an external (device specific) \r
+ * interrupt, or negative to specify an internal (core) interrupt.\r
+ *\r
+ * The returned priority value is automatically aligned to the implemented\r
+ * priority bits of the microcontroller.\r
+ *\r
+ * Note: The priority cannot be set for every core interrupt.\r
+ */\r
+static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)\r
+{\r
+\r
+ if(IRQn < 0) {\r
+ return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M3 system interrupts */\r
+ else {\r
+ return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */\r
+}\r
+\r
+\r
+/**\r
+ * @brief Encode the priority for an interrupt\r
+ *\r
+ * @param uint32_t PriorityGroup is the used priority group\r
+ * @param uint32_t PreemptPriority is the preemptive priority value (starting from 0)\r
+ * @param uint32_t SubPriority is the sub priority value (starting from 0)\r
+ * @return uint32_t the priority for the interrupt\r
+ *\r
+ * Encode the priority for an interrupt with the given priority group,\r
+ * preemptive priority value and sub priority value.\r
+ * In case of a conflict between priority grouping and available\r
+ * priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.\r
+ *\r
+ * The returned priority value can be used for NVIC_SetPriority(...) function\r
+ */\r
+static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)\r
+{\r
+ uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */\r
+ uint32_t PreemptPriorityBits;\r
+ uint32_t SubPriorityBits;\r
+\r
+ PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;\r
+ SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;\r
+ \r
+ return (\r
+ ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |\r
+ ((SubPriority & ((1 << (SubPriorityBits )) - 1)))\r
+ );\r
+}\r
+\r
+\r
+/**\r
+ * @brief Decode the priority of an interrupt\r
+ *\r
+ * @param uint32_t Priority the priority for the interrupt\r
+ * @param uint32_t PrioGroup is the used priority group\r
+ * @param uint32_t* pPreemptPrio is the preemptive priority value (starting from 0)\r
+ * @param uint32_t* pSubPrio is the sub priority value (starting from 0)\r
+ * @return none\r
+ *\r
+ * Decode an interrupt priority value with the given priority group to \r
+ * preemptive priority value and sub priority value.\r
+ * In case of a conflict between priority grouping and available\r
+ * priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.\r
+ *\r
+ * The priority value can be retrieved with NVIC_GetPriority(...) function\r
+ */\r
+static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)\r
+{\r
+ uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */\r
+ uint32_t PreemptPriorityBits;\r
+ uint32_t SubPriorityBits;\r
+\r
+ PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;\r
+ SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;\r
+ \r
+ *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);\r
+ *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);\r
+}\r
+\r
+\r
+\r
+/* ################################## SysTick function ############################################ */\r
+\r
+#if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)\r
+\r
+/* SysTick constants */\r
+#define SYSTICK_ENABLE 0 /* Config-Bit to start or stop the SysTick Timer */\r
+#define SYSTICK_TICKINT 1 /* Config-Bit to enable or disable the SysTick interrupt */\r
+#define SYSTICK_CLKSOURCE 2 /* Clocksource has the offset 2 in SysTick Control and Status Register */\r
+#define SYSTICK_MAXCOUNT ((1<<24) -1) /* SysTick MaxCount */\r
+\r
+/**\r
+ * @brief Initialize and start the SysTick counter and its interrupt.\r
+ *\r
+ * @param uint32_t ticks is the number of ticks between two interrupts\r
+ * @return none\r
+ *\r
+ * Initialise the system tick timer and its interrupt and start the\r
+ * system tick timer / counter in free running mode to generate \r
+ * periodical interrupts.\r
+ */\r
+static __INLINE uint32_t SysTick_Config(uint32_t ticks)\r
+{ \r
+ if (ticks > SYSTICK_MAXCOUNT) return (1); /* Reload value impossible */\r
+\r
+ SysTick->LOAD = (ticks & SYSTICK_MAXCOUNT) - 1; /* set reload register */\r
+ NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */\r
+ SysTick->VAL = (0x00); /* Load the SysTick Counter Value */\r
+ SysTick->CTRL = (1 << SYSTICK_CLKSOURCE) | (1<<SYSTICK_ENABLE) | (1<<SYSTICK_TICKINT); /* Enable SysTick IRQ and SysTick Timer */\r
+ return (0); /* Function successful */\r
+}\r
+\r
+#endif\r
+\r
+\r
+\r
+\r
+\r
+/* ################################## Reset function ############################################ */\r
+\r
+/**\r
+ * @brief Initiate a system reset request.\r
+ *\r
+ * @param none\r
+ * @return none\r
+ *\r
+ * Initialize a system reset request to reset the MCU\r
+ */\r
+static __INLINE void NVIC_SystemReset(void)\r
+{\r
+ SCB->AIRCR = (NVIC_AIRCR_VECTKEY | (SCB->AIRCR & (0x700)) | (1<<NVIC_SYSRESETREQ)); /* Keep priority group unchanged */\r
+ __DSB(); /* Ensure completion of memory access */ \r
+ while(1); /* wait until reset */\r
+}\r
+\r
+\r
+/* ################################## Debug Output function ############################################ */\r
+\r
+\r
+/**\r
+ * @brief Outputs a character via the ITM channel 0\r
+ *\r
+ * @param uint32_t character to output\r
+ * @return uint32_t input character\r
+ *\r
+ * The function outputs a character via the ITM channel 0. \r
+ * The function returns when no debugger is connected that has booked the output. \r
+ * It is blocking when a debugger is connected, but the previous character send is not transmitted. \r
+ */\r
+static __INLINE uint32_t ITM_SendChar (uint32_t ch)\r
+{\r
+ if (ch == '\n') ITM_SendChar('\r');\r
+ \r
+ if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) &&\r
+ (ITM->TCR & ITM_TCR_ITMENA) &&\r
+ (ITM->TER & (1UL << 0)) ) \r
+ {\r
+ while (ITM->PORT[0].u32 == 0);\r
+ ITM->PORT[0].u8 = (uint8_t) ch;\r
+ } \r
+ return (ch);\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __CM3_CORE_H__ */\r
+\r
+/*lint -restore */\r
--- /dev/null
+//*****************************************************************************\r
+// +--+ \r
+// | ++----+ \r
+// +-++ | \r
+// | | \r
+// +-+--+ | \r
+// | +--+--+ \r
+// +----+ Copyright (c) 2009 Code Red Technologies Ltd. \r
+//\r
+// Microcontroller Startup code for use with Red Suite\r
+//\r
+// Software License Agreement\r
+// \r
+// The software is owned by Code Red Technologies and/or its suppliers, and is \r
+// protected under applicable copyright laws. All rights are reserved. Any \r
+// use in violation of the foregoing restrictions may subject the user to criminal \r
+// sanctions under applicable laws, as well as to civil liability for the breach \r
+// of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT\r
+// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH\r
+// CODE RED TECHNOLOGIES LTD. \r
+//\r
+//*****************************************************************************\r
+#define WEAK __attribute__ ((weak))\r
+#define ALIAS(f) __attribute__ ((weak, alias (#f)))\r
+\r
+//*****************************************************************************\r
+//\r
+// Forward declaration of the default handlers.\r
+//\r
+//*****************************************************************************\r
+void Reset_Handler(void);\r
+void ResetISR(void) ALIAS(Reset_Handler);\r
+static void NMI_Handler(void);\r
+static void HardFault_Handler(void);\r
+static void MemManage_Handler(void);\r
+static void BusFault_Handler(void);\r
+static void UsageFault_Handler(void);\r
+static void DebugMon_Handler(void);\r
+\r
+//*****************************************************************************\r
+//\r
+// Forward declaration of the specific IRQ handlers. These are aliased\r
+// to the IntDefaultHandler, which is a 'forever' loop. When the application\r
+// defines a handler (with the same name), this will automatically take \r
+// precedence over these weak definitions\r
+//\r
+//*****************************************************************************\r
+void WDT_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void TIMER0_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void TIMER1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void TIMER2_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void TIMER3_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void UART0_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void UART1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void UART2_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void UART3_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void PWM1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void I2C1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void I2C2_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void SPI_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void SSP0_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void SSP1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void PLL0_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void RTC_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void EINT0_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void EINT1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void EINT2_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void EINT3_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void ADC_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void BOD_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void USB_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void CAN_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void DMA_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void I2S_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void ENET_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void RIT_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void MCPWM_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void QEI_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+void PLL1_IRQHandler(void) ALIAS(IntDefaultHandler);\r
+\r
+extern void xPortSysTickHandler(void);\r
+extern void xPortPendSVHandler(void);\r
+extern void vPortSVCHandler( void );\r
+extern void vEMAC_ISR( void );\r
+\r
+\r
+//*****************************************************************************\r
+//\r
+// The entry point for the C++ library startup\r
+//\r
+//*****************************************************************************\r
+extern WEAK void __libc_init_array(void);\r
+\r
+//*****************************************************************************\r
+//\r
+// The entry point for the application.\r
+// __main() is the entry point for redlib based applications\r
+// main() is the entry point for newlib based applications\r
+//\r
+//*****************************************************************************\r
+extern WEAK void __main(void);\r
+extern WEAK void main(void);\r
+//*****************************************************************************\r
+//\r
+// External declaration for the pointer to the stack top from the Linker Script\r
+//\r
+//*****************************************************************************\r
+extern void _vStackTop;\r
+\r
+//*****************************************************************************\r
+//\r
+// The vector table.\r
+// This relies on the linker script to place at correct location in memory.\r
+//\r
+//*****************************************************************************\r
+__attribute__ ((section(".isr_vector")))\r
+void (* const g_pfnVectors[])(void) =\r
+{\r
+ // Core Level - CM3\r
+ (void *)&_vStackTop, // The initial stack pointer\r
+ Reset_Handler, // The reset handler\r
+ NMI_Handler, // The NMI handler\r
+ HardFault_Handler, // The hard fault handler\r
+ MemManage_Handler, // The MPU fault handler\r
+ BusFault_Handler, // The bus fault handler\r
+ UsageFault_Handler, // The usage fault handler\r
+ 0, // Reserved\r
+ 0, // Reserved\r
+ 0, // Reserved\r
+ 0, // Reserved\r
+ vPortSVCHandler, // SVCall handler\r
+ DebugMon_Handler, // Debug monitor handler\r
+ 0, // Reserved\r
+ xPortPendSVHandler, // The PendSV handler\r
+ xPortSysTickHandler, // The SysTick handler\r
+\r
+ // Chip Level - LPC17\r
+ WDT_IRQHandler, // 16, 0x40 - WDT\r
+ TIMER0_IRQHandler, // 17, 0x44 - TIMER0\r
+ TIMER1_IRQHandler, // 18, 0x48 - TIMER1\r
+ TIMER2_IRQHandler, // 19, 0x4c - TIMER2\r
+ TIMER3_IRQHandler, // 20, 0x50 - TIMER3\r
+ UART0_IRQHandler, // 21, 0x54 - UART0\r
+ UART1_IRQHandler, // 22, 0x58 - UART1\r
+ UART2_IRQHandler, // 23, 0x5c - UART2\r
+ UART3_IRQHandler, // 24, 0x60 - UART3\r
+ PWM1_IRQHandler, // 25, 0x64 - PWM1\r
+ I2C0_IRQHandler, // 26, 0x68 - I2C0\r
+ I2C1_IRQHandler, // 27, 0x6c - I2C1\r
+ I2C2_IRQHandler, // 28, 0x70 - I2C2\r
+ SPI_IRQHandler, // 29, 0x74 - SPI\r
+ SSP0_IRQHandler, // 30, 0x78 - SSP0\r
+ SSP1_IRQHandler, // 31, 0x7c - SSP1\r
+ PLL0_IRQHandler, // 32, 0x80 - PLL0 (Main PLL)\r
+ RTC_IRQHandler, // 33, 0x84 - RTC\r
+ EINT0_IRQHandler, // 34, 0x88 - EINT0\r
+ EINT1_IRQHandler, // 35, 0x8c - EINT1\r
+ EINT2_IRQHandler, // 36, 0x90 - EINT2\r
+ EINT3_IRQHandler, // 37, 0x94 - EINT3\r
+ ADC_IRQHandler, // 38, 0x98 - ADC\r
+ BOD_IRQHandler, // 39, 0x9c - BOD\r
+ USB_IRQHandler, // 40, 0xA0 - USB\r
+ CAN_IRQHandler, // 41, 0xa4 - CAN\r
+ DMA_IRQHandler, // 42, 0xa8 - GP DMA\r
+ I2S_IRQHandler, // 43, 0xac - I2S\r
+ vEMAC_ISR, // Ethernet.\r
+ RIT_IRQHandler, // 45, 0xb4 - RITINT\r
+ MCPWM_IRQHandler, // 46, 0xb8 - Motor Control PWM\r
+ QEI_IRQHandler, // 47, 0xbc - Quadrature Encoder\r
+ PLL1_IRQHandler, // 48, 0xc0 - PLL1 (USB PLL)\r
+};\r
+\r
+//*****************************************************************************\r
+//\r
+// The following are constructs created by the linker, indicating where the\r
+// the "data" and "bss" segments reside in memory. The initializers for the\r
+// for the "data" segment resides immediately following the "text" segment.\r
+//\r
+//*****************************************************************************\r
+extern unsigned long _etext;\r
+extern unsigned long _data;\r
+extern unsigned long _edata;\r
+extern unsigned long _bss;\r
+extern unsigned long _ebss;\r
+\r
+//*****************************************************************************\r
+// Reset entry point for your code.\r
+// Sets up a simple runtime environment and initializes the C/C++\r
+// library.\r
+//\r
+//*****************************************************************************\r
+void Reset_Handler(void)\r
+{\r
+ unsigned long *pulSrc, *pulDest;\r
+\r
+ //\r
+ // Copy the data segment initializers from flash to SRAM.\r
+ //\r
+ pulSrc = &_etext;\r
+ for(pulDest = &_data; pulDest < &_edata; )\r
+ {\r
+ *pulDest++ = *pulSrc++;\r
+ }\r
+\r
+ //\r
+ // Zero fill the bss segment. This is done with inline assembly since this\r
+ // will clear the value of pulDest if it is not kept in a register.\r
+ //\r
+ __asm(" ldr r0, =_bss\n"\r
+ " ldr r1, =_ebss\n"\r
+ " mov r2, #0\n"\r
+ " .thumb_func\n"\r
+ "zero_loop:\n"\r
+ " cmp r0, r1\n"\r
+ " it lt\n"\r
+ " strlt r2, [r0], #4\n"\r
+ " blt zero_loop");\r
+\r
+ //\r
+ // Call C++ library initilisation, if present\r
+ //\r
+ if (__libc_init_array)\r
+ __libc_init_array() ;\r
+\r
+ //\r
+ // Call the application's entry point.\r
+ // __main() is the entry point for redlib based applications (which calls main())\r
+ // main() is the entry point for newlib based applications\r
+ //\r
+ if (__main)\r
+ __main() ;\r
+ else\r
+ main() ;\r
+\r
+ //\r
+ // main() shouldn't return, but if it does, we'll just enter an infinite loop \r
+ //\r
+ while (1) {\r
+ ;\r
+ }\r
+}\r
+\r
+//*****************************************************************************\r
+//\r
+// This is the code that gets called when the processor receives a NMI. This\r
+// simply enters an infinite loop, preserving the system state for examination\r
+// by a debugger.\r
+//\r
+//*****************************************************************************\r
+static void NMI_Handler(void)\r
+{\r
+ while(1)\r
+ {\r
+ }\r
+}\r
+\r
+static void HardFault_Handler(void)\r
+{\r
+ while(1)\r
+ {\r
+ }\r
+}\r
+\r
+static void MemManage_Handler(void)\r
+{\r
+ while(1)\r
+ {\r
+ }\r
+}\r
+\r
+static void BusFault_Handler(void)\r
+{\r
+ while(1)\r
+ {\r
+ }\r
+}\r
+\r
+static void UsageFault_Handler(void)\r
+{\r
+ while(1)\r
+ {\r
+ }\r
+}\r
+\r
+static void DebugMon_Handler(void)\r
+{\r
+ while(1)\r
+ {\r
+ }\r
+}\r
+\r
+//*****************************************************************************\r
+//\r
+// Processor ends up here if an unexpected interrupt occurs or a handler\r
+// is not present in the application code.\r
+//\r
+//*****************************************************************************\r
+static void IntDefaultHandler(void)\r
+{\r
+ //\r
+ // Go into an infinite loop.\r
+ //\r
+ while(1)\r
+ {\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it\r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
+ **NOTE** The exception to the GPL is included to allow you to distribute a\r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
+ the source code for any proprietary components. Alternative commercial\r
+ license and support terms are also available upon request. See the\r
+ licensing section of http://www.FreeRTOS.org for full details.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details.\r
+\r
+ You should have received a copy of the GNU General Public License along\r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ Please ensure to read the configuration and relevant port sections of the\r
+ online documentation.\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+\r
+/*\r
+ * Creates all the demo application tasks, then starts the scheduler. The WEB\r
+ * documentation provides more details of the standard demo application tasks\r
+ * (which just exist to test the kernel port and provide an example of how to use\r
+ * each FreeRTOS API function).\r
+ *\r
+ * In addition to the standard demo tasks, the following tasks and tests are\r
+ * defined and/or created within this file:\r
+ *\r
+ * "Check" hook - This only executes fully every five seconds from the tick\r
+ * hook. Its main function is to check that all the standard demo tasks are\r
+ * still operational. The status can be viewed using on the Task Stats page\r
+ * served by the WEB server.\r
+ *\r
+ * "uIP" task - This is the task that handles the uIP stack. All TCP/IP\r
+ * processing is performed in this task.\r
+ */\r
+\r
+/* Standard includes. */\r
+#include "stdio.h"\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+/* Demo app includes. */\r
+#include "BlockQ.h"\r
+#include "integer.h"\r
+#include "blocktim.h"\r
+#include "flash.h"\r
+#include "partest.h"\r
+#include "semtest.h"\r
+#include "PollQ.h"\r
+#include "GenQTest.h"\r
+#include "QPeek.h"\r
+#include "recmutex.h"\r
+\r
+/* Red Suite includes. */\r
+#include "lcd_driver.h"\r
+#include "lcd.h"\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The time between cycles of the 'check' functionality (defined within the\r
+tick hook. */\r
+#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
+\r
+/* Task priorities. */\r
+#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainUIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
+#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
+#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
+#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+\r
+/* The WEB server has a larger stack as it utilises stack hungry string\r
+handling library calls. */\r
+#define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 4 )\r
+\r
+/* The message displayed by the WEB server when all tasks are executing\r
+without an error being reported. */\r
+#define mainPASS_STATUS_MESSAGE "All tasks are executing without error."\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Configure the hardware for the demo.\r
+ */\r
+static void prvSetupHardware( void );\r
+\r
+/*\r
+ * The task that handles the uIP stack. All TCP/IP processing is performed in\r
+ * this task.\r
+ */\r
+extern void vuIP_Task( void *pvParameters );\r
+\r
+/*\r
+ * Simply returns the current status message for display on served WEB pages.\r
+ */\r
+char *pcGetTaskStatusMessage( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Holds the status message displayed by the WEB server. */\r
+static char *pcStatusMessage = mainPASS_STATUS_MESSAGE;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+int main( void )\r
+{\r
+char cIPAddress[ 16 ]; /* Enough space for "xxx.xxx.xxx.xxx\0". */\r
+\r
+ /* Configure the hardware for use by this demo. */\r
+ prvSetupHardware();\r
+\r
+ /* Start the standard demo tasks. These are just here to exercise the\r
+ kernel port and provide examples of how the FreeRTOS API can be used. */\r
+ vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
+ vCreateBlockTimeTasks();\r
+ vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+ vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
+ vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
+ vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
+ vStartQueuePeekTasks();\r
+ vStartRecursiveMutexTasks();\r
+ vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
+\r
+ /* Display the IP address, then create the uIP task. The WEB server runs \r
+ in this task. */\r
+ LCDdriver_initialisation();\r
+ LCD_PrintString( 5, 10, "FreeRTOS.org", 14, COLOR_GREEN);\r
+ sprintf( cIPAddress, "%d.%d.%d.%d", configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
+ LCD_PrintString( 5, 30, cIPAddress, 14, COLOR_RED);\r
+ xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );\r
+\r
+ /* Start the scheduler. */\r
+ vTaskStartScheduler();\r
+\r
+ /* Will only get here if there was insufficient memory to create the idle\r
+ task. The idle task is created within vTaskStartScheduler(). */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationTickHook( void )\r
+{\r
+static unsigned portLONG ulTicksSinceLastDisplay = 0;\r
+\r
+ /* Called from every tick interrupt as described in the comments at the top\r
+ of this file.\r
+\r
+ Have enough ticks passed to make it time to perform our health status\r
+ check again? */\r
+ ulTicksSinceLastDisplay++;\r
+ if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )\r
+ {\r
+ /* Reset the counter so these checks run again in mainCHECK_DELAY\r
+ ticks time. */\r
+ ulTicksSinceLastDisplay = 0;\r
+\r
+ /* Has an error been found in any task? */\r
+ if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Generic Queue test/demo.";\r
+ }\r
+ else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Peek Queue test/demo.";\r
+ }\r
+ else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Block Queue test/demo.";\r
+ }\r
+ else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Block Time test/demo.";\r
+ }\r
+ else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Semaphore test/demo.";\r
+ }\r
+ else if( xArePollingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Poll Queue test/demo.";\r
+ }\r
+ else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Int Math test/demo.";\r
+ }\r
+ else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "An error has been detected in the Mutex test/demo.";\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+char *pcGetTaskStatusMessage( void )\r
+{\r
+ /* Not bothered about a critical section here. */\r
+ return pcStatusMessage;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void prvSetupHardware( void )\r
+{\r
+ /* Disable peripherals power. */\r
+ SC->PCONP = 0;\r
+\r
+ /* Enable GPIO power. */\r
+ SC->PCONP = PCONP_PCGPIO;\r
+\r
+ /* Disable TPIU. */\r
+ PINCON->PINSEL10 = 0;\r
+\r
+ /* Disconnect the main PLL. */\r
+ SC->PLL0CON &= ~PLLCON_PLLC;\r
+ SC->PLL0FEED = PLLFEED_FEED1;\r
+ SC->PLL0FEED = PLLFEED_FEED2;\r
+ while ((SC->PLL0STAT & PLLSTAT_PLLC) != 0);\r
+\r
+ /* Turn off the main PLL. */\r
+ SC->PLL0CON &= ~PLLCON_PLLE;\r
+ SC->PLL0FEED = PLLFEED_FEED1;\r
+ SC->PLL0FEED = PLLFEED_FEED2;\r
+ while ((SC->PLL0STAT & PLLSTAT_PLLE) != 0);\r
+\r
+ /* No CPU clock divider. */\r
+ SC->CCLKCFG = 0;\r
+\r
+ /* OSCEN. */\r
+ SC->SCS = 0x20;\r
+ while ((SC->SCS & 0x40) == 0);\r
+\r
+ /* Use main oscillator. */\r
+ SC->CLKSRCSEL = 1;\r
+ SC->PLL0CFG = (PLLCFG_MUL16 | PLLCFG_DIV1);\r
+\r
+ SC->PLL0FEED = PLLFEED_FEED1;\r
+ SC->PLL0FEED = PLLFEED_FEED2;\r
+\r
+ /* Activate the PLL by turning it on then feeding the correct\r
+ sequence of bytes. */\r
+ SC->PLL0CON = PLLCON_PLLE;\r
+ SC->PLL0FEED = PLLFEED_FEED1;\r
+ SC->PLL0FEED = PLLFEED_FEED2;\r
+\r
+ /* 6x CPU clock divider (64 MHz) */\r
+ SC->CCLKCFG = 5;\r
+\r
+ /* Wait for the PLL to lock. */\r
+ while ((SC->PLL0STAT & PLLSTAT_PLOCK) == 0);\r
+\r
+ /* Connect the PLL. */\r
+ SC->PLL0CON = PLLCON_PLLC | PLLCON_PLLE;\r
+ SC->PLL0FEED = PLLFEED_FEED1;\r
+ SC->PLL0FEED = PLLFEED_FEED2;\r
+\r
+ /* Setup the peripheral bus to be the same as the PLL output (64 MHz). */\r
+ SC->PCLKSEL0 = 0x05555555;\r
+\r
+ /* Configure the LEDs. */\r
+ vParTestInitialise();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
+{\r
+ /* This function will get called if a task overflows its stack. */\r
+\r
+ ( void ) pxTask;\r
+ ( void ) pcTaskName;\r
+\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vConfigureTimerForRunTimeStats( void )\r
+{\r
+const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;\r
+\r
+ /* This function configures a timer that is used as the time base when\r
+ collecting run time statistical information - basically the percentage\r
+ of CPU time that each task is utilising. It is called automatically when\r
+ the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set\r
+ to 1). */\r
+\r
+ /* Power up and feed the timer. */\r
+ SC->PCONP |= 0x02UL;\r
+ SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);\r
+\r
+ /* Reset Timer 0 */\r
+ TIM0->TCR = TCR_COUNT_RESET;\r
+\r
+ /* Just count up. */\r
+ TIM0->CTCR = CTCR_CTM_TIMER;\r
+\r
+ /* Prescale to a frequency that is good enough to get a decent resolution,\r
+ but not too fast so as to overflow all the time. */\r
+ TIM0->PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;\r
+\r
+ /* Start the counter. */\r
+ TIM0->TCR = TCR_COUNT_ENABLE;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
--- /dev/null
+/*\r
+ Copyright 2001, 2002 Georges Menie (www.menie.org)\r
+ stdarg version contributed by Christian Ettinger\r
+\r
+ This program is free software; you can redistribute it and/or modify\r
+ it under the terms of the GNU Lesser General Public License as published by\r
+ the Free Software Foundation; either version 2 of the License, or\r
+ (at your option) any later version.\r
+\r
+ This program is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU Lesser General Public License for more details.\r
+\r
+ You should have received a copy of the GNU Lesser General Public License\r
+ along with this program; if not, write to the Free Software\r
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*/\r
+\r
+/*\r
+ putchar is the only external dependency for this file,\r
+ if you have a working putchar, leave it commented out.\r
+ If not, uncomment the define below and\r
+ replace outbyte(c) by your own function call.\r
+\r
+*/\r
+\r
+#define putchar(c) c\r
+\r
+#include <stdarg.h>\r
+\r
+static void printchar(char **str, int c)\r
+{\r
+ //extern int putchar(int c);\r
+ \r
+ if (str) {\r
+ **str = (char)c;\r
+ ++(*str);\r
+ }\r
+ else\r
+ { \r
+ (void)putchar(c);\r
+ }\r
+}\r
+\r
+#define PAD_RIGHT 1\r
+#define PAD_ZERO 2\r
+\r
+static int prints(char **out, const char *string, int width, int pad)\r
+{\r
+ register int pc = 0, padchar = ' ';\r
+\r
+ if (width > 0) {\r
+ register int len = 0;\r
+ register const char *ptr;\r
+ for (ptr = string; *ptr; ++ptr) ++len;\r
+ if (len >= width) width = 0;\r
+ else width -= len;\r
+ if (pad & PAD_ZERO) padchar = '0';\r
+ }\r
+ if (!(pad & PAD_RIGHT)) {\r
+ for ( ; width > 0; --width) {\r
+ printchar (out, padchar);\r
+ ++pc;\r
+ }\r
+ }\r
+ for ( ; *string ; ++string) {\r
+ printchar (out, *string);\r
+ ++pc;\r
+ }\r
+ for ( ; width > 0; --width) {\r
+ printchar (out, padchar);\r
+ ++pc;\r
+ }\r
+\r
+ return pc;\r
+}\r
+\r
+/* the following should be enough for 32 bit int */\r
+#define PRINT_BUF_LEN 12\r
+\r
+static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase)\r
+{\r
+ char print_buf[PRINT_BUF_LEN];\r
+ register char *s;\r
+ register int t, neg = 0, pc = 0;\r
+ register unsigned int u = (unsigned int)i;\r
+\r
+ if (i == 0) {\r
+ print_buf[0] = '0';\r
+ print_buf[1] = '\0';\r
+ return prints (out, print_buf, width, pad);\r
+ }\r
+\r
+ if (sg && b == 10 && i < 0) {\r
+ neg = 1;\r
+ u = (unsigned int)-i;\r
+ }\r
+\r
+ s = print_buf + PRINT_BUF_LEN-1;\r
+ *s = '\0';\r
+\r
+ while (u) {\r
+ t = (unsigned int)u % b;\r
+ if( t >= 10 )\r
+ t += letbase - '0' - 10;\r
+ *--s = (char)(t + '0');\r
+ u /= b;\r
+ }\r
+\r
+ if (neg) {\r
+ if( width && (pad & PAD_ZERO) ) {\r
+ printchar (out, '-');\r
+ ++pc;\r
+ --width;\r
+ }\r
+ else {\r
+ *--s = '-';\r
+ }\r
+ }\r
+\r
+ return pc + prints (out, s, width, pad);\r
+}\r
+\r
+static int print( char **out, const char *format, va_list args )\r
+{\r
+ register int width, pad;\r
+ register int pc = 0;\r
+ char scr[2];\r
+\r
+ for (; *format != 0; ++format) {\r
+ if (*format == '%') {\r
+ ++format;\r
+ width = pad = 0;\r
+ if (*format == '\0') break;\r
+ if (*format == '%') goto out;\r
+ if (*format == '-') {\r
+ ++format;\r
+ pad = PAD_RIGHT;\r
+ }\r
+ while (*format == '0') {\r
+ ++format;\r
+ pad |= PAD_ZERO;\r
+ }\r
+ for ( ; *format >= '0' && *format <= '9'; ++format) {\r
+ width *= 10;\r
+ width += *format - '0';\r
+ }\r
+ if( *format == 's' ) {\r
+ register char *s = (char *)va_arg( args, int );\r
+ pc += prints (out, s?s:"(null)", width, pad);\r
+ continue;\r
+ }\r
+ if( *format == 'd' ) {\r
+ pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');\r
+ continue;\r
+ }\r
+ if( *format == 'x' ) {\r
+ pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');\r
+ continue;\r
+ }\r
+ if( *format == 'X' ) {\r
+ pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');\r
+ continue;\r
+ }\r
+ if( *format == 'u' ) {\r
+ pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');\r
+ continue;\r
+ }\r
+ if( *format == 'c' ) {\r
+ /* char are converted to int then pushed on the stack */\r
+ scr[0] = (char)va_arg( args, int );\r
+ scr[1] = '\0';\r
+ pc += prints (out, scr, width, pad);\r
+ continue;\r
+ }\r
+ }\r
+ else {\r
+ out:\r
+ printchar (out, *format);\r
+ ++pc;\r
+ }\r
+ }\r
+ if (out) **out = '\0';\r
+ va_end( args );\r
+ return pc;\r
+}\r
+\r
+int printf(const char *format, ...)\r
+{\r
+ va_list args;\r
+ \r
+ va_start( args, format );\r
+ return print( 0, format, args );\r
+}\r
+\r
+int sprintf(char *out, const char *format, ...)\r
+{\r
+ va_list args;\r
+ \r
+ va_start( args, format );\r
+ return print( &out, format, args );\r
+}\r
+\r
+\r
+int snprintf( char *buf, unsigned int count, const char *format, ... )\r
+{\r
+ va_list args;\r
+ \r
+ ( void ) count;\r
+ \r
+ va_start( args, format );\r
+ return print( &buf, format, args );\r
+}\r
+\r
+\r
+#ifdef TEST_PRINTF\r
+int main(void)\r
+{\r
+ char *ptr = "Hello world!";\r
+ char *np = 0;\r
+ int i = 5;\r
+ unsigned int bs = sizeof(int)*8;\r
+ int mi;\r
+ char buf[80];\r
+\r
+ mi = (1 << (bs-1)) + 1;\r
+ printf("%s\n", ptr);\r
+ printf("printf test\n");\r
+ printf("%s is null pointer\n", np);\r
+ printf("%d = 5\n", i);\r
+ printf("%d = - max int\n", mi);\r
+ printf("char %c = 'a'\n", 'a');\r
+ printf("hex %x = ff\n", 0xff);\r
+ printf("hex %02x = 00\n", 0);\r
+ printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);\r
+ printf("%d %s(s)%", 0, "message");\r
+ printf("\n");\r
+ printf("%d %s(s) with %%\n", 0, "message");\r
+ sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);\r
+ sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);\r
+ sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);\r
+ sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);\r
+ sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);\r
+ sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);\r
+ sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);\r
+ sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);\r
+\r
+ return 0;\r
+}\r
+\r
+/*\r
+ * if you compile this file with\r
+ * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c\r
+ * you will get a normal warning:\r
+ * printf.c:214: warning: spurious trailing `%' in format\r
+ * this line is testing an invalid % at the end of the format string.\r
+ *\r
+ * this should display (on 32bit int machine) :\r
+ *\r
+ * Hello world!\r
+ * printf test\r
+ * (null) is null pointer\r
+ * 5 = 5\r
+ * -2147483647 = - max int\r
+ * char a = 'a'\r
+ * hex ff = ff\r
+ * hex 00 = 00\r
+ * signed -3 = unsigned 4294967293 = hex fffffffd\r
+ * 0 message(s)\r
+ * 0 message(s) with %\r
+ * justif: "left "\r
+ * justif: " right"\r
+ * 3: 0003 zero padded\r
+ * 3: 3 left justif.\r
+ * 3: 3 right justif.\r
+ * -3: -003 zero padded\r
+ * -3: -3 left justif.\r
+ * -3: -3 right justif.\r
+ */\r
+\r
+#endif\r
+\r
+\r
+/* To keep linker happy. */\r
+int write( int i, char* c, int n)\r
+{\r
+ (void)i;\r
+ (void)n;\r
+ (void)c;\r
+ return 0;\r
+}\r
+\r
--- /dev/null
+/*\r
+ * GENERATED FILE - DO NOT EDIT\r
+ * (C) Code Red Technologies Ltd, 2008-9 \r
+ * Generated C linker script file for LPC1768 \r
+ * (created from nxp_lpc13_c.ld (v2.0.11 (200907061347)) on Thu Jul 09 12:44:31 BST 2009)\r
+*/\r
+\r
+INCLUDE "rtosdemo_rdb1768_Debug_lib.ld "
+INCLUDE "rtosdemo_rdb1768_Debug_mem.ld "\r
+\r
+ENTRY(ResetISR)\r
+\r
+SECTIONS\r
+{\r
+ .text :\r
+ {\r
+ KEEP(*(.isr_vector))\r
+ *(.text*)\r
+ *(.rodata*)\r
+\r
+ } > FLASH\r
+\r
+\r
+ /* for exception handling/unwind - some Newlib functions (in common with C++ and STDC++) use this. */\r
+ \r
+ .ARM.extab : \r
+ {\r
+ *(.ARM.extab* .gnu.linkonce.armextab.*)\r
+ } > FLASH\r
+\r
+ __exidx_start = .;\r
+ .ARM.exidx :\r
+ {\r
+ *(.ARM.exidx* .gnu.linkonce.armexidx.*)\r
+ } > FLASH\r
+ __exidx_end = .;\r
+\r
+ _etext = .;\r
+ \r
+ .data : AT (__exidx_end)\r
+ {\r
+ _data = .;\r
+ *(vtable)\r
+ *(.data*)\r
+ _edata = .;\r
+ } > SRAM\r
+\r
+ /* zero initialized data */\r
+ .bss :\r
+ {\r
+ _bss = .;\r
+ *(.bss*)\r
+ *(COMMON)\r
+ _ebss = .;\r
+ } > SRAM\r
+ \r
+ /* Where we put the heap with cr_clib */\r
+ .cr_heap :\r
+ {\r
+ end = .;\r
+ _pvHeapStart = .;\r
+ } > SRAM\r
+\r
+/*\r
+ Note: (ref: M0000066)\r
+ Moving the stack down by 16 is to work around a GDB bug.\r
+ This space can be reclaimed for Production Builds.\r
+*/ \r
+ _vStackTop = _vRamTop - 16;\r
+ \r
+ .ETHRAM :\r
+ {\r
+ } > AHBRAM0\r
+ \r
+ .USBRAM :\r
+ {\r
+ } > AHBRAM1\r
+}\r
--- /dev/null
+/*\r
+ * GENERATED FILE - DO NOT EDIT\r
+ * (C) Code Red Technologies Ltd, 2008-9\r
+ * Generated linker script library include file for Newlib (none) \r
+ * (created from newlib_none_c.ld (v2.0.11 (200907061347)) on Thu Jul 09 13:02:36 BST 2009)\r
+*/\r
+\r
+GROUP(libgcc.a libc.a)\r
--- /dev/null
+/*\r
+ * GENERATED FILE - DO NOT EDIT\r
+ * (C) Code Red Technologies Ltd, 2008-9\r
+ * Generated linker script include file for \r
+ * (created from LinkMemoryTemplate (v2.0.11 (200907061347)) on Thu Jul 09 12:44:31 BST 2009)\r
+*/\r
+\r
+MEMORY\r
+{\r
+ FLASH (rx) : ORIGIN = 0x0 LENGTH = 0x80000\r
+ SRAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x8000\r
+ AHBSRAM0 : ORIGIN = 0x2007c000, LENGTH = 0x4000\r
+ AHBSRAM1 : ORIGIN = 0x20080000, LENGTH = 0x4000\r
+}\r
+\r
+_vRamTop = 0x10000000 + 0x8000;\r
--- /dev/null
+/* Don't need anything here. */
+
+#include <stdlib.h>
+#include <sys/stat.h>
+
+int _read_r (struct _reent *r, int file, char * ptr, int len)
+{
+ ( void ) r;
+ ( void ) file;
+ ( void ) ptr;
+ ( void ) len;
+ return -1;
+}
+
+/***************************************************************************/
+
+int _lseek_r (struct _reent *r, int file, int ptr, int dir)
+{
+ ( void ) r;
+ ( void ) file;
+ ( void ) ptr;
+ ( void ) dir;
+
+ return 0;
+}
+
+/***************************************************************************/
+
+int _write_r (struct _reent *r, int file, char * ptr, int len)
+{
+ ( void ) r;
+ ( void ) file;
+ ( void ) ptr;
+ ( void ) len;
+
+ return 0;
+}
+
+/***************************************************************************/
+
+int _close_r (struct _reent *r, int file)
+{
+ ( void ) r;
+ ( void ) file;
+
+ return 0;
+}
+
+/***************************************************************************/
+
+caddr_t _sbrk_r (struct _reent *r, int incr)
+{
+ ( void ) r;
+ ( void ) incr;
+
+ return 0;
+}
+
+/***************************************************************************/
+
+int _fstat_r (struct _reent *r, int file, struct stat * st)
+{
+ ( void ) r;
+ ( void ) file;
+ ( void ) st;
+
+ return 0;
+}
+
+/***************************************************************************/
+
+int _isatty_r(struct _reent *r, int fd)
+{
+ ( void ) r;
+ ( void ) fd;
+
+ return 0;
+}
+
+
+
+
--- /dev/null
+/******************************************************************************\r
+ * @file: system_LPC17xx.h\r
+ * @purpose: CMSIS Cortex-M3 Device Peripheral Access Layer Header File\r
+ * for the NXP LPC17xx Device Series \r
+ * @version: V1.0\r
+ * @date: 25. Nov. 2008\r
+ *----------------------------------------------------------------------------\r
+ *\r
+ * Copyright (C) 2008 ARM Limited. All rights reserved.\r
+ *\r
+ * ARM Limited (ARM) is supplying this software for use with Cortex-M3 \r
+ * processor based microcontrollers. This file can be freely distributed \r
+ * within development tools that are supporting such ARM based processors. \r
+ *\r
+ * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
+ *\r
+ ******************************************************************************/\r
+\r
+\r
+#ifndef __SYSTEM_LPC17xx_H\r
+#define __SYSTEM_LPC17xx_H\r
+\r
+extern uint32_t SystemFrequency; /*!< System Clock Frequency (Core Clock) */\r
+\r
+\r
+/**\r
+ * Initialize the system\r
+ *\r
+ * @param none\r
+ * @return none\r
+ *\r
+ * @brief Setup the microcontroller system.\r
+ * Initialize the System and update the SystemFrequency variable.\r
+ */\r
+extern void SystemInit (void);\r
+#endif\r
--- /dev/null
+/*\r
+ * @file: EthDev.h\r
+ * @purpose: Ethernet Device Definitions\r
+ * @version: V1.10\r
+ * @date: 24. Feb. 2009\r
+ *----------------------------------------------------------------------------\r
+ *\r
+ * Copyright (C) 2009 ARM Limited. All rights reserved.\r
+ *\r
+ * ARM Limited (ARM) is supplying this software for use with Cortex-M3\r
+ * processor based microcontrollers. This file can be freely distributed\r
+ * within development tools that are supporting such ARM based processors.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
+ *\r
+ */\r
+\r
+#ifndef _ETHDEV__H\r
+#define _ETHDEV__H\r
+\r
+#ifndef NULL\r
+ #define NULL 0\r
+#endif\r
+\r
+/*----------------------------------------------------------------------------\r
+ Ethernet Device Defines\r
+ *----------------------------------------------------------------------------*/\r
+#define EthDev_ADDR_SIZE 6 /*!< Ethernet Address size in bytes */\r
+#define EthDev_MTU_SIZE 1514 /*!< Maximum Transmission Unit */\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ Ethernet Device Configuration and Control Command Defines\r
+ *----------------------------------------------------------------------------*/\r
+typedef enum {\r
+ EthDev_LINK_DOWN = 0, /*!< Ethernet link not established */\r
+ EthDev_LINK_UP = 1, /*!< Ethernet link established */\r
+} EthDev_LINK;\r
+\r
+typedef enum {\r
+ EthDev_SPEED_10M = 0, /*!< 10.0 Mbps link speed */\r
+ EthDev_SPEED_100M = 1, /*!< 100.0 Mbps link speed */\r
+ EthDev_SPEED_1000M = 2, /*!< 1.0 Gbps link speed */\r
+} EthDev_SPEED;\r
+\r
+typedef enum {\r
+ EthDev_DUPLEX_HALF = 0, /*!< Link half duplex */\r
+ EthDev_DUPLEX_FULL = 1, /*!< Link full duplex */\r
+} EthDev_DUPLEX;\r
+\r
+typedef enum {\r
+ EthDev_MODE_AUTO = 0,\r
+ EthDev_MODE_10M_FULL = 1,\r
+ EthDev_MODE_10M_HALF = 2,\r
+ EthDev_MODE_100M_FULL = 3,\r
+ EthDev_MODE_100M_HALF = 4,\r
+ EthDev_MODE_1000M_FULL = 5,\r
+ EthDev_MODE_1000M_HALF = 6,\r
+} EthDev_MODE;\r
+\r
+typedef struct {\r
+ EthDev_LINK Link : 1;\r
+ EthDev_DUPLEX Duplex : 1;\r
+ EthDev_SPEED Speed : 2;\r
+} EthDev_STATUS;\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ Ethernet Device IO Block Structure\r
+ *----------------------------------------------------------------------------*/\r
+typedef struct {\r
+\r
+ /* Initialized by the user application before call to Init. */\r
+ EthDev_MODE Mode;\r
+ unsigned char HwAddr[EthDev_ADDR_SIZE];\r
+ void *(*RxFrame) (int size);\r
+ void (*RxFrameReady) (int size);\r
+\r
+ /* Initialized by Ethernet driver. */\r
+ int (*Init) (void);\r
+ int (*UnInit) (void);\r
+ int (*SetMCFilter)(int NumHwAddr, unsigned char *pHwAddr);\r
+ int (*TxFrame) (void *pData, int size);\r
+ void (*Lock) (void);\r
+ void (*UnLock) (void);\r
+ EthDev_STATUS (*LinkChk) (void);\r
+} EthDev_IOB;\r
+\r
+\r
+/*\r
+ * Look for received data. If data is found then uip_buf is assigned to the\r
+ * new data and the length of the data is returned. If no data is found then\r
+ * uip_buf is not updated and 0 is returned.\r
+ */\r
+unsigned long ulGetEMACRxData( void );\r
+\r
+/*\r
+ * Send usTxDataLen bytes from uip_buf.\r
+ */\r
+void vSendEMACTxData( unsigned short usTxDataLen );\r
+\r
+/*\r
+ * Prepare the Ethernet hardware ready for TCP/IP comms.\r
+ */\r
+long lEMACInit(void);\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ * @file: EthDev_LPC17xx.h\r
+ * @purpose: Ethernet Device Definitions for NXP LPC17xx\r
+ * @version: V0.01\r
+ * @date: 14. May 2009\r
+ *----------------------------------------------------------------------------\r
+ *\r
+ * Copyright (C) 2009 ARM Limited. All rights reserved.\r
+ *\r
+ * ARM Limited (ARM) is supplying this software for use with Cortex-M3\r
+ * processor based microcontrollers. This file can be freely distributed\r
+ * within development tools that are supporting such ARM based processors.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
+ *\r
+ */\r
+\r
+#ifndef __ETHDEV_LPC17XX_H\r
+#define __ETHDEV_LPC17XX_H\r
+\r
+#include <stdint.h>\r
+\r
+/* EMAC Memory Buffer configuration for 16K Ethernet RAM. */\r
+#define NUM_RX_FRAG 3 /* Num.of RX Fragments. */\r
+#define NUM_TX_FRAG 2 /* Num.of TX Fragments. */\r
+#define ETH_FRAG_SIZE 1536 /* Packet Fragment size 1536 Bytes */\r
+\r
+#define ETH_MAX_FLEN 1536 /* Max. Ethernet Frame Size */\r
+\r
+typedef struct { /* RX Descriptor struct */\r
+ uint32_t Packet;\r
+ uint32_t Ctrl;\r
+} RX_DESC_TypeDef;\r
+\r
+typedef struct { /* RX Status struct */\r
+ uint32_t Info;\r
+ uint32_t HashCRC;\r
+} RX_STAT_TypeDef;\r
+\r
+typedef struct { /* TX Descriptor struct */\r
+ uint32_t Packet;\r
+ uint32_t Ctrl;\r
+} TX_DESC_TypeDef;\r
+\r
+typedef struct { /* TX Status struct */\r
+ uint32_t Info;\r
+} TX_STAT_TypeDef;\r
+\r
+\r
+/* EMAC variables located in AHB SRAM bank 1*/\r
+#define AHB_SRAM_BANK1_BASE 0x2007c000UL\r
+#define RX_DESC_BASE (AHB_SRAM_BANK1_BASE )\r
+#define RX_STAT_BASE (RX_DESC_BASE + NUM_RX_FRAG*(2*4)) /* 2 * uint32_t, see RX_DESC_TypeDef */\r
+#define TX_DESC_BASE (RX_STAT_BASE + NUM_RX_FRAG*(2*4)) /* 2 * uint32_t, see RX_STAT_TypeDef */\r
+#define TX_STAT_BASE (TX_DESC_BASE + NUM_TX_FRAG*(2*4)) /* 2 * uint32_t, see TX_DESC_TypeDef */\r
+#define ETH_BUF_BASE (TX_STAT_BASE + NUM_TX_FRAG*(1*4)) /* 1 * uint32_t, see TX_STAT_TypeDef */\r
+\r
+/* RX and TX descriptor and status definitions. */\r
+#define RX_DESC_PACKET(i) (*(unsigned int *)(RX_DESC_BASE + 8*i))\r
+#define RX_DESC_CTRL(i) (*(unsigned int *)(RX_DESC_BASE+4 + 8*i))\r
+#define RX_STAT_INFO(i) (*(unsigned int *)(RX_STAT_BASE + 8*i))\r
+#define RX_STAT_HASHCRC(i) (*(unsigned int *)(RX_STAT_BASE+4 + 8*i))\r
+#define TX_DESC_PACKET(i) (*(unsigned int *)(TX_DESC_BASE + 8*i))\r
+#define TX_DESC_CTRL(i) (*(unsigned int *)(TX_DESC_BASE+4 + 8*i))\r
+#define TX_STAT_INFO(i) (*(unsigned int *)(TX_STAT_BASE + 4*i))\r
+#define ETH_BUF(i) ( ETH_BUF_BASE + ETH_FRAG_SIZE*i )\r
+#define ETH_NUM_BUFFERS ( NUM_TX_FRAG + NUM_RX_FRAG + 1 ) /* There are in fact 2 more buffers than descriptors as the two Tx descriptors use the same buffer to speed up the uip Tx. */\r
+\r
+\r
+/* MAC Configuration Register 1 */\r
+#define MAC1_REC_EN 0x00000001 /* Receive Enable */\r
+#define MAC1_PASS_ALL 0x00000002 /* Pass All Receive Frames */\r
+#define MAC1_RX_FLOWC 0x00000004 /* RX Flow Control */\r
+#define MAC1_TX_FLOWC 0x00000008 /* TX Flow Control */\r
+#define MAC1_LOOPB 0x00000010 /* Loop Back Mode */\r
+#define MAC1_RES_TX 0x00000100 /* Reset TX Logic */\r
+#define MAC1_RES_MCS_TX 0x00000200 /* Reset MAC TX Control Sublayer */\r
+#define MAC1_RES_RX 0x00000400 /* Reset RX Logic */\r
+#define MAC1_RES_MCS_RX 0x00000800 /* Reset MAC RX Control Sublayer */\r
+#define MAC1_SIM_RES 0x00004000 /* Simulation Reset */\r
+#define MAC1_SOFT_RES 0x00008000 /* Soft Reset MAC */\r
+\r
+/* MAC Configuration Register 2 */\r
+#define MAC2_FULL_DUP 0x00000001 /* Full Duplex Mode */\r
+#define MAC2_FRM_LEN_CHK 0x00000002 /* Frame Length Checking */\r
+#define MAC2_HUGE_FRM_EN 0x00000004 /* Huge Frame Enable */\r
+#define MAC2_DLY_CRC 0x00000008 /* Delayed CRC Mode */\r
+#define MAC2_CRC_EN 0x00000010 /* Append CRC to every Frame */\r
+#define MAC2_PAD_EN 0x00000020 /* Pad all Short Frames */\r
+#define MAC2_VLAN_PAD_EN 0x00000040 /* VLAN Pad Enable */\r
+#define MAC2_ADET_PAD_EN 0x00000080 /* Auto Detect Pad Enable */\r
+#define MAC2_PPREAM_ENF 0x00000100 /* Pure Preamble Enforcement */\r
+#define MAC2_LPREAM_ENF 0x00000200 /* Long Preamble Enforcement */\r
+#define MAC2_NO_BACKOFF 0x00001000 /* No Backoff Algorithm */\r
+#define MAC2_BACK_PRESSURE 0x00002000 /* Backoff Presurre / No Backoff */\r
+#define MAC2_EXCESS_DEF 0x00004000 /* Excess Defer */\r
+\r
+/* Back-to-Back Inter-Packet-Gap Register */\r
+#define IPGT_FULL_DUP 0x00000015 /* Recommended value for Full Duplex */\r
+#define IPGT_HALF_DUP 0x00000012 /* Recommended value for Half Duplex */\r
+\r
+/* Non Back-to-Back Inter-Packet-Gap Register */\r
+#define IPGR_DEF 0x00000012 /* Recommended value */\r
+\r
+/* Collision Window/Retry Register */\r
+#define CLRT_DEF 0x0000370F /* Default value */\r
+\r
+/* PHY Support Register */\r
+#define SUPP_SPEED 0x00000100 /* Reduced MII Logic Current Speed */\r
+#define SUPP_RES_RMII 0x00000800 /* Reset Reduced MII Logic */\r
+\r
+/* Test Register */\r
+#define TEST_SHCUT_PQUANTA 0x00000001 /* Shortcut Pause Quanta */\r
+#define TEST_TST_PAUSE 0x00000002 /* Test Pause */\r
+#define TEST_TST_BACKP 0x00000004 /* Test Back Pressure */\r
+\r
+/* MII Management Configuration Register */\r
+#define MCFG_SCAN_INC 0x00000001 /* Scan Increment PHY Address */\r
+#define MCFG_SUPP_PREAM 0x00000002 /* Suppress Preamble */\r
+#define MCFG_CLK_SEL 0x0000003C /* Clock Select Mask */\r
+#define MCFG_RES_MII 0x00008000 /* Reset MII Management Hardware */\r
+\r
+/* MII Management Command Register */\r
+#define MCMD_READ 0x00000001 /* MII Read */\r
+#define MCMD_SCAN 0x00000002 /* MII Scan continuously */\r
+\r
+#define MII_WR_TOUT 0x00050000 /* MII Write timeout count */\r
+#define MII_RD_TOUT 0x00050000 /* MII Read timeout count */\r
+\r
+/* MII Management Address Register */\r
+#define MADR_REG_ADR 0x0000001F /* MII Register Address Mask */\r
+#define MADR_PHY_ADR 0x00001F00 /* PHY Address Mask */\r
+\r
+/* MII Management Indicators Register */\r
+#define MIND_BUSY 0x00000001 /* MII is Busy */\r
+#define MIND_SCAN 0x00000002 /* MII Scanning in Progress */\r
+#define MIND_NOT_VAL 0x00000004 /* MII Read Data not valid */\r
+#define MIND_MII_LINK_FAIL 0x00000008 /* MII Link Failed */\r
+\r
+/* Command Register */\r
+#define CR_RX_EN 0x00000001 /* Enable Receive */\r
+#define CR_TX_EN 0x00000002 /* Enable Transmit */\r
+#define CR_REG_RES 0x00000008 /* Reset Host Registers */\r
+#define CR_TX_RES 0x00000010 /* Reset Transmit Datapath */\r
+#define CR_RX_RES 0x00000020 /* Reset Receive Datapath */\r
+#define CR_PASS_RUNT_FRM 0x00000040 /* Pass Runt Frames */\r
+#define CR_PASS_RX_FILT 0x00000080 /* Pass RX Filter */\r
+#define CR_TX_FLOW_CTRL 0x00000100 /* TX Flow Control */\r
+#define CR_RMII 0x00000200 /* Reduced MII Interface */\r
+#define CR_FULL_DUP 0x00000400 /* Full Duplex */\r
+\r
+/* Status Register */\r
+#define SR_RX_EN 0x00000001 /* Enable Receive */\r
+#define SR_TX_EN 0x00000002 /* Enable Transmit */\r
+\r
+/* Transmit Status Vector 0 Register */\r
+#define TSV0_CRC_ERR 0x00000001 /* CRC error */\r
+#define TSV0_LEN_CHKERR 0x00000002 /* Length Check Error */\r
+#define TSV0_LEN_OUTRNG 0x00000004 /* Length Out of Range */\r
+#define TSV0_DONE 0x00000008 /* Tramsmission Completed */\r
+#define TSV0_MCAST 0x00000010 /* Multicast Destination */\r
+#define TSV0_BCAST 0x00000020 /* Broadcast Destination */\r
+#define TSV0_PKT_DEFER 0x00000040 /* Packet Deferred */\r
+#define TSV0_EXC_DEFER 0x00000080 /* Excessive Packet Deferral */\r
+#define TSV0_EXC_COLL 0x00000100 /* Excessive Collision */\r
+#define TSV0_LATE_COLL 0x00000200 /* Late Collision Occured */\r
+#define TSV0_GIANT 0x00000400 /* Giant Frame */\r
+#define TSV0_UNDERRUN 0x00000800 /* Buffer Underrun */\r
+#define TSV0_BYTES 0x0FFFF000 /* Total Bytes Transferred */\r
+#define TSV0_CTRL_FRAME 0x10000000 /* Control Frame */\r
+#define TSV0_PAUSE 0x20000000 /* Pause Frame */\r
+#define TSV0_BACK_PRESS 0x40000000 /* Backpressure Method Applied */\r
+#define TSV0_VLAN 0x80000000 /* VLAN Frame */\r
+\r
+/* Transmit Status Vector 1 Register */\r
+#define TSV1_BYTE_CNT 0x0000FFFF /* Transmit Byte Count */\r
+#define TSV1_COLL_CNT 0x000F0000 /* Transmit Collision Count */\r
+\r
+/* Receive Status Vector Register */\r
+#define RSV_BYTE_CNT 0x0000FFFF /* Receive Byte Count */\r
+#define RSV_PKT_IGNORED 0x00010000 /* Packet Previously Ignored */\r
+#define RSV_RXDV_SEEN 0x00020000 /* RXDV Event Previously Seen */\r
+#define RSV_CARR_SEEN 0x00040000 /* Carrier Event Previously Seen */\r
+#define RSV_REC_CODEV 0x00080000 /* Receive Code Violation */\r
+#define RSV_CRC_ERR 0x00100000 /* CRC Error */\r
+#define RSV_LEN_CHKERR 0x00200000 /* Length Check Error */\r
+#define RSV_LEN_OUTRNG 0x00400000 /* Length Out of Range */\r
+#define RSV_REC_OK 0x00800000 /* Frame Received OK */\r
+#define RSV_MCAST 0x01000000 /* Multicast Frame */\r
+#define RSV_BCAST 0x02000000 /* Broadcast Frame */\r
+#define RSV_DRIB_NIBB 0x04000000 /* Dribble Nibble */\r
+#define RSV_CTRL_FRAME 0x08000000 /* Control Frame */\r
+#define RSV_PAUSE 0x10000000 /* Pause Frame */\r
+#define RSV_UNSUPP_OPC 0x20000000 /* Unsupported Opcode */\r
+#define RSV_VLAN 0x40000000 /* VLAN Frame */\r
+\r
+/* Flow Control Counter Register */\r
+#define FCC_MIRR_CNT 0x0000FFFF /* Mirror Counter */\r
+#define FCC_PAUSE_TIM 0xFFFF0000 /* Pause Timer */\r
+\r
+/* Flow Control Status Register */\r
+#define FCS_MIRR_CNT 0x0000FFFF /* Mirror Counter Current */\r
+\r
+/* Receive Filter Control Register */\r
+#define RFC_UCAST_EN 0x00000001 /* Accept Unicast Frames Enable */\r
+#define RFC_BCAST_EN 0x00000002 /* Accept Broadcast Frames Enable */\r
+#define RFC_MCAST_EN 0x00000004 /* Accept Multicast Frames Enable */\r
+#define RFC_UCAST_HASH_EN 0x00000008 /* Accept Unicast Hash Filter Frames */\r
+#define RFC_MCAST_HASH_EN 0x00000010 /* Accept Multicast Hash Filter Fram.*/\r
+#define RFC_PERFECT_EN 0x00000020 /* Accept Perfect Match Enable */\r
+#define RFC_MAGP_WOL_EN 0x00001000 /* Magic Packet Filter WoL Enable */\r
+#define RFC_PFILT_WOL_EN 0x00002000 /* Perfect Filter WoL Enable */\r
+\r
+/* Receive Filter WoL Status/Clear Registers */\r
+#define WOL_UCAST 0x00000001 /* Unicast Frame caused WoL */\r
+#define WOL_BCAST 0x00000002 /* Broadcast Frame caused WoL */\r
+#define WOL_MCAST 0x00000004 /* Multicast Frame caused WoL */\r
+#define WOL_UCAST_HASH 0x00000008 /* Unicast Hash Filter Frame WoL */\r
+#define WOL_MCAST_HASH 0x00000010 /* Multicast Hash Filter Frame WoL */\r
+#define WOL_PERFECT 0x00000020 /* Perfect Filter WoL */\r
+#define WOL_RX_FILTER 0x00000080 /* RX Filter caused WoL */\r
+#define WOL_MAG_PACKET 0x00000100 /* Magic Packet Filter caused WoL */\r
+\r
+/* Interrupt Status/Enable/Clear/Set Registers */\r
+#define INT_RX_OVERRUN 0x00000001 /* Overrun Error in RX Queue */\r
+#define INT_RX_ERR 0x00000002 /* Receive Error */\r
+#define INT_RX_FIN 0x00000004 /* RX Finished Process Descriptors */\r
+#define INT_RX_DONE 0x00000008 /* Receive Done */\r
+#define INT_TX_UNDERRUN 0x00000010 /* Transmit Underrun */\r
+#define INT_TX_ERR 0x00000020 /* Transmit Error */\r
+#define INT_TX_FIN 0x00000040 /* TX Finished Process Descriptors */\r
+#define INT_TX_DONE 0x00000080 /* Transmit Done */\r
+#define INT_SOFT_INT 0x00001000 /* Software Triggered Interrupt */\r
+#define INT_WAKEUP 0x00002000 /* Wakeup Event Interrupt */\r
+\r
+/* Power Down Register */\r
+#define PD_POWER_DOWN 0x80000000 /* Power Down MAC */\r
+\r
+/* RX Descriptor Control Word */\r
+#define RCTRL_SIZE 0x000007FF /* Buffer size mask */\r
+#define RCTRL_INT 0x80000000 /* Generate RxDone Interrupt */\r
+\r
+/* RX Status Hash CRC Word */\r
+#define RHASH_SA 0x000001FF /* Hash CRC for Source Address */\r
+#define RHASH_DA 0x001FF000 /* Hash CRC for Destination Address */\r
+\r
+/* RX Status Information Word */\r
+#define RINFO_SIZE 0x000007FF /* Data size in bytes */\r
+#define RINFO_CTRL_FRAME 0x00040000 /* Control Frame */\r
+#define RINFO_VLAN 0x00080000 /* VLAN Frame */\r
+#define RINFO_FAIL_FILT 0x00100000 /* RX Filter Failed */\r
+#define RINFO_MCAST 0x00200000 /* Multicast Frame */\r
+#define RINFO_BCAST 0x00400000 /* Broadcast Frame */\r
+#define RINFO_CRC_ERR 0x00800000 /* CRC Error in Frame */\r
+#define RINFO_SYM_ERR 0x01000000 /* Symbol Error from PHY */\r
+#define RINFO_LEN_ERR 0x02000000 /* Length Error */\r
+#define RINFO_RANGE_ERR 0x04000000 /* Range Error (exceeded max. size) */\r
+#define RINFO_ALIGN_ERR 0x08000000 /* Alignment Error */\r
+#define RINFO_OVERRUN 0x10000000 /* Receive overrun */\r
+#define RINFO_NO_DESCR 0x20000000 /* No new Descriptor available */\r
+#define RINFO_LAST_FLAG 0x40000000 /* Last Fragment in Frame */\r
+#define RINFO_ERR 0x80000000 /* Error Occured (OR of all errors) */\r
+\r
+#define RINFO_ERR_MASK (RINFO_FAIL_FILT | RINFO_CRC_ERR | RINFO_SYM_ERR | \\r
+ RINFO_LEN_ERR | RINFO_ALIGN_ERR | RINFO_OVERRUN)\r
+\r
+/* TX Descriptor Control Word */\r
+#define TCTRL_SIZE 0x000007FF /* Size of data buffer in bytes */\r
+#define TCTRL_OVERRIDE 0x04000000 /* Override Default MAC Registers */\r
+#define TCTRL_HUGE 0x08000000 /* Enable Huge Frame */\r
+#define TCTRL_PAD 0x10000000 /* Pad short Frames to 64 bytes */\r
+#define TCTRL_CRC 0x20000000 /* Append a hardware CRC to Frame */\r
+#define TCTRL_LAST 0x40000000 /* Last Descriptor for TX Frame */\r
+#define TCTRL_INT 0x80000000 /* Generate TxDone Interrupt */\r
+\r
+/* TX Status Information Word */\r
+#define TINFO_COL_CNT 0x01E00000 /* Collision Count */\r
+#define TINFO_DEFER 0x02000000 /* Packet Deferred (not an error) */\r
+#define TINFO_EXCESS_DEF 0x04000000 /* Excessive Deferral */\r
+#define TINFO_EXCESS_COL 0x08000000 /* Excessive Collision */\r
+#define TINFO_LATE_COL 0x10000000 /* Late Collision Occured */\r
+#define TINFO_UNDERRUN 0x20000000 /* Transmit Underrun */\r
+#define TINFO_NO_DESCR 0x40000000 /* No new Descriptor available */\r
+#define TINFO_ERR 0x80000000 /* Error Occured (OR of all errors) */\r
+\r
+/* ENET Device Revision ID */\r
+#define OLD_EMAC_MODULE_ID 0x39022000 /* Rev. ID for first rev '-' */\r
+\r
+/* DP83848C PHY Registers */\r
+#define PHY_REG_BMCR 0x00 /* Basic Mode Control Register */\r
+#define PHY_REG_BMSR 0x01 /* Basic Mode Status Register */\r
+#define PHY_REG_IDR1 0x02 /* PHY Identifier 1 */\r
+#define PHY_REG_IDR2 0x03 /* PHY Identifier 2 */\r
+#define PHY_REG_ANAR 0x04 /* Auto-Negotiation Advertisement */\r
+#define PHY_REG_ANLPAR 0x05 /* Auto-Neg. Link Partner Abitily */\r
+#define PHY_REG_ANER 0x06 /* Auto-Neg. Expansion Register */\r
+#define PHY_REG_ANNPTR 0x07 /* Auto-Neg. Next Page TX */\r
+\r
+/* PHY Extended Registers */\r
+#define PHY_REG_STS 0x10 /* Status Register */\r
+#define PHY_REG_MICR 0x11 /* MII Interrupt Control Register */\r
+#define PHY_REG_MISR 0x12 /* MII Interrupt Status Register */\r
+#define PHY_REG_FCSCR 0x14 /* False Carrier Sense Counter */\r
+#define PHY_REG_RECR 0x15 /* Receive Error Counter */\r
+#define PHY_REG_PCSR 0x16 /* PCS Sublayer Config. and Status */\r
+#define PHY_REG_RBR 0x17 /* RMII and Bypass Register */\r
+#define PHY_REG_LEDCR 0x18 /* LED Direct Control Register */\r
+#define PHY_REG_PHYCR 0x19 /* PHY Control Register */\r
+#define PHY_REG_10BTSCR 0x1A /* 10Base-T Status/Control Register */\r
+#define PHY_REG_CDCTRL1 0x1B /* CD Test Control and BIST Extens. */\r
+#define PHY_REG_EDCR 0x1D /* Energy Detect Control Register */\r
+\r
+#define PHY_FULLD_100M 0x2100 /* Full Duplex 100Mbit */\r
+#define PHY_HALFD_100M 0x2000 /* Half Duplex 100Mbit */\r
+#define PHY_FULLD_10M 0x0100 /* Full Duplex 10Mbit */\r
+#define PHY_HALFD_10M 0x0000 /* Half Duplex 10MBit */\r
+#define PHY_AUTO_NEG 0x3000 /* Select Auto Negotiation */\r
+#define PHY_AUTO_NEG_COMPLETE 0x0020 /* Auto negotiation have finished. */\r
+\r
+#define DP83848C_DEF_ADR 0x0100 /* Default PHY device address */\r
+#define DP83848C_ID 0x20005C90 /* PHY Identifier */\r
+\r
+#endif\r
+\r
+/*----------------------------------------------------------------------------\r
+ * end of file\r
+ *---------------------------------------------------------------------------*/\r
--- /dev/null
+/*\r
+ * Copyright (c) 2006, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * $Id: clock-arch.h,v 1.2 2006/06/12 08:00:31 adam Exp $\r
+ */\r
+\r
+#ifndef __CLOCK_ARCH_H__\r
+#define __CLOCK_ARCH_H__\r
+\r
+#include "FreeRTOS.h"\r
+\r
+typedef unsigned long clock_time_t;\r
+#define CLOCK_CONF_SECOND configTICK_RATE_HZ\r
+\r
+#endif /* __CLOCK_ARCH_H__ */\r
--- /dev/null
+/**\r
+ * \defgroup clock Clock interface\r
+ *\r
+ * The clock interface is the interface between the \ref timer "timer library"\r
+ * and the platform specific clock functionality. The clock\r
+ * interface must be implemented for each platform that uses the \ref\r
+ * timer "timer library".\r
+ *\r
+ * The clock interface does only one this: it measures time. The clock\r
+ * interface provides a macro, CLOCK_SECOND, which corresponds to one\r
+ * second of system time.\r
+ *\r
+ * \sa \ref timer "Timer library"\r
+ *\r
+ * @{\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: clock.h,v 1.3 2006/06/11 21:46:39 adam Exp $\r
+ */\r
+#ifndef __CLOCK_H__\r
+#define __CLOCK_H__\r
+\r
+#include "clock-arch.h"\r
+\r
+/**\r
+ * Initialize the clock library.\r
+ *\r
+ * This function initializes the clock library and should be called\r
+ * from the main() function of the system.\r
+ *\r
+ */\r
+void clock_init(void);\r
+\r
+/**\r
+ * Get the current clock time.\r
+ *\r
+ * This function returns the current system clock time.\r
+ *\r
+ * \return The current clock time, measured in system ticks.\r
+ */\r
+clock_time_t clock_time(void);\r
+\r
+/**\r
+ * A second, measured in system clock time.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef CLOCK_CONF_SECOND\r
+#define CLOCK_SECOND CLOCK_CONF_SECOND\r
+#else\r
+#define CLOCK_SECOND (clock_time_t)32\r
+#endif\r
+\r
+#endif /* __CLOCK_H__ */\r
+\r
+/** @} */\r
--- /dev/null
+/*\r
+ FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it\r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
+ **NOTE** The exception to the GPL is included to allow you to distribute a\r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
+ the source code for any proprietary components. Alternative commercial\r
+ license and support terms are also available upon request. See the\r
+ licensing section of http://www.FreeRTOS.org for full details.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details.\r
+\r
+ You should have received a copy of the GNU General Public License along\r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ Please ensure to read the configuration and relevant port sections of the\r
+ online documentation.\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/* Originally adapted from file written by Andreas Dannenberg. Supplied with permission. */\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* Hardware specific includes. */\r
+#include "EthDev_LPC17xx.h"\r
+\r
+/* Time to wait between each inspection of the link status. */\r
+#define emacWAIT_FOR_LINK_TO_ESTABLISH ( 500 / portTICK_RATE_MS )\r
+\r
+/* Short delay used in several places during the initialisation process. */\r
+#define emacSHORT_DELAY ( 2 )\r
+\r
+/* Hardware specific bit definitions. */\r
+#define emacLINK_ESTABLISHED ( 0x0001 )\r
+#define emacFULL_DUPLEX_ENABLED ( 0x0004 )\r
+#define emac10BASE_T_MODE ( 0x0002 )\r
+#define emacPINSEL2_VALUE 0x50150105\r
+\r
+/* If no buffers are available, then wait this long before looking again.... */\r
+#define emacBUFFER_WAIT_DELAY ( 3 / portTICK_RATE_MS )\r
+\r
+/* ...and don't look more than this many times. */\r
+#define emacBUFFER_WAIT_ATTEMPTS ( 30 )\r
+\r
+/* Index to the Tx descriptor that is always used first for every Tx. The second\r
+descriptor is then used to re-send in order to speed up the uIP Tx process. */\r
+#define emacTX_DESC_INDEX ( 0 )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Configure both the Rx and Tx descriptors during the init process.\r
+ */\r
+static void prvInitDescriptors( void );\r
+\r
+/*\r
+ * Setup the IO and peripherals required for Ethernet communication.\r
+ */\r
+static void prvSetupEMACHardware( void );\r
+\r
+/*\r
+ * Control the auto negotiate process.\r
+ */\r
+static void prvConfigurePHY( void );\r
+\r
+/*\r
+ * Wait for a link to be established, then setup the PHY according to the link\r
+ * parameters.\r
+ */\r
+static long prvSetupLinkStatus( void );\r
+\r
+/*\r
+ * Search the pool of buffers to find one that is free. If a buffer is found\r
+ * mark it as in use before returning its address.\r
+ */\r
+static unsigned char *prvGetNextBuffer( void );\r
+\r
+/*\r
+ * Return an allocated buffer to the pool of free buffers.\r
+ */\r
+static void prvReturnBuffer( unsigned char *pucBuffer );\r
+\r
+/*\r
+ * Send lValue to the lPhyReg within the PHY.\r
+ */\r
+static long prvWritePHY( long lPhyReg, long lValue );\r
+\r
+/*\r
+ * Read a value from ucPhyReg within the PHY. *plStatus will be set to\r
+ * pdFALSE if there is an error.\r
+ */\r
+static unsigned short prvReadPHY( unsigned char ucPhyReg, long *plStatus );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The semaphore used to wake the uIP task when data arrives. */\r
+extern xSemaphoreHandle xEMACSemaphore;\r
+\r
+/* Each ucBufferInUse index corresponds to a position in the pool of buffers.\r
+If the index contains a 1 then the buffer within pool is in use, if it\r
+contains a 0 then the buffer is free. */\r
+static unsigned char ucBufferInUse[ ETH_NUM_BUFFERS ] = { pdFALSE };\r
+\r
+/* The uip_buffer is not a fixed array, but instead gets pointed to the buffers\r
+allocated within this file. */\r
+unsigned char * uip_buf;\r
+\r
+/* Store the length of the data being sent so the data can be sent twice. The\r
+value will be set back to 0 once the data has been sent twice. */\r
+static unsigned short usSendLen = 0;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+long lEMACInit( void )\r
+{\r
+long lReturn = pdPASS;\r
+unsigned long ulID1, ulID2;\r
+\r
+ /* Reset peripherals, configure port pins and registers. */\r
+ prvSetupEMACHardware();\r
+\r
+ /* Check the PHY part number is as expected. */\r
+ ulID1 = prvReadPHY( PHY_REG_IDR1, &lReturn );\r
+ ulID2 = prvReadPHY( PHY_REG_IDR2, &lReturn );\r
+ if( ( (ulID1 << 16UL ) | ( ulID2 & 0xFFF0UL ) ) == DP83848C_ID )\r
+ {\r
+ /* Set the Ethernet MAC Address registers */\r
+ EMAC->SA0 = ( configMAC_ADDR0 << 8 ) | configMAC_ADDR1;\r
+ EMAC->SA1 = ( configMAC_ADDR2 << 8 ) | configMAC_ADDR3;\r
+ EMAC->SA2 = ( configMAC_ADDR4 << 8 ) | configMAC_ADDR5;\r
+\r
+ /* Initialize Tx and Rx DMA Descriptors */\r
+ prvInitDescriptors();\r
+\r
+ /* Receive broadcast and perfect match packets */\r
+ EMAC->RxFilterCtrl = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;\r
+\r
+ /* Setup the PHY. */\r
+ prvConfigurePHY();\r
+ }\r
+ else\r
+ {\r
+ lReturn = pdFAIL;\r
+ }\r
+\r
+ /* Check the link status. */\r
+ if( lReturn == pdPASS )\r
+ {\r
+ lReturn = prvSetupLinkStatus();\r
+ }\r
+\r
+ if( lReturn == pdPASS )\r
+ {\r
+ /* Initialise uip_buf to ensure it points somewhere valid. */\r
+ uip_buf = prvGetNextBuffer();\r
+\r
+ /* Reset all interrupts */\r
+ EMAC->IntClear = ( INT_RX_OVERRUN | INT_RX_ERR | INT_RX_FIN | INT_RX_DONE | INT_TX_UNDERRUN | INT_TX_ERR | INT_TX_FIN | INT_TX_DONE | INT_SOFT_INT | INT_WAKEUP );\r
+\r
+ /* Enable receive and transmit mode of MAC Ethernet core */\r
+ EMAC->Command |= ( CR_RX_EN | CR_TX_EN );\r
+ EMAC->MAC1 |= MAC1_REC_EN;\r
+ }\r
+\r
+ return lReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static unsigned char *prvGetNextBuffer( void )\r
+{\r
+long x;\r
+unsigned char *pucReturn = NULL;\r
+unsigned long ulAttempts = 0;\r
+\r
+ while( pucReturn == NULL )\r
+ {\r
+ /* Look through the buffers to find one that is not in use by\r
+ anything else. */\r
+ for( x = 0; x < ETH_NUM_BUFFERS; x++ )\r
+ {\r
+ if( ucBufferInUse[ x ] == pdFALSE )\r
+ {\r
+ ucBufferInUse[ x ] = pdTRUE;\r
+ pucReturn = ( unsigned char * ) ETH_BUF( x );\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* Was a buffer found? */\r
+ if( pucReturn == NULL )\r
+ {\r
+ ulAttempts++;\r
+\r
+ if( ulAttempts >= emacBUFFER_WAIT_ATTEMPTS )\r
+ {\r
+ break;\r
+ }\r
+\r
+ /* Wait then look again. */\r
+ vTaskDelay( emacBUFFER_WAIT_DELAY );\r
+ }\r
+ }\r
+\r
+ return pucReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvInitDescriptors( void )\r
+{\r
+long x, lNextBuffer = 0;\r
+\r
+ for( x = 0; x < NUM_RX_FRAG; x++ )\r
+ {\r
+ /* Allocate the next Ethernet buffer to this descriptor. */\r
+ RX_DESC_PACKET( x ) = ETH_BUF( lNextBuffer );\r
+ RX_DESC_CTRL( x ) = RCTRL_INT | ( ETH_FRAG_SIZE - 1 );\r
+ RX_STAT_INFO( x ) = 0;\r
+ RX_STAT_HASHCRC( x ) = 0;\r
+\r
+ /* The Ethernet buffer is now in use. */\r
+ ucBufferInUse[ lNextBuffer ] = pdTRUE;\r
+ lNextBuffer++;\r
+ }\r
+\r
+ /* Set EMAC Receive Descriptor Registers. */\r
+ EMAC->RxDescriptor = RX_DESC_BASE;\r
+ EMAC->RxStatus = RX_STAT_BASE;\r
+ EMAC->RxDescriptorNumber = NUM_RX_FRAG - 1;\r
+\r
+ /* Rx Descriptors Point to 0 */\r
+ EMAC->RxConsumeIndex = 0;\r
+\r
+ /* A buffer is not allocated to the Tx descriptors until they are actually\r
+ used. */\r
+ for( x = 0; x < NUM_TX_FRAG; x++ )\r
+ {\r
+ TX_DESC_PACKET( x ) = ( unsigned long ) NULL;\r
+ TX_DESC_CTRL( x ) = 0;\r
+ TX_STAT_INFO( x ) = 0;\r
+ }\r
+\r
+ /* Set EMAC Transmit Descriptor Registers. */\r
+ EMAC->TxDescriptor = TX_DESC_BASE;\r
+ EMAC->TxStatus = TX_STAT_BASE;\r
+ EMAC->TxDescriptorNumber = NUM_TX_FRAG - 1;\r
+\r
+ /* Tx Descriptors Point to 0 */\r
+ EMAC->TxProduceIndex = 0;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvSetupEMACHardware( void )\r
+{\r
+unsigned short us;\r
+long x, lDummy;\r
+\r
+ /* Enable P1 Ethernet Pins. */\r
+ PINCON->PINSEL2 = emacPINSEL2_VALUE;\r
+ PINCON->PINSEL3 = ( PINCON->PINSEL3 & ~0x0000000F ) | 0x00000005;\r
+\r
+ /* Power Up the EMAC controller. */\r
+ SC->PCONP |= PCONP_PCENET;\r
+ vTaskDelay( emacSHORT_DELAY );\r
+\r
+ /* Reset all EMAC internal modules. */\r
+ EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | MAC1_SIM_RES | MAC1_SOFT_RES;\r
+ EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES | CR_PASS_RUNT_FRM;\r
+\r
+ /* A short delay after reset. */\r
+ vTaskDelay( emacSHORT_DELAY );\r
+\r
+ /* Initialize MAC control registers. */\r
+ EMAC->MAC1 = MAC1_PASS_ALL;\r
+ EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN;\r
+ EMAC->MAXF = ETH_MAX_FLEN;\r
+ EMAC->CLRT = CLRT_DEF;\r
+ EMAC->IPGR = IPGR_DEF;\r
+\r
+ /* Enable Reduced MII interface. */\r
+ EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM;\r
+\r
+ /* Reset Reduced MII Logic. */\r
+ EMAC->SUPP = SUPP_RES_RMII;\r
+ vTaskDelay( emacSHORT_DELAY );\r
+ EMAC->SUPP = 0;\r
+\r
+ /* Put the PHY in reset mode */\r
+ prvWritePHY( PHY_REG_BMCR, MCFG_RES_MII );\r
+ prvWritePHY( PHY_REG_BMCR, MCFG_RES_MII );\r
+\r
+ /* Wait for hardware reset to end. */\r
+ for( x = 0; x < 100; x++ )\r
+ {\r
+ vTaskDelay( emacSHORT_DELAY * 5 );\r
+ us = prvReadPHY( PHY_REG_BMCR, &lDummy );\r
+ if( !( us & MCFG_RES_MII ) )\r
+ {\r
+ /* Reset complete */\r
+ break;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvConfigurePHY( void )\r
+{\r
+unsigned short us;\r
+long x, lDummy;\r
+\r
+ /* Auto negotiate the configuration. */\r
+ if( prvWritePHY( PHY_REG_BMCR, PHY_AUTO_NEG ) )\r
+ {\r
+ vTaskDelay( emacSHORT_DELAY * 5 );\r
+\r
+ for( x = 0; x < 10; x++ )\r
+ {\r
+ us = prvReadPHY( PHY_REG_BMSR, &lDummy );\r
+\r
+ if( us & PHY_AUTO_NEG_COMPLETE )\r
+ {\r
+ break;\r
+ }\r
+\r
+ vTaskDelay( emacWAIT_FOR_LINK_TO_ESTABLISH );\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static long prvSetupLinkStatus( void )\r
+{\r
+long lReturn = pdFAIL, x;\r
+unsigned short usLinkStatus;\r
+\r
+ /* Wait with timeout for the link to be established. */\r
+ for( x = 0; x < 10; x++ )\r
+ {\r
+ usLinkStatus = prvReadPHY( PHY_REG_STS, &lReturn );\r
+ if( usLinkStatus & emacLINK_ESTABLISHED )\r
+ {\r
+ /* Link is established. */\r
+ lReturn = pdPASS;\r
+ break;\r
+ }\r
+\r
+ vTaskDelay( emacWAIT_FOR_LINK_TO_ESTABLISH );\r
+ }\r
+\r
+ if( lReturn == pdPASS )\r
+ {\r
+ /* Configure Full/Half Duplex mode. */\r
+ if( usLinkStatus & emacFULL_DUPLEX_ENABLED )\r
+ {\r
+ /* Full duplex is enabled. */\r
+ EMAC->MAC2 |= MAC2_FULL_DUP;\r
+ EMAC->Command |= CR_FULL_DUP;\r
+ EMAC->IPGT = IPGT_FULL_DUP;\r
+ }\r
+ else\r
+ {\r
+ /* Half duplex mode. */\r
+ EMAC->IPGT = IPGT_HALF_DUP;\r
+ }\r
+\r
+ /* Configure 100MBit/10MBit mode. */\r
+ if( usLinkStatus & emac10BASE_T_MODE )\r
+ {\r
+ /* 10MBit mode. */\r
+ EMAC->SUPP = 0;\r
+ }\r
+ else\r
+ {\r
+ /* 100MBit mode. */\r
+ EMAC->SUPP = SUPP_SPEED;\r
+ }\r
+ }\r
+\r
+ return lReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvReturnBuffer( unsigned char *pucBuffer )\r
+{\r
+unsigned long ul;\r
+\r
+ /* Return a buffer to the pool of free buffers. */\r
+ for( ul = 0; ul < ETH_NUM_BUFFERS; ul++ )\r
+ {\r
+ if( ETH_BUF( ul ) == ( unsigned long ) pucBuffer )\r
+ {\r
+ ucBufferInUse[ ul ] = pdFALSE;\r
+ break;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned long ulGetEMACRxData( void )\r
+{\r
+unsigned long ulLen = 0;\r
+long lIndex;\r
+\r
+ if( EMAC->RxProduceIndex != EMAC->RxConsumeIndex )\r
+ {\r
+ /* Mark the current buffer as free as uip_buf is going to be set to\r
+ the buffer that contains the received data. */\r
+ prvReturnBuffer( uip_buf );\r
+\r
+ ulLen = ( RX_STAT_INFO( EMAC->RxConsumeIndex ) & RINFO_SIZE ) - 3;\r
+ uip_buf = ( unsigned char * ) RX_DESC_PACKET( EMAC->RxConsumeIndex );\r
+\r
+ /* Allocate a new buffer to the descriptor. */\r
+ RX_DESC_PACKET( EMAC->RxConsumeIndex ) = ( unsigned long ) prvGetNextBuffer();\r
+\r
+ /* Move the consume index onto the next position, ensuring it wraps to\r
+ the beginning at the appropriate place. */\r
+ lIndex = EMAC->RxConsumeIndex;\r
+\r
+ lIndex++;\r
+ if( lIndex >= NUM_RX_FRAG )\r
+ {\r
+ lIndex = 0;\r
+ }\r
+\r
+ EMAC->RxConsumeIndex = lIndex;\r
+ }\r
+\r
+ return ulLen;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vSendEMACTxData( unsigned short usTxDataLen )\r
+{\r
+unsigned long ulAttempts = 0UL;\r
+\r
+ /* Check to see if the Tx descriptor is free, indicated by its buffer being\r
+ NULL. */\r
+ while( TX_DESC_PACKET( emacTX_DESC_INDEX ) != ( unsigned long ) NULL )\r
+ {\r
+ /* Wait for the Tx descriptor to become available. */\r
+ vTaskDelay( emacBUFFER_WAIT_DELAY );\r
+\r
+ ulAttempts++;\r
+ if( ulAttempts > emacBUFFER_WAIT_ATTEMPTS )\r
+ {\r
+ /* Something has gone wrong as the Tx descriptor is still in use.\r
+ Clear it down manually, the data it was sending will probably be\r
+ lost. */\r
+ prvReturnBuffer( ( unsigned char * ) TX_DESC_PACKET( emacTX_DESC_INDEX ) );\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* Setup the Tx descriptor for transmission. Remember the length of the\r
+ data being sent so the second descriptor can be used to send it again from\r
+ within the ISR. */\r
+ usSendLen = usTxDataLen;\r
+ TX_DESC_PACKET( emacTX_DESC_INDEX ) = ( unsigned long ) uip_buf;\r
+ TX_DESC_CTRL( emacTX_DESC_INDEX ) = ( usTxDataLen | TCTRL_LAST | TCTRL_INT );\r
+ EMAC->TxProduceIndex = ( emacTX_DESC_INDEX + 1 );\r
+\r
+ /* uip_buf is being sent by the Tx descriptor. Allocate a new buffer. */\r
+ uip_buf = prvGetNextBuffer();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static long prvWritePHY( long lPhyReg, long lValue )\r
+{\r
+const long lMaxTime = 10;\r
+long x;\r
+\r
+ EMAC->MADR = DP83848C_DEF_ADR | lPhyReg;\r
+ EMAC->MWTD = lValue;\r
+\r
+ x = 0;\r
+ for( x = 0; x < lMaxTime; x++ )\r
+ {\r
+ if( ( EMAC->MIND & MIND_BUSY ) == 0 )\r
+ {\r
+ /* Operation has finished. */\r
+ break;\r
+ }\r
+\r
+ vTaskDelay( emacSHORT_DELAY );\r
+ }\r
+\r
+ if( x < lMaxTime )\r
+ {\r
+ return pdPASS;\r
+ }\r
+ else\r
+ {\r
+ return pdFAIL;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static unsigned short prvReadPHY( unsigned char ucPhyReg, long *plStatus )\r
+{\r
+long x;\r
+const long lMaxTime = 10;\r
+\r
+ EMAC->MADR = DP83848C_DEF_ADR | ucPhyReg;\r
+ EMAC->MCMD = MCMD_READ;\r
+\r
+ for( x = 0; x < lMaxTime; x++ )\r
+ {\r
+ /* Operation has finished. */\r
+ if( ( EMAC->MIND & MIND_BUSY ) == 0 )\r
+ {\r
+ break;\r
+ }\r
+\r
+ vTaskDelay( emacSHORT_DELAY );\r
+ }\r
+\r
+ EMAC->MCMD = 0;\r
+\r
+ if( x >= lMaxTime )\r
+ {\r
+ *plStatus = pdFAIL;\r
+ }\r
+\r
+ return( EMAC->MRDD );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vEMAC_ISR( void )\r
+{\r
+unsigned long ulStatus;\r
+long lHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ ulStatus = EMAC->IntStatus;\r
+\r
+ /* Clear the interrupt. */\r
+ EMAC->IntClear = ulStatus;\r
+\r
+ if( ulStatus & INT_RX_DONE )\r
+ {\r
+ /* Ensure the uIP task is not blocked as data has arrived. */\r
+ xSemaphoreGiveFromISR( xEMACSemaphore, &lHigherPriorityTaskWoken );\r
+ }\r
+\r
+ if( ulStatus & INT_TX_DONE )\r
+ {\r
+ if( usSendLen > 0 )\r
+ {\r
+ /* Send the data again, using the second descriptor. As there are\r
+ only two descriptors the index is set back to 0. */\r
+ TX_DESC_PACKET( ( emacTX_DESC_INDEX + 1 ) ) = TX_DESC_PACKET( emacTX_DESC_INDEX );\r
+ TX_DESC_CTRL( ( emacTX_DESC_INDEX + 1 ) ) = ( usSendLen | TCTRL_LAST | TCTRL_INT );\r
+ EMAC->TxProduceIndex = ( emacTX_DESC_INDEX );\r
+\r
+ /* This is the second Tx so set usSendLen to 0 to indicate that the\r
+ Tx descriptors will be free again. */\r
+ usSendLen = 0UL;\r
+ }\r
+ else\r
+ {\r
+ /* The Tx buffer is no longer required. */\r
+ prvReturnBuffer( ( unsigned char * ) TX_DESC_PACKET( emacTX_DESC_INDEX ) );\r
+ TX_DESC_PACKET( emacTX_DESC_INDEX ) = ( unsigned long ) NULL;\r
+ }\r
+ }\r
+\r
+ portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
+}\r
--- /dev/null
+http_http "http://"\r
+http_200 "200 "\r
+http_301 "301 "\r
+http_302 "302 "\r
+http_get "GET "\r
+http_10 "HTTP/1.0"\r
+http_11 "HTTP/1.1"\r
+http_content_type "content-type: "\r
+http_texthtml "text/html"\r
+http_location "location: "\r
+http_host "host: "\r
+http_crnl "\r\n"\r
+http_index_html "/index.html"\r
+http_404_html "/404.html"\r
+http_referer "Referer:"\r
+http_header_200 "HTTP/1.0 200 OK\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n"\r
+http_header_404 "HTTP/1.0 404 Not found\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n"\r
+http_content_type_plain "Content-type: text/plain\r\n\r\n"\r
+http_content_type_html "Content-type: text/html\r\n\r\n"\r
+http_content_type_css "Content-type: text/css\r\n\r\n"\r
+http_content_type_text "Content-type: text/text\r\n\r\n"\r
+http_content_type_png "Content-type: image/png\r\n\r\n"\r
+http_content_type_gif "Content-type: image/gif\r\n\r\n"\r
+http_content_type_jpg "Content-type: image/jpeg\r\n\r\n"\r
+http_content_type_binary "Content-type: application/octet-stream\r\n\r\n"\r
+http_html ".html"\r
+http_shtml ".shtml"\r
+http_htm ".htm"\r
+http_css ".css"\r
+http_png ".png"\r
+http_gif ".gif"\r
+http_jpg ".jpg"\r
+http_text ".txt"\r
+http_txt ".txt"\r
+\r
--- /dev/null
+const char http_http[8] = \r
+/* "http://" */\r
+{0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, };\r
+const char http_200[5] = \r
+/* "200 " */\r
+{0x32, 0x30, 0x30, 0x20, };\r
+const char http_301[5] = \r
+/* "301 " */\r
+{0x33, 0x30, 0x31, 0x20, };\r
+const char http_302[5] = \r
+/* "302 " */\r
+{0x33, 0x30, 0x32, 0x20, };\r
+const char http_get[5] = \r
+/* "GET " */\r
+{0x47, 0x45, 0x54, 0x20, };\r
+const char http_10[9] = \r
+/* "HTTP/1.0" */\r
+{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, };\r
+const char http_11[9] = \r
+/* "HTTP/1.1" */\r
+{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, };\r
+const char http_content_type[15] = \r
+/* "content-type: " */\r
+{0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, };\r
+const char http_texthtml[10] = \r
+/* "text/html" */\r
+{0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, };\r
+const char http_location[11] = \r
+/* "location: " */\r
+{0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, };\r
+const char http_host[7] = \r
+/* "host: " */\r
+{0x68, 0x6f, 0x73, 0x74, 0x3a, 0x20, };\r
+const char http_crnl[3] = \r
+/* "\r\n" */\r
+{0xd, 0xa, };\r
+const char http_index_html[12] = \r
+/* "/index.html" */\r
+{0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, };\r
+const char http_404_html[10] = \r
+/* "/404.html" */\r
+{0x2f, 0x34, 0x30, 0x34, 0x2e, 0x68, 0x74, 0x6d, 0x6c, };\r
+const char http_referer[9] = \r
+/* "Referer:" */\r
+{0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, 0x3a, };\r
+const char http_header_200[84] = \r
+/* "HTTP/1.0 200 OK\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n" */\r
+{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x75, 0x49, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x2f, 0x7e, 0x61, 0x64, 0x61, 0x6d, 0x2f, 0x75, 0x69, 0x70, 0x2f, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, };\r
+const char http_header_404[91] = \r
+/* "HTTP/1.0 404 Not found\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n" */\r
+{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x34, 0x30, 0x34, 0x20, 0x4e, 0x6f, 0x74, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x75, 0x49, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x2f, 0x7e, 0x61, 0x64, 0x61, 0x6d, 0x2f, 0x75, 0x69, 0x70, 0x2f, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, };\r
+const char http_content_type_plain[29] = \r
+/* "Content-type: text/plain\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_html[28] = \r
+/* "Content-type: text/html\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_css [27] = \r
+/* "Content-type: text/css\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x63, 0x73, 0x73, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_text[28] = \r
+/* "Content-type: text/text\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x74, 0x65, 0x78, 0x74, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_png [28] = \r
+/* "Content-type: image/png\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_gif [28] = \r
+/* "Content-type: image/gif\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, 0x69, 0x66, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_jpg [29] = \r
+/* "Content-type: image/jpeg\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x65, 0x67, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_content_type_binary[43] = \r
+/* "Content-type: application/octet-stream\r\n\r\n" */\r
+{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x74, 0x65, 0x74, 0x2d, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0xd, 0xa, 0xd, 0xa, };\r
+const char http_html[6] = \r
+/* ".html" */\r
+{0x2e, 0x68, 0x74, 0x6d, 0x6c, };\r
+const char http_shtml[7] = \r
+/* ".shtml" */\r
+{0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, };\r
+const char http_htm[5] = \r
+/* ".htm" */\r
+{0x2e, 0x68, 0x74, 0x6d, };\r
+const char http_css[5] = \r
+/* ".css" */\r
+{0x2e, 0x63, 0x73, 0x73, };\r
+const char http_png[5] = \r
+/* ".png" */\r
+{0x2e, 0x70, 0x6e, 0x67, };\r
+const char http_gif[5] = \r
+/* ".gif" */\r
+{0x2e, 0x67, 0x69, 0x66, };\r
+const char http_jpg[5] = \r
+/* ".jpg" */\r
+{0x2e, 0x6a, 0x70, 0x67, };\r
+const char http_text[5] = \r
+/* ".txt" */\r
+{0x2e, 0x74, 0x78, 0x74, };\r
+const char http_txt[5] = \r
+/* ".txt" */\r
+{0x2e, 0x74, 0x78, 0x74, };\r
--- /dev/null
+extern const char http_http[8];\r
+extern const char http_200[5];\r
+extern const char http_301[5];\r
+extern const char http_302[5];\r
+extern const char http_get[5];\r
+extern const char http_10[9];\r
+extern const char http_11[9];\r
+extern const char http_content_type[15];\r
+extern const char http_texthtml[10];\r
+extern const char http_location[11];\r
+extern const char http_host[7];\r
+extern const char http_crnl[3];\r
+extern const char http_index_html[12];\r
+extern const char http_404_html[10];\r
+extern const char http_referer[9];\r
+extern const char http_header_200[84];\r
+extern const char http_header_404[91];\r
+extern const char http_content_type_plain[29];\r
+extern const char http_content_type_html[28];\r
+extern const char http_content_type_css [27];\r
+extern const char http_content_type_text[28];\r
+extern const char http_content_type_png [28];\r
+extern const char http_content_type_gif [28];\r
+extern const char http_content_type_jpg [29];\r
+extern const char http_content_type_binary[43];\r
+extern const char http_html[6];\r
+extern const char http_shtml[7];\r
+extern const char http_htm[5];\r
+extern const char http_css[5];\r
+extern const char http_png[5];\r
+extern const char http_gif[5];\r
+extern const char http_jpg[5];\r
+extern const char http_text[5];\r
+extern const char http_txt[5];\r
--- /dev/null
+/**\r
+ * \addtogroup httpd\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Web server script interface\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2006, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: httpd-cgi.c,v 1.2 2006/06/11 21:46:37 adam Exp $\r
+ *\r
+ */\r
+\r
+#include "uip.h"\r
+#include "psock.h"\r
+#include "httpd.h"\r
+#include "httpd-cgi.h"\r
+#include "httpd-fs.h"\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+HTTPD_CGI_CALL(file, "file-stats", file_stats);\r
+HTTPD_CGI_CALL(tcp, "tcp-connections", tcp_stats);\r
+HTTPD_CGI_CALL(net, "net-stats", net_stats);\r
+HTTPD_CGI_CALL(rtos, "rtos-stats", rtos_stats );\r
+HTTPD_CGI_CALL(run, "run-time", run_time );\r
+HTTPD_CGI_CALL(io, "led-io", led_io );\r
+\r
+\r
+static const struct httpd_cgi_call *calls[] = { &file, &tcp, &net, &rtos, &run, &io, NULL };\r
+\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(nullfunction(struct httpd_state *s, char *ptr))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+ ( void ) ptr;\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+httpd_cgifunction\r
+httpd_cgi(char *name)\r
+{\r
+ const struct httpd_cgi_call **f;\r
+\r
+ /* Find the matching name in the table, return the function. */\r
+ for(f = calls; *f != NULL; ++f) {\r
+ if(strncmp((*f)->name, name, strlen((*f)->name)) == 0) {\r
+ return (*f)->function;\r
+ }\r
+ }\r
+ return nullfunction;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static unsigned short\r
+generate_file_stats(void *arg)\r
+{\r
+ char *f = (char *)arg;\r
+ return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE, "%5u", httpd_fs_count(f));\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(file_stats(struct httpd_state *s, char *ptr))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, strchr(ptr, ' ') + 1);\r
+\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static const char closed[] = /* "CLOSED",*/\r
+{0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};\r
+static const char syn_rcvd[] = /* "SYN-RCVD",*/\r
+{0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,\r
+ 0x44, 0};\r
+static const char syn_sent[] = /* "SYN-SENT",*/\r
+{0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,\r
+ 0x54, 0};\r
+static const char established[] = /* "ESTABLISHED",*/\r
+{0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48,\r
+ 0x45, 0x44, 0};\r
+static const char fin_wait_1[] = /* "FIN-WAIT-1",*/\r
+{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,\r
+ 0x54, 0x2d, 0x31, 0};\r
+static const char fin_wait_2[] = /* "FIN-WAIT-2",*/\r
+{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,\r
+ 0x54, 0x2d, 0x32, 0};\r
+static const char closing[] = /* "CLOSING",*/\r
+{0x43, 0x4c, 0x4f, 0x53, 0x49,\r
+ 0x4e, 0x47, 0};\r
+static const char time_wait[] = /* "TIME-WAIT,"*/\r
+{0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,\r
+ 0x49, 0x54, 0};\r
+static const char last_ack[] = /* "LAST-ACK"*/\r
+{0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,\r
+ 0x4b, 0};\r
+\r
+static const char *states[] = {\r
+ closed,\r
+ syn_rcvd,\r
+ syn_sent,\r
+ established,\r
+ fin_wait_1,\r
+ fin_wait_2,\r
+ closing,\r
+ time_wait,\r
+ last_ack};\r
+\r
+\r
+static unsigned short\r
+generate_tcp_stats(void *arg)\r
+{\r
+ struct uip_conn *conn;\r
+ struct httpd_state *s = (struct httpd_state *)arg;\r
+\r
+ conn = &uip_conns[s->count];\r
+ return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE,\r
+ "<tr><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",\r
+ htons(conn->lport),\r
+ htons(conn->ripaddr[0]) >> 8,\r
+ htons(conn->ripaddr[0]) & 0xff,\r
+ htons(conn->ripaddr[1]) >> 8,\r
+ htons(conn->ripaddr[1]) & 0xff,\r
+ htons(conn->rport),\r
+ states[conn->tcpstateflags & UIP_TS_MASK],\r
+ conn->nrtx,\r
+ conn->timer,\r
+ (uip_outstanding(conn))? '*':' ',\r
+ (uip_stopped(conn))? '!':' ');\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(tcp_stats(struct httpd_state *s, char *ptr))\r
+{\r
+\r
+ PSOCK_BEGIN(&s->sout);\r
+ ( void ) ptr;\r
+ for(s->count = 0; s->count < UIP_CONNS; ++s->count) {\r
+ if((uip_conns[s->count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_tcp_stats, s);\r
+ }\r
+ }\r
+\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static unsigned short\r
+generate_net_stats(void *arg)\r
+{\r
+ struct httpd_state *s = (struct httpd_state *)arg;\r
+ return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE,\r
+ "%5u\n", ((uip_stats_t *)&uip_stat)[s->count]);\r
+}\r
+\r
+static\r
+PT_THREAD(net_stats(struct httpd_state *s, char *ptr))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+\r
+ ( void ) ptr;\r
+#if UIP_STATISTICS\r
+\r
+ for(s->count = 0; s->count < sizeof(uip_stat) / sizeof(uip_stats_t);\r
+ ++s->count) {\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_net_stats, s);\r
+ }\r
+\r
+#endif /* UIP_STATISTICS */\r
+\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+extern void vTaskList( signed char *pcWriteBuffer );\r
+extern char *pcGetTaskStatusMessage( void );\r
+static char cCountBuf[ 128 ];\r
+long lRefreshCount = 0;\r
+static unsigned short\r
+generate_rtos_stats(void *arg)\r
+{\r
+ ( void ) arg;\r
+ lRefreshCount++;\r
+ sprintf( cCountBuf, "<p><br>Refresh count = %d<p><br>%s", (int)lRefreshCount, pcGetTaskStatusMessage() );\r
+ vTaskList( uip_appdata );\r
+ strcat( uip_appdata, cCountBuf );\r
+\r
+ return strlen( uip_appdata );\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+\r
+static\r
+PT_THREAD(rtos_stats(struct httpd_state *s, char *ptr))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+ ( void ) ptr;\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_rtos_stats, NULL);\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+char *pcStatus;\r
+unsigned long ulString;\r
+\r
+static unsigned short generate_io_state( void *arg )\r
+{\r
+extern long uxParTextGetLED( unsigned long ulLED );\r
+const unsigned long ulLEDNo = 3;\r
+\r
+ ( void ) arg;\r
+\r
+ if( uxParTextGetLED( ulLEDNo ) == 0 )\r
+ {\r
+ pcStatus = "";\r
+ }\r
+ else\r
+ {\r
+ pcStatus = "checked";\r
+ }\r
+\r
+ sprintf( uip_appdata,\r
+ "<input type=\"checkbox\" name=\"LED0\" value=\"1\" %s>LED<p><p>", pcStatus );\r
+\r
+ return strlen( uip_appdata );\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+extern void vTaskGetRunTimeStats( signed char *pcWriteBuffer );\r
+static unsigned short\r
+generate_runtime_stats(void *arg)\r
+{\r
+ ( void ) arg;\r
+ lRefreshCount++;\r
+ sprintf( cCountBuf, "<p><br>Refresh count = %d", (int)lRefreshCount );\r
+ vTaskGetRunTimeStats( uip_appdata );\r
+ strcat( uip_appdata, cCountBuf );\r
+\r
+ return strlen( uip_appdata );\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+\r
+static\r
+PT_THREAD(run_time(struct httpd_state *s, char *ptr))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+ ( void ) ptr;\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_runtime_stats, NULL);\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+\r
+static PT_THREAD(led_io(struct httpd_state *s, char *ptr))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+ ( void ) ptr;\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_io_state, NULL);\r
+ PSOCK_END(&s->sout);\r
+}\r
+\r
+/** @} */\r
+\r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+/**\r
+ * \addtogroup httpd\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Web server script interface header file\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+\r
+\r
+/*\r
+ * Copyright (c) 2001, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: httpd-cgi.h,v 1.2 2006/06/11 21:46:38 adam Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __HTTPD_CGI_H__\r
+#define __HTTPD_CGI_H__\r
+\r
+#include "psock.h"\r
+#include "httpd.h"\r
+\r
+typedef PT_THREAD((* httpd_cgifunction)(struct httpd_state *, char *));\r
+\r
+httpd_cgifunction httpd_cgi(char *name);\r
+\r
+struct httpd_cgi_call {\r
+ const char *name;\r
+ const httpd_cgifunction function;\r
+};\r
+\r
+/**\r
+ * \brief HTTPD CGI function declaration\r
+ * \param name The C variable name of the function\r
+ * \param str The string name of the function, used in the script file\r
+ * \param function A pointer to the function that implements it\r
+ *\r
+ * This macro is used for declaring a HTTPD CGI\r
+ * function. This function is then added to the list of\r
+ * HTTPD CGI functions with the httpd_cgi_add() function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define HTTPD_CGI_CALL(name, str, function) \\r
+static PT_THREAD(function(struct httpd_state *, char *)); \\r
+static const struct httpd_cgi_call name = {str, function}\r
+\r
+void httpd_cgi_init(void);\r
+#endif /* __HTTPD_CGI_H__ */\r
+\r
+/** @} */\r
--- /dev/null
+/*\r
+ * Copyright (c) 2001, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the lwIP TCP/IP stack.\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: httpd-fs.c,v 1.1 2006/06/07 09:13:08 adam Exp $\r
+ */\r
+\r
+#include "httpd.h"\r
+#include "httpd-fs.h"\r
+#include "httpd-fsdata.h"\r
+\r
+#ifndef NULL\r
+#define NULL 0\r
+#endif /* NULL */\r
+\r
+#include "httpd-fsdata.c"\r
+\r
+#if HTTPD_FS_STATISTICS\r
+static u16_t count[HTTPD_FS_NUMFILES];\r
+#endif /* HTTPD_FS_STATISTICS */\r
+\r
+/*-----------------------------------------------------------------------------------*/\r
+static u8_t\r
+httpd_fs_strcmp(const char *str1, const char *str2)\r
+{\r
+ u8_t i;\r
+ i = 0;\r
+ loop:\r
+\r
+ if(str2[i] == 0 ||\r
+ str1[i] == '\r' ||\r
+ str1[i] == '\n') {\r
+ return 0;\r
+ }\r
+\r
+ if(str1[i] != str2[i]) {\r
+ return 1;\r
+ }\r
+\r
+\r
+ ++i;\r
+ goto loop;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+int\r
+httpd_fs_open(const char *name, struct httpd_fs_file *file)\r
+{\r
+#if HTTPD_FS_STATISTICS\r
+ u16_t i = 0;\r
+#endif /* HTTPD_FS_STATISTICS */\r
+ struct httpd_fsdata_file_noconst *f;\r
+\r
+ for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;\r
+ f != NULL;\r
+ f = (struct httpd_fsdata_file_noconst *)f->next) {\r
+\r
+ if(httpd_fs_strcmp(name, f->name) == 0) {\r
+ file->data = f->data;\r
+ file->len = f->len;\r
+#if HTTPD_FS_STATISTICS\r
+ ++count[i];\r
+#endif /* HTTPD_FS_STATISTICS */\r
+ return 1;\r
+ }\r
+#if HTTPD_FS_STATISTICS\r
+ ++i;\r
+#endif /* HTTPD_FS_STATISTICS */\r
+\r
+ }\r
+ return 0;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+httpd_fs_init(void)\r
+{\r
+#if HTTPD_FS_STATISTICS\r
+ u16_t i;\r
+ for(i = 0; i < HTTPD_FS_NUMFILES; i++) {\r
+ count[i] = 0;\r
+ }\r
+#endif /* HTTPD_FS_STATISTICS */\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+#if HTTPD_FS_STATISTICS\r
+u16_t httpd_fs_count\r
+(char *name)\r
+{\r
+ struct httpd_fsdata_file_noconst *f;\r
+ u16_t i;\r
+\r
+ i = 0;\r
+ for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;\r
+ f != NULL;\r
+ f = (struct httpd_fsdata_file_noconst *)f->next) {\r
+\r
+ if(httpd_fs_strcmp(name, f->name) == 0) {\r
+ return count[i];\r
+ }\r
+ ++i;\r
+ }\r
+ return 0;\r
+}\r
+#endif /* HTTPD_FS_STATISTICS */\r
+/*-----------------------------------------------------------------------------------*/\r
--- /dev/null
+/*\r
+ * Copyright (c) 2001, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the lwIP TCP/IP stack.\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: httpd-fs.h,v 1.1 2006/06/07 09:13:08 adam Exp $\r
+ */\r
+#ifndef __HTTPD_FS_H__\r
+#define __HTTPD_FS_H__\r
+\r
+#define HTTPD_FS_STATISTICS 1\r
+\r
+struct httpd_fs_file {\r
+ char *data;\r
+ int len;\r
+};\r
+\r
+/* file must be allocated by caller and will be filled in\r
+ by the function. */\r
+int httpd_fs_open(const char *name, struct httpd_fs_file *file);\r
+\r
+#ifdef HTTPD_FS_STATISTICS\r
+#if HTTPD_FS_STATISTICS == 1\r
+u16_t httpd_fs_count(char *name);\r
+#endif /* HTTPD_FS_STATISTICS */\r
+#endif /* HTTPD_FS_STATISTICS */\r
+\r
+void httpd_fs_init(void);\r
+\r
+#endif /* __HTTPD_FS_H__ */\r
--- /dev/null
+<html>\r
+ <body bgcolor="white">\r
+ <center>\r
+ <h1>404 - file not found</h1>\r
+ <h3>Go <a href="/">here</a> instead.</h3>\r
+ </center>\r
+ </body>\r
+</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
+<html>\r
+ <head>\r
+ <title>FreeRTOS.org uIP WEB server demo</title>\r
+ </head>\r
+ <BODY onLoad="window.setTimeout("location.href='index.shtml'",100)">\r
+<font face="arial">\r
+Loading index.shtml. Click <a href="index.shtml">here</a> if not automatically redirected.\r
+</font>\r
+</font>\r
+</body>\r
+</html>\r
+\r
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
+<html>\r
+ <head>\r
+ <title>FreeRTOS.org uIP WEB server demo</title>\r
+ </head>\r
+ <BODY onLoad="window.setTimeout("location.href='index.shtml'",2000)">\r
+<font face="arial">\r
+<a href="index.shtml">Task Stats</a> <b>|</b> <a href="runtime.shtml">Run Time Stats</a> <b>|</b> <a href="stats.shtml">TCP Stats</a> <b>|</b> <a href="tcp.shtml">Connections</a> <b>|</b> <a href="http://www.freertos.org/">FreeRTOS.org Homepage</a> <b>|</b> <a href="io.shtml">IO</a>\r
+<br><p>\r
+<hr>\r
+<br><p>\r
+<h2>Task statistics</h2>\r
+Page will refresh every 2 seconds.<p>\r
+<font face="courier"><pre>Task State Priority Stack #<br>************************************************<br>\r
+%! rtos-stats\r
+</pre></font>\r
+</font>\r
+</body>\r
+</html>\r
+\r
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
+<html>\r
+ <head>\r
+ <title>FreeRTOS.org uIP WEB server demo</title>\r
+ </head>\r
+ <BODY>\r
+<font face="arial">\r
+<a href="index.shtml">Task Stats</a> <b>|</b> <a href="runtime.shtml">Run Time Stats</a> <b>|</b> <a href="stats.shtml">TCP Stats</a> <b>|</b> <a href="tcp.shtml">Connections</a> <b>|</b> <a href="http://www.freertos.org/">FreeRTOS.org Homepage</a> <b>|</b> <a href="io.shtml">IO</a>\r
+<br><p>\r
+<hr>\r
+<b>LED and LCD IO</b><br>\r
+\r
+<p>\r
+\r
+Use the check box to turn on or off the LED, enter text to display on the OLED display, then click "Update IO".\r
+\r
+\r
+<p>\r
+<form name="aForm" action="/io.shtml" method="get">\r
+%! led-io\r
+<p>\r
+<input type="submit" value="Update IO">\r
+</form>\r
+<br><p>\r
+</font>\r
+</body>\r
+</html>\r
+\r
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
+<html>\r
+ <head>\r
+ <title>FreeRTOS.org uIP WEB server demo</title>\r
+ </head>\r
+ <BODY onLoad="window.setTimeout("location.href='runtime.shtml'",2000)">\r
+<font face="arial">\r
+<a href="index.shtml">Task Stats</a> <b>|</b> <a href="runtime.shtml">Run Time Stats</a> <b>|</b> <a href="stats.shtml">TCP Stats</a> <b>|</b> <a href="tcp.shtml">Connections</a> <b>|</b> <a href="http://www.freertos.org/">FreeRTOS.org Homepage</a> <b>|</b> <a href="io.shtml">IO</a>\r
+<br><p>\r
+<hr>\r
+<br><p>\r
+<h2>Run-time statistics</h2>\r
+Page will refresh every 2 seconds.<p>\r
+<font face="courier"><pre>Task Abs Time % Time<br>****************************************<br>\r
+%! run-time\r
+</pre></font>\r
+</font>\r
+</body>\r
+</html>\r
+\r
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
+<html>\r
+ <head>\r
+ <title>FreeRTOS.org uIP WEB server demo</title>\r
+ </head>\r
+ <BODY>\r
+<font face="arial">\r
+<a href="index.shtml">Task Stats</a> <b>|</b> <a href="runtime.shtml">Run Time Stats</a> <b>|</b> <a href="stats.shtml">TCP Stats</a> <b>|</b> <a href="tcp.shtml">Connections</a> <b>|</b> <a href="http://www.freertos.org/">FreeRTOS.org Homepage</a> <b>|</b> <a href="io.shtml">IO</a>\r
+<br><p>\r
+<hr>\r
+<br><p>\r
+<h2>Network statistics</h2>\r
+<table width="300" border="0">\r
+<tr><td align="left"><font face="courier"><pre>\r
+IP Packets dropped\r
+ Packets received\r
+ Packets sent\r
+IP errors IP version/header length\r
+ IP length, high byte\r
+ IP length, low byte\r
+ IP fragments\r
+ Header checksum\r
+ Wrong protocol\r
+ICMP Packets dropped\r
+ Packets received\r
+ Packets sent\r
+ Type errors\r
+TCP Packets dropped\r
+ Packets received\r
+ Packets sent\r
+ Checksum errors\r
+ Data packets without ACKs\r
+ Resets\r
+ Retransmissions\r
+ No connection avaliable\r
+ Connection attempts to closed ports\r
+</pre></font></td><td><pre>%! net-stats\r
+</pre></table>\r
+</font>\r
+</body>\r
+</html>\r
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
+<html>\r
+ <head>\r
+ <title>FreeRTOS.org uIP WEB server demo</title>\r
+ </head>\r
+ <BODY>\r
+<font face="arial">\r
+<a href="index.shtml">Task Stats</a> <b>|</b> <a href="runtime.shtml">Run Time Stats</a> <b>|</b> <a href="stats.shtml">TCP Stats</a> <b>|</b> <a href="tcp.shtml">Connections</a> <b>|</b> <a href="http://www.freertos.org/">FreeRTOS.org Homepage</a> <b>|</b> <a href="io.shtml">IO</a>\r
+<br><p>\r
+<hr>\r
+<br>\r
+<h2>Network connections</h2>\r
+<p>\r
+<table>\r
+<tr><th>Local</th><th>Remote</th><th>State</th><th>Retransmissions</th><th>Timer</th><th>Flags</th></tr>\r
+%! tcp-connections\r
+</pre></font>\r
+</font>\r
+</body>\r
+</html>\r
+\r
--- /dev/null
+static const char data_404_html[] = {\r
+ /* /404.html */\r
+ 0x2f, 0x34, 0x30, 0x34, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0x20, 0x20, 0x3c, \r
+ 0x62, 0x6f, 0x64, 0x79, 0x20, 0x62, 0x67, 0x63, 0x6f, 0x6c, \r
+ 0x6f, 0x72, 0x3d, 0x22, 0x77, 0x68, 0x69, 0x74, 0x65, 0x22, \r
+ 0x3e, 0xa, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x63, 0x65, 0x6e, \r
+ 0x74, 0x65, 0x72, 0x3e, 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x3c, 0x68, 0x31, 0x3e, 0x34, 0x30, 0x34, 0x20, 0x2d, \r
+ 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20, \r
+ 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x3c, 0x2f, 0x68, 0x31, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x68, 0x33, \r
+ 0x3e, 0x47, 0x6f, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, \r
+ 0x66, 0x3d, 0x22, 0x2f, 0x22, 0x3e, 0x68, 0x65, 0x72, 0x65, \r
+ 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x69, 0x6e, 0x73, 0x74, 0x65, \r
+ 0x61, 0x64, 0x2e, 0x3c, 0x2f, 0x68, 0x33, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65, \r
+ 0x72, 0x3e, 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64, \r
+ 0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, \r
+0};\r
+\r
+static const char data_index_html[] = {\r
+ /* /index.html */\r
+ 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, \r
+ 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, \r
+ 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, \r
+ 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, \r
+ 0x34, 0x2e, 0x30, 0x31, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, \r
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x2f, 0x45, \r
+ 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, \r
+ 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, \r
+ 0x67, 0x2f, 0x54, 0x52, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, \r
+ 0x2f, 0x6c, 0x6f, 0x6f, 0x73, 0x65, 0x2e, 0x64, 0x74, 0x64, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, \r
+ 0x20, 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, \r
+ 0x72, 0x67, 0x20, 0x75, 0x49, 0x50, 0x20, 0x57, 0x45, 0x42, \r
+ 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x64, 0x65, \r
+ 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x42, 0x4f, 0x44, 0x59, 0x20, 0x6f, \r
+ 0x6e, 0x4c, 0x6f, 0x61, 0x64, 0x3d, 0x22, 0x77, 0x69, 0x6e, \r
+ 0x64, 0x6f, 0x77, 0x2e, 0x73, 0x65, 0x74, 0x54, 0x69, 0x6d, \r
+ 0x65, 0x6f, 0x75, 0x74, 0x28, 0x26, 0x71, 0x75, 0x6f, 0x74, \r
+ 0x3b, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, \r
+ 0x68, 0x72, 0x65, 0x66, 0x3d, 0x27, 0x69, 0x6e, 0x64, 0x65, \r
+ 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x27, 0x26, 0x71, \r
+ 0x75, 0x6f, 0x74, 0x3b, 0x2c, 0x31, 0x30, 0x30, 0x29, 0x22, \r
+ 0x3e, 0xa, 0x3c, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x66, 0x61, \r
+ 0x63, 0x65, 0x3d, 0x22, 0x61, 0x72, 0x69, 0x61, 0x6c, 0x22, \r
+ 0x3e, 0xa, 0x4c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, \r
+ 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x2e, 0x20, 0x20, 0x43, 0x6c, 0x69, 0x63, 0x6b, 0x20, \r
+ 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, \r
+ 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, \r
+ 0x22, 0x3e, 0x68, 0x65, 0x72, 0x65, 0x3c, 0x2f, 0x61, 0x3e, \r
+ 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x61, 0x75, \r
+ 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x6c, \r
+ 0x79, 0x20, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, \r
+ 0x65, 0x64, 0x2e, 0xa, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, \r
+ 0x3e, 0xa, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0xa, \r
+ 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0xa, 0x3c, 0x2f, \r
+ 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0xa, 0};\r
+\r
+static const char data_index_shtml[] = {\r
+ /* /index.shtml */\r
+ 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, \r
+ 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, \r
+ 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, \r
+ 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, \r
+ 0x34, 0x2e, 0x30, 0x31, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, \r
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x2f, 0x45, \r
+ 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, \r
+ 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, \r
+ 0x67, 0x2f, 0x54, 0x52, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, \r
+ 0x2f, 0x6c, 0x6f, 0x6f, 0x73, 0x65, 0x2e, 0x64, 0x74, 0x64, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, \r
+ 0x20, 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, \r
+ 0x72, 0x67, 0x20, 0x75, 0x49, 0x50, 0x20, 0x57, 0x45, 0x42, \r
+ 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x64, 0x65, \r
+ 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x42, 0x4f, 0x44, 0x59, 0x20, 0x6f, \r
+ 0x6e, 0x4c, 0x6f, 0x61, 0x64, 0x3d, 0x22, 0x77, 0x69, 0x6e, \r
+ 0x64, 0x6f, 0x77, 0x2e, 0x73, 0x65, 0x74, 0x54, 0x69, 0x6d, \r
+ 0x65, 0x6f, 0x75, 0x74, 0x28, 0x26, 0x71, 0x75, 0x6f, 0x74, \r
+ 0x3b, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, \r
+ 0x68, 0x72, 0x65, 0x66, 0x3d, 0x27, 0x69, 0x6e, 0x64, 0x65, \r
+ 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x27, 0x26, 0x71, \r
+ 0x75, 0x6f, 0x74, 0x3b, 0x2c, 0x32, 0x30, 0x30, 0x30, 0x29, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x66, \r
+ 0x61, 0x63, 0x65, 0x3d, 0x22, 0x61, 0x72, 0x69, 0x61, 0x6c, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, \r
+ 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x54, 0x61, 0x73, 0x6b, 0x20, \r
+ 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, \r
+ 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, \r
+ 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x72, 0x75, \r
+ 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x73, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x22, 0x3e, 0x52, 0x75, 0x6e, 0x20, 0x54, 0x69, 0x6d, \r
+ 0x65, 0x20, 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, \r
+ 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, \r
+ 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, \r
+ 0x73, 0x74, 0x61, 0x74, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x22, 0x3e, 0x54, 0x43, 0x50, 0x20, 0x53, 0x74, 0x61, \r
+ 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, \r
+ 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, \r
+ 0x72, 0x65, 0x66, 0x3d, 0x22, 0x74, 0x63, 0x70, 0x2e, 0x73, \r
+ 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x43, 0x6f, 0x6e, 0x6e, \r
+ 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3c, 0x2f, 0x61, \r
+ 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, \r
+ 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, \r
+ 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, \r
+ 0x2e, 0x66, 0x72, 0x65, 0x65, 0x72, 0x74, 0x6f, 0x73, 0x2e, \r
+ 0x6f, 0x72, 0x67, 0x2f, 0x22, 0x3e, 0x46, 0x72, 0x65, 0x65, \r
+ 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, 0x72, 0x67, 0x20, 0x48, \r
+ 0x6f, 0x6d, 0x65, 0x70, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x61, \r
+ 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, \r
+ 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, \r
+ 0x69, 0x6f, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x49, 0x4f, 0x3c, 0x2f, 0x61, 0x3e, 0xa, 0x3c, 0x62, 0x72, \r
+ 0x3e, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x68, 0x72, 0x3e, 0xa, \r
+ 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x68, \r
+ 0x32, 0x3e, 0x54, 0x61, 0x73, 0x6b, 0x20, 0x73, 0x74, 0x61, \r
+ 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x3c, 0x2f, 0x68, \r
+ 0x32, 0x3e, 0xa, 0x50, 0x61, 0x67, 0x65, 0x20, 0x77, 0x69, \r
+ 0x6c, 0x6c, 0x20, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, \r
+ 0x20, 0x65, 0x76, 0x65, 0x72, 0x79, 0x20, 0x32, 0x20, 0x73, \r
+ 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x2e, 0x3c, 0x70, 0x3e, \r
+ 0xa, 0x3c, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x66, 0x61, 0x63, \r
+ 0x65, 0x3d, 0x22, 0x63, 0x6f, 0x75, 0x72, 0x69, 0x65, 0x72, \r
+ 0x22, 0x3e, 0x3c, 0x70, 0x72, 0x65, 0x3e, 0x54, 0x61, 0x73, \r
+ 0x6b, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x53, 0x74, 0x61, 0x74, 0x65, 0x20, 0x20, 0x50, 0x72, \r
+ 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x20, 0x20, 0x53, 0x74, \r
+ 0x61, 0x63, 0x6b, 0x9, 0x23, 0x3c, 0x62, 0x72, 0x3e, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x3c, 0x62, 0x72, \r
+ 0x3e, 0xa, 0x25, 0x21, 0x20, 0x72, 0x74, 0x6f, 0x73, 0x2d, \r
+ 0x73, 0x74, 0x61, 0x74, 0x73, 0xa, 0x3c, 0x2f, 0x70, 0x72, \r
+ 0x65, 0x3e, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0xa, \r
+ 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0xa, 0x3c, 0x2f, \r
+ 0x62, 0x6f, 0x64, 0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, 0x74, \r
+ 0x6d, 0x6c, 0x3e, 0xa, 0xa, 0};\r
+\r
+static const char data_io_shtml[] = {\r
+ /* /io.shtml */\r
+ 0x2f, 0x69, 0x6f, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, \r
+ 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, \r
+ 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, \r
+ 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, \r
+ 0x34, 0x2e, 0x30, 0x31, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, \r
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x2f, 0x45, \r
+ 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, \r
+ 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, \r
+ 0x67, 0x2f, 0x54, 0x52, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, \r
+ 0x2f, 0x6c, 0x6f, 0x6f, 0x73, 0x65, 0x2e, 0x64, 0x74, 0x64, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, \r
+ 0x20, 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, \r
+ 0x72, 0x67, 0x20, 0x75, 0x49, 0x50, 0x20, 0x57, 0x45, 0x42, \r
+ 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x64, 0x65, \r
+ 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x42, 0x4f, 0x44, 0x59, 0x3e, 0xa, \r
+ 0x3c, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x66, 0x61, 0x63, 0x65, \r
+ 0x3d, 0x22, 0x61, 0x72, 0x69, 0x61, 0x6c, 0x22, 0x3e, 0xa, \r
+ 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, \r
+ 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, \r
+ 0x22, 0x3e, 0x54, 0x61, 0x73, 0x6b, 0x20, 0x53, 0x74, 0x61, \r
+ 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, \r
+ 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, \r
+ 0x72, 0x65, 0x66, 0x3d, 0x22, 0x72, 0x75, 0x6e, 0x74, 0x69, \r
+ 0x6d, 0x65, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x52, 0x75, 0x6e, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x20, 0x53, \r
+ 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x73, 0x74, 0x61, \r
+ 0x74, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x54, 0x43, 0x50, 0x20, 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, \r
+ 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x74, 0x63, 0x70, 0x2e, 0x73, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x22, 0x3e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, \r
+ 0x69, 0x6f, 0x6e, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, \r
+ 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x66, 0x72, \r
+ 0x65, 0x65, 0x72, 0x74, 0x6f, 0x73, 0x2e, 0x6f, 0x72, 0x67, \r
+ 0x2f, 0x22, 0x3e, 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, \r
+ 0x53, 0x2e, 0x6f, 0x72, 0x67, 0x20, 0x48, 0x6f, 0x6d, 0x65, \r
+ 0x70, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, 0x6f, 0x2e, \r
+ 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x49, 0x4f, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0xa, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, \r
+ 0x3e, 0xa, 0x3c, 0x68, 0x72, 0x3e, 0xa, 0x3c, 0x62, 0x3e, \r
+ 0x4c, 0x45, 0x44, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x4c, 0x43, \r
+ 0x44, 0x20, 0x49, 0x4f, 0x3c, 0x2f, 0x62, 0x3e, 0x3c, 0x62, \r
+ 0x72, 0x3e, 0xa, 0xa, 0x3c, 0x70, 0x3e, 0xa, 0xa, 0x55, \r
+ 0x73, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x68, 0x65, \r
+ 0x63, 0x6b, 0x20, 0x62, 0x6f, 0x78, 0x20, 0x74, 0x6f, 0x20, \r
+ 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x6e, 0x20, 0x6f, 0x72, \r
+ 0x20, 0x6f, 0x66, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4c, \r
+ 0x45, 0x44, 0x2c, 0x20, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x20, \r
+ 0x74, 0x65, 0x78, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x64, 0x69, \r
+ 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x6f, 0x6e, 0x20, 0x74, \r
+ 0x68, 0x65, 0x20, 0x4f, 0x4c, 0x45, 0x44, 0x20, 0x64, 0x69, \r
+ 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x20, 0x74, 0x68, 0x65, \r
+ 0x6e, 0x20, 0x63, 0x6c, 0x69, 0x63, 0x6b, 0x20, 0x22, 0x55, \r
+ 0x70, 0x64, 0x61, 0x74, 0x65, 0x20, 0x49, 0x4f, 0x22, 0x2e, \r
+ 0xa, 0xa, 0xa, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x66, 0x6f, \r
+ 0x72, 0x6d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x61, \r
+ 0x46, 0x6f, 0x72, 0x6d, 0x22, 0x20, 0x61, 0x63, 0x74, 0x69, \r
+ 0x6f, 0x6e, 0x3d, 0x22, 0x2f, 0x69, 0x6f, 0x2e, 0x73, 0x68, \r
+ 0x74, 0x6d, 0x6c, 0x22, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, \r
+ 0x64, 0x3d, 0x22, 0x67, 0x65, 0x74, 0x22, 0x3e, 0xa, 0x25, \r
+ 0x21, 0x20, 0x6c, 0x65, 0x64, 0x2d, 0x69, 0x6f, 0xa, 0x3c, \r
+ 0x70, 0x3e, 0xa, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, \r
+ 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, \r
+ 0x69, 0x74, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, \r
+ 0x22, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x20, 0x49, 0x4f, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x3e, \r
+ 0xa, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, 0x3e, 0xa, 0x3c, \r
+ 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0xa, 0x3c, 0x2f, 0x62, \r
+ 0x6f, 0x64, 0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x3e, 0xa, 0xa, 0};\r
+\r
+static const char data_runtime_shtml[] = {\r
+ /* /runtime.shtml */\r
+ 0x2f, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, \r
+ 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, \r
+ 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, \r
+ 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, \r
+ 0x34, 0x2e, 0x30, 0x31, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, \r
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x2f, 0x45, \r
+ 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, \r
+ 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, \r
+ 0x67, 0x2f, 0x54, 0x52, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, \r
+ 0x2f, 0x6c, 0x6f, 0x6f, 0x73, 0x65, 0x2e, 0x64, 0x74, 0x64, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, \r
+ 0x20, 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, \r
+ 0x72, 0x67, 0x20, 0x75, 0x49, 0x50, 0x20, 0x57, 0x45, 0x42, \r
+ 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x64, 0x65, \r
+ 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x42, 0x4f, 0x44, 0x59, 0x20, 0x6f, \r
+ 0x6e, 0x4c, 0x6f, 0x61, 0x64, 0x3d, 0x22, 0x77, 0x69, 0x6e, \r
+ 0x64, 0x6f, 0x77, 0x2e, 0x73, 0x65, 0x74, 0x54, 0x69, 0x6d, \r
+ 0x65, 0x6f, 0x75, 0x74, 0x28, 0x26, 0x71, 0x75, 0x6f, 0x74, \r
+ 0x3b, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, \r
+ 0x68, 0x72, 0x65, 0x66, 0x3d, 0x27, 0x72, 0x75, 0x6e, 0x74, \r
+ 0x69, 0x6d, 0x65, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x27, \r
+ 0x26, 0x71, 0x75, 0x6f, 0x74, 0x3b, 0x2c, 0x32, 0x30, 0x30, \r
+ 0x30, 0x29, 0x22, 0x3e, 0xa, 0x3c, 0x66, 0x6f, 0x6e, 0x74, \r
+ 0x20, 0x66, 0x61, 0x63, 0x65, 0x3d, 0x22, 0x61, 0x72, 0x69, \r
+ 0x61, 0x6c, 0x22, 0x3e, 0xa, 0x3c, 0x61, 0x20, 0x68, 0x72, \r
+ 0x65, 0x66, 0x3d, 0x22, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, \r
+ 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x54, 0x61, 0x73, \r
+ 0x6b, 0x20, 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, \r
+ 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, \r
+ 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, \r
+ 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x73, 0x68, \r
+ 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x52, 0x75, 0x6e, 0x20, 0x54, \r
+ 0x69, 0x6d, 0x65, 0x20, 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, \r
+ 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x73, 0x74, 0x61, 0x74, 0x73, 0x2e, 0x73, 0x68, \r
+ 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x54, 0x43, 0x50, 0x20, 0x53, \r
+ 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x74, 0x63, 0x70, \r
+ 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x43, 0x6f, \r
+ 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, \r
+ 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, \r
+ 0x77, 0x77, 0x2e, 0x66, 0x72, 0x65, 0x65, 0x72, 0x74, 0x6f, \r
+ 0x73, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x22, 0x3e, 0x46, 0x72, \r
+ 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, 0x72, 0x67, \r
+ 0x20, 0x48, 0x6f, 0x6d, 0x65, 0x70, 0x61, 0x67, 0x65, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, \r
+ 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x69, 0x6f, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, \r
+ 0x22, 0x3e, 0x49, 0x4f, 0x3c, 0x2f, 0x61, 0x3e, 0xa, 0x3c, \r
+ 0x62, 0x72, 0x3e, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x68, 0x72, \r
+ 0x3e, 0xa, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, 0x3e, 0xa, \r
+ 0x3c, 0x68, 0x32, 0x3e, 0x52, 0x75, 0x6e, 0x2d, 0x74, 0x69, \r
+ 0x6d, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, \r
+ 0x69, 0x63, 0x73, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0xa, 0x50, \r
+ 0x61, 0x67, 0x65, 0x20, 0x77, 0x69, 0x6c, 0x6c, 0x20, 0x72, \r
+ 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x20, 0x65, 0x76, 0x65, \r
+ 0x72, 0x79, 0x20, 0x32, 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, \r
+ 0x64, 0x73, 0x2e, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x66, 0x6f, \r
+ 0x6e, 0x74, 0x20, 0x66, 0x61, 0x63, 0x65, 0x3d, 0x22, 0x63, \r
+ 0x6f, 0x75, 0x72, 0x69, 0x65, 0x72, 0x22, 0x3e, 0x3c, 0x70, \r
+ 0x72, 0x65, 0x3e, 0x54, 0x61, 0x73, 0x6b, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x41, \r
+ 0x62, 0x73, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x25, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x3c, \r
+ 0x62, 0x72, 0x3e, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, \r
+ 0x2a, 0x2a, 0x2a, 0x3c, 0x62, 0x72, 0x3e, 0xa, 0x25, 0x21, \r
+ 0x20, 0x72, 0x75, 0x6e, 0x2d, 0x74, 0x69, 0x6d, 0x65, 0xa, \r
+ 0x3c, 0x2f, 0x70, 0x72, 0x65, 0x3e, 0x3c, 0x2f, 0x66, 0x6f, \r
+ 0x6e, 0x74, 0x3e, 0xa, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, \r
+ 0x3e, 0xa, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0xa, \r
+ 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0xa, 0};\r
+\r
+static const char data_stats_shtml[] = {\r
+ /* /stats.shtml */\r
+ 0x2f, 0x73, 0x74, 0x61, 0x74, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, \r
+ 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, \r
+ 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, \r
+ 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, \r
+ 0x34, 0x2e, 0x30, 0x31, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, \r
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x2f, 0x45, \r
+ 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, \r
+ 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, \r
+ 0x67, 0x2f, 0x54, 0x52, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, \r
+ 0x2f, 0x6c, 0x6f, 0x6f, 0x73, 0x65, 0x2e, 0x64, 0x74, 0x64, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, \r
+ 0x20, 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, \r
+ 0x72, 0x67, 0x20, 0x75, 0x49, 0x50, 0x20, 0x57, 0x45, 0x42, \r
+ 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x64, 0x65, \r
+ 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x42, 0x4f, 0x44, 0x59, 0x3e, 0xa, \r
+ 0x3c, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x66, 0x61, 0x63, 0x65, \r
+ 0x3d, 0x22, 0x61, 0x72, 0x69, 0x61, 0x6c, 0x22, 0x3e, 0xa, \r
+ 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, \r
+ 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, \r
+ 0x22, 0x3e, 0x54, 0x61, 0x73, 0x6b, 0x20, 0x53, 0x74, 0x61, \r
+ 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, \r
+ 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, \r
+ 0x72, 0x65, 0x66, 0x3d, 0x22, 0x72, 0x75, 0x6e, 0x74, 0x69, \r
+ 0x6d, 0x65, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x52, 0x75, 0x6e, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x20, 0x53, \r
+ 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x73, 0x74, 0x61, \r
+ 0x74, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x54, 0x43, 0x50, 0x20, 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, \r
+ 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x74, 0x63, 0x70, 0x2e, 0x73, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x22, 0x3e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, \r
+ 0x69, 0x6f, 0x6e, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, \r
+ 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x66, 0x72, \r
+ 0x65, 0x65, 0x72, 0x74, 0x6f, 0x73, 0x2e, 0x6f, 0x72, 0x67, \r
+ 0x2f, 0x22, 0x3e, 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, \r
+ 0x53, 0x2e, 0x6f, 0x72, 0x67, 0x20, 0x48, 0x6f, 0x6d, 0x65, \r
+ 0x70, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, 0x6f, 0x2e, \r
+ 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x49, 0x4f, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0xa, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, \r
+ 0x3e, 0xa, 0x3c, 0x68, 0x72, 0x3e, 0xa, 0x3c, 0x62, 0x72, \r
+ 0x3e, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x68, 0x32, 0x3e, 0x4e, \r
+ 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x73, 0x74, 0x61, \r
+ 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x3c, 0x2f, 0x68, \r
+ 0x32, 0x3e, 0xa, 0x3c, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, \r
+ 0x77, 0x69, 0x64, 0x74, 0x68, 0x3d, 0x22, 0x33, 0x30, 0x30, \r
+ 0x22, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x3d, 0x22, \r
+ 0x30, 0x22, 0x3e, 0xa, 0x3c, 0x74, 0x72, 0x3e, 0x3c, 0x74, \r
+ 0x64, 0x20, 0x61, 0x6c, 0x69, 0x67, 0x6e, 0x3d, 0x22, 0x6c, \r
+ 0x65, 0x66, 0x74, 0x22, 0x3e, 0x3c, 0x66, 0x6f, 0x6e, 0x74, \r
+ 0x20, 0x66, 0x61, 0x63, 0x65, 0x3d, 0x22, 0x63, 0x6f, 0x75, \r
+ 0x72, 0x69, 0x65, 0x72, 0x22, 0x3e, 0x3c, 0x70, 0x72, 0x65, \r
+ 0x3e, 0xa, 0x49, 0x50, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, \r
+ 0x74, 0x73, 0x20, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x73, 0x65, 0x6e, 0x74, 0xa, 0x49, 0x50, 0x20, \r
+ 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x20, 0x20, 0x20, 0x20, \r
+ 0x49, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, \r
+ 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x6c, 0x65, \r
+ 0x6e, 0x67, 0x74, 0x68, 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x49, 0x50, \r
+ 0x20, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x2c, 0x20, 0x68, \r
+ 0x69, 0x67, 0x68, 0x20, 0x62, 0x79, 0x74, 0x65, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x49, 0x50, 0x20, 0x6c, 0x65, 0x6e, 0x67, 0x74, \r
+ 0x68, 0x2c, 0x20, 0x6c, 0x6f, 0x77, 0x20, 0x62, 0x79, 0x74, \r
+ 0x65, 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x49, 0x50, 0x20, 0x66, 0x72, \r
+ 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0xa, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x63, 0x68, \r
+ 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0xa, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x57, 0x72, 0x6f, 0x6e, 0x67, 0x20, 0x70, 0x72, 0x6f, 0x74, \r
+ 0x6f, 0x63, 0x6f, 0x6c, 0xa, 0x49, 0x43, 0x4d, 0x50, 0x9, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, \r
+ 0x74, 0x73, 0x20, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x73, 0x65, 0x6e, 0x74, 0xa, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x54, 0x79, 0x70, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, \r
+ 0x73, 0xa, 0x54, 0x43, 0x50, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, \r
+ 0x74, 0x73, 0x20, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, \r
+ 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x73, 0x65, 0x6e, 0x74, 0xa, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x43, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x20, 0x65, \r
+ 0x72, 0x72, 0x6f, 0x72, 0x73, 0xa, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x44, \r
+ 0x61, 0x74, 0x61, 0x20, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, \r
+ 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, \r
+ 0x41, 0x43, 0x4b, 0x73, 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x52, 0x65, \r
+ 0x73, 0x65, 0x74, 0x73, 0xa, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x52, 0x65, \r
+ 0x74, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x69, \r
+ 0x6f, 0x6e, 0x73, 0xa, 0x9, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x4e, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, \r
+ 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x76, 0x61, 0x6c, 0x69, 0x61, \r
+ 0x62, 0x6c, 0x65, 0xa, 0x9, 0x20, 0x20, 0x20, 0x20, 0x20, \r
+ 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, \r
+ 0x20, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x20, \r
+ 0x74, 0x6f, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x20, \r
+ 0x70, 0x6f, 0x72, 0x74, 0x73, 0xa, 0x3c, 0x2f, 0x70, 0x72, \r
+ 0x65, 0x3e, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0x3c, \r
+ 0x2f, 0x74, 0x64, 0x3e, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x70, \r
+ 0x72, 0x65, 0x3e, 0x25, 0x21, 0x20, 0x6e, 0x65, 0x74, 0x2d, \r
+ 0x73, 0x74, 0x61, 0x74, 0x73, 0xa, 0x3c, 0x2f, 0x70, 0x72, \r
+ 0x65, 0x3e, 0x3c, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0xa, 0x3c, \r
+ 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, \r
+ 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0};\r
+\r
+static const char data_tcp_shtml[] = {\r
+ /* /tcp.shtml */\r
+ 0x2f, 0x74, 0x63, 0x70, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,\r
+ 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, \r
+ 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, \r
+ 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, \r
+ 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, \r
+ 0x34, 0x2e, 0x30, 0x31, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, \r
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x2f, 0x45, \r
+ 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, \r
+ 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, \r
+ 0x67, 0x2f, 0x54, 0x52, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, \r
+ 0x2f, 0x6c, 0x6f, 0x6f, 0x73, 0x65, 0x2e, 0x64, 0x74, 0x64, \r
+ 0x22, 0x3e, 0xa, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, \r
+ 0x20, 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0xa, 0x20, \r
+ 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x2e, 0x6f, \r
+ 0x72, 0x67, 0x20, 0x75, 0x49, 0x50, 0x20, 0x57, 0x45, 0x42, \r
+ 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x64, 0x65, \r
+ 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, \r
+ 0xa, 0x20, 0x20, 0x3c, 0x42, 0x4f, 0x44, 0x59, 0x3e, 0xa, \r
+ 0x3c, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x66, 0x61, 0x63, 0x65, \r
+ 0x3d, 0x22, 0x61, 0x72, 0x69, 0x61, 0x6c, 0x22, 0x3e, 0xa, \r
+ 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, \r
+ 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, \r
+ 0x22, 0x3e, 0x54, 0x61, 0x73, 0x6b, 0x20, 0x53, 0x74, 0x61, \r
+ 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, \r
+ 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, \r
+ 0x72, 0x65, 0x66, 0x3d, 0x22, 0x72, 0x75, 0x6e, 0x74, 0x69, \r
+ 0x6d, 0x65, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x52, 0x75, 0x6e, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x20, 0x53, \r
+ 0x74, 0x61, 0x74, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x73, 0x74, 0x61, \r
+ 0x74, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, \r
+ 0x54, 0x43, 0x50, 0x20, 0x53, 0x74, 0x61, 0x74, 0x73, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0x20, 0x3c, 0x62, 0x3e, 0x7c, 0x3c, 0x2f, \r
+ 0x62, 0x3e, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, \r
+ 0x3d, 0x22, 0x74, 0x63, 0x70, 0x2e, 0x73, 0x68, 0x74, 0x6d, \r
+ 0x6c, 0x22, 0x3e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, \r
+ 0x69, 0x6f, 0x6e, 0x73, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, \r
+ 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x66, 0x72, \r
+ 0x65, 0x65, 0x72, 0x74, 0x6f, 0x73, 0x2e, 0x6f, 0x72, 0x67, \r
+ 0x2f, 0x22, 0x3e, 0x46, 0x72, 0x65, 0x65, 0x52, 0x54, 0x4f, \r
+ 0x53, 0x2e, 0x6f, 0x72, 0x67, 0x20, 0x48, 0x6f, 0x6d, 0x65, \r
+ 0x70, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x3c, \r
+ 0x62, 0x3e, 0x7c, 0x3c, 0x2f, 0x62, 0x3e, 0x20, 0x3c, 0x61, \r
+ 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x69, 0x6f, 0x2e, \r
+ 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x49, 0x4f, 0x3c, \r
+ 0x2f, 0x61, 0x3e, 0xa, 0x3c, 0x62, 0x72, 0x3e, 0x3c, 0x70, \r
+ 0x3e, 0xa, 0x3c, 0x68, 0x72, 0x3e, 0xa, 0x3c, 0x62, 0x72, \r
+ 0x3e, 0xa, 0x3c, 0x68, 0x32, 0x3e, 0x4e, 0x65, 0x74, 0x77, \r
+ 0x6f, 0x72, 0x6b, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, \r
+ 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3c, 0x2f, 0x68, 0x32, 0x3e, \r
+ 0xa, 0x3c, 0x70, 0x3e, 0xa, 0x3c, 0x74, 0x61, 0x62, 0x6c, \r
+ 0x65, 0x3e, 0xa, 0x3c, 0x74, 0x72, 0x3e, 0x3c, 0x74, 0x68, \r
+ 0x3e, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x3c, 0x2f, 0x74, 0x68, \r
+ 0x3e, 0x3c, 0x74, 0x68, 0x3e, 0x52, 0x65, 0x6d, 0x6f, 0x74, \r
+ 0x65, 0x3c, 0x2f, 0x74, 0x68, 0x3e, 0x3c, 0x74, 0x68, 0x3e, \r
+ 0x53, 0x74, 0x61, 0x74, 0x65, 0x3c, 0x2f, 0x74, 0x68, 0x3e, \r
+ 0x3c, 0x74, 0x68, 0x3e, 0x52, 0x65, 0x74, 0x72, 0x61, 0x6e, \r
+ 0x73, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x3c, \r
+ 0x2f, 0x74, 0x68, 0x3e, 0x3c, 0x74, 0x68, 0x3e, 0x54, 0x69, \r
+ 0x6d, 0x65, 0x72, 0x3c, 0x2f, 0x74, 0x68, 0x3e, 0x3c, 0x74, \r
+ 0x68, 0x3e, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x3c, 0x2f, 0x74, \r
+ 0x68, 0x3e, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0xa, 0x25, 0x21, \r
+ 0x20, 0x74, 0x63, 0x70, 0x2d, 0x63, 0x6f, 0x6e, 0x6e, 0x65, \r
+ 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0xa, 0x3c, 0x2f, 0x70, \r
+ 0x72, 0x65, 0x3e, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, \r
+ 0xa, 0x3c, 0x2f, 0x66, 0x6f, 0x6e, 0x74, 0x3e, 0xa, 0x3c, \r
+ 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, \r
+ 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0xa, 0};\r
+\r
+const struct httpd_fsdata_file file_404_html[] = {{NULL, data_404_html, data_404_html + 10, sizeof(data_404_html) - 10, 0}};\r
+\r
+const struct httpd_fsdata_file file_index_html[] = {{file_404_html, data_index_html, data_index_html + 12, sizeof(data_index_html) - 12, 0}};\r
+\r
+const struct httpd_fsdata_file file_index_shtml[] = {{file_index_html, data_index_shtml, data_index_shtml + 13, sizeof(data_index_shtml) - 13, 0}};\r
+\r
+const struct httpd_fsdata_file file_io_shtml[] = {{file_index_shtml, data_io_shtml, data_io_shtml + 10, sizeof(data_io_shtml) - 10, 0}};\r
+\r
+const struct httpd_fsdata_file file_runtime_shtml[] = {{file_io_shtml, data_runtime_shtml, data_runtime_shtml + 15, sizeof(data_runtime_shtml) - 15, 0}};\r
+\r
+const struct httpd_fsdata_file file_stats_shtml[] = {{file_runtime_shtml, data_stats_shtml, data_stats_shtml + 13, sizeof(data_stats_shtml) - 13, 0}};\r
+\r
+const struct httpd_fsdata_file file_tcp_shtml[] = {{file_stats_shtml, data_tcp_shtml, data_tcp_shtml + 11, sizeof(data_tcp_shtml) - 11, 0}};\r
+\r
+#define HTTPD_FS_ROOT file_tcp_shtml\r
+\r
+#define HTTPD_FS_NUMFILES 7\r
--- /dev/null
+/*\r
+ * Copyright (c) 2001, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the lwIP TCP/IP stack.\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: httpd-fsdata.h,v 1.1 2006/06/07 09:13:08 adam Exp $\r
+ */\r
+#ifndef __HTTPD_FSDATA_H__\r
+#define __HTTPD_FSDATA_H__\r
+\r
+#include "uip.h"\r
+\r
+struct httpd_fsdata_file {\r
+ const struct httpd_fsdata_file *next;\r
+ const char *name;\r
+ const char *data;\r
+ const int len;\r
+#ifdef HTTPD_FS_STATISTICS\r
+#if HTTPD_FS_STATISTICS == 1\r
+ u16_t count;\r
+#endif /* HTTPD_FS_STATISTICS */\r
+#endif /* HTTPD_FS_STATISTICS */\r
+};\r
+\r
+struct httpd_fsdata_file_noconst {\r
+ struct httpd_fsdata_file *next;\r
+ char *name;\r
+ char *data;\r
+ int len;\r
+#ifdef HTTPD_FS_STATISTICS\r
+#if HTTPD_FS_STATISTICS == 1\r
+ u16_t count;\r
+#endif /* HTTPD_FS_STATISTICS */\r
+#endif /* HTTPD_FS_STATISTICS */\r
+};\r
+\r
+#endif /* __HTTPD_FSDATA_H__ */\r
--- /dev/null
+/**\r
+ * \addtogroup apps\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \defgroup httpd Web server\r
+ * @{\r
+ * The uIP web server is a very simplistic implementation of an HTTP\r
+ * server. It can serve web pages and files from a read-only ROM\r
+ * filesystem, and provides a very small scripting language.\r
+\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Web server\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ */\r
+\r
+\r
+/*\r
+ * Copyright (c) 2004, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: httpd.c,v 1.2 2006/06/11 21:46:38 adam Exp $\r
+ */\r
+\r
+#include "uip.h"\r
+#include "httpd.h"\r
+#include "httpd-fs.h"\r
+#include "httpd-cgi.h"\r
+#include "http-strings.h"\r
+\r
+#include <string.h>\r
+\r
+#define STATE_WAITING 0\r
+#define STATE_OUTPUT 1\r
+\r
+#define ISO_nl 0x0a\r
+#define ISO_space 0x20\r
+#define ISO_bang 0x21\r
+#define ISO_percent 0x25\r
+#define ISO_period 0x2e\r
+#define ISO_slash 0x2f\r
+#define ISO_colon 0x3a\r
+\r
+\r
+/*---------------------------------------------------------------------------*/\r
+static unsigned short\r
+generate_part_of_file(void *state)\r
+{\r
+ struct httpd_state *s = (struct httpd_state *)state;\r
+\r
+ if(s->file.len > uip_mss()) {\r
+ s->len = uip_mss();\r
+ } else {\r
+ s->len = s->file.len;\r
+ }\r
+ memcpy(uip_appdata, s->file.data, s->len);\r
+ \r
+ return s->len;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(send_file(struct httpd_state *s))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+ \r
+ do {\r
+ PSOCK_GENERATOR_SEND(&s->sout, generate_part_of_file, s);\r
+ s->file.len -= s->len;\r
+ s->file.data += s->len;\r
+ } while(s->file.len > 0);\r
+ \r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(send_part_of_file(struct httpd_state *s))\r
+{\r
+ PSOCK_BEGIN(&s->sout);\r
+\r
+ PSOCK_SEND(&s->sout, s->file.data, s->len);\r
+ \r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static void\r
+next_scriptstate(struct httpd_state *s)\r
+{\r
+ char *p;\r
+ p = strchr(s->scriptptr, ISO_nl) + 1;\r
+ s->scriptlen -= (unsigned short)(p - s->scriptptr);\r
+ s->scriptptr = p;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(handle_script(struct httpd_state *s))\r
+{\r
+ char *ptr;\r
+ \r
+ PT_BEGIN(&s->scriptpt);\r
+\r
+\r
+ while(s->file.len > 0) {\r
+\r
+ /* Check if we should start executing a script. */\r
+ if(*s->file.data == ISO_percent &&\r
+ *(s->file.data + 1) == ISO_bang) {\r
+ s->scriptptr = s->file.data + 3;\r
+ s->scriptlen = s->file.len - 3;\r
+ if(*(s->scriptptr - 1) == ISO_colon) {\r
+ httpd_fs_open(s->scriptptr + 1, &s->file);\r
+ PT_WAIT_THREAD(&s->scriptpt, send_file(s));\r
+ } else {\r
+ PT_WAIT_THREAD(&s->scriptpt,\r
+ httpd_cgi(s->scriptptr)(s, s->scriptptr));\r
+ }\r
+ next_scriptstate(s);\r
+ \r
+ /* The script is over, so we reset the pointers and continue\r
+ sending the rest of the file. */\r
+ s->file.data = s->scriptptr;\r
+ s->file.len = s->scriptlen;\r
+ } else {\r
+ /* See if we find the start of script marker in the block of HTML\r
+ to be sent. */\r
+\r
+ if(s->file.len > uip_mss()) {\r
+ s->len = uip_mss();\r
+ } else {\r
+ s->len = s->file.len;\r
+ }\r
+\r
+ if(*s->file.data == ISO_percent) {\r
+ ptr = strchr(s->file.data + 1, ISO_percent);\r
+ } else {\r
+ ptr = strchr(s->file.data, ISO_percent);\r
+ }\r
+ if(ptr != NULL &&\r
+ ptr != s->file.data) {\r
+ s->len = (int)(ptr - s->file.data);\r
+ if(s->len >= uip_mss()) {\r
+ s->len = uip_mss();\r
+ }\r
+ }\r
+ PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s));\r
+ s->file.data += s->len;\r
+ s->file.len -= s->len;\r
+ \r
+ }\r
+ }\r
+ \r
+ PT_END(&s->scriptpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))\r
+{\r
+ char *ptr;\r
+\r
+ PSOCK_BEGIN(&s->sout);\r
+\r
+ PSOCK_SEND_STR(&s->sout, statushdr);\r
+\r
+ ptr = strrchr(s->filename, ISO_period);\r
+ if(ptr == NULL) {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_binary);\r
+ } else if(strncmp(http_html, ptr, 5) == 0 ||\r
+ strncmp(http_shtml, ptr, 6) == 0) {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_html);\r
+ } else if(strncmp(http_css, ptr, 4) == 0) {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_css);\r
+ } else if(strncmp(http_png, ptr, 4) == 0) {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_png);\r
+ } else if(strncmp(http_gif, ptr, 4) == 0) {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_gif);\r
+ } else if(strncmp(http_jpg, ptr, 4) == 0) {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_jpg);\r
+ } else {\r
+ PSOCK_SEND_STR(&s->sout, http_content_type_plain);\r
+ }\r
+ PSOCK_END(&s->sout);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(handle_output(struct httpd_state *s))\r
+{\r
+ char *ptr;\r
+ \r
+ PT_BEGIN(&s->outputpt);\r
+ \r
+ if(!httpd_fs_open(s->filename, &s->file)) {\r
+ httpd_fs_open(http_404_html, &s->file);\r
+ strcpy(s->filename, http_404_html);\r
+ PT_WAIT_THREAD(&s->outputpt,\r
+ send_headers(s,\r
+ http_header_404));\r
+ PT_WAIT_THREAD(&s->outputpt,\r
+ send_file(s));\r
+ } else {\r
+ PT_WAIT_THREAD(&s->outputpt,\r
+ send_headers(s,\r
+ http_header_200));\r
+ ptr = strchr(s->filename, ISO_period);\r
+ if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0) {\r
+ PT_INIT(&s->scriptpt);\r
+ PT_WAIT_THREAD(&s->outputpt, handle_script(s));\r
+ } else {\r
+ PT_WAIT_THREAD(&s->outputpt,\r
+ send_file(s));\r
+ }\r
+ }\r
+ PSOCK_CLOSE(&s->sout);\r
+ PT_END(&s->outputpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static\r
+PT_THREAD(handle_input(struct httpd_state *s))\r
+{\r
+ PSOCK_BEGIN(&s->sin);\r
+\r
+ PSOCK_READTO(&s->sin, ISO_space);\r
+\r
+ \r
+ if(strncmp(s->inputbuf, http_get, 4) != 0) {\r
+ PSOCK_CLOSE_EXIT(&s->sin);\r
+ }\r
+ PSOCK_READTO(&s->sin, ISO_space);\r
+\r
+ if(s->inputbuf[0] != ISO_slash) {\r
+ PSOCK_CLOSE_EXIT(&s->sin);\r
+ }\r
+\r
+ if(s->inputbuf[1] == ISO_space) {\r
+ strncpy(s->filename, http_index_html, sizeof(s->filename));\r
+ } else {\r
+\r
+ s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;\r
+\r
+ /* Process any form input being sent to the server. */\r
+ {\r
+ extern void vApplicationProcessFormInput( char *pcInputString );\r
+ vApplicationProcessFormInput( s->inputbuf );\r
+ }\r
+\r
+ strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));\r
+ }\r
+\r
+ /* httpd_log_file(uip_conn->ripaddr, s->filename);*/\r
+ \r
+ s->state = STATE_OUTPUT;\r
+\r
+ while(1) {\r
+ PSOCK_READTO(&s->sin, ISO_nl);\r
+\r
+ if(strncmp(s->inputbuf, http_referer, 8) == 0) {\r
+ s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;\r
+ /* httpd_log(&s->inputbuf[9]);*/\r
+ }\r
+ }\r
+ \r
+ PSOCK_END(&s->sin);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static void\r
+handle_connection(struct httpd_state *s)\r
+{\r
+ handle_input(s);\r
+ if(s->state == STATE_OUTPUT) {\r
+ handle_output(s);\r
+ }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+httpd_appcall(void)\r
+{\r
+ struct httpd_state *s = (struct httpd_state *)&(uip_conn->appstate);\r
+\r
+ if(uip_closed() || uip_aborted() || uip_timedout()) {\r
+ } else if(uip_connected()) {\r
+ PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1);\r
+ PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1);\r
+ PT_INIT(&s->outputpt);\r
+ s->state = STATE_WAITING;\r
+ /* timer_set(&s->timer, CLOCK_SECOND * 100);*/\r
+ s->timer = 0;\r
+ handle_connection(s);\r
+ } else if(s != NULL) {\r
+ if(uip_poll()) {\r
+ ++s->timer;\r
+ if(s->timer >= 20) {\r
+ uip_abort();\r
+ }\r
+ } else {\r
+ s->timer = 0;\r
+ }\r
+ handle_connection(s);\r
+ } else {\r
+ uip_abort();\r
+ }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * \brief Initialize the web server\r
+ *\r
+ * This function initializes the web server and should be\r
+ * called at system boot-up.\r
+ */\r
+void\r
+httpd_init(void)\r
+{\r
+ uip_listen(HTONS(80));\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/** @} */\r
--- /dev/null
+/*\r
+ * Copyright (c) 2001-2005, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: httpd.h,v 1.2 2006/06/11 21:46:38 adam Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __HTTPD_H__\r
+#define __HTTPD_H__\r
+\r
+#include "psock.h"\r
+#include "httpd-fs.h"\r
+\r
+struct httpd_state {\r
+ unsigned char timer;\r
+ struct psock sin, sout;\r
+ struct pt outputpt, scriptpt;\r
+ char inputbuf[50];\r
+ char filename[20];\r
+ char state;\r
+ struct httpd_fs_file file;\r
+ int len;\r
+ char *scriptptr;\r
+ int scriptlen;\r
+ \r
+ unsigned short count;\r
+};\r
+\r
+void httpd_init(void);\r
+void httpd_appcall(void);\r
+\r
+void httpd_log(char *msg);\r
+void httpd_log_file(u16_t *requester, char *file);\r
+\r
+#endif /* __HTTPD_H__ */\r
--- /dev/null
+/*\r
+ * Copyright (c) 2004-2005, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: lc-switch.h,v 1.2 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+/**\r
+ * \addtogroup lc\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Implementation of local continuations based on switch() statment\r
+ * \author Adam Dunkels <adam@sics.se>\r
+ *\r
+ * This implementation of local continuations uses the C switch()\r
+ * statement to resume execution of a function somewhere inside the\r
+ * function's body. The implementation is based on the fact that\r
+ * switch() statements are able to jump directly into the bodies of\r
+ * control structures such as if() or while() statmenets.\r
+ *\r
+ * This implementation borrows heavily from Simon Tatham's coroutines\r
+ * implementation in C:\r
+ * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\r
+ */\r
+\r
+#ifndef __LC_SWITCH_H__\r
+#define __LC_SWTICH_H__\r
+\r
+/* WARNING! lc implementation using switch() does not work if an\r
+ LC_SET() is done within another switch() statement! */\r
+\r
+/** \hideinitializer */\r
+typedef unsigned short lc_t;\r
+\r
+#define LC_INIT(s) s = 0;\r
+\r
+#define LC_RESUME(s) switch(s) { case 0:\r
+\r
+#define LC_SET(s) s = __LINE__; case __LINE__:\r
+\r
+#define LC_END(s) }\r
+\r
+#endif /* __LC_SWITCH_H__ */\r
+\r
+/** @} */\r
--- /dev/null
+/*\r
+ * Copyright (c) 2004-2005, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: lc.h,v 1.2 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+/**\r
+ * \addtogroup pt\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \defgroup lc Local continuations\r
+ * @{\r
+ *\r
+ * Local continuations form the basis for implementing protothreads. A\r
+ * local continuation can be <i>set</i> in a specific function to\r
+ * capture the state of the function. After a local continuation has\r
+ * been set can be <i>resumed</i> in order to restore the state of the\r
+ * function at the point where the local continuation was set.\r
+ *\r
+ *\r
+ */\r
+\r
+/**\r
+ * \file lc.h\r
+ * Local continuations\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+#ifdef DOXYGEN\r
+/**\r
+ * Initialize a local continuation.\r
+ *\r
+ * This operation initializes the local continuation, thereby\r
+ * unsetting any previously set continuation state.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define LC_INIT(lc)\r
+\r
+/**\r
+ * Set a local continuation.\r
+ *\r
+ * The set operation saves the state of the function at the point\r
+ * where the operation is executed. As far as the set operation is\r
+ * concerned, the state of the function does <b>not</b> include the\r
+ * call-stack or local (automatic) variables, but only the program\r
+ * counter and such CPU registers that needs to be saved.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define LC_SET(lc)\r
+\r
+/**\r
+ * Resume a local continuation.\r
+ *\r
+ * The resume operation resumes a previously set local continuation, thus\r
+ * restoring the state in which the function was when the local\r
+ * continuation was set. If the local continuation has not been\r
+ * previously set, the resume operation does nothing.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define LC_RESUME(lc)\r
+\r
+/**\r
+ * Mark the end of local continuation usage.\r
+ *\r
+ * The end operation signifies that local continuations should not be\r
+ * used any more in the function. This operation is not needed for\r
+ * most implementations of local continuation, but is required by a\r
+ * few implementations.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define LC_END(lc)\r
+\r
+/**\r
+ * \var typedef lc_t;\r
+ *\r
+ * The local continuation type.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#endif /* DOXYGEN */\r
+\r
+#ifndef __LC_H__\r
+#define __LC_H__\r
+\r
+#ifdef LC_CONF_INCLUDE\r
+#include LC_CONF_INCLUDE\r
+#else\r
+#include "lc-switch.h"\r
+#endif /* LC_CONF_INCLUDE */\r
+\r
+#endif /* __LC_H__ */\r
+\r
+/** @} */\r
+/** @} */\r
--- /dev/null
+#!/usr/bin/perl\r
+\r
+open(OUTPUT, "> httpd-fsdata.c");\r
+\r
+chdir("httpd-fs");\r
+\r
+opendir(DIR, ".");\r
+@files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);\r
+closedir(DIR);\r
+\r
+foreach $file (@files) { \r
+ \r
+ if(-d $file && $file !~ /^\./) {\r
+ print "Processing directory $file\n";\r
+ opendir(DIR, $file);\r
+ @newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);\r
+ closedir(DIR);\r
+ printf "Adding files @newfiles\n";\r
+ @files = (@files, map { $_ = "$file/$_" } @newfiles);\r
+ next;\r
+ }\r
+}\r
+\r
+foreach $file (@files) {\r
+ if(-f $file) {\r
+ \r
+ print "Adding file $file\n";\r
+ \r
+ open(FILE, $file) || die "Could not open file $file\n";\r
+\r
+ $file =~ s-^-/-;\r
+ $fvar = $file;\r
+ $fvar =~ s-/-_-g;\r
+ $fvar =~ s-\.-_-g;\r
+ # for AVR, add PROGMEM here\r
+ print(OUTPUT "static const unsigned char data".$fvar."[] = {\n");\r
+ print(OUTPUT "\t/* $file */\n\t");\r
+ for($j = 0; $j < length($file); $j++) {\r
+ printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));\r
+ }\r
+ printf(OUTPUT "0,\n");\r
+ \r
+ \r
+ $i = 0; \r
+ while(read(FILE, $data, 1)) {\r
+ if($i == 0) {\r
+ print(OUTPUT "\t");\r
+ }\r
+ printf(OUTPUT "%#02x, ", unpack("C", $data));\r
+ $i++;\r
+ if($i == 10) {\r
+ print(OUTPUT "\n");\r
+ $i = 0;\r
+ }\r
+ }\r
+ print(OUTPUT "0};\n\n");\r
+ close(FILE);\r
+ push(@fvars, $fvar);\r
+ push(@pfiles, $file);\r
+ }\r
+}\r
+\r
+for($i = 0; $i < @fvars; $i++) {\r
+ $file = $pfiles[$i];\r
+ $fvar = $fvars[$i];\r
+\r
+ if($i == 0) {\r
+ $prevfile = "NULL";\r
+ } else {\r
+ $prevfile = "file" . $fvars[$i - 1];\r
+ }\r
+ print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, ");\r
+ print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");\r
+ print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");\r
+}\r
+\r
+print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");\r
+print(OUTPUT "#define HTTPD_FS_NUMFILES $i\n");\r
--- /dev/null
+#!/usr/bin/perl\r
+\r
+\r
+sub stringify {\r
+ my $name = shift(@_);\r
+ open(OUTPUTC, "> $name.c");\r
+ open(OUTPUTH, "> $name.h");\r
+ \r
+ open(FILE, "$name");\r
+ \r
+ while(<FILE>) {\r
+ if(/(.+) "(.+)"/) {\r
+ $var = $1;\r
+ $data = $2;\r
+ \r
+ $datan = $data;\r
+ $datan =~ s/\\r/\r/g;\r
+ $datan =~ s/\\n/\n/g;\r
+ $datan =~ s/\\01/\01/g; \r
+ $datan =~ s/\\0/\0/g;\r
+ \r
+ printf(OUTPUTC "const char $var\[%d] = \n", length($datan) + 1);\r
+ printf(OUTPUTC "/* \"$data\" */\n");\r
+ printf(OUTPUTC "{");\r
+ for($j = 0; $j < length($datan); $j++) {\r
+ printf(OUTPUTC "%#02x, ", unpack("C", substr($datan, $j, 1)));\r
+ }\r
+ printf(OUTPUTC "};\n");\r
+ \r
+ printf(OUTPUTH "extern const char $var\[%d];\n", length($datan) + 1);\r
+ \r
+ }\r
+ }\r
+ close(OUTPUTC);\r
+ close(OUTPUTH);\r
+}\r
+stringify("http-strings");\r
+\r
+exit 0;\r
+\r
--- /dev/null
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: psock.c,v 1.2 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include "uipopt.h"\r
+#include "psock.h"\r
+#include "uip.h"\r
+\r
+#define STATE_NONE 0\r
+#define STATE_ACKED 1\r
+#define STATE_READ 2\r
+#define STATE_BLOCKED_NEWDATA 3\r
+#define STATE_BLOCKED_CLOSE 4\r
+#define STATE_BLOCKED_SEND 5\r
+#define STATE_DATA_SENT 6\r
+\r
+/*\r
+ * Return value of the buffering functions that indicates that a\r
+ * buffer was not filled by incoming data.\r
+ *\r
+ */\r
+#define BUF_NOT_FULL 0\r
+#define BUF_NOT_FOUND 0\r
+\r
+/*\r
+ * Return value of the buffering functions that indicates that a\r
+ * buffer was completely filled by incoming data.\r
+ *\r
+ */\r
+#define BUF_FULL 1\r
+\r
+/*\r
+ * Return value of the buffering functions that indicates that an\r
+ * end-marker byte was found.\r
+ *\r
+ */\r
+#define BUF_FOUND 2\r
+\r
+/*---------------------------------------------------------------------------*/\r
+static void\r
+buf_setup(struct psock_buf *buf,\r
+ u8_t *bufptr, u16_t bufsize)\r
+{\r
+ buf->ptr = bufptr;\r
+ buf->left = bufsize;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static u8_t\r
+buf_bufdata(struct psock_buf *buf, u16_t len,\r
+ u8_t **dataptr, u16_t *datalen)\r
+{\r
+ ( void ) len;\r
+ if(*datalen < buf->left) {\r
+ memcpy(buf->ptr, *dataptr, *datalen);\r
+ buf->ptr += *datalen;\r
+ buf->left -= *datalen;\r
+ *dataptr += *datalen;\r
+ *datalen = 0;\r
+ return BUF_NOT_FULL;\r
+ } else if(*datalen == buf->left) {\r
+ memcpy(buf->ptr, *dataptr, *datalen);\r
+ buf->ptr += *datalen;\r
+ buf->left = 0;\r
+ *dataptr += *datalen;\r
+ *datalen = 0;\r
+ return BUF_FULL;\r
+ } else {\r
+ memcpy(buf->ptr, *dataptr, buf->left);\r
+ buf->ptr += buf->left;\r
+ *datalen -= buf->left;\r
+ *dataptr += buf->left;\r
+ buf->left = 0;\r
+ return BUF_FULL;\r
+ }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static u8_t\r
+buf_bufto(register struct psock_buf *buf, u8_t endmarker,\r
+ register u8_t **dataptr, register u16_t *datalen)\r
+{\r
+ u8_t c;\r
+ while(buf->left > 0 && *datalen > 0) {\r
+ c = *buf->ptr = **dataptr;\r
+ ++*dataptr;\r
+ ++buf->ptr;\r
+ --*datalen;\r
+ --buf->left;\r
+ \r
+ if(c == endmarker) {\r
+ return BUF_FOUND;\r
+ }\r
+ }\r
+\r
+ if(*datalen == 0) {\r
+ return BUF_NOT_FOUND;\r
+ }\r
+\r
+ while(*datalen > 0) {\r
+ c = **dataptr;\r
+ --*datalen;\r
+ ++*dataptr;\r
+ \r
+ if(c == endmarker) {\r
+ return BUF_FOUND | BUF_FULL;\r
+ }\r
+ }\r
+ \r
+ return BUF_FULL;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static char\r
+send_data(register struct psock *s)\r
+{\r
+ if(s->state != STATE_DATA_SENT || uip_rexmit()) {\r
+ if(s->sendlen > uip_mss()) {\r
+ uip_send(s->sendptr, uip_mss());\r
+ } else {\r
+ uip_send(s->sendptr, s->sendlen);\r
+ }\r
+ s->state = STATE_DATA_SENT;\r
+ return 1;\r
+ }\r
+ return 0;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+static char\r
+data_acked(register struct psock *s)\r
+{\r
+ if(s->state == STATE_DATA_SENT && uip_acked()) {\r
+ if(s->sendlen > uip_mss()) {\r
+ s->sendlen -= uip_mss();\r
+ s->sendptr += uip_mss();\r
+ } else {\r
+ s->sendptr += s->sendlen;\r
+ s->sendlen = 0;\r
+ }\r
+ s->state = STATE_ACKED;\r
+ return 1;\r
+ }\r
+ return 0;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+PT_THREAD(psock_send(register struct psock *s, const char *buf,\r
+ unsigned int len))\r
+{\r
+ PT_BEGIN(&s->psockpt);\r
+\r
+ /* If there is no data to send, we exit immediately. */\r
+ if(len == 0) {\r
+ PT_EXIT(&s->psockpt);\r
+ }\r
+\r
+ /* Save the length of and a pointer to the data that is to be\r
+ sent. */\r
+ s->sendptr = (unsigned char*)buf;\r
+ s->sendlen = len;\r
+\r
+ s->state = STATE_NONE;\r
+\r
+ /* We loop here until all data is sent. The s->sendlen variable is\r
+ updated by the data_sent() function. */\r
+ while(s->sendlen > 0) {\r
+\r
+ /*\r
+ * The condition for this PT_WAIT_UNTIL is a little tricky: the\r
+ * protothread will wait here until all data has been acknowledged\r
+ * (data_acked() returns true) and until all data has been sent\r
+ * (send_data() returns true). The two functions data_acked() and\r
+ * send_data() must be called in succession to ensure that all\r
+ * data is sent. Therefore the & operator is used instead of the\r
+ * && operator, which would cause only the data_acked() function\r
+ * to be called when it returns false.\r
+ */\r
+ PT_WAIT_UNTIL(&s->psockpt, data_acked(s) & send_data(s));\r
+ }\r
+\r
+ s->state = STATE_NONE;\r
+ \r
+ PT_END(&s->psockpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+PT_THREAD(psock_generator_send(register struct psock *s,\r
+ unsigned short (*generate)(void *), void *arg))\r
+{\r
+ PT_BEGIN(&s->psockpt);\r
+\r
+ /* Ensure that there is a generator function to call. */\r
+ if(generate == NULL) {\r
+ PT_EXIT(&s->psockpt);\r
+ }\r
+\r
+ /* Call the generator function to generate the data in the\r
+ uip_appdata buffer. */\r
+ s->sendlen = generate(arg);\r
+ s->sendptr = uip_appdata;\r
+\r
+ s->state = STATE_NONE; \r
+ do {\r
+ /* Call the generator function again if we are called to perform a\r
+ retransmission. */\r
+ if(uip_rexmit()) {\r
+ generate(arg);\r
+ }\r
+ /* Wait until all data is sent and acknowledged. */\r
+ PT_WAIT_UNTIL(&s->psockpt, data_acked(s) & send_data(s));\r
+ } while(s->sendlen > 0);\r
+ \r
+ s->state = STATE_NONE;\r
+ \r
+ PT_END(&s->psockpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+psock_datalen(struct psock *psock)\r
+{\r
+ return psock->bufsize - psock->buf.left;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+char\r
+psock_newdata(struct psock *s)\r
+{\r
+ if(s->readlen > 0) {\r
+ /* There is data in the uip_appdata buffer that has not yet been\r
+ read with the PSOCK_READ functions. */\r
+ return 1;\r
+ } else if(s->state == STATE_READ) {\r
+ /* All data in uip_appdata buffer already consumed. */\r
+ s->state = STATE_BLOCKED_NEWDATA;\r
+ return 0;\r
+ } else if(uip_newdata()) {\r
+ /* There is new data that has not been consumed. */\r
+ return 1;\r
+ } else {\r
+ /* There is no new data. */\r
+ return 0;\r
+ }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+PT_THREAD(psock_readto(register struct psock *psock, unsigned char c))\r
+{\r
+ PT_BEGIN(&psock->psockpt);\r
+\r
+ buf_setup(&psock->buf, (unsigned char*)psock->bufptr, psock->bufsize);\r
+ \r
+ /* XXX: Should add buf_checkmarker() before do{} loop, if\r
+ incoming data has been handled while waiting for a write. */\r
+\r
+ do {\r
+ if(psock->readlen == 0) {\r
+ PT_WAIT_UNTIL(&psock->psockpt, psock_newdata(psock));\r
+ psock->state = STATE_READ;\r
+ psock->readptr = (u8_t *)uip_appdata;\r
+ psock->readlen = uip_datalen();\r
+ }\r
+ } while((buf_bufto(&psock->buf, c,\r
+ &psock->readptr,\r
+ &psock->readlen) & BUF_FOUND) == 0);\r
+ \r
+ if(psock_datalen(psock) == 0) {\r
+ psock->state = STATE_NONE;\r
+ PT_RESTART(&psock->psockpt);\r
+ }\r
+ PT_END(&psock->psockpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+PT_THREAD(psock_readbuf(register struct psock *psock))\r
+{\r
+ PT_BEGIN(&psock->psockpt);\r
+\r
+ buf_setup(&psock->buf, (unsigned char * ) psock->bufptr, psock->bufsize);\r
+ \r
+ /* XXX: Should add buf_checkmarker() before do{} loop, if\r
+ incoming data has been handled while waiting for a write. */\r
+\r
+ do {\r
+ if(psock->readlen == 0) {\r
+ PT_WAIT_UNTIL(&psock->psockpt, psock_newdata(psock));\r
+ printf("Waited for newdata\n");\r
+ psock->state = STATE_READ;\r
+ psock->readptr = (u8_t *)uip_appdata;\r
+ psock->readlen = uip_datalen();\r
+ }\r
+ } while(buf_bufdata(&psock->buf, psock->bufsize,\r
+ &psock->readptr,\r
+ &psock->readlen) != BUF_FULL);\r
+\r
+ if(psock_datalen(psock) == 0) {\r
+ psock->state = STATE_NONE;\r
+ PT_RESTART(&psock->psockpt);\r
+ }\r
+ PT_END(&psock->psockpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+psock_init(register struct psock *psock, char *buffer, unsigned int buffersize)\r
+{\r
+ psock->state = STATE_NONE;\r
+ psock->readlen = 0;\r
+ psock->bufptr = buffer;\r
+ psock->bufsize = buffersize;\r
+ buf_setup(&psock->buf, (unsigned char*) buffer, buffersize);\r
+ PT_INIT(&psock->pt);\r
+ PT_INIT(&psock->psockpt);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
--- /dev/null
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: psock.h,v 1.3 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+/**\r
+ * \defgroup psock Protosockets library\r
+ * @{\r
+ *\r
+ * The protosocket library provides an interface to the uIP stack that is\r
+ * similar to the traditional BSD socket interface. Unlike programs\r
+ * written for the ordinary uIP event-driven interface, programs\r
+ * written with the protosocket library are executed in a sequential\r
+ * fashion and does not have to be implemented as explicit state\r
+ * machines.\r
+ *\r
+ * Protosockets only work with TCP connections.\r
+ *\r
+ * The protosocket library uses \ref pt protothreads to provide\r
+ * sequential control flow. This makes the protosockets lightweight in\r
+ * terms of memory, but also means that protosockets inherits the\r
+ * functional limitations of protothreads. Each protosocket lives only\r
+ * within a single function. Automatic variables (stack variables) are\r
+ * not retained across a protosocket library function call.\r
+ *\r
+ * \note Because the protosocket library uses protothreads, local\r
+ * variables will not always be saved across a call to a protosocket\r
+ * library function. It is therefore advised that local variables are\r
+ * used with extreme care.\r
+ *\r
+ * The protosocket library provides functions for sending data without\r
+ * having to deal with retransmissions and acknowledgements, as well\r
+ * as functions for reading data without having to deal with data\r
+ * being split across more than one TCP segment.\r
+ *\r
+ * Because each protosocket runs as a protothread, the protosocket has to be\r
+ * started with a call to PSOCK_BEGIN() at the start of the function\r
+ * in which the protosocket is used. Similarly, the protosocket protothread can\r
+ * be terminated by a call to PSOCK_EXIT().\r
+ *\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Protosocket library header file\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+#ifndef __PSOCK_H__\r
+#define __PSOCK_H__\r
+\r
+#include "uipopt.h"\r
+#include "pt.h"\r
+\r
+ /*\r
+ * The structure that holds the state of a buffer.\r
+ *\r
+ * This structure holds the state of a uIP buffer. The structure has\r
+ * no user-visible elements, but is used through the functions\r
+ * provided by the library.\r
+ *\r
+ */\r
+struct psock_buf {\r
+ u8_t *ptr;\r
+ unsigned short left;\r
+};\r
+\r
+/**\r
+ * The representation of a protosocket.\r
+ *\r
+ * The protosocket structrure is an opaque structure with no user-visible\r
+ * elements.\r
+ */\r
+struct psock {\r
+ struct pt pt, psockpt; /* Protothreads - one that's using the psock\r
+ functions, and one that runs inside the\r
+ psock functions. */\r
+ const u8_t *sendptr; /* Pointer to the next data to be sent. */\r
+ u8_t *readptr; /* Pointer to the next data to be read. */\r
+ \r
+ char *bufptr; /* Pointer to the buffer used for buffering\r
+ incoming data. */\r
+ \r
+ u16_t sendlen; /* The number of bytes left to be sent. */\r
+ u16_t readlen; /* The number of bytes left to be read. */\r
+\r
+ struct psock_buf buf; /* The structure holding the state of the\r
+ input buffer. */\r
+ unsigned int bufsize; /* The size of the input buffer. */\r
+ \r
+ unsigned char state; /* The state of the protosocket. */\r
+};\r
+\r
+void psock_init(struct psock *psock, char *buffer, unsigned int buffersize);\r
+/**\r
+ * Initialize a protosocket.\r
+ *\r
+ * This macro initializes a protosocket and must be called before the\r
+ * protosocket is used. The initialization also specifies the input buffer\r
+ * for the protosocket.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket to be\r
+ * initialized\r
+ *\r
+ * \param buffer (char *) A pointer to the input buffer for the\r
+ * protosocket.\r
+ *\r
+ * \param buffersize (unsigned int) The size of the input buffer.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_INIT(psock, buffer, buffersize) \\r
+ psock_init(psock, buffer, buffersize)\r
+\r
+/**\r
+ * Start the protosocket protothread in a function.\r
+ *\r
+ * This macro starts the protothread associated with the protosocket and\r
+ * must come before other protosocket calls in the function it is used.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket to be\r
+ * started.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_BEGIN(psock) PT_BEGIN(&((psock)->pt))\r
+\r
+PT_THREAD(psock_send(struct psock *psock, const char *buf, unsigned int len));\r
+/**\r
+ * Send data.\r
+ *\r
+ * This macro sends data over a protosocket. The protosocket protothread blocks\r
+ * until all data has been sent and is known to have been received by\r
+ * the remote end of the TCP connection.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket over which\r
+ * data is to be sent.\r
+ *\r
+ * \param data (char *) A pointer to the data that is to be sent.\r
+ *\r
+ * \param datalen (unsigned int) The length of the data that is to be\r
+ * sent.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_SEND(psock, data, datalen) \\r
+ PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, data, datalen))\r
+\r
+/**\r
+ * \brief Send a null-terminated string.\r
+ * \param psock Pointer to the protosocket.\r
+ * \param str The string to be sent.\r
+ *\r
+ * This function sends a null-terminated string over the\r
+ * protosocket.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_SEND_STR(psock, str) \\r
+ PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, str, strlen(str)))\r
+\r
+PT_THREAD(psock_generator_send(struct psock *psock,\r
+ unsigned short (*f)(void *), void *arg));\r
+\r
+/**\r
+ * \brief Generate data with a function and send it\r
+ * \param psock Pointer to the protosocket.\r
+ * \param generator Pointer to the generator function\r
+ * \param arg Argument to the generator function\r
+ *\r
+ * This function generates data and sends it over the\r
+ * protosocket. This can be used to dynamically generate\r
+ * data for a transmission, instead of generating the data\r
+ * in a buffer beforehand. This function reduces the need for\r
+ * buffer memory. The generator function is implemented by\r
+ * the application, and a pointer to the function is given\r
+ * as an argument with the call to PSOCK_GENERATOR_SEND().\r
+ *\r
+ * The generator function should place the generated data\r
+ * directly in the uip_appdata buffer, and return the\r
+ * length of the generated data. The generator function is\r
+ * called by the protosocket layer when the data first is\r
+ * sent, and once for every retransmission that is needed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_GENERATOR_SEND(psock, generator, arg) \\r
+ PT_WAIT_THREAD(&((psock)->pt), \\r
+ psock_generator_send(psock, generator, arg))\r
+\r
+\r
+/**\r
+ * Close a protosocket.\r
+ *\r
+ * This macro closes a protosocket and can only be called from within the\r
+ * protothread in which the protosocket lives.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket that is to\r
+ * be closed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_CLOSE(psock) uip_close()\r
+\r
+PT_THREAD(psock_readbuf(struct psock *psock));\r
+/**\r
+ * Read data until the buffer is full.\r
+ *\r
+ * This macro will block waiting for data and read the data into the\r
+ * input buffer specified with the call to PSOCK_INIT(). Data is read\r
+ * until the buffer is full..\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket from which\r
+ * data should be read.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_READBUF(psock) \\r
+ PT_WAIT_THREAD(&((psock)->pt), psock_readbuf(psock))\r
+\r
+PT_THREAD(psock_readto(struct psock *psock, unsigned char c));\r
+/**\r
+ * Read data up to a specified character.\r
+ *\r
+ * This macro will block waiting for data and read the data into the\r
+ * input buffer specified with the call to PSOCK_INIT(). Data is only\r
+ * read until the specifieed character appears in the data stream.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket from which\r
+ * data should be read.\r
+ *\r
+ * \param c (char) The character at which to stop reading.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_READTO(psock, c) \\r
+ PT_WAIT_THREAD(&((psock)->pt), psock_readto(psock, c))\r
+\r
+/**\r
+ * The length of the data that was previously read.\r
+ *\r
+ * This macro returns the length of the data that was previously read\r
+ * using PSOCK_READTO() or PSOCK_READ().\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket holding the data.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_DATALEN(psock) psock_datalen(psock)\r
+\r
+u16_t psock_datalen(struct psock *psock);\r
+\r
+/**\r
+ * Exit the protosocket's protothread.\r
+ *\r
+ * This macro terminates the protothread of the protosocket and should\r
+ * almost always be used in conjunction with PSOCK_CLOSE().\r
+ *\r
+ * \sa PSOCK_CLOSE_EXIT()\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_EXIT(psock) PT_EXIT(&((psock)->pt))\r
+\r
+/**\r
+ * Close a protosocket and exit the protosocket's protothread.\r
+ *\r
+ * This macro closes a protosocket and exits the protosocket's protothread.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_CLOSE_EXIT(psock) \\r
+ do { \\r
+ PSOCK_CLOSE(psock); \\r
+ PSOCK_EXIT(psock); \\r
+ } while(0)\r
+\r
+/**\r
+ * Declare the end of a protosocket's protothread.\r
+ *\r
+ * This macro is used for declaring that the protosocket's protothread\r
+ * ends. It must always be used together with a matching PSOCK_BEGIN()\r
+ * macro.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_END(psock) PT_END(&((psock)->pt))\r
+\r
+char psock_newdata(struct psock *s);\r
+\r
+/**\r
+ * Check if new data has arrived on a protosocket.\r
+ *\r
+ * This macro is used in conjunction with the PSOCK_WAIT_UNTIL()\r
+ * macro to check if data has arrived on a protosocket.\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_NEWDATA(psock) psock_newdata(psock)\r
+\r
+/**\r
+ * Wait until a condition is true.\r
+ *\r
+ * This macro blocks the protothread until the specified condition is\r
+ * true. The macro PSOCK_NEWDATA() can be used to check if new data\r
+ * arrives when the protosocket is waiting.\r
+ *\r
+ * Typically, this macro is used as follows:\r
+ *\r
+ \code\r
+ PT_THREAD(thread(struct psock *s, struct timer *t))\r
+ {\r
+ PSOCK_BEGIN(s);\r
+\r
+ PSOCK_WAIT_UNTIL(s, PSOCK_NEWADATA(s) || timer_expired(t));\r
+ \r
+ if(PSOCK_NEWDATA(s)) {\r
+ PSOCK_READTO(s, '\n');\r
+ } else {\r
+ handle_timed_out(s);\r
+ }\r
+ \r
+ PSOCK_END(s);\r
+ }\r
+ \endcode\r
+ *\r
+ * \param psock (struct psock *) A pointer to the protosocket.\r
+ * \param condition The condition to wait for.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PSOCK_WAIT_UNTIL(psock, condition) \\r
+ PT_WAIT_UNTIL(&((psock)->pt), (condition));\r
+\r
+#define PSOCK_WAIT_THREAD(psock, condition) \\r
+ PT_WAIT_THREAD(&((psock)->pt), (condition))\r
+\r
+#endif /* __PSOCK_H__ */\r
+\r
+/** @} */\r
--- /dev/null
+/*\r
+ * Copyright (c) 2004-2005, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: pt.h,v 1.2 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+/**\r
+ * \addtogroup pt\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Protothreads implementation.\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+#ifndef __PT_H__\r
+#define __PT_H__\r
+\r
+#include "lc.h"\r
+\r
+struct pt {\r
+ lc_t lc;\r
+};\r
+\r
+#define PT_WAITING 0\r
+#define PT_EXITED 1\r
+#define PT_ENDED 2\r
+#define PT_YIELDED 3\r
+\r
+/**\r
+ * \name Initialization\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Initialize a protothread.\r
+ *\r
+ * Initializes a protothread. Initialization must be done prior to\r
+ * starting to execute the protothread.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ *\r
+ * \sa PT_SPAWN()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_INIT(pt) LC_INIT((pt)->lc)\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \name Declaration and definition\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Declaration of a protothread.\r
+ *\r
+ * This macro is used to declare a protothread. All protothreads must\r
+ * be declared with this macro.\r
+ *\r
+ * \param name_args The name and arguments of the C function\r
+ * implementing the protothread.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_THREAD(name_args) char name_args\r
+\r
+/**\r
+ * Declare the start of a protothread inside the C function\r
+ * implementing the protothread.\r
+ *\r
+ * This macro is used to declare the starting point of a\r
+ * protothread. It should be placed at the start of the function in\r
+ * which the protothread runs. All C statements above the PT_BEGIN()\r
+ * invokation will be executed each time the protothread is scheduled.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)\r
+\r
+/**\r
+ * Declare the end of a protothread.\r
+ *\r
+ * This macro is used for declaring that a protothread ends. It must\r
+ * always be used together with a matching PT_BEGIN() macro.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \\r
+ PT_INIT(pt); return PT_ENDED; }\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \name Blocked wait\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Block and wait until condition is true.\r
+ *\r
+ * This macro blocks the protothread until the specified condition is\r
+ * true.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ * \param condition The condition.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_WAIT_UNTIL(pt, condition) \\r
+ do { \\r
+ LC_SET((pt)->lc); \\r
+ if(!(condition)) { \\r
+ return PT_WAITING; \\r
+ } \\r
+ } while(0)\r
+\r
+/**\r
+ * Block and wait while condition is true.\r
+ *\r
+ * This function blocks and waits while condition is true. See\r
+ * PT_WAIT_UNTIL().\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ * \param cond The condition.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond))\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \name Hierarchical protothreads\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Block and wait until a child protothread completes.\r
+ *\r
+ * This macro schedules a child protothread. The current protothread\r
+ * will block until the child protothread completes.\r
+ *\r
+ * \note The child protothread must be manually initialized with the\r
+ * PT_INIT() function before this function is used.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ * \param thread The child protothread with arguments\r
+ *\r
+ * \sa PT_SPAWN()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread))\r
+\r
+/**\r
+ * Spawn a child protothread and wait until it exits.\r
+ *\r
+ * This macro spawns a child protothread and waits until it exits. The\r
+ * macro can only be used within a protothread.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ * \param child A pointer to the child protothread's control structure.\r
+ * \param thread The child protothread with arguments\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_SPAWN(pt, child, thread) \\r
+ do { \\r
+ PT_INIT((child)); \\r
+ PT_WAIT_THREAD((pt), (thread)); \\r
+ } while(0)\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \name Exiting and restarting\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Restart the protothread.\r
+ *\r
+ * This macro will block and cause the running protothread to restart\r
+ * its execution at the place of the PT_BEGIN() call.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_RESTART(pt) \\r
+ do { \\r
+ PT_INIT(pt); \\r
+ return PT_WAITING; \\r
+ } while(0)\r
+\r
+/**\r
+ * Exit the protothread.\r
+ *\r
+ * This macro causes the protothread to exit. If the protothread was\r
+ * spawned by another protothread, the parent protothread will become\r
+ * unblocked and can continue to run.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_EXIT(pt) \\r
+ do { \\r
+ PT_INIT(pt); \\r
+ return PT_EXITED; \\r
+ } while(0)\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \name Calling a protothread\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Schedule a protothread.\r
+ *\r
+ * This function shedules a protothread. The return value of the\r
+ * function is non-zero if the protothread is running or zero if the\r
+ * protothread has exited.\r
+ *\r
+ * \param f The call to the C function implementing the protothread to\r
+ * be scheduled\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_SCHEDULE(f) ((f) == PT_WAITING)\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \name Yielding from a protothread\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Yield from the current protothread.\r
+ *\r
+ * This function will yield the protothread, thereby allowing other\r
+ * processing to take place in the system.\r
+ *\r
+ * \param pt A pointer to the protothread control structure.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_YIELD(pt) \\r
+ do { \\r
+ PT_YIELD_FLAG = 0; \\r
+ LC_SET((pt)->lc); \\r
+ if(PT_YIELD_FLAG == 0) { \\r
+ return PT_YIELDED; \\r
+ } \\r
+ } while(0)\r
+\r
+/**\r
+ * \brief Yield from the protothread until a condition occurs.\r
+ * \param pt A pointer to the protothread control structure.\r
+ * \param cond The condition.\r
+ *\r
+ * This function will yield the protothread, until the\r
+ * specified condition evaluates to true.\r
+ *\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define PT_YIELD_UNTIL(pt, cond) \\r
+ do { \\r
+ PT_YIELD_FLAG = 0; \\r
+ LC_SET((pt)->lc); \\r
+ if((PT_YIELD_FLAG == 0) || !(cond)) { \\r
+ return PT_YIELDED; \\r
+ } \\r
+ } while(0)\r
+\r
+/** @} */\r
+\r
+#endif /* __PT_H__ */\r
+\r
+/** @} */\r
--- /dev/null
+/**\r
+ * \addtogroup timer\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Timer library implementation.\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+#include "clock.h"\r
+#include "timer.h"\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Set a timer.\r
+ *\r
+ * This function is used to set a timer for a time sometime in the\r
+ * future. The function timer_expired() will evaluate to true after\r
+ * the timer has expired.\r
+ *\r
+ * \param t A pointer to the timer\r
+ * \param interval The interval before the timer expires.\r
+ *\r
+ */\r
+void\r
+timer_set(struct timer *t, clock_time_t interval)\r
+{\r
+ t->interval = interval;\r
+ t->start = clock_time();\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Reset the timer with the same interval.\r
+ *\r
+ * This function resets the timer with the same interval that was\r
+ * given to the timer_set() function. The start point of the interval\r
+ * is the exact time that the timer last expired. Therefore, this\r
+ * function will cause the timer to be stable over time, unlike the\r
+ * timer_rester() function.\r
+ *\r
+ * \param t A pointer to the timer.\r
+ *\r
+ * \sa timer_restart()\r
+ */\r
+void\r
+timer_reset(struct timer *t)\r
+{\r
+ t->start += t->interval;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Restart the timer from the current point in time\r
+ *\r
+ * This function restarts a timer with the same interval that was\r
+ * given to the timer_set() function. The timer will start at the\r
+ * current time.\r
+ *\r
+ * \note A periodic timer will drift if this function is used to reset\r
+ * it. For preioric timers, use the timer_reset() function instead.\r
+ *\r
+ * \param t A pointer to the timer.\r
+ *\r
+ * \sa timer_reset()\r
+ */\r
+void\r
+timer_restart(struct timer *t)\r
+{\r
+ t->start = clock_time();\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Check if a timer has expired.\r
+ *\r
+ * This function tests if a timer has expired and returns true or\r
+ * false depending on its status.\r
+ *\r
+ * \param t A pointer to the timer\r
+ *\r
+ * \return Non-zero if the timer has expired, zero otherwise.\r
+ *\r
+ */\r
+int\r
+timer_expired(struct timer *t)\r
+{\r
+ return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+/** @} */\r
--- /dev/null
+/**\r
+ * \defgroup timer Timer library\r
+ *\r
+ * The timer library provides functions for setting, resetting and\r
+ * restarting timers, and for checking if a timer has expired. An\r
+ * application must "manually" check if its timers have expired; this\r
+ * is not done automatically.\r
+ *\r
+ * A timer is declared as a \c struct \c timer and all access to the\r
+ * timer is made by a pointer to the declared timer.\r
+ *\r
+ * \note The timer library uses the \ref clock "Clock library" to\r
+ * measure time. Intervals should be specified in the format used by\r
+ * the clock library.\r
+ *\r
+ * @{\r
+ */\r
+\r
+\r
+/**\r
+ * \file\r
+ * Timer library header file.\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: timer.h,v 1.3 2006/06/11 21:46:39 adam Exp $\r
+ */\r
+#ifndef __TIMER_H__\r
+#define __TIMER_H__\r
+\r
+#include "clock.h"\r
+\r
+/**\r
+ * A timer.\r
+ *\r
+ * This structure is used for declaring a timer. The timer must be set\r
+ * with timer_set() before it can be used.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+struct timer {\r
+ clock_time_t start;\r
+ clock_time_t interval;\r
+};\r
+\r
+void timer_set(struct timer *t, clock_time_t interval);\r
+void timer_reset(struct timer *t);\r
+void timer_restart(struct timer *t);\r
+int timer_expired(struct timer *t);\r
+\r
+#endif /* __TIMER_H__ */\r
+\r
+/** @} */\r
--- /dev/null
+/*\r
+ FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it\r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
+ **NOTE** The exception to the GPL is included to allow you to distribute a\r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
+ the source code for any proprietary components. Alternative commercial\r
+ license and support terms are also available upon request. See the\r
+ licensing section of http://www.FreeRTOS.org for full details.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details.\r
+\r
+ You should have received a copy of the GNU General Public License along\r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ Please ensure to read the configuration and relevant port sections of the\r
+ online documentation.\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/* Standard includes. */\r
+#include <string.h>\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* uip includes. */\r
+#include "uip.h"\r
+#include "uip_arp.h"\r
+#include "httpd.h"\r
+#include "timer.h"\r
+#include "clock-arch.h"\r
+\r
+/* Demo includes. */\r
+#include "EthDev_LPC17xx.h"\r
+#include "EthDev.h"\r
+#include "ParTest.h"\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* How long to wait before attempting to connect the MAC again. */\r
+#define uipINIT_WAIT ( 100 / portTICK_RATE_MS )\r
+\r
+/* Shortcut to the header within the Rx buffer. */\r
+#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
+\r
+/* Standard constant. */\r
+#define uipTOTAL_FRAME_HEADER_SIZE 54\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Setup the MAC address in the MAC itself, and in the uIP stack.\r
+ */\r
+static void prvSetMACAddress( void );\r
+\r
+/*\r
+ * Port functions required by the uIP stack.\r
+ */\r
+void clock_init( void );\r
+clock_time_t clock_time( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The semaphore used by the ISR to wake the uIP task. */\r
+xSemaphoreHandle xEMACSemaphore = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void clock_init(void)\r
+{\r
+ /* This is done when the scheduler starts. */\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+clock_time_t clock_time( void )\r
+{\r
+ return xTaskGetTickCount();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vuIP_Task( void *pvParameters )\r
+{\r
+portBASE_TYPE i;\r
+uip_ipaddr_t xIPAddr;\r
+struct timer periodic_timer, arp_timer;\r
+extern void ( vEMAC_ISR_Wrapper )( void );\r
+\r
+ ( void ) pvParameters;\r
+\r
+ /* Initialise the uIP stack. */\r
+ timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
+ timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
+ uip_init();\r
+ uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
+ uip_sethostaddr( xIPAddr );\r
+ uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
+ uip_setnetmask( xIPAddr );\r
+ httpd_init();\r
+\r
+ /* Create the semaphore used to wake the uIP task. */\r
+ vSemaphoreCreateBinary( xEMACSemaphore );\r
+\r
+ /* Initialise the MAC. */\r
+ while( lEMACInit() != pdPASS )\r
+ {\r
+ vTaskDelay( uipINIT_WAIT );\r
+ }\r
+\r
+ portENTER_CRITICAL();\r
+ {\r
+ EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );\r
+\r
+ /* Set the interrupt priority to the max permissible to cause some\r
+ interrupt nesting. */\r
+ NVIC_SetPriority( ENET_IRQn, configMAX_SYSCALL_INTERRUPT_PRIORITY );\r
+\r
+ /* Enable the interrupt. */\r
+ NVIC_EnableIRQ( ENET_IRQn );\r
+ prvSetMACAddress();\r
+ }\r
+ portEXIT_CRITICAL();\r
+\r
+\r
+ for( ;; )\r
+ {\r
+ /* Is there received data ready to be processed? */\r
+ uip_len = ulGetEMACRxData();\r
+\r
+ if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
+ {\r
+ /* Standard uIP loop taken from the uIP manual. */\r
+ if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
+ {\r
+ uip_arp_ipin();\r
+ uip_input();\r
+\r
+ /* If the above function invocation resulted in data that\r
+ should be sent out on the network, the global variable\r
+ uip_len is set to a value > 0. */\r
+ if( uip_len > 0 )\r
+ {\r
+ uip_arp_out();\r
+ vSendEMACTxData( uip_len );\r
+ }\r
+ }\r
+ else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
+ {\r
+ uip_arp_arpin();\r
+\r
+ /* If the above function invocation resulted in data that\r
+ should be sent out on the network, the global variable\r
+ uip_len is set to a value > 0. */\r
+ if( uip_len > 0 )\r
+ {\r
+ vSendEMACTxData( uip_len );\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )\r
+ {\r
+ timer_reset( &periodic_timer );\r
+ for( i = 0; i < UIP_CONNS; i++ )\r
+ {\r
+ uip_periodic( i );\r
+\r
+ /* If the above function invocation resulted in data that\r
+ should be sent out on the network, the global variable\r
+ uip_len is set to a value > 0. */\r
+ if( uip_len > 0 )\r
+ {\r
+ uip_arp_out();\r
+ vSendEMACTxData( uip_len );\r
+ }\r
+ }\r
+\r
+ /* Call the ARP timer function every 10 seconds. */\r
+ if( timer_expired( &arp_timer ) )\r
+ {\r
+ timer_reset( &arp_timer );\r
+ uip_arp_timer();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* We did not receive a packet, and there was no periodic\r
+ processing to perform. Block for a fixed period. If a packet\r
+ is received during this period we will be woken by the ISR\r
+ giving us the Semaphore. */\r
+ xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );\r
+ }\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvSetMACAddress( void )\r
+{\r
+struct uip_eth_addr xAddr;\r
+\r
+ /* Configure the MAC address in the uIP stack. */\r
+ xAddr.addr[ 0 ] = configMAC_ADDR0;\r
+ xAddr.addr[ 1 ] = configMAC_ADDR1;\r
+ xAddr.addr[ 2 ] = configMAC_ADDR2;\r
+ xAddr.addr[ 3 ] = configMAC_ADDR3;\r
+ xAddr.addr[ 4 ] = configMAC_ADDR4;\r
+ xAddr.addr[ 5 ] = configMAC_ADDR5;\r
+ uip_setethaddr( xAddr );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationProcessFormInput( portCHAR *pcInputString )\r
+{\r
+char *c;\r
+const unsigned long ulLEDNo = 3;\r
+\r
+ /* Process the form input sent by the IO page of the served HTML. */\r
+\r
+ c = strstr( pcInputString, "?" );\r
+ if( c )\r
+ {\r
+ /* Turn LED's on or off in accordance with the check box status. */\r
+ if( strstr( c, "LED0=1" ) != NULL )\r
+ {\r
+ /* Set LED7. */\r
+ vParTestSetLED( ulLEDNo, pdFALSE );\r
+ }\r
+ else\r
+ {\r
+ /* Clear LED7. */\r
+ vParTestSetLED( ulLEDNo, pdTRUE );\r
+ }\r
+ }\r
+}\r
+\r
--- /dev/null
+/**\r
+ * \addtogroup uipopt\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \name Project-specific configuration options\r
+ * @{\r
+ *\r
+ * uIP has a number of configuration options that can be overridden\r
+ * for each project. These are kept in a project-specific uip-conf.h\r
+ * file and all configuration names have the prefix UIP_CONF.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2006, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * $Id: uip-conf.h,v 1.6 2006/06/12 08:00:31 adam Exp $\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * An example uIP configuration file\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ */\r
+\r
+#ifndef __UIP_CONF_H__\r
+#define __UIP_CONF_H__\r
+\r
+#include <stdint.h>\r
+\r
+#define UIP_CONF_EXTERNAL_BUFFER\r
+\r
+/**\r
+ * 8 bit datatype\r
+ *\r
+ * This typedef defines the 8-bit type used throughout uIP.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+typedef uint8_t u8_t;\r
+\r
+/**\r
+ * 16 bit datatype\r
+ *\r
+ * This typedef defines the 16-bit type used throughout uIP.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+typedef uint16_t u16_t;\r
+\r
+/**\r
+ * Statistics datatype\r
+ *\r
+ * This typedef defines the dataype used for keeping statistics in\r
+ * uIP.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+typedef unsigned short uip_stats_t;\r
+\r
+/**\r
+ * Maximum number of TCP connections.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_MAX_CONNECTIONS 40\r
+\r
+/**\r
+ * Maximum number of listening TCP ports.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_MAX_LISTENPORTS 40\r
+\r
+/**\r
+ * uIP buffer size.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_BUFFER_SIZE 1480\r
+\r
+/**\r
+ * CPU byte order.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_BYTE_ORDER LITTLE_ENDIAN\r
+\r
+/**\r
+ * Logging on or off\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_LOGGING 0\r
+\r
+/**\r
+ * UDP support on or off\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_UDP 0\r
+\r
+/**\r
+ * UDP checksums on or off\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_UDP_CHECKSUMS 1\r
+\r
+/**\r
+ * uIP statistics on or off\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_CONF_STATISTICS 1\r
+\r
+/* Here we include the header file for the application(s) we use in\r
+ our project. */\r
+/*#include "smtp.h"*/\r
+/*#include "hello-world.h"*/\r
+/*#include "telnetd.h"*/\r
+#include "webserver.h"\r
+/*#include "dhcpc.h"*/\r
+/*#include "resolv.h"*/\r
+/*#include "webclient.h"*/\r
+\r
+#endif /* __UIP_CONF_H__ */\r
+\r
+/** @} */\r
+/** @} */\r
--- /dev/null
+#define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/\r
+\r
+/**\r
+ * \defgroup uip The uIP TCP/IP stack\r
+ * @{\r
+ *\r
+ * uIP is an implementation of the TCP/IP protocol stack intended for\r
+ * small 8-bit and 16-bit microcontrollers.\r
+ *\r
+ * uIP provides the necessary protocols for Internet communication,\r
+ * with a very small code footprint and RAM requirements - the uIP\r
+ * code size is on the order of a few kilobytes and RAM usage is on\r
+ * the order of a few hundred bytes.\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * The uIP TCP/IP stack code.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip.c,v 1.65 2006/06/11 21:46:39 adam Exp $\r
+ *\r
+ */\r
+\r
+/*\r
+ * uIP is a small implementation of the IP, UDP and TCP protocols (as\r
+ * well as some basic ICMP stuff). The implementation couples the IP,\r
+ * UDP, TCP and the application layers very tightly. To keep the size\r
+ * of the compiled code down, this code frequently uses the goto\r
+ * statement. While it would be possible to break the uip_process()\r
+ * function into many smaller functions, this would increase the code\r
+ * size because of the overhead of parameter passing and the fact that\r
+ * the optimier would not be as efficient.\r
+ *\r
+ * The principle is that we have a small buffer, called the uip_buf,\r
+ * in which the device driver puts an incoming packet. The TCP/IP\r
+ * stack parses the headers in the packet, and calls the\r
+ * application. If the remote host has sent data to the application,\r
+ * this data is present in the uip_buf and the application read the\r
+ * data from there. It is up to the application to put this data into\r
+ * a byte stream if needed. The application will not be fed with data\r
+ * that is out of sequence.\r
+ *\r
+ * If the application whishes to send data to the peer, it should put\r
+ * its data into the uip_buf. The uip_appdata pointer points to the\r
+ * first available byte. The TCP/IP stack will calculate the\r
+ * checksums, and fill in the necessary header fields and finally send\r
+ * the packet back to the peer.\r
+*/\r
+\r
+#include "uip.h"\r
+#include "uipopt.h"\r
+#include "uip_arch.h"\r
+\r
+#if UIP_CONF_IPV6\r
+#include "uip-neighbor.h"\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+#include <string.h>\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* Variable definitions. */\r
+\r
+\r
+/* The IP address of this host. If it is defined to be fixed (by\r
+ setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set\r
+ here. Otherwise, the address */\r
+#if UIP_FIXEDADDR > 0\r
+const uip_ipaddr_t uip_hostaddr =\r
+ {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),\r
+ HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};\r
+const uip_ipaddr_t uip_draddr =\r
+ {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),\r
+ HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};\r
+const uip_ipaddr_t uip_netmask =\r
+ {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),\r
+ HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};\r
+#else\r
+uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;\r
+#endif /* UIP_FIXEDADDR */\r
+\r
+static const uip_ipaddr_t all_ones_addr =\r
+#if UIP_CONF_IPV6\r
+ {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};\r
+#else /* UIP_CONF_IPV6 */\r
+ {0xffff,0xffff};\r
+#endif /* UIP_CONF_IPV6 */\r
+static const uip_ipaddr_t all_zeroes_addr =\r
+#if UIP_CONF_IPV6\r
+ {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};\r
+#else /* UIP_CONF_IPV6 */\r
+ {0x0000,0x0000};\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+#if UIP_FIXEDETHADDR\r
+const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,\r
+ UIP_ETHADDR1,\r
+ UIP_ETHADDR2,\r
+ UIP_ETHADDR3,\r
+ UIP_ETHADDR4,\r
+ UIP_ETHADDR5}};\r
+#else\r
+struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};\r
+#endif\r
+\r
+#ifndef UIP_CONF_EXTERNAL_BUFFER\r
+\r
+#ifdef __ICCARM__\r
+ #pragma data_alignment=4\r
+ u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains incoming packets. */\r
+#else\r
+ u8_t uip_buf[UIP_BUFSIZE + 2] ALIGN_STRUCT_END; /* The packet buffer that contains incoming packets. */\r
+#endif\r
+\r
+#endif /* UIP_CONF_EXTERNAL_BUFFER */\r
+\r
+void *uip_appdata; /* The uip_appdata pointer points to\r
+ application data. */\r
+void *uip_sappdata; /* The uip_appdata pointer points to\r
+ the application data which is to\r
+ be sent. */\r
+#if UIP_URGDATA > 0\r
+void *uip_urgdata; /* The uip_urgdata pointer points to\r
+ urgent data (out-of-band data), if\r
+ present. */\r
+u16_t uip_urglen, uip_surglen;\r
+#endif /* UIP_URGDATA > 0 */\r
+\r
+u16_t uip_len, uip_slen;\r
+ /* The uip_len is either 8 or 16 bits,\r
+ depending on the maximum packet\r
+ size. */\r
+\r
+u8_t uip_flags; /* The uip_flags variable is used for\r
+ communication between the TCP/IP stack\r
+ and the application program. */\r
+struct uip_conn *uip_conn; /* uip_conn always points to the current\r
+ connection. */\r
+\r
+struct uip_conn uip_conns[UIP_CONNS];\r
+ /* The uip_conns array holds all TCP\r
+ connections. */\r
+u16_t uip_listenports[UIP_LISTENPORTS];\r
+ /* The uip_listenports list all currently\r
+ listning ports. */\r
+#if UIP_UDP\r
+struct uip_udp_conn *uip_udp_conn;\r
+struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];\r
+#endif /* UIP_UDP */\r
+\r
+static u16_t ipid; /* Ths ipid variable is an increasing\r
+ number that is used for the IP ID\r
+ field. */\r
+\r
+void uip_setipid(u16_t id) { ipid = id; }\r
+\r
+static u8_t iss[4]; /* The iss variable is used for the TCP\r
+ initial sequence number. */\r
+\r
+#if UIP_ACTIVE_OPEN\r
+static u16_t lastport; /* Keeps track of the last port used for\r
+ a new connection. */\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+/* Temporary variables. */\r
+u8_t uip_acc32[4];\r
+static u8_t c, opt;\r
+static u16_t tmp16;\r
+\r
+/* Structures and definitions. */\r
+#define TCP_FIN 0x01\r
+#define TCP_SYN 0x02\r
+#define TCP_RST 0x04\r
+#define TCP_PSH 0x08\r
+#define TCP_ACK 0x10\r
+#define TCP_URG 0x20\r
+#define TCP_CTL 0x3f\r
+\r
+#define TCP_OPT_END 0 /* End of TCP options list */\r
+#define TCP_OPT_NOOP 1 /* "No-operation" TCP option */\r
+#define TCP_OPT_MSS 2 /* Maximum segment size TCP option */\r
+\r
+#define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */\r
+\r
+#define ICMP_ECHO_REPLY 0\r
+#define ICMP_ECHO 8\r
+\r
+#define ICMP6_ECHO_REPLY 129\r
+#define ICMP6_ECHO 128\r
+#define ICMP6_NEIGHBOR_SOLICITATION 135\r
+#define ICMP6_NEIGHBOR_ADVERTISEMENT 136\r
+\r
+#define ICMP6_FLAG_S (1 << 6)\r
+\r
+#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1\r
+#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2\r
+\r
+\r
+/* Macros. */\r
+#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])\r
+#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+\r
+\r
+#if UIP_STATISTICS == 1\r
+struct uip_stats uip_stat;\r
+#define UIP_STAT(s) s\r
+#else\r
+#define UIP_STAT(s)\r
+#endif /* UIP_STATISTICS == 1 */\r
+\r
+#if UIP_LOGGING == 1\r
+#include <stdio.h>\r
+void uip_log(char *msg);\r
+#define UIP_LOG(m) uip_log(m)\r
+#else\r
+#define UIP_LOG(m)\r
+#endif /* UIP_LOGGING == 1 */\r
+\r
+#if ! UIP_ARCH_ADD32\r
+void\r
+uip_add32(u8_t *op32, u16_t op16)\r
+{\r
+ uip_acc32[3] = op32[3] + (op16 & 0xff);\r
+ uip_acc32[2] = op32[2] + (op16 >> 8);\r
+ uip_acc32[1] = op32[1];\r
+ uip_acc32[0] = op32[0];\r
+\r
+ if(uip_acc32[2] < (op16 >> 8)) {\r
+ ++uip_acc32[1];\r
+ if(uip_acc32[1] == 0) {\r
+ ++uip_acc32[0];\r
+ }\r
+ }\r
+\r
+\r
+ if(uip_acc32[3] < (op16 & 0xff)) {\r
+ ++uip_acc32[2];\r
+ if(uip_acc32[2] == 0) {\r
+ ++uip_acc32[1];\r
+ if(uip_acc32[1] == 0) {\r
+ ++uip_acc32[0];\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+#endif /* UIP_ARCH_ADD32 */\r
+\r
+#if ! UIP_ARCH_CHKSUM\r
+/*---------------------------------------------------------------------------*/\r
+static u16_t\r
+chksum(u16_t sum, const u8_t *data, u16_t len)\r
+{\r
+ u16_t t;\r
+ const u8_t *dataptr;\r
+ const u8_t *last_byte;\r
+\r
+ dataptr = data;\r
+ last_byte = data + len - 1;\r
+\r
+ while(dataptr < last_byte) { /* At least two more bytes */\r
+ t = (dataptr[0] << 8) + dataptr[1];\r
+ sum += t;\r
+ if(sum < t) {\r
+ sum++; /* carry */\r
+ }\r
+ dataptr += 2;\r
+ }\r
+\r
+ if(dataptr == last_byte) {\r
+ t = (dataptr[0] << 8) + 0;\r
+ sum += t;\r
+ if(sum < t) {\r
+ sum++; /* carry */\r
+ }\r
+ }\r
+\r
+ /* Return sum in host byte order. */\r
+ return sum;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+uip_chksum(u16_t *data, u16_t len)\r
+{\r
+ return htons(chksum(0, (u8_t *)data, len));\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#ifndef UIP_ARCH_IPCHKSUM\r
+u16_t\r
+uip_ipchksum(void)\r
+{\r
+ u16_t sum;\r
+\r
+ sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);\r
+ DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);\r
+ return (sum == 0) ? 0xffff : htons(sum);\r
+}\r
+#endif\r
+/*---------------------------------------------------------------------------*/\r
+static u16_t\r
+upper_layer_chksum(u8_t proto)\r
+{\r
+ u16_t upper_layer_len;\r
+ u16_t sum;\r
+\r
+#if UIP_CONF_IPV6\r
+ upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);\r
+#else /* UIP_CONF_IPV6 */\r
+ upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ /* First sum pseudoheader. */\r
+\r
+ /* IP protocol and length fields. This addition cannot carry. */\r
+ sum = upper_layer_len + proto;\r
+ /* Sum IP source and destination addresses. */\r
+ sum = chksum(sum, (u8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t));\r
+\r
+ /* Sum TCP header and data. */\r
+ sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],\r
+ upper_layer_len);\r
+\r
+ return (sum == 0) ? 0xffff : htons(sum);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_CONF_IPV6\r
+u16_t\r
+uip_icmp6chksum(void)\r
+{\r
+ return upper_layer_chksum(UIP_PROTO_ICMP6);\r
+\r
+}\r
+#endif /* UIP_CONF_IPV6 */\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+uip_tcpchksum(void)\r
+{\r
+ return upper_layer_chksum(UIP_PROTO_TCP);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_UDP_CHECKSUMS\r
+u16_t\r
+uip_udpchksum(void)\r
+{\r
+ return upper_layer_chksum(UIP_PROTO_UDP);\r
+}\r
+#endif /* UIP_UDP_CHECKSUMS */\r
+#endif /* UIP_ARCH_CHKSUM */\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_init(void)\r
+{\r
+ for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+ uip_listenports[c] = 0;\r
+ }\r
+ for(c = 0; c < UIP_CONNS; ++c) {\r
+ uip_conns[c].tcpstateflags = UIP_CLOSED;\r
+ }\r
+#if UIP_ACTIVE_OPEN\r
+ lastport = 1024;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+#if UIP_UDP\r
+ for(c = 0; c < UIP_UDP_CONNS; ++c) {\r
+ uip_udp_conns[c].lport = 0;\r
+ }\r
+#endif /* UIP_UDP */\r
+\r
+\r
+ /* IPv4 initialization. */\r
+#if UIP_FIXEDADDR == 0\r
+ /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/\r
+#endif /* UIP_FIXEDADDR */\r
+\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_ACTIVE_OPEN\r
+struct uip_conn *\r
+uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)\r
+{\r
+ register struct uip_conn *conn, *cconn;\r
+\r
+ /* Find an unused local port. */\r
+ again:\r
+ ++lastport;\r
+\r
+ if(lastport >= 32000) {\r
+ lastport = 4096;\r
+ }\r
+\r
+ /* Check if this port is already in use, and if so try to find\r
+ another one. */\r
+ for(c = 0; c < UIP_CONNS; ++c) {\r
+ conn = &uip_conns[c];\r
+ if(conn->tcpstateflags != UIP_CLOSED &&\r
+ conn->lport == htons(lastport)) {\r
+ goto again;\r
+ }\r
+ }\r
+\r
+ conn = 0;\r
+ for(c = 0; c < UIP_CONNS; ++c) {\r
+ cconn = &uip_conns[c];\r
+ if(cconn->tcpstateflags == UIP_CLOSED) {\r
+ conn = cconn;\r
+ break;\r
+ }\r
+ if(cconn->tcpstateflags == UIP_TIME_WAIT) {\r
+ if(conn == 0 ||\r
+ cconn->timer > conn->timer) {\r
+ conn = cconn;\r
+ }\r
+ }\r
+ }\r
+\r
+ if(conn == 0) {\r
+ return 0;\r
+ }\r
+\r
+ conn->tcpstateflags = UIP_SYN_SENT;\r
+\r
+ conn->snd_nxt[0] = iss[0];\r
+ conn->snd_nxt[1] = iss[1];\r
+ conn->snd_nxt[2] = iss[2];\r
+ conn->snd_nxt[3] = iss[3];\r
+\r
+ conn->initialmss = conn->mss = UIP_TCP_MSS;\r
+\r
+ conn->len = 1; /* TCP length of the SYN is one. */\r
+ conn->nrtx = 0;\r
+ conn->timer = 1; /* Send the SYN next time around. */\r
+ conn->rto = UIP_RTO;\r
+ conn->sa = 0;\r
+ conn->sv = 16; /* Initial value of the RTT variance. */\r
+ conn->lport = htons(lastport);\r
+ conn->rport = rport;\r
+ uip_ipaddr_copy(&conn->ripaddr, ripaddr);\r
+\r
+ return conn;\r
+}\r
+#endif /* UIP_ACTIVE_OPEN */\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_UDP\r
+struct uip_udp_conn *\r
+uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport)\r
+{\r
+ register struct uip_udp_conn *conn;\r
+\r
+ /* Find an unused local port. */\r
+ again:\r
+ ++lastport;\r
+\r
+ if(lastport >= 32000) {\r
+ lastport = 4096;\r
+ }\r
+\r
+ for(c = 0; c < UIP_UDP_CONNS; ++c) {\r
+ if(uip_udp_conns[c].lport == htons(lastport)) {\r
+ goto again;\r
+ }\r
+ }\r
+\r
+\r
+ conn = 0;\r
+ for(c = 0; c < UIP_UDP_CONNS; ++c) {\r
+ if(uip_udp_conns[c].lport == 0) {\r
+ conn = &uip_udp_conns[c];\r
+ break;\r
+ }\r
+ }\r
+\r
+ if(conn == 0) {\r
+ return 0;\r
+ }\r
+\r
+ conn->lport = HTONS(lastport);\r
+ conn->rport = rport;\r
+ if(ripaddr == NULL) {\r
+ memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t));\r
+ } else {\r
+ uip_ipaddr_copy(&conn->ripaddr, ripaddr);\r
+ }\r
+ conn->ttl = UIP_TTL;\r
+\r
+ return conn;\r
+}\r
+#endif /* UIP_UDP */\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_unlisten(u16_t port)\r
+{\r
+ for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+ if(uip_listenports[c] == port) {\r
+ uip_listenports[c] = 0;\r
+ return;\r
+ }\r
+ }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_listen(u16_t port)\r
+{\r
+ for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+ if(uip_listenports[c] == 0) {\r
+ uip_listenports[c] = port;\r
+ return;\r
+ }\r
+ }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/* XXX: IP fragment reassembly: not well-tested. */\r
+\r
+#if UIP_REASSEMBLY && !UIP_CONF_IPV6\r
+#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)\r
+static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];\r
+static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];\r
+static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,\r
+ 0x0f, 0x07, 0x03, 0x01};\r
+static u16_t uip_reasslen;\r
+static u8_t uip_reassflags;\r
+#define UIP_REASS_FLAG_LASTFRAG 0x01\r
+static u8_t uip_reasstmr;\r
+\r
+#define IP_MF 0x20\r
+\r
+static u8_t\r
+uip_reass(void)\r
+{\r
+ u16_t offset, len;\r
+ u16_t i;\r
+\r
+ /* If ip_reasstmr is zero, no packet is present in the buffer, so we\r
+ write the IP header of the fragment into the reassembly\r
+ buffer. The timer is updated with the maximum age. */\r
+ if(uip_reasstmr == 0) {\r
+ memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);\r
+ uip_reasstmr = UIP_REASS_MAXAGE;\r
+ uip_reassflags = 0;\r
+ /* Clear the bitmap. */\r
+ memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap));\r
+ }\r
+\r
+ /* Check if the incoming fragment matches the one currently present\r
+ in the reasembly buffer. If so, we proceed with copying the\r
+ fragment into the buffer. */\r
+ if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&\r
+ BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&\r
+ BUF->destipaddr[0] == FBUF->destipaddr[0] &&\r
+ BUF->destipaddr[1] == FBUF->destipaddr[1] &&\r
+ BUF->ipid[0] == FBUF->ipid[0] &&\r
+ BUF->ipid[1] == FBUF->ipid[1]) {\r
+\r
+ len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;\r
+ offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;\r
+\r
+ /* If the offset or the offset + fragment length overflows the\r
+ reassembly buffer, we discard the entire packet. */\r
+ if(offset > UIP_REASS_BUFSIZE ||\r
+ offset + len > UIP_REASS_BUFSIZE) {\r
+ uip_reasstmr = 0;\r
+ goto nullreturn;\r
+ }\r
+\r
+ /* Copy the fragment into the reassembly buffer, at the right\r
+ offset. */\r
+ memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],\r
+ (char *)BUF + (int)((BUF->vhl & 0x0f) * 4),\r
+ len);\r
+\r
+ /* Update the bitmap. */\r
+ if(offset / (8 * 8) == (offset + len) / (8 * 8)) {\r
+ /* If the two endpoints are in the same byte, we only update\r
+ that byte. */\r
+\r
+ uip_reassbitmap[offset / (8 * 8)] |=\r
+ bitmap_bits[(offset / 8 ) & 7] &\r
+ ~bitmap_bits[((offset + len) / 8 ) & 7];\r
+ } else {\r
+ /* If the two endpoints are in different bytes, we update the\r
+ bytes in the endpoints and fill the stuff inbetween with\r
+ 0xff. */\r
+ uip_reassbitmap[offset / (8 * 8)] |=\r
+ bitmap_bits[(offset / 8 ) & 7];\r
+ for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {\r
+ uip_reassbitmap[i] = 0xff;\r
+ }\r
+ uip_reassbitmap[(offset + len) / (8 * 8)] |=\r
+ ~bitmap_bits[((offset + len) / 8 ) & 7];\r
+ }\r
+\r
+ /* If this fragment has the More Fragments flag set to zero, we\r
+ know that this is the last fragment, so we can calculate the\r
+ size of the entire packet. We also set the\r
+ IP_REASS_FLAG_LASTFRAG flag to indicate that we have received\r
+ the final fragment. */\r
+\r
+ if((BUF->ipoffset[0] & IP_MF) == 0) {\r
+ uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;\r
+ uip_reasslen = offset + len;\r
+ }\r
+\r
+ /* Finally, we check if we have a full packet in the buffer. We do\r
+ this by checking if we have the last fragment and if all bits\r
+ in the bitmap are set. */\r
+ if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {\r
+ /* Check all bytes up to and including all but the last byte in\r
+ the bitmap. */\r
+ for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {\r
+ if(uip_reassbitmap[i] != 0xff) {\r
+ goto nullreturn;\r
+ }\r
+ }\r
+ /* Check the last byte in the bitmap. It should contain just the\r
+ right amount of bits. */\r
+ if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=\r
+ (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {\r
+ goto nullreturn;\r
+ }\r
+\r
+ /* If we have come this far, we have a full packet in the\r
+ buffer, so we allocate a pbuf and copy the packet into it. We\r
+ also reset the timer. */\r
+ uip_reasstmr = 0;\r
+ memcpy(BUF, FBUF, uip_reasslen);\r
+\r
+ /* Pretend to be a "normal" (i.e., not fragmented) IP packet\r
+ from now on. */\r
+ BUF->ipoffset[0] = BUF->ipoffset[1] = 0;\r
+ BUF->len[0] = uip_reasslen >> 8;\r
+ BUF->len[1] = uip_reasslen & 0xff;\r
+ BUF->ipchksum = 0;\r
+ BUF->ipchksum = ~(uip_ipchksum());\r
+\r
+ return uip_reasslen;\r
+ }\r
+ }\r
+\r
+ nullreturn:\r
+ return 0;\r
+}\r
+#endif /* UIP_REASSEMBLY */\r
+/*---------------------------------------------------------------------------*/\r
+static void\r
+uip_add_rcv_nxt(u16_t n)\r
+{\r
+ uip_add32(uip_conn->rcv_nxt, n);\r
+ uip_conn->rcv_nxt[0] = uip_acc32[0];\r
+ uip_conn->rcv_nxt[1] = uip_acc32[1];\r
+ uip_conn->rcv_nxt[2] = uip_acc32[2];\r
+ uip_conn->rcv_nxt[3] = uip_acc32[3];\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_process(u8_t flag)\r
+{\r
+ register struct uip_conn *uip_connr = uip_conn;\r
+\r
+#if UIP_UDP\r
+ if(flag == UIP_UDP_SEND_CONN) {\r
+ goto udp_send;\r
+ }\r
+#endif /* UIP_UDP */\r
+\r
+ uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];\r
+\r
+ /* Check if we were invoked because of a poll request for a\r
+ particular connection. */\r
+ if(flag == UIP_POLL_REQUEST) {\r
+ if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&\r
+ !uip_outstanding(uip_connr)) {\r
+ uip_flags = UIP_POLL;\r
+ UIP_APPCALL();\r
+ goto appsend;\r
+ }\r
+ goto drop;\r
+\r
+ /* Check if we were invoked because of the perodic timer fireing. */\r
+ } else if(flag == UIP_TIMER) {\r
+#if UIP_REASSEMBLY\r
+ if(uip_reasstmr != 0) {\r
+ --uip_reasstmr;\r
+ }\r
+#endif /* UIP_REASSEMBLY */\r
+ /* Increase the initial sequence number. */\r
+ if(++iss[3] == 0) {\r
+ if(++iss[2] == 0) {\r
+ if(++iss[1] == 0) {\r
+ ++iss[0];\r
+ }\r
+ }\r
+ }\r
+\r
+ /* Reset the length variables. */\r
+ uip_len = 0;\r
+ uip_slen = 0;\r
+\r
+ /* Check if the connection is in a state in which we simply wait\r
+ for the connection to time out. If so, we increase the\r
+ connection's timer and remove the connection if it times\r
+ out. */\r
+ if(uip_connr->tcpstateflags == UIP_TIME_WAIT ||\r
+ uip_connr->tcpstateflags == UIP_FIN_WAIT_2) {\r
+ ++(uip_connr->timer);\r
+ if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {\r
+ uip_connr->tcpstateflags = UIP_CLOSED;\r
+ }\r
+ } else if(uip_connr->tcpstateflags != UIP_CLOSED) {\r
+ /* If the connection has outstanding data, we increase the\r
+ connection's timer and see if it has reached the RTO value\r
+ in which case we retransmit. */\r
+ if(uip_outstanding(uip_connr)) {\r
+ uip_connr->timer = uip_connr->timer - 1;\r
+ if(uip_connr->timer == 0) {\r
+ if(uip_connr->nrtx == UIP_MAXRTX ||\r
+ ((uip_connr->tcpstateflags == UIP_SYN_SENT ||\r
+ uip_connr->tcpstateflags == UIP_SYN_RCVD) &&\r
+ uip_connr->nrtx == UIP_MAXSYNRTX)) {\r
+ uip_connr->tcpstateflags = UIP_CLOSED;\r
+\r
+ /* We call UIP_APPCALL() with uip_flags set to\r
+ UIP_TIMEDOUT to inform the application that the\r
+ connection has timed out. */\r
+ uip_flags = UIP_TIMEDOUT;\r
+ UIP_APPCALL();\r
+\r
+ /* We also send a reset packet to the remote host. */\r
+ BUF->flags = TCP_RST | TCP_ACK;\r
+ goto tcp_send_nodata;\r
+ }\r
+\r
+ /* Exponential backoff. */\r
+ uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?\r
+ 4:\r
+ uip_connr->nrtx);\r
+ ++(uip_connr->nrtx);\r
+\r
+ /* Ok, so we need to retransmit. We do this differently\r
+ depending on which state we are in. In ESTABLISHED, we\r
+ call upon the application so that it may prepare the\r
+ data for the retransmit. In SYN_RCVD, we resend the\r
+ SYNACK that we sent earlier and in LAST_ACK we have to\r
+ retransmit our FINACK. */\r
+ UIP_STAT(++uip_stat.tcp.rexmit);\r
+ switch(uip_connr->tcpstateflags & UIP_TS_MASK) {\r
+ case UIP_SYN_RCVD:\r
+ /* In the SYN_RCVD state, we should retransmit our\r
+ SYNACK. */\r
+ goto tcp_send_synack;\r
+\r
+#if UIP_ACTIVE_OPEN\r
+ case UIP_SYN_SENT:\r
+ /* In the SYN_SENT state, we retransmit out SYN. */\r
+ BUF->flags = 0;\r
+ goto tcp_send_syn;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+ case UIP_ESTABLISHED:\r
+ /* In the ESTABLISHED state, we call upon the application\r
+ to do the actual retransmit after which we jump into\r
+ the code for sending out the packet (the apprexmit\r
+ label). */\r
+ uip_flags = UIP_REXMIT;\r
+ UIP_APPCALL();\r
+ goto apprexmit;\r
+\r
+ case UIP_FIN_WAIT_1:\r
+ case UIP_CLOSING:\r
+ case UIP_LAST_ACK:\r
+ /* In all these states we should retransmit a FINACK. */\r
+ goto tcp_send_finack;\r
+\r
+ }\r
+ }\r
+ } else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {\r
+ /* If there was no need for a retransmission, we poll the\r
+ application for new data. */\r
+ uip_flags = UIP_POLL;\r
+ UIP_APPCALL();\r
+ goto appsend;\r
+ }\r
+ }\r
+ goto drop;\r
+ }\r
+#if UIP_UDP\r
+ if(flag == UIP_UDP_TIMER) {\r
+ if(uip_udp_conn->lport != 0) {\r
+ uip_conn = NULL;\r
+ uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+ uip_len = uip_slen = 0;\r
+ uip_flags = UIP_POLL;\r
+ UIP_UDP_APPCALL();\r
+ goto udp_send;\r
+ } else {\r
+ goto drop;\r
+ }\r
+ }\r
+#endif\r
+\r
+ /* This is where the input processing starts. */\r
+ UIP_STAT(++uip_stat.ip.recv);\r
+\r
+ /* Start of IP input header processing code. */\r
+\r
+#if UIP_CONF_IPV6\r
+ /* Check validity of the IP header. */\r
+ if((BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ UIP_STAT(++uip_stat.ip.vhlerr);\r
+ UIP_LOG("ipv6: invalid version.");\r
+ goto drop;\r
+ }\r
+#else /* UIP_CONF_IPV6 */\r
+ /* Check validity of the IP header. */\r
+ if(BUF->vhl != 0x45) { /* IP version and header length. */\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ UIP_STAT(++uip_stat.ip.vhlerr);\r
+ UIP_LOG("ip: invalid version or header length.");\r
+ goto drop;\r
+ }\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ /* Check the size of the packet. If the size reported to us in\r
+ uip_len is smaller the size reported in the IP header, we assume\r
+ that the packet has been corrupted in transit. If the size of\r
+ uip_len is larger than the size reported in the IP packet header,\r
+ the packet has been padded and we set uip_len to the correct\r
+ value.. */\r
+\r
+ if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {\r
+ uip_len = (BUF->len[0] << 8) + BUF->len[1];\r
+#if UIP_CONF_IPV6\r
+ uip_len += 40; /* The length reported in the IPv6 header is the\r
+ length of the payload that follows the\r
+ header. However, uIP uses the uip_len variable\r
+ for holding the size of the entire packet,\r
+ including the IP header. For IPv4 this is not a\r
+ problem as the length field in the IPv4 header\r
+ contains the length of the entire packet. But\r
+ for IPv6 we need to add the size of the IPv6\r
+ header (40 bytes). */\r
+#endif /* UIP_CONF_IPV6 */\r
+ } else {\r
+ UIP_LOG("ip: packet shorter than reported in IP header.");\r
+ goto drop;\r
+ }\r
+\r
+#if !UIP_CONF_IPV6\r
+ /* Check the fragment flag. */\r
+ if((BUF->ipoffset[0] & 0x3f) != 0 ||\r
+ BUF->ipoffset[1] != 0) {\r
+#if UIP_REASSEMBLY\r
+ uip_len = uip_reass();\r
+ if(uip_len == 0) {\r
+ goto drop;\r
+ }\r
+#else /* UIP_REASSEMBLY */\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ UIP_STAT(++uip_stat.ip.fragerr);\r
+ UIP_LOG("ip: fragment dropped.");\r
+ goto drop;\r
+#endif /* UIP_REASSEMBLY */\r
+ }\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ if(uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr)) {\r
+ /* If we are configured to use ping IP address configuration and\r
+ hasn't been assigned an IP address yet, we accept all ICMP\r
+ packets. */\r
+#if UIP_PINGADDRCONF && !UIP_CONF_IPV6\r
+ if(BUF->proto == UIP_PROTO_ICMP) {\r
+ UIP_LOG("ip: possible ping config packet received.");\r
+ goto icmp_input;\r
+ } else {\r
+ UIP_LOG("ip: packet dropped since no address assigned.");\r
+ goto drop;\r
+ }\r
+#endif /* UIP_PINGADDRCONF */\r
+\r
+ } else {\r
+ /* If IP broadcast support is configured, we check for a broadcast\r
+ UDP packet, which may be destined to us. */\r
+#if UIP_BROADCAST\r
+ DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());\r
+ if(BUF->proto == UIP_PROTO_UDP &&\r
+ uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr)\r
+ /*&&\r
+ uip_ipchksum() == 0xffff*/) {\r
+ goto udp_input;\r
+ }\r
+#endif /* UIP_BROADCAST */\r
+\r
+ /* Check if the packet is destined for our IP address. */\r
+#if !UIP_CONF_IPV6\r
+ if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ goto drop;\r
+ }\r
+#else /* UIP_CONF_IPV6 */\r
+ /* For IPv6, packet reception is a little trickier as we need to\r
+ make sure that we listen to certain multicast addresses (all\r
+ hosts multicast address, and the solicited-node multicast\r
+ address) as well. However, we will cheat here and accept all\r
+ multicast packets that are sent to the ff02::/16 addresses. */\r
+ if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) &&\r
+ BUF->destipaddr[0] != HTONS(0xff02)) {\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ goto drop;\r
+ }\r
+#endif /* UIP_CONF_IPV6 */\r
+ }\r
+\r
+#if !UIP_CONF_IPV6\r
+ if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header\r
+ checksum. */\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ UIP_STAT(++uip_stat.ip.chkerr);\r
+ UIP_LOG("ip: bad checksum.");\r
+ goto drop;\r
+ }\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,\r
+ proceed with TCP input\r
+ processing. */\r
+ goto tcp_input;\r
+ }\r
+\r
+#if UIP_UDP\r
+ if(BUF->proto == UIP_PROTO_UDP) {\r
+ goto udp_input;\r
+ }\r
+#endif /* UIP_UDP */\r
+\r
+#if !UIP_CONF_IPV6\r
+ /* ICMPv4 processing code follows. */\r
+ if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from\r
+ here. */\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ UIP_STAT(++uip_stat.ip.protoerr);\r
+ UIP_LOG("ip: neither tcp nor icmp.");\r
+ goto drop;\r
+ }\r
+\r
+#if UIP_PINGADDRCONF\r
+ icmp_input:\r
+#endif /* UIP_PINGADDRCONF */\r
+ UIP_STAT(++uip_stat.icmp.recv);\r
+\r
+ /* ICMP echo (i.e., ping) processing. This is simple, we only change\r
+ the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP\r
+ checksum before we return the packet. */\r
+ if(ICMPBUF->type != ICMP_ECHO) {\r
+ UIP_STAT(++uip_stat.icmp.drop);\r
+ UIP_STAT(++uip_stat.icmp.typeerr);\r
+ UIP_LOG("icmp: not icmp echo.");\r
+ goto drop;\r
+ }\r
+\r
+ /* If we are configured to use ping IP address assignment, we use\r
+ the destination IP address of this ping packet and assign it to\r
+ ourself. */\r
+#if UIP_PINGADDRCONF\r
+ if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {\r
+ uip_hostaddr[0] = BUF->destipaddr[0];\r
+ uip_hostaddr[1] = BUF->destipaddr[1];\r
+ }\r
+#endif /* UIP_PINGADDRCONF */\r
+\r
+ ICMPBUF->type = ICMP_ECHO_REPLY;\r
+\r
+ if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {\r
+ ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;\r
+ } else {\r
+ ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);\r
+ }\r
+\r
+ /* Swap IP addresses. */\r
+ uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);\r
+ uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);\r
+\r
+ UIP_STAT(++uip_stat.icmp.sent);\r
+ goto send;\r
+\r
+ /* End of IPv4 input header processing code. */\r
+#else /* !UIP_CONF_IPV6 */\r
+\r
+ /* This is IPv6 ICMPv6 processing code. */\r
+ DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);\r
+\r
+ if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from\r
+ here. */\r
+ UIP_STAT(++uip_stat.ip.drop);\r
+ UIP_STAT(++uip_stat.ip.protoerr);\r
+ UIP_LOG("ip: neither tcp nor icmp6.");\r
+ goto drop;\r
+ }\r
+\r
+ UIP_STAT(++uip_stat.icmp.recv);\r
+\r
+ /* If we get a neighbor solicitation for our address we should send\r
+ a neighbor advertisement message back. */\r
+ if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {\r
+ if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {\r
+\r
+ if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {\r
+ /* Save the sender's address in our neighbor list. */\r
+ uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));\r
+ }\r
+\r
+ /* We should now send a neighbor advertisement back to where the\r
+ neighbor solicication came from. */\r
+ ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;\r
+ ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */\r
+\r
+ ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;\r
+\r
+ uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);\r
+ uip_ipaddr_copy(ICMPBUF->srcipaddr, uip_hostaddr);\r
+ ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;\r
+ ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */\r
+ memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));\r
+ ICMPBUF->icmpchksum = 0;\r
+ ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
+ goto send;\r
+\r
+ }\r
+ goto drop;\r
+ } else if(ICMPBUF->type == ICMP6_ECHO) {\r
+ /* ICMP echo (i.e., ping) processing. This is simple, we only\r
+ change the ICMP type from ECHO to ECHO_REPLY and update the\r
+ ICMP checksum before we return the packet. */\r
+\r
+ ICMPBUF->type = ICMP6_ECHO_REPLY;\r
+\r
+ uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);\r
+ uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);\r
+ ICMPBUF->icmpchksum = 0;\r
+ ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
+\r
+ UIP_STAT(++uip_stat.icmp.sent);\r
+ goto send;\r
+ } else {\r
+ DEBUG_PRINTF("Unknown icmp6 message type %d\n", ICMPBUF->type);\r
+ UIP_STAT(++uip_stat.icmp.drop);\r
+ UIP_STAT(++uip_stat.icmp.typeerr);\r
+ UIP_LOG("icmp: unknown ICMP message.");\r
+ goto drop;\r
+ }\r
+\r
+ /* End of IPv6 ICMP processing. */\r
+\r
+#endif /* !UIP_CONF_IPV6 */\r
+\r
+#if UIP_UDP\r
+ /* UDP input processing. */\r
+ udp_input:\r
+ /* UDP processing is really just a hack. We don't do anything to the\r
+ UDP/IP headers, but let the UDP application do all the hard\r
+ work. If the application sets uip_slen, it has a packet to\r
+ send. */\r
+#if UIP_UDP_CHECKSUMS\r
+ uip_len = uip_len - UIP_IPUDPH_LEN;\r
+ uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+ if(UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {\r
+ UIP_STAT(++uip_stat.udp.drop);\r
+ UIP_STAT(++uip_stat.udp.chkerr);\r
+ UIP_LOG("udp: bad checksum.");\r
+ goto drop;\r
+ }\r
+#else /* UIP_UDP_CHECKSUMS */\r
+ uip_len = uip_len - UIP_IPUDPH_LEN;\r
+#endif /* UIP_UDP_CHECKSUMS */\r
+\r
+ /* Demultiplex this UDP packet between the UDP "connections". */\r
+ for(uip_udp_conn = &uip_udp_conns[0];\r
+ uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS];\r
+ ++uip_udp_conn) {\r
+ /* If the local UDP port is non-zero, the connection is considered\r
+ to be used. If so, the local port number is checked against the\r
+ destination port number in the received packet. If the two port\r
+ numbers match, the remote port number is checked if the\r
+ connection is bound to a remote port. Finally, if the\r
+ connection is bound to a remote IP address, the source IP\r
+ address of the packet is checked. */\r
+ if(uip_udp_conn->lport != 0 &&\r
+ UDPBUF->destport == uip_udp_conn->lport &&\r
+ (uip_udp_conn->rport == 0 ||\r
+ UDPBUF->srcport == uip_udp_conn->rport) &&\r
+ (uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) ||\r
+ uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||\r
+ uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {\r
+ goto udp_found;\r
+ }\r
+ }\r
+ UIP_LOG("udp: no matching connection found");\r
+ goto drop;\r
+\r
+ udp_found:\r
+ UIP_STAT(++uip_stat.udp.recv);\r
+ uip_conn = NULL;\r
+ uip_flags = UIP_NEWDATA;\r
+ uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+ uip_slen = 0;\r
+ UIP_UDP_APPCALL();\r
+ udp_send:\r
+ if(uip_slen == 0) {\r
+ goto drop;\r
+ }\r
+ uip_len = uip_slen + UIP_IPUDPH_LEN;\r
+\r
+#if UIP_CONF_IPV6\r
+ /* For IPv6, the IP length field does not include the IPv6 IP header\r
+ length. */\r
+ BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);\r
+ BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);\r
+#else /* UIP_CONF_IPV6 */\r
+ BUF->len[0] = (uip_len >> 8);\r
+ BUF->len[1] = (uip_len & 0xff);\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ BUF->ttl = uip_udp_conn->ttl;\r
+ BUF->proto = UIP_PROTO_UDP;\r
+\r
+ UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);\r
+ UDPBUF->udpchksum = 0;\r
+\r
+ BUF->srcport = uip_udp_conn->lport;\r
+ BUF->destport = uip_udp_conn->rport;\r
+\r
+ uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);\r
+ uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);\r
+\r
+ uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];\r
+\r
+#if UIP_UDP_CHECKSUMS\r
+ /* Calculate UDP checksum. */\r
+ UDPBUF->udpchksum = ~(uip_udpchksum());\r
+ if(UDPBUF->udpchksum == 0) {\r
+ UDPBUF->udpchksum = 0xffff;\r
+ }\r
+#endif /* UIP_UDP_CHECKSUMS */\r
+ UIP_STAT(++uip_stat.udp.sent);\r
+ goto ip_send_nolen;\r
+#endif /* UIP_UDP */\r
+\r
+ /* TCP input processing. */\r
+ tcp_input:\r
+ UIP_STAT(++uip_stat.tcp.recv);\r
+\r
+ /* Start of TCP input header processing code. */\r
+\r
+ if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP\r
+ checksum. */\r
+ UIP_STAT(++uip_stat.tcp.drop);\r
+ UIP_STAT(++uip_stat.tcp.chkerr);\r
+ UIP_LOG("tcp: bad checksum.");\r
+ goto drop;\r
+ }\r
+\r
+\r
+ /* Demultiplex this segment. */\r
+ /* First check any active connections. */\r
+ for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];\r
+ ++uip_connr) {\r
+ if(uip_connr->tcpstateflags != UIP_CLOSED &&\r
+ BUF->destport == uip_connr->lport &&\r
+ BUF->srcport == uip_connr->rport &&\r
+ uip_ipaddr_cmp(BUF->srcipaddr, uip_connr->ripaddr)) {\r
+ goto found;\r
+ }\r
+ }\r
+\r
+ /* If we didn't find and active connection that expected the packet,\r
+ either this packet is an old duplicate, or this is a SYN packet\r
+ destined for a connection in LISTEN. If the SYN flag isn't set,\r
+ it is an old packet and we send a RST. */\r
+ if((BUF->flags & TCP_CTL) != TCP_SYN) {\r
+ goto reset;\r
+ }\r
+\r
+ tmp16 = BUF->destport;\r
+ /* Next, check listening connections. */\r
+ for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+ if(tmp16 == uip_listenports[c])\r
+ goto found_listen;\r
+ }\r
+\r
+ /* No matching connection found, so we send a RST packet. */\r
+ UIP_STAT(++uip_stat.tcp.synrst);\r
+ reset:\r
+\r
+ /* We do not send resets in response to resets. */\r
+ if(BUF->flags & TCP_RST) {\r
+ goto drop;\r
+ }\r
+\r
+ UIP_STAT(++uip_stat.tcp.rst);\r
+\r
+ BUF->flags = TCP_RST | TCP_ACK;\r
+ uip_len = UIP_IPTCPH_LEN;\r
+ BUF->tcpoffset = 5 << 4;\r
+\r
+ /* Flip the seqno and ackno fields in the TCP header. */\r
+ c = BUF->seqno[3];\r
+ BUF->seqno[3] = BUF->ackno[3];\r
+ BUF->ackno[3] = c;\r
+\r
+ c = BUF->seqno[2];\r
+ BUF->seqno[2] = BUF->ackno[2];\r
+ BUF->ackno[2] = c;\r
+\r
+ c = BUF->seqno[1];\r
+ BUF->seqno[1] = BUF->ackno[1];\r
+ BUF->ackno[1] = c;\r
+\r
+ c = BUF->seqno[0];\r
+ BUF->seqno[0] = BUF->ackno[0];\r
+ BUF->ackno[0] = c;\r
+\r
+ /* We also have to increase the sequence number we are\r
+ acknowledging. If the least significant byte overflowed, we need\r
+ to propagate the carry to the other bytes as well. */\r
+ if(++BUF->ackno[3] == 0) {\r
+ if(++BUF->ackno[2] == 0) {\r
+ if(++BUF->ackno[1] == 0) {\r
+ ++BUF->ackno[0];\r
+ }\r
+ }\r
+ }\r
+\r
+ /* Swap port numbers. */\r
+ tmp16 = BUF->srcport;\r
+ BUF->srcport = BUF->destport;\r
+ BUF->destport = tmp16;\r
+\r
+ /* Swap IP addresses. */\r
+ uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);\r
+ uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);\r
+\r
+ /* And send out the RST packet! */\r
+ goto tcp_send_noconn;\r
+\r
+ /* This label will be jumped to if we matched the incoming packet\r
+ with a connection in LISTEN. In that case, we should create a new\r
+ connection and send a SYNACK in return. */\r
+ found_listen:\r
+ /* First we check if there are any connections avaliable. Unused\r
+ connections are kept in the same table as used connections, but\r
+ unused ones have the tcpstate set to CLOSED. Also, connections in\r
+ TIME_WAIT are kept track of and we'll use the oldest one if no\r
+ CLOSED connections are found. Thanks to Eddie C. Dost for a very\r
+ nice algorithm for the TIME_WAIT search. */\r
+ uip_connr = 0;\r
+ for(c = 0; c < UIP_CONNS; ++c) {\r
+ if(uip_conns[c].tcpstateflags == UIP_CLOSED) {\r
+ uip_connr = &uip_conns[c];\r
+ break;\r
+ }\r
+ if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {\r
+ if(uip_connr == 0 ||\r
+ uip_conns[c].timer > uip_connr->timer) {\r
+ uip_connr = &uip_conns[c];\r
+ }\r
+ }\r
+ }\r
+\r
+ if(uip_connr == 0) {\r
+ /* All connections are used already, we drop packet and hope that\r
+ the remote end will retransmit the packet at a time when we\r
+ have more spare connections. */\r
+ UIP_STAT(++uip_stat.tcp.syndrop);\r
+ UIP_LOG("tcp: found no unused connections.");\r
+ goto drop;\r
+ }\r
+ uip_conn = uip_connr;\r
+\r
+ /* Fill in the necessary fields for the new connection. */\r
+ uip_connr->rto = uip_connr->timer = UIP_RTO;\r
+ uip_connr->sa = 0;\r
+ uip_connr->sv = 4;\r
+ uip_connr->nrtx = 0;\r
+ uip_connr->lport = BUF->destport;\r
+ uip_connr->rport = BUF->srcport;\r
+ uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);\r
+ uip_connr->tcpstateflags = UIP_SYN_RCVD;\r
+\r
+ uip_connr->snd_nxt[0] = iss[0];\r
+ uip_connr->snd_nxt[1] = iss[1];\r
+ uip_connr->snd_nxt[2] = iss[2];\r
+ uip_connr->snd_nxt[3] = iss[3];\r
+ uip_connr->len = 1;\r
+\r
+ /* rcv_nxt should be the seqno from the incoming packet + 1. */\r
+ uip_connr->rcv_nxt[3] = BUF->seqno[3];\r
+ uip_connr->rcv_nxt[2] = BUF->seqno[2];\r
+ uip_connr->rcv_nxt[1] = BUF->seqno[1];\r
+ uip_connr->rcv_nxt[0] = BUF->seqno[0];\r
+ uip_add_rcv_nxt(1);\r
+\r
+ /* Parse the TCP MSS option, if present. */\r
+ if((BUF->tcpoffset & 0xf0) > 0x50) {\r
+ for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {\r
+ opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];\r
+ if(opt == TCP_OPT_END) {\r
+ /* End of options. */\r
+ break;\r
+ } else if(opt == TCP_OPT_NOOP) {\r
+ ++c;\r
+ /* NOP option. */\r
+ } else if(opt == TCP_OPT_MSS &&\r
+ uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {\r
+ /* An MSS option with the right option length. */\r
+ tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |\r
+ (u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];\r
+ uip_connr->initialmss = uip_connr->mss =\r
+ tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;\r
+\r
+ /* And we are done processing options. */\r
+ break;\r
+ } else {\r
+ /* All other options have a length field, so that we easily\r
+ can skip past them. */\r
+ if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {\r
+ /* If the length field is zero, the options are malformed\r
+ and we don't process them further. */\r
+ break;\r
+ }\r
+ c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];\r
+ }\r
+ }\r
+ }\r
+\r
+ /* Our response will be a SYNACK. */\r
+#if UIP_ACTIVE_OPEN\r
+ tcp_send_synack:\r
+ BUF->flags = TCP_ACK;\r
+\r
+ tcp_send_syn:\r
+ BUF->flags |= TCP_SYN;\r
+#else /* UIP_ACTIVE_OPEN */\r
+ tcp_send_synack:\r
+ BUF->flags = TCP_SYN | TCP_ACK;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+ /* We send out the TCP Maximum Segment Size option with our\r
+ SYNACK. */\r
+ BUF->optdata[0] = TCP_OPT_MSS;\r
+ BUF->optdata[1] = TCP_OPT_MSS_LEN;\r
+ BUF->optdata[2] = (UIP_TCP_MSS) / 256;\r
+ BUF->optdata[3] = (UIP_TCP_MSS) & 255;\r
+ uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;\r
+ BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;\r
+ goto tcp_send;\r
+\r
+ /* This label will be jumped to if we found an active connection. */\r
+ found:\r
+ uip_conn = uip_connr;\r
+ uip_flags = 0;\r
+ /* We do a very naive form of TCP reset processing; we just accept\r
+ any RST and kill our connection. We should in fact check if the\r
+ sequence number of this reset is wihtin our advertised window\r
+ before we accept the reset. */\r
+ if(BUF->flags & TCP_RST) {\r
+ uip_connr->tcpstateflags = UIP_CLOSED;\r
+ UIP_LOG("tcp: got reset, aborting connection.");\r
+ uip_flags = UIP_ABORT;\r
+ UIP_APPCALL();\r
+ goto drop;\r
+ }\r
+ /* Calculated the length of the data, if the application has sent\r
+ any data to us. */\r
+ c = (BUF->tcpoffset >> 4) << 2;\r
+ /* uip_len will contain the length of the actual TCP data. This is\r
+ calculated by subtracing the length of the TCP header (in\r
+ c) and the length of the IP header (20 bytes). */\r
+ uip_len = uip_len - c - UIP_IPH_LEN;\r
+\r
+ /* First, check if the sequence number of the incoming packet is\r
+ what we're expecting next. If not, we send out an ACK with the\r
+ correct numbers in. */\r
+ if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&\r
+ ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {\r
+ if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&\r
+ (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||\r
+ BUF->seqno[1] != uip_connr->rcv_nxt[1] ||\r
+ BUF->seqno[2] != uip_connr->rcv_nxt[2] ||\r
+ BUF->seqno[3] != uip_connr->rcv_nxt[3])) {\r
+ goto tcp_send_ack;\r
+ }\r
+ }\r
+\r
+ /* Next, check if the incoming segment acknowledges any outstanding\r
+ data. If so, we update the sequence number, reset the length of\r
+ the outstanding data, calculate RTT estimations, and reset the\r
+ retransmission timer. */\r
+ if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {\r
+ uip_add32(uip_connr->snd_nxt, uip_connr->len);\r
+\r
+ if(BUF->ackno[0] == uip_acc32[0] &&\r
+ BUF->ackno[1] == uip_acc32[1] &&\r
+ BUF->ackno[2] == uip_acc32[2] &&\r
+ BUF->ackno[3] == uip_acc32[3]) {\r
+ /* Update sequence number. */\r
+ uip_connr->snd_nxt[0] = uip_acc32[0];\r
+ uip_connr->snd_nxt[1] = uip_acc32[1];\r
+ uip_connr->snd_nxt[2] = uip_acc32[2];\r
+ uip_connr->snd_nxt[3] = uip_acc32[3];\r
+\r
+\r
+ /* Do RTT estimation, unless we have done retransmissions. */\r
+ if(uip_connr->nrtx == 0) {\r
+ signed char m;\r
+ m = uip_connr->rto - uip_connr->timer;\r
+ /* This is taken directly from VJs original code in his paper */\r
+ m = m - (uip_connr->sa >> 3);\r
+ uip_connr->sa += m;\r
+ if(m < 0) {\r
+ m = -m;\r
+ }\r
+ m = m - (uip_connr->sv >> 2);\r
+ uip_connr->sv += m;\r
+ uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;\r
+\r
+ }\r
+ /* Set the acknowledged flag. */\r
+ uip_flags = UIP_ACKDATA;\r
+ /* Reset the retransmission timer. */\r
+ uip_connr->timer = uip_connr->rto;\r
+\r
+ /* Reset length of outstanding data. */\r
+ uip_connr->len = 0;\r
+ }\r
+\r
+ }\r
+\r
+ /* Do different things depending on in what state the connection is. */\r
+ switch(uip_connr->tcpstateflags & UIP_TS_MASK) {\r
+ /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not\r
+ implemented, since we force the application to close when the\r
+ peer sends a FIN (hence the application goes directly from\r
+ ESTABLISHED to LAST_ACK). */\r
+ case UIP_SYN_RCVD:\r
+ /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and\r
+ we are waiting for an ACK that acknowledges the data we sent\r
+ out the last time. Therefore, we want to have the UIP_ACKDATA\r
+ flag set. If so, we enter the ESTABLISHED state. */\r
+ if(uip_flags & UIP_ACKDATA) {\r
+ uip_connr->tcpstateflags = UIP_ESTABLISHED;\r
+ uip_flags = UIP_CONNECTED;\r
+ uip_connr->len = 0;\r
+ if(uip_len > 0) {\r
+ uip_flags |= UIP_NEWDATA;\r
+ uip_add_rcv_nxt(uip_len);\r
+ }\r
+ uip_slen = 0;\r
+ UIP_APPCALL();\r
+ goto appsend;\r
+ }\r
+ goto drop;\r
+#if UIP_ACTIVE_OPEN\r
+ case UIP_SYN_SENT:\r
+ /* In SYN_SENT, we wait for a SYNACK that is sent in response to\r
+ our SYN. The rcv_nxt is set to sequence number in the SYNACK\r
+ plus one, and we send an ACK. We move into the ESTABLISHED\r
+ state. */\r
+ if((uip_flags & UIP_ACKDATA) &&\r
+ (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {\r
+\r
+ /* Parse the TCP MSS option, if present. */\r
+ if((BUF->tcpoffset & 0xf0) > 0x50) {\r
+ for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {\r
+ opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];\r
+ if(opt == TCP_OPT_END) {\r
+ /* End of options. */\r
+ break;\r
+ } else if(opt == TCP_OPT_NOOP) {\r
+ ++c;\r
+ /* NOP option. */\r
+ } else if(opt == TCP_OPT_MSS &&\r
+ uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {\r
+ /* An MSS option with the right option length. */\r
+ tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |\r
+ uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];\r
+ uip_connr->initialmss =\r
+ uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;\r
+\r
+ /* And we are done processing options. */\r
+ break;\r
+ } else {\r
+ /* All other options have a length field, so that we easily\r
+ can skip past them. */\r
+ if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {\r
+ /* If the length field is zero, the options are malformed\r
+ and we don't process them further. */\r
+ break;\r
+ }\r
+ c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];\r
+ }\r
+ }\r
+ }\r
+ uip_connr->tcpstateflags = UIP_ESTABLISHED;\r
+ uip_connr->rcv_nxt[0] = BUF->seqno[0];\r
+ uip_connr->rcv_nxt[1] = BUF->seqno[1];\r
+ uip_connr->rcv_nxt[2] = BUF->seqno[2];\r
+ uip_connr->rcv_nxt[3] = BUF->seqno[3];\r
+ uip_add_rcv_nxt(1);\r
+ uip_flags = UIP_CONNECTED | UIP_NEWDATA;\r
+ uip_connr->len = 0;\r
+ uip_len = 0;\r
+ uip_slen = 0;\r
+ UIP_APPCALL();\r
+ goto appsend;\r
+ }\r
+ /* Inform the application that the connection failed */\r
+ uip_flags = UIP_ABORT;\r
+ UIP_APPCALL();\r
+ /* The connection is closed after we send the RST */\r
+ uip_conn->tcpstateflags = UIP_CLOSED;\r
+ goto reset;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+ case UIP_ESTABLISHED:\r
+ /* In the ESTABLISHED state, we call upon the application to feed\r
+ data into the uip_buf. If the UIP_ACKDATA flag is set, the\r
+ application should put new data into the buffer, otherwise we are\r
+ retransmitting an old segment, and the application should put that\r
+ data into the buffer.\r
+\r
+ If the incoming packet is a FIN, we should close the connection on\r
+ this side as well, and we send out a FIN and enter the LAST_ACK\r
+ state. We require that there is no outstanding data; otherwise the\r
+ sequence numbers will be screwed up. */\r
+\r
+ if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {\r
+ if(uip_outstanding(uip_connr)) {\r
+ goto drop;\r
+ }\r
+ uip_add_rcv_nxt(1 + uip_len);\r
+ uip_flags |= UIP_CLOSE;\r
+ if(uip_len > 0) {\r
+ uip_flags |= UIP_NEWDATA;\r
+ }\r
+ UIP_APPCALL();\r
+ uip_connr->len = 1;\r
+ uip_connr->tcpstateflags = UIP_LAST_ACK;\r
+ uip_connr->nrtx = 0;\r
+ tcp_send_finack:\r
+ BUF->flags = TCP_FIN | TCP_ACK;\r
+ goto tcp_send_nodata;\r
+ }\r
+\r
+ /* Check the URG flag. If this is set, the segment carries urgent\r
+ data that we must pass to the application. */\r
+ if((BUF->flags & TCP_URG) != 0) {\r
+#if UIP_URGDATA > 0\r
+ uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];\r
+ if(uip_urglen > uip_len) {\r
+ /* There is more urgent data in the next segment to come. */\r
+ uip_urglen = uip_len;\r
+ }\r
+ uip_add_rcv_nxt(uip_urglen);\r
+ uip_len -= uip_urglen;\r
+ uip_urgdata = uip_appdata;\r
+ uip_appdata += uip_urglen;\r
+ } else {\r
+ uip_urglen = 0;\r
+#else /* UIP_URGDATA > 0 */\r
+ uip_appdata = ((char *)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]);\r
+ uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];\r
+#endif /* UIP_URGDATA > 0 */\r
+ }\r
+\r
+ /* If uip_len > 0 we have TCP data in the packet, and we flag this\r
+ by setting the UIP_NEWDATA flag and update the sequence number\r
+ we acknowledge. If the application has stopped the dataflow\r
+ using uip_stop(), we must not accept any data packets from the\r
+ remote host. */\r
+ if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {\r
+ uip_flags |= UIP_NEWDATA;\r
+ uip_add_rcv_nxt(uip_len);\r
+ }\r
+\r
+ /* Check if the available buffer space advertised by the other end\r
+ is smaller than the initial MSS for this connection. If so, we\r
+ set the current MSS to the window size to ensure that the\r
+ application does not send more data than the other end can\r
+ handle.\r
+\r
+ If the remote host advertises a zero window, we set the MSS to\r
+ the initial MSS so that the application will send an entire MSS\r
+ of data. This data will not be acknowledged by the receiver,\r
+ and the application will retransmit it. This is called the\r
+ "persistent timer" and uses the retransmission mechanim.\r
+ */\r
+ tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1];\r
+ if(tmp16 > uip_connr->initialmss ||\r
+ tmp16 == 0) {\r
+ tmp16 = uip_connr->initialmss;\r
+ }\r
+ uip_connr->mss = tmp16;\r
+\r
+ /* If this packet constitutes an ACK for outstanding data (flagged\r
+ by the UIP_ACKDATA flag, we should call the application since it\r
+ might want to send more data. If the incoming packet had data\r
+ from the peer (as flagged by the UIP_NEWDATA flag), the\r
+ application must also be notified.\r
+\r
+ When the application is called, the global variable uip_len\r
+ contains the length of the incoming data. The application can\r
+ access the incoming data through the global pointer\r
+ uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN\r
+ bytes into the uip_buf array.\r
+\r
+ If the application wishes to send any data, this data should be\r
+ put into the uip_appdata and the length of the data should be\r
+ put into uip_len. If the application don't have any data to\r
+ send, uip_len must be set to 0. */\r
+ if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {\r
+ uip_slen = 0;\r
+ UIP_APPCALL();\r
+\r
+ appsend:\r
+\r
+ if(uip_flags & UIP_ABORT) {\r
+ uip_slen = 0;\r
+ uip_connr->tcpstateflags = UIP_CLOSED;\r
+ BUF->flags = TCP_RST | TCP_ACK;\r
+ goto tcp_send_nodata;\r
+ }\r
+\r
+ if(uip_flags & UIP_CLOSE) {\r
+ uip_slen = 0;\r
+ uip_connr->len = 1;\r
+ uip_connr->tcpstateflags = UIP_FIN_WAIT_1;\r
+ uip_connr->nrtx = 0;\r
+ BUF->flags = TCP_FIN | TCP_ACK;\r
+ goto tcp_send_nodata;\r
+ }\r
+\r
+ /* If uip_slen > 0, the application has data to be sent. */\r
+ if(uip_slen > 0) {\r
+\r
+ /* If the connection has acknowledged data, the contents of\r
+ the ->len variable should be discarded. */\r
+ if((uip_flags & UIP_ACKDATA) != 0) {\r
+ uip_connr->len = 0;\r
+ }\r
+\r
+ /* If the ->len variable is non-zero the connection has\r
+ already data in transit and cannot send anymore right\r
+ now. */\r
+ if(uip_connr->len == 0) {\r
+\r
+ /* The application cannot send more than what is allowed by\r
+ the mss (the minumum of the MSS and the available\r
+ window). */\r
+ if(uip_slen > uip_connr->mss) {\r
+ uip_slen = uip_connr->mss;\r
+ }\r
+\r
+ /* Remember how much data we send out now so that we know\r
+ when everything has been acknowledged. */\r
+ uip_connr->len = uip_slen;\r
+ } else {\r
+\r
+ /* If the application already had unacknowledged data, we\r
+ make sure that the application does not send (i.e.,\r
+ retransmit) out more than it previously sent out. */\r
+ uip_slen = uip_connr->len;\r
+ }\r
+ }\r
+ uip_connr->nrtx = 0;\r
+ apprexmit:\r
+ uip_appdata = uip_sappdata;\r
+\r
+ /* If the application has data to be sent, or if the incoming\r
+ packet had new data in it, we must send out a packet. */\r
+ if(uip_slen > 0 && uip_connr->len > 0) {\r
+ /* Add the length of the IP and TCP headers. */\r
+ uip_len = uip_connr->len + UIP_TCPIP_HLEN;\r
+ /* We always set the ACK flag in response packets. */\r
+ BUF->flags = TCP_ACK | TCP_PSH;\r
+ /* Send the packet. */\r
+ goto tcp_send_noopts;\r
+ }\r
+ /* If there is no data to send, just send out a pure ACK if\r
+ there is newdata. */\r
+ if(uip_flags & UIP_NEWDATA) {\r
+ uip_len = UIP_TCPIP_HLEN;\r
+ BUF->flags = TCP_ACK;\r
+ goto tcp_send_noopts;\r
+ }\r
+ }\r
+ goto drop;\r
+ case UIP_LAST_ACK:\r
+ /* We can close this connection if the peer has acknowledged our\r
+ FIN. This is indicated by the UIP_ACKDATA flag. */\r
+ if(uip_flags & UIP_ACKDATA) {\r
+ uip_connr->tcpstateflags = UIP_CLOSED;\r
+ uip_flags = UIP_CLOSE;\r
+ UIP_APPCALL();\r
+ }\r
+ break;\r
+\r
+ case UIP_FIN_WAIT_1:\r
+ /* The application has closed the connection, but the remote host\r
+ hasn't closed its end yet. Thus we do nothing but wait for a\r
+ FIN from the other side. */\r
+ if(uip_len > 0) {\r
+ uip_add_rcv_nxt(uip_len);\r
+ }\r
+ if(BUF->flags & TCP_FIN) {\r
+ if(uip_flags & UIP_ACKDATA) {\r
+ uip_connr->tcpstateflags = UIP_TIME_WAIT;\r
+ uip_connr->timer = 0;\r
+ uip_connr->len = 0;\r
+ } else {\r
+ uip_connr->tcpstateflags = UIP_CLOSING;\r
+ }\r
+ uip_add_rcv_nxt(1);\r
+ uip_flags = UIP_CLOSE;\r
+ UIP_APPCALL();\r
+ goto tcp_send_ack;\r
+ } else if(uip_flags & UIP_ACKDATA) {\r
+ uip_connr->tcpstateflags = UIP_FIN_WAIT_2;\r
+ uip_connr->len = 0;\r
+ goto drop;\r
+ }\r
+ if(uip_len > 0) {\r
+ goto tcp_send_ack;\r
+ }\r
+ goto drop;\r
+\r
+ case UIP_FIN_WAIT_2:\r
+ if(uip_len > 0) {\r
+ uip_add_rcv_nxt(uip_len);\r
+ }\r
+ if(BUF->flags & TCP_FIN) {\r
+ uip_connr->tcpstateflags = UIP_TIME_WAIT;\r
+ uip_connr->timer = 0;\r
+ uip_add_rcv_nxt(1);\r
+ uip_flags = UIP_CLOSE;\r
+ UIP_APPCALL();\r
+ goto tcp_send_ack;\r
+ }\r
+ if(uip_len > 0) {\r
+ goto tcp_send_ack;\r
+ }\r
+ goto drop;\r
+\r
+ case UIP_TIME_WAIT:\r
+ goto tcp_send_ack;\r
+\r
+ case UIP_CLOSING:\r
+ if(uip_flags & UIP_ACKDATA) {\r
+ uip_connr->tcpstateflags = UIP_TIME_WAIT;\r
+ uip_connr->timer = 0;\r
+ }\r
+ }\r
+ goto drop;\r
+\r
+\r
+ /* We jump here when we are ready to send the packet, and just want\r
+ to set the appropriate TCP sequence numbers in the TCP header. */\r
+ tcp_send_ack:\r
+ BUF->flags = TCP_ACK;\r
+ tcp_send_nodata:\r
+ uip_len = UIP_IPTCPH_LEN;\r
+ tcp_send_noopts:\r
+ BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;\r
+ tcp_send:\r
+ /* We're done with the input processing. We are now ready to send a\r
+ reply. Our job is to fill in all the fields of the TCP and IP\r
+ headers before calculating the checksum and finally send the\r
+ packet. */\r
+ BUF->ackno[0] = uip_connr->rcv_nxt[0];\r
+ BUF->ackno[1] = uip_connr->rcv_nxt[1];\r
+ BUF->ackno[2] = uip_connr->rcv_nxt[2];\r
+ BUF->ackno[3] = uip_connr->rcv_nxt[3];\r
+\r
+ BUF->seqno[0] = uip_connr->snd_nxt[0];\r
+ BUF->seqno[1] = uip_connr->snd_nxt[1];\r
+ BUF->seqno[2] = uip_connr->snd_nxt[2];\r
+ BUF->seqno[3] = uip_connr->snd_nxt[3];\r
+\r
+ BUF->proto = UIP_PROTO_TCP;\r
+\r
+ BUF->srcport = uip_connr->lport;\r
+ BUF->destport = uip_connr->rport;\r
+\r
+ uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);\r
+ uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr);\r
+\r
+ if(uip_connr->tcpstateflags & UIP_STOPPED) {\r
+ /* If the connection has issued uip_stop(), we advertise a zero\r
+ window so that the remote host will stop sending data. */\r
+ BUF->wnd[0] = BUF->wnd[1] = 0;\r
+ } else {\r
+ BUF->wnd[0] = ((UIP_RECEIVE_WINDOW) >> 8);\r
+ BUF->wnd[1] = ((UIP_RECEIVE_WINDOW) & 0xff);\r
+ }\r
+\r
+ tcp_send_noconn:\r
+ BUF->ttl = UIP_TTL;\r
+#if UIP_CONF_IPV6\r
+ /* For IPv6, the IP length field does not include the IPv6 IP header\r
+ length. */\r
+ BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);\r
+ BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);\r
+#else /* UIP_CONF_IPV6 */\r
+ BUF->len[0] = (uip_len >> 8);\r
+ BUF->len[1] = (uip_len & 0xff);\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ BUF->urgp[0] = BUF->urgp[1] = 0;\r
+\r
+ /* Calculate TCP checksum. */\r
+ BUF->tcpchksum = 0;\r
+ BUF->tcpchksum = ~(uip_tcpchksum());\r
+\r
+#if UIP_UDP\r
+ ip_send_nolen:\r
+#endif /* UIP_UDP */\r
+\r
+#if UIP_CONF_IPV6\r
+ BUF->vtc = 0x60;\r
+ BUF->tcflow = 0x00;\r
+ BUF->flow = 0x00;\r
+#else /* UIP_CONF_IPV6 */\r
+ BUF->vhl = 0x45;\r
+ BUF->tos = 0;\r
+ BUF->ipoffset[0] = BUF->ipoffset[1] = 0;\r
+ ++ipid;\r
+ BUF->ipid[0] = ipid >> 8;\r
+ BUF->ipid[1] = ipid & 0xff;\r
+ /* Calculate IP checksum. */\r
+ BUF->ipchksum = 0;\r
+ BUF->ipchksum = ~(uip_ipchksum());\r
+ DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ UIP_STAT(++uip_stat.tcp.sent);\r
+ send:\r
+ DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,\r
+ (BUF->len[0] << 8) | BUF->len[1]);\r
+\r
+ UIP_STAT(++uip_stat.ip.sent);\r
+ /* Return and let the caller do the actual transmission. */\r
+ uip_flags = 0;\r
+ return;\r
+ drop:\r
+ uip_len = 0;\r
+ uip_flags = 0;\r
+ return;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+htons(u16_t val)\r
+{\r
+ return HTONS(val);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_send(const void *data, int len)\r
+{\r
+ if(len > 0) {\r
+ uip_slen = len;\r
+ if(data != uip_sappdata) {\r
+ memcpy(uip_sappdata, (data), uip_slen);\r
+ }\r
+ }\r
+}\r
+/** @} */\r
--- /dev/null
+\r
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Header file for the uIP TCP/IP stack.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ *\r
+ * The uIP TCP/IP stack header file contains definitions for a number\r
+ * of C macros that are used by uIP programs as well as internal uIP\r
+ * structures, TCP/IP header structures and function declarations.\r
+ *\r
+ */\r
+\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip.h,v 1.40 2006/06/08 07:12:07 adam Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIP_H__\r
+#define __UIP_H__\r
+\r
+#include "uipopt.h"\r
+\r
+/**\r
+ * Repressentation of an IP address.\r
+ *\r
+ */\r
+typedef u16_t uip_ip4addr_t[2];\r
+typedef u16_t uip_ip6addr_t[8];\r
+#if UIP_CONF_IPV6\r
+typedef uip_ip6addr_t uip_ipaddr_t;\r
+#else /* UIP_CONF_IPV6 */\r
+typedef uip_ip4addr_t uip_ipaddr_t;\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* First, the functions that should be called from the\r
+ * system. Initialization, the periodic timer and incoming packets are\r
+ * handled by the following three functions.\r
+ */\r
+\r
+/**\r
+ * \defgroup uipconffunc uIP configuration functions\r
+ * @{\r
+ *\r
+ * The uIP configuration functions are used for setting run-time\r
+ * parameters in uIP such as IP addresses.\r
+ */\r
+\r
+/**\r
+ * Set the IP address of this host.\r
+ *\r
+ * The IP address is represented as a 4-byte array where the first\r
+ * octet of the IP address is put in the first member of the 4-byte\r
+ * array.\r
+ *\r
+ * Example:\r
+ \code\r
+\r
+ uip_ipaddr_t addr;\r
+\r
+ uip_ipaddr(&addr, 192,168,1,2);\r
+ uip_sethostaddr(&addr);\r
+\r
+ \endcode\r
+ * \param addr A pointer to an IP address of type uip_ipaddr_t;\r
+ *\r
+ * \sa uip_ipaddr()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr))\r
+\r
+/**\r
+ * Get the IP address of this host.\r
+ *\r
+ * The IP address is represented as a 4-byte array where the first\r
+ * octet of the IP address is put in the first member of the 4-byte\r
+ * array.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t hostaddr;\r
+\r
+ uip_gethostaddr(&hostaddr);\r
+ \endcode\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the currently configured IP address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr)\r
+\r
+/**\r
+ * Set the default router's IP address.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable containing the IP\r
+ * address of the default router.\r
+ *\r
+ * \sa uip_ipaddr()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))\r
+\r
+/**\r
+ * Set the netmask.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable containing the IP\r
+ * address of the netmask.\r
+ *\r
+ * \sa uip_ipaddr()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr))\r
+\r
+\r
+/**\r
+ * Get the default router's IP address.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the IP address of the default router.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)\r
+\r
+/**\r
+ * Get the netmask.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the value of the netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask)\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \defgroup uipinit uIP initialization functions\r
+ * @{\r
+ *\r
+ * The uIP initialization functions are used for booting uIP.\r
+ */\r
+\r
+/**\r
+ * uIP initialization function.\r
+ *\r
+ * This function should be called at boot up to initilize the uIP\r
+ * TCP/IP stack.\r
+ */\r
+void uip_init(void);\r
+\r
+/**\r
+ * uIP initialization function.\r
+ *\r
+ * This function may be used at boot time to set the initial ip_id.\r
+ */\r
+void uip_setipid(u16_t id);\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \defgroup uipdevfunc uIP device driver functions\r
+ * @{\r
+ *\r
+ * These functions are used by a network device driver for interacting\r
+ * with uIP.\r
+ */\r
+\r
+/**\r
+ * Process an incoming packet.\r
+ *\r
+ * This function should be called when the device driver has received\r
+ * a packet from the network. The packet from the device driver must\r
+ * be present in the uip_buf buffer, and the length of the packet\r
+ * should be placed in the uip_len variable.\r
+ *\r
+ * When the function returns, there may be an outbound packet placed\r
+ * in the uip_buf packet buffer. If so, the uip_len variable is set to\r
+ * the length of the packet. If no packet is to be sent out, the\r
+ * uip_len variable is set to 0.\r
+ *\r
+ * The usual way of calling the function is presented by the source\r
+ * code below.\r
+ \code\r
+ uip_len = devicedriver_poll();\r
+ if(uip_len > 0) {\r
+ uip_input();\r
+ if(uip_len > 0) {\r
+ devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \note If you are writing a uIP device driver that needs ARP\r
+ * (Address Resolution Protocol), e.g., when running uIP over\r
+ * Ethernet, you will need to call the uIP ARP code before calling\r
+ * this function:\r
+ \code\r
+ #define BUF ((struct uip_eth_hdr *)&uip_buf[0])\r
+ uip_len = ethernet_devicedrver_poll();\r
+ if(uip_len > 0) {\r
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {\r
+ uip_arp_ipin();\r
+ uip_input();\r
+ if(uip_len > 0) {\r
+ uip_arp_out();\r
+ ethernet_devicedriver_send();\r
+ }\r
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {\r
+ uip_arp_arpin();\r
+ if(uip_len > 0) {\r
+ ethernet_devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_input() uip_process(UIP_DATA)\r
+\r
+/**\r
+ * Periodic processing for a connection identified by its number.\r
+ *\r
+ * This function does the necessary periodic processing (timers,\r
+ * polling) for a uIP TCP conneciton, and should be called when the\r
+ * periodic uIP timer goes off. It should be called for every\r
+ * connection, regardless of whether they are open of closed.\r
+ *\r
+ * When the function returns, it may have an outbound packet waiting\r
+ * for service in the uIP packet buffer, and if so the uip_len\r
+ * variable is set to a value larger than zero. The device driver\r
+ * should be called to send out the packet.\r
+ *\r
+ * The ususal way of calling the function is through a for() loop like\r
+ * this:\r
+ \code\r
+ for(i = 0; i < UIP_CONNS; ++i) {\r
+ uip_periodic(i);\r
+ if(uip_len > 0) {\r
+ devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \note If you are writing a uIP device driver that needs ARP\r
+ * (Address Resolution Protocol), e.g., when running uIP over\r
+ * Ethernet, you will need to call the uip_arp_out() function before\r
+ * calling the device driver:\r
+ \code\r
+ for(i = 0; i < UIP_CONNS; ++i) {\r
+ uip_periodic(i);\r
+ if(uip_len > 0) {\r
+ uip_arp_out();\r
+ ethernet_devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \param conn The number of the connection which is to be periodically polled.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \\r
+ uip_process(UIP_TIMER); } while (0)\r
+\r
+/**\r
+ *\r
+ *\r
+ */\r
+#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)\r
+\r
+/**\r
+ * Perform periodic processing for a connection identified by a pointer\r
+ * to its structure.\r
+ *\r
+ * Same as uip_periodic() but takes a pointer to the actual uip_conn\r
+ * struct instead of an integer as its argument. This function can be\r
+ * used to force periodic processing of a specific connection.\r
+ *\r
+ * \param conn A pointer to the uip_conn struct for the connection to\r
+ * be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_periodic_conn(conn) do { uip_conn = conn; \\r
+ uip_process(UIP_TIMER); } while (0)\r
+\r
+/**\r
+ * Reuqest that a particular connection should be polled.\r
+ *\r
+ * Similar to uip_periodic_conn() but does not perform any timer\r
+ * processing. The application is polled for new data.\r
+ *\r
+ * \param conn A pointer to the uip_conn struct for the connection to\r
+ * be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_poll_conn(conn) do { uip_conn = conn; \\r
+ uip_process(UIP_POLL_REQUEST); } while (0)\r
+\r
+\r
+#if UIP_UDP\r
+/**\r
+ * Periodic processing for a UDP connection identified by its number.\r
+ *\r
+ * This function is essentially the same as uip_periodic(), but for\r
+ * UDP connections. It is called in a similar fashion as the\r
+ * uip_periodic() function:\r
+ \code\r
+ for(i = 0; i < UIP_UDP_CONNS; i++) {\r
+ uip_udp_periodic(i);\r
+ if(uip_len > 0) {\r
+ devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \note As for the uip_periodic() function, special care has to be\r
+ * taken when using uIP together with ARP and Ethernet:\r
+ \code\r
+ for(i = 0; i < UIP_UDP_CONNS; i++) {\r
+ uip_udp_periodic(i);\r
+ if(uip_len > 0) {\r
+ uip_arp_out();\r
+ ethernet_devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \param conn The number of the UDP connection to be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \\r
+ uip_process(UIP_UDP_TIMER); } while (0)\r
+\r
+/**\r
+ * Periodic processing for a UDP connection identified by a pointer to\r
+ * its structure.\r
+ *\r
+ * Same as uip_udp_periodic() but takes a pointer to the actual\r
+ * uip_conn struct instead of an integer as its argument. This\r
+ * function can be used to force periodic processing of a specific\r
+ * connection.\r
+ *\r
+ * \param conn A pointer to the uip_udp_conn struct for the connection\r
+ * to be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \\r
+ uip_process(UIP_UDP_TIMER); } while (0)\r
+\r
+\r
+#endif /* UIP_UDP */\r
+\r
+/**\r
+ * The uIP packet buffer.\r
+ *\r
+ * The uip_buf array is used to hold incoming and outgoing\r
+ * packets. The device driver should place incoming data into this\r
+ * buffer. When sending data, the device driver should read the link\r
+ * level headers and the TCP/IP headers from this buffer. The size of\r
+ * the link level headers is configured by the UIP_LLH_LEN define.\r
+ *\r
+ * \note The application data need not be placed in this buffer, so\r
+ * the device driver must read it from the place pointed to by the\r
+ * uip_appdata pointer as illustrated by the following example:\r
+ \code\r
+ void\r
+ devicedriver_send(void)\r
+ {\r
+ hwsend(&uip_buf[0], UIP_LLH_LEN);\r
+ if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {\r
+ hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);\r
+ } else {\r
+ hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);\r
+ hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);\r
+ }\r
+ }\r
+ \endcode\r
+ */\r
+#ifndef UIP_CONF_EXTERNAL_BUFFER\r
+ extern u8_t uip_buf[UIP_BUFSIZE+2];\r
+#else\r
+ extern unsigned char *uip_buf;\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* Functions that are used by the uIP application program. Opening and\r
+ * closing connections, sending and receiving data, etc. is all\r
+ * handled by the functions below.\r
+*/\r
+/**\r
+ * \defgroup uipappfunc uIP application functions\r
+ * @{\r
+ *\r
+ * Functions used by an application running of top of uIP.\r
+ */\r
+\r
+/**\r
+ * Start listening to the specified port.\r
+ *\r
+ * \note Since this function expects the port number in network byte\r
+ * order, a conversion using HTONS() or htons() is necessary.\r
+ *\r
+ \code\r
+ uip_listen(HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param port A 16-bit port number in network byte order.\r
+ */\r
+void uip_listen(u16_t port);\r
+\r
+/**\r
+ * Stop listening to the specified port.\r
+ *\r
+ * \note Since this function expects the port number in network byte\r
+ * order, a conversion using HTONS() or htons() is necessary.\r
+ *\r
+ \code\r
+ uip_unlisten(HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param port A 16-bit port number in network byte order.\r
+ */\r
+void uip_unlisten(u16_t port);\r
+\r
+/**\r
+ * Connect to a remote host using TCP.\r
+ *\r
+ * This function is used to start a new connection to the specified\r
+ * port on the specied host. It allocates a new connection identifier,\r
+ * sets the connection to the SYN_SENT state and sets the\r
+ * retransmission timer to 0. This will cause a TCP SYN segment to be\r
+ * sent out the next time this connection is periodically processed,\r
+ * which usually is done within 0.5 seconds after the call to\r
+ * uip_connect().\r
+ *\r
+ * \note This function is avaliable only if support for active open\r
+ * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.\r
+ *\r
+ * \note Since this function requires the port number to be in network\r
+ * byte order, a conversion using HTONS() or htons() is necessary.\r
+ *\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+\r
+ uip_ipaddr(&ipaddr, 192,168,1,2);\r
+ uip_connect(&ipaddr, HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param ripaddr The IP address of the remote hot.\r
+ *\r
+ * \param port A 16-bit port number in network byte order.\r
+ *\r
+ * \return A pointer to the uIP connection identifier for the new connection,\r
+ * or NULL if no connection could be allocated.\r
+ *\r
+ */\r
+struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port);\r
+\r
+\r
+\r
+/**\r
+ * \internal\r
+ *\r
+ * Check if a connection has outstanding (i.e., unacknowledged) data.\r
+ *\r
+ * \param conn A pointer to the uip_conn structure for the connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_outstanding(conn) ((conn)->len)\r
+\r
+/**\r
+ * Send data on the current connection.\r
+ *\r
+ * This function is used to send out a single segment of TCP\r
+ * data. Only applications that have been invoked by uIP for event\r
+ * processing can send data.\r
+ *\r
+ * The amount of data that actually is sent out after a call to this\r
+ * funcion is determined by the maximum amount of data TCP allows. uIP\r
+ * will automatically crop the data so that only the appropriate\r
+ * amount of data is sent. The function uip_mss() can be used to query\r
+ * uIP for the amount of data that actually will be sent.\r
+ *\r
+ * \note This function does not guarantee that the sent data will\r
+ * arrive at the destination. If the data is lost in the network, the\r
+ * application will be invoked with the uip_rexmit() event being\r
+ * set. The application will then have to resend the data using this\r
+ * function.\r
+ *\r
+ * \param data A pointer to the data which is to be sent.\r
+ *\r
+ * \param len The maximum amount of data bytes to be sent.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+void uip_send(const void *data, int len);\r
+\r
+/**\r
+ * The length of any incoming data that is currently avaliable (if avaliable)\r
+ * in the uip_appdata buffer.\r
+ *\r
+ * The test function uip_data() must first be used to check if there\r
+ * is any data available at all.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+/*void uip_datalen(void);*/\r
+#define uip_datalen() uip_len\r
+\r
+/**\r
+ * The length of any out-of-band data (urgent data) that has arrived\r
+ * on the connection.\r
+ *\r
+ * \note The configuration parameter UIP_URGDATA must be set for this\r
+ * function to be enabled.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_urgdatalen() uip_urglen\r
+\r
+/**\r
+ * Close the current connection.\r
+ *\r
+ * This function will close the current connection in a nice way.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_close() (uip_flags = UIP_CLOSE)\r
+\r
+/**\r
+ * Abort the current connection.\r
+ *\r
+ * This function will abort (reset) the current connection, and is\r
+ * usually used when an error has occured that prevents using the\r
+ * uip_close() function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_abort() (uip_flags = UIP_ABORT)\r
+\r
+/**\r
+ * Tell the sending host to stop sending data.\r
+ *\r
+ * This function will close our receiver's window so that we stop\r
+ * receiving data for the current connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)\r
+\r
+/**\r
+ * Find out if the current connection has been previously stopped with\r
+ * uip_stop().\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)\r
+\r
+/**\r
+ * Restart the current connection, if is has previously been stopped\r
+ * with uip_stop().\r
+ *\r
+ * This function will open the receiver's window again so that we\r
+ * start receiving data for the current connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_restart() do { uip_flags |= UIP_NEWDATA; \\r
+ uip_conn->tcpstateflags &= ~UIP_STOPPED; \\r
+ } while(0)\r
+\r
+\r
+/* uIP tests that can be made to determine in what state the current\r
+ connection is, and what the application function should do. */\r
+\r
+/**\r
+ * Is the current connection a UDP connection?\r
+ *\r
+ * This function checks whether the current connection is a UDP connection.\r
+ *\r
+ * \hideinitializer\r
+ *\r
+ */\r
+#define uip_udpconnection() (uip_conn == NULL)\r
+\r
+/**\r
+ * Is new incoming data available?\r
+ *\r
+ * Will reduce to non-zero if there is new data for the application\r
+ * present at the uip_appdata pointer. The size of the data is\r
+ * avaliable through the uip_len variable.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_newdata() (uip_flags & UIP_NEWDATA)\r
+\r
+/**\r
+ * Has previously sent data been acknowledged?\r
+ *\r
+ * Will reduce to non-zero if the previously sent data has been\r
+ * acknowledged by the remote host. This means that the application\r
+ * can send new data.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_acked() (uip_flags & UIP_ACKDATA)\r
+\r
+/**\r
+ * Has the connection just been connected?\r
+ *\r
+ * Reduces to non-zero if the current connection has been connected to\r
+ * a remote host. This will happen both if the connection has been\r
+ * actively opened (with uip_connect()) or passively opened (with\r
+ * uip_listen()).\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_connected() (uip_flags & UIP_CONNECTED)\r
+\r
+/**\r
+ * Has the connection been closed by the other end?\r
+ *\r
+ * Is non-zero if the connection has been closed by the remote\r
+ * host. The application may then do the necessary clean-ups.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_closed() (uip_flags & UIP_CLOSE)\r
+\r
+/**\r
+ * Has the connection been aborted by the other end?\r
+ *\r
+ * Non-zero if the current connection has been aborted (reset) by the\r
+ * remote host.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_aborted() (uip_flags & UIP_ABORT)\r
+\r
+/**\r
+ * Has the connection timed out?\r
+ *\r
+ * Non-zero if the current connection has been aborted due to too many\r
+ * retransmissions.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_timedout() (uip_flags & UIP_TIMEDOUT)\r
+\r
+/**\r
+ * Do we need to retransmit previously data?\r
+ *\r
+ * Reduces to non-zero if the previously sent data has been lost in\r
+ * the network, and the application should retransmit it. The\r
+ * application should send the exact same data as it did the last\r
+ * time, using the uip_send() function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_rexmit() (uip_flags & UIP_REXMIT)\r
+\r
+/**\r
+ * Is the connection being polled by uIP?\r
+ *\r
+ * Is non-zero if the reason the application is invoked is that the\r
+ * current connection has been idle for a while and should be\r
+ * polled.\r
+ *\r
+ * The polling event can be used for sending data without having to\r
+ * wait for the remote host to send data.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_poll() (uip_flags & UIP_POLL)\r
+\r
+/**\r
+ * Get the initial maxium segment size (MSS) of the current\r
+ * connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_initialmss() (uip_conn->initialmss)\r
+\r
+/**\r
+ * Get the current maxium segment size that can be sent on the current\r
+ * connection.\r
+ *\r
+ * The current maxiumum segment size that can be sent on the\r
+ * connection is computed from the receiver's window and the MSS of\r
+ * the connection (which also is available by calling\r
+ * uip_initialmss()).\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_mss() (uip_conn->mss)\r
+\r
+/**\r
+ * Set up a new UDP connection.\r
+ *\r
+ * This function sets up a new UDP connection. The function will\r
+ * automatically allocate an unused local port for the new\r
+ * connection. However, another port can be chosen by using the\r
+ * uip_udp_bind() call, after the uip_udp_new() function has been\r
+ * called.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t addr;\r
+ struct uip_udp_conn *c;\r
+\r
+ uip_ipaddr(&addr, 192,168,2,1);\r
+ c = uip_udp_new(&addr, HTONS(12345));\r
+ if(c != NULL) {\r
+ uip_udp_bind(c, HTONS(12344));\r
+ }\r
+ \endcode\r
+ * \param ripaddr The IP address of the remote host.\r
+ *\r
+ * \param rport The remote port number in network byte order.\r
+ *\r
+ * \return The uip_udp_conn structure for the new connection or NULL\r
+ * if no connection could be allocated.\r
+ */\r
+struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);\r
+\r
+/**\r
+ * Removed a UDP connection.\r
+ *\r
+ * \param conn A pointer to the uip_udp_conn structure for the connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_remove(conn) (conn)->lport = 0\r
+\r
+/**\r
+ * Bind a UDP connection to a local port.\r
+ *\r
+ * \param conn A pointer to the uip_udp_conn structure for the\r
+ * connection.\r
+ *\r
+ * \param port The local port number, in network byte order.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_bind(conn, port) (conn)->lport = port\r
+\r
+/**\r
+ * Send a UDP datagram of length len on the current connection.\r
+ *\r
+ * This function can only be called in response to a UDP event (poll\r
+ * or newdata). The data must be present in the uip_buf buffer, at the\r
+ * place pointed to by the uip_appdata pointer.\r
+ *\r
+ * \param len The length of the data in the uip_buf buffer.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_send(len) uip_send((char *)uip_appdata, len)\r
+\r
+/** @} */\r
+\r
+/* uIP convenience and converting functions. */\r
+\r
+/**\r
+ * \defgroup uipconvfunc uIP conversion functions\r
+ * @{\r
+ *\r
+ * These functions can be used for converting between different data\r
+ * formats used by uIP.\r
+ */\r
+\r
+/**\r
+ * Construct an IP address from four bytes.\r
+ *\r
+ * This function constructs an IP address of the type that uIP handles\r
+ * internally from four bytes. The function is handy for specifying IP\r
+ * addresses to use with e.g. the uip_connect() function.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ struct uip_conn *c;\r
+\r
+ uip_ipaddr(&ipaddr, 192,168,1,2);\r
+ c = uip_connect(&ipaddr, HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the IP address.\r
+ *\r
+ * \param addr0 The first octet of the IP address.\r
+ * \param addr1 The second octet of the IP address.\r
+ * \param addr2 The third octet of the IP address.\r
+ * \param addr3 The forth octet of the IP address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \\r
+ ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \\r
+ ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \\r
+ } while(0)\r
+\r
+/**\r
+ * Construct an IPv6 address from eight 16-bit words.\r
+ *\r
+ * This function constructs an IPv6 address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \\r
+ ((u16_t *)(addr))[0] = HTONS((addr0)); \\r
+ ((u16_t *)(addr))[1] = HTONS((addr1)); \\r
+ ((u16_t *)(addr))[2] = HTONS((addr2)); \\r
+ ((u16_t *)(addr))[3] = HTONS((addr3)); \\r
+ ((u16_t *)(addr))[4] = HTONS((addr4)); \\r
+ ((u16_t *)(addr))[5] = HTONS((addr5)); \\r
+ ((u16_t *)(addr))[6] = HTONS((addr6)); \\r
+ ((u16_t *)(addr))[7] = HTONS((addr7)); \\r
+ } while(0)\r
+\r
+/**\r
+ * Copy an IP address to another IP address.\r
+ *\r
+ * Copies an IP address from one place to another.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2;\r
+\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ uip_ipaddr_copy(&ipaddr2, &ipaddr1);\r
+ \endcode\r
+ *\r
+ * \param dest The destination for the copy.\r
+ * \param src The source from where to copy.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#if !UIP_CONF_IPV6\r
+#define uip_ipaddr_copy(dest, src) do { \\r
+ ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \\r
+ ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \\r
+ } while(0)\r
+#else /* !UIP_CONF_IPV6 */\r
+#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t))\r
+#endif /* !UIP_CONF_IPV6 */\r
+\r
+/**\r
+ * Compare two IP addresses\r
+ *\r
+ * Compares two IP addresses.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2;\r
+\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {\r
+ printf("They are the same");\r
+ }\r
+ \endcode\r
+ *\r
+ * \param addr1 The first IP address.\r
+ * \param addr2 The second IP address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#if !UIP_CONF_IPV6\r
+#define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \\r
+ ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1])\r
+#else /* !UIP_CONF_IPV6 */\r
+#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)\r
+#endif /* !UIP_CONF_IPV6 */\r
+\r
+/**\r
+ * Compare two IP addresses with netmasks\r
+ *\r
+ * Compares two IP addresses with netmasks. The masks are used to mask\r
+ * out the bits that are to be compared.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2, mask;\r
+\r
+ uip_ipaddr(&mask, 255,255,255,0);\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ uip_ipaddr(&ipaddr2, 192,16,1,3);\r
+ if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {\r
+ printf("They are the same");\r
+ }\r
+ \endcode\r
+ *\r
+ * \param addr1 The first IP address.\r
+ * \param addr2 The second IP address.\r
+ * \param mask The netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr_maskcmp(addr1, addr2, mask) \\r
+ (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \\r
+ (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \\r
+ ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \\r
+ (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))\r
+\r
+\r
+/**\r
+ * Mask out the network part of an IP address.\r
+ *\r
+ * Masks out the network part of an IP address, given the address and\r
+ * the netmask.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2, netmask;\r
+\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ uip_ipaddr(&netmask, 255,255,255,0);\r
+ uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "ipaddr2" will contain the IP\r
+ * address 192.168.1.0.\r
+ *\r
+ * \param dest Where the result is to be placed.\r
+ * \param src The IP address.\r
+ * \param mask The netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr_mask(dest, src, mask) do { \\r
+ ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \\r
+ ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \\r
+ } while(0)\r
+\r
+/**\r
+ * Pick the first octet of an IP address.\r
+ *\r
+ * Picks out the first octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr1(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 1.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8)\r
+\r
+/**\r
+ * Pick the second octet of an IP address.\r
+ *\r
+ * Picks out the second octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr2(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 2.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff)\r
+\r
+/**\r
+ * Pick the third octet of an IP address.\r
+ *\r
+ * Picks out the third octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr3(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 3.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8)\r
+\r
+/**\r
+ * Pick the fourth octet of an IP address.\r
+ *\r
+ * Picks out the fourth octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr4(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 4.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff)\r
+\r
+/**\r
+ * Convert 16-bit quantity from host byte order to network byte order.\r
+ *\r
+ * This macro is primarily used for converting constants from host\r
+ * byte order to network byte order. For converting variables to\r
+ * network byte order, use the htons() function instead.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef HTONS\r
+# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN\r
+# define HTONS(n) (n)\r
+# else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */\r
+# define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))\r
+# endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */\r
+#else\r
+#error "HTONS already defined!"\r
+#endif /* HTONS */\r
+\r
+/**\r
+ * Convert 16-bit quantity from host byte order to network byte order.\r
+ *\r
+ * This function is primarily used for converting variables from host\r
+ * byte order to network byte order. For converting constants to\r
+ * network byte order, use the HTONS() macro instead.\r
+ */\r
+#ifndef htons\r
+u16_t htons(u16_t val);\r
+#endif /* htons */\r
+#ifndef ntohs\r
+#define ntohs htons\r
+#endif\r
+\r
+/** @} */\r
+\r
+/**\r
+ * Pointer to the application data in the packet buffer.\r
+ *\r
+ * This pointer points to the application data when the application is\r
+ * called. If the application wishes to send data, the application may\r
+ * use this space to write the data into before calling uip_send().\r
+ */\r
+extern void *uip_appdata;\r
+\r
+#if UIP_URGDATA > 0\r
+/* u8_t *uip_urgdata:\r
+ *\r
+ * This pointer points to any urgent data that has been received. Only\r
+ * present if compiled with support for urgent data (UIP_URGDATA).\r
+ */\r
+extern void *uip_urgdata;\r
+#endif /* UIP_URGDATA > 0 */\r
+\r
+\r
+/**\r
+ * \defgroup uipdrivervars Variables used in uIP device drivers\r
+ * @{\r
+ *\r
+ * uIP has a few global variables that are used in device drivers for\r
+ * uIP.\r
+ */\r
+\r
+/**\r
+ * The length of the packet in the uip_buf buffer.\r
+ *\r
+ * The global variable uip_len holds the length of the packet in the\r
+ * uip_buf buffer.\r
+ *\r
+ * When the network device driver calls the uIP input function,\r
+ * uip_len should be set to the length of the packet in the uip_buf\r
+ * buffer.\r
+ *\r
+ * When sending packets, the device driver should use the contents of\r
+ * the uip_len variable to determine the length of the outgoing\r
+ * packet.\r
+ *\r
+ */\r
+extern u16_t uip_len;\r
+\r
+/** @} */\r
+\r
+#if UIP_URGDATA > 0\r
+extern u16_t uip_urglen, uip_surglen;\r
+#endif /* UIP_URGDATA > 0 */\r
+\r
+\r
+/**\r
+ * Representation of a uIP TCP connection.\r
+ *\r
+ * The uip_conn structure is used for identifying a connection. All\r
+ * but one field in the structure are to be considered read-only by an\r
+ * application. The only exception is the appstate field whos purpose\r
+ * is to let the application store application-specific state (e.g.,\r
+ * file pointers) for the connection. The type of this field is\r
+ * configured in the "uipopt.h" header file.\r
+ */\r
+struct uip_conn {\r
+ uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */\r
+\r
+ u16_t lport; /**< The local TCP port, in network byte order. */\r
+ u16_t rport; /**< The local remote TCP port, in network byte\r
+ order. */\r
+\r
+ u8_t rcv_nxt[4]; /**< The sequence number that we expect to\r
+ receive next. */\r
+ u8_t snd_nxt[4]; /**< The sequence number that was last sent by\r
+ us. */\r
+ u16_t len; /**< Length of the data that was previously sent. */\r
+ u16_t mss; /**< Current maximum segment size for the\r
+ connection. */\r
+ u16_t initialmss; /**< Initial maximum segment size for the\r
+ connection. */\r
+ u8_t sa; /**< Retransmission time-out calculation state\r
+ variable. */\r
+ u8_t sv; /**< Retransmission time-out calculation state\r
+ variable. */\r
+ u8_t rto; /**< Retransmission time-out. */\r
+ u8_t tcpstateflags; /**< TCP state and flags. */\r
+ u8_t timer; /**< The retransmission timer. */\r
+ u8_t nrtx; /**< The number of retransmissions for the last\r
+ segment sent. */\r
+\r
+ /** The application state. */\r
+ uip_tcp_appstate_t appstate;\r
+};\r
+\r
+\r
+/**\r
+ * Pointer to the current TCP connection.\r
+ *\r
+ * The uip_conn pointer can be used to access the current TCP\r
+ * connection.\r
+ */\r
+extern struct uip_conn *uip_conn;\r
+/* The array containing all uIP connections. */\r
+extern struct uip_conn uip_conns[UIP_CONNS];\r
+/**\r
+ * \addtogroup uiparch\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * 4-byte array used for the 32-bit sequence number calculations.\r
+ */\r
+extern u8_t uip_acc32[4];\r
+\r
+/** @} */\r
+\r
+\r
+#if UIP_UDP\r
+/**\r
+ * Representation of a uIP UDP connection.\r
+ */\r
+struct uip_udp_conn {\r
+ uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */\r
+ u16_t lport; /**< The local port number in network byte order. */\r
+ u16_t rport; /**< The remote port number in network byte order. */\r
+ u8_t ttl; /**< Default time-to-live. */\r
+\r
+ /** The application state. */\r
+ uip_udp_appstate_t appstate;\r
+};\r
+\r
+/**\r
+ * The current UDP connection.\r
+ */\r
+extern struct uip_udp_conn *uip_udp_conn;\r
+extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];\r
+#endif /* UIP_UDP */\r
+\r
+/**\r
+ * The structure holding the TCP/IP statistics that are gathered if\r
+ * UIP_STATISTICS is set to 1.\r
+ *\r
+ */\r
+struct uip_stats {\r
+ struct {\r
+ uip_stats_t drop; /**< Number of dropped packets at the IP\r
+ layer. */\r
+ uip_stats_t recv; /**< Number of received packets at the IP\r
+ layer. */\r
+ uip_stats_t sent; /**< Number of sent packets at the IP\r
+ layer. */\r
+ uip_stats_t vhlerr; /**< Number of packets dropped due to wrong\r
+ IP version or header length. */\r
+ uip_stats_t hblenerr; /**< Number of packets dropped due to wrong\r
+ IP length, high byte. */\r
+ uip_stats_t lblenerr; /**< Number of packets dropped due to wrong\r
+ IP length, low byte. */\r
+ uip_stats_t fragerr; /**< Number of packets dropped since they\r
+ were IP fragments. */\r
+ uip_stats_t chkerr; /**< Number of packets dropped due to IP\r
+ checksum errors. */\r
+ uip_stats_t protoerr; /**< Number of packets dropped since they\r
+ were neither ICMP, UDP nor TCP. */\r
+ } ip; /**< IP statistics. */\r
+ struct {\r
+ uip_stats_t drop; /**< Number of dropped ICMP packets. */\r
+ uip_stats_t recv; /**< Number of received ICMP packets. */\r
+ uip_stats_t sent; /**< Number of sent ICMP packets. */\r
+ uip_stats_t typeerr; /**< Number of ICMP packets with a wrong\r
+ type. */\r
+ } icmp; /**< ICMP statistics. */\r
+ struct {\r
+ uip_stats_t drop; /**< Number of dropped TCP segments. */\r
+ uip_stats_t recv; /**< Number of recived TCP segments. */\r
+ uip_stats_t sent; /**< Number of sent TCP segments. */\r
+ uip_stats_t chkerr; /**< Number of TCP segments with a bad\r
+ checksum. */\r
+ uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK\r
+ number. */\r
+ uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */\r
+ uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */\r
+ uip_stats_t syndrop; /**< Number of dropped SYNs due to too few\r
+ connections was avaliable. */\r
+ uip_stats_t synrst; /**< Number of SYNs for closed ports,\r
+ triggering a RST. */\r
+ } tcp; /**< TCP statistics. */\r
+#if UIP_UDP\r
+ struct {\r
+ uip_stats_t drop; /**< Number of dropped UDP segments. */\r
+ uip_stats_t recv; /**< Number of recived UDP segments. */\r
+ uip_stats_t sent; /**< Number of sent UDP segments. */\r
+ uip_stats_t chkerr; /**< Number of UDP segments with a bad\r
+ checksum. */\r
+ } udp; /**< UDP statistics. */\r
+#endif /* UIP_UDP */\r
+};\r
+\r
+/**\r
+ * The uIP TCP/IP statistics.\r
+ *\r
+ * This is the variable in which the uIP TCP/IP statistics are gathered.\r
+ */\r
+extern struct uip_stats uip_stat;\r
+\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* All the stuff below this point is internal to uIP and should not be\r
+ * used directly by an application or by a device driver.\r
+ */\r
+/*---------------------------------------------------------------------------*/\r
+/* u8_t uip_flags:\r
+ *\r
+ * When the application is called, uip_flags will contain the flags\r
+ * that are defined in this file. Please read below for more\r
+ * infomation.\r
+ */\r
+extern u8_t uip_flags;\r
+\r
+/* The following flags may be set in the global variable uip_flags\r
+ before calling the application callback. The UIP_ACKDATA,\r
+ UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,\r
+ whereas the others are mutualy exclusive. Note that these flags\r
+ should *NOT* be accessed directly, but only through the uIP\r
+ functions/macros. */\r
+\r
+#define UIP_ACKDATA 1 /* Signifies that the outstanding data was\r
+ acked and the application should send\r
+ out new data instead of retransmitting\r
+ the last data. */\r
+#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent\r
+ us new data. */\r
+#define UIP_REXMIT 4 /* Tells the application to retransmit the\r
+ data that was last sent. */\r
+#define UIP_POLL 8 /* Used for polling the application, to\r
+ check if the application has data that\r
+ it wants to send. */\r
+#define UIP_CLOSE 16 /* The remote host has closed the\r
+ connection, thus the connection has\r
+ gone away. Or the application signals\r
+ that it wants to close the\r
+ connection. */\r
+#define UIP_ABORT 32 /* The remote host has aborted the\r
+ connection, thus the connection has\r
+ gone away. Or the application signals\r
+ that it wants to abort the\r
+ connection. */\r
+#define UIP_CONNECTED 64 /* We have got a connection from a remote\r
+ host and have set up a new connection\r
+ for it, or an active connection has\r
+ been successfully established. */\r
+\r
+#define UIP_TIMEDOUT 128 /* The connection has been aborted due to\r
+ too many retransmissions. */\r
+\r
+/* uip_process(flag):\r
+ *\r
+ * The actual uIP function which does all the work.\r
+ */\r
+void uip_process(u8_t flag);\r
+\r
+/* The following flags are passed as an argument to the uip_process()\r
+ function. They are used to distinguish between the two cases where\r
+ uip_process() is called. It can be called either because we have\r
+ incoming data that should be processed, or because the periodic\r
+ timer has fired. These values are never used directly, but only in\r
+ the macrose defined in this file. */\r
+\r
+#define UIP_DATA 1 /* Tells uIP that there is incoming\r
+ data in the uip_buf buffer. The\r
+ length of the data is stored in the\r
+ global variable uip_len. */\r
+#define UIP_TIMER 2 /* Tells uIP that the periodic timer\r
+ has fired. */\r
+#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should\r
+ be polled. */\r
+#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram\r
+ should be constructed in the\r
+ uip_buf buffer. */\r
+#if UIP_UDP\r
+#define UIP_UDP_TIMER 5\r
+#endif /* UIP_UDP */\r
+\r
+/* The TCP states used in the uip_conn->tcpstateflags. */\r
+#define UIP_CLOSED 0\r
+#define UIP_SYN_RCVD 1\r
+#define UIP_SYN_SENT 2\r
+#define UIP_ESTABLISHED 3\r
+#define UIP_FIN_WAIT_1 4\r
+#define UIP_FIN_WAIT_2 5\r
+#define UIP_CLOSING 6\r
+#define UIP_TIME_WAIT 7\r
+#define UIP_LAST_ACK 8\r
+#define UIP_TS_MASK 15\r
+\r
+#define UIP_STOPPED 16\r
+\r
+/* The TCP and IP headers. */\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct uip_tcpip_hdr {\r
+#if UIP_CONF_IPV6\r
+ /* IPv6 header. */\r
+ u8_t vtc,\r
+ tcflow;\r
+ u16_t flow;\r
+ u8_t len[2];\r
+ u8_t proto, ttl;\r
+ uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+ /* IPv4 header. */\r
+ u8_t vhl,\r
+ tos,\r
+ len[2],\r
+ ipid[2],\r
+ ipoffset[2],\r
+ ttl,\r
+ proto;\r
+ u16_t ipchksum;\r
+ u16_t srcipaddr[2],\r
+ destipaddr[2];\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ /* TCP header. */\r
+ u16_t srcport,\r
+ destport;\r
+ u8_t seqno[4],\r
+ ackno[4],\r
+ tcpoffset,\r
+ flags,\r
+ wnd[2];\r
+ u16_t tcpchksum;\r
+ u8_t urgp[2];\r
+ u8_t optdata[4];\r
+} PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+/* The ICMP and IP headers. */\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct uip_icmpip_hdr {\r
+#if UIP_CONF_IPV6\r
+ /* IPv6 header. */\r
+ u8_t vtc,\r
+ tcf;\r
+ u16_t flow;\r
+ u8_t len[2];\r
+ u8_t proto, ttl;\r
+ uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+ /* IPv4 header. */\r
+ u8_t vhl,\r
+ tos,\r
+ len[2],\r
+ ipid[2],\r
+ ipoffset[2],\r
+ ttl,\r
+ proto;\r
+ u16_t ipchksum;\r
+ u16_t srcipaddr[2],\r
+ destipaddr[2];\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ /* ICMP (echo) header. */\r
+ u8_t type, icode;\r
+ u16_t icmpchksum;\r
+#if !UIP_CONF_IPV6\r
+ u16_t id, seqno;\r
+#else /* !UIP_CONF_IPV6 */\r
+ u8_t flags, reserved1, reserved2, reserved3;\r
+ u8_t icmp6data[16];\r
+ u8_t options[1];\r
+#endif /* !UIP_CONF_IPV6 */\r
+} PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+\r
+/* The UDP and IP headers. */\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct uip_udpip_hdr {\r
+#if UIP_CONF_IPV6\r
+ /* IPv6 header. */\r
+ u8_t vtc,\r
+ tcf;\r
+ u16_t flow;\r
+ u8_t len[2];\r
+ u8_t proto, ttl;\r
+ uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+ /* IP header. */\r
+ u8_t vhl,\r
+ tos,\r
+ len[2],\r
+ ipid[2],\r
+ ipoffset[2],\r
+ ttl,\r
+ proto;\r
+ u16_t ipchksum;\r
+ u16_t srcipaddr[2],\r
+ destipaddr[2];\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+ /* UDP header. */\r
+ u16_t srcport,\r
+ destport;\r
+ u16_t udplen;\r
+ u16_t udpchksum;\r
+} PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+\r
+\r
+/**\r
+ * The buffer size available for user data in the \ref uip_buf buffer.\r
+ *\r
+ * This macro holds the available size for user data in the \ref\r
+ * uip_buf buffer. The macro is intended to be used for checking\r
+ * bounds of available user data.\r
+ *\r
+ * Example:\r
+ \code\r
+ snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);\r
+ \endcode\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)\r
+\r
+\r
+#define UIP_PROTO_ICMP 1\r
+#define UIP_PROTO_TCP 6\r
+#define UIP_PROTO_UDP 17\r
+#define UIP_PROTO_ICMP6 58\r
+\r
+/* Header sizes. */\r
+#if UIP_CONF_IPV6\r
+#define UIP_IPH_LEN 40\r
+#else /* UIP_CONF_IPV6 */\r
+#define UIP_IPH_LEN 20 /* Size of IP header */\r
+#endif /* UIP_CONF_IPV6 */\r
+#define UIP_UDPH_LEN 8 /* Size of UDP header */\r
+#define UIP_TCPH_LEN 20 /* Size of TCP header */\r
+#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +\r
+ UDP\r
+ header */\r
+#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +\r
+ TCP\r
+ header */\r
+#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN\r
+\r
+\r
+#if UIP_FIXEDADDR\r
+extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;\r
+#else /* UIP_FIXEDADDR */\r
+extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;\r
+#endif /* UIP_FIXEDADDR */\r
+\r
+\r
+\r
+/**\r
+ * Representation of a 48-bit Ethernet address.\r
+ */\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct uip_eth_addr {\r
+ u8_t addr[6];\r
+} PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+/**\r
+ * Calculate the Internet checksum over a buffer.\r
+ *\r
+ * The Internet checksum is the one's complement of the one's\r
+ * complement sum of all 16-bit words in the buffer.\r
+ *\r
+ * See RFC1071.\r
+ *\r
+ * \param buf A pointer to the buffer over which the checksum is to be\r
+ * computed.\r
+ *\r
+ * \param len The length of the buffer over which the checksum is to\r
+ * be computed.\r
+ *\r
+ * \return The Internet checksum of the buffer.\r
+ */\r
+u16_t uip_chksum(u16_t *buf, u16_t len);\r
+\r
+/**\r
+ * Calculate the IP header checksum of the packet header in uip_buf.\r
+ *\r
+ * The IP header checksum is the Internet checksum of the 20 bytes of\r
+ * the IP header.\r
+ *\r
+ * \return The IP header checksum of the IP header in the uip_buf\r
+ * buffer.\r
+ */\r
+u16_t uip_ipchksum(void);\r
+\r
+/**\r
+ * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.\r
+ *\r
+ * The TCP checksum is the Internet checksum of data contents of the\r
+ * TCP segment, and a pseudo-header as defined in RFC793.\r
+ *\r
+ * \return The TCP checksum of the TCP segment in uip_buf and pointed\r
+ * to by uip_appdata.\r
+ */\r
+u16_t uip_tcpchksum(void);\r
+\r
+/**\r
+ * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.\r
+ *\r
+ * The UDP checksum is the Internet checksum of data contents of the\r
+ * UDP segment, and a pseudo-header as defined in RFC768.\r
+ *\r
+ * \return The UDP checksum of the UDP segment in uip_buf and pointed\r
+ * to by uip_appdata.\r
+ */\r
+u16_t uip_udpchksum(void);\r
+\r
+\r
+#endif /* __UIP_H__ */\r
+\r
+\r
+/** @} */\r
--- /dev/null
+/**\r
+ * \addtogroup uip\r
+ * {@\r
+ */\r
+\r
+/**\r
+ * \defgroup uiparch Architecture specific uIP functions\r
+ * @{\r
+ *\r
+ * The functions in the architecture specific module implement the IP\r
+ * check sum and 32-bit additions.\r
+ *\r
+ * The IP checksum calculation is the most computationally expensive\r
+ * operation in the TCP/IP stack and it therefore pays off to\r
+ * implement this in efficient assembler. The purpose of the uip-arch\r
+ * module is to let the checksum functions to be implemented in\r
+ * architecture specific assembler.\r
+ *\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Declarations of architecture specific functions.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip_arch.h,v 1.2 2006/06/07 09:15:19 adam Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIP_ARCH_H__\r
+#define __UIP_ARCH_H__\r
+\r
+#include "uip.h"\r
+\r
+/**\r
+ * Carry out a 32-bit addition.\r
+ *\r
+ * Because not all architectures for which uIP is intended has native\r
+ * 32-bit arithmetic, uIP uses an external C function for doing the\r
+ * required 32-bit additions in the TCP protocol processing. This\r
+ * function should add the two arguments and place the result in the\r
+ * global variable uip_acc32.\r
+ *\r
+ * \note The 32-bit integer pointed to by the op32 parameter and the\r
+ * result in the uip_acc32 variable are in network byte order (big\r
+ * endian).\r
+ *\r
+ * \param op32 A pointer to a 4-byte array representing a 32-bit\r
+ * integer in network byte order (big endian).\r
+ *\r
+ * \param op16 A 16-bit integer in host byte order.\r
+ */\r
+void uip_add32(u8_t *op32, u16_t op16);\r
+\r
+/**\r
+ * Calculate the Internet checksum over a buffer.\r
+ *\r
+ * The Internet checksum is the one's complement of the one's\r
+ * complement sum of all 16-bit words in the buffer.\r
+ *\r
+ * See RFC1071.\r
+ *\r
+ * \note This function is not called in the current version of uIP,\r
+ * but future versions might make use of it.\r
+ *\r
+ * \param buf A pointer to the buffer over which the checksum is to be\r
+ * computed.\r
+ *\r
+ * \param len The length of the buffer over which the checksum is to\r
+ * be computed.\r
+ *\r
+ * \return The Internet checksum of the buffer.\r
+ */\r
+u16_t uip_chksum(u16_t *buf, u16_t len);\r
+\r
+/**\r
+ * Calculate the IP header checksum of the packet header in uip_buf.\r
+ *\r
+ * The IP header checksum is the Internet checksum of the 20 bytes of\r
+ * the IP header.\r
+ *\r
+ * \return The IP header checksum of the IP header in the uip_buf\r
+ * buffer.\r
+ */\r
+u16_t uip_ipchksum(void);\r
+\r
+/**\r
+ * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.\r
+ *\r
+ * The TCP checksum is the Internet checksum of data contents of the\r
+ * TCP segment, and a pseudo-header as defined in RFC793.\r
+ *\r
+ * \note The uip_appdata pointer that points to the packet data may\r
+ * point anywhere in memory, so it is not possible to simply calculate\r
+ * the Internet checksum of the contents of the uip_buf buffer.\r
+ *\r
+ * \return The TCP checksum of the TCP segment in uip_buf and pointed\r
+ * to by uip_appdata.\r
+ */\r
+u16_t uip_tcpchksum(void);\r
+\r
+u16_t uip_udpchksum(void);\r
+\r
+/** @} */\r
+/** @} */\r
+\r
+#endif /* __UIP_ARCH_H__ */\r
--- /dev/null
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \defgroup uiparp uIP Address Resolution Protocol\r
+ * @{\r
+ *\r
+ * The Address Resolution Protocol ARP is used for mapping between IP\r
+ * addresses and link level addresses such as the Ethernet MAC\r
+ * addresses. ARP uses broadcast queries to ask for the link level\r
+ * address of a known IP address and the host which is configured with\r
+ * the IP address for which the query was meant, will respond with its\r
+ * link level address.\r
+ *\r
+ * \note This ARP implementation only supports Ethernet.\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Implementation of the ARP Address Resolution Protocol.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ *\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $\r
+ *\r
+ */\r
+\r
+\r
+#include "uip_arp.h"\r
+\r
+#include <string.h>\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct arp_hdr {\r
+ struct uip_eth_hdr ethhdr;\r
+ u16_t hwtype;\r
+ u16_t protocol;\r
+ u8_t hwlen;\r
+ u8_t protolen;\r
+ u16_t opcode;\r
+ struct uip_eth_addr shwaddr;\r
+ u16_t sipaddr[2];\r
+ struct uip_eth_addr dhwaddr;\r
+ u16_t dipaddr[2];\r
+} PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct ethip_hdr {\r
+ struct uip_eth_hdr ethhdr;\r
+ /* IP header. */\r
+ u8_t vhl,\r
+ tos,\r
+ len[2],\r
+ ipid[2],\r
+ ipoffset[2],\r
+ ttl,\r
+ proto;\r
+ u16_t ipchksum;\r
+ u16_t srcipaddr[2],\r
+ destipaddr[2];\r
+} PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+#define ARP_REQUEST 1\r
+#define ARP_REPLY 2\r
+\r
+#define ARP_HWTYPE_ETH 1\r
+\r
+struct arp_entry {\r
+ u16_t ipaddr[2];\r
+ struct uip_eth_addr ethaddr;\r
+ u8_t time;\r
+};\r
+\r
+static const struct uip_eth_addr broadcast_ethaddr =\r
+ {{0xff,0xff,0xff,0xff,0xff,0xff}};\r
+static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};\r
+\r
+static struct arp_entry arp_table[UIP_ARPTAB_SIZE];\r
+static u16_t ipaddr[2];\r
+static u8_t i, c;\r
+\r
+static u8_t arptime;\r
+static u8_t tmpage;\r
+\r
+#define BUF ((struct arp_hdr *)&uip_buf[0])\r
+#define IPBUF ((struct ethip_hdr *)&uip_buf[0])\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Initialize the ARP module.\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_init(void)\r
+{\r
+ for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+ memset(arp_table[i].ipaddr, 0, 4);\r
+ }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Periodic ARP processing function.\r
+ *\r
+ * This function performs periodic timer processing in the ARP module\r
+ * and should be called at regular intervals. The recommended interval\r
+ * is 10 seconds between the calls.\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_timer(void)\r
+{\r
+ struct arp_entry *tabptr;\r
+\r
+ ++arptime;\r
+ for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+ tabptr = &arp_table[i];\r
+ if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&\r
+ arptime - tabptr->time >= UIP_ARP_MAXAGE) {\r
+ memset(tabptr->ipaddr, 0, 4);\r
+ }\r
+ }\r
+\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+static void\r
+uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)\r
+{\r
+ register struct arp_entry *tabptr;\r
+ /* Walk through the ARP mapping table and try to find an entry to\r
+ update. If none is found, the IP -> MAC address mapping is\r
+ inserted in the ARP table. */\r
+ for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+\r
+ tabptr = &arp_table[i];\r
+ /* Only check those entries that are actually in use. */\r
+ if(tabptr->ipaddr[0] != 0 &&\r
+ tabptr->ipaddr[1] != 0) {\r
+\r
+ /* Check if the source IP address of the incoming packet matches\r
+ the IP address in this ARP table entry. */\r
+ if(ipaddr[0] == tabptr->ipaddr[0] &&\r
+ ipaddr[1] == tabptr->ipaddr[1]) {\r
+ \r
+ /* An old entry found, update this and return. */\r
+ memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
+ tabptr->time = arptime;\r
+\r
+ return;\r
+ }\r
+ }\r
+ }\r
+\r
+ /* If we get here, no existing ARP table entry was found, so we\r
+ create one. */\r
+\r
+ /* First, we try to find an unused entry in the ARP table. */\r
+ for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+ tabptr = &arp_table[i];\r
+ if(tabptr->ipaddr[0] == 0 &&\r
+ tabptr->ipaddr[1] == 0) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* If no unused entry is found, we try to find the oldest entry and\r
+ throw it away. */\r
+ if(i == UIP_ARPTAB_SIZE) {\r
+ tmpage = 0;\r
+ c = 0;\r
+ for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+ tabptr = &arp_table[i];\r
+ if(arptime - tabptr->time > tmpage) {\r
+ tmpage = arptime - tabptr->time;\r
+ c = i;\r
+ }\r
+ }\r
+ i = c;\r
+ tabptr = &arp_table[i];\r
+ }\r
+\r
+ /* Now, i is the ARP table entry which we will fill with the new\r
+ information. */\r
+ memcpy(tabptr->ipaddr, ipaddr, 4);\r
+ memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
+ tabptr->time = arptime;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * ARP processing for incoming IP packets\r
+ *\r
+ * This function should be called by the device driver when an IP\r
+ * packet has been received. The function will check if the address is\r
+ * in the ARP cache, and if so the ARP cache entry will be\r
+ * refreshed. If no ARP cache entry was found, a new one is created.\r
+ *\r
+ * This function expects an IP packet with a prepended Ethernet header\r
+ * in the uip_buf[] buffer, and the length of the packet in the global\r
+ * variable uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+#if 1\r
+void\r
+uip_arp_ipin(void)\r
+{\r
+ uip_len -= sizeof(struct uip_eth_hdr);\r
+ \r
+ /* Only insert/update an entry if the source IP address of the\r
+ incoming IP packet comes from a host on the local network. */\r
+ if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=\r
+ (uip_hostaddr[0] & uip_netmask[0])) {\r
+ return;\r
+ }\r
+ if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=\r
+ (uip_hostaddr[1] & uip_netmask[1])) {\r
+ return;\r
+ }\r
+ uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));\r
+\r
+ return;\r
+}\r
+#endif /* 0 */\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * ARP processing for incoming ARP packets.\r
+ *\r
+ * This function should be called by the device driver when an ARP\r
+ * packet has been received. The function will act differently\r
+ * depending on the ARP packet type: if it is a reply for a request\r
+ * that we previously sent out, the ARP cache will be filled in with\r
+ * the values from the ARP reply. If the incoming ARP packet is an ARP\r
+ * request for our IP address, an ARP reply packet is created and put\r
+ * into the uip_buf[] buffer.\r
+ *\r
+ * When the function returns, the value of the global variable uip_len\r
+ * indicates whether the device driver should send out a packet or\r
+ * not. If uip_len is zero, no packet should be sent. If uip_len is\r
+ * non-zero, it contains the length of the outbound packet that is\r
+ * present in the uip_buf[] buffer.\r
+ *\r
+ * This function expects an ARP packet with a prepended Ethernet\r
+ * header in the uip_buf[] buffer, and the length of the packet in the\r
+ * global variable uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_arpin(void)\r
+{\r
+\r
+ if(uip_len < sizeof(struct arp_hdr)) {\r
+ uip_len = 0;\r
+ return;\r
+ }\r
+ uip_len = 0;\r
+\r
+ switch(BUF->opcode) {\r
+ case HTONS(ARP_REQUEST):\r
+ /* ARP request. If it asked for our address, we send out a\r
+ reply. */\r
+ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {\r
+ /* First, we register the one who made the request in our ARP\r
+ table, since it is likely that we will do more communication\r
+ with this host in the future. */\r
+ uip_arp_update(BUF->sipaddr, &BUF->shwaddr);\r
+\r
+ /* The reply opcode is 2. */\r
+ BUF->opcode = HTONS(2);\r
+\r
+ memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);\r
+ memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);\r
+ memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);\r
+ memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);\r
+\r
+ BUF->dipaddr[0] = BUF->sipaddr[0];\r
+ BUF->dipaddr[1] = BUF->sipaddr[1];\r
+ BUF->sipaddr[0] = uip_hostaddr[0];\r
+ BUF->sipaddr[1] = uip_hostaddr[1];\r
+\r
+ BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);\r
+ uip_len = sizeof(struct arp_hdr);\r
+ }\r
+ break;\r
+ case HTONS(ARP_REPLY):\r
+ /* ARP reply. We insert or update the ARP table if it was meant\r
+ for us. */\r
+ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {\r
+ uip_arp_update(BUF->sipaddr, &BUF->shwaddr);\r
+ }\r
+ break;\r
+ }\r
+\r
+ return;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Prepend Ethernet header to an outbound IP packet and see if we need\r
+ * to send out an ARP request.\r
+ *\r
+ * This function should be called before sending out an IP packet. The\r
+ * function checks the destination IP address of the IP packet to see\r
+ * what Ethernet MAC address that should be used as a destination MAC\r
+ * address on the Ethernet.\r
+ *\r
+ * If the destination IP address is in the local network (determined\r
+ * by logical ANDing of netmask and our IP address), the function\r
+ * checks the ARP cache to see if an entry for the destination IP\r
+ * address is found. If so, an Ethernet header is prepended and the\r
+ * function returns. If no ARP cache entry is found for the\r
+ * destination IP address, the packet in the uip_buf[] is replaced by\r
+ * an ARP request packet for the IP address. The IP packet is dropped\r
+ * and it is assumed that they higher level protocols (e.g., TCP)\r
+ * eventually will retransmit the dropped packet.\r
+ *\r
+ * If the destination IP address is not on the local network, the IP\r
+ * address of the default router is used instead.\r
+ *\r
+ * When the function returns, a packet is present in the uip_buf[]\r
+ * buffer, and the length of the packet is in the global variable\r
+ * uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_out(void)\r
+{\r
+ struct arp_entry *tabptr;\r
+\r
+ /* Find the destination IP address in the ARP table and construct\r
+ the Ethernet header. If the destination IP addres isn't on the\r
+ local network, we use the default router's IP address instead.\r
+\r
+ If not ARP table entry is found, we overwrite the original IP\r
+ packet with an ARP request for the IP address. */\r
+\r
+ /* First check if destination is a local broadcast. */\r
+ if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {\r
+ memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);\r
+ } else {\r
+ /* Check if the destination address is on the local network. */\r
+ if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {\r
+ /* Destination address was not on the local network, so we need to\r
+ use the default router's IP address instead of the destination\r
+ address when determining the MAC address. */\r
+ uip_ipaddr_copy(ipaddr, uip_draddr);\r
+ } else {\r
+ /* Else, we use the destination IP address. */\r
+ uip_ipaddr_copy(ipaddr, IPBUF->destipaddr);\r
+ }\r
+\r
+ for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+ tabptr = &arp_table[i];\r
+ if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ if(i == UIP_ARPTAB_SIZE) {\r
+ /* The destination address was not in our ARP table, so we\r
+ overwrite the IP packet with an ARP request. */\r
+\r
+ memset(BUF->ethhdr.dest.addr, 0xff, 6);\r
+ memset(BUF->dhwaddr.addr, 0x00, 6);\r
+ memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);\r
+ memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);\r
+\r
+ uip_ipaddr_copy(BUF->dipaddr, ipaddr);\r
+ uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr);\r
+ BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */\r
+ BUF->hwtype = HTONS(ARP_HWTYPE_ETH);\r
+ BUF->protocol = HTONS(UIP_ETHTYPE_IP);\r
+ BUF->hwlen = 6;\r
+ BUF->protolen = 4;\r
+ BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);\r
+\r
+ uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];\r
+\r
+ uip_len = sizeof(struct arp_hdr);\r
+ return;\r
+ }\r
+\r
+ /* Build an ethernet header. */\r
+ memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);\r
+ }\r
+ memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);\r
+\r
+ IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);\r
+\r
+ uip_len += sizeof(struct uip_eth_hdr);\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
+/** @} */\r
+/** @} */\r
--- /dev/null
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \addtogroup uiparp\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Macros and definitions for the ARP module.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ */\r
+\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip_arp.h,v 1.5 2006/06/11 21:46:39 adam Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIP_ARP_H__\r
+#define __UIP_ARP_H__\r
+\r
+#include "uip.h"\r
+\r
+\r
+extern struct uip_eth_addr uip_ethaddr;\r
+\r
+/**\r
+ * The Ethernet header.\r
+ */\r
+#ifdef __ICCARM__\r
+ #pragma pack(1)\r
+#endif\r
+\r
+struct uip_eth_hdr {\r
+ struct uip_eth_addr dest;\r
+ struct uip_eth_addr src;\r
+ u16_t type;\r
+}PACK_STRUCT_END;\r
+\r
+#ifdef __ICCARM__\r
+ #pragma pack()\r
+#endif\r
+\r
+#define UIP_ETHTYPE_ARP 0x0806\r
+#define UIP_ETHTYPE_IP 0x0800\r
+#define UIP_ETHTYPE_IP6 0x86dd\r
+\r
+\r
+/* The uip_arp_init() function must be called before any of the other\r
+ ARP functions. */\r
+void uip_arp_init(void);\r
+\r
+/* The uip_arp_ipin() function should be called whenever an IP packet\r
+ arrives from the Ethernet. This function refreshes the ARP table or\r
+ inserts a new mapping if none exists. The function assumes that an\r
+ IP packet with an Ethernet header is present in the uip_buf buffer\r
+ and that the length of the packet is in the uip_len variable. */\r
+void uip_arp_ipin(void);\r
+//#define uip_arp_ipin()\r
+\r
+/* The uip_arp_arpin() should be called when an ARP packet is received\r
+ by the Ethernet driver. This function also assumes that the\r
+ Ethernet frame is present in the uip_buf buffer. When the\r
+ uip_arp_arpin() function returns, the contents of the uip_buf\r
+ buffer should be sent out on the Ethernet if the uip_len variable\r
+ is > 0. */\r
+void uip_arp_arpin(void);\r
+\r
+/* The uip_arp_out() function should be called when an IP packet\r
+ should be sent out on the Ethernet. This function creates an\r
+ Ethernet header before the IP header in the uip_buf buffer. The\r
+ Ethernet header will have the correct Ethernet MAC destination\r
+ address filled in if an ARP table entry for the destination IP\r
+ address (or the IP address of the default router) is present. If no\r
+ such table entry is found, the IP packet is overwritten with an ARP\r
+ request and we rely on TCP to retransmit the packet that was\r
+ overwritten. In any case, the uip_len variable holds the length of\r
+ the Ethernet frame that should be transmitted. */\r
+void uip_arp_out(void);\r
+\r
+/* The uip_arp_timer() function should be called every ten seconds. It\r
+ is responsible for flushing old entries in the ARP table. */\r
+void uip_arp_timer(void);\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \addtogroup uipconffunc\r
+ * @{\r
+ */\r
+\r
+\r
+/**\r
+ * Specifiy the Ethernet MAC address.\r
+ *\r
+ * The ARP code needs to know the MAC address of the Ethernet card in\r
+ * order to be able to respond to ARP queries and to generate working\r
+ * Ethernet headers.\r
+ *\r
+ * \note This macro only specifies the Ethernet MAC address to the ARP\r
+ * code. It cannot be used to change the MAC address of the Ethernet\r
+ * card.\r
+ *\r
+ * \param eaddr A pointer to a struct uip_eth_addr containing the\r
+ * Ethernet MAC address of the Ethernet card.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \\r
+ uip_ethaddr.addr[1] = eaddr.addr[1];\\r
+ uip_ethaddr.addr[2] = eaddr.addr[2];\\r
+ uip_ethaddr.addr[3] = eaddr.addr[3];\\r
+ uip_ethaddr.addr[4] = eaddr.addr[4];\\r
+ uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)\r
+\r
+/** @} */\r
+/** @} */\r
+\r
+#endif /* __UIP_ARP_H__ */\r
--- /dev/null
+/**\r
+ * \defgroup uipopt Configuration options for uIP\r
+ * @{\r
+ *\r
+ * uIP is configured using the per-project configuration file\r
+ * uipopt.h. This file contains all compile-time options for uIP and\r
+ * should be tweaked to match each specific project. The uIP\r
+ * distribution contains a documented example "uipopt.h" that can be\r
+ * copied and modified for each project.\r
+ *\r
+ * \note Most of the configuration options in the uipopt.h should not\r
+ * be changed, but rather the per-project uip-conf.h file.\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Configuration options for uIP.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ *\r
+ * This file is used for tweaking various configuration options for\r
+ * uIP. You should make a copy of this file into one of your project's\r
+ * directories instead of editing this example "uipopt.h" file that\r
+ * comes with the uIP distribution.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uipopt.h,v 1.4 2006/06/12 08:00:31 adam Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIPOPT_H__\r
+#define __UIPOPT_H__\r
+\r
+#ifndef UIP_LITTLE_ENDIAN\r
+#define UIP_LITTLE_ENDIAN 3412\r
+#endif /* UIP_LITTLE_ENDIAN */\r
+#ifndef UIP_BIG_ENDIAN\r
+#define UIP_BIG_ENDIAN 1234\r
+#endif /* UIP_BIG_ENDIAN */\r
+\r
+#include "uip-conf.h"\r
+\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \name Static configuration options\r
+ * @{\r
+ *\r
+ * These configuration options can be used for setting the IP address\r
+ * settings statically, but only if UIP_FIXEDADDR is set to 1. The\r
+ * configuration options for a specific node includes IP address,\r
+ * netmask and default router as well as the Ethernet address. The\r
+ * netmask, default router and Ethernet address are appliciable only\r
+ * if uIP should be run over Ethernet.\r
+ *\r
+ * All of these should be changed to suit your project.\r
+*/\r
+\r
+/**\r
+ * Determines if uIP should use a fixed IP address or not.\r
+ *\r
+ * If uIP should use a fixed IP address, the settings are set in the\r
+ * uipopt.h file. If not, the macros uip_sethostaddr(),\r
+ * uip_setdraddr() and uip_setnetmask() should be used instead.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_FIXEDADDR 0\r
+\r
+/**\r
+ * Ping IP address asignment.\r
+ *\r
+ * uIP uses a "ping" packets for setting its own IP address if this\r
+ * option is set. If so, uIP will start with an empty IP address and\r
+ * the destination IP address of the first incoming "ping" (ICMP echo)\r
+ * packet will be used for setting the hosts IP address.\r
+ *\r
+ * \note This works only if UIP_FIXEDADDR is 0.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_PINGADDRCONF\r
+#define UIP_PINGADDRCONF UIP_CONF_PINGADDRCONF\r
+#else /* UIP_CONF_PINGADDRCONF */\r
+#define UIP_PINGADDRCONF 0\r
+#endif /* UIP_CONF_PINGADDRCONF */\r
+\r
+\r
+/**\r
+ * Specifies if the uIP ARP module should be compiled with a fixed\r
+ * Ethernet MAC address or not.\r
+ *\r
+ * If this configuration option is 0, the macro uip_setethaddr() can\r
+ * be used to specify the Ethernet address at run-time.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_FIXEDETHADDR 0\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \name IP configuration options\r
+ * @{\r
+ *\r
+ */\r
+/**\r
+ * The IP TTL (time to live) of IP packets sent by uIP.\r
+ *\r
+ * This should normally not be changed.\r
+ */\r
+#define UIP_TTL 64\r
+\r
+/**\r
+ * Turn on support for IP packet reassembly.\r
+ *\r
+ * uIP supports reassembly of fragmented IP packets. This features\r
+ * requires an additonal amount of RAM to hold the reassembly buffer\r
+ * and the reassembly code size is approximately 700 bytes. The\r
+ * reassembly buffer is of the same size as the uip_buf buffer\r
+ * (configured by UIP_BUFSIZE).\r
+ *\r
+ * \note IP packet reassembly is not heavily tested.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_REASSEMBLY 0\r
+\r
+/**\r
+ * The maximum time an IP fragment should wait in the reassembly\r
+ * buffer before it is dropped.\r
+ *\r
+ */\r
+#define UIP_REASS_MAXAGE 40\r
+\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \name UDP configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Toggles wether UDP support should be compiled in or not.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_UDP\r
+#define UIP_UDP UIP_CONF_UDP\r
+#else /* UIP_CONF_UDP */\r
+#define UIP_UDP 0\r
+#endif /* UIP_CONF_UDP */\r
+\r
+/**\r
+ * Toggles if UDP checksums should be used or not.\r
+ *\r
+ * \note Support for UDP checksums is currently not included in uIP,\r
+ * so this option has no function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_UDP_CHECKSUMS\r
+#define UIP_UDP_CHECKSUMS UIP_CONF_UDP_CHECKSUMS\r
+#else\r
+#define UIP_UDP_CHECKSUMS 0\r
+#endif\r
+\r
+/**\r
+ * The maximum amount of concurrent UDP connections.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_UDP_CONNS\r
+#define UIP_UDP_CONNS UIP_CONF_UDP_CONNS\r
+#else /* UIP_CONF_UDP_CONNS */\r
+#define UIP_UDP_CONNS 10\r
+#endif /* UIP_CONF_UDP_CONNS */\r
+\r
+/**\r
+ * The name of the function that should be called when UDP datagrams arrive.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \name TCP configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Determines if support for opening connections from uIP should be\r
+ * compiled in.\r
+ *\r
+ * If the applications that are running on top of uIP for this project\r
+ * do not need to open outgoing TCP connections, this configration\r
+ * option can be turned off to reduce the code size of uIP.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_ACTIVE_OPEN 1\r
+\r
+/**\r
+ * The maximum number of simultaneously open TCP connections.\r
+ *\r
+ * Since the TCP connections are statically allocated, turning this\r
+ * configuration knob down results in less RAM used. Each TCP\r
+ * connection requires approximatly 30 bytes of memory.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_MAX_CONNECTIONS\r
+#define UIP_CONNS 10\r
+#else /* UIP_CONF_MAX_CONNECTIONS */\r
+#define UIP_CONNS UIP_CONF_MAX_CONNECTIONS\r
+#endif /* UIP_CONF_MAX_CONNECTIONS */\r
+\r
+\r
+/**\r
+ * The maximum number of simultaneously listening TCP ports.\r
+ *\r
+ * Each listening TCP port requires 2 bytes of memory.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_MAX_LISTENPORTS\r
+#define UIP_LISTENPORTS 20\r
+#else /* UIP_CONF_MAX_LISTENPORTS */\r
+#define UIP_LISTENPORTS UIP_CONF_MAX_LISTENPORTS\r
+#endif /* UIP_CONF_MAX_LISTENPORTS */\r
+\r
+/**\r
+ * Determines if support for TCP urgent data notification should be\r
+ * compiled in.\r
+ *\r
+ * Urgent data (out-of-band data) is a rarely used TCP feature that\r
+ * very seldom would be required.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_URGDATA 0\r
+\r
+/**\r
+ * The initial retransmission timeout counted in timer pulses.\r
+ *\r
+ * This should not be changed.\r
+ */\r
+#define UIP_RTO 3\r
+\r
+/**\r
+ * The maximum number of times a segment should be retransmitted\r
+ * before the connection should be aborted.\r
+ *\r
+ * This should not be changed.\r
+ */\r
+#define UIP_MAXRTX 8\r
+\r
+/**\r
+ * The maximum number of times a SYN segment should be retransmitted\r
+ * before a connection request should be deemed to have been\r
+ * unsuccessful.\r
+ *\r
+ * This should not need to be changed.\r
+ */\r
+#define UIP_MAXSYNRTX 5\r
+\r
+/**\r
+ * The TCP maximum segment size.\r
+ *\r
+ * This is should not be to set to more than\r
+ * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.\r
+ */\r
+#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)\r
+\r
+/**\r
+ * The size of the advertised receiver's window.\r
+ *\r
+ * Should be set low (i.e., to the size of the uip_buf buffer) is the\r
+ * application is slow to process incoming data, or high (32768 bytes)\r
+ * if the application processes data quickly.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_RECEIVE_WINDOW\r
+#define UIP_RECEIVE_WINDOW UIP_TCP_MSS\r
+#else\r
+#define UIP_RECEIVE_WINDOW UIP_CONF_RECEIVE_WINDOW\r
+#endif\r
+\r
+/**\r
+ * How long a connection should stay in the TIME_WAIT state.\r
+ *\r
+ * This configiration option has no real implication, and it should be\r
+ * left untouched.\r
+ */\r
+#define UIP_TIME_WAIT_TIMEOUT 120\r
+\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \name ARP configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * The size of the ARP table.\r
+ *\r
+ * This option should be set to a larger value if this uIP node will\r
+ * have many connections from the local network.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_ARPTAB_SIZE\r
+#define UIP_ARPTAB_SIZE UIP_CONF_ARPTAB_SIZE\r
+#else\r
+#define UIP_ARPTAB_SIZE 8\r
+#endif\r
+\r
+/**\r
+ * The maxium age of ARP table entries measured in 10ths of seconds.\r
+ *\r
+ * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD\r
+ * default).\r
+ */\r
+#define UIP_ARP_MAXAGE 120\r
+\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \name General configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * The size of the uIP packet buffer.\r
+ *\r
+ * The uIP packet buffer should not be smaller than 60 bytes, and does\r
+ * not need to be larger than 1500 bytes. Lower size results in lower\r
+ * TCP throughput, larger size results in higher TCP throughput.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_BUFFER_SIZE\r
+#define UIP_BUFSIZE 1500\r
+#else /* UIP_CONF_BUFFER_SIZE */\r
+#define UIP_BUFSIZE UIP_CONF_BUFFER_SIZE\r
+#endif /* UIP_CONF_BUFFER_SIZE */\r
+\r
+\r
+/**\r
+ * Determines if statistics support should be compiled in.\r
+ *\r
+ * The statistics is useful for debugging and to show the user.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_STATISTICS\r
+#define UIP_STATISTICS 0\r
+#else /* UIP_CONF_STATISTICS */\r
+#define UIP_STATISTICS UIP_CONF_STATISTICS\r
+#endif /* UIP_CONF_STATISTICS */\r
+\r
+/**\r
+ * Determines if logging of certain events should be compiled in.\r
+ *\r
+ * This is useful mostly for debugging. The function uip_log()\r
+ * must be implemented to suit the architecture of the project, if\r
+ * logging is turned on.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_LOGGING\r
+#define UIP_LOGGING 0\r
+#else /* UIP_CONF_LOGGING */\r
+#define UIP_LOGGING UIP_CONF_LOGGING\r
+#endif /* UIP_CONF_LOGGING */\r
+\r
+/**\r
+ * Broadcast support.\r
+ *\r
+ * This flag configures IP broadcast support. This is useful only\r
+ * together with UDP.\r
+ *\r
+ * \hideinitializer\r
+ *\r
+ */\r
+#ifndef UIP_CONF_BROADCAST\r
+#define UIP_BROADCAST 0\r
+#else /* UIP_CONF_BROADCAST */\r
+#define UIP_BROADCAST UIP_CONF_BROADCAST\r
+#endif /* UIP_CONF_BROADCAST */\r
+\r
+/**\r
+ * Print out a uIP log message.\r
+ *\r
+ * This function must be implemented by the module that uses uIP, and\r
+ * is called by uIP whenever a log message is generated.\r
+ */\r
+void uip_log(char *msg);\r
+\r
+/**\r
+ * The link level header length.\r
+ *\r
+ * This is the offset into the uip_buf where the IP header can be\r
+ * found. For Ethernet, this should be set to 14. For SLIP, this\r
+ * should be set to 0.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_LLH_LEN\r
+#define UIP_LLH_LEN UIP_CONF_LLH_LEN\r
+#else /* UIP_CONF_LLH_LEN */\r
+#define UIP_LLH_LEN 14\r
+#endif /* UIP_CONF_LLH_LEN */\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \name CPU architecture configuration\r
+ * @{\r
+ *\r
+ * The CPU architecture configuration is where the endianess of the\r
+ * CPU on which uIP is to be run is specified. Most CPUs today are\r
+ * little endian, and the most notable exception are the Motorolas\r
+ * which are big endian. The BYTE_ORDER macro should be changed to\r
+ * reflect the CPU architecture on which uIP is to be run.\r
+ */\r
+\r
+/**\r
+ * The byte order of the CPU architecture on which uIP is to be run.\r
+ *\r
+ * This option can be either BIG_ENDIAN (Motorola byte order) or\r
+ * LITTLE_ENDIAN (Intel byte order).\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_BYTE_ORDER\r
+#define UIP_BYTE_ORDER UIP_CONF_BYTE_ORDER\r
+#else /* UIP_CONF_BYTE_ORDER */\r
+#define UIP_BYTE_ORDER UIP_LITTLE_ENDIAN\r
+#endif /* UIP_CONF_BYTE_ORDER */\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \name Appication specific configurations\r
+ * @{\r
+ *\r
+ * An uIP application is implemented using a single application\r
+ * function that is called by uIP whenever a TCP/IP event occurs. The\r
+ * name of this function must be registered with uIP at compile time\r
+ * using the UIP_APPCALL definition.\r
+ *\r
+ * uIP applications can store the application state within the\r
+ * uip_conn structure by specifying the type of the application\r
+ * structure by typedef:ing the type uip_tcp_appstate_t and uip_udp_appstate_t.\r
+ *\r
+ * The file containing the definitions must be included in the\r
+ * uipopt.h file.\r
+ *\r
+ * The following example illustrates how this can look.\r
+ \code\r
+\r
+void httpd_appcall(void);\r
+#define UIP_APPCALL httpd_appcall\r
+\r
+struct httpd_state {\r
+ u8_t state;\r
+ u16_t count;\r
+ char *dataptr;\r
+ char *script;\r
+};\r
+typedef struct httpd_state uip_tcp_appstate_t\r
+ \endcode\r
+ */\r
+\r
+/**\r
+ * \var #define UIP_APPCALL\r
+ *\r
+ * The name of the application function that uIP should call in\r
+ * response to TCP/IP events.\r
+ *\r
+ */\r
+\r
+/**\r
+ * \var typedef uip_tcp_appstate_t\r
+ *\r
+ * The type of the application state that is to be stored in the\r
+ * uip_conn structure. This usually is typedef:ed to a struct holding\r
+ * application state information.\r
+ */\r
+\r
+/**\r
+ * \var typedef uip_udp_appstate_t\r
+ *\r
+ * The type of the application state that is to be stored in the\r
+ * uip_conn structure. This usually is typedef:ed to a struct holding\r
+ * application state information.\r
+ */\r
+/** @} */\r
+/** @} */\r
+\r
+#endif /* __UIPOPT_H__ */\r
--- /dev/null
+/*\r
+ * Copyright (c) 2002, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer in the documentation and/or other materials provided\r
+ * with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ * products derived from this software without specific prior\r
+ * written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * $Id: webserver.h,v 1.2 2006/06/11 21:46:38 adam Exp $\r
+ *\r
+ */\r
+#ifndef __WEBSERVER_H__\r
+#define __WEBSERVER_H__\r
+\r
+#include "httpd.h"\r
+\r
+typedef struct httpd_state uip_tcp_appstate_t;\r
+/* UIP_APPCALL: the name of the application function. This function\r
+ must return void and take no arguments (i.e., C type "void\r
+ appfunc(void)"). */\r
+#ifndef UIP_APPCALL\r
+#define UIP_APPCALL httpd_appcall\r
+#endif\r
+\r
+\r
+#endif /* __WEBSERVER_H__ */\r