• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguiwindowsc翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

BASIC compiler/interpreter for PIC32MX/MZ-80K


Commit MetaInfo

Revision2bc5befaf4129de46fceb01e6ca335f6185fa5e1 (tree)
Time2019-05-16 08:03:21
AuthorKatsumi <kmorimatsu@sour...>
CommiterKatsumi

Log Message

Provide video, file-system etc for CLIB.

Change Summary

Incremental Difference

--- a/mips/clib/clib.c
+++ b/mips/clib/clib.c
@@ -11,12 +11,9 @@
1111
1212 /*
1313 * g_data[] contains the data from MachiKania compiler for this library
14- * g_data[0] : lib_calloc_memory
15- * g_data[1] : lib_delete
16- * g_data[2] : g_gp
17- * g_data[3-]: Reserved for higher version of CLIB
14+ * See the comment in clib.h
1815 */
19-void** g_data;
16+void*** g_data;
2017
2118 /*
2219 * clibdata[] contains the data from this library for MachiKania compiler
@@ -41,7 +38,7 @@ const void* const clibdata[]={
4138 * in linker script must be changed.
4239 * This function is called twice, for exchanging data and for calling init().
4340 */
44-void* CLIBINIT clib_init(void** data){
41+void* CLIBINIT clib_init(void*** data){
4542 // Store pointer to data
4643 if (data) g_data=data;
4744 // Call user initialization routine
@@ -51,15 +48,126 @@ void* CLIBINIT clib_init(void** data){
5148 }
5249
5350 // call lib_calloc_memory() function
54-void* clib_calloc(int size, void** g_data){
55- asm volatile("lw $v0,0($a1)");
56- asm volatile("lw $gp,8($a1)");
51+void* __attribute__((section("clib_calloc"))) clib_calloc(int size, void*** g_data){
52+ asm volatile("lw $v1,0($a1)"); // g_data[0]
53+ asm volatile("lw $v0,4($a1)"); // g_data[1]
54+ asm volatile("lw $v0,0($v0)"); // g_data[1][0]
55+ asm volatile("lw $gp,0($v1)"); // g_data[0][0]
5756 asm volatile("jr $v0");
5857 }
5958
6059 // call lib_delete() function
61-void clib_free(void* addr, void** g_data){
62- asm volatile("lw $v0,4($a1)");
63- asm volatile("lw $gp,8($a1)");
60+void __attribute__((section("clib_free"))) clib_free(void* addr, void*** g_data){
61+ asm volatile("lw $v1,0($a1)"); // g_data[0]
62+ asm volatile("lw $v0,4($a1)"); // g_data[1]
63+ asm volatile("lw $v0,4($v0)"); // g_data[1][1]
64+ asm volatile("lw $gp,0($v1)"); // g_data[0][0]
6465 asm volatile("jr $v0");
6566 }
67+
68+// Function to get g_data in $v0
69+void*** __attribute__((section("clib_g_data"))) clib_g_data(){ return g_data; }
70+
71+// Video functions below use following macro
72+// $v0=g_data;
73+// lw $v1,0($v0) // g_data[0]
74+// lw $v0,12($v0) // g_data[3]
75+// lw $v0,"x"($v0) // g_data[3][x/4]
76+// lw $gp,0($v1) // g_data[0][0]
77+// jalr $v0
78+#define machikania_video(x) \
79+ clib_g_data();\
80+ asm volatile("lw $v1,0($v0)");\
81+ asm volatile("lw $v0,12($v0)");\
82+ asm volatile("lw $v0,"x"($v0)");\
83+ asm volatile("lw $gp,0($v1)");\
84+ asm volatile("jalr $v0")
85+
86+void __attribute__((section("start_composite"))) start_composite(void)
87+{ machikania_video("0"); }
88+void __attribute__((section("stop_composite"))) stop_composite(void)
89+{ machikania_video("4"); }
90+void __attribute__((section("printchar"))) printchar(unsigned char n)
91+{ machikania_video("8"); }
92+void __attribute__((section("printstr"))) printstr(unsigned char *s)
93+{ machikania_video("12"); }
94+void __attribute__((section("printnum"))) printnum(unsigned int n)
95+{ machikania_video("16"); }
96+void __attribute__((section("printnum2"))) printnum2(unsigned int n,unsigned char e)
97+{ machikania_video("20"); }
98+void __attribute__((section("cls"))) cls(void)
99+{ machikania_video("24"); }
100+void __attribute__((section("vramscroll"))) vramscroll(void)
101+{ machikania_video("28"); }
102+void __attribute__((section("setcursorcolor"))) setcursorcolor(unsigned char c)
103+{ machikania_video("32"); }
104+void __attribute__((section("setcursor"))) setcursor(unsigned char x,unsigned char y,unsigned char c)
105+{ machikania_video("36"); }
106+void __attribute__((section("set_palette"))) set_palette(unsigned char n,unsigned char b,unsigned char r,unsigned char g)
107+{ machikania_video("40"); }
108+void __attribute__((section("set_bgcolor"))) set_bgcolor(unsigned char b,unsigned char r,unsigned char g)
109+{ machikania_video("44"); }
110+
111+// Graphic functions below use following macro
112+// $v0=g_data;
113+// lw $v1,0($v0) // g_data[0]
114+// lw $v0,16($v0) // g_data[4]
115+// lw $v0,"x"($v0) // g_data[4][x/4]
116+// lw $gp,0($v1) // g_data[0][0]
117+// jalr $v0
118+#define machikania_graphic(x) \
119+ clib_g_data();\
120+ asm volatile("lw $v1,0($v0)");\
121+ asm volatile("lw $v0,16($v0)");\
122+ asm volatile("lw $v0,"x"($v0)");\
123+ asm volatile("lw $gp,0($v1)");\
124+ asm volatile("jalr $v0")
125+
126+void __attribute__((section("g_pset"))) g_pset(int x,int y,unsigned int c)
127+{ machikania_graphic("0"); }
128+void __attribute__((section("g_putbmpmn"))) g_putbmpmn(int x,int y,char m,char n,const unsigned char bmp[])
129+{ machikania_graphic("4"); }
130+void __attribute__((section("g_clrbmpmn"))) g_clrbmpmn(int x,int y,char m,char n)
131+{ machikania_graphic("8"); }
132+void __attribute__((section("g_gline"))) g_gline(int x1,int y1,int x2,int y2,unsigned int c)
133+{ machikania_graphic("12"); }
134+void __attribute__((section("g_hline"))) g_hline(int x1,int x2,int y,unsigned int c)
135+{ machikania_graphic("16"); }
136+void __attribute__((section("g_circle"))) g_circle(int x0,int y0,unsigned int r,unsigned int c)
137+{ machikania_graphic("20"); }
138+void __attribute__((section("g_circlefill"))) g_circlefill(int x0,int y0,unsigned int r,unsigned int c)
139+{ machikania_graphic("24"); }
140+void __attribute__((section("g_boxfill"))) g_boxfill(int x1,int y1,int x2,int y2,unsigned int c)
141+{ machikania_graphic("28"); }
142+void __attribute__((section("g_putfont"))) g_putfont(int x,int y,unsigned int c,int bc,unsigned char n)
143+{ machikania_graphic("32"); }
144+void __attribute__((section("g_printstr"))) g_printstr(int x,int y,unsigned int c,int bc,unsigned char *s)
145+{ machikania_graphic("36"); }
146+void __attribute__((section("g_printnum"))) g_printnum(int x,int y,unsigned char c,int bc,unsigned int n)
147+{ machikania_graphic("40"); }
148+void __attribute__((section("g_printnum2"))) g_printnum2(int x,int y,unsigned char c,int bc,unsigned int n,unsigned char e)
149+{ machikania_graphic("44"); }
150+unsigned int __attribute__((section("g_color"))) g_color(int x,int y)
151+{ machikania_graphic("48"); }
152+
153+// Keyboard functions below use following macro
154+// $v0=g_data;
155+// lw $v1,0($v0) // g_data[0]
156+// lw $v0,20($v0) // g_data[5]
157+// lw $v0,"x"($v0) // g_data[5][x/4]
158+// lw $gp,0($v1) // g_data[0][0]
159+// jalr $v0
160+#define machikania_keyboard(x) \
161+ clib_g_data();\
162+ asm volatile("lw $v1,0($v0)");\
163+ asm volatile("lw $v0,20($v0)");\
164+ asm volatile("lw $v0,"x"($v0)");\
165+ asm volatile("lw $gp,0($v1)");\
166+ asm volatile("jalr $v0")
167+
168+unsigned char __attribute__((section("shiftkeys"))) shiftkeys()
169+{ machikania_keyboard("0"); }
170+unsigned char __attribute__((section("ps2readkey"))) ps2readkey()
171+{ machikania_keyboard("4"); }
172+
173+//*/
\ No newline at end of file
--- a/mips/clib/clib.h
+++ b/mips/clib/clib.h
@@ -4,7 +4,6 @@
44 * *
55 ***********************************/
66
7-
87 // Definition of data and program area.
98 // See also linker library.
109 // When expansion of data area size is required, edit following value
@@ -13,8 +12,8 @@
1312 #define CLIB_DATA_MEM_SIZE 0x0080
1413 #define CLIB_DATA_MEM (CLIB_PROGMRAM_MEM-CLIB_DATA_MEM_SIZE)
1514
16-// Global variables
17-// These must be defined by user
15+// List of public function(s))
16+// This must be defined by user
1817 extern const void* const functions[];
1918
2019 // Prototypes
@@ -25,17 +24,210 @@ extern const void* const functions[];
2524 */
2625 void init(void);
2726
27+// Variable used in clib.c
28+extern void*** g_data;
29+
30+/*
31+ * For calling MachiKania functions.
32+ * The structure of g_data[] is the same as g_data_clib[] below.
33+ *
34+const void* const g_data_clib_var[]={
35+ &g_gp,// g_data[0][0],"0"
36+};
37+
38+const void* const g_data_clib_core[]={
39+ lib_calloc_memory,// g_data[1][0],"0"
40+ lib_delete, // g_data[1][1],"4"
41+};
42+
43+const void* const g_data_clib_file[]={
44+#ifdef __DEBUG
45+ 0 // Disabled in debug mode
46+#else
47+ FSInit, // g_data[2][0],"0"
48+ FSfopen, // g_data[2][1],"4"
49+ FSfclose, // g_data[2][2],"8"
50+ FSfread, // g_data[2][3],"12"
51+ FSfwrite, // g_data[2][4],"16"
52+ FSfeof, // g_data[2][5],"20"
53+ FSftell, // g_data[2][6],"24"
54+ FSfseek, // g_data[2][7],"28"
55+ FSrewind, // g_data[2][8],"32"
56+ FindFirst,// g_data[2][9],"36"
57+ FindNext, // g_data[2][10],"40"
58+ FSmkdir, // g_data[2][11],"44"
59+ FSgetcwd, // g_data[2][12],"48"
60+ FSchdir, // g_data[2][13],"52"
61+ FSremove, // g_data[2][14],"56"
62+ FSrename, // g_data[2][15],"60"
63+#endif
64+};
65+
66+const void* const g_data_clib_video[]={
67+ start_composite,// g_data[3][0],"0"
68+ stop_composite, // g_data[3][1],"4"
69+ printchar, // g_data[3][2],"8"
70+ printstr, // g_data[3][3],"12"
71+ printnum, // g_data[3][4],"16"
72+ printnum2, // g_data[3][5],"20"
73+ cls, // g_data[3][6],"24"
74+ vramscroll, // g_data[3][7],"28"
75+ setcursorcolor, // g_data[3][8],"32"
76+ setcursor, // g_data[3][9],"36"
77+ set_palette, // g_data[3][10],"40"
78+ set_bgcolor, // g_data[3][11],"44"
79+};
80+
81+const void* const g_data_clib_graphic[]={
82+ g_pset, // g_data[4][0],"0"
83+ g_putbmpmn, // g_data[4][1],"4"
84+ g_clrbmpmn, // g_data[4][2],"8"
85+ g_gline, // g_data[4][3],"12"
86+ g_hline, // g_data[4][4],"16"
87+ g_circle, // g_data[4][5],"20"
88+ g_circlefill, // g_data[4][6],"24"
89+ g_boxfill, // g_data[4][7],"28"
90+ g_putfont, // g_data[4][8],"32"
91+ g_printstr, // g_data[4][9],"36"
92+ g_printnum, // g_data[4][10],"40"
93+ g_printnum2, // g_data[4][11],"44"
94+ g_color, // g_data[4][12],"48"
95+};
96+
97+const void* const g_data_clib_keyboard[]={
98+ shiftkeys, // g_data[5][0],"0"
99+ ps2readkey,// g_data[5][1],"4"
100+};
101+
102+const void* const g_data_clib[]={
103+ &g_data_clib_var[0], // g_data[0],"0"
104+ &g_data_clib_core[0], // g_data[1],"4"
105+ &g_data_clib_file[0], // g_data[2],"8"
106+ &g_data_clib_video[0], // g_data[3],"12"
107+ &g_data_clib_graphic[0], // g_data[4],"16"
108+ &g_data_clib_keyboard[0],// g_data[5],"20"
109+};
110+ */
111+
112+/*
113+ * MachiKanika core functions
114+ */
115+
28116 /*
29- malloc(int size);
30- calloc(int size);
117+ * malloc(int size);
118+ * calloc(int size);
119+ *
120+ * Allocates size bytes of uninitialized storage.
31121 */
32122 #define malloc(x) clib_calloc(((x)+3)>>2,g_data)
33123 #define calloc(x) clib_calloc(((x)+3)>>2,g_data)
34-extern void** g_data;
35-void* clib_calloc(int size, void** g_data);
124+void* clib_calloc(int size, void*** g_data);
36125
37126 /*
38- free(void* addr);
127+ * free(void* addr);
128+ *
129+ * Deallocates the space previously allocated by malloc() or calloc()
39130 */
40131 #define free(x) clib_free(x,g_data)
41-void clib_free(void* addr, void** g_data);
132+void clib_free(void* addr, void*** g_data);
133+
134+/*
135+ * MachiKanika file system functions
136+ * See "sdsfio370f.h" for using these functions.
137+ * Following functions are supported:
138+ * FSInit
139+ * FSfopen
140+ * FSfclose
141+ * FSfread
142+ * FSfwrite
143+ * FSfeof
144+ * FSftell
145+ * FSfseek
146+ * FSrewind
147+ * FindFirst
148+ * FindNext
149+ * FSmkdir
150+ * FSgetcwd
151+ * FSchdir
152+ * FSremove
153+ * FSrename
154+ */
155+
156+/*
157+ * MachiKanika video functions
158+ */
159+
160+void start_composite(void);
161+//カラーコンポジット出力開始
162+void stop_composite(void);
163+//カラーコンポジット出力停止
164+void printchar(unsigned char n);
165+//カーソル位置にテキストコードnを1文字表示し、カーソルを1文字進める
166+void printstr(unsigned char *s);
167+//カーソル位置に文字列sを表示
168+void printnum(unsigned int n);
169+//カーソル位置に符号なし整数nを10進数表示
170+void printnum2(unsigned int n,unsigned char e);
171+//カーソル位置に符号なし整数nをe桁の10進数表示(前の空き桁部分はスペースで埋める)
172+void cls(void);
173+//テキスト画面を0でクリアし、カーソルを画面先頭に移動
174+void vramscroll(void);
175+//1行スクロール
176+void setcursorcolor(unsigned char c);
177+//カーソル位置そのままでカラー番号をcに設定
178+void setcursor(unsigned char x,unsigned char y,unsigned char c);
179+//カーソル位置とカラーを設定
180+void set_palette(unsigned char n,unsigned char b,unsigned char r,unsigned char g);
181+//テキストパレット設定
182+void set_bgcolor(unsigned char b,unsigned char r,unsigned char g);
183+//バックグランドカラー設定
184+
185+/*
186+ * MachiKanika graphic functions
187+ */
188+
189+void g_pset(int x,int y,unsigned int c);
190+// (x,y)の位置にカラーcで点を描画
191+void g_putbmpmn(int x,int y,char m,char n,const unsigned char bmp[]);
192+// 横m*縦nドットのキャラクターを座標x,yに表示
193+// unsigned char bmp[m*n]配列に、単純にカラー番号を並べる
194+// カラー番号が0の部分は透明色として扱う
195+void g_clrbmpmn(int x,int y,char m,char n);
196+// 縦m*横nドットのキャラクター消去
197+// カラー0で塗りつぶし
198+void g_gline(int x1,int y1,int x2,int y2,unsigned int c);
199+// (x1,y1)-(x2,y2)にカラーcで線分を描画
200+void g_hline(int x1,int x2,int y,unsigned int c);
201+// (x1,y)-(x2,y)への水平ラインを高速描画
202+void g_circle(int x0,int y0,unsigned int r,unsigned int c);
203+// (x0,y0)を中心に、半径r、カラーcの円を描画
204+void g_circlefill(int x0,int y0,unsigned int r,unsigned int c);
205+// (x0,y0)を中心に、半径r、カラーcで塗られた円を描画
206+void g_boxfill(int x1,int y1,int x2,int y2,unsigned int c);
207+// (x1,y1),(x2,y2)を対角線とするカラーcで塗られた長方形を描画
208+void g_putfont(int x,int y,unsigned int c,int bc,unsigned char n);
209+//8*8ドットのアルファベットフォント表示
210+//座標(x,y)、カラー番号c
211+//bc:バックグランドカラー、負数の場合無視
212+//n:文字番号
213+void g_printstr(int x,int y,unsigned int c,int bc,unsigned char *s);
214+//座標(x,y)からカラー番号cで文字列sを表示、bc:バックグランドカラー
215+void g_printnum(int x,int y,unsigned char c,int bc,unsigned int n);
216+//座標(x,y)にカラー番号cで数値nを表示、bc:バックグランドカラー
217+void g_printnum2(int x,int y,unsigned char c,int bc,unsigned int n,unsigned char e);
218+//座標(x,y)にカラー番号cで数値nを表示、bc:バックグランドカラー、e桁で表示
219+unsigned int g_color(int x,int y);
220+//座標(x,y)のVRAM上の現在のパレット番号を返す、画面外は0を返す
221+
222+/*
223+ * MachiKanika keyboard functions
224+ */
225+
226+unsigned char shiftkeys();
227+// SHIFT関連キーの押下状態を返す
228+unsigned char ps2readkey();
229+// 入力された1つのキーのキーコードをグローバル変数vkeyに格納(押されていなければ0を返す)
230+// 下位8ビット:キーコード
231+// 上位8ビット:シフト状態(押下:1)、上位から<0><CAPSLK><NUMLK><SCRLK><Win><ALT><CTRL><SHIFT>
232+// 英数・記号文字の場合、戻り値としてASCIIコード(それ以外は0を返す)
233+
--- a/mips/clib/example.c
+++ b/mips/clib/example.c
@@ -20,11 +20,14 @@ void init(void){
2020 char* test_private(int param1){
2121 switch(param1){
2222 case 0:
23+ cls();
24+ printstr("CLIB test.");
2325 return "Hello World!";
2426 default:
2527 return "This is a test";
2628 }
2729 }
30+
2831 char* test_public(int param1){
2932 return test_private(param1);
3033 }
--- a/mips/clib/nbproject/Makefile-default.mk
+++ b/mips/clib/nbproject/Makefile-default.mk
@@ -57,17 +57,17 @@ OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
5757 DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
5858
5959 # Source Files Quoted if spaced
60-SOURCEFILES_QUOTED_IF_SPACED=clib.c example.c
60+SOURCEFILES_QUOTED_IF_SPACED=clib.c example.c sdfsio370f.c
6161
6262 # Object Files Quoted if spaced
63-OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/clib.o ${OBJECTDIR}/example.o
64-POSSIBLE_DEPFILES=${OBJECTDIR}/clib.o.d ${OBJECTDIR}/example.o.d
63+OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/clib.o ${OBJECTDIR}/example.o ${OBJECTDIR}/sdfsio370f.o
64+POSSIBLE_DEPFILES=${OBJECTDIR}/clib.o.d ${OBJECTDIR}/example.o.d ${OBJECTDIR}/sdfsio370f.o.d
6565
6666 # Object Files
67-OBJECTFILES=${OBJECTDIR}/clib.o ${OBJECTDIR}/example.o
67+OBJECTFILES=${OBJECTDIR}/clib.o ${OBJECTDIR}/example.o ${OBJECTDIR}/sdfsio370f.o
6868
6969 # Source Files
70-SOURCEFILES=clib.c example.c
70+SOURCEFILES=clib.c example.c sdfsio370f.c
7171
7272
7373 CFLAGS=
@@ -118,6 +118,12 @@ ${OBJECTDIR}/example.o: example.c nbproject/Makefile-${CND_CONF}.mk
118118 @${RM} ${OBJECTDIR}/example.o
119119 @${FIXDEPS} "${OBJECTDIR}/example.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_SIMULATOR=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/example.o.d" -o ${OBJECTDIR}/example.o example.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mgen-pie-static
120120
121+${OBJECTDIR}/sdfsio370f.o: sdfsio370f.c nbproject/Makefile-${CND_CONF}.mk
122+ @${MKDIR} "${OBJECTDIR}"
123+ @${RM} ${OBJECTDIR}/sdfsio370f.o.d
124+ @${RM} ${OBJECTDIR}/sdfsio370f.o
125+ @${FIXDEPS} "${OBJECTDIR}/sdfsio370f.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_SIMULATOR=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/sdfsio370f.o.d" -o ${OBJECTDIR}/sdfsio370f.o sdfsio370f.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mgen-pie-static
126+
121127 else
122128 ${OBJECTDIR}/clib.o: clib.c nbproject/Makefile-${CND_CONF}.mk
123129 @${MKDIR} "${OBJECTDIR}"
@@ -131,6 +137,12 @@ ${OBJECTDIR}/example.o: example.c nbproject/Makefile-${CND_CONF}.mk
131137 @${RM} ${OBJECTDIR}/example.o
132138 @${FIXDEPS} "${OBJECTDIR}/example.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/example.o.d" -o ${OBJECTDIR}/example.o example.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mgen-pie-static
133139
140+${OBJECTDIR}/sdfsio370f.o: sdfsio370f.c nbproject/Makefile-${CND_CONF}.mk
141+ @${MKDIR} "${OBJECTDIR}"
142+ @${RM} ${OBJECTDIR}/sdfsio370f.o.d
143+ @${RM} ${OBJECTDIR}/sdfsio370f.o
144+ @${FIXDEPS} "${OBJECTDIR}/sdfsio370f.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/sdfsio370f.o.d" -o ${OBJECTDIR}/sdfsio370f.o sdfsio370f.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mgen-pie-static
145+
134146 endif
135147
136148 # ------------------------------------------------------------------------------------
--- a/mips/clib/nbproject/Makefile-genesis.properties
+++ b/mips/clib/nbproject/Makefile-genesis.properties
@@ -1,8 +1,8 @@
11 #
2-#Tue May 14 12:14:44 PDT 2019
2+#Wed May 15 15:38:15 PDT 2019
33 default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=f2639e8ffe4e3a80ef2cdaeba61da340
44 default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc32\\v1.42\\bin
5-configurations-xml=d396d647be909bd57511217de4e29ec7
5+configurations-xml=2f3193434ad25f263dc0e914df895fd6
66 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=52742b11d992fb0dd234edfb95066b34
77 default.languagetoolchain.version=1.42
88 host.platform=windows
--- a/mips/clib/nbproject/configurations.xml
+++ b/mips/clib/nbproject/configurations.xml
@@ -5,6 +5,7 @@
55 displayName="Header Files"
66 projectFiles="true">
77 <itemPath>clib.h</itemPath>
8+ <itemPath>sdfsio370f.h</itemPath>
89 </logicalFolder>
910 <logicalFolder name="LinkerScript"
1011 displayName="Linker Files"
@@ -16,6 +17,7 @@
1617 projectFiles="true">
1718 <itemPath>clib.c</itemPath>
1819 <itemPath>example.c</itemPath>
20+ <itemPath>sdfsio370f.c</itemPath>
1921 </logicalFolder>
2022 <logicalFolder name="ExternalFiles"
2123 displayName="Important Files"
--- /dev/null
+++ b/mips/clib/sdfsio370f.c
@@ -0,0 +1,59 @@
1+/***********************************
2+ * *
3+ * Template of CLIB for MachiKania *
4+ * *
5+ ***********************************/
6+
7+#include "./sdfsio370f.h"
8+
9+// Local prototyping
10+void clib_g_data();
11+
12+// File System functions below use following macro
13+// $v0=g_data;
14+// lw $v1,0($v0) // g_data[0]
15+// lw $v0,8($v0) // g_data[2]
16+// lw $v0,"x"($v0) // g_data[2][x/4]
17+// lw $gp,0($v1) // g_data[0][0]
18+// jalr $v0
19+#define machikania_file(x) \
20+ clib_g_data();\
21+ asm volatile("lw $v1,0($v0)");\
22+ asm volatile("lw $v0,8($v0)");\
23+ asm volatile("lw $v0,"x"($v0)");\
24+ asm volatile("lw $gp,0($v1)");\
25+ asm volatile("jalr $v0")
26+
27+int __attribute__((section("FSInit"))) FSInit(void)
28+{ machikania_file("0"); }
29+FSFILE * __attribute__((section("FSfopen"))) FSfopen (const char * fileName, const char *mode)
30+{ machikania_file("4"); }
31+int __attribute__((section("FSfclose"))) FSfclose(FSFILE *fo)
32+{ machikania_file("8"); }
33+size_t __attribute__((section("FSfread"))) FSfread(void *ptr, size_t size, size_t n, FSFILE *stream)
34+{ machikania_file("12"); }
35+size_t __attribute__((section("FSfwrite"))) FSfwrite(const void *data_to_write, size_t size, size_t n, FSFILE *stream)
36+{ machikania_file("16"); }
37+int __attribute__((section("FSfeof"))) FSfeof( FSFILE * stream )
38+{ machikania_file("20"); }
39+long __attribute__((section("FSftell"))) FSftell (FSFILE * fo)
40+{ machikania_file("24"); }
41+int __attribute__((section("FSfseek"))) FSfseek(FSFILE *stream, long offset, int whence)
42+{ machikania_file("28"); }
43+void __attribute__((section("FSrewind"))) FSrewind (FSFILE * fo)
44+{ machikania_file("32"); }
45+int __attribute__((section("FindFirst"))) FindFirst (const char * fileName, unsigned int attr, SearchRec * rec)
46+{ machikania_file("36"); }
47+int __attribute__((section("FindNext"))) FindNext (SearchRec * rec)
48+{ machikania_file("40"); }
49+int __attribute__((section("FSmkdir"))) FSmkdir (char * path)
50+{ machikania_file("44"); }
51+char * __attribute__((section("FSgetcwd"))) FSgetcwd (char * path, int numchars)
52+{ machikania_file("48"); }
53+int __attribute__((section("FSchdir"))) FSchdir (char * path)
54+{ machikania_file("52"); }
55+int __attribute__((section("FSremove"))) FSremove (const char * fileName)
56+{ machikania_file("56"); }
57+int __attribute__((section("FSrename"))) FSrename (const char * fileName, FSFILE * fo)
58+{ machikania_file("60"); }
59+
--- /dev/null
+++ b/mips/clib/sdfsio370f.h
@@ -0,0 +1,2381 @@
1+// sdfsio370f.h
2+// PIC32MX370F512HでSPI2接続されたSDカードにアクセスする
3+// sdfsio370fLib.aを利用するためのヘッダーファイル
4+// FSIO.h,FSconfig.h,FSDefs.hから抜粋 by K.Tanaka
5+//
6+// サポート
7+// FAT32,書き込み,ファイルサーチ,Dir
8+// 未サポート
9+// LongFileName,FSfprintf,format,FSGetDiskProperties
10+// 同時オープン数 3
11+
12+#ifndef BOOL
13+ typedef enum _BOOL { FALSE = 0, TRUE } BOOL;
14+#endif
15+
16+#ifndef BYTE
17+ #define BYTE unsigned char
18+#endif
19+
20+#ifndef WORD
21+ #define WORD unsigned short
22+#endif
23+
24+#ifndef DWORD
25+ #define DWORD unsigned long
26+#endif
27+
28+#ifndef UINT16
29+ #define UINT16 unsigned short
30+#endif
31+
32+#ifndef size_t
33+ #define size_t unsigned int
34+#endif
35+
36+/******************************************************************************
37+ *
38+ * Microchip Memory Disk Drive File System
39+ *
40+ ******************************************************************************
41+ * FileName: FSIO.h
42+ * Dependencies: GenericTypeDefs.h
43+ * FSconfig.h
44+ * FSDefs.h
45+ * stddef.h
46+ * Processor: PIC18/PIC24/dsPIC30/dsPIC33/PIC32
47+ * Compiler: C18/C30/C32
48+ * Company: Microchip Technology, Inc.
49+ * Version: 1.3.0
50+ *
51+ * Software License Agreement
52+ *
53+ * The software supplied herewith by Microchip Technology Incorporated
54+ * (the 鼎ompany・ for its PICmicroョ Microcontroller is intended and
55+ * supplied to you, the Company痴 customer, for use solely and
56+ * exclusively on Microchip PICmicro Microcontroller products. The
57+ * software is owned by the Company and/or its supplier, and is
58+ * protected under applicable copyright laws. All rights are reserved.
59+ * Any use in violation of the foregoing restrictions may subject the
60+ * user to criminal sanctions under applicable laws, as well as to
61+ * civil liability for the breach of the terms and conditions of this
62+ * license.
63+ *
64+ * THIS SOFTWARE IS PROVIDED IN AN 鄭S IS・CONDITION. NO WARRANTIES,
65+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
66+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
67+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
68+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
69+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
70+ *
71+*****************************************************************************/
72+
73+#ifndef FS_DOT_H
74+#define FS_DOT_H
75+
76+#define MDD_MediaInitialize MDD_SDSPI_MediaInitialize
77+#define MDD_MediaDetect MDD_SDSPI_MediaDetect
78+#define MDD_SectorRead MDD_SDSPI_SectorRead
79+#define MDD_SectorWrite MDD_SDSPI_SectorWrite
80+#define MDD_InitIO MDD_SDSPI_InitIO
81+#define MDD_ShutdownMedia MDD_SDSPI_ShutdownMedia
82+#define MDD_WriteProtectState MDD_SDSPI_WriteProtectState
83+
84+#define ALLOW_FILESEARCH
85+#define ALLOW_WRITES
86+#define ALLOW_DIRS
87+#define SUPPORT_FAT32
88+
89+// Summary: An enumeration used for various error codes.
90+// Description: The CETYPE enumeration is used to indicate different error conditions during device operation.
91+typedef enum _CETYPE
92+{
93+ CE_GOOD = 0, // No error
94+ CE_ERASE_FAIL, // An erase failed
95+ CE_NOT_PRESENT, // No device was present
96+ CE_NOT_FORMATTED, // The disk is of an unsupported format
97+ CE_BAD_PARTITION, // The boot record is bad
98+ CE_UNSUPPORTED_FS, // The file system type is unsupported
99+ CE_INIT_ERROR, // An initialization error has occured
100+ CE_NOT_INIT, // An operation was performed on an uninitialized device
101+ CE_BAD_SECTOR_READ, // A bad read of a sector occured
102+ CE_WRITE_ERROR, // Could not write to a sector
103+ CE_INVALID_CLUSTER, // Invalid cluster value > maxcls
104+ CE_FILE_NOT_FOUND, // Could not find the file on the device
105+ CE_DIR_NOT_FOUND, // Could not find the directory
106+ CE_BAD_FILE, // File is corrupted
107+ CE_DONE, // No more files in this directory
108+ CE_COULD_NOT_GET_CLUSTER, // Could not load/allocate next cluster in file
109+ CE_FILENAME_2_LONG, // A specified file name is too long to use
110+ CE_FILENAME_EXISTS, // A specified filename already exists on the device
111+ CE_INVALID_FILENAME, // Invalid file name
112+ CE_DELETE_DIR, // The user tried to delete a directory with FSremove
113+ CE_DIR_FULL, // All root dir entry are taken
114+ CE_DISK_FULL, // All clusters in partition are taken
115+ CE_DIR_NOT_EMPTY, // This directory is not empty yet, remove files before deleting
116+ CE_NONSUPPORTED_SIZE, // The disk is too big to format as FAT16
117+ CE_WRITE_PROTECTED, // Card is write protected
118+ CE_FILENOTOPENED, // File not opened for the write
119+ CE_SEEK_ERROR, // File location could not be changed successfully
120+ CE_BADCACHEREAD, // Bad cache read
121+ CE_CARDFAT32, // FAT 32 - card not supported
122+ CE_READONLY, // The file is read-only
123+ CE_WRITEONLY, // The file is write-only
124+ CE_INVALID_ARGUMENT, // Invalid argument
125+ CE_TOO_MANY_FILES_OPEN, // Too many files are already open
126+ CE_UNSUPPORTED_SECTOR_SIZE // Unsupported sector size
127+} CETYPE;
128+
129+
130+// Summary: A macro indicating a dir entry was found
131+// Description: The FOUND macro indicates that a directory entry was found in the specified position
132+#define FOUND 0
133+
134+// Summary: A macro indicating no dir entry was found
135+// Description: The NOT_FOUND macro indicates that the specified directory entry to load was deleted
136+#define NOT_FOUND 1
137+
138+// Summary: A macro indicating that no more files were found
139+// Description: The NO_MORE macro indicates that there are no more directory entries to search for
140+#define NO_MORE 2
141+
142+
143+
144+// Summary: A macro indicating the device is formatted with FAT12
145+// Description: The FAT12 macro is used to indicate that the file system on the device being accessed is a FAT12 file system.
146+#define FAT12 1
147+
148+// Summary: A macro indicating the device is formatted with FAT16
149+// Description: The FAT16 macro is used to indicate that the file system on the device being accessed is a FAT16 file system.
150+#define FAT16 2
151+
152+// Summary: A macro indicating the device is formatted with FAT32
153+// Description: The FAT32 macro is used to indicate that the file system on the device being accessed is a FAT32 file system.
154+#define FAT32 3
155+
156+
157+
158+// Summary: A read-only attribute macro
159+// Description: A macro for the read-only attribute. A file with this attribute should not be written to. Note that this
160+// attribute will not actually prevent a write to the file; that functionality is operating-system dependant. The
161+// user should take care not to write to a read-only file.
162+#define ATTR_READ_ONLY 0x01
163+
164+// Summary: A hidden attribute macro
165+// Description: A macro for the hidden attribute. A file with this attribute may be hidden from the user, depending on the
166+// implementation of the operating system.
167+#define ATTR_HIDDEN 0x02
168+
169+// Summary: A system attribute macro
170+// Description: A macro for the system attribute. A file with this attribute is used by the operating system, and should not be
171+// modified. Note that this attribute will not actually prevent a write to the file.
172+#define ATTR_SYSTEM 0x04
173+
174+// Summary: A volume attribute macro
175+// Description: A macro for the volume attribute. If the first directory entry in the root directory has the volume attribute set,
176+// the device will use the name in that directory entry as the volume name.
177+#define ATTR_VOLUME 0x08
178+
179+// Summary: A macro for the attributes for a long-file name entry
180+// Description: A macro for the long-name attributes. If a directory entry is used in a long-file name implementation, it will have
181+// all four lower bits set. This indicates that any software that does not support long file names should ignore that
182+// entry.
183+#define ATTR_LONG_NAME 0x0f
184+
185+// Summary: A directory attribute macro
186+// Description: A macro for the directory attribute. If a directory entry has this attribute set, the file it points to is a directory-
187+// type file, and will contain directory entries that point to additional directories or files.
188+#define ATTR_DIRECTORY 0x10
189+
190+// Summary: An archive attribute macro
191+// Description: A macro for the archive attribute. This attribute will indicate to some archiving programs that the file with this
192+// attribute needs to be backed up. Most operating systems create files with the archive attribute set.
193+#define ATTR_ARCHIVE 0x20
194+
195+// Summary: A macro for all attributes
196+// Description: A macro for all attributes. The search functions in this library require an argument that determines which attributes
197+// a file is allowed to have in order to be found. If ATTR_MASK is specified as this argument, any file may be found, regardless
198+// of its attributes.
199+#define ATTR_MASK 0x3f
200+
201+
202+
203+// Summary: A macro to indicate an empty FAT entry
204+// Description: The CLUSTER_EMPTY value is used to indicate that a FAT entry and it's corresponding cluster are available.
205+#define CLUSTER_EMPTY 0x0000
206+
207+// Summary: A macro to indicate the last cluster value for FAT12
208+// Description: The LAST_CLUSTER_FAT12 macro is used when reading the FAT to indicate that the next FAT12 entry for a file contains
209+// the end-of-file value.
210+#define LAST_CLUSTER_FAT12 0xff8
211+
212+// Summary: A macro to indicate the last cluster value for FAT16
213+// Description: The LAST_CLUSTER_FAT16 macro is used when reading the FAT to indicate that the next FAT16 entry for a file contains
214+// the end-of-file value.
215+#define LAST_CLUSTER_FAT16 0xfff8
216+
217+// Summary: A macro to indicate the last allocatable cluster for FAT12
218+// Description: The END_CLUSTER_FAT12 value is used as a comparison in FAT12 to determine that the firmware has reached the end of
219+// the range of allowed allocatable clusters.
220+#define END_CLUSTER_FAT12 0xFF7
221+
222+// Summary: A macro to indicate the last allocatable cluster for FAT16
223+// Description: The END_CLUSTER_FAT16 value is used as a comparison in FAT16 to determine that the firmware has reached the end of
224+// the range of allowed allocatable clusters.
225+#define END_CLUSTER_FAT16 0xFFF7
226+
227+// Summary: A macro to indicate the failure of the ReadFAT function
228+// Description: The CLUSTER_FAIL_FAT16 macro is used by the ReadFAT function to indicate that an error occured reading a FAT12 or FAT16
229+// file allocation table. Note that since '0xFFF8' is used for the last cluster return value in the FAT16 implementation
230+// the end-of-file value '0xFFFF' can be used to indicate an error condition.
231+#define CLUSTER_FAIL_FAT16 0xFFFF
232+
233+
234+
235+#ifdef SUPPORT_FAT32
236+ // Summary: A macro to indicate the last cluster value for FAT32
237+ // Description: The LAST_CLUSTER_FAT32 macro is used when reading the FAT to indicate that the next FAT32 entry for a file contains
238+ // the end-of-file value.
239+ #define LAST_CLUSTER_FAT32 0x0FFFFFF8
240+
241+ // Summary: A macro to indicate the last allocatable cluster for FAT32
242+ // Description: The END_CLUSTER_FAT32 value is used as a comparison in FAT32 to determine that the firmware has reached the end of
243+ // the range of allowed allocatable clusters.
244+ #define END_CLUSTER_FAT32 0x0FFFFFF7
245+
246+ // Summary: A macro to indicate the failure of the ReadFAT function
247+ // Description: The CLUSTER_FAIL_FAT32 macro is used by the ReadFAT function to indicate that an error occured reading a FAT32
248+ // file allocation able.
249+ #define CLUSTER_FAIL_FAT32 0x0FFFFFFF
250+
251+#endif
252+
253+// Summary: A macro indicating the number of bytes in a directory entry.
254+// Description: The NUMBER_OF_BYTES_IN_DIR_ENTRY macro represents the number of bytes in one directory entry. It is used to calculate
255+// the number of sectors in the root directory based on information in the boot sector.
256+#define NUMBER_OF_BYTES_IN_DIR_ENTRY 32
257+
258+
259+
260+// Summary: A macro for a deleted dir entry marker.
261+// Description: The DIR_DEL macro is used to mark a directory entry as deleted. When a file is deleted, this value will replace the
262+// first character in the file name, and will indicate that the file the entry points to was deleted.
263+#define DIR_DEL 0xE5
264+
265+// Summary: A macro for the last dir entry marker.
266+// Description: The DIR_EMPTY macro is used to indicate the last entry in a directory. Since entries in use cannot start with a 0 and
267+// deleted entries start with the DIR_DEL character, a 0 will mark the end of the in-use or previously used group of
268+// entries in a directory
269+#define DIR_EMPTY 0
270+
271+
272+
273+// Summary: A macro used to indicate the length of an 8.3 file name
274+// Description: The DIR_NAMESIZE macro is used when validing the name portion of 8.3 filenames
275+#define DIR_NAMESIZE 8
276+
277+// Summary: A macro used to indicate the length of an 8.3 file extension
278+// Description: The DIR_EXTENSION macro is used when validating the extension portion of 8.3 filenames
279+#define DIR_EXTENSION 3
280+
281+// Summary: A macro used to indicate the length of an 8.3 file name and extension
282+// Description: The DIR_NAMECOMP macro is used when validating 8.3 filenames
283+#define DIR_NAMECOMP (DIR_NAMESIZE+DIR_EXTENSION)
284+
285+
286+
287+// Summary: A macro to write a byte to RAM
288+// Description: The RAMwrite macro is used to write a byte of data to a RAM array
289+#define RAMwrite( a, f, d) *(a+f) = d
290+
291+// Summary: A macro to read a byte from RAM
292+// Description: The RAMread macro is used to read a byte of data from a RAM array
293+#define RAMread( a, f) *(a+f)
294+
295+// Summary: A macro to read a 16-bit word from RAM
296+// Description: The RAMreadW macro is used to read two bytes of data from a RAM array
297+#define RAMreadW( a, f) *(WORD *)(a+f)
298+
299+// Summary: A macro to read a 32-bit word from RAM
300+// Description: The RAMreadD macro is used to read four bytes of data from a RAM array
301+#define RAMreadD( a, f) *(DWORD *)(a+f)
302+
303+
304+
305+#ifndef EOF
306+ // Summary: Indicates error conditions or end-of-file conditions
307+ // Description: The EOF macro is used to indicate error conditions in some function calls. It is also used to indicate
308+ // that the end-of-file has been reached.
309+ #define EOF ((int)-1)
310+#endif
311+
312+
313+
314+// Summary: A structure containing information about the device.
315+// Description: The DISK structure contains information about the device being accessed.
316+typedef struct
317+{
318+ BYTE * buffer; // Address of the global data buffer used to read and write file information
319+ DWORD firsts; // Logical block address of the first sector of the FAT partition on the device
320+ DWORD fat; // Logical block address of the FAT
321+ DWORD root; // Logical block address of the root directory
322+ DWORD data; // Logical block address of the data section of the device.
323+ WORD maxroot; // The maximum number of entries in the root directory.
324+ DWORD maxcls; // The maximum number of clusters in the partition.
325+ DWORD sectorSize; // The size of a sector in bytes
326+ DWORD fatsize; // The number of sectors in the FAT
327+ BYTE fatcopy; // The number of copies of the FAT in the partition
328+ BYTE SecPerClus; // The number of sectors per cluster in the data region
329+ BYTE type; // The file system type of the partition (FAT12, FAT16 or FAT32)
330+ BYTE mount; // Device mount flag (TRUE if disk was mounted successfully, FALSE otherwise)
331+#if defined __PIC32MX__ || defined __C30__
332+} __attribute__ ((packed)) DISK;
333+#else
334+} DISK;
335+#endif
336+
337+
338+#ifdef __18CXX
339+ // Summary: A 24-bit data type
340+ // Description: The SWORD macro is used to defined a 24-bit data type. For 16+ bit architectures, this must be represented as
341+ // an array of three bytes.
342+ typedef unsigned short long SWORD;
343+#else
344+ // Summary: A 24-bit data type
345+ // Description: The SWORD macro is used to defined a 24-bit data type. For 16+ bit architectures, this must be represented as
346+ // an array of three bytes.
347+ typedef struct
348+ {
349+ unsigned char array[3];
350+#if defined __PIC32MX__ || defined __C30__
351+ } __attribute__ ((packed)) SWORD;
352+#else
353+ } SWORD;
354+#endif
355+#endif
356+
357+
358+
359+// Summary: A structure containing the bios parameter block for a FAT12 file system (in the boot sector)
360+// Description: The _BPB_FAT12 structure provides a layout of the "bios parameter block" in the boot sector of a FAT12 partition.
361+typedef struct {
362+ SWORD BootSec_JumpCmd; // Jump Command
363+ BYTE BootSec_OEMName[8]; // OEM name
364+ WORD BootSec_BPS; // Number of bytes per sector
365+ BYTE BootSec_SPC; // Number of sectors per cluster
366+ WORD BootSec_ResrvSec; // Number of reserved sectors at the beginning of the partition
367+ BYTE BootSec_FATCount; // Number of FATs on the partition
368+ WORD BootSec_RootDirEnts; // Number of root directory entries
369+ WORD BootSec_TotSec16; // Total number of sectors
370+ BYTE BootSec_MDesc; // Media descriptor
371+ WORD BootSec_SPF; // Number of sectors per FAT
372+ WORD BootSec_SPT; // Number of sectors per track
373+ WORD BootSec_HeadCnt; // Number of heads
374+ DWORD BootSec_HiddenSecCnt; // Number of hidden sectors
375+ DWORD BootSec_Reserved; // Reserved space
376+ BYTE BootSec_DriveNum; // Drive number
377+ BYTE BootSec_Reserved2; // Reserved space
378+ BYTE BootSec_BootSig; // Boot signature - equal to 0x29
379+ BYTE BootSec_VolID[4]; // Volume ID
380+ BYTE BootSec_VolLabel[11]; // Volume Label
381+ BYTE BootSec_FSType[8]; // File system type in ASCII. Not used for determination
382+#if defined __PIC32MX__ || defined __C30__
383+ } __attribute__ ((packed)) _BPB_FAT12;
384+#else
385+ } _BPB_FAT12;
386+#endif
387+
388+// Summary: A structure containing the bios parameter block for a FAT16 file system (in the boot sector)
389+// Description: The _BPB_FAT16 structure provides a layout of the "bios parameter block" in the boot sector of a FAT16 partition.
390+typedef struct {
391+ SWORD BootSec_JumpCmd; // Jump Command
392+ BYTE BootSec_OEMName[8]; // OEM name
393+ WORD BootSec_BPS; // Number of bytes per sector
394+ BYTE BootSec_SPC; // Number of sectors per cluster
395+ WORD BootSec_ResrvSec; // Number of reserved sectors at the beginning of the partition
396+ BYTE BootSec_FATCount; // Number of FATs on the partition
397+ WORD BootSec_RootDirEnts; // Number of root directory entries
398+ WORD BootSec_TotSec16; // Total number of sectors
399+ BYTE BootSec_MDesc; // Media descriptor
400+ WORD BootSec_SPF; // Number of sectors per FAT
401+ WORD BootSec_SPT; // Number of sectors per track
402+ WORD BootSec_HeadCnt; // Number of heads
403+ DWORD BootSec_HiddenSecCnt; // Number of hidden sectors
404+ DWORD BootSec_TotSec32; // Total sector count (32 bits)
405+ BYTE BootSec_DriveNum; // Drive number
406+ BYTE BootSec_Reserved; // Reserved space
407+ BYTE BootSec_BootSig; // Boot signature - equal to 0x29
408+ BYTE BootSec_VolID[4]; // Volume ID
409+ BYTE BootSec_VolLabel[11]; // Volume Label
410+ BYTE BootSec_FSType[8]; // File system type in ASCII. Not used for determination
411+#if defined __PIC32MX__ || defined __C30__
412+ } __attribute__ ((packed)) _BPB_FAT16;
413+#else
414+ } _BPB_FAT16;
415+#endif
416+
417+// Summary: A structure containing the bios parameter block for a FAT32 file system (in the boot sector)
418+// Description: The _BPB_FAT32 structure provides a layout of the "bios parameter block" in the boot sector of a FAT32 partition.
419+typedef struct {
420+ SWORD BootSec_jmpBoot; // Jump Command
421+ BYTE BootSec_OEMName[8]; // OEM name
422+ WORD BootSec_BytsPerSec; // Number of bytes per sector
423+ BYTE BootSec_SecPerClus; // Number of sectors per cluster
424+ WORD BootSec_RsvdSecCnt; // Number of reserved sectors at the beginning of the partition
425+ BYTE BootSec_NumFATs; // Number of FATs on the partition
426+ WORD BootSec_RootEntCnt; // Number of root directory entries
427+ WORD BootSec_TotSec16; // Total number of sectors
428+ BYTE BootSec_Media; // Media descriptor
429+ WORD BootSec_FATSz16; // Number of sectors per FAT
430+ WORD BootSec_SecPerTrk; // Number of sectors per track
431+ WORD BootSec_NumHeads; // Number of heads
432+ DWORD BootSec_HiddSec; // Number of hidden sectors
433+ DWORD BootSec_TotSec32; // Total sector count (32 bits)
434+ DWORD BootSec_FATSz32; // Sectors per FAT (32 bits)
435+ WORD BootSec_ExtFlags; // Presently active FAT. Defined by bits 0-3 if bit 7 is 1.
436+ WORD BootSec_FSVers; // FAT32 filesystem version. Should be 0:0
437+ DWORD BootSec_RootClus; // Start cluster of the root directory (should be 2)
438+ WORD BootSec_FSInfo; // File system information
439+ WORD BootSec_BkBootSec; // Backup boot sector address.
440+ BYTE BootSec_Reserved[12]; // Reserved space
441+ BYTE BootSec_DrvNum; // Drive number
442+ BYTE BootSec_Reserved1; // Reserved space
443+ BYTE BootSec_BootSig; // Boot signature - 0x29
444+ BYTE BootSec_VolID[4]; // Volume ID
445+ BYTE BootSec_VolLab[11]; // Volume Label
446+ BYTE BootSec_FilSysType[8]; // File system type in ASCII. Not used for determination
447+#if defined __PIC32MX__ || defined __C30__
448+ } __attribute__ ((packed)) _BPB_FAT32;
449+#else
450+ } _BPB_FAT32;
451+#endif
452+
453+
454+// Description: A macro for the boot sector bytes per sector value offset
455+#define BSI_BPS 11
456+
457+// Description: A macro for the boot sector sector per cluster value offset
458+#define BSI_SPC 13
459+
460+// Description: A macro for the boot sector reserved sector count value offset
461+#define BSI_RESRVSEC 14
462+
463+// Description: A macro for the boot sector FAT count value offset
464+#define BSI_FATCOUNT 16
465+
466+// Description: A macro for the boot sector root directory entry count value offset
467+#define BSI_ROOTDIRENTS 17
468+
469+// Description: A macro for the boot sector 16-bit total sector count value offset
470+#define BSI_TOTSEC16 19
471+
472+// Description: A macro for the boot sector sectors per FAT value offset
473+#define BSI_SPF 22
474+
475+// Description: A macro for the boot sector 32-bit total sector count value offset
476+#define BSI_TOTSEC32 32
477+
478+// Description: A macro for the boot sector boot signature offset
479+#define BSI_BOOTSIG 38
480+
481+// Description: A macro for the boot sector file system type string offset
482+#define BSI_FSTYPE 54
483+
484+// Description: A macro for the boot sector 32-bit sector per FAT value offset
485+#define BSI_FATSZ32 36
486+
487+// Description: A macro for the boot sector start cluster of root directory value offset
488+#define BSI_ROOTCLUS 44
489+
490+// Description: A macro for the FAT32 boot sector boot signature offset
491+#define BSI_FAT32_BOOTSIG 66
492+
493+// Description: A macro for the FAT32 boot sector file system type string offset
494+#define BSI_FAT32_FSTYPE 82
495+
496+
497+
498+// Summary: A partition table entry structure.
499+// Description: The PTE_MBR structure contains values found in a partition table entry in the MBR of a device.
500+typedef struct
501+{
502+ BYTE PTE_BootDes; // The boot descriptor (should be 0x00 in a non-bootable device)
503+ SWORD PTE_FrstPartSect; // The cylinder-head-sector address of the first sector of the partition
504+ BYTE PTE_FSDesc; // The file system descriptor
505+ SWORD PTE_LstPartSect; // The cylinder-head-sector address of the last sector of the partition
506+ DWORD PTE_FrstSect; // The logical block address of the first sector of the partition
507+ DWORD PTE_NumSect; // The number of sectors in a partition
508+#if defined __PIC32MX__ || defined __C30__
509+ } __attribute__ ((packed)) PTE_MBR;
510+#else
511+ } PTE_MBR;
512+#endif
513+
514+
515+// Summary: A structure of the organization of a master boot record.
516+// Description: The _PT_MBR structure has the same form as a master boot record. When the MBR is loaded from the device, it will
517+// be cast as a _PT_MBR structure so the MBR elements can be accessed.
518+typedef struct
519+{
520+ BYTE ConsChkRtn[446]; // Boot code
521+ PTE_MBR Partition0; // The first partition table entry
522+ PTE_MBR Partition1; // The second partition table entry
523+ PTE_MBR Partition2; // The third partition table entry
524+ PTE_MBR Partition3; // The fourth partition table entry
525+ BYTE Signature0; // MBR signature code - equal to 0x55
526+ BYTE Signature1; // MBR signature code - equal to 0xAA
527+#if defined __PIC32MX__ || defined __C30__
528+}__attribute__((packed)) _PT_MBR;
529+#else
530+}_PT_MBR;
531+#endif
532+
533+// Summary: A pointer to a _PT_MBR structure
534+// Description: The PT_MBR pointer points to a _PT_MBR structure.
535+typedef _PT_MBR * PT_MBR;
536+
537+
538+
539+// Summary: A structure of the organization of a boot sector.
540+// Description: The _BootSec structure has the same form as a boot sector. When the boot sector is loaded from the device, it will
541+// be cast as a _BootSec structure so the boot sector elements can be accessed.
542+typedef struct
543+{
544+ // A union of different bios parameter blocks
545+ union
546+ {
547+ _BPB_FAT32 FAT_32;
548+ _BPB_FAT16 FAT_16;
549+ _BPB_FAT12 FAT_12;
550+ }FAT;
551+ BYTE Reserved[512-sizeof(_BPB_FAT32)-2]; // Reserved space
552+ BYTE Signature0; // Boot sector signature code - equal to 0x55
553+ BYTE Signature1; // Boot sector signature code - equal to 0xAA
554+#if defined __PIC32MX__ || defined __C30__
555+ } __attribute__ ((packed)) _BootSec;
556+#else
557+ } _BootSec;
558+#endif
559+
560+// Summary: A pointer to a _BootSec structure
561+// Description: The BootSec pointer points to a _BootSec structure.
562+typedef _BootSec * BootSec;
563+
564+
565+
566+// Summary: A macro indicating the offset for the master boot record
567+// Description: FO_MBR is a macro that indicates the addresss of the master boot record on the device. When the device is initialized
568+// this sector will be read
569+#define FO_MBR 0L
570+
571+
572+
573+// Summary: A macro for the first boot sector/MBR signature byte
574+// Description: The FAT_GOOD_SIGN_0 macro is used to determine that the first byte of the MBR or boot sector signature code is correct
575+#define FAT_GOOD_SIGN_0 0x55
576+
577+// Summary: A macro for the second boot sector/MBR signature byte
578+// Description: The FAT_GOOD_SIGN_1 macro is used to determine that the second byte of the MBR or boot sector signature code is correct
579+#define FAT_GOOD_SIGN_1 0xAA
580+
581+
582+typedef struct
583+{
584+ BYTE errorCode;
585+ union
586+ {
587+ BYTE value;
588+ struct
589+ {
590+ BYTE sectorSize : 1;
591+ BYTE maxLUN : 1;
592+ } bits;
593+ } validityFlags;
594+
595+ WORD sectorSize;
596+ BYTE maxLUN;
597+} MEDIA_INFORMATION;
598+
599+typedef enum
600+{
601+ MEDIA_NO_ERROR, // No errors
602+ MEDIA_DEVICE_NOT_PRESENT, // The requested device is not present
603+ MEDIA_CANNOT_INITIALIZE // Cannot initialize media
604+} MEDIA_ERRORS;
605+
606+
607+
608+
609+/*******************************************************************/
610+/* Strunctures and defines */
611+/*******************************************************************/
612+
613+#ifndef FALSE
614+ // Summary: False value
615+ // Description: This macro will indicate that a condition is false.
616+ #define FALSE 0
617+#endif
618+#ifndef TRUE
619+ // Summary: True value
620+ // Description: This macro will indicate that a condition is true.
621+ #define TRUE !FALSE // True value
622+#endif
623+
624+
625+
626+
627+#ifndef SEEK_SET
628+ // Summary: Macro for the FSfseek SEEK_SET base location.
629+ // Description: Functions as an input for FSfseek that specifies that the position in the file will be changed
630+ // relative to the beginning of the file.
631+ #define SEEK_SET 0
632+
633+#endif
634+#ifndef SEEK_CUR
635+
636+ // Summary: Macro for the FSfseek SEEK_CUR base location.
637+ // Description: Functions as an input for FSfseek that specifies that the position in the file will be changed
638+ // relative to the current location of the file
639+ #define SEEK_CUR 1
640+
641+#endif
642+#ifndef SEEK_END
643+
644+ // Summary: Macro for the FSfseek SEEK_END base location
645+ // Description: Functions as an input for FSfseek that specifies that the position in the file will be changed
646+ // relative to the end of the file. For this macro, the offset value will be subtracted from
647+ // the end location of the file by default.
648+ #define SEEK_END 2
649+
650+#endif
651+
652+
653+
654+
655+// Summary: Macro for the FSfopen FS_APPEND mode
656+// Description: If this macro is specified as the mode argument in a call of FSfopen, the file being opened will
657+// be created if it doesn't exist. If it does exist, it's file information will be loaded and the
658+// current location in the file will be set to the end. The user will then be able to write to the file.
659+#define FS_APPEND "a"
660+#define APPEND "a" //deprecated
661+
662+// Summary: Macro for the FSfopen FS_WRITE mode
663+// Description: If this macro is specified as the mode argument in a call of FSfopen, the file being opened will
664+// be created if it doesn't exist. If it does exist, it will be erased and replaced by an empty file
665+// of the same name. The user will then be able to write to the file.
666+#define FS_WRITE "w"
667+#define WRITE "w" //deprecated
668+
669+// Summary: Macro for the FSfopen FS_READ mode
670+// Description: If this macro is specified as the mode argument in a call of FSfopen, the file information for the
671+// specified file will be loaded. If the file does not exist, the FSfopen function will fail. The user
672+// will then be able to read from the file.
673+#define FS_READ "r"
674+#if defined(__32MX795F512L__)
675+ #warning FSfopen must use "r" and not READ as input on this device
676+#else
677+ #define READ "r" //deprecated
678+#endif
679+
680+// Summary: Macro for the FSfopen FS_APPEND+ mode
681+// Description: If this macro is specified as the mode argument in a call of FSfopen, the file being opened will
682+// be created if it doesn't exist. If it does exist, it's file information will be loaded and the
683+// current location in the file will be set to the end. The user will then be able to write to the file
684+// or read from the file.
685+#define FS_APPENDPLUS "a+"
686+#define APPENDPLUS "a+" //deprecated
687+
688+// Summary: Macro for the FSfopen FS_WRITE+ mode
689+// Description: If this macro is specified as the mode argument in a call of FSfopen, the file being opened will
690+// be created if it doesn't exist. If it does exist, it will be erased and replaced by an empty file
691+// of the same name. The user will then be able to write to the file or read from the file.
692+#define FS_WRITEPLUS "w+"
693+#define WRITEPLUS "w+" //deprecated
694+
695+// Summary: Macro for the FSfopen FS_READ+ mode
696+// Description: If this macro is specified as the mode argument in a call of FSfopen, the file information for the
697+// specified file will be loaded. If the file does not exist, the FSfopen function will fail. The user
698+// will then be able to read from the file or write to the file.
699+#define FS_READPLUS "r+"
700+#define READPLUS "r+" //deprecated
701+
702+
703+
704+#ifndef intmax_t
705+ #ifdef __PIC24F__
706+ // Summary: A data type indicating the maximum integer size in an architecture
707+ // Description: The intmax_t data type refers to the maximum-sized data type on any given architecture. This
708+ // data type can be specified as a format specifier size specification for the FSfprintf function.
709+ #define intmax_t long long
710+ #elif defined __PIC24H__
711+ #define intmax_t long long
712+ #elif defined __dsPIC30F__
713+ #define intmax_t long long
714+ #elif defined __dsPIC33F__
715+ #define intmax_t long long
716+ #endif
717+#endif
718+
719+
720+
721+// Summary: Indicates flag conditions for a file object
722+// Description: The FILEFLAGS structure is used to indicate conditions in a file. It contains three flags: 'write' indicates
723+// that the file was opened in a mode that allows writes, 'read' indicates that the file was opened in a mode
724+// that allows reads, and 'FileWriteEOF' indicates that additional data that is written to the file will increase
725+// the file size.
726+typedef struct
727+{
728+ unsigned write :1; // Indicates a file was opened in a mode that allows writes
729+ unsigned read :1; // Indicates a file was opened in a mode that allows reads
730+ unsigned FileWriteEOF :1; // Indicates the current position in a file is at the end of the file
731+}FILEFLAGS;
732+
733+
734+
735+// Summary: Indicates how to search for file entries in the FILEfind function
736+// Description: The values in the SEARCH_TYPE enumeration are used internally by the library to indicate how the FILEfind function
737+// how to perform a search. The 'LOOK_FOR_EMPTY_ENTRY' value indicates that FILEfind should search for an empty file entry.
738+// The 'LOOK_FOR_MATCHING_ENTRY' value indicates that FILEfind should search for an entry that matches the FSFILE object
739+// that was passed into the FILEfind function.
740+typedef enum{
741+ LOOK_FOR_EMPTY_ENTRY = 0,
742+ LOOK_FOR_MATCHING_ENTRY
743+} SEARCH_TYPE;
744+
745+
746+
747+// Summary: Macro indicating the length of a 8.3 file name
748+// Description: The TOTAL_FILE_SIZE_8P3 macro indicates the maximum number of characters in an 8.3 file name. This value includes
749+// 8 characters for the name, three for the extentsion, and 1 for the radix ('.')
750+#define TOTAL_FILE_SIZE_8P3 (8+3+1)
751+#define TOTAL_FILE_SIZE TOTAL_FILE_SIZE_8P3
752+
753+// Summary: Macro indicating the max length of a LFN file name
754+// Description: The MAX_FILE_NAME_LENGTH_LFN macro indicates the maximum number of characters in an LFN file name.
755+#define MAX_FILE_NAME_LENGTH_LFN 256
756+
757+// Summary: A mask that indicates the limit of directory entries in a sector
758+// Description: The MASK_MAX_FILE_ENTRY_LIMIT_BITS is used to indicate to the Cache_File_Entry function that a new sector needs to
759+// be loaded.
760+#define MASK_MAX_FILE_ENTRY_LIMIT_BITS 0x0f
761+
762+// Summary: Value used for shift operations to calculate the sector offset in a directory
763+// Description: The VALUE_BASED_ON_ENTRIES_PER_CLUSTER macro is used to calculate sector offsets for directories. The position of the
764+// entry is shifted by 4 bits (divided by 16, since there are 16 entries in a sector) to calculate how many sectors a
765+// specified entry is offset from the beginning of the directory.
766+#define VALUE_BASED_ON_ENTRIES_PER_CLUSTER 4
767+
768+// Summary: A value that will indicate that a dotdot directory entry points to the root.
769+// Description: The VALUE_DOTDOT_CLUSTER_VALUE_FOR_ROOT macro is used as an absolute address when writing information to a dotdot entry
770+// in a newly created directory. If a dotdot entry points to the root directory, it's cluster value must be set to 0,
771+// regardless of the actual cluster number of the root directory.
772+#define VALUE_DOTDOT_CLUSTER_VALUE_FOR_ROOT 0
773+
774+// Summary: MAcro indicating the length of an 8.3 file name in a directory entry
775+// Description: The FILE_NAME_SIZE_8P3 macro indicates the number of characters that an 8.3 file name will take up when packed in
776+// a directory entry. This value includes 8 characters for the name and 3 for the extension. Note that the radix is not
777+// stored in the directory entry.
778+#define FILE_NAME_SIZE_8P3 11
779+#define FILE_NAME_SIZE FILE_NAME_SIZE_8P3
780+
781+
782+// Summary: Contains file information and is used to indicate which file to access.
783+// Description: The FSFILE structure is used to hold file information for an open file as it's being modified or accessed. A pointer to
784+// an open file's FSFILE structure will be passeed to any library function that will modify that file.
785+typedef struct
786+{
787+ DISK * dsk; // Pointer to a DISK structure
788+ DWORD cluster; // The first cluster of the file
789+ DWORD ccls; // The current cluster of the file
790+ WORD sec; // The current sector in the current cluster of the file
791+ WORD pos; // The position in the current sector
792+ DWORD seek; // The absolute position in the file
793+ DWORD size; // The size of the file
794+ FILEFLAGS flags; // A structure containing file flags
795+ WORD time; // The file's last update time
796+ WORD date; // The file's last update date
797+ char name[FILE_NAME_SIZE_8P3]; // The short name of the file
798+ #ifdef SUPPORT_LFN
799+ BOOL AsciiEncodingType; // Ascii file name or Non-Ascii file name indicator
800+ unsigned short int *utf16LFNptr; // Pointer to long file name in UTF16 format
801+ unsigned short int utf16LFNlength; // LFN length in terms of words including the NULL word at the last.
802+ #endif
803+ WORD entry; // The position of the file's directory entry in it's directory
804+ WORD chk; // File structure checksum
805+ WORD attributes; // The file attributes
806+ DWORD dirclus; // The base cluster of the file's directory
807+ DWORD dirccls; // The current cluster of the file's directory
808+} FSFILE;
809+
810+/* Summary: Possible results of the FSGetDiskProperties() function.
811+** Description: See the FSGetDiskProperties() function for more information.
812+*/
813+typedef enum
814+{
815+ FS_GET_PROPERTIES_NO_ERRORS = 0,
816+ FS_GET_PROPERTIES_DISK_NOT_MOUNTED,
817+ FS_GET_PROPERTIES_CLUSTER_FAILURE,
818+ FS_GET_PROPERTIES_STILL_WORKING = 0xFF
819+} FS_DISK_ERRORS;
820+
821+
822+/* Summary: Contains the disk search information, intermediate values, and results
823+** Description: This structure is used in conjunction with the FSGetDiskProperties()
824+** function. See that function for more information about the usage.
825+*/
826+typedef struct
827+{
828+ DISK * disk; /* pointer to the disk we are searching */
829+ BOOL new_request; /* is this a new request or a continued request */
830+ FS_DISK_ERRORS properties_status; /* status of the last call of the function */
831+
832+ struct
833+ {
834+ BYTE disk_format; /* disk format: FAT12, FAT16, FAT32 */
835+ WORD sector_size; /* sector size of the drive */
836+ BYTE sectors_per_cluster; /* number of sectors per cluster */
837+ DWORD total_clusters; /* the number of total clusters on the drive */
838+ DWORD free_clusters; /* the number of free (unused) clusters on drive */
839+ } results; /* the results of the current search */
840+
841+ struct
842+ {
843+ DWORD c;
844+ DWORD curcls;
845+ DWORD EndClusterLimit;
846+ DWORD ClusterFailValue;
847+ } private; /* intermediate values used to continue searches. This
848+ member should be used only by the FSGetDiskProperties()
849+ function */
850+
851+} FS_DISK_PROPERTIES;
852+
853+// Summary: A structure used for searching for files on a device.
854+// Description: The SearchRec structure is used when searching for file on a device. It contains parameters that will be loaded with
855+// file information when a file is found. It also contains the parameters that the user searched for, allowing further
856+// searches to be perfomed in the same directory for additional files that meet the specified criteria.
857+typedef struct
858+{
859+ char filename[FILE_NAME_SIZE_8P3 + 2]; // The name of the file that has been found
860+ unsigned char attributes; // The attributes of the file that has been found
861+ unsigned long filesize; // The size of the file that has been found
862+ unsigned long timestamp; // The last modified time of the file that has been found (create time for directories)
863+ #ifdef SUPPORT_LFN
864+ BOOL AsciiEncodingType; // Ascii file name or Non-Ascii file name indicator
865+ unsigned short int *utf16LFNfound; // Pointer to long file name found in UTF16 format
866+ unsigned short int utf16LFNfoundLength; // LFN Found length in terms of words including the NULL word at the last.
867+ #endif
868+ unsigned int entry; // The directory entry of the last file found that matches the specified attributes. (Internal use only)
869+ char searchname[FILE_NAME_SIZE_8P3 + 2]; // The 8.3 format name specified when the user began the search. (Internal use only)
870+ unsigned char searchattr; // The attributes specified when the user began the search. (Internal use only)
871+ unsigned long cwdclus; // The directory that this search was performed in. (Internal use only)
872+ unsigned char initialized; // Check to determine if the structure was initialized by FindFirst (Internal use only)
873+} SearchRec;
874+
875+
876+/***************************************************************************
877+* Prototypes *
878+***************************************************************************/
879+
880+
881+
882+
883+/*************************************************************************
884+ Function:
885+ int FSInit(void)
886+ Summary:
887+ Function to initialize the device.
888+ Conditions:
889+ The physical device should be connected to the microcontroller.
890+ Input:
891+ None
892+ Return Values:
893+ TRUE - Initialization successful
894+ FALSE - Initialization unsuccessful
895+ Side Effects:
896+ The FSerrno variable will be changed.
897+ Description:
898+ Initializes the static or dynamic memory slots for holding file
899+ structures. Initializes the device with the DISKmount function. Loads
900+ MBR and boot sector information. Initializes the current working
901+ directory to the root directory for the device if directory support
902+ is enabled.
903+ Remarks:
904+ None
905+ *************************************************************************/
906+
907+int FSInit(void);
908+
909+
910+/*********************************************************************
911+ Function:
912+ FSFILE * FSfopen (const char * fileName, const char *mode)
913+ Summary:
914+ Open a Ascii file
915+ Conditions:
916+ For read modes, file exists; FSInit performed
917+ Input:
918+ fileName - The name of the file to open
919+ mode -
920+ - WRITE - Create a new file or replace an existing file
921+ - READ - Read data from an existing file
922+ - APPEND - Append data to an existing file
923+ - WRITEPLUS - Create a new file or replace an existing file (reads also enabled)
924+ - READPLUS - Read data from an existing file (writes also enabled)
925+ - APPENDPLUS - Append data to an existing file (reads also enabled)
926+ Return Values:
927+ FSFILE * - The pointer to the file object
928+ NULL - The file could not be opened
929+ Side Effects:
930+ The FSerrno variable will be changed.
931+ Description:
932+ This function will open a file or directory. First, RAM in the
933+ dynamic heap or static array will be allocated to a new FSFILE object.
934+ Then, the specified file name will be formatted to ensure that it's
935+ in 8.3 format or LFN format. Next, the FILEfind function will be used
936+ to search for the specified file name. If the name is found, one of three
937+ things will happen: if the file was opened in read mode, its file
938+ info will be loaded using the FILEopen function; if it was opened in
939+ write mode, it will be erased, and a new file will be constructed in
940+ its place; if it was opened in append mode, its file info will be
941+ loaded with FILEopen and the current location will be moved to the
942+ end of the file using the FSfseek function. If the file was not
943+ found by FILEfind, a new file will be created if the mode was specified as
944+ a write or append mode. In these cases, a pointer to the heap or
945+ static FSFILE object array will be returned. If the file was not
946+ found and the mode was specified as a read mode, the memory
947+ allocated to the file will be freed and the NULL pointer value
948+ will be returned.
949+ Remarks:
950+ None.
951+ *********************************************************************/
952+
953+FSFILE * FSfopen(const char * fileName, const char *mode);
954+
955+#ifdef SUPPORT_LFN
956+/*********************************************************************
957+ Function:
958+ FSFILE * wFSfopen (const unsigned short int * fileName, const char *mode)
959+ Summary:
960+ Open a UTF16 file.
961+ Conditions:
962+ For read modes, file exists; FSInit performed
963+ Input:
964+ fileName - The name of the file to open
965+ mode -
966+ - WRITE - Create a new file or replace an existing file
967+ - READ - Read data from an existing file
968+ - APPEND - Append data to an existing file
969+ - WRITEPLUS - Create a new file or replace an existing file (reads also enabled)
970+ - READPLUS - Read data from an existing file (writes also enabled)
971+ - APPENDPLUS - Append data to an existing file (reads also enabled)
972+ Return Values:
973+ FSFILE * - The pointer to the file object
974+ NULL - The file could not be opened
975+ Side Effects:
976+ The FSerrno variable will be changed.
977+ Description:
978+ This function will open a file or directory. First, RAM in the
979+ dynamic heap or static array will be allocated to a new FSFILE object.
980+ Then, the specified file name will be formatted to ensure that it's
981+ in 8.3 format or LFN format. Next, the FILEfind function will be used
982+ to search for the specified file name. If the name is found, one of three
983+ things will happen: if the file was opened in read mode, its file
984+ info will be loaded using the FILEopen function; if it was opened in
985+ write mode, it will be erased, and a new file will be constructed in
986+ its place; if it was opened in append mode, its file info will be
987+ loaded with FILEopen and the current location will be moved to the
988+ end of the file using the FSfseek function. If the file was not
989+ found by FILEfind, a new file will be created if the mode was specified as
990+ a write or append mode. In these cases, a pointer to the heap or
991+ static FSFILE object array will be returned. If the file was not
992+ found and the mode was specified as a read mode, the memory
993+ allocated to the file will be freed and the NULL pointer value
994+ will be returned.
995+ Remarks:
996+ None.
997+ *********************************************************************/
998+
999+FSFILE * wFSfopen(const unsigned short int * fileName, const char *mode);
1000+#endif
1001+
1002+#ifdef ALLOW_PGMFUNCTIONS
1003+
1004+/******************************************************************************
1005+ Function:
1006+ FSFILE * FSfopenpgm(const rom char * fileName, const rom char *mode)
1007+ Summary:
1008+ Open a Ascii file named with a ROM string on PIC18
1009+ Conditions:
1010+ For read modes, file exists; FSInit performed
1011+ Input:
1012+ fileName - The name of the file to be opened (ROM)
1013+ mode - The mode the file will be opened in (ROM)
1014+ Return Values:
1015+ FSFILE * - A pointer to the file object
1016+ NULL - File could not be opened
1017+ Side Effects:
1018+ The FSerrno variable will be changed.
1019+ Description:
1020+ The FSfopenpgm function will copy a PIC18 ROM fileName and mode argument
1021+ into RAM arrays, and then pass those arrays to the FSfopen function.
1022+ Remarks:
1023+ This function is for use with PIC18 when passing arguments in ROM.
1024+ ******************************************************************************/
1025+
1026+ FSFILE * FSfopenpgm(const rom char * fileName, const rom char *mode);
1027+
1028+
1029+/**************************************************************************************
1030+ Function:
1031+ int FindFirstpgm (const char * fileName, unsigned int attr, SearchRec * rec)
1032+ Summary:
1033+ Find a file named with a ROM string on PIC18
1034+ Conditions:
1035+ None
1036+ Input:
1037+ fileName - The name of the file to be found (ROM)
1038+ attr - The attributes of the file to be found
1039+ rec - Pointer to a search record to store the file info in
1040+ Return Values:
1041+ 0 - File was found
1042+ -1 - No file matching the given parameters was found
1043+ Side Effects:
1044+ Search criteria from previous FindFirstpgm call on passed SearchRec object
1045+ will be lost.The FSerrno variable will be changed.
1046+ Description:
1047+ The FindFirstpgm function will copy a PIC18 ROM fileName argument
1048+ into a RAM array, and then pass that array to the FindFirst function.
1049+ Remarks:
1050+ Call FindFirstpgm or FindFirst before calling FindNext.
1051+ This function is for use with PIC18 when passing arguments in ROM.
1052+ **************************************************************************************/
1053+
1054+ int FindFirstpgm (const rom char * fileName, unsigned int attr, SearchRec * rec);
1055+
1056+
1057+/**************************************************************************
1058+ Function:
1059+ int FSchdirpgm (const rom char * path)
1060+ Summary:
1061+ Changed the CWD with a path in ROM on PIC18
1062+ Conditions:
1063+ None
1064+ Input:
1065+ path - The path of the directory to change to (ROM)
1066+ Return Values:
1067+ 0 - The current working directory was changed successfully
1068+ EOF - The current working directory could not be changed
1069+ Side Effects:
1070+ The current working directory may be changed. The FSerrno variable will
1071+ be changed.
1072+ Description:
1073+ The FSchdirpgm function passes a PIC18 ROM path pointer to the
1074+ chdirhelper function.
1075+ Remarks:
1076+ This function is for use with PIC18 when passing arguments in ROM
1077+ **************************************************************************/
1078+
1079+ int FSchdirpgm (const rom char * path);
1080+
1081+ #ifdef ALLOW_WRITES
1082+
1083+
1084+/*************************************************************
1085+ Function:
1086+ int FSremovepgm (const rom char * fileName)
1087+ Summary:
1088+ Delete a file named with a ROM string on PIC18
1089+ Conditions:
1090+ File not opened; file exists
1091+ Input:
1092+ fileName - The name of the file to be deleted (ROM)
1093+ Return Values:
1094+ 0 - File was removed successfully
1095+ -1 - File could not be removed
1096+ Side Effects:
1097+ The FSerrno variable will be changed.
1098+ Description:
1099+ The FSremovepgm function will copy a PIC18 ROM fileName argument
1100+ into a RAM array, and then pass that array to the FSremove function.
1101+ Remarks:
1102+ This function is for use with PIC18 when passing arguments in ROM.
1103+ *************************************************************/
1104+
1105+ int FSremovepgm (const rom char * fileName);
1106+
1107+
1108+/**************************************************************************
1109+ Function:
1110+ int FSmkdirpgm (const rom char * path)
1111+ Summary:
1112+ Create a directory with a path in ROM on PIC18
1113+ Conditions:
1114+ None
1115+ Input:
1116+ path - The path of directories to create (ROM)
1117+ Return Values:
1118+ 0 - The specified directory was created successfully
1119+ EOF - The specified directory could not be created
1120+ Side Effects:
1121+ Will create all non-existent directories in the path. The FSerrno
1122+ variable will be changed.
1123+ Description:
1124+ The FSmkdirpgm function passes a PIC18 ROM path pointer to the
1125+ mkdirhelper function.
1126+ Remarks:
1127+ This function is for use with PIC18 when passing arugments in ROM
1128+ **************************************************************************/
1129+
1130+ int FSmkdirpgm (const rom char * path);
1131+
1132+
1133+/**************************************************************************
1134+ Function:
1135+ int FSrmdirpgm (const rom char * path)
1136+ Summary:
1137+ Delete a directory with a path in ROM on PIC18
1138+ Conditions:
1139+ None.
1140+ Input:
1141+ path - The path of the directory to remove (ROM)
1142+ rmsubdirs -
1143+ - TRUE - All sub-dirs and files in the target dir will be removed
1144+ - FALSE - FSrmdir will not remove non-empty directories
1145+ Return Values:
1146+ 0 - The specified directory was deleted successfully
1147+ EOF - The specified directory could not be deleted
1148+ Side Effects:
1149+ The FSerrno variable will be changed.
1150+ Description:
1151+ The FSrmdirpgm function passes a PIC18 ROM path pointer to the
1152+ rmdirhelper function.
1153+ Remarks:
1154+ This function is for use with PIC18 when passing arguments in ROM.
1155+ **************************************************************************/
1156+
1157+ int FSrmdirpgm (const rom char * path, unsigned char rmsubdirs);
1158+
1159+
1160+/*****************************************************************
1161+ Function:
1162+ int FSrenamepgm(const rom char * fileName, FSFILE * fo)
1163+ Summary:
1164+ Rename a file named with a ROM string on PIC18
1165+ Conditions:
1166+ File opened.
1167+ Input:
1168+ fileName - The new name of the file (in ROM)
1169+ fo - The file to rename
1170+ Return Values:
1171+ 0 - File renamed successfully
1172+ -1 - File could not be renamed
1173+ Side Effects:
1174+ The FSerrno variable will be changed.
1175+ Description:
1176+ The Fsrenamepgm function will copy the rom fileName specified
1177+ by the user into a RAM array and pass that array into the
1178+ FSrename function.
1179+ Remarks:
1180+ This function is for use with PIC18 when passing arguments in ROM.
1181+ *****************************************************************/
1182+
1183+ int FSrenamepgm (const rom char * fileName, FSFILE * fo);
1184+ #endif
1185+#endif
1186+
1187+
1188+/************************************************************
1189+ Function:
1190+ int FSfclose(FSFILE *fo)
1191+ Summary:
1192+ Update file information and free FSFILE objects
1193+ Conditions:
1194+ File opened
1195+ Input:
1196+ fo - Pointer to the file to close
1197+ Return Values:
1198+ 0 - File closed successfully
1199+ EOF - Error closing the file
1200+ Side Effects:
1201+ The FSerrno variable will be changed.
1202+ Description:
1203+ This function will update the directory entry for the
1204+ file pointed to by 'fo' with the information contained
1205+ in 'fo,' including the new file size and attributes.
1206+ Timestamp information will also be loaded based on the
1207+ method selected by the user and written to the entry
1208+ as the last modified time and date. The file entry will
1209+ then be written to the device. Finally, the memory
1210+ used for the specified file object will be freed from
1211+ the dynamic heap or the array of FSFILE objects.
1212+ Remarks:
1213+ A function to flush data to the device without closing the
1214+ file can be created by removing the portion of this
1215+ function that frees the memory and the line that clears
1216+ the write flag.
1217+ ************************************************************/
1218+
1219+int FSfclose(FSFILE *fo);
1220+
1221+
1222+/*********************************************************
1223+ Function:
1224+ void FSrewind (FSFILE * fo)
1225+ Summary:
1226+ Set the current position in a file to the beginning
1227+ Conditions:
1228+ File opened.
1229+ Input:
1230+ fo - Pointer to file structure
1231+ Return Values:
1232+ None
1233+ Side Effects:
1234+ None.
1235+ Description:
1236+ The FSrewind funciton will reset the position of the
1237+ specified file to the beginning of the file. This
1238+ functionality is faster than using FSfseek to reset
1239+ the position in the file.
1240+ Remarks:
1241+ None.
1242+ *********************************************************/
1243+
1244+void FSrewind (FSFILE *fo);
1245+
1246+
1247+/**************************************************************************
1248+ Function:
1249+ size_t FSfread(void *ptr, size_t size, size_t n, FSFILE *stream)
1250+ Summary:
1251+ Read data from a file
1252+ Conditions:
1253+ File is opened in a read mode
1254+ Input:
1255+ ptr - Destination buffer for read bytes
1256+ size - Size of units in bytes
1257+ n - Number of units to be read
1258+ stream - File to be read from
1259+ Return:
1260+ size_t - number of units read
1261+ Side Effects:
1262+ The FSerrno variable will be changed.
1263+ Description:
1264+ The FSfread function will read data from the specified file. First,
1265+ the appropriate sector of the file is loaded. Then, data is read into
1266+ the specified buffer until the specified number of bytes have been read.
1267+ When a cluster boundary is reached, a new cluster will be loaded. The
1268+ parameters 'size' and 'n' indicate how much data to read. 'Size'
1269+ refers to the size of one object to read (in bytes), and 'n' will refer
1270+ to the number of these objects to read. The value returned will be equal
1271+ to 'n' unless an error occured or the user tried to read beyond the end
1272+ of the file.
1273+ Remarks:
1274+ None.
1275+ **************************************************************************/
1276+
1277+size_t FSfread(void *ptr, size_t size, size_t n, FSFILE *stream);
1278+
1279+
1280+/**********************************************************************
1281+ Function:
1282+ int FSfseek(FSFILE *stream, long offset, int whence)
1283+ Summary:
1284+ Change the current position in a file
1285+ Conditions:
1286+ File opened
1287+ Input:
1288+ stream - Pointer to file structure
1289+ offset - Offset from base location
1290+ whence -
1291+ - SEEK_SET - Seek from start of file
1292+ - SEEK_CUR - Seek from current location
1293+ - SEEK_END - Seek from end of file (subtract offset)
1294+ Return Values:
1295+ 0 - Operation successful
1296+ -1 - Operation unsuccesful
1297+ Side Effects:
1298+ The FSerrno variable will be changed.
1299+ Description:
1300+ The FSfseek function will change the current position in the file to
1301+ one specified by the user. First, an absolute offset is calculated
1302+ using the offset and base location passed in by the user. Then, the
1303+ position variables are updated, and the sector number that corresponds
1304+ to the new location. That sector is then loaded. If the offset
1305+ falls exactly on a cluster boundary, a new cluster will be allocated
1306+ to the file and the position will be set to the first byte of that
1307+ cluster.
1308+ Remarks:
1309+ None
1310+ **********************************************************************/
1311+
1312+int FSfseek(FSFILE *stream, long offset, int whence);
1313+
1314+
1315+/*******************************************************************
1316+ Function:
1317+ long FSftell (FSFILE * fo)
1318+ Summary:
1319+ Determine the current location in a file
1320+ Conditions:
1321+ File opened
1322+ Input:
1323+ fo - Pointer to file structure
1324+ Return: Current location in the file
1325+ Side Effects:
1326+ The FSerrno variable will be changed
1327+ Description:
1328+ The FSftell function will return the current position in the
1329+ file pointed to by 'fo' by returning the 'seek' variable in the
1330+ FSFILE object, which is used to keep track of the absolute
1331+ location of the current position in the file.
1332+ Remarks:
1333+ None
1334+ *******************************************************************/
1335+
1336+long FSftell(FSFILE *fo);
1337+
1338+
1339+/****************************************************
1340+ Function:
1341+ int FSfeof( FSFILE * stream )
1342+ Summary:
1343+ Indicate whether the current file position is at the end
1344+ Conditions:
1345+ File is open in a read mode
1346+ Input:
1347+ stream - Pointer to the target file
1348+ Return Values:
1349+ Non-Zero - EOF reached
1350+ 0 - Not at end of File
1351+ Side Effects:
1352+ The FSerrno variable will be changed.
1353+ Description:
1354+ The FSfeof function will indicate that the end-of-
1355+ file has been reached for the specified file by
1356+ comparing the absolute location in the file to the
1357+ size of the file.
1358+ Remarks:
1359+ None.
1360+ ****************************************************/
1361+
1362+int FSfeof( FSFILE * stream );
1363+
1364+
1365+#ifdef ALLOW_FORMATS
1366+/*******************************************************************
1367+ Function:
1368+ int FSformat (char mode, long int serialNumber, char * volumeID)
1369+ Summary:
1370+ Formats a device
1371+ Conditions:
1372+ The device must possess a valid master boot record.
1373+ Input:
1374+ mode - - 0 - Just erase the FAT and root
1375+ - 1 - Create a new boot sector
1376+ serialNumber - Serial number to write to the card
1377+ volumeID - Name of the card
1378+ Return Values:
1379+ 0 - Format was successful
1380+ EOF - Format was unsuccessful
1381+ Side Effects:
1382+ The FSerrno variable will be changed.
1383+ Description:
1384+ The FSformat function can be used to create a new boot sector
1385+ on a device, based on the information in the master boot record.
1386+ This function will first initialize the I/O pins and the device,
1387+ and then attempts to read the master boot record. If the MBR
1388+ cannot be loaded successfully, the function will fail. Next, if
1389+ the 'mode' argument is specified as '0' the existing boot sector
1390+ information will be loaded. If the 'mode' argument is '1' an
1391+ entirely new boot sector will be constructed using the disk
1392+ values from the master boot record. Once the boot sector has
1393+ been successfully loaded/created, the locations of the FAT and
1394+ root will be loaded from it, and they will be completely
1395+ erased. If the user has specified a volumeID parameter, a
1396+ VOLUME attribute entry will be created in the root directory
1397+ to name the device.
1398+
1399+ FAT12, FAT16 and FAT32 formatting are supported.
1400+
1401+ Based on the number of sectors, the format function automatically
1402+ compute the smallest possible value for the cluster size in order to
1403+ accommodate the physical size of the media. In this case, if a media
1404+ with a big capacity is formatted, the format function may take a very
1405+ long time to write all the FAT tables.
1406+
1407+ Therefore, the FORMAT_SECTORS_PER_CLUSTER macro may be used to
1408+ specify the exact cluster size (in multiples of sector size). This
1409+ macro can be defined in FSconfig.h
1410+
1411+ Remarks:
1412+ Only devices with a sector size of 512 bytes are supported by the
1413+ format function
1414+ *******************************************************************/
1415+
1416+int FSformat (char mode, long int serialNumber, char * volumeID);
1417+#endif
1418+
1419+
1420+#ifdef ALLOW_WRITES
1421+/***************************************************************************
1422+ Function:
1423+ int FSattrib (FSFILE * file, unsigned char attributes)
1424+ Summary:
1425+ Change the attributes of a file
1426+ Conditions:
1427+ File opened
1428+ Input:
1429+ file - Pointer to file structure
1430+ attributes - The attributes to set for the file
1431+ - Attribute - Value - Indications
1432+ - ATTR_READ_ONLY - 0x01 - The read-only attribute
1433+ - ATTR_HIDDEN - 0x02 - The hidden attribute
1434+ - ATTR_SYSTEM - 0x04 - The system attribute
1435+ - ATTR_ARCHIVE - 0x20 - The archive attribute
1436+ Return Values:
1437+ 0 - Attribute change was successful
1438+ -1 - Attribute change was unsuccessful
1439+ Side Effects:
1440+ The FSerrno variable will be changed.
1441+ Description:
1442+ The FSattrib funciton will set the attributes of the specified file
1443+ to the attributes passed in by the user. This function will load the
1444+ file entry, replace the attributes with the ones specified, and write
1445+ the attributes back. If the specified file is a directory, the
1446+ directory attribute will be preserved.
1447+ Remarks:
1448+ None
1449+ ***************************************************************************/
1450+
1451+int FSattrib (FSFILE * file, unsigned char attributes);
1452+
1453+
1454+/***************************************************************
1455+ Function:
1456+ int FSrename (const rom char * fileName, FSFILE * fo)
1457+ Summary:
1458+ Change the Ascii name of a file or directory
1459+ Conditions:
1460+ File opened.
1461+ Input:
1462+ fileName - The new name of the file
1463+ fo - The file to rename
1464+ Return Values:
1465+ 0 - File was renamed successfully
1466+ EOF - File was not renamed
1467+ Side Effects:
1468+ The FSerrno variable will be changed.
1469+ Description:
1470+ The FSrename function will rename a file. First, it will
1471+ search through the current working directory to ensure the
1472+ specified new filename is not already in use. If it isn't,
1473+ the new filename will be written to the file entry of the
1474+ file pointed to by 'fo.'
1475+ Remarks:
1476+ None
1477+ ***************************************************************/
1478+
1479+int FSrename (const char * fileName, FSFILE * fo);
1480+
1481+#ifdef SUPPORT_LFN
1482+/***************************************************************
1483+ Function:
1484+ int wFSrename (const rom unsigned short int * fileName, FSFILE * fo)
1485+ Summary:
1486+ Change the name of a file or directory to the UTF16 input fileName
1487+ Conditions:
1488+ File opened.
1489+ Input:
1490+ fileName - The new name of the file
1491+ fo - The file to rename
1492+ Return Values:
1493+ 0 - File was renamed successfully
1494+ EOF - File was not renamed
1495+ Side Effects:
1496+ The FSerrno variable will be changed.
1497+ Description:
1498+ The wFSrename function will rename a file. First, it will
1499+ search through the current working directory to ensure the
1500+ specified new UTF16 filename is not already in use. If it isn't,
1501+ the new filename will be written to the file entry of the
1502+ file pointed to by 'fo.'
1503+ Remarks:
1504+ None
1505+ ***************************************************************/
1506+
1507+int wFSrename (const unsigned short int * fileName, FSFILE * fo);
1508+#endif
1509+
1510+/*********************************************************************
1511+ Function:
1512+ int FSremove (const char * fileName)
1513+ Summary:
1514+ Delete a Ascii file
1515+ Conditions:
1516+ File not opened, file exists
1517+ Input:
1518+ fileName - Name of the file to erase
1519+ Return Values:
1520+ 0 - File removed
1521+ EOF - File was not removed
1522+ Side Effects:
1523+ The FSerrno variable will be changed.
1524+ Description:
1525+ The FSremove function will attempt to find the specified file with
1526+ the FILEfind function. If the file is found, it will be erased
1527+ using the FILEerase function.The user can also provide ascii alias name
1528+ of the ascii long file name as the input to this function to get it erased
1529+ from the memory.
1530+ Remarks:
1531+ None
1532+ **********************************************************************/
1533+
1534+int FSremove (const char * fileName);
1535+
1536+#ifdef SUPPORT_LFN
1537+/*********************************************************************
1538+ Function:
1539+ int wFSremove (const unsigned short int * fileName)
1540+ Summary:
1541+ Delete a UTF16 file
1542+ Conditions:
1543+ File not opened, file exists
1544+ Input:
1545+ fileName - Name of the file to erase
1546+ Return Values:
1547+ 0 - File removed
1548+ EOF - File was not removed
1549+ Side Effects:
1550+ The FSerrno variable will be changed.
1551+ Description:
1552+ The wFSremove function will attempt to find the specified UTF16 file
1553+ name with the FILEfind function. If the file is found, it will be erased
1554+ using the FILEerase function.
1555+ Remarks:
1556+ None
1557+ **********************************************************************/
1558+
1559+int wFSremove (const unsigned short int * fileName);
1560+#endif
1561+
1562+/*********************************************************************************
1563+ Function:
1564+ size_t FSfwrite(const void *data_to_write, size_t size, size_t n, FSFILE *stream)
1565+ Summary:
1566+ Write data to a file
1567+ Conditions:
1568+ File opened in WRITE, APPEND, WRITE+, APPEND+, READ+ mode
1569+ Input:
1570+ data_to_write - Pointer to source buffer
1571+ size - Size of units in bytes
1572+ n - Number of units to transfer
1573+ stream - Pointer to file structure
1574+ Return:
1575+ size_t - number of units written
1576+ Side Effects:
1577+ The FSerrno variable will be changed.
1578+ Description:
1579+ The FSfwrite function will write data to a file. First, the sector that
1580+ corresponds to the current position in the file will be loaded (if it hasn't
1581+ already been cached in the global data buffer). Data will then be written to
1582+ the device from the specified buffer until the specified amount has been written.
1583+ If the end of a cluster is reached, the next cluster will be loaded, unless
1584+ the end-of-file flag for the specified file has been set. If it has, a new
1585+ cluster will be allocated to the file. Finally, the new position and filesize
1586+ will be stored in the FSFILE object. The parameters 'size' and 'n' indicate how
1587+ much data to write. 'Size' refers to the size of one object to write (in bytes),
1588+ and 'n' will refer to the number of these objects to write. The value returned
1589+ will be equal to 'n' unless an error occured.
1590+ Remarks:
1591+ None.
1592+ *********************************************************************************/
1593+
1594+size_t FSfwrite(const void *data_to_write, size_t size, size_t n, FSFILE *stream);
1595+
1596+#endif
1597+
1598+#ifdef ALLOW_DIRS
1599+
1600+
1601+/**************************************************************************
1602+ Function:
1603+ int FSchdir (char * path)
1604+ Summary:
1605+ Change the current working directory as per the path specified in Ascii format
1606+ Conditions:
1607+ None
1608+ Input:
1609+ path - The path of the directory to change to.
1610+ Return Values:
1611+ 0 - The current working directory was changed successfully
1612+ EOF - The current working directory could not be changed
1613+ Side Effects:
1614+ The current working directory may be changed. The FSerrno variable will
1615+ be changed.
1616+ Description:
1617+ The FSchdir function passes a RAM pointer to the path to the
1618+ chdirhelper function.
1619+ Remarks:
1620+ None
1621+ **************************************************************************/
1622+
1623+int FSchdir (char * path);
1624+
1625+#ifdef SUPPORT_LFN
1626+/**************************************************************************
1627+ Function:
1628+ int wFSchdir (unsigned short int * path)
1629+ Summary:
1630+ Change the current working directory as per the path specified in UTF16 format
1631+ Conditions:
1632+ None
1633+ Input:
1634+ path - The path of the directory to change to.
1635+ Return Values:
1636+ 0 - The current working directory was changed successfully
1637+ EOF - The current working directory could not be changed
1638+ Side Effects:
1639+ The current working directory may be changed. The FSerrno variable will
1640+ be changed.
1641+ Description:
1642+ The FSchdir function passes a RAM pointer to the path to the
1643+ chdirhelper function.
1644+ Remarks:
1645+ None
1646+ **************************************************************************/
1647+
1648+int wFSchdir (unsigned short int * path);
1649+#endif
1650+
1651+/**************************************************************
1652+ Function:
1653+ char * FSgetcwd (char * path, int numchars)
1654+ Summary:
1655+ Get the current working directory path in Ascii format
1656+ Conditions:
1657+ None
1658+ Input:
1659+ path - Pointer to the array to return the cwd name in
1660+ numchars - Number of chars in the path
1661+ Return Values:
1662+ char * - The cwd name string pointer (path or defaultArray)
1663+ NULL - The current working directory name could not be loaded.
1664+ Side Effects:
1665+ The FSerrno variable will be changed
1666+ Description:
1667+ The FSgetcwd function will get the name of the current
1668+ working directory and return it to the user. The name
1669+ will be copied into the buffer pointed to by 'path,'
1670+ starting at the root directory and copying as many chars
1671+ as possible before the end of the buffer. The buffer
1672+ size is indicated by the 'numchars' argument. The first
1673+ thing this function will do is load the name of the current
1674+ working directory, if it isn't already present. This could
1675+ occur if the user switched to the dotdot entry of a
1676+ subdirectory immediately before calling this function. The
1677+ function will then copy the current working directory name
1678+ into the buffer backwards, and insert a backslash character.
1679+ Next, the function will continuously switch to the previous
1680+ directories and copy their names backwards into the buffer
1681+ until it reaches the root. If the buffer overflows, it
1682+ will be treated as a circular buffer, and data will be
1683+ copied over existing characters, starting at the beginning.
1684+ Once the root directory is reached, the text in the buffer
1685+ will be swapped, so that the buffer contains as much of the
1686+ current working directory name as possible, starting at the
1687+ root.
1688+ Remarks:
1689+ None
1690+ **************************************************************/
1691+
1692+char * FSgetcwd (char * path, int numbchars);
1693+
1694+#ifdef SUPPORT_LFN
1695+/**************************************************************
1696+ Function:
1697+ char * wFSgetcwd (unsigned short int * path, int numchars)
1698+ Summary:
1699+ Get the current working directory path in UTF16 format
1700+ Conditions:
1701+ None
1702+ Input:
1703+ path - Pointer to the array to return the cwd name in
1704+ numchars - Number of chars in the path
1705+ Return Values:
1706+ char * - The cwd name string pointer (path or defaultArray)
1707+ NULL - The current working directory name could not be loaded.
1708+ Side Effects:
1709+ The FSerrno variable will be changed
1710+ Description:
1711+ The FSgetcwd function will get the name of the current
1712+ working directory and return it to the user. The name
1713+ will be copied into the buffer pointed to by 'path,'
1714+ starting at the root directory and copying as many chars
1715+ as possible before the end of the buffer. The buffer
1716+ size is indicated by the 'numchars' argument. The first
1717+ thing this function will do is load the name of the current
1718+ working directory, if it isn't already present. This could
1719+ occur if the user switched to the dotdot entry of a
1720+ subdirectory immediately before calling this function. The
1721+ function will then copy the current working directory name
1722+ into the buffer backwards, and insert a backslash character.
1723+ Next, the function will continuously switch to the previous
1724+ directories and copy their names backwards into the buffer
1725+ until it reaches the root. If the buffer overflows, it
1726+ will be treated as a circular buffer, and data will be
1727+ copied over existing characters, starting at the beginning.
1728+ Once the root directory is reached, the text in the buffer
1729+ will be swapped, so that the buffer contains as much of the
1730+ current working directory name as possible, starting at the
1731+ root.
1732+ Remarks:
1733+ None
1734+ **************************************************************/
1735+
1736+char * wFSgetcwd (unsigned short int * path, int numbchars);
1737+#endif
1738+
1739+#ifdef ALLOW_WRITES
1740+
1741+/**************************************************************************
1742+ Function:
1743+ int FSmkdir (char * path)
1744+ Summary:
1745+ Create a directory as per the Ascii input path
1746+ Conditions:
1747+ None
1748+ Input:
1749+ path - The path of directories to create.
1750+ Return Values:
1751+ 0 - The specified directory was created successfully
1752+ EOF - The specified directory could not be created
1753+ Side Effects:
1754+ Will create all non-existent directories in the path. The FSerrno
1755+ variable will be changed.
1756+ Description:
1757+ The FSmkdir function passes a RAM pointer to the path to the
1758+ mkdirhelper function.
1759+ Remarks:
1760+ None
1761+ **************************************************************************/
1762+
1763+int FSmkdir (char * path);
1764+
1765+#ifdef SUPPORT_LFN
1766+/**************************************************************************
1767+ Function:
1768+ int wFSmkdir (unsigned short int * path)
1769+ Summary:
1770+ Create a directory as per the UTF16 input path
1771+ Conditions:
1772+ None
1773+ Input:
1774+ path - The path of directories to create.
1775+ Return Values:
1776+ 0 - The specified directory was created successfully
1777+ EOF - The specified directory could not be created
1778+ Side Effects:
1779+ Will create all non-existent directories in the path. The FSerrno
1780+ variable will be changed.
1781+ Description:
1782+ The wFSmkdir function passes a RAM pointer to the path to the
1783+ mkdirhelper function.
1784+ Remarks:
1785+ None
1786+ **************************************************************************/
1787+
1788+int wFSmkdir (unsigned short int * path);
1789+#endif
1790+
1791+/**************************************************************************
1792+ Function:
1793+ int FSrmdir (char * path)
1794+ Summary:
1795+ Delete a directory as per the Ascii input path
1796+ Conditions:
1797+ None
1798+ Input:
1799+ path - The path of the directory to remove
1800+ rmsubdirs -
1801+ - TRUE - All sub-dirs and files in the target dir will be removed
1802+ - FALSE - FSrmdir will not remove non-empty directories
1803+ Return Values:
1804+ 0 - The specified directory was deleted successfully
1805+ EOF - The specified directory could not be deleted
1806+ Side Effects:
1807+ The FSerrno variable will be changed.
1808+ Description:
1809+ The FSrmdir function passes a RAM pointer to the path to the
1810+ rmdirhelper function.
1811+ Remarks:
1812+ None.
1813+ **************************************************************************/
1814+
1815+int FSrmdir (char * path, unsigned char rmsubdirs);
1816+
1817+#ifdef SUPPORT_LFN
1818+/**************************************************************************
1819+ Function:
1820+ int wFSrmdir (unsigned short int * path, unsigned char rmsubdirs)
1821+ Summary:
1822+ Delete a directory as per the UTF16 input path
1823+ Conditions:
1824+ None
1825+ Input:
1826+ path - The path of the directory to remove
1827+ rmsubdirs -
1828+ - TRUE - All sub-dirs and files in the target dir will be removed
1829+ - FALSE - FSrmdir will not remove non-empty directories
1830+ Return Values:
1831+ 0 - The specified directory was deleted successfully
1832+ EOF - The specified directory could not be deleted
1833+ Side Effects:
1834+ The FSerrno variable will be changed.
1835+ Description:
1836+ The wFSrmdir function passes a RAM pointer to the path to the
1837+ rmdirhelper function.
1838+ Remarks:
1839+ None.
1840+ **************************************************************************/
1841+
1842+int wFSrmdir (unsigned short int * path, unsigned char rmsubdirs);
1843+#endif
1844+
1845+#endif
1846+
1847+#endif
1848+
1849+#ifdef USERDEFINEDCLOCK
1850+
1851+
1852+/***********************************************************************************************************
1853+ Function:
1854+ int SetClockVars (unsigned int year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, unsigned char second)
1855+ Summary:
1856+ Manually set timestamp variables
1857+ Conditions:
1858+ USERDEFINEDCLOCK macro defined in FSconfig.h.
1859+ Input:
1860+ year - The year (1980\-2107)
1861+ month - The month (1\-12)
1862+ day - The day of the month (1\-31)
1863+ hour - The hour (0\-23)
1864+ minute - The minute (0\-59)
1865+ second - The second (0\-59)
1866+ Return Values:
1867+ None
1868+ Side Effects:
1869+ Modifies global timing variables
1870+ Description:
1871+ Lets the user manually set the timing variables. The values passed in will be converted to the format
1872+ used by the FAT timestamps.
1873+ Remarks:
1874+ Call this before creating a file or directory (set create time) and
1875+ before closing a file (set last access time, last modified time)
1876+ ***********************************************************************************************************/
1877+
1878+int SetClockVars (unsigned int year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, unsigned char second);
1879+#endif
1880+
1881+
1882+#ifdef ALLOW_FILESEARCH
1883+
1884+/***********************************************************************************
1885+ Function:
1886+ int FindFirst (const char * fileName, unsigned int attr, SearchRec * rec)
1887+ Summary:
1888+ Initial search function for the input Ascii fileName
1889+ Conditions:
1890+ None
1891+ Input:
1892+ fileName - The name to search for
1893+ - Parital string search characters
1894+ - * - Indicates the rest of the filename or extension can vary (e.g. FILE.*)
1895+ - ? - Indicates that one character in a filename can vary (e.g. F?LE.T?T)
1896+ attr - The attributes that a found file may have
1897+ - ATTR_READ_ONLY - File may be read only
1898+ - ATTR_HIDDEN - File may be a hidden file
1899+ - ATTR_SYSTEM - File may be a system file
1900+ - ATTR_VOLUME - Entry may be a volume label
1901+ - ATTR_DIRECTORY - File may be a directory
1902+ - ATTR_ARCHIVE - File may have archive attribute
1903+ - ATTR_MASK - All attributes
1904+ rec - pointer to a structure to put the file information in
1905+ Return Values:
1906+ 0 - File was found
1907+ -1 - No file matching the specified criteria was found
1908+ Side Effects:
1909+ Search criteria from previous FindFirst call on passed SearchRec object
1910+ will be lost. "utf16LFNfound" is overwritten after subsequent FindFirst/FindNext
1911+ operations.It is the responsibility of the application to read the "utf16LFNfound"
1912+ before it is lost.The FSerrno variable will be changed.
1913+ Description:
1914+ The FindFirst function will search for a file based on parameters passed in
1915+ by the user. This function will use the FILEfind function to parse through
1916+ the current working directory searching for entries that match the specified
1917+ parameters. If a file is found, its parameters are copied into the SearchRec
1918+ structure, as are the initial parameters passed in by the user and the position
1919+ of the file entry in the current working directory.If the return value of the
1920+ function is 0 then "utf16LFNfoundLength" indicates whether the file found was
1921+ long file name or short file name(8P3 format). The "utf16LFNfoundLength" is non-zero
1922+ for long file name and is zero for 8P3 format."utf16LFNfound" points to the
1923+ address of long file name if found during the operation.
1924+ Remarks:
1925+ Call FindFirst or FindFirstpgm before calling FindNext
1926+ ***********************************************************************************/
1927+
1928+int FindFirst (const char * fileName, unsigned int attr, SearchRec * rec);
1929+
1930+#ifdef SUPPORT_LFN
1931+/***********************************************************************************
1932+ Function:
1933+ int wFindFirst (const unsigned short int * fileName, unsigned int attr, SearchRec * rec)
1934+ Summary:
1935+ Initial search function for the input UTF16 fileName
1936+ Conditions:
1937+ None
1938+ Input:
1939+ fileName - The name to search for
1940+ - Parital string search characters
1941+ - * - Indicates the rest of the filename or extension can vary (e.g. FILE.*)
1942+ - ? - Indicates that one character in a filename can vary (e.g. F?LE.T?T)
1943+ attr - The attributes that a found file may have
1944+ - ATTR_READ_ONLY - File may be read only
1945+ - ATTR_HIDDEN - File may be a hidden file
1946+ - ATTR_SYSTEM - File may be a system file
1947+ - ATTR_VOLUME - Entry may be a volume label
1948+ - ATTR_DIRECTORY - File may be a directory
1949+ - ATTR_ARCHIVE - File may have archive attribute
1950+ - ATTR_MASK - All attributes
1951+ rec - pointer to a structure to put the file information in
1952+ Return Values:
1953+ 0 - File was found
1954+ -1 - No file matching the specified criteria was found
1955+ Side Effects:
1956+ Search criteria from previous wFindFirst call on passed SearchRec object
1957+ will be lost. "utf16LFNfound" is overwritten after subsequent wFindFirst/FindNext
1958+ operations.It is the responsibility of the application to read the "utf16LFNfound"
1959+ before it is lost.The FSerrno variable will be changed.
1960+ Description:
1961+ The wFindFirst function will search for a file based on parameters passed in
1962+ by the user. This function will use the FILEfind function to parse through
1963+ the current working directory searching for entries that match the specified
1964+ parameters. If a file is found, its parameters are copied into the SearchRec
1965+ structure, as are the initial parameters passed in by the user and the position
1966+ of the file entry in the current working directory.If the return value of the
1967+ function is 0 then "utf16LFNfoundLength" indicates whether the file found was
1968+ long file name or short file name(8P3 format). The "utf16LFNfoundLength" is non-zero
1969+ for long file name and is zero for 8P3 format."utf16LFNfound" points to the
1970+ address of long file name if found during the operation.
1971+ Remarks:
1972+ Call FindFirst or FindFirstpgm before calling FindNext
1973+ ***********************************************************************************/
1974+
1975+int wFindFirst (const unsigned short int * fileName, unsigned int attr, SearchRec * rec);
1976+#endif
1977+
1978+/**********************************************************************
1979+ Function:
1980+ int FindNext (SearchRec * rec)
1981+ Summary:
1982+ Sequential search function
1983+ Conditions:
1984+ None
1985+ Input:
1986+ rec - The structure to store the file information in
1987+ Return Values:
1988+ 0 - File was found
1989+ -1 - No additional files matching the specified criteria were found
1990+ Side Effects:
1991+ Search criteria from previous FindNext call on passed SearchRec object
1992+ will be lost. "utf16LFNfound" is overwritten after subsequent FindFirst/FindNext
1993+ operations.It is the responsibility of the application to read the "utf16LFNfound"
1994+ before it is lost.The FSerrno variable will be changed.
1995+ Description:
1996+ The FindNext function performs the same function as the FindFirst
1997+ funciton, except it does not copy any search parameters into the
1998+ SearchRec structure (only info about found files) and it begins
1999+ searching at the last directory entry offset at which a file was
2000+ found, rather than at the beginning of the current working
2001+ directory.If the return value of the function is 0 then "utf16LFNfoundLength"
2002+ indicates whether the file found was long file name or short file
2003+ name(8P3 format). The "utf16LFNfoundLength" is non-zero for long file name
2004+ and is zero for 8P3 format."utf16LFNfound" points to the address of long
2005+ file name if found during the operation.
2006+ Remarks:
2007+ Call FindFirst or FindFirstpgm before calling this function
2008+ **********************************************************************/
2009+
2010+int FindNext (SearchRec * rec);
2011+#endif
2012+
2013+
2014+/**********************************************************************
2015+ Function:
2016+ // PIC24/30/33/32
2017+ int FSfprintf (FSFILE * fptr, const char * fmt, ...)
2018+ // PIC18
2019+ int FSfpritnf (FSFILE * fptr, const rom char * fmt, ...)
2020+ Summary:
2021+ Function to write formatted strings to a file
2022+ Conditions:
2023+ For PIC18, integer promotion must be enabled in the project build
2024+ options menu. File opened in a write mode.
2025+ Input:
2026+ fptr - A pointer to the file to write to.
2027+ fmt - A string of characters and format specifiers to write to
2028+ the file
2029+ ... - Additional arguments inserted in the string by format
2030+ specifiers
2031+ Returns:
2032+ The number of characters written to the file
2033+ Side Effects:
2034+ The FSerrno variable will be changed.
2035+ Description:
2036+ Writes a specially formatted string to a file.
2037+ Remarks:
2038+ Consult AN1045 for a full description of how to use format
2039+ specifiers.
2040+ **********************************************************************/
2041+
2042+#ifdef ALLOW_FSFPRINTF
2043+ #ifdef __18CXX
2044+ int FSfprintf (FSFILE *fptr, const rom char *fmt, ...);
2045+ #else
2046+ int FSfprintf (FSFILE *fptr, const char * fmt, ...);
2047+ #endif
2048+#endif
2049+
2050+
2051+/**************************************************************************
2052+ Function:
2053+ int FSerror (void)
2054+ Summary:
2055+ Return an error code for the last function call
2056+ Conditions:
2057+ The return value depends on the last function called.
2058+ Input:
2059+ None
2060+ Side Effects:
2061+ None.
2062+ Return Values:
2063+ FSInit -
2064+ - CE_GOOD ・ No Error
2065+ - CE_INIT_ERROR ・ The physical media could not be initialized
2066+ - CE_BAD_SECTOR_READ ・ The MBR or the boot sector could not be
2067+ read correctly
2068+ - CE_BAD_PARITION ・ The MBR signature code was incorrect.
2069+ - CE_NOT_FORMATTED ・ The boot sector signature code was incorrect or
2070+ indicates an invalid number of bytes per sector.
2071+ - CE_CARDFAT32 ・ The physical media is FAT32 type (only an error
2072+ when FAT32 support is disabled).
2073+ - CE_UNSUPPORTED_FS ・ The device is formatted with an unsupported file
2074+ system (not FAT12 or 16).
2075+ FSfopen -
2076+ - CE_GOOD ・ No Error
2077+ - CE_NOT_INIT ・ The device has not been initialized.
2078+ - CE_TOO_MANY_FILES_OPEN ・ The function could not allocate any
2079+ additional file information to the array
2080+ of FSFILE structures or the heap.
2081+ - CE_INVALID_FILENAME ・ The file name argument was invalid.
2082+ - CE_INVALID_ARGUMENT ・ The user attempted to open a directory in a
2083+ write mode or specified an invalid mode argument.
2084+ - CE_FILE_NOT_FOUND ・ The specified file (which was to be opened in read
2085+ mode) does not exist on the device.
2086+ - CE_BADCACHEREAD ・ A read from the device failed.
2087+ - CE_ERASE_FAIL ・ The existing file could not be erased (when opening
2088+ a file in WRITE mode).
2089+ - CE_DIR_FULL ・ The directory is full.
2090+ - CE_DISK_FULL・ The data memory section is full.
2091+ - CE_WRITE_ERROR ・ A write to the device failed.
2092+ - CE_SEEK_ERROR ・ The current position in the file could not be set to
2093+ the end (when the file was opened in APPEND mode).
2094+ FSfclose -
2095+ - CE_GOOD ・ No Error
2096+ - CE_WRITE_ERROR ・ The existing data in the data buffer or the new file
2097+ entry information could not be written to the device.
2098+ - CE_BADCACHEREAD ・ The file entry information could not be cached
2099+ FSfread -
2100+ - CE_GOOD ・ No Error
2101+ - CE_WRITEONLY ・ The file was opened in a write-only mode.
2102+ - CE_WRITE_ERROR ・ The existing data in the data buffer could not be
2103+ written to the device.
2104+ - CE_BAD_SECTOR_READ ・ The data sector could not be read.
2105+ - CE_EOF ・ The end of the file was reached.
2106+ - CE_COULD_NOT_GET_CLUSTER ・Additional clusters in the file could not be loaded.
2107+ FSfwrite -
2108+ - CE_GOOD ・ No Error
2109+ - CE_READONLY ・ The file was opened in a read-only mode.
2110+ - CE_WRITE_PROTECTED ・ The device write-protect check function indicated
2111+ that the device has been write-protected.
2112+ - CE_WRITE_ERROR ・ There was an error writing data to the device.
2113+ - CE_BADCACHEREAD ・ The data sector to be modified could not be read from
2114+ the device.
2115+ - CE_DISK_FULL ・ All data clusters on the device are in use.
2116+ FSfseek -
2117+ - CE_GOOD ・ No Error
2118+ - CE_WRITE_ERROR ・ The existing data in the data buffer could not be
2119+ written to the device.
2120+ - CE_INVALID_ARGUMENT ・ The specified offset exceeds the size of the file.
2121+ - CE_BADCACHEREAD ・ The sector that contains the new current position
2122+ could not be loaded.
2123+ - CE_COULD_NOT_GET_CLUSTER ・Additional clusters in the file could not be
2124+ loaded/allocated.
2125+ FSftell -
2126+ - CE_GOOD ・ No Error
2127+ FSattrib -
2128+ - CE_GOOD ・ No Error
2129+ - CE_INVALID_ARGUMENT ・ The attribute argument was invalid.
2130+ - CE_BADCACHEREAD ・ The existing file entry information could not be
2131+ loaded.
2132+ - CE_WRITE_ERROR ・ The file entry information could not be written to
2133+ the device.
2134+ FSrename -
2135+ - CE_GOOD ・ No Error
2136+ - CE_FILENOTOPENED ・ A null file pointer was passed into the function.
2137+ - CE_INVALID_FILENAME ・ The file name passed into the function was invalid.
2138+ - CE_BADCACHEREAD ・ A read from the device failed.
2139+ - CE_FILENAME_EXISTS ・ A file with the specified name already exists.
2140+ - CE_WRITE_ERROR ・ The new file entry data could not be written to the
2141+ device.
2142+ FSfeof -
2143+ - CE_GOOD ・ No Error
2144+ FSformat -
2145+ - CE_GOOD ・ No Error
2146+ - CE_INIT_ERROR ・ The device could not be initialized.
2147+ - CE_BADCACHEREAD ・ The master boot record or boot sector could not be
2148+ loaded successfully.
2149+ - CE_INVALID_ARGUMENT ・ The user selected to create their own boot sector on
2150+ a device that has no master boot record, or the mode
2151+ argument was invalid.
2152+ - CE_WRITE_ERROR ・ The updated MBR/Boot sector could not be written to
2153+ the device.
2154+ - CE_BAD_PARTITION ・ The calculated number of sectors per clusters was
2155+ invalid.
2156+ - CE_NONSUPPORTED_SIZE ・ The card has too many sectors to be formatted as
2157+ FAT12 or FAT16.
2158+ FSremove -
2159+ - CE_GOOD ・ No Error
2160+ - CE_WRITE_PROTECTED ・ The device write-protect check function indicated
2161+ that the device has been write-protected.
2162+ - CE_INVALID_FILENAME ・ The specified filename was invalid.
2163+ - CE_FILE_NOT_FOUND ・ The specified file could not be found.
2164+ - CE_ERASE_FAIL ・ The file could not be erased.
2165+ FSchdir -
2166+ - CE_GOOD ・ No Error
2167+ - CE_INVALID_ARGUMENT ・ The path string was mis-formed or the user tried to
2168+ change to a non-directory file.
2169+ - CE_BADCACHEREAD ・ A directory entry could not be cached.
2170+ - CE_DIR_NOT_FOUND ・ Could not find a directory in the path.
2171+ FSgetcwd -
2172+ - CE_GOOD ・ No Error
2173+ - CE_INVALID_ARGUMENT ・ The user passed a 0-length buffer into the function.
2174+ - CE_BADCACHEREAD ・ A directory entry could not be cached.
2175+ - CE_BAD_SECTOR_READ ・ The function could not determine a previous directory
2176+ of the current working directory.
2177+ FSmkdir -
2178+ - CE_GOOD ・ No Error
2179+ - CE_WRITE_PROTECTED ・ The device write-protect check function indicated
2180+ that the device has been write-protected.
2181+ - CE_INVALID_ARGUMENT ・ The path string was mis-formed.
2182+ - CE_BADCACHEREAD ・ Could not successfully change to a recently created
2183+ directory to store its dir entry information, or
2184+ could not cache directory entry information.
2185+ - CE_INVALID_FILENAME ・ One or more of the directory names has an invalid
2186+ format.
2187+ - CE_WRITE_ERROR ・ The existing data in the data buffer could not be
2188+ written to the device or the dot/dotdot entries could
2189+ not be written to a newly created directory.
2190+ - CE_DIR_FULL ・ There are no available dir entries in the CWD.
2191+ - CE_DISK_FULL ・ There are no available clusters in the data region of
2192+ the device.
2193+ FSrmdir -
2194+ - CE_GOOD ・ No Error
2195+ - CE_DIR_NOT_FOUND ・ The directory specified could not be found or the
2196+ function could not change to a subdirectory within
2197+ the directory to be deleted (when recursive delete is
2198+ enabled).
2199+ - CE_INVALID_ARGUMENT ・ The user tried to remove the CWD or root directory.
2200+ - CE_BADCACHEREAD ・ A directory entry could not be cached.
2201+ - CE_DIR_NOT_EMPTY ・ The directory to be deleted was not empty and
2202+ recursive subdirectory removal was disabled.
2203+ - CE_ERASE_FAIL ・ The directory or one of the directories or files
2204+ within it could not be deleted.
2205+ - CE_BAD_SECTOR_READ ・ The function could not determine a previous directory
2206+ of the CWD.
2207+ SetClockVars -
2208+ - CE_GOOD ・ No Error
2209+ - CE_INVALID_ARGUMENT ・ The time values passed into the function were
2210+ invalid.
2211+ FindFirst -
2212+ - CE_GOOD ・ No Error
2213+ - CE_INVALID_FILENAME ・ The specified filename was invalid.
2214+ - CE_FILE_NOT_FOUND ・ No file matching the specified criteria was found.
2215+ - CE_BADCACHEREAD ・ The file information for the file that was found
2216+ could not be cached.
2217+ FindNext -
2218+ - CE_GOOD ・ No Error
2219+ - CE_NOT_INIT ・ The SearchRec object was not initialized by a call to
2220+ FindFirst.
2221+ - CE_INVALID_ARGUMENT ・ The SearchRec object was initialized in a different
2222+ directory from the CWD.
2223+ - CE_INVALID_FILENAME ・ The filename is invalid.
2224+ - CE_FILE_NOT_FOUND ・ No file matching the specified criteria was found.
2225+ FSfprintf -
2226+ - CE_GOOD ・ No Error
2227+ - CE_WRITE_ERROR ・ Characters could not be written to the file.
2228+ Description:
2229+ The FSerror function will return the FSerrno variable. This global
2230+ variable will have been set to an error value during the last call of a
2231+ library function.
2232+ Remarks:
2233+ None
2234+ **************************************************************************/
2235+
2236+int FSerror (void);
2237+
2238+
2239+/*********************************************************************************
2240+ Function:
2241+ int FSCreateMBR (unsigned long firstSector, unsigned long numSectors)
2242+ Summary:
2243+ Creates a master boot record
2244+ Conditions:
2245+ The I/O pins for the device have been initialized by the InitIO function.
2246+ Input:
2247+ firstSector - The first sector of the partition on the device (cannot
2248+ be 0; that's the MBR)
2249+ numSectors - The number of sectors available in memory (including the
2250+ MBR)
2251+ Return Values:
2252+ 0 - MBR was created successfully
2253+ EOF - MBR could not be created
2254+ Side Effects:
2255+ None
2256+ Description:
2257+ This function can be used to create a master boot record for a device. Note
2258+ that this function should not be used on a device that is already formatted
2259+ with a master boot record (i.e. most SD cards, CF cards, USB keys). This
2260+ function will fill the global data buffer with appropriate partition information
2261+ for a FAT partition with a type determined by the number of sectors available
2262+ to the partition. It will then write the MBR information to the first sector
2263+ on the device. This function should be followed by a call to FSformat, which
2264+ will create a boot sector, root dir, and FAT appropriate the the information
2265+ contained in the new master boot record. Note that FSformat only supports
2266+ FAT12 and FAT16 formatting at this time, and so cannot be used to format a
2267+ device with more than 0x3FFD5F sectors.
2268+ Remarks:
2269+ This function can damage the device being used, and should not be called
2270+ unless the user is sure about the size of the device and the first sector value.
2271+ *********************************************************************************/
2272+
2273+int FSCreateMBR (unsigned long firstSector, unsigned long numSectors);
2274+
2275+
2276+#ifdef ALLOW_GET_DISK_PROPERTIES
2277+/*********************************************************************************
2278+ Function:
2279+ void FSGetDiskProperties(FS_DISK_PROPERTIES* properties)
2280+ Summary:
2281+ Allows user to get the disk properties (size of disk, free space, etc)
2282+ Conditions:
2283+ 1) ALLOW_GET_DISK_PROPERTIES must be defined in FSconfig.h
2284+ 2) a FS_DISK_PROPERTIES object must be created before the function is called
2285+ 3) the new_request member of the FS_DISK_PROPERTIES object must be set before
2286+ calling the function for the first time. This will start a new search.
2287+ 4) this function should not be called while there is a file open. Close all
2288+ files before calling this function.
2289+ Input:
2290+ properties - a pointer to a FS_DISK_PROPERTIES object where the results should
2291+ be stored.
2292+ Return Values:
2293+ This function returns void. The properties_status of the previous call of
2294+ this function is located in the properties.status field. This field has
2295+ the following possible values:
2296+
2297+ FS_GET_PROPERTIES_NO_ERRORS - operation completed without error. Results
2298+ are in the properties object passed into the function.
2299+ FS_GET_PROPERTIES_DISK_NOT_MOUNTED - there is no mounted disk. Results in
2300+ properties object is not valid
2301+ FS_GET_PROPERTIES_CLUSTER_FAILURE - there was a failure trying to read a
2302+ cluster from the drive. The results in the properties object is a partial
2303+ result up until the point of the failure.
2304+ FS_GET_PROPERTIES_STILL_WORKING - the search for free sectors is still in
2305+ process. Continue calling this function with the same properties pointer
2306+ until either the function completes or until the partial results meets the
2307+ application needs. The properties object contains the partial results of
2308+ the search and can be used by the application.
2309+ Side Effects:
2310+ Can cause errors if called when files are open. Close all files before
2311+ calling this function.
2312+
2313+ Calling this function without setting the new_request member on the first
2314+ call can result in undefined behavior and results.
2315+
2316+ Calling this function after a result is returned other than
2317+ FS_GET_PROPERTIES_STILL_WORKING can result in undefined behavior and results.
2318+ Description:
2319+ This function returns the information about the mounted drive. The results
2320+ member of the properties object passed into the function is populated with
2321+ the information about the drive.
2322+
2323+ Before starting a new request, the new_request member of the properties
2324+ input parameter should be set to TRUE. This will initiate a new search
2325+ request.
2326+
2327+ This function will return before the search is complete with partial results.
2328+ All of the results except the free_clusters will be correct after the first
2329+ call. The free_clusters will contain the number of free clusters found up
2330+ until that point, thus the free_clusters result will continue to grow until
2331+ the entire drive is searched. If an application only needs to know that a
2332+ certain number of bytes is available and doesn't need to know the total free
2333+ size, then this function can be called until the required free size is
2334+ verified. To continue a search, pass a pointer to the same FS_DISK_PROPERTIES
2335+ object that was passed in to create the search.
2336+
2337+ A new search request sould be made once this function has returned a value
2338+ other than FS_GET_PROPERTIES_STILL_WORKING. Continuing a completed search
2339+ can result in undefined behavior or results.
2340+
2341+ Typical Usage:
2342+ <code>
2343+ FS_DISK_PROPERTIES disk_properties;
2344+
2345+ disk_properties.new_request = TRUE;
2346+
2347+ do
2348+ {
2349+ FSGetDiskProperties(&disk_properties);
2350+ } while (disk_properties.properties_status == FS_GET_PROPERTIES_STILL_WORKING);
2351+ </code>
2352+
2353+ results.disk_format - contains the format of the drive. Valid results are
2354+ FAT12(1), FAT16(2), or FAT32(3).
2355+
2356+ results.sector_size - the sector size of the mounted drive. Valid values are
2357+ 512, 1024, 2048, and 4096.
2358+
2359+ results.sectors_per_cluster - the number sectors per cluster.
2360+
2361+ results.total_clusters - the number of total clusters on the drive. This
2362+ can be used to calculate the total disk size (total_clusters *
2363+ sectors_per_cluster * sector_size = total size of drive in bytes)
2364+
2365+ results.free_clusters - the number of free (unallocated) clusters on the drive.
2366+ This can be used to calculate the total free disk size (free_clusters *
2367+ sectors_per_cluster * sector_size = total size of drive in bytes)
2368+
2369+ Remarks:
2370+ PIC24F size estimates:
2371+ Flash - 400 bytes (-Os setting)
2372+
2373+ PIC24F speed estimates:
2374+ Search takes approximately 7 seconds per Gigabyte of drive space. Speed
2375+ will vary based on the number of sectors per cluster and the sector size.
2376+ *********************************************************************************/
2377+void FSGetDiskProperties(FS_DISK_PROPERTIES* properties);
2378+#endif
2379+
2380+
2381+#endif
--- a/mips/megalopa/clib.c
+++ b/mips/megalopa/clib.c
@@ -29,12 +29,94 @@
2929 record[3]: pointer to function
3030 */
3131
32+/*
33+ * g_data_clib[] contains the data from MachiKania compiler for this library
34+ */
35+void* g_data_clib_var[]={
36+ 0, // will be g_gp, g_data[0][0],"0"
37+};
38+
39+const void* const g_data_clib_core[]={
40+ lib_calloc_memory,// g_data[1][0],"0"
41+ lib_delete, // g_data[1][1],"4"
42+};
43+
44+const void* const g_data_clib_file[]={
45+#ifdef __DEBUG
46+ 0 // Disabled in debug mode
47+#else
48+ FSInit, // g_data[2][0],"0"
49+ FSfopen, // g_data[2][1],"4"
50+ FSfclose, // g_data[2][2],"8"
51+ FSfread, // g_data[2][3],"12"
52+ FSfwrite, // g_data[2][4],"16"
53+ FSfeof, // g_data[2][5],"20"
54+ FSftell, // g_data[2][6],"24"
55+ FSfseek, // g_data[2][7],"28"
56+ FSrewind, // g_data[2][8],"32"
57+ FindFirst,// g_data[2][9],"36"
58+ FindNext, // g_data[2][10],"40"
59+ FSmkdir, // g_data[2][11],"44"
60+ FSgetcwd, // g_data[2][12],"48"
61+ FSchdir, // g_data[2][13],"52"
62+ FSremove, // g_data[2][14],"56"
63+ FSrename, // g_data[2][15],"60"
64+#endif
65+};
66+
67+const void* const g_data_clib_video[]={
68+ start_composite,// g_data[3][0],"0"
69+ stop_composite, // g_data[3][1],"4"
70+ printchar, // g_data[3][2],"8"
71+ printstr, // g_data[3][3],"12"
72+ printnum, // g_data[3][4],"16"
73+ printnum2, // g_data[3][5],"20"
74+ cls, // g_data[3][6],"24"
75+ vramscroll, // g_data[3][7],"28"
76+ setcursorcolor, // g_data[3][8],"32"
77+ setcursor, // g_data[3][9],"36"
78+ set_palette, // g_data[3][10],"40"
79+ set_bgcolor, // g_data[3][11],"44"
80+};
81+
82+const void* const g_data_clib_graphic[]={
83+ g_pset, // g_data[4][0],"0"
84+ g_putbmpmn, // g_data[4][1],"4"
85+ g_clrbmpmn, // g_data[4][2],"8"
86+ g_gline, // g_data[4][3],"12"
87+ g_hline, // g_data[4][4],"16"
88+ g_circle, // g_data[4][5],"20"
89+ g_circlefill, // g_data[4][6],"24"
90+ g_boxfill, // g_data[4][7],"28"
91+ g_putfont, // g_data[4][8],"32"
92+ g_printstr, // g_data[4][9],"36"
93+ g_printnum, // g_data[4][10],"40"
94+ g_printnum2, // g_data[4][11],"44"
95+ g_color, // g_data[4][12],"48"
96+};
97+
98+const void* const g_data_clib_keyboard[]={
99+ shiftkeys, // g_data[5][0],"0"
100+ ps2readkey,// g_data[5][1],"4"
101+};
102+
103+const void* const g_data_clib[]={
104+ &g_data_clib_var[0], // g_data[0],"0"
105+ &g_data_clib_core[0], // g_data[1],"4"
106+ &g_data_clib_file[0], // g_data[2],"8"
107+ &g_data_clib_video[0], // g_data[3],"12"
108+ &g_data_clib_graphic[0], // g_data[4],"16"
109+ &g_data_clib_keyboard[0],// g_data[5],"20"
110+};
111+
32112 // CLIB name used (name as 31 bit integer)
33113 static unsigned int g_clib;
34114
35115 char* useclib_statement(){
36116 int i;
37- int* cmpdata;
117+ int* cmpdata;
118+ // Initialize g_data_clib_var[]
119+ g_data_clib_var[0]=g_gp;
38120 do {
39121 next_position();
40122 i=check_var_name();
@@ -62,19 +144,6 @@ char* useclib_statement(){
62144 return 0;
63145 }
64146
65-/*
66- * g_data[] contains the data from MachiKania compiler for this library
67- * g_data[0] : lib_calloc_memory
68- * g_data[1] : lib_delete
69- * g_data[2] : g_gp
70- * g_data[3-]: Reserved for higher version of CLIB
71- */
72-void* g_data_for_clib[]={
73- lib_calloc_memory,
74- lib_delete,
75- 0, // = g_gp
76-};
77-
78147 void* call_clib_init(void** data, void* address){
79148 // Store gp and ra
80149 asm volatile("#":::"s0");
@@ -166,10 +235,8 @@ char* clib_main(){
166235 got[i]+=adjust;
167236 }
168237 }
169- // Prepare g_data_for_clib[]
170- g_data_for_clib[2]=(void*)g_gp;
171238 // Call the clib_init() to get the address of clibdata array.
172- clibdata=call_clib_init(&g_data_for_clib[0],(void*)0xA0008000+adjust);
239+ clibdata=call_clib_init((void**)&g_data_clib[0],(void*)(0xA0008000+adjust));
173240 // Check version
174241 if (((int*)clibdata)[0]>SYSVERI) {
175242 return "Newer version of C library than MachiKania cannot be used.";
--- a/mips/megalopa/debug.c
+++ b/mips/megalopa/debug.c
@@ -234,7 +234,6 @@ static const char initext[]=
234234
235235 static const char bastext[]=
236236 "useclib TCLIB\n"
237-"CLS\n"
238237 "print TCLIB::TEST$(0);\n"
239238 "print clib$(TCLIB::TEST,1)\n"
240239 "\n"
@@ -267,23 +266,43 @@ static const char hextext[]=
267266 ":10803000000000001000bc8f2080828f1c00bf8fca\n"
268267 ":088040000800e0032000bd2749\n"
269268 ":020000040000fa\n"
270-":107f80000000000000000080a07f00a0508000a042\n"
271-":107f9000dc8000a0000001a0588000a000000000cc\n"
269+":107f80000000000000000080ac7f00a0508000a036\n"
270+":107f9000cc8100a0b48100a0388100a0000001a025\n"
271+":0c7fa000f08000a0588000a0000000004d\n"
272272 ":020000040000fa\n"
273273 ":108050000800e0030000000000001c3c187f9c2783\n"
274-":1080600021e09903040080542480828f2480828f31\n"
275-":108070000800e003b48042240800e003c4804224e6\n"
276-":1080800000001c3cf07e9c2721e09903e0ffbd2707\n"
277-":108090001c00bfaf1000bcaf2880998f09f82003e7\n"
278-":1080a000000000001000bc8f1c00bf8f0800e00320\n"
279-":0480b0002000bd27c8\n"
274+":1080600021e09903e0ffbd271c00bfaf1000bcafab\n"
275+":108070000e0080542c80828f2880998f09f820036d\n"
276+":10808000000000001000bc8f2c80848fa08184240d\n"
277+":108090003080998f09f82003000000001000bc8f89\n"
278+":1080a0002c80828f02000010808142249081422423\n"
279+":1080b0001c00bf8f0800e0032000bd2700001c3c0f\n"
280+":1080c000b47e9c2721e09903e0ffbd271c00bfafd1\n"
281+":1080d0001000bcaf3480998f09f820030000000025\n"
282+":1080e0001000bc8f1c00bf8f0800e0032000bd27dc\n"
280283 ":020000040000fa\n"
281-":1080b40048656c6c6f20576f726c6421000000007f\n"
282-":1080c40054686973206973206120746573740000b7\n"
283-":0880d400544553540000000064\n"
284+":1080f00000001c3c807e9c2721e09903e0ffbd2707\n"
285+":108100001c00bfaf1000bcaf2480998f09f820037a\n"
286+":10811000000000001000bc8f0000438c0c00428c5b\n"
287+":108120000c00428c09f8400000007c8c1c00bf8fc2\n"
288+":088130000800e0032000bd2758\n"
284289 ":020000040000fa\n"
285-":1080dc004001000080000000ec8000a000000000c7\n"
286-":0c80ec00d48000a0808000a000000000f4\n"
290+":1081380000001c3c387e9c2721e09903e0ffbd2706\n"
291+":108148001c00bfaf1000bcaf2480998f09f8200332\n"
292+":10815800000000001000bc8f0000438c0c00428c13\n"
293+":108168001800428c09f8400000007c8c1c00bf8f6e\n"
294+":088178000800e0032000bd2710\n"
295+":020000040000fa\n"
296+":1081800048656c6c6f20576f726c642100000000b2\n"
297+":1081900054686973206973206120746573740000ea\n"
298+":1081a000434c494220746573742e00005445535467\n"
299+":0481b00000000000cb\n"
300+":020000040000fa\n"
301+":1081b40000001c3cbc7d9c2721e099031880828f21\n"
302+":0881c4000800e0030000428cfa\n"
303+":020000040000fa\n"
304+":1081cc004001000080000000dc8100a000000000e5\n"
305+":0c81dc00ac8100a0bc8000a000000000ee\n"
287306 ":00000001FF\n"
288307 ;
289308