source: uKadecot/trunk/uip/task/uip_adpt.c

Last change on this file was 262, checked in by coas-nagasima, 7 years ago

uIPを更新
プロジェクトファイルを更新

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr; charset=SHIFT_JIS
File size: 3.5 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2014 Cores Co., Ltd. Japan
5 *
6 * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
8 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
9 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
10 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
11 * スコード中に含まれていること.
12 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
13 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
14 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
15 * の無保証規定を掲載すること.
16 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
17 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
18 * と.
19 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
20 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
21 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
22 * 報告すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
27 * 免責すること.
28 *
29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
31 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
33 * の責任を負わない.
34 *
35 * @(#) $Id: uip_adpt.c 262 2016-11-18 05:58:30Z coas-nagasima $
36 */
37
38#include <kernel.h>
39#include "net/ip/uip.h"
40#include "uip_adpt.h"
41#include "t_syslog.h"
42#include "kernel_cfg.h"
43
44/*
45 * uip_taskを起動
46 */
47ER uip_start()
48{
49 ER ret;
50
51 /* uip_task用周期ハンドラの起動 */
52 ret = sta_cyc(UIP_CYCHDR);
53 if (ret != E_OK) {
54 syslog(LOG_DEBUG, "sta_cyc() result = %d", ret);
55 return ret;
56 }
57
58 return E_OK;
59}
60
61/*
62 * convert_hexdigit -- 16進数→文字列変換
63 */
64int_t convert_hexdigit (char *buf, uint_t val, int_t radix, int_t width, char padchar)
65{
66 static const char radhex[] = "0123456789abcdef";
67
68 char digits[11], *start;
69 int_t ix, pad;
70
71 ix = 0;
72 start = buf;
73 do {
74 digits[ix ++] = radhex[(val % radix) & 0x0f];
75 val /= radix;
76 } while (val != 0);
77 for (pad = ix; pad < width; pad ++)
78 *buf ++ = padchar;
79 while (ix -- > 0)
80 *buf ++ = digits[ix];
81 *buf = '\0';
82 return (int_t)(buf - start);
83}
84
85/*
86 * ip2str -- IPv4 アドレスを文字列に変換する。
87 */
88char *ip2str(char *buf, const T_IN4_ADDR ipaddr)
89{
90 char *start;
91
92 start = buf;
93 buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[0] >> 0) & 0xff), 10, 0, ' ');
94 *(buf ++) = '.';
95 buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[0] >> 8) & 0xff), 10, 0, ' ');
96 *(buf ++) = '.';
97 buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[1] >> 0) & 0xff), 10, 0, ' ');
98 *(buf ++) = '.';
99 buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[1] >> 8) & 0xff), 10, 0, ' ');
100 *buf = '\0';
101
102 return start;
103}
104
105ID uip_getid(struct uip_conn *conn)
106{
107 int index;
108
109 index = ((intptr_t)conn - (intptr_t)uip_conns) / sizeof(uip_conns[0]);
110 if ((index < 0) || (index >= sizeof(uip_conns) / sizeof(uip_conns[0])))
111 return -1;
112
113 return index + 1;
114}
115
116struct uip_conn *uip_getconn(ID connid)
117{
118 int index = connid - 1;
119
120 if ((index < 0) || (index >= sizeof(uip_conns) / sizeof(uip_conns[0])))
121 return NULL;
122
123 return &uip_conns[index];
124}
Note: See TracBrowser for help on using the repository browser.