summaryrefslogtreecommitdiff
path: root/firmware/system.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-01-21 08:04:43 -0500
committerGerrit Rockbox <gerrit@rockbox.org>2017-01-25 00:05:13 +0100
commit783c77531c35e62dd754c510c4f2beefe6df4a9d (patch)
tree79e747eb1ba3716b56e5178145536f316c44e403 /firmware/system.c
parenta1d1832049146925400b57c4cd81b0739b674971 (diff)
downloadrockbox-783c77531c35e62dd754c510c4f2beefe6df4a9d.tar.gz
rockbox-783c77531c35e62dd754c510c4f2beefe6df4a9d.zip
AMS: Return ascodec to interrupt-based I2C2 driver
1. Slightly revised and regularized internal interface. Callback is used for read and write to provide completion signal instead of having two mechanisms. 2. Lower overhead for asynchronous or alterate completion callbacks. We now only init what is required by the transfer. A couple unneeded structure members were also nixed. 3. Fixes a bug that would neglect a semaphore wait if pumping the I2C interrupts in a loop when not in thread state or interrupts are masked. 4. Corrects broken initialization order by defining KDEV_INIT, which makes kernel_init() call kernel_device_init() to initialize additional devices _after_ the kernel, threading and synchronization objects are safe to use. 5. Locking set_cpu_frequency has to be done at the highest level in system.c to ensure the boost counter and the frequency are both set in agreement. Reconcile the locking inteface between PP and AMS (the only two currently using locking there) to keep it clean. Now works fine with voltages in GIT HEAD on my Fuze v2, type 0. Previously, everything crashed and died instantly. action.c calling set_cpu_frequency from a tick was part of it. The rest may have been related to 3. and 4. Honestly, I'm not certain! Testing by Mihail Zenkov indicates it solves our problems. This will get the developer builds running again after the kernel assert code push. Change-Id: Ie245994fb3e318dd5ef48e383ce61fdd977224d4
Diffstat (limited to 'firmware/system.c')
-rw-r--r--firmware/system.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/firmware/system.c b/firmware/system.c
index 37631b8735..537e901b05 100644
--- a/firmware/system.c
+++ b/firmware/system.c
@@ -35,13 +35,6 @@ long cpu_frequency SHAREDBSS_ATTR = CPU_FREQ;
35#ifdef HAVE_ADJUSTABLE_CPU_FREQ 35#ifdef HAVE_ADJUSTABLE_CPU_FREQ
36static int boost_counter SHAREDBSS_ATTR = 0; 36static int boost_counter SHAREDBSS_ATTR = 0;
37static bool cpu_idle SHAREDBSS_ATTR = false; 37static bool cpu_idle SHAREDBSS_ATTR = false;
38#if NUM_CORES > 1
39static struct corelock boostctrl_cl SHAREDBSS_ATTR;
40void cpu_boost_init(void)
41{
42 corelock_init(&boostctrl_cl);
43}
44#endif
45 38
46int get_cpu_boost_counter(void) 39int get_cpu_boost_counter(void)
47{ 40{
@@ -60,7 +53,7 @@ int cpu_boost_log_getcount(void)
60char * cpu_boost_log_getlog_first(void) 53char * cpu_boost_log_getlog_first(void)
61{ 54{
62 char *first; 55 char *first;
63 corelock_lock(&boostctrl_cl); 56 cpu_boost_lock();
64 57
65 first = NULL; 58 first = NULL;
66 59
@@ -70,7 +63,7 @@ char * cpu_boost_log_getlog_first(void)
70 first = cpu_boost_calls[cpu_boost_first]; 63 first = cpu_boost_calls[cpu_boost_first];
71 } 64 }
72 65
73 corelock_unlock(&boostctrl_cl); 66 cpu_boost_unlock();
74 return first; 67 return first;
75} 68}
76 69
@@ -79,7 +72,7 @@ char * cpu_boost_log_getlog_next(void)
79 int message; 72 int message;
80 char *next; 73 char *next;
81 74
82 corelock_lock(&boostctrl_cl); 75 cpu_boost_lock();
83 76
84 message = (cpu_boost_track_message+cpu_boost_first)%MAX_BOOST_LOG; 77 message = (cpu_boost_track_message+cpu_boost_first)%MAX_BOOST_LOG;
85 next = NULL; 78 next = NULL;
@@ -90,13 +83,14 @@ char * cpu_boost_log_getlog_next(void)
90 next = cpu_boost_calls[message]; 83 next = cpu_boost_calls[message];
91 } 84 }
92 85
93 corelock_unlock(&boostctrl_cl); 86 cpu_boost_unlock();
94 return next; 87 return next;
95} 88}
96 89
97void cpu_boost_(bool on_off, char* location, int line) 90void cpu_boost_(bool on_off, char* location, int line)
98{ 91{
99 corelock_lock(&boostctrl_cl); 92 if (!cpu_boost_lock())
93 return;
100 94
101 if (cpu_boost_calls_count == MAX_BOOST_LOG) 95 if (cpu_boost_calls_count == MAX_BOOST_LOG)
102 { 96 {
@@ -115,7 +109,9 @@ void cpu_boost_(bool on_off, char* location, int line)
115#else 109#else
116void cpu_boost(bool on_off) 110void cpu_boost(bool on_off)
117{ 111{
118 corelock_lock(&boostctrl_cl); 112 if (!cpu_boost_lock())
113 return;
114
119#endif /* CPU_BOOST_LOGGING */ 115#endif /* CPU_BOOST_LOGGING */
120 if(on_off) 116 if(on_off)
121 { 117 {
@@ -141,12 +137,13 @@ void cpu_boost(bool on_off)
141 } 137 }
142 } 138 }
143 139
144 corelock_unlock(&boostctrl_cl); 140 cpu_boost_unlock();
145} 141}
146 142
147void cpu_idle_mode(bool on_off) 143void cpu_idle_mode(bool on_off)
148{ 144{
149 corelock_lock(&boostctrl_cl); 145 if (!cpu_boost_lock())
146 return;
150 147
151 cpu_idle = on_off; 148 cpu_idle = on_off;
152 149
@@ -160,7 +157,7 @@ void cpu_idle_mode(bool on_off)
160 set_cpu_frequency(CPUFREQ_NORMAL); 157 set_cpu_frequency(CPUFREQ_NORMAL);
161 } 158 }
162 159
163 corelock_unlock(&boostctrl_cl); 160 cpu_boost_unlock();
164} 161}
165#endif /* HAVE_ADJUSTABLE_CPU_FREQ */ 162#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
166 163