/**************************************************************************** * @(#) Ndless - OS Calls * * Copyright (C) 2010 by ANNEHEIM Geoffrey and ARMAND Olivier * Contact: geoffrey.anneheim@gmail.com / olivier.calc@gmail.com * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. * * RCSID $Id$ ****************************************************************************/ #ifndef _OS_H_ #define _OS_H_ #include "common.h" #ifdef CAS #include "os_cas_1.2.2344.h" #elif NON_CAS #include "os_1.2.2398.h" #else #error You must specify a Nspire hardware (CAS or NON-CAS) #endif /** GNU AS */ #ifdef GNU_AS .macro oscall address mov lr,pc ldr pc,=\address .endm #define _oscall(rettype,funcaddr,...) funcaddr /** GNU C Compiler */ #else #define _oscall(rettype,funcaddr,...) (*((rettype(*)(__VA_ARGS__))(funcaddr))) #define NULL ((void*)0) typedef enum bool {FALSE = 0, TRUE = 1} BOOL; typedef struct{} FILE; typedef unsigned long size_t; #endif #define fopen (_oscall(FILE*, fopen_, const char *filename, const char *mode)) #define fread (_oscall(size_t, fread_, void *ptr, size_t size, size_t nitems, FILE *stream)) #define fwrite (_oscall(size_t, fwrite_, const void *ptr, size_t size, size_t count, FILE *stream)) #define fclose (_oscall(int, fclose_, FILE *stream)) #define fseek (_oscall(int, fseek_, FILE *stream, long int offset, int origin )) #define ftell (_oscall(long int, ftell_, FILE *stream)) #define fflush (_oscall(int, fflush_, FILE *stream)) #define ferror (_oscall(int, ferror_, FILE *stream)) #define fgets (_oscall(char *,fgets_, const char *ptr, size_t count, FILE *stream)) #define malloc (_oscall(void*, malloc_, size_t size)) #define free (_oscall(void, free_, void *ptr)) #define memset (_oscall(void*, memset_, void *ptr, int value, size_t num)) #define memchr (_oscall(void*, memchr_, void *ptr, int value, size_t num)) #define memcpy (_oscall(void*, memcpy_, void *restrict s1, const void *restrict s2, size_t n)) #define memcmp (_oscall(int, memcmp_, const void *ptr1, const void *ptr2, size_t num)) #define printf (_oscall(int __attribute__((__format__(__printf__,1,2))), printf_, const char *format, ...)) #define sprintf (_oscall(int __attribute__((__format__(__printf__,2,3))), sprintf_, const char *s, const char *format, ...)) #define fprintf (_oscall(int __attribute__((__format__(__printf__,2,3))), fprintf_, FILE *stream, const char *format, ...)) #define ascii2utf16 (_oscall(void, ascii2utf16_, void *buff, const char *str, int max_size)) #define show_dialog_box2 (_oscall(void, show_dialog_box2_, int undef, const char *title, const char *msg)) #define mkdir (_oscall(int, mkdir_, const char *path, int mode)) #define rmdir (_oscall(int, rmdir_, const char *path)) #define chdir (_oscall(void, chdir_, const char*)) #define set_current_path (_oscall(void, set_current_path_, const char*)) #define stat (_oscall(int, stat_, const char *restric path, struct stat *restrict buf)) #define unlink (_oscall(int, unlink_, const char *)) #define rename (_oscall(int, rename_, const char *old, const char *new)) //#define _log_rs232 (_oscall(void, log_rs232_, const char* msg, void *param2)) //#define log_rs232(msg) (_log_rs232(msg "\n", (void*)log_rs232_param2_)) //#define log_rs232_v(msg) (_log_rs232(msg, (void*)log_rs232_param2_)) //#define printf_rs232 (_oscall(void, printf_rs232_, const char*, ...)) #define power_off (_oscall(void, power_off_, void)) #define TCT_Local_Control_Interrupts (_oscall(int, TCT_Local_Control_Interrupts_, int newlevel)) #define NU_Get_First (_oscall(int, NU_Get_First_, unsigned char* StructDstat, const char* pattern)) #define NU_Get_Next (_oscall(int, NU_Get_Next_, unsigned char* StructDstat)) #define NU_Done (_oscall(void, NU_Done_, unsigned char* StructDstat)) #define NU_Set_Current_Dir (_oscall(int, NU_Set_Current_Dir_, const char* newdir)) #define NU_Current_Dir (_oscall(int, NU_Current_Dir_, const char* drive, const char* dirbuffer)) #define read_unaligned_longword (_oscall(unsigned long, read_unaligned_longword_, void *ptr )) // 4 byte longword #define read_unaligned_word (_oscall(int, read_unaligned_word_, void *ptr )) // 2 byte word #define strcpy (_oscall(char*, strcpy_, const char *dest, const char *src )) #define strcat (_oscall(char*, strcat_, const char *dest, const char *src )) #define strchr (_oscall(char*, strchr_, const char *str, int character )) #define strpbrk (_oscall(char*, strpbrk_, const char *str1, const char *str2 )) #define atoi (_oscall(int, atoi_, const char *str)) #define strtoul (_oscall(unsigned long, strtoul_, const char *str,char ** endptr, int base , int *chbase)) // normally set chbase = NULL #define flash_erase_range (_oscall(unsigned, flash_erase_range_, unsigned, unsigned )) #endif