From e1a51dae219ca34167e92809da2a6e61230b6a61 Mon Sep 17 00:00:00 2001 From: lephe Date: Thu, 5 May 2016 22:33:15 +0200 Subject: [PATCH] Displayed keyboard state in test [1]. Implemented some API for user RTC interrupt management. --- TODO | 4 ++- ginttest.c | 40 ++++++++++++++++---------- ginttest.g1a | Bin 13652 -> 14384 bytes icon.bmp | Bin 1870 -> 1870 bytes include/display.h | 41 +++++++++++++++++++++----- include/gint.h | 51 ++++++++++++++++++++++++++------ include/mpu.h | 13 +++++++++ include/screen.h | 4 +++ include/setjmp.h | 4 +-- libc.a | Bin 1770 -> 1770 bytes libgint.a | Bin 23548 -> 24660 bytes src/display.c | 21 ++++++++++---- src/gint.c | 39 +++++++++++++++++++++++++ src/gint_7305.c | 36 +++++++++++++++++++++-- src/gint_7705.c | 41 ++++++++++++++++++++++++-- src/keyboard.c | 2 +- src/mpu.c | 12 ++++---- src/timer.c | 72 ++++++++++++++++++++++++++++------------------ 18 files changed, 301 insertions(+), 79 deletions(-) diff --git a/TODO b/TODO index 360005e..8e540a7 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,11 @@ - multi-getkey repeats (if possible, which doesn't seem likely) -- getkey() may unwantedly repeat a key if it was triggered for multigetkey() - write and test gray engine - full rtc driver (time) - callbacks and complete user API +- exhaustive save for setjmp() +- registers that need to be saved when configuring gint + _ 7305.h _ libc diff --git a/ginttest.c b/ginttest.c index 3211a45..5b5781a 100644 --- a/ginttest.c +++ b/ginttest.c @@ -17,7 +17,7 @@ void print_clear(void) { char *empty_line = " "; int i = 0; - while(i < 8) print(empty_line, 0, i++); + while(i < 8) __Print(empty_line, 0, i++); } void print(const char *str, int x, int y) { @@ -66,30 +66,38 @@ void print_hexa(unsigned int n, int digits, int x, int y) /* Keyboard tests. + The user timer reproduces the parameters of the keyboard timer. */ +void keyboard_test_timer(void) +{ + volatile unsigned char *state = keystate(); + + print_bin(state[0], 0, 1); + print_bin(state[1], 0, 2); + print_bin(state[2], 0, 3); + print_bin(state[3], 0, 4); + print_bin(state[4], 0, 5); + + print_bin(state[5], 9, 1); + print_bin(state[6], 9, 2); + print_bin(state[7], 9, 3); + print_bin(state[8], 9, 4); + print_bin(state[9], 9, 5); +} + void keyboard_test(void) { -/* - print_bin(keyboard_state[0], 0, 2); - print_bin(keyboard_state[1], 0, 3); - print_bin(keyboard_state[2], 0, 4); - print_bin(keyboard_state[3], 0, 5); - print_bin(keyboard_state[4], 0, 6); - - print_bin(keyboard_state[5], 9, 2); - print_bin(keyboard_state[6], 9, 3); - print_bin(keyboard_state[7], 9, 4); - print_bin(keyboard_state[8], 9, 5); - print_bin(keyboard_state[9], 9, 6); -*/ - int x = 0; char str[3]; int keys[4] = { 0 }; int i; + timer_start(TIMER_USER, 1700, TIMER_Po_256, keyboard_test_timer, 0); + print_clear(); + print("Keyboard state:", 0, 0); + print("multi-getkey ^^", 6, 7); while(1) { @@ -114,6 +122,8 @@ void keyboard_test(void) #undef hexa } + + timer_stop(TIMER_USER); } /* diff --git a/ginttest.g1a b/ginttest.g1a index ab2465188f8691e80912dc21c73c09f49836ec55..4e1da8246c504857e8af6bc5545e2ed1cf52ff87 100644 GIT binary patch delta 2661 zcmb7GUrbxq89(=r&AqW5Utb%riR0M!IwTYpU!16ol1Q~_HLic;G^lBF3X zly$Aj=6J#tDC-8fsExWk_`wg+gp{=I!~S%WAJ9hChxt;ZMca#kfT}6lA~ouGi12>r z*br}T1ATno{hjarzCY)D=dyC;?pW)u7yfW(cKYKFoV9=9_vf`*?azN{pKI;yjmMA1 z2|4i*5&M>j_`;`;_Q3EzY7K;|J!kk8Gi z@S6P~Xk0#XO6cREmV`B`7Q|1fO4*jPE??~Z*yezieLVWj<@I+Kt-hp#$Z5fUAiaKV zaqvJ|Ne4H%4KnPtPO%k+UgH?fGyLf$oM*VeaH9zq7%npWsU|!tvIQGkh&CxX9jmVDHGj#mvD_QtCZ5q^>?r z9Zdw&!n#`ztjb5*Z>Xz>3LYZci|CSJ_Y*^_;P6Sr==4EfhK{0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b/icon.bmp index c97606c7cb0c2bcf40cf8d23fa16df42da126d41..27f0e48206978289bfc171e9aa03a16e1d448acc 100644 GIT binary patch delta 221 zcmZ`zJqp4w7;XC{9|S^MGR0=`29D02#2W;`)e|@w-s~ti3XU#bz#c(+0iie0&r%n` z;qiv|+m>y4niCqf*iwb1X4I-ly+cO^Yj&71r-wyN8c_vI3nyUgwZ&C2{&*i8MO5ta2zdKQRbZSAb GEPDfw=R#Zn literal 1870 zcmb_aI~Kw)3=0f!02U?=(}f8J&cVjU2{<74DN00y>$tRh{9asHmXy**cQ~$7sVn*! zXNR-FS)?s`O7~StHxT*M>h`Bg#dDuaC+z#)G5;Hp{dv%7dX0>*aW&j$ff!*~!h|Z5 zY7&GoAvu-Zn#2e&BYY`nqHjWNyAqRaroPHH{wEA$Lb4db&F^H*#*<+Lh0aYRnf5|z ztWug{!9*)NM@nd7w>-CELP1HBM8Ij=vG|_JP diff --git a/libgint.a b/libgint.a index 82f815bbb16ae8095cfcf035ac5766bd1f6d87f1..4425ae3f51729ff48ab558755b6da25d93b189e8 100644 GIT binary patch delta 3762 zcmb7HZ%kX)6+id+Vf%rxjctt0AM>!mhCqmMC}ArrX3z?)2@poJwkW|sXcCoB;yO~Q z(K?pmDQUI@aw09Q(1td&qV+?O9BI+URz5^qrgj=mBaKP@K$K~kwtR@RX^ONc?A+(~ zY~!+SyXZXs&UxqlJ->7A&KU6YmV}4;_%@pv+tTQ)LE2QOk!gT0lhH6h zMli@;^SwD08y@NH9iN__7@vF{#!j4?iH)7uVZ^H}5+J7+qElziPR&fdHFn@Y@R=R1 z*;ly5juiOr|Bt@g4FMbwB*W?1vty@bPT@?48&3ry>O!=C$wkn@r!ZJ&4$y)(S8&YLcqu-#`N>m@O5AtZ#X zmkr!=#FIAllz_A(fu!n^qB9`NJH|I24EksO3FJY402G>B+xO?exHtY}=I_+;wz81h zhimIxmvw2!xNXS;5>2m7%BSa(N@)upenQ9lkhgcqNPZIMgGRD_Gm+@zn1@E8PsmI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*10E~(Tam<5sl>xP`ro`PEU=&%sEGrxpztqYaq3H0j4jk5g<_hF m(O1wdYWz6a=@V|tjX~2$jlrj-B9i;3C!0=#R$_%@EB*mN2hMl^ diff --git a/src/display.c b/src/display.c index 92b2315..d004b1e 100644 --- a/src/display.c +++ b/src/display.c @@ -41,7 +41,7 @@ static int *vram = local_vram; //--- -// Local helper functions. +// Local functions. //--- /* @@ -115,14 +115,25 @@ static void getmasks(int x1, int x2, unsigned int *masks) //--- /* - display_getVRAM() - Returns the current video ram. + display_getLocalVRAM() + Returns the local video ram. @return Video ram address. */ void *display_getLocalVRAM(void) { - return (void*)local_vram; + return (void *)local_vram; +} + +/* + display_getCurrentVRAM() + Returns the current vido ram. + + @return Video ram address. +*/ +void *display_getCurrentVRAM(void) +{ + return (void *)vram; } /* @@ -370,7 +381,7 @@ void dline(int x1, int y1, int x2, int y2, enum Color color) // the same : get a part of the image in an operator, shift it depending // on the drawing x-coordinate, compute a mask that indicates which bits // of the operator contain information, and modify a vram long using the -// operator. +// operator and the mask. //--- /* diff --git a/src/gint.c b/src/gint.c index 19198c9..e63596b 100644 --- a/src/gint.c +++ b/src/gint.c @@ -1,6 +1,7 @@ #include #include #include +#include //--- // Local variables. @@ -10,6 +11,8 @@ static unsigned int new_vbr, sys_vbr; +static void (*rtc_callback)(void) = NULL; + //--- @@ -60,6 +63,42 @@ unsigned int gint_systemVBR(void) return sys_vbr; } +/* + gint_setRTCCallback() + Sets the callback function for the real-time clock interrupt. If + frequency is non-NULL, the clock frequency is set to the given value. + + @arg callback Callback function. + @arg frequency Interrupt frequency. +*/ +void gint_setRTCCallback(void (*callback)(void), enum RTCFrequency frequency) +{ + if(frequency < 1 || frequency > 7) return; + rtc_callback = callback; + + if(isSH3()) + gint_setRTCFrequency_7705(frequency); + else + gint_setRTCFrequency_7305(frequency); +} + +/* + gint_getRTCCallback() + Returns the callback function. If frequency is non-NULL, it is set to + the current frequency value. +*/ +void (*gint_getRTCCallback(enum RTCFrequency *frequency))(void) +{ + if(!frequency) return rtc_callback; + + if(isSH3()) + *frequency = gint_getRTCFrequency_7705(); + else + *frequency = gint_getRTCFrequency_7305(); + + return rtc_callback; +} + /* gint() Handles interrupts. diff --git a/src/gint_7305.c b/src/gint_7305.c index 25330e9..bbdc22c 100644 --- a/src/gint_7305.c +++ b/src/gint_7305.c @@ -15,6 +15,35 @@ +//--- +// Various MPU-dependent procedures. +//--- + +/* + gint_setRTCFrequency() + Sets the RTC interrupt frequency and enables interrupts. + + @arg frequency +*/ +void gint_setRTCFrequency_7305(enum RTCFrequency frequency) +{ + if(frequency < 1 || frequency > 7) return; + RTC.RCR2.BYTE = (frequency << 4) | 0x09; +} + +/* + gint_getRTCFrequency() + Returns the RTC interrupt frequency. + + @return RTC interrupt frequency. +*/ +enum RTCFrequency gint_getRTCFrequency_7305(void) +{ + return (RTC.RCR2.BYTE & 0x70) >> 4; +} + + + //--- // Keyboard management. //--- @@ -272,15 +301,16 @@ void gint_setup_7305(void) { gint_priority_lock_7305(); - // Configuring the RTC to have a 16-Hz keyboard. + // Saving the RTC configuration. rcr2 = RTC.RCR2.BYTE; - RTC.RCR2.BYTE = 0x39; + // Disabling RTC interrupts by default. + RTC.RCR2.BYTE = 0x09; } void gint_stop_7305(void) { gint_priority_unlock_7305(); - // Stopping the RTC interrupt. + // Restoring the RTC configuration. RTC.RCR2.BYTE = rcr2; } diff --git a/src/gint_7705.c b/src/gint_7705.c index 563958b..4a08601 100644 --- a/src/gint_7705.c +++ b/src/gint_7705.c @@ -15,6 +15,35 @@ +//--- +// Various MPU-dependent procedures. +//--- + +/* + gint_setRTCFrequency() + Sets the RTC interrupt frequency and enables interrupts. + + @arg frequency +*/ +void gint_setRTCFrequency_7705(enum RTCFrequency frequency) +{ + if(frequency < 1 || frequency > 7) return; + RTC.RCR2.BYTE = (frequency << 4) | 0x09; +} + +/* + gint_getRTCFrequency() + Returns the RTC interrupt frequency. + + @return RTC interrupt frequency. +*/ +enum RTCFrequency gint_getRTCFrequency_7705(void) +{ + return (RTC.RCR2.BYTE & 0x70) >> 4; +} + + + //--- // Keyboard management. //--- @@ -22,7 +51,7 @@ /* kdelay() Used to be a low-level sleep using the watchdog, as in the system. This - way seems ok at least, and it doesn't create column effects as for + way seems OK at least, and it doesn't create column effects as for SH7305. */ static void kdelay(void) @@ -181,6 +210,7 @@ void gint_7705(void) //--- static unsigned short iprs[8]; +static unsigned char rcr2; static void gint_priority_lock_7705(void) { @@ -230,11 +260,16 @@ void gint_setup_7705(void) { gint_priority_lock_7705(); - // Configuring the RTC to have a 16-Hz keyboard. - RTC.RCR2.BYTE = 0x39; + // Saving the RTC configuration. + rcr2 = RTC.RCR2.BYTE; + // Disabling RTC interrupts by default. + RTC.RCR2.BYTE = 0x09; } void gint_stop_7705(void) { gint_priority_unlock_7705(); + + // Restoring the RTC configuration. + RTC.RCR2.BYTE = rcr2; } diff --git a/src/keyboard.c b/src/keyboard.c index 0ec7a0e..1f44d74 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -214,7 +214,7 @@ int keylast(int *repeat_count) /* keystate() Returns the address of the keyboard state array. The returned address - if the handler's buffer, therefore it contains volatile data. + is the handler's buffer, therefore it contains volatile data. @return 10-byte keyboard state buffer. */ diff --git a/src/mpu.c b/src/mpu.c index ccc38d6..fa5fbea 100644 --- a/src/mpu.c +++ b/src/mpu.c @@ -63,13 +63,13 @@ enum MPU getMPU(void) return MPU_Unknown; } -static void mpu_init(void) - __attribute__(( - section(".pretext"), - constructor - )); -static void mpu_init(void) + +/* + mpu_init() + Determines the MPU type and stores the result into MPU_CURRENT. +*/ +void mpu_init(void) { MPU_CURRENT = getMPU(); } diff --git a/src/timer.c b/src/timer.c index d7afc15..77c9a9d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -2,9 +2,14 @@ #include #include +//--- +// Internal declarations. +// Timer structure and running information (callbacks, repeats etc.) +//--- + /* struct Timer - This structure handles a running timer information. + This structure holds information for a running timer. */ struct Timer { @@ -17,7 +22,8 @@ static struct Timer timers[3] = { { NULL, 0 }, { NULL, 0 }, { NULL, 0 } }; /* struct mod_tmu - This structure allows access to a timer using its address. + This structure holds information about the timer unit (peripheral + module) registers. */ struct mod_tmu { @@ -48,6 +54,10 @@ struct mod_tmu +//--- +// Internal API. +//--- + /* timer_get() @@ -57,7 +67,7 @@ struct mod_tmu @arg tmu mod_tmu structure pointer address. @arg tstr mod_tstr structure pointer address. */ -void timer_get(int timer, struct mod_tmu **tmu, unsigned char **tstr) +static void timer_get(int timer, struct mod_tmu **tmu, unsigned char **tstr) { // Using SH7705 information for SH-3-based MPUs. if(MPU_CURRENT == MPU_SH7337 || MPU_CURRENT == MPU_SH7355) @@ -76,6 +86,37 @@ void timer_get(int timer, struct mod_tmu **tmu, unsigned char **tstr) if(tmu) *tmu += timer; } +/* + timer_interrupt() + Handles the interrupt for the given timer. + + @timer Timer that generated the interrupt. +*/ +void timer_interrupt(int timer) +{ + // Getting the timer address. + struct mod_tmu *tmu; + timer_get(timer, &tmu, NULL); + + // Resetting the interrupt flag. + (*tmu).TCR.UNF = 0; + + // Calling the callback function. + if(timers[timer].callback) timers[timer].callback(); + + // Reducing the number of repetitions left, if not infinite. + if(!timers[timer].repetitions) return; + // And stopping it if necessary. + if(timers[timer].repetitions == 1) timer_stop(timer); + else timers[timer].repetitions--; +} + + + +//--- +// Public API. +//--- + /* timer_start() Configures and starts a timer. @@ -135,28 +176,3 @@ void timer_stop(int timer) // Stopping the timer. *tstr &= ~byte; } - -/* - timer_interrupt() - Handles the interrupt for the given timer. - - @timer Timer that generated the interrupt. -*/ -void timer_interrupt(int timer) -{ - // Getting the timer address. - struct mod_tmu *tmu; - timer_get(timer, &tmu, NULL); - - // Resetting the interrupt flag. - (*tmu).TCR.UNF = 0; - - // Calling the callback function. - if(timers[timer].callback) timers[timer].callback(); - - // Reducing the number of repetitions left, if not infinite. - if(!timers[timer].repetitions) return; - // And stopping it if necessary. - if(timers[timer].repetitions == 1) timer_stop(timer); - else timers[timer].repetitions--; -}