1b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*
2b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
3b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
4b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Licensed under the Apache License, Version 2.0 (the "License");
5b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * you may not use this file except in compliance with the License.
6b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * You may obtain a copy of the License at
7b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
8b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *     http://www.apache.org/licenses/LICENSE-2.0
9b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
10b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Unless required by applicable law or agreed to in writing, software
11b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * distributed under the License is distributed on an "AS IS" BASIS,
12b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * See the License for the specific language governing permissions and
14b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * limitations under the License.
15b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
16b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
17b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @file picoos.h
18b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
19b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
20b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * All rights reserved.
21b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
22b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * History:
23b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * - 2009-04-20 -- initial version
24b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
25b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
26b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
27b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @addtogroup picoos
28b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
29b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * <b> Operating system generalization module </b>\n
30b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
31b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen*/
32b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
33b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#ifndef PICOOS_H_
34b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_H_
35b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
36b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picodefs.h"
37b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picopal.h"
38b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
39b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#ifdef __cplusplus
40b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern "C" {
41b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
42b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#if 0
43b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}
44b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
45b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
46b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
47b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* some "switch"  used in picopal and in picocep ... */
48b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_DIV_USE_INV PICOPAL_DIV_USE_INV
49b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
50b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *************************************************/
51b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* types                                           */
52b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *************************************************/
53b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
54b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_uint8   picoos_uint8;
55b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_uint16  picoos_uint16;
56b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_uint32  picoos_uint32;
57b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
58b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_int8    picoos_int8;
59b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_int16   picoos_int16;
60b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_int32   picoos_int32;
61b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
62b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_double  picoos_double;
63b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_single  picoos_single;
64b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
65b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_char    picoos_char;
66b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_uchar   picoos_uchar;
67b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
68b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_uint8   picoos_bool;
69b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
70b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_objsize_t picoos_objsize_t;
71b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picopal_ptrdiff_t picoos_ptrdiff_t;
72b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
73b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *************************************************/
74b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* functions                                       */
75b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *************************************************/
76b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
77b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
78b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_int32 picoos_atoi(const picoos_char *);
79b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_int8 picoos_strcmp(const picoos_char *, const picoos_char *);
80b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_int8 picoos_strncmp(const picoos_char *a, const picoos_char *b, picoos_objsize_t siz);
81b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint32 picoos_strlen(const picoos_char *);
82b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_char * picoos_strchr(const picoos_char *, picoos_char);
83b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_char *picoos_strstr(const picoos_char *s, const picoos_char *substr);
84b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_int16 picoos_slprintf(picoos_char * b, picoos_uint32 bsize, const picoos_char *f, ...);
85b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_char * picoos_strcpy(picoos_char *, const picoos_char *);
86b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_char * picoos_strcat(picoos_char *, const picoos_char *);
87b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
88b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* copies 'length' bytes from 'src' to 'dest'. (regions may be overlapping) no error checks! */
89b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid * picoos_mem_copy(const void * src, void * dst,  picoos_objsize_t length);
90b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
91b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* safe versions */
92b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_objsize_t picoos_strlcpy(picoos_char *dst, const picoos_char *src, picoos_objsize_t siz);
93b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid * picoos_mem_set(void * dest, picoos_uint8 byte_val, picoos_objsize_t length);
94b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
95b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_double picoos_cos(const picoos_double cos_arg);
96b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_double picoos_sin(const picoos_double sin_arg);
97b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_double picoos_fabs(const picoos_double fabs_arg);
98b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
99b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_double picoos_quick_exp(const picoos_double y);
100b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
101b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
102b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_get_sep_part_str (picoos_char string[], picoos_int32 stringlen, picoos_int32 * ind, picoos_char sepCh, picoos_char part[], picoos_int32 maxsize, picoos_uint8 * done);
103b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_string_to_uint32 (picoos_char str[], picoos_uint32 * res);
104b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_string_to_int32 (picoos_char str[], picoos_int32 * res);
105b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
106b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
107b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* "Common"                                                        */
108b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
109b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* picoos_common is a collection of basic functionalities that must be globally accesible from every "big" function.
110b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * It includes pointers to the MemoryManasger, ExceptionManager and a list of open files. */
111b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
112b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct memory_manager * picoos_MemoryManager;
113b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_exception_manager * picoos_ExceptionManager;
114b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_file * picoos_File;
115b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
116b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
117b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**  object   : Common
118b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *   shortcut : common
119b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
120b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
121b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_common * picoos_Common;
122b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
123b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* the picoos_common structure itself is exported so no access functions are needed. Handle with care! (might be changed later) */
124b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_common {
125b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_ExceptionManager em;
126b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_MemoryManager mm;
127b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_File fileList;
128b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} picoos_common_t;
129b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
130b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_Common picoos_newCommon(picoos_MemoryManager mm);
131b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
132b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_disposeCommon(picoos_MemoryManager mm, picoos_Common * this);
133b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
134b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
135b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
136b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Memory Management                                               */
137b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
138b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
139b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char * byte_ptr_t;
140b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
141b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_ALIGN_SIZE 8
142b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
143b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
144b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
145b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid * picoos_raw_malloc(byte_ptr_t raw_mem,
146b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_objsize_t raw_mem_size, picoos_objsize_t alloc_size,
147b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        byte_ptr_t * rest_mem, picoos_objsize_t * rest_mem_size);
148b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
149b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
150b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Creates a new memory manager object for the specified raw memory
151b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * block. 'enableProtMem' enables or disables memory protection
152b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * functionality; if disabled, picoos_protectMem() has no effect.
153b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
154b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_MemoryManager picoos_newMemoryManager(
155b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        void *raw_memory,
156b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_objsize_t size,
157b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_bool enableMemProt);
158b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
159b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
160b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
161b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_disposeMemoryManager(picoos_MemoryManager * mm);
162b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
163b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
164b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid * picoos_allocate(picoos_MemoryManager this, picoos_objsize_t byteSize);
165b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_deallocate(picoos_MemoryManager this, void * * adr);
166b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
167b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* the following memory manager routines are for testing and
168b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen   debugging purposes */
169b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
170b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
171b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Same as picoos_allocate, but write access to the memory block may be
172b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * prohibited by a subsequent call to picoos_protectMem().
173b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
174b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid *picoos_allocProtMem(picoos_MemoryManager mm, picoos_objsize_t byteSize);
175b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
176b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
177b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Releases a memory block previously allocated by picoos_allocProtMem().
178b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
179b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_deallocProtMem(picoos_MemoryManager mm, void **addr);
180b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
181b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
182b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Enables or disables write protection of a memory block previously
183b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * allocated by picoos_allocProtMem(). If write protection is enabled,
184b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * any subsequent write access will cause a segmentation fault.
185b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
186b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_protectMem(
187b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_MemoryManager mm,
188b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        void *addr,
189b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_objsize_t len,
190b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_bool enable);
191b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
192b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_getMemUsage(
193b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_MemoryManager this,
194b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_bool resetIncremental,
195b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int32 *usedBytes,
196b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int32 *incrUsedBytes,
197b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int32 *maxUsedBytes);
198b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
199b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_showMemUsage(
200b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_MemoryManager this,
201b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_bool incremental,
202b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_bool resetIncremental);
203b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
204b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
205b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Exception Management                                                */
206b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
207b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**  object   : ExceptionManager
208b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *   shortcut : em
209b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
210b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
211b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
212b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
213b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_MAX_EXC_MSG_LEN 512
214b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_MAX_WARN_MSG_LEN 64
215b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_MAX_NUM_WARNINGS 8
216b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
217b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_setErrorMsg(picoos_char * dst, picoos_objsize_t siz,
218b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int16 code, picoos_char * base, const picoos_char *fmt, ...);
219b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
220b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
221b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_ExceptionManager picoos_newExceptionManager(picoos_MemoryManager mm);
222b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
223b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_disposeExceptionManager(picoos_MemoryManager mm,
224b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_ExceptionManager * this);
225b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
226b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
227b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_emReset(picoos_ExceptionManager this);
228b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
229b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* For convenience, this function returns the resulting exception code of 'this'
230b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * (as would be returned by emGetExceptionCode).
231b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * The return value therefore is NOT the status of raising
232b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * the error! */
233b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_emRaiseException(picoos_ExceptionManager this,
234b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pico_status_t exceptionCode, picoos_char * baseMessage, picoos_char * fmt, ...);
235b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
236b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_emGetExceptionCode(picoos_ExceptionManager this);
237b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
238b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_emGetExceptionMessage(picoos_ExceptionManager this, picoos_char * msg, picoos_uint16 maxsize);
239b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
240b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_emRaiseWarning(picoos_ExceptionManager this,
241b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pico_status_t warningCode, picoos_char * baseMessage, picoos_char * fmt, ...);
242b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
243b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8 picoos_emGetNumOfWarnings(picoos_ExceptionManager this);
244b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
245b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_emGetWarningCode(picoos_ExceptionManager this, picoos_uint8 warnNum);
246b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
247b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_emGetWarningMessage(picoos_ExceptionManager this, picoos_uint8 warnNum, picoos_char * msg, picoos_uint16 maxsize);
248b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
249b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
250b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
251b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
252b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
253b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* File Access                                                     */
254b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
255b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
256b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define picoos_MaxFileNameLen 512
257b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define picoos_MaxKeyLen 512
258b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define picoos_MaxPathLen 512
259b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define picoos_MaxPathListLen 2048
260b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
261b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char picoos_Key[picoos_MaxKeyLen];
262b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char picoos_FileName[picoos_MaxFileNameLen];
263b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char picoos_Path[picoos_MaxPathLen];
264b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char picoos_PathList[picoos_MaxPathListLen];
265b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
266b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
267b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* ***** Sequential binary file access ******/
268b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
269b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Remark: 'ReadByte', 'ReadBytes' and 'ReadVar' may be mixed;
270b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen 'WriteByte', 'WriteBytes' and 'WriteVar' may be mixed. */
271b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
272b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Open existing binary file for read access. */
273b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8 picoos_OpenBinary(picoos_Common g, picoos_File * f, picoos_char name[]);
274b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
275b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
276b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Read next byte from file 'f'. */
277b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8  picoos_ReadByte(picoos_File f, picoos_uint8 * by);
278b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
279b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Read next 'len' bytes from 'f' into 'bytes'; 'len' returns the
280b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen number of bytes actually read (may be smaller than requested
281b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen length if 'bytes' is too small to hold all bytes or at end of file).
282b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen Remark: 'bytes' is compabtible with any variable of any size. */
283b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8  picoos_ReadBytes(picoos_File f, picoos_uint8 bytes[],
284b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint32 * len);
285b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
286b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
287b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Create new binary file.
288b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen If 'key' is not empty, the file is encrypted with 'key'. */
289b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8 picoos_CreateBinary(picoos_Common g, picoos_File * f, picoos_char name[]);
290b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
291b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8  picoos_WriteByte(picoos_File f, picoos_char by);
292b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
293b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Writes 'len' bytes from 'bytes' onto file 'f'; 'len' returns
294b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen the number of bytes actually written. */
295b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8  picoos_WriteBytes(picoos_File f, const picoos_char bytes[],
296b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int32 * len);
297b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
298b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
299b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Close previously opened binary file. */
300b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8 picoos_CloseBinary(picoos_Common g, picoos_File * f);
301b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
302b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
303b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
304b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
305b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
306b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
307b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_le_int16 (picoos_File file, picoos_int16 * val);
308b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_le_uint16 (picoos_File file, picoos_uint16 * val);
309b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_le_uint32 (picoos_File file, picoos_uint32 * val);
310b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
311b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
312b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_pi_uint16 (picoos_File file, picoos_uint16 * val);
313b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_pi_uint32 (picoos_File file, picoos_uint32 * val);
314b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
315b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_write_le_uint16 (picoos_File file, picoos_uint16 val);
316b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_write_le_uint32 (picoos_File file, picoos_uint32 val);
317b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
318b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*
319b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_write_pi_uint32 (picoos_File file, const picoos_uint32 val);
320b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
321b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_write_pi_uint16 (picoos_File file, const picoos_uint16 val);
322b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen*/
323b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
324b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
325b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* **************************************************************************************/
326b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *** general file routines *****/
327b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
328b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Returns whether end of file was encountered in previous
329b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen read operation. */
330b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool picoos_Eof(picoos_File f);
331b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
332b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*  sets the file pointer to
333b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen 'pos' bytes from beginning (first byte = byte 0). This
334b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen routine should only be used for binary files. */
335b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool  picoos_SetPos(picoos_File f, picoos_int32 pos);
336b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
337b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Get position from file 'f'. */
338b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool picoos_GetPos(picoos_File f, picoos_uint32 * pos);
339b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
340b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Returns the length of the file in bytes. */
341b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool picoos_FileLength(picoos_File f, picoos_uint32 * len);
342b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
343b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Return full name of file 'f'. */
344b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool picoos_Name(picoos_File f, picoos_char name[], picoos_uint32 maxsize);
345b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
346b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Returns whether file 'name' exists or not. */
347b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool picoos_FileExists(picoos_Common g, picoos_char name[] /*, picoos_char ckey[] */);
348b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
349b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Delete a file. */
350b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool  picoos_Delete(picoos_char name[]);
351b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
352b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Rename a file. */
353b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_bool  picoos_Rename(picoos_char oldName[], picoos_char newName[]);
354b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
355b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
356b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
357b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* Sampled Data Files                                                    */
358b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
359b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
360b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define SAMPLE_FREQ_16KHZ (picoos_uint32) 16000
361b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
362b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef enum {
363b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FILE_TYPE_WAV,
364b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FILE_TYPE_AU,
365b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FILE_TYPE_RAW,
366b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FILE_TYPE_OTHER
367b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} wave_file_type_t;
368b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
369b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef enum {
370b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FORMAT_TAG_LIN = 1, /**< linear 16-bit encoding */
371b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FORMAT_TAG_ALAW = 6, /**< a-law encoding, 8 bit */
372b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    FORMAT_TAG_ULAW = 7 /**< u-law encoding, 8 bit */
373b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* there are many more */
374b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} wave_format_tag_t;
375b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
376b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
377b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef enum {
378b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* values corresponding RIFF wFormatTag */
379b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    PICOOS_ENC_LIN = FORMAT_TAG_LIN,  /**< linear 16-bit encoding; standard */
380b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    PICOOS_ENC_ALAW = FORMAT_TAG_ALAW, /**< a-law encoding, 8 bit */
381b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    PICOOS_ENC_ULAW = FORMAT_TAG_ULAW, /**< u-law encoding, 8 bit */
382b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* values outside RIFF wFormatTag values (above 4100) */
383b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    PICOOS_ENC_OTHER = 5000  /**< other; (treated as raw) */
384b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }  picoos_encoding_t;
385b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
386b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_sd_file * picoos_SDFile;
387b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
388b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* SDFile input functions */
389b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
390b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* orig. comment from SDInOut.def
391b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             Opens sampled data file 'fileName' for input and returns
392b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             the encoding 'enc' of the file, sampling rate 'sf',
393b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             nr of samples 'nrSamples', and a handle to the opened file
394b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             in 'sdFile'.
395b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
396b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             If 'fileName' is empty, the input is taken from the direct
397b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             acoustic input using the sampling rate specified by
398b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             "SetRawDefaults". In this case, 'encoding' returns 'EncLin',
399b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             and 'nrSamples' returns 0.
400b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
401b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             The file format is taken from the file name extension:
402b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                ".wav"           --> wav file
403b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                ".au"            --> au file
404b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                other extensions --> headerless files
405b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
406b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             For wav and au files, the sampling rate and encoding are taken
407b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             from the file header and returned in 'sf' and 'enc'. For
408b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             headerless files, 'sf' and 'enc' are taken from the
409b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             most recently set default values (procedure SetRawDefaults).
410b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
411b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             'done' returns whether the sampled data file was successfully
412b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen             opened. */
413b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_sdfOpenIn (picoos_Common g, picoos_SDFile * sdFile, picoos_char fileName[], picoos_uint32 * sf, picoos_encoding_t * enc, picoos_uint32 * nrSamples);
414b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
415b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
416b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_sdfGetSamples (picoos_SDFile sdFile, picoos_uint32 start, picoos_uint32 * nrSamples, picoos_int16 samples[]);
417b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
418b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
419b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_sdfCloseIn (picoos_Common g, picoos_SDFile * sdFile);
420b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
421b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
422b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* SDFile output functions*/
423b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
424b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_sdfOpenOut (picoos_Common g, picoos_SDFile * sdFile, picoos_char fileName[], int sf, picoos_encoding_t enc);
425b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
426b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
427b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_sdfPutSamples (picoos_SDFile sdFile, picoos_uint32 nrSamples, picoos_int16 samples[]);
428b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
429b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*
430b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_AbortOutput (picoos_SDFile sdFile);
431b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
432b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
433b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_ResumeOutput (picoos_SDFile sdFile);
434b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
435b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
436b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_FlushOutput (picoos_SDFile sdFile);
437b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen*/
438b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
439b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern picoos_bool picoos_sdfCloseOut (picoos_Common g, picoos_SDFile * sdFile);
440b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
441b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
442b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
443b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* File Headers                                                    */
444b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
445b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
446b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_MAX_FIELD_STRING_LEN 32 /* including terminating char */
447b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
448b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_MAX_NUM_HEADER_FIELDS 10
449b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_NUM_BASIC_HEADER_FIELDS 5
450b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
451b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_HEADER_NAME 0
452b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_HEADER_VERSION 1
453b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_HEADER_DATE 2
454b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_HEADER_TIME 3
455b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_HEADER_CONTENT_TYPE 4
456b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
457b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOOS_MAX_HEADER_STRING_LEN (PICOOS_MAX_NUM_HEADER_FIELDS * (2 * PICOOS_MAX_FIELD_STRING_LEN))
458b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
459b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char picoos_field_string_t[PICOOS_MAX_FIELD_STRING_LEN];
460b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
461b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef picoos_char picoos_header_string_t[PICOOS_MAX_HEADER_STRING_LEN];
462b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
463b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef enum {PICOOS_FIELD_IGNORE, PICOOS_FIELD_EQUAL, PICOOS_FIELD_COMPAT} picoos_compare_op_t;
464b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
465b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* private */
466b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_file_header_field {
467b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_field_string_t key;
468b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_field_string_t value;
469b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_compare_op_t op;
470b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} picoos_file_header_field_t;
471b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
472b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* public */
473b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_file_header * picoos_FileHeader;
474b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct picoos_file_header {
475b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 numFields;
476b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_file_header_field_t  field[PICOOS_MAX_NUM_HEADER_FIELDS];
477b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} picoos_file_header_t;
478b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
479b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
480b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_clearHeader(picoos_FileHeader header);
481b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
482b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_setHeaderField(picoos_FileHeader header, picoos_uint8 index, picoos_char * key, picoos_char * value, picoos_compare_op_t op);
483b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
484b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* caller has to make sure allocated space at key and value are large enough to hold a picoos_field_string */
485b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_getHeaderField(picoos_FileHeader header, picoos_uint8 index, picoos_field_string_t key, picoos_field_string_t value, picoos_compare_op_t * op);
486b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
487b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* caller has to make sure allocated space at str is large enough to hold the header in question */
488b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*
489b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_hdrToString(picoos_FileHeader header, picoos_header_string_t str);
490b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen*/
491b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
492b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_hdrParseHeader(picoos_FileHeader header, picoos_header_string_t str);
493b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
494b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_getSVOXHeaderString(picoos_char * str, picoos_uint8 * len, picoos_uint32 maxlen);
495b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
496b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_readPicoHeader(picoos_File f, picoos_uint32 * headerlen);
497b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
498b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
499b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
500b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
501b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* String search and compare operations                            */
502b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
503b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
504b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
505b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8 picoos_has_extension(const picoos_char *str, const picoos_char *suf);
506b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
507b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
508b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* String/Number Manipulations  (might be moved to picopal)          */
509b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
510b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
511b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_string_to_int32(picoos_char str[],
512b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int32 * res);
513b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
514b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_string_to_uint32(picoos_char str[],
515b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint32 * res);
516b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
517b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* 'stringlen' is the part of input string to be considered, possibly not containing NULLC (e.g. result of strlen).
518b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *  'maxsize' is the maximal size of 'part' including a byte for the terminating NULLC! */
519b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_get_sep_part_str(picoos_char string[],
520b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int32 stringlen, picoos_int32 * ind, picoos_char sepCh,
521b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_char part[], picoos_int32 maxsize, picoos_uint8 * done);
522b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
523b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* searches for the first contiguous string of printable characters (> ' ') inside fromStr, possibly skipping
524b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * chars <= ' ') and returns it in toStr.
525b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * fromStr is assumed to be NULLC terminated and toStr is forced to be NULLC terminated within maxsize.
526b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * The search is started at *pos inside fromStr and at return, *pos is the position within fromStr after the
527b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * found string, or the position after the end of fromStr, if no string was found.
528b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * the function returns TRUE if a string was found and fitted toStr, or FALSE otherwise. */
529b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicoos_uint8 picoos_get_str (picoos_char * fromStr, picoos_uint32 * pos, picoos_char * toStr, picoos_objsize_t maxsize);
530b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
531b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
532b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_mem_pi_uint16 (picoos_uint8 * data, picoos_uint32 * pos, picoos_uint16 * val);
533b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
534b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_read_mem_pi_uint32 (picoos_uint8 * data, picoos_uint32 * pos, picoos_uint32 * val);
535b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
536b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpico_status_t picoos_write_mem_pi_uint16 (picoos_uint8 * data, picoos_uint32 * pos, picoos_uint16 val);
537b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
538b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
539b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
540b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* timer function          */
541b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* *****************************************************************/
542b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
543b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenvoid picoos_get_timer(picopal_uint32 * sec, picopal_uint32 * usec);
544b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
545b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#ifdef __cplusplus
546b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}
547b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
548b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
549b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
550b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif /*PICOOS_H_*/
551