Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /**
Pawel Zarembski 0:01f31e923fe2 2 * @file RTL.h
Pawel Zarembski 0:01f31e923fe2 3 * @brief
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 7 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 8 *
Pawel Zarembski 0:01f31e923fe2 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 10 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 11 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 12 *
Pawel Zarembski 0:01f31e923fe2 13 * http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 14 *
Pawel Zarembski 0:01f31e923fe2 15 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 18 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 19 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 20 */
Pawel Zarembski 0:01f31e923fe2 21
Pawel Zarembski 0:01f31e923fe2 22 #ifndef __RTL_H__
Pawel Zarembski 0:01f31e923fe2 23 #define __RTL_H__
Pawel Zarembski 0:01f31e923fe2 24
Pawel Zarembski 0:01f31e923fe2 25 /* RL-ARM version number. */
Pawel Zarembski 0:01f31e923fe2 26 #define __RL_ARM_VER 471
Pawel Zarembski 0:01f31e923fe2 27
Pawel Zarembski 0:01f31e923fe2 28 #define __task __declspec(noreturn)
Pawel Zarembski 0:01f31e923fe2 29 #define __used __attribute__((used))
Pawel Zarembski 0:01f31e923fe2 30
Pawel Zarembski 0:01f31e923fe2 31 #ifndef NULL
Pawel Zarembski 0:01f31e923fe2 32 #ifdef __cplusplus
Pawel Zarembski 0:01f31e923fe2 33 #define NULL 0
Pawel Zarembski 0:01f31e923fe2 34 #else
Pawel Zarembski 0:01f31e923fe2 35 #define NULL ((void *) 0)
Pawel Zarembski 0:01f31e923fe2 36 #endif
Pawel Zarembski 0:01f31e923fe2 37 #endif
Pawel Zarembski 0:01f31e923fe2 38
Pawel Zarembski 0:01f31e923fe2 39 #ifndef EOF
Pawel Zarembski 0:01f31e923fe2 40 #define EOF (-1)
Pawel Zarembski 0:01f31e923fe2 41 #endif
Pawel Zarembski 0:01f31e923fe2 42
Pawel Zarembski 0:01f31e923fe2 43 #ifndef __size_t
Pawel Zarembski 0:01f31e923fe2 44 #define __size_t 1
Pawel Zarembski 0:01f31e923fe2 45 typedef unsigned int size_t;
Pawel Zarembski 0:01f31e923fe2 46 #endif
Pawel Zarembski 0:01f31e923fe2 47
Pawel Zarembski 0:01f31e923fe2 48 typedef signed char S8;
Pawel Zarembski 0:01f31e923fe2 49 typedef unsigned char U8;
Pawel Zarembski 0:01f31e923fe2 50 typedef short S16;
Pawel Zarembski 0:01f31e923fe2 51 typedef unsigned short U16;
Pawel Zarembski 0:01f31e923fe2 52 typedef int S32;
Pawel Zarembski 0:01f31e923fe2 53 typedef unsigned int U32;
Pawel Zarembski 0:01f31e923fe2 54 typedef long long S64;
Pawel Zarembski 0:01f31e923fe2 55 typedef unsigned long long U64;
Pawel Zarembski 0:01f31e923fe2 56 typedef unsigned char BIT;
Pawel Zarembski 0:01f31e923fe2 57 typedef unsigned int BOOL;
Pawel Zarembski 0:01f31e923fe2 58
Pawel Zarembski 0:01f31e923fe2 59 #ifndef __TRUE
Pawel Zarembski 0:01f31e923fe2 60 #define __TRUE 1
Pawel Zarembski 0:01f31e923fe2 61 #endif
Pawel Zarembski 0:01f31e923fe2 62 #ifndef __FALSE
Pawel Zarembski 0:01f31e923fe2 63 #define __FALSE 0
Pawel Zarembski 0:01f31e923fe2 64 #endif
Pawel Zarembski 0:01f31e923fe2 65
Pawel Zarembski 0:01f31e923fe2 66 #ifdef __BIG_ENDIAN
Pawel Zarembski 0:01f31e923fe2 67 #define U32_LE(v) (U32)(__rev(v))
Pawel Zarembski 0:01f31e923fe2 68 #define U16_LE(v) (U16)(__rev(v) >> 16)
Pawel Zarembski 0:01f31e923fe2 69 #define U32_BE(v) (U32)(v)
Pawel Zarembski 0:01f31e923fe2 70 #define U16_BE(v) (U16)(v)
Pawel Zarembski 0:01f31e923fe2 71 #else
Pawel Zarembski 0:01f31e923fe2 72 #define U32_BE(v) (U32)(__rev(v))
Pawel Zarembski 0:01f31e923fe2 73 #define U16_BE(v) (U16)(__rev(v) >> 16)
Pawel Zarembski 0:01f31e923fe2 74 #define U32_LE(v) (U32)(v)
Pawel Zarembski 0:01f31e923fe2 75 #define U16_LE(v) (U16)(v)
Pawel Zarembski 0:01f31e923fe2 76 #endif
Pawel Zarembski 0:01f31e923fe2 77 #define ntohs(v) U16_BE(v)
Pawel Zarembski 0:01f31e923fe2 78 #define ntohl(v) U32_BE(v)
Pawel Zarembski 0:01f31e923fe2 79 #define htons(v) ntohs(v)
Pawel Zarembski 0:01f31e923fe2 80 #define htonl(v) ntohl(v)
Pawel Zarembski 0:01f31e923fe2 81
Pawel Zarembski 0:01f31e923fe2 82 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 83 * RTX Kernel API
Pawel Zarembski 0:01f31e923fe2 84 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 85
Pawel Zarembski 0:01f31e923fe2 86 #ifdef __cplusplus
Pawel Zarembski 0:01f31e923fe2 87 extern "C" {
Pawel Zarembski 0:01f31e923fe2 88 #endif
Pawel Zarembski 0:01f31e923fe2 89
Pawel Zarembski 0:01f31e923fe2 90 /* Definition of Semaphore type */
Pawel Zarembski 0:01f31e923fe2 91 typedef U32 OS_SEM[2];
Pawel Zarembski 0:01f31e923fe2 92
Pawel Zarembski 0:01f31e923fe2 93 /* Definition of Mailbox type */
Pawel Zarembski 0:01f31e923fe2 94 #define os_mbx_declare(name,cnt) U32 name [4 + cnt]
Pawel Zarembski 0:01f31e923fe2 95 typedef U32 OS_MBX[];
Pawel Zarembski 0:01f31e923fe2 96
Pawel Zarembski 0:01f31e923fe2 97 /* Definition of Mutex type */
Pawel Zarembski 0:01f31e923fe2 98 typedef U32 OS_MUT[3];
Pawel Zarembski 0:01f31e923fe2 99
Pawel Zarembski 0:01f31e923fe2 100 /* Task Identification number. */
Pawel Zarembski 0:01f31e923fe2 101 typedef U32 OS_TID;
Pawel Zarembski 0:01f31e923fe2 102
Pawel Zarembski 0:01f31e923fe2 103 /* Function return of system calls returning an object identification */
Pawel Zarembski 0:01f31e923fe2 104 typedef void *OS_ID;
Pawel Zarembski 0:01f31e923fe2 105
Pawel Zarembski 0:01f31e923fe2 106 /* Function return of system calls indicating an event or completion state */
Pawel Zarembski 0:01f31e923fe2 107 typedef U32 OS_RESULT;
Pawel Zarembski 0:01f31e923fe2 108
Pawel Zarembski 0:01f31e923fe2 109 /* Return codes */
Pawel Zarembski 0:01f31e923fe2 110 #define OS_R_TMO 0x01
Pawel Zarembski 0:01f31e923fe2 111 #define OS_R_EVT 0x02
Pawel Zarembski 0:01f31e923fe2 112 #define OS_R_SEM 0x03
Pawel Zarembski 0:01f31e923fe2 113 #define OS_R_MBX 0x04
Pawel Zarembski 0:01f31e923fe2 114 #define OS_R_MUT 0x05
Pawel Zarembski 0:01f31e923fe2 115
Pawel Zarembski 0:01f31e923fe2 116 #define OS_R_OK 0x00
Pawel Zarembski 0:01f31e923fe2 117 #define OS_R_NOK 0xff
Pawel Zarembski 0:01f31e923fe2 118
Pawel Zarembski 0:01f31e923fe2 119 #define OS_TCB_SIZE 48
Pawel Zarembski 0:01f31e923fe2 120 #define OS_TMR_SIZE 8
Pawel Zarembski 0:01f31e923fe2 121
Pawel Zarembski 0:01f31e923fe2 122 /* Error Codes */
Pawel Zarembski 0:01f31e923fe2 123 #define OS_ERR_STK_OVF 1
Pawel Zarembski 0:01f31e923fe2 124 #define OS_ERR_FIFO_OVF 2
Pawel Zarembski 0:01f31e923fe2 125 #define OS_ERR_MBX_OVF 3
Pawel Zarembski 0:01f31e923fe2 126
Pawel Zarembski 0:01f31e923fe2 127 #if !(__TARGET_ARCH_6S_M || __TARGET_ARCH_7_M || __TARGET_ARCH_7E_M)
Pawel Zarembski 0:01f31e923fe2 128
Pawel Zarembski 0:01f31e923fe2 129 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 130 * Functions ARM
Pawel Zarembski 0:01f31e923fe2 131 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 132
Pawel Zarembski 0:01f31e923fe2 133 /* Task Management */
Pawel Zarembski 0:01f31e923fe2 134 #define os_sys_init(tsk) os_sys_init0(tsk,0,NULL)
Pawel Zarembski 0:01f31e923fe2 135 #define os_sys_init_prio(tsk,prio) os_sys_init0(tsk,prio,NULL)
Pawel Zarembski 0:01f31e923fe2 136 #define os_sys_init_user(tsk,prio,stk,size) \
Pawel Zarembski 0:01f31e923fe2 137 os_sys_init0(tsk,prio|(size<<8),stk)
Pawel Zarembski 0:01f31e923fe2 138 #define os_tsk_create(tsk,prio) os_tsk_create0(tsk,prio,NULL,NULL)
Pawel Zarembski 0:01f31e923fe2 139 #define os_tsk_create_user(tsk,prio,stk,size) \
Pawel Zarembski 0:01f31e923fe2 140 os_tsk_create0(tsk,prio|(size<<8),stk,NULL)
Pawel Zarembski 0:01f31e923fe2 141 #define os_tsk_create_ex(tsk,prio,argv) os_tsk_create_ex0(tsk,prio,NULL,argv)
Pawel Zarembski 0:01f31e923fe2 142 #define os_tsk_create_user_ex(tsk,prio,stk,size,argv) \
Pawel Zarembski 0:01f31e923fe2 143 os_tsk_create_ex0(tsk,prio|(size<<8),stk,argv)
Pawel Zarembski 0:01f31e923fe2 144 #define os_tsk_delete_self() os_tsk_delete(0)
Pawel Zarembski 0:01f31e923fe2 145 #define os_tsk_prio_self(prio) os_tsk_prio(0,prio)
Pawel Zarembski 0:01f31e923fe2 146 #define isr_tsk_get() os_tsk_self()
Pawel Zarembski 0:01f31e923fe2 147
Pawel Zarembski 0:01f31e923fe2 148 extern void os_sys_init0 (void (*task)(void), U32 prio_stksz, void *stk);
Pawel Zarembski 0:01f31e923fe2 149 extern OS_TID os_tsk_create0 (void (*task)(void), U32 prio_stksz,
Pawel Zarembski 0:01f31e923fe2 150 void *stk, void *argv);
Pawel Zarembski 0:01f31e923fe2 151 extern OS_TID os_tsk_create_ex0 (void (*task)(void *), U32 prio_stksz,
Pawel Zarembski 0:01f31e923fe2 152 void *stk, void *argv);
Pawel Zarembski 0:01f31e923fe2 153 extern OS_TID os_tsk_self (void);
Pawel Zarembski 0:01f31e923fe2 154 extern void os_tsk_pass (void);
Pawel Zarembski 0:01f31e923fe2 155 extern OS_RESULT os_tsk_prio (OS_TID task_id, U8 new_prio);
Pawel Zarembski 0:01f31e923fe2 156 extern OS_RESULT os_tsk_delete (OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 157
Pawel Zarembski 0:01f31e923fe2 158 /* Event flag Management */
Pawel Zarembski 0:01f31e923fe2 159 #define os_evt_wait_or(wflags,tmo) os_evt_wait(wflags,tmo,__FALSE)
Pawel Zarembski 0:01f31e923fe2 160 #define os_evt_wait_and(wflags,tmo) os_evt_wait(wflags,tmo,__TRUE)
Pawel Zarembski 0:01f31e923fe2 161
Pawel Zarembski 0:01f31e923fe2 162 extern OS_RESULT os_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait);
Pawel Zarembski 0:01f31e923fe2 163 extern void os_evt_set (U16 event_flags, OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 164 extern void os_evt_clr (U16 clear_flags, OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 165 extern void isr_evt_set (U16 event_flags, OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 166 extern U16 os_evt_get (void);
Pawel Zarembski 0:01f31e923fe2 167
Pawel Zarembski 0:01f31e923fe2 168 /* Semaphore Management */
Pawel Zarembski 0:01f31e923fe2 169 extern void os_sem_init (OS_ID semaphore, U16 token_count);
Pawel Zarembski 0:01f31e923fe2 170 extern OS_RESULT os_sem_send (OS_ID semaphore);
Pawel Zarembski 0:01f31e923fe2 171 extern OS_RESULT os_sem_wait (OS_ID semaphore, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 172 extern void isr_sem_send (OS_ID semaphore);
Pawel Zarembski 0:01f31e923fe2 173
Pawel Zarembski 0:01f31e923fe2 174 /* Mailbox Management */
Pawel Zarembski 0:01f31e923fe2 175 #define isr_mbx_check(mbx) os_mbx_check(mbx)
Pawel Zarembski 0:01f31e923fe2 176
Pawel Zarembski 0:01f31e923fe2 177 extern void os_mbx_init (OS_ID mailbox, U16 mbx_size);
Pawel Zarembski 0:01f31e923fe2 178 extern OS_RESULT os_mbx_send (OS_ID mailbox, void *message_ptr, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 179 extern OS_RESULT os_mbx_wait (OS_ID mailbox, void **message, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 180 extern OS_RESULT os_mbx_check (OS_ID mailbox);
Pawel Zarembski 0:01f31e923fe2 181 extern void isr_mbx_send (OS_ID mailbox, void *message_ptr);
Pawel Zarembski 0:01f31e923fe2 182 extern OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message);
Pawel Zarembski 0:01f31e923fe2 183
Pawel Zarembski 0:01f31e923fe2 184 /* Mutex Management */
Pawel Zarembski 0:01f31e923fe2 185 extern void os_mut_init (OS_ID mutex);
Pawel Zarembski 0:01f31e923fe2 186 extern OS_RESULT os_mut_release (OS_ID mutex);
Pawel Zarembski 0:01f31e923fe2 187 extern OS_RESULT os_mut_wait (OS_ID mutex, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 188
Pawel Zarembski 0:01f31e923fe2 189 /* Time Management */
Pawel Zarembski 0:01f31e923fe2 190 extern U32 os_time_get (void);
Pawel Zarembski 0:01f31e923fe2 191 extern void os_dly_wait (U16 delay_time);
Pawel Zarembski 0:01f31e923fe2 192 extern void os_itv_set (U16 interval_time);
Pawel Zarembski 0:01f31e923fe2 193 extern void os_itv_wait (void);
Pawel Zarembski 0:01f31e923fe2 194
Pawel Zarembski 0:01f31e923fe2 195 /* User Timer Management */
Pawel Zarembski 0:01f31e923fe2 196 extern OS_ID os_tmr_create (U16 tcnt, U16 info);
Pawel Zarembski 0:01f31e923fe2 197 extern OS_ID os_tmr_kill (OS_ID timer);
Pawel Zarembski 0:01f31e923fe2 198
Pawel Zarembski 0:01f31e923fe2 199 /* System Functions */
Pawel Zarembski 0:01f31e923fe2 200 extern U32 os_suspend (void);
Pawel Zarembski 0:01f31e923fe2 201 extern void os_resume (U32 sleep_time);
Pawel Zarembski 0:01f31e923fe2 202 extern void tsk_lock (void) __swi (5);
Pawel Zarembski 0:01f31e923fe2 203 extern void tsk_unlock (void);
Pawel Zarembski 0:01f31e923fe2 204
Pawel Zarembski 0:01f31e923fe2 205 /* Fixed Memory Block Management Functions */
Pawel Zarembski 0:01f31e923fe2 206 extern int _init_box (void *box_mem, U32 box_size, U32 blk_size);
Pawel Zarembski 0:01f31e923fe2 207 extern void *_alloc_box (void *box_mem) __swi (1);
Pawel Zarembski 0:01f31e923fe2 208 extern void *_calloc_box (void *box_mem);
Pawel Zarembski 0:01f31e923fe2 209 extern int _free_box (void *box_mem, void *box) __swi (2);
Pawel Zarembski 0:01f31e923fe2 210
Pawel Zarembski 0:01f31e923fe2 211 #else
Pawel Zarembski 0:01f31e923fe2 212
Pawel Zarembski 0:01f31e923fe2 213 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 214 * Functions Cortex-M
Pawel Zarembski 0:01f31e923fe2 215 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 216
Pawel Zarembski 0:01f31e923fe2 217 #define __SVC_0 __svc_indirect(0)
Pawel Zarembski 0:01f31e923fe2 218
Pawel Zarembski 0:01f31e923fe2 219 /* Task Management */
Pawel Zarembski 0:01f31e923fe2 220 extern void os_set_env (void);
Pawel Zarembski 0:01f31e923fe2 221 extern void rt_sys_init (void (*task)(void), U8 priority, void *stk);
Pawel Zarembski 0:01f31e923fe2 222 extern void rt_tsk_pass (void);
Pawel Zarembski 0:01f31e923fe2 223 extern OS_TID rt_tsk_self (void);
Pawel Zarembski 0:01f31e923fe2 224 extern OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio);
Pawel Zarembski 0:01f31e923fe2 225 extern OS_TID rt_tsk_create (void (*task)(void), U8 priority, void *stk, void *argv);
Pawel Zarembski 0:01f31e923fe2 226 extern OS_RESULT rt_tsk_delete (OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 227
Pawel Zarembski 0:01f31e923fe2 228 #define os_sys_init(tsk) os_set_env(); \
Pawel Zarembski 0:01f31e923fe2 229 _os_sys_init((U32)rt_sys_init,tsk,0,NULL)
Pawel Zarembski 0:01f31e923fe2 230 #define os_sys_init_user(tsk,prio,stk,size) \
Pawel Zarembski 0:01f31e923fe2 231 os_set_env(); \
Pawel Zarembski 0:01f31e923fe2 232 _os_sys_init((U32)rt_sys_init,tsk,prio|(size<<8),stk)
Pawel Zarembski 0:01f31e923fe2 233 #define os_sys_init_prio(tsk,prio) os_set_env(); \
Pawel Zarembski 0:01f31e923fe2 234 _os_sys_init((U32)rt_sys_init,tsk,prio,NULL)
Pawel Zarembski 0:01f31e923fe2 235 #define os_tsk_create(tsk,prio) _os_tsk_create((U32)rt_tsk_create,tsk,prio,NULL,NULL)
Pawel Zarembski 0:01f31e923fe2 236 #define os_tsk_create_user(tsk,prio,stk,size) \
Pawel Zarembski 0:01f31e923fe2 237 _os_tsk_create((U32)rt_tsk_create,tsk,prio|(size<<8),stk,NULL)
Pawel Zarembski 0:01f31e923fe2 238 #define os_tsk_create_ex(tsk,prio,argv) _os_tsk_create_ex((U32)rt_tsk_create,tsk,prio,NULL,argv)
Pawel Zarembski 0:01f31e923fe2 239 #define os_tsk_create_user_ex(tsk,prio,stk,size,argv) \
Pawel Zarembski 0:01f31e923fe2 240 _os_tsk_create_ex((U32)rt_tsk_create,tsk,prio|(size<<8),stk,argv)
Pawel Zarembski 0:01f31e923fe2 241 #define os_tsk_self() _os_tsk_self((U32)rt_tsk_self)
Pawel Zarembski 0:01f31e923fe2 242 #define os_tsk_pass() _os_tsk_pass((U32)rt_tsk_pass)
Pawel Zarembski 0:01f31e923fe2 243 #define os_tsk_prio(task_id,new_prio) _os_tsk_prio((U32)rt_tsk_prio,task_id,new_prio)
Pawel Zarembski 0:01f31e923fe2 244 #define os_tsk_prio_self(prio) _os_tsk_prio((U32)rt_tsk_prio,0,prio)
Pawel Zarembski 0:01f31e923fe2 245 #define os_tsk_delete(task_id) _os_tsk_delete((U32)rt_tsk_delete,task_id)
Pawel Zarembski 0:01f31e923fe2 246 #define os_tsk_delete_self() _os_tsk_delete((U32)rt_tsk_delete, 0)
Pawel Zarembski 0:01f31e923fe2 247 #define isr_tsk_get() rt_tsk_self()
Pawel Zarembski 0:01f31e923fe2 248
Pawel Zarembski 0:01f31e923fe2 249 extern void _os_sys_init(U32 p, void (*task)(void), U32 prio_stksz,
Pawel Zarembski 0:01f31e923fe2 250 void *stk) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 251 extern OS_TID _os_tsk_create (U32 p, void (*task)(void), U32 prio_stksz,
Pawel Zarembski 0:01f31e923fe2 252 void *stk, void *argv) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 253 extern OS_TID _os_tsk_create_ex (U32 p, void (*task)(void *), U32 prio_stksz,
Pawel Zarembski 0:01f31e923fe2 254 void *stk, void *argv) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 255 extern OS_TID _os_tsk_self (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 256 extern void _os_tsk_pass (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 257 extern OS_RESULT _os_tsk_prio (U32 p, OS_TID task_id, U8 new_prio) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 258 extern OS_RESULT _os_tsk_delete (U32 p, OS_TID task_id) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 259
Pawel Zarembski 0:01f31e923fe2 260 /* Event flag Management */
Pawel Zarembski 0:01f31e923fe2 261 extern OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait);
Pawel Zarembski 0:01f31e923fe2 262 extern void rt_evt_set (U16 event_flags, OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 263 extern void rt_evt_clr (U16 clear_flags, OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 264 extern U16 rt_evt_get (void);
Pawel Zarembski 0:01f31e923fe2 265
Pawel Zarembski 0:01f31e923fe2 266 #define os_evt_wait_or(wflags,tmo) _os_evt_wait((U32)rt_evt_wait,wflags,tmo,__FALSE)
Pawel Zarembski 0:01f31e923fe2 267 #define os_evt_wait_and(wflags,tmo) _os_evt_wait((U32)rt_evt_wait,wflags,tmo,__TRUE)
Pawel Zarembski 0:01f31e923fe2 268 #define os_evt_set(evt_flags,task_id) _os_evt_set((U32)rt_evt_set,evt_flags,task_id)
Pawel Zarembski 0:01f31e923fe2 269 #define os_evt_clr(clr_flags,task_id) _os_evt_clr((U32)rt_evt_clr,clr_flags,task_id)
Pawel Zarembski 0:01f31e923fe2 270 #define os_evt_get() _os_evt_get((U32)rt_evt_get)
Pawel Zarembski 0:01f31e923fe2 271
Pawel Zarembski 0:01f31e923fe2 272 extern OS_RESULT _os_evt_wait(U32 p, U16 wait_flags, U16 timeout,
Pawel Zarembski 0:01f31e923fe2 273 BOOL and_wait) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 274 extern void _os_evt_set (U32 p, U16 event_flags, OS_TID task_id) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 275 extern void _os_evt_clr (U32 p, U16 clear_flags, OS_TID task_id) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 276 extern U16 _os_evt_get (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 277 extern void isr_evt_set (U16 event_flags, OS_TID task_id);
Pawel Zarembski 0:01f31e923fe2 278
Pawel Zarembski 0:01f31e923fe2 279 /* Semaphore Management */
Pawel Zarembski 0:01f31e923fe2 280 extern void rt_sem_init (OS_ID semaphore, U16 token_count);
Pawel Zarembski 0:01f31e923fe2 281 extern OS_RESULT rt_sem_send (OS_ID semaphore);
Pawel Zarembski 0:01f31e923fe2 282 extern OS_RESULT rt_sem_wait (OS_ID semaphore, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 283
Pawel Zarembski 0:01f31e923fe2 284 #define os_sem_init(sem,t_count) _os_sem_init((U32)rt_sem_init,sem,t_count)
Pawel Zarembski 0:01f31e923fe2 285 #define os_sem_send(sem) _os_sem_send((U32)rt_sem_send,sem)
Pawel Zarembski 0:01f31e923fe2 286 #define os_sem_wait(sem,tmo) _os_sem_wait((U32)rt_sem_wait,sem,tmo)
Pawel Zarembski 0:01f31e923fe2 287
Pawel Zarembski 0:01f31e923fe2 288 extern void _os_sem_init (U32 p, OS_ID semaphore,
Pawel Zarembski 0:01f31e923fe2 289 U16 token_count) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 290 extern OS_RESULT _os_sem_send (U32 p, OS_ID semaphore) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 291 extern OS_RESULT _os_sem_wait (U32 p, OS_ID semaphore, U16 timeout) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 292 extern void isr_sem_send (OS_ID semaphore);
Pawel Zarembski 0:01f31e923fe2 293
Pawel Zarembski 0:01f31e923fe2 294 /* Mailbox Management */
Pawel Zarembski 0:01f31e923fe2 295 extern void rt_mbx_init (OS_ID mailbox, U16 mbx_size);
Pawel Zarembski 0:01f31e923fe2 296 extern OS_RESULT rt_mbx_send (OS_ID mailbox, void *p_msg, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 297 extern OS_RESULT rt_mbx_wait (OS_ID mailbox, void **message, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 298 extern OS_RESULT rt_mbx_check (OS_ID mailbox);
Pawel Zarembski 0:01f31e923fe2 299
Pawel Zarembski 0:01f31e923fe2 300 #define os_mbx_init(mbx,mbx_size) _os_mbx_init((U32)rt_mbx_init,mbx,mbx_size)
Pawel Zarembski 0:01f31e923fe2 301 #define os_mbx_send(mbx,p_msg,tmo) _os_mbx_send((U32)rt_mbx_send,mbx,p_msg,tmo)
Pawel Zarembski 0:01f31e923fe2 302 #define os_mbx_wait(mbx,message,tmo) _os_mbx_wait((U32)rt_mbx_wait,mbx,message,tmo)
Pawel Zarembski 0:01f31e923fe2 303 #define os_mbx_check(mbx) _os_mbx_check((U32)rt_mbx_check,mbx)
Pawel Zarembski 0:01f31e923fe2 304 #define isr_mbx_check(mbx) rt_mbx_check(mbx)
Pawel Zarembski 0:01f31e923fe2 305
Pawel Zarembski 0:01f31e923fe2 306 extern void _os_mbx_init (U32 p, OS_ID mailbox, U16 mbx_size) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 307 extern OS_RESULT _os_mbx_send (U32 p, OS_ID mailbox, void *message_ptr,
Pawel Zarembski 0:01f31e923fe2 308 U16 timeout) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 309 extern OS_RESULT _os_mbx_wait (U32 p, OS_ID mailbox, void **message,
Pawel Zarembski 0:01f31e923fe2 310 U16 timeout) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 311 extern OS_RESULT _os_mbx_check (U32 p, OS_ID mailbox) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 312 extern void isr_mbx_send (OS_ID mailbox, void *message_ptr);
Pawel Zarembski 0:01f31e923fe2 313 extern OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message);
Pawel Zarembski 0:01f31e923fe2 314
Pawel Zarembski 0:01f31e923fe2 315 /* Mutex Management */
Pawel Zarembski 0:01f31e923fe2 316 extern void rt_mut_init (OS_ID mutex);
Pawel Zarembski 0:01f31e923fe2 317 extern OS_RESULT rt_mut_release (OS_ID mutex);
Pawel Zarembski 0:01f31e923fe2 318 extern OS_RESULT rt_mut_wait (OS_ID mutex, U16 timeout);
Pawel Zarembski 0:01f31e923fe2 319
Pawel Zarembski 0:01f31e923fe2 320 #define os_mut_init(mutex) _os_mut_init((U32)rt_mut_init,mutex)
Pawel Zarembski 0:01f31e923fe2 321 #define os_mut_release(mutex) _os_mut_release((U32)rt_mut_release,mutex)
Pawel Zarembski 0:01f31e923fe2 322 #define os_mut_wait(mutex,timeout) _os_mut_wait((U32)rt_mut_wait,mutex,timeout)
Pawel Zarembski 0:01f31e923fe2 323
Pawel Zarembski 0:01f31e923fe2 324 extern void _os_mut_init (U32 p, OS_ID mutex) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 325 extern OS_RESULT _os_mut_release (U32 p, OS_ID mutex) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 326 extern OS_RESULT _os_mut_wait (U32 p, OS_ID mutex, U16 timeout) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 327
Pawel Zarembski 0:01f31e923fe2 328 /* Time Management */
Pawel Zarembski 0:01f31e923fe2 329 extern U32 rt_time_get (void);
Pawel Zarembski 0:01f31e923fe2 330 extern void rt_dly_wait (U16 delay_time);
Pawel Zarembski 0:01f31e923fe2 331 extern void rt_itv_set (U16 interval_time);
Pawel Zarembski 0:01f31e923fe2 332 extern void rt_itv_wait (void);
Pawel Zarembski 0:01f31e923fe2 333
Pawel Zarembski 0:01f31e923fe2 334 #define os_time_get() _os_time_get((U32)rt_time_get)
Pawel Zarembski 0:01f31e923fe2 335 #define os_dly_wait(delay_time) _os_dly_wait((U32)rt_dly_wait,delay_time)
Pawel Zarembski 0:01f31e923fe2 336 #define os_itv_set(interval_time) _os_itv_set((U32)rt_itv_set,interval_time)
Pawel Zarembski 0:01f31e923fe2 337 #define os_itv_wait() _os_itv_wait((U32)rt_itv_wait)
Pawel Zarembski 0:01f31e923fe2 338
Pawel Zarembski 0:01f31e923fe2 339 extern U32 _os_time_get (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 340 extern void _os_dly_wait (U32 p, U16 delay_time) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 341 extern void _os_itv_set (U32 p, U16 interval_time) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 342 extern void _os_itv_wait (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 343
Pawel Zarembski 0:01f31e923fe2 344 /* User Timer Management */
Pawel Zarembski 0:01f31e923fe2 345 extern OS_ID rt_tmr_create (U16 tcnt, U16 info);
Pawel Zarembski 0:01f31e923fe2 346 extern OS_ID rt_tmr_kill (OS_ID timer);
Pawel Zarembski 0:01f31e923fe2 347
Pawel Zarembski 0:01f31e923fe2 348 #define os_tmr_create(tcnt,info) _os_tmr_create((U32)rt_tmr_create,tcnt,info)
Pawel Zarembski 0:01f31e923fe2 349 #define os_tmr_kill(timer) _os_tmr_kill((U32)rt_tmr_kill,timer)
Pawel Zarembski 0:01f31e923fe2 350
Pawel Zarembski 0:01f31e923fe2 351 extern OS_ID _os_tmr_create (U32 p, U16 tcnt, U16 info) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 352 extern OS_ID _os_tmr_kill (U32 p, OS_ID timer) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 353
Pawel Zarembski 0:01f31e923fe2 354 /* System Functions */
Pawel Zarembski 0:01f31e923fe2 355 extern U32 rt_suspend (void);
Pawel Zarembski 0:01f31e923fe2 356 extern void rt_resume (U32 sleep_time);
Pawel Zarembski 0:01f31e923fe2 357 extern void rt_tsk_lock (void);
Pawel Zarembski 0:01f31e923fe2 358 extern void rt_tsk_unlock (void);
Pawel Zarembski 0:01f31e923fe2 359
Pawel Zarembski 0:01f31e923fe2 360 #define os_suspend() _os_suspend((U32)rt_suspend)
Pawel Zarembski 0:01f31e923fe2 361 #define os_resume(sleep_time) _os_resume((U32)rt_resume,sleep_time)
Pawel Zarembski 0:01f31e923fe2 362 #define tsk_lock() _os_tsk_lock((U32)rt_tsk_lock)
Pawel Zarembski 0:01f31e923fe2 363 #define tsk_unlock() _os_tsk_unlock((U32)rt_tsk_unlock)
Pawel Zarembski 0:01f31e923fe2 364
Pawel Zarembski 0:01f31e923fe2 365 extern U32 _os_suspend (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 366 extern void _os_resume (U32 p, U32 sleep_time) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 367 extern void _os_tsk_lock (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 368 extern void _os_tsk_unlock (U32 p) __SVC_0;
Pawel Zarembski 0:01f31e923fe2 369
Pawel Zarembski 0:01f31e923fe2 370 /* Fixed Memory Block Management Functions */
Pawel Zarembski 0:01f31e923fe2 371 extern int _init_box (void *box_mem, U32 box_size, U32 blk_size);
Pawel Zarembski 0:01f31e923fe2 372 extern void *_alloc_box (void *box_mem);
Pawel Zarembski 0:01f31e923fe2 373 extern void *_calloc_box (void *box_mem);
Pawel Zarembski 0:01f31e923fe2 374 extern int _free_box (void *box_mem, void *box);
Pawel Zarembski 0:01f31e923fe2 375
Pawel Zarembski 0:01f31e923fe2 376 #endif
Pawel Zarembski 0:01f31e923fe2 377
Pawel Zarembski 0:01f31e923fe2 378 #define BOX_ALIGN_8 0x80000000
Pawel Zarembski 0:01f31e923fe2 379 #define _declare_box(pool,size,cnt) U32 pool[(((size)+3)/4)*(cnt) + 3]
Pawel Zarembski 0:01f31e923fe2 380 #define _declare_box8(pool,size,cnt) U64 pool[(((size)+7)/8)*(cnt) + 2]
Pawel Zarembski 0:01f31e923fe2 381 #define _init_box8(pool,size,bsize) _init_box (pool,size,bsize | BOX_ALIGN_8)
Pawel Zarembski 0:01f31e923fe2 382
Pawel Zarembski 0:01f31e923fe2 383 /* For compatibility with older configurations.*/
Pawel Zarembski 0:01f31e923fe2 384 #define os_stk_overflow os_error
Pawel Zarembski 0:01f31e923fe2 385
Pawel Zarembski 0:01f31e923fe2 386 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 387 * Flash File System API
Pawel Zarembski 0:01f31e923fe2 388 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 389
Pawel Zarembski 0:01f31e923fe2 390 typedef struct { /* RL Time format (FFS, TCPnet) */
Pawel Zarembski 0:01f31e923fe2 391 U8 hr; /* Hours [0..23] */
Pawel Zarembski 0:01f31e923fe2 392 U8 min; /* Minutes [0..59] */
Pawel Zarembski 0:01f31e923fe2 393 U8 sec; /* Seconds [0..59] */
Pawel Zarembski 0:01f31e923fe2 394 U8 day; /* Day [1..31] */
Pawel Zarembski 0:01f31e923fe2 395 U8 mon; /* Month [1..12] */
Pawel Zarembski 0:01f31e923fe2 396 U16 year; /* Year [1980..2107] */
Pawel Zarembski 0:01f31e923fe2 397 } RL_TIME;
Pawel Zarembski 0:01f31e923fe2 398
Pawel Zarembski 0:01f31e923fe2 399 typedef struct { /* Search info record */
Pawel Zarembski 0:01f31e923fe2 400 S8 name[256]; /* Name */
Pawel Zarembski 0:01f31e923fe2 401 U32 size; /* File size in bytes */
Pawel Zarembski 0:01f31e923fe2 402 U16 fileID; /* System Identification */
Pawel Zarembski 0:01f31e923fe2 403 U8 attrib; /* Attributes */
Pawel Zarembski 0:01f31e923fe2 404 RL_TIME time; /* Create/Modify Time */
Pawel Zarembski 0:01f31e923fe2 405 } FINFO;
Pawel Zarembski 0:01f31e923fe2 406
Pawel Zarembski 0:01f31e923fe2 407 extern int finit (const char *drive);
Pawel Zarembski 0:01f31e923fe2 408 extern int funinit (const char *drive);
Pawel Zarembski 0:01f31e923fe2 409 extern int fdelete (const char *filename);
Pawel Zarembski 0:01f31e923fe2 410 extern int frename (const char *oldname, const char *newname);
Pawel Zarembski 0:01f31e923fe2 411 extern int ffind (const char *pattern, FINFO *info);
Pawel Zarembski 0:01f31e923fe2 412 extern U64 ffree (const char *drive);
Pawel Zarembski 0:01f31e923fe2 413 extern int fformat (const char *drive);
Pawel Zarembski 0:01f31e923fe2 414 extern int fanalyse (const char *drive);
Pawel Zarembski 0:01f31e923fe2 415 extern int fcheck (const char *drive);
Pawel Zarembski 0:01f31e923fe2 416 extern int fdefrag (const char *drive);
Pawel Zarembski 0:01f31e923fe2 417 extern int fattrib (const char *par, const char *path);
Pawel Zarembski 0:01f31e923fe2 418 extern int fvol (const char *drive, char *buf);
Pawel Zarembski 0:01f31e923fe2 419
Pawel Zarembski 0:01f31e923fe2 420 /* The following macros provide for common functions */
Pawel Zarembski 0:01f31e923fe2 421 #define unlink(fn) fdelete(fn);
Pawel Zarembski 0:01f31e923fe2 422
Pawel Zarembski 0:01f31e923fe2 423 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 424 * TCPnet API
Pawel Zarembski 0:01f31e923fe2 425 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 426
Pawel Zarembski 0:01f31e923fe2 427 /* UDP Options */
Pawel Zarembski 0:01f31e923fe2 428 #define UDP_OPT_SEND_CS 0x01 /* Calculate Checksum for UDP send frames */
Pawel Zarembski 0:01f31e923fe2 429 #define UDP_OPT_CHK_CS 0x02 /* Verify Checksum for received UDP frames */
Pawel Zarembski 0:01f31e923fe2 430
Pawel Zarembski 0:01f31e923fe2 431 /* TCP Socket Types */
Pawel Zarembski 0:01f31e923fe2 432 #define TCP_TYPE_SERVER 0x01 /* Socket Type Server (open for listening) */
Pawel Zarembski 0:01f31e923fe2 433 #define TCP_TYPE_CLIENT 0x02 /* Socket Type Client (initiate connect) */
Pawel Zarembski 0:01f31e923fe2 434 #define TCP_TYPE_DELAY_ACK 0x04 /* Socket Type Delayed Acknowledge */
Pawel Zarembski 0:01f31e923fe2 435 #define TCP_TYPE_FLOW_CTRL 0x08 /* Socket Type Flow Control */
Pawel Zarembski 0:01f31e923fe2 436 #define TCP_TYPE_KEEP_ALIVE 0x10 /* Socket Type Keep Alive */
Pawel Zarembski 0:01f31e923fe2 437 #define TCP_TYPE_CLIENT_SERVER (TCP_TYPE_SERVER | TCP_TYPE_CLIENT)
Pawel Zarembski 0:01f31e923fe2 438
Pawel Zarembski 0:01f31e923fe2 439 /* TCP Callback Events */
Pawel Zarembski 0:01f31e923fe2 440 #define TCP_EVT_CONREQ 0 /* Connect request received event */
Pawel Zarembski 0:01f31e923fe2 441 #define TCP_EVT_CONNECT 1 /* Connection established event */
Pawel Zarembski 0:01f31e923fe2 442 #define TCP_EVT_CLOSE 2 /* Connection was properly closed */
Pawel Zarembski 0:01f31e923fe2 443 #define TCP_EVT_ABORT 3 /* Connection is for some reason aborted */
Pawel Zarembski 0:01f31e923fe2 444 #define TCP_EVT_ACK 4 /* Previously send data acknowledged */
Pawel Zarembski 0:01f31e923fe2 445 #define TCP_EVT_DATA 5 /* Data received event */
Pawel Zarembski 0:01f31e923fe2 446
Pawel Zarembski 0:01f31e923fe2 447 /* TCP States */
Pawel Zarembski 0:01f31e923fe2 448 #define TCP_STATE_FREE 0 /* Entry is free and unused */
Pawel Zarembski 0:01f31e923fe2 449 #define TCP_STATE_CLOSED 1 /* Entry allocated, socket still closed */
Pawel Zarembski 0:01f31e923fe2 450 #define TCP_STATE_LISTEN 2 /* Socket waiting for incoming connection */
Pawel Zarembski 0:01f31e923fe2 451 #define TCP_STATE_SYN_REC 3 /* SYN frame received */
Pawel Zarembski 0:01f31e923fe2 452 #define TCP_STATE_SYN_SENT 4 /* SYN packet sent to establish a connect. */
Pawel Zarembski 0:01f31e923fe2 453 #define TCP_STATE_FINW1 5 /* Tcp_close started FIN packet was sent */
Pawel Zarembski 0:01f31e923fe2 454 #define TCP_STATE_FINW2 6 /* Our FIN ack-ed, waiting for remote FIN */
Pawel Zarembski 0:01f31e923fe2 455 #define TCP_STATE_CLOSING 7 /* Received FIN independently of our FIN */
Pawel Zarembski 0:01f31e923fe2 456 #define TCP_STATE_LAST_ACK 8 /* Waiting for last ACK for our FIN */
Pawel Zarembski 0:01f31e923fe2 457 #define TCP_STATE_TWAIT 9 /* Timed waiting for 2MSL */
Pawel Zarembski 0:01f31e923fe2 458 #define TCP_STATE_CONNECT 10 /* TCP Connection established */
Pawel Zarembski 0:01f31e923fe2 459
Pawel Zarembski 0:01f31e923fe2 460 /* BSD Socket Address Family */
Pawel Zarembski 0:01f31e923fe2 461 #define AF_UNSPEC 0 /* Unspecified */
Pawel Zarembski 0:01f31e923fe2 462 #define AF_INET 1 /* Internet Address Family (UDP, TCP) */
Pawel Zarembski 0:01f31e923fe2 463 #define AF_NETBIOS 2 /* NetBios-style addresses */
Pawel Zarembski 0:01f31e923fe2 464
Pawel Zarembski 0:01f31e923fe2 465 /* BSD Protocol families, same as address families */
Pawel Zarembski 0:01f31e923fe2 466 #define PF_UNSPEC AF_UNSPEC
Pawel Zarembski 0:01f31e923fe2 467 #define PF_INET AF_INET
Pawel Zarembski 0:01f31e923fe2 468 #define PF_NETBIOS AF_NETBIOS
Pawel Zarembski 0:01f31e923fe2 469
Pawel Zarembski 0:01f31e923fe2 470 /* BSD Socket Type */
Pawel Zarembski 0:01f31e923fe2 471 #define SOCK_STREAM 1 /* Stream Socket (Connection oriented) */
Pawel Zarembski 0:01f31e923fe2 472 #define SOCK_DGRAM 2 /* Datagram Socket (Connectionless) */
Pawel Zarembski 0:01f31e923fe2 473
Pawel Zarembski 0:01f31e923fe2 474 /* BSD Socket Protocol */
Pawel Zarembski 0:01f31e923fe2 475 #define IPPROTO_TCP 1 /* TCP Protocol */
Pawel Zarembski 0:01f31e923fe2 476 #define IPPROTO_UDP 2 /* UDP Protocol */
Pawel Zarembski 0:01f31e923fe2 477
Pawel Zarembski 0:01f31e923fe2 478 /* BSD Internet Addresses */
Pawel Zarembski 0:01f31e923fe2 479 #define INADDR_ANY 0x00000000 /* All IP addresses accepted */
Pawel Zarembski 0:01f31e923fe2 480 #define INADDR_NONE 0xffffffff /* No IP address accepted */
Pawel Zarembski 0:01f31e923fe2 481
Pawel Zarembski 0:01f31e923fe2 482 /* BSD Socket Return values */
Pawel Zarembski 0:01f31e923fe2 483 #define SCK_SUCCESS 0 /* Success */
Pawel Zarembski 0:01f31e923fe2 484 #define SCK_ERROR (-1) /* General Error */
Pawel Zarembski 0:01f31e923fe2 485 #define SCK_EINVALID (-2) /* Invalid socket descriptor */
Pawel Zarembski 0:01f31e923fe2 486 #define SCK_EINVALIDPARA (-3) /* Invalid parameter */
Pawel Zarembski 0:01f31e923fe2 487 #define SCK_EWOULDBLOCK (-4) /* It would have blocked. */
Pawel Zarembski 0:01f31e923fe2 488 #define SCK_EMEMNOTAVAIL (-5) /* Not enough memory in memory pool */
Pawel Zarembski 0:01f31e923fe2 489 #define SCK_ECLOSED (-6) /* Connection is closed or aborted */
Pawel Zarembski 0:01f31e923fe2 490 #define SCK_ELOCKED (-7) /* Socket is locked in RTX environment */
Pawel Zarembski 0:01f31e923fe2 491 #define SCK_ETIMEOUT (-8) /* Socket, Host Resolver timeout */
Pawel Zarembski 0:01f31e923fe2 492 #define SCK_EINPROGRESS (-9) /* Host Name resolving in progress */
Pawel Zarembski 0:01f31e923fe2 493 #define SCK_ENONAME (-10) /* Host Name not existing */
Pawel Zarembski 0:01f31e923fe2 494
Pawel Zarembski 0:01f31e923fe2 495 /* BSD Socket flags parameter */
Pawel Zarembski 0:01f31e923fe2 496 #define MSG_DONTWAIT 0x01 /* Enables non-blocking operation */
Pawel Zarembski 0:01f31e923fe2 497 #define MSG_PEEK 0x02 /* Peeks at the incoming data */
Pawel Zarembski 0:01f31e923fe2 498
Pawel Zarembski 0:01f31e923fe2 499 /* BSD Socket ioctl commands */
Pawel Zarembski 0:01f31e923fe2 500 #define FIONBIO 1 /* Set mode (blocking/non-blocking) */
Pawel Zarembski 0:01f31e923fe2 501 #define FIO_DELAY_ACK 2 /* Set DELAY_ACK mode for stream socket */
Pawel Zarembski 0:01f31e923fe2 502 #define FIO_KEEP_ALIVE 3 /* Set KEEP_ALIVE mode for stream socket */
Pawel Zarembski 0:01f31e923fe2 503 #define FIO_FLOW_CTRL 4 /* Set FLOW_CTRL mode for stream socket */
Pawel Zarembski 0:01f31e923fe2 504
Pawel Zarembski 0:01f31e923fe2 505 /* ICMP (ping) Callback Events */
Pawel Zarembski 0:01f31e923fe2 506 #define ICMP_EVT_SUCCESS 0 /* Pinged Host responded */
Pawel Zarembski 0:01f31e923fe2 507 #define ICMP_EVT_TIMEOUT 1 /* Timeout, no ping response received */
Pawel Zarembski 0:01f31e923fe2 508
Pawel Zarembski 0:01f31e923fe2 509 /* DNS Client Callback Events */
Pawel Zarembski 0:01f31e923fe2 510 #define DNS_EVT_SUCCESS 0 /* Host name successfully resolved */
Pawel Zarembski 0:01f31e923fe2 511 #define DNS_EVT_NONAME 1 /* DNS Error, no such name */
Pawel Zarembski 0:01f31e923fe2 512 #define DNS_EVT_TIMEOUT 2 /* Timeout resolving host */
Pawel Zarembski 0:01f31e923fe2 513 #define DNS_EVT_ERROR 3 /* Erroneous response packet */
Pawel Zarembski 0:01f31e923fe2 514
Pawel Zarembski 0:01f31e923fe2 515 /* DNS 'get_host_by_name()' result codes */
Pawel Zarembski 0:01f31e923fe2 516 #define DNS_RES_OK 0 /* Resolver successfully started */
Pawel Zarembski 0:01f31e923fe2 517 #define DNS_ERROR_BUSY 1 /* Resolver busy, can't process request */
Pawel Zarembski 0:01f31e923fe2 518 #define DNS_ERROR_LABEL 2 /* Label in Hostname not valid */
Pawel Zarembski 0:01f31e923fe2 519 #define DNS_ERROR_NAME 3 /* Entire Hostname not valid */
Pawel Zarembski 0:01f31e923fe2 520 #define DNS_ERROR_NOSRV 4 /* Prim. DNS server not specified (0.0.0.0)*/
Pawel Zarembski 0:01f31e923fe2 521 #define DNS_ERROR_PARAM 5 /* Invalid parameter */
Pawel Zarembski 0:01f31e923fe2 522
Pawel Zarembski 0:01f31e923fe2 523 /* SMTP Client Callback Events */
Pawel Zarembski 0:01f31e923fe2 524 #define SMTP_EVT_SUCCESS 0 /* Email successfully sent */
Pawel Zarembski 0:01f31e923fe2 525 #define SMTP_EVT_TIMEOUT 1 /* Timeout sending email */
Pawel Zarembski 0:01f31e923fe2 526 #define SMTP_EVT_ERROR 2 /* Error when sending email */
Pawel Zarembski 0:01f31e923fe2 527
Pawel Zarembski 0:01f31e923fe2 528 /* FTP Client Commands */
Pawel Zarembski 0:01f31e923fe2 529 #define FTPC_CMD_PUT 0 /* Puts a file on FTP server */
Pawel Zarembski 0:01f31e923fe2 530 #define FTPC_CMD_GET 1 /* Retrieves a file from FTP server */
Pawel Zarembski 0:01f31e923fe2 531 #define FTPC_CMD_APPEND 2 /* Append file on FTP server (with create) */
Pawel Zarembski 0:01f31e923fe2 532 #define FTPC_CMD_DELETE 3 /* Deletes a file on FTP server */
Pawel Zarembski 0:01f31e923fe2 533 #define FTPC_CMD_LIST 4 /* Lists files stored on FTP server */
Pawel Zarembski 0:01f31e923fe2 534 #define FTPC_CMD_RENAME 5 /* Renames a file on FTP server */
Pawel Zarembski 0:01f31e923fe2 535 #define FTPC_CMD_MKDIR 6 /* Makes a directory on FTP server */
Pawel Zarembski 0:01f31e923fe2 536 #define FTPC_CMD_RMDIR 7 /* Removes an empty directory on FTP server*/
Pawel Zarembski 0:01f31e923fe2 537
Pawel Zarembski 0:01f31e923fe2 538 /* FTP Client Callback Events */
Pawel Zarembski 0:01f31e923fe2 539 #define FTPC_EVT_SUCCESS 0 /* File operation successful */
Pawel Zarembski 0:01f31e923fe2 540 #define FTPC_EVT_TIMEOUT 1 /* Timeout on file operation */
Pawel Zarembski 0:01f31e923fe2 541 #define FTPC_EVT_LOGINFAIL 2 /* Login error, username/passw invalid */
Pawel Zarembski 0:01f31e923fe2 542 #define FTPC_EVT_NOACCESS 3 /* File access not allowed */
Pawel Zarembski 0:01f31e923fe2 543 #define FTPC_EVT_NOTFOUND 4 /* File not found */
Pawel Zarembski 0:01f31e923fe2 544 #define FTPC_EVT_NOPATH 5 /* Working directory path not found */
Pawel Zarembski 0:01f31e923fe2 545 #define FTPC_EVT_ERRLOCAL 6 /* Local file open error */
Pawel Zarembski 0:01f31e923fe2 546 #define FTPC_EVT_ERROR 7 /* Generic FTP client error */
Pawel Zarembski 0:01f31e923fe2 547
Pawel Zarembski 0:01f31e923fe2 548 /* TFTP Client Callback Events */
Pawel Zarembski 0:01f31e923fe2 549 #define TFTPC_EVT_SUCCESS 0 /* File operation successful */
Pawel Zarembski 0:01f31e923fe2 550 #define TFTPC_EVT_TIMEOUT 1 /* Timeout on file operation */
Pawel Zarembski 0:01f31e923fe2 551 #define TFTPC_EVT_NOACCESS 2 /* File access not allowed */
Pawel Zarembski 0:01f31e923fe2 552 #define TFTPC_EVT_NOTFOUND 3 /* File not found */
Pawel Zarembski 0:01f31e923fe2 553 #define TFTPC_EVT_DISKFULL 4 /* Disk full (local or remote) */
Pawel Zarembski 0:01f31e923fe2 554 #define TFTPC_EVT_ERROR 5 /* Generic TFTP client error */
Pawel Zarembski 0:01f31e923fe2 555
Pawel Zarembski 0:01f31e923fe2 556 /* ARP Cache Entry types */
Pawel Zarembski 0:01f31e923fe2 557 #define ARP_FIXED_IP 0 /* Fixed IP adrs is refreshed after tout */
Pawel Zarembski 0:01f31e923fe2 558 #define ARP_TEMP_IP 1 /* Temp adrs is removed after timeout */
Pawel Zarembski 0:01f31e923fe2 559
Pawel Zarembski 0:01f31e923fe2 560 /* BSD Socket typedef's */
Pawel Zarembski 0:01f31e923fe2 561 typedef struct sockaddr { /* << Generic Socket Address structure >> */
Pawel Zarembski 0:01f31e923fe2 562 U16 sa_family; /* Address family */
Pawel Zarembski 0:01f31e923fe2 563 char sa_data[14]; /* Direct address (up to 14 bytes) */
Pawel Zarembski 0:01f31e923fe2 564 } SOCKADDR;
Pawel Zarembski 0:01f31e923fe2 565
Pawel Zarembski 0:01f31e923fe2 566 #pragma push
Pawel Zarembski 0:01f31e923fe2 567 #pragma anon_unions
Pawel Zarembski 0:01f31e923fe2 568
Pawel Zarembski 0:01f31e923fe2 569 typedef struct in_addr { /* << Generic IPv4 Address structure >> */
Pawel Zarembski 0:01f31e923fe2 570 union {
Pawel Zarembski 0:01f31e923fe2 571 struct {
Pawel Zarembski 0:01f31e923fe2 572 U8 s_b1,s_b2,s_b3,s_b4; /* IP address, byte access */
Pawel Zarembski 0:01f31e923fe2 573 };
Pawel Zarembski 0:01f31e923fe2 574 struct {
Pawel Zarembski 0:01f31e923fe2 575 U16 s_w1,s_w2; /* IP address, short int access */
Pawel Zarembski 0:01f31e923fe2 576 };
Pawel Zarembski 0:01f31e923fe2 577 U32 s_addr; /* IP address in network byte order */
Pawel Zarembski 0:01f31e923fe2 578 };
Pawel Zarembski 0:01f31e923fe2 579 } IN_ADDR;
Pawel Zarembski 0:01f31e923fe2 580 #pragma pop
Pawel Zarembski 0:01f31e923fe2 581
Pawel Zarembski 0:01f31e923fe2 582 typedef struct sockaddr_in { /* << IPv4 Socket Address structure >> */
Pawel Zarembski 0:01f31e923fe2 583 S16 sin_family; /* Socket domain */
Pawel Zarembski 0:01f31e923fe2 584 U16 sin_port; /* Port */
Pawel Zarembski 0:01f31e923fe2 585 IN_ADDR sin_addr; /* IP address */
Pawel Zarembski 0:01f31e923fe2 586 S8 sin_zero[8]; /* reserved */
Pawel Zarembski 0:01f31e923fe2 587 } SOCKADDR_IN;
Pawel Zarembski 0:01f31e923fe2 588
Pawel Zarembski 0:01f31e923fe2 589 typedef struct hostent { /* << BSD Host Entry structure >> */
Pawel Zarembski 0:01f31e923fe2 590 char *h_name; /* Official name of host */
Pawel Zarembski 0:01f31e923fe2 591 char **h_aliases; /* Pointer to an array of alias names */
Pawel Zarembski 0:01f31e923fe2 592 S16 h_addrtype; /* Address Type: AF_INET, AF_NETBIOS */
Pawel Zarembski 0:01f31e923fe2 593 S16 h_length; /* Length of address in bytes */
Pawel Zarembski 0:01f31e923fe2 594 char **h_addr_list; /* Pointer to an array of IPv4 addresses */
Pawel Zarembski 0:01f31e923fe2 595 } HOSTENT;
Pawel Zarembski 0:01f31e923fe2 596
Pawel Zarembski 0:01f31e923fe2 597 extern void init_TcpNet (void);
Pawel Zarembski 0:01f31e923fe2 598 extern BOOL main_TcpNet (void);
Pawel Zarembski 0:01f31e923fe2 599 extern void timer_tick (void);
Pawel Zarembski 0:01f31e923fe2 600 extern U8 udp_get_socket (U8 tos, U8 opt,
Pawel Zarembski 0:01f31e923fe2 601 U16 (*listener)(U8 socket, U8 *remip, U16 port, U8 *buf, U16 len));
Pawel Zarembski 0:01f31e923fe2 602 extern BOOL udp_release_socket (U8 socket);
Pawel Zarembski 0:01f31e923fe2 603 extern BOOL udp_open (U8 socket, U16 locport);
Pawel Zarembski 0:01f31e923fe2 604 extern BOOL udp_close (U8 socket);
Pawel Zarembski 0:01f31e923fe2 605 extern BOOL udp_mcast_ttl (U8 socket, U8 ttl);
Pawel Zarembski 0:01f31e923fe2 606 extern U8 *udp_get_buf (U16 size);
Pawel Zarembski 0:01f31e923fe2 607 extern BOOL udp_send (U8 socket, U8 *remip, U16 remport, U8 *buf, U16 dlen);
Pawel Zarembski 0:01f31e923fe2 608 extern U8 tcp_get_socket (U8 type, U8 tos, U16 tout,
Pawel Zarembski 0:01f31e923fe2 609 U16 (*listener)(U8 socket, U8 event, U8 *buf, U16 len));
Pawel Zarembski 0:01f31e923fe2 610 extern BOOL tcp_release_socket (U8 socket);
Pawel Zarembski 0:01f31e923fe2 611 extern BOOL tcp_listen (U8 socket, U16 locport);
Pawel Zarembski 0:01f31e923fe2 612 extern BOOL tcp_connect (U8 socket, U8 *remip, U16 remport, U16 locport);
Pawel Zarembski 0:01f31e923fe2 613 extern U8 *tcp_get_buf (U16 size);
Pawel Zarembski 0:01f31e923fe2 614 extern U16 tcp_max_dsize (U8 socket);
Pawel Zarembski 0:01f31e923fe2 615 extern BOOL tcp_check_send (U8 socket);
Pawel Zarembski 0:01f31e923fe2 616 extern U8 tcp_get_state (U8 socket);
Pawel Zarembski 0:01f31e923fe2 617 extern BOOL tcp_send (U8 socket, U8 *buf, U16 dlen);
Pawel Zarembski 0:01f31e923fe2 618 extern BOOL tcp_close (U8 socket);
Pawel Zarembski 0:01f31e923fe2 619 extern BOOL tcp_abort (U8 socket);
Pawel Zarembski 0:01f31e923fe2 620 extern void tcp_reset_window (U8 socket);
Pawel Zarembski 0:01f31e923fe2 621 extern BOOL arp_cache_ip (U8 *ipadr, U8 type);
Pawel Zarembski 0:01f31e923fe2 622 extern BOOL arp_cache_mac (U8 *hwadr);
Pawel Zarembski 0:01f31e923fe2 623 extern void ppp_listen (const char *user, const char *passw);
Pawel Zarembski 0:01f31e923fe2 624 extern void ppp_connect (const char *dialnum, const char *user, const char *passw);
Pawel Zarembski 0:01f31e923fe2 625 extern void ppp_close (void);
Pawel Zarembski 0:01f31e923fe2 626 extern BOOL ppp_is_up (void);
Pawel Zarembski 0:01f31e923fe2 627 extern void slip_listen (void);
Pawel Zarembski 0:01f31e923fe2 628 extern void slip_connect (const char *dialnum);
Pawel Zarembski 0:01f31e923fe2 629 extern void slip_close (void);
Pawel Zarembski 0:01f31e923fe2 630 extern BOOL slip_is_up (void);
Pawel Zarembski 0:01f31e923fe2 631 extern U8 get_host_by_name (U8 *hostn, void (*cbfunc)(U8 event, U8 *host_ip));
Pawel Zarembski 0:01f31e923fe2 632 extern BOOL smtp_connect (U8 *ipadr, U16 port, void (*cbfunc)(U8 event));
Pawel Zarembski 0:01f31e923fe2 633 extern void dhcp_disable (void);
Pawel Zarembski 0:01f31e923fe2 634 extern BOOL igmp_join (U8 *group_ip);
Pawel Zarembski 0:01f31e923fe2 635 extern BOOL igmp_leave (U8 *group_ip);
Pawel Zarembski 0:01f31e923fe2 636 extern BOOL snmp_trap (U8 *manager_ip, U8 gen_trap, U8 spec_trap, U16 *obj_list);
Pawel Zarembski 0:01f31e923fe2 637 extern BOOL snmp_set_community (const char *community);
Pawel Zarembski 0:01f31e923fe2 638 extern BOOL icmp_ping (U8 *remip, void (*cbfunc)(U8 event));
Pawel Zarembski 0:01f31e923fe2 639 extern BOOL ftpc_connect (U8 *ipadr, U16 port, U8 command, void (*cbfunc)(U8 event));
Pawel Zarembski 0:01f31e923fe2 640 extern BOOL tftpc_put (U8 *ipadr, U16 port,
Pawel Zarembski 0:01f31e923fe2 641 const char *src, const char *dst, void (*cbfunc)(U8 event));
Pawel Zarembski 0:01f31e923fe2 642 extern BOOL tftpc_get (U8 *ipadr, U16 port,
Pawel Zarembski 0:01f31e923fe2 643 const char *src, const char *dst, void (*cbfunc)(U8 event));
Pawel Zarembski 0:01f31e923fe2 644 extern BOOL sntp_get_time (U8 *ipadr, void (*cbfunc)(U32 utc_time));
Pawel Zarembski 0:01f31e923fe2 645
Pawel Zarembski 0:01f31e923fe2 646 /* BSD Socket API */
Pawel Zarembski 0:01f31e923fe2 647 extern int socket (int family, int type, int protocol);
Pawel Zarembski 0:01f31e923fe2 648 extern int bind (int sock, const SOCKADDR *addr, int addrlen);
Pawel Zarembski 0:01f31e923fe2 649 extern int listen (int sock, int backlog);
Pawel Zarembski 0:01f31e923fe2 650 extern int accept (int sock, SOCKADDR *addr, int *addrlen);
Pawel Zarembski 0:01f31e923fe2 651 extern int connect (int sock, SOCKADDR *addr, int addrlen);
Pawel Zarembski 0:01f31e923fe2 652 extern int send (int sock, const char *buf, int len, int flags);
Pawel Zarembski 0:01f31e923fe2 653 extern int sendto (int sock, const char *buf, int len, int flags, SOCKADDR *to, int tolen);
Pawel Zarembski 0:01f31e923fe2 654 extern int recv (int sock, char *buf, int len, int flags);
Pawel Zarembski 0:01f31e923fe2 655 extern int recvfrom (int sock, char *buf, int len, int flags, SOCKADDR *from, int *fromlen);
Pawel Zarembski 0:01f31e923fe2 656 extern int closesocket (int sock);
Pawel Zarembski 0:01f31e923fe2 657 extern int getpeername (int sock, SOCKADDR *name, int *namelen);
Pawel Zarembski 0:01f31e923fe2 658 extern int getsockname (int sock, SOCKADDR *name, int *namelen);
Pawel Zarembski 0:01f31e923fe2 659 extern int ioctlsocket (int sock, long cmd, unsigned long *argp);
Pawel Zarembski 0:01f31e923fe2 660 extern HOSTENT *gethostbyname (const char *name, int *err);
Pawel Zarembski 0:01f31e923fe2 661
Pawel Zarembski 0:01f31e923fe2 662 #ifdef __cplusplus
Pawel Zarembski 0:01f31e923fe2 663 }
Pawel Zarembski 0:01f31e923fe2 664 #endif
Pawel Zarembski 0:01f31e923fe2 665
Pawel Zarembski 0:01f31e923fe2 666 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 667 * end of file
Pawel Zarembski 0:01f31e923fe2 668 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 669
Pawel Zarembski 0:01f31e923fe2 670 #endif
Pawel Zarembski 0:01f31e923fe2 671