HPGCC3 Documentation 3.0 R003

sys.h

Go to the documentation of this file.
00001 //& *** (c) 2006-2011 The HPGCC3 Team ***
00002 //& Claudio Lapilli
00003 //& Ingo Blank
00004 //&
00005 //& This file is licensed under the terms and conditions of the
00006 //& HPGCC3 license that is included with the source distribution.
00007 //& *** (c) 2006-2011 The HPGCC3 Team ***
00008 
00009 
00010 
00015 #ifndef _HPSYS_H
00016 #define _HPSYS_H
00017 
00018 // LONG TYPE DEFINITION, ADDED BY CLAUDIO 01/14/05
00019 #ifndef _LONGLONG_DEF
00020 typedef unsigned long long ULONGLONG;
00021 typedef long long LONGLONG;
00022 #define _LONGLONG_DEF
00023 #endif
00024 
00025 
00026 #include <kos.h>
00027 
00028 #ifndef EXTERN
00029 #define EXTERN extern
00030 #endif
00031 
00032 #ifndef NULL
00033 #define NULL 0
00034 #endif
00035 
00036 
00038 
00039 typedef void (*__interrupt__)(void);
00040 
00041 // atexit machinery added by ibl 2005-01-31
00042 
00043 typedef void (*ATEXITFUNC)();
00044 
00045 typedef struct _atexit_entry {
00046     ATEXITFUNC f;
00047     struct _atexit_entry *next;
00048 } ATEXIT_ENTRY;
00049 
00050 int atexit(ATEXITFUNC f);
00051 
00052 /* -*- OBSOLETE -*-
00053 // < ibl ; 2006-04-06 >
00054 
00055 // Convert a BCD format number to an hexa value
00056 // char  *sys_bcd2str(unsigned int BCD);
00057 */
00058 
00060 #define sys_bcd2bin(BCD) sys_bcd2bin_nibbles(BCD,2)
00061 
00062 unsigned int sys_bcd2bin_nibbles(unsigned int  BCD,int nibbles);
00063 
00064 
00065 
00066 
00067 
00068 // arithmetics
00069 
00070  typedef struct
00071  {
00072  LONGLONG quot;
00073  LONGLONG rem;
00074  } lldiv_t;
00075 
00076  lldiv_t lldiv(LONGLONG,LONGLONG);
00077 
00092 unsigned divlu2(unsigned num_h,unsigned num_l,unsigned den,unsigned *rem);
00093 
00094 ULONGLONG
00095 udiv64(ULONGLONG nom, unsigned den, unsigned *rem);
00096 
00097 LONGLONG
00098 sdiv64(LONGLONG nom, int den, int *rem);
00099 
00100 
00101 // loader globals
00102 
00104 
00156 // GLOBALS CONVERTED TO CONSTANTS
00157 
00158 #define _mmu_table_addr 0x01100000
00159 #define _code_base_addr 0x01220000
00160 #define _ram_base_addr  0x01101000
00161 #define _ram_size   ((__mg->_mmu_table_entries-4)<<10)
00162 
00163 
00164 // HARDWARE CONSTANTS
00165 #define MEM_REGS        0x07000000
00166 #define SD_REGS         0x07e00000
00167 #define IO_REGS         0x07a00000
00168 #define LCD_REGS    0x07300000
00169 #define CLK_REGS    0x07200000
00170 #define RTC_REGS    0x07B00000 // < ibl ; 2005-06-23 >
00171 #define TMR_REGS        0x07600000
00172 #define INT_REGS        0x07100000
00173 
00174 
00175 // CLOCK MODE CONSTANTS
00176 #define CLK_1MHZ 0x16000000
00177 #define CLK_6MHZ 0x11000000
00178 #define CLK_12MHZ 0x10000000
00179 #define CLK_48MHZ 0x78023
00180 #define CLK_75MHZ 0x43012
00181 #define CLK_120MHZ 0x5c080
00182 #define CLK_152MHZ 0x44011
00183 #define CLK_192MHZ 0x58011
00184 
00185 
00186 
00187 
00188 //ARM interrupts
00189 void cpu_intoff(); 
00190 void cpu_inton();
00192 void cpu_intsave(unsigned int *buffer);
00194 void cpu_intrestore(unsigned int *buffer);
00195 
00196 // power management routines
00197 //void sys_slowOn(); 
00198 //void sys_slowOff();
00199 //int sys_is_slowOn();
00200 
00201 // CPU CLOCK SAVE/RESTORE
00203 void cpu_clksave(unsigned int *buf);
00205 void cpu_clkrestore(unsigned int *buf);
00207 int cpu_setspeed(int hz);
00209 int cpu_getspeed();
00211 int __cpu_setspeed(int PLLCON);
00213 int __cpu_getFCLK();
00215 int __cpu_getHCLK();
00217 int __cpu_getPCLK();
00219 void cpu_flush_cache(int *ptr,int size);
00220 
00221 // *********************************
00222 //    TIMER MACHINERY DEFINITIONS
00223 // *********************************
00224 
00225 #define NUM_EVENTS  5   // NUMBER OF SIMULTANEOUS TIMED EVENTS
00226 
00227 // INTERNAL USE ONLY
00228 typedef struct {
00229 __interrupt__ eventhandler;
00230 ULONGLONG ticks;
00231 unsigned int  delay;
00232 unsigned int status; // 1=ACTIVE, 2=AUTORELOAD
00233 } timed_event;
00234 
00236 typedef int HEVENT;
00237 
00239 void tmr_save(unsigned int *tmrbuffer);
00241 void tmr_restore(unsigned int *tmrbuffer);
00243 void tmr_setup();
00244 
00246 typedef ULONGLONG tmr_t;
00247 
00249 tmr_t tmr_getsysfreq();
00250 
00252 tmr_t tmr_ticks();
00254 void tmr_delayms(int milliseconds);
00256 void tmr_delayus(int microseconds);
00257 
00259 int tmr_ticks2ms(tmr_t before, tmr_t after);
00261 int tmr_ticks2us(tmr_t before, tmr_t after);
00263 tmr_t tmr_addms(tmr_t time, int ms);
00265 tmr_t tmr_addus(tmr_t time, int us);
00267 void tmr_waituntil(tmr_t time);
00268 
00270 #define tmr_ms2ticks(a) tmr_addms((tmr_t)0,(a))
00271 
00273 #define tmr_us2ticks(a) tmr_addus((tmr_t)0,(a))
00274 
00275 
00276 
00298 HEVENT tmr_eventcreate(__interrupt__ handler,unsigned int ms,BOOL autorepeat);
00299 
00309 void tmr_eventkill(HEVENT event);
00310 
00311 
00312 
00313 /*
00314 // REMOVED BY CLAUDIO - FUNCTIONALITY IS NOW OBSOLETE
00315 typedef struct
00316 {
00317     ULONGLONG current;
00318     unsigned last_val : 16;
00319     unsigned timer : 3;
00320     unsigned inited : 1;
00321 } sys_timer_t;
00322 
00323 #define SYS_TIMER_INITIALIZER { 0, 0, 0, 0 }
00324 #define SYS_TIMER_INITIALIZER_NUM(n) { 0, 0, n, 0 }
00325 
00326 ULONGLONG sys_updateTimer(sys_timer_t *timer);
00327 
00328 
00329 
00330 
00331 void sys_sleep(unsigned int millis);
00332 
00334 void sys_waitTicks(unsigned int time); 
00335 void sys_setupTimers();
00336 void sys_restoreTimers();
00337 
00339 unsigned short int sys_getPWMCounter0();
00340 */
00341 
00342 
00344 
00349 int sys_RTC_seconds();
00350 
00351 
00352 
00353 // VIDEO MODE CONSTANTS
00354 #define MODE_MONO 0
00355 #define MODE_4GRAY 1
00356 #define MODE_16GRAY 2
00357 
00359 void lcd_sync();
00361 void __lcd_fix();
00363 void lcd_save(unsigned int *buffer);
00365 void lcd_restore(unsigned int *buffer);
00371 int lcd_setmode(int mode,int *physicalbuffer);
00372 // ! Returns the screen height in pixels
00373 int lcd_getheight();
00375 void lcd_off();
00377 void lcd_on();
00378 
00382 void lcd_setcontrast(int level);
00383 
00384 
00385 
00386 // mmu mapping functions
00388 EXTERN int sys_map_v2p(unsigned int vaddr);
00390 EXTERN int sys_map_p2v(unsigned int paddr);
00392 int sys_mem_classify(int addr);
00393 
00394 // mmu independent physical malloc
00395 
00396 void *sys_phys_malloc(size_t);
00397 
00398 
00399 // particular functions
00400 
00407 EXTERN void sys_playTone(unsigned int tone, unsigned int duration);
00408 EXTERN void sys_waitTicks (unsigned int time);
00409 EXTERN void setDisplayPlane(unsigned char * plane);
00410 
00411 EXTERN void sys_playTone2(unsigned int time, unsigned int duration);
00412 
00414 int sys_isRTCTick();
00416 unsigned char sys_setRTCTickPeriod(unsigned char n);
00418 void sys_waitRTCTicks(int count);
00419 
00420 
00421 // < ibl >
00422 
00432 int sys_delta_seconds(int t_start, int t_end);
00433 
00434 // < ibl ; 2005-02-08 >
00435 
00444 void sys_error(const char *msg, int code);
00445 
00446 // < ibl ; 2005-05-16 >
00447 
00455 void *sys_chkptr(void *p);
00456 
00457 // MAIN EXCEPTION HANDLER
00458 
00459 
00463 #define __EX_CONT 1             // SHOW CONTINUE OPTION
00464 
00467 #define __EX_EXIT 2             // SHOW EXIT OPTION
00468 
00471 #define __EX_WARM 4             // SHOW WARMSTART OPTION
00472 
00475 #define __EX_RESET 8    // SHOW RESET OPTION
00476 
00477 
00500 void throw_exception(char * message, unsigned int options);
00501 
00502 void throw_dbgexception(char * message, unsigned int options);
00503 
00504 
00505 // *****************************************************
00506 // **************  IRQ MACHINERY ***********************
00507 // *****************************************************
00508 
00509 
00557 void __irq_addhook(int service_number,__interrupt__ serv_routine);
00558 
00559 
00574 void __irq_releasehook(int service_number);
00575 
00576 
00577 
00578 
00579 #endif 
00580