;* *
;* *
;* *
-;*(C) 2003 Ullrich von Bassewitz *
-;* Römerstrasse 52 *
-;* D-70794 Filderstadt *
-;*EMail: uz@cc65.org *
+;*(C) 2003-2006, Ullrich von Bassewitz *
+;* Römerstrasse 52 *
+;* D-70794 Filderstadt *
+;*EMail: uz@cc65.org *
;* *
;* *
;*This software is provided 'as-is', without any expressed or implied *
.global ser_irq
;------------------------------------------------------------------------------
-; ASM functions
+; C callable functions
.global _ser_unload
.global _ser_install
.global _ser_status
.global _ser_ioctl
+ .global _ser_clear_ptr
/* */
/* */
/* */
-/* (C) 2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2003-2006, Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Pointer to serial driver, exported from ser-kernel.s */
extern void* ser_drv;
+/* Function that clears the driver pointer (ser-kernel.s) */
+void ser_clear_ptr (void);
+
/*****************************************************************************/
+/* Use static local variables, since the module is not reentrant anyway */
+#pragma staticlocals (on);
+
+
+
unsigned char __fastcall__ ser_load_driver (const char* name)
/* Load a serial driver and return an error code */
{
/* Load the module */
Res = mod_load (&ctrl);
-
+
/* Close the input file */
close (ctrl.callerdata);
if (Res == MLOAD_OK) {
/* Check the driver signature, install the driver */
- return ser_install (ctrl.module);
-
+ Res = ser_install (ctrl.module);
+
+ /* If the driver did not install correctly, remove it from
+ * memory again.
+ */
+ if (Res != SER_ERR_OK) {
+ /* Do not call ser_uninstall here, since the driver is not
+ * correctly installed.
+ */
+ mod_free (ser_drv);
+ ser_clear_ptr ();
+ }
+
+ /* Return the error code */
+ return Res;
}
}