;;; syscall.list        -*- scheme -*-

;;; grifo - a small kernel for WikiReader
;;;
;;; Copyright (c) 2009 Openmoko Inc.
;;;
;;; Authors   Christopher Hall <hsw@openmoko.com>;;;
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; 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.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; File format:
;;;
;;; A. Command
;;;    1 = command name
;;;    rest = command arguments
;;;
;;; B. System Call
;;;    1 = system call number 0..n in increments of 1
;;;    2 = Grifo internal function name
;;;    3 = list (type function arguments)
;;;    4 = optional attributes

(
 ;; GPLV3+
 (copy-all "src/license.i")

 (ifnot _GRIFO_H_)

 (include<> inttypes.h)
 (include<> stdbool.h)
 (include<> stdlib.h)

 (newline)

 (output "#define SizeOfArray(a) (sizeof(a) / sizeof((a)[0]))")

 (newline)

 (output "typedef int32_t ssize_t;")

 ;; functions
 (0 System_panic ("void" "panic" "const char *format" "...") ("noreturn" "format (printf, 1, 2)"))

 (section "Console Debugging")
 (1 Serial_print   ("void" "debug_print" "const char *message"))
 (2 Serial_PutChar ("int" "debug_print_char" "int c"))
 (3 Serial_printf  ("int" "debug_printf" "const char *format" "...") "format (printf, 1, 2)")
 (4 Serial_HexDump ("void" "debug_hex_dump" "const void *buffer" "size_t length"))


 (section "Power Off / Reboot")

 (remark "These values can be used as the retunr from main()")
 (output "enum {")
 (copy-part "src/system.h" "exit")
 (output "};")

 (16 System_exit ("void" "exit" "int result") "noreturn")
 (17 System_chain ("void" "chain" "const char *command") "noreturn")
 (18 System_PowerOff ("void" "power_off" "void") "noreturn")
 (19 System_reboot ("void" "reboot" "void") "noreturn")


 (section "Interrupt Handlers")

 (output "typedef enum {")
 (copy-part "src/vector.h" "vectors")
 (output "} vector_t;")
 (newline)
 (output "typedef void interrupt_handler(void);")
 (newline)

 (20 Vector_get ("interrupt_handler *" "vector_get" "vector_t vector_number"))
 (21 Vector_set ("interrupt_handler *" "vector_set" "vector_t vector_number" "interrupt_handler *vector"))


 (section "Critcal Sections")

 (output "typedef uint32_t critical_t;")
 (newline)

 (prototype ("inline critical_t" "critcal_enter" "void"))
 (copy-part "src/interrupt.h" "enter")
 (newline)

 (prototype ("inline void" "critical_exit" "critical_t state"))
 (copy-part "src/interrupt.h" "exit")


 (section "Timer and Delay")

 (30 Delay_microseconds ("void" "delay_us" "unsigned long microseconds"))

 (copy-part "src/timer.h" "enum")
 (newline)
 (34 Timer_get ("unsigned long" "timer_get" "void"))

 (output "typedef enum {")
 (copy-part "src/watchdog.h" "key")
 (output "} watchdog_t;")
 (39 Watchdog_KeepAlive ("void" "watchdog" "watchdog_t key"))


 (section "Event Queue")
 (copy-part "src/event.h" "types")
 (newline)

 (40 Event_flush ("void" "event_flush" "void"))
 ;;(41 Event_clear ("void" "event_flush" "event_item_t item_type"))

 ;;(43 Event_available ("bool" "event_avail" "event_item_t item_type"));

 (comment "src/event.h" "get")
 (44 Event_get ("event_item_t" "event_get" "event_t *event"))

 (newline)
 (output "typedef bool event_callback_t(void *arg);");

 (comment "src/event.h" "wait")
 (45 Event_wait ("event_item_t" "event_wait" "event_t *event" "event_callback_t *callback" "void *arg"))


 (section "LCD Access")

 (copy-part "src/LCD.h" "types")

 (comment "src/LCD.h" "gfb")
 (50 LCD_GetFrameBuffer ("uint8_t *" "lcd_get_framebuffer" "void"))

 (comment "src/LCD.h" "sfb")
 (51 LCD_SetFrameBuffer ("uint32_t *" "lcd_set_framebuffer" "uint32_t *address"))

 (comment "src/LCD.h" "rfb")
 (52 LCD_ResetFrameBuffer ("uint32_t *" "lcd_set_default_framebuffer" "void"))

 (newline)
 (output "typedef enum {")
 (copy-part "src/LCD.h" "colours")
 (output "} lcd_colour_t;")

 (comment "src/LCD.h" "clr")
 (53 LCD_clear ("void" "lcd_clear" "lcd_colour_t colour"))

 (comment "src/LCD.h" "pix")
 (54 LCD_GetPixel ("lcd_colour_t" "lcd_get_pixel" "int x" "int y"))
 (55 LCD_SetPixel ("void" "lcd_set_pixel" "int x" "int y" "lcd_colour_t colour"))

 (comment "src/LCD.h" "pt")
 (56 LCD_point ("void" "lcd_point" "int x" "int y"))

 (comment "src/LCD.h" "line")
 (57 LCD_MoveTo ("void" "lcd_move_to" "int x" "int y"))
 (58 LCD_LineTo ("void" "lcd_line_to" "int x" "int y"))

 (comment "src/LCD.h" "text")
 (60 LCD_AtXY ("void" "lcd_at_xy" "int x" "int y"))
 (61 LCD_print  ("int" "lcd_print" "const char *text"))
 (62 LCD_PutChar  ("int" "lcd_print_char" "char c"))
 (63 LCD_printf  ("int" "lcd_printf" "const char *format" "...") "format (printf, 1, 2)")
 (64 LCD_SetColour ("lcd_colour_t" "lcd_set_colour" "lcd_colour_t value"))
 (65 LCD_GetColour ("lcd_colour_t" "lcd_get_colour" "void"))


 (section "LCD Window (picture-in-picture)")

 (comment "src/LCD.h" "win")
 (70 LCD_Window ("size_t" "lcd_window" "int x" "int y" "int w" "int h"))

 (comment "src/LCD.h" "wint")
 (71 LCD_Window_GetBufferSize ("size_t" "lcd_window_get_buffer_size" "void"))

 (comment "src/LCD.h" "winb")
 (72 LCD_Window_GetByteWidth ("size_t" "lcd_window_get_byte_width" "void"))

 (comment "src/LCD.h" "wina")
 (73 LCD_Window_GetBuffer ("uint8_t *" "lcd_window_get_buffer" "void"))

 (comment "src/LCD.h" "winsb")
 (74 LCD_Window_SetBuffer ("uint32_t *" "lcd_window_set_buffer" "uint32_t *address"))

 (comment "src/LCD.h" "windis")
 (75 LCD_Window_disable ("void" "lcd_window_disable" "void"))

 (comment "src/LCD.h" "winen")
 (76 LCD_Window_enable ("void" "lcd_window_enable" "void"))

 (comment "src/LCD.h" "wingr")
 (80 LCD_Window_clear ("void" "lcd_window_clear" "lcd_colour_t colour"))
 (81 LCD_Window_GetPixel ("lcd_colour_t" "lcd_window_get_pixel" "int x" "int y"))
 (82 LCD_Window_SetPixel ("void" "lcd_window_set_pixel" "int x" "int y" "lcd_colour_t colour"))
 (83 LCD_Window_SetColour ("lcd_colour_t" "lcd_window_set_colour" "lcd_colour_t colour"))
 (84 LCD_Window_GetColour ("lcd_colour_t" "lcd_window_get_colour" "void"))
 (85 LCD_Window_Point ("void" "lcd_window_point" "int x" "int y"))
 (86 LCD_Window_MoveTo ("void" "lcd_window_move_to" "int x" "int y"))
 (87 LCD_Window_LineTo ("void" "lcd_window_line_to" "int x" "int y"))


 (90 LCD_PutBitMap ("void" "lcd_bitmap" "void *framebuffer" "size_t BufferWidth"
                    "int x" "int y" "size_t width" "size_t height"
                    "bool reverse" "const uint8_t *bits"))


 (section "Files and Directory Access")

 (output "typedef enum {")
 (copy-part "src/file.h" "access")
 (output "} file_access_t;")

 (output "typedef enum {")
 (copy-part "src/file.h" "error")
 (output "} file_error_t;")

 (100 File_CloseAll ("void" "file_close_all" "void"))

 (101 File_rename ("file_error_t" "file_rename" "const char *OldFilename" "const char *NewFilename"))
 (102 File_delete ("file_error_t" "file_delete" "const char *filename"))
 (103 File_size ("file_error_t" "file_size"" const char *filename" "unsigned long *length"))

 (110 File_create ("file_error_t" "file_create" "const char *filename" "file_access_t fam"))
 (111 File_open ("file_error_t" "file_open" "const char *filename" "file_access_t fam"))
 (112 File_close ("file_error_t" "file_close" "int handle"))
 (113 File_read ("ssize_t" "file_read" "int handle" "void *buffer" "size_t length"))
 (114 File_write ("ssize_t" "file_write" "int handle" "void *buffer" "size_t length"))
 (115 File_sync ("file_error_t" "file_sync" "int handle"))
 (116 File_lseek ("file_error_t" "file_lseek" "int handle" "unsigned long pos"))
 ;;(117 File_ltell ("file_error_t" "file_ltell" "int handle" "unsigned long *pos"))

 ;;(120 File_ChangeDirectory ("file_error_t" "directory_chdir" "const char *directoryname"))
 ;;(121 File_CurrentDirectory ("file_error_t" "directory_cwd" "char *directoryname" "size_t length"))
 (122 File_CreateDirectory ("file_error_t" "directory_create" "const char *directoryname"))
 (123 File_OpenDirectory ("file_error_t" "directory_open" "const char *directoryname"))
 (124 File_CloseDirectory ("file_error_t" "directory_close" "int handle"))
 (125 File_ReadDirectory ("ssize_t" "directory_read" "int handle" "void *buffer" "size_t length"))

 (output "enum {" "\tSECTOR_SIZE = 512," "};")

 (130 File_AbsoluteRead ("file_error_t" "sector_read" "unsigned long sector" "void *buffer" "int count"))
 (131 File_AbsoluteWrite ("file_error_t" "sector_write" "unsigned long sector" "const void *buffer" "int count"))

 (section "Files and Directory Access")

 (comment "src/memory.h" "alloc")
 (140 Memory_allocate ("void *" "memory_allocate" "size_t size" "const char *tag"))
 (141 Memory_free ("void" "memory_free" "void *address" "const char *tag"))

 (comment "src/memory.h" "debug")
 (142 Memory_debug ("void" "memory_debug" "const char *message"))


 (section "Analog Inputs")

 (output "typedef enum {")
 (copy-part "src/analog.h" "channels")
 (output "} analog_channel_t;")

 (150 Analog_read ("long" "analog_input" "analog_channel_t channel"))


 (endif)
)
