Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DDRO_Farrari by
Diff: main.cpp
- Revision:
- 10:95e9932f7990
- Parent:
- 9:cbb692f51e0f
--- a/main.cpp Tue Feb 11 21:36:52 2014 +0000
+++ b/main.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -1,56 +1,40 @@
-#include <InterruptIn.h>
#include "mbed.h"
-#include "dac.h"
-#include "board_test.h"
-#include "scan.h"
+#include "rtos.h"
#include "power.h"
#include "pinout.h"
#include "pll.h"
-#include "lcd.h"
#include "jtag.h"
#include "mmap.h"
-#include "clock.h"
-#include "EasyBMP.h"
+#include "GPIOInterrupt.h"
+#include "basic_io.h"
+#include "panic.h"
#include "main.h"
-#include "serialIO.h"
+#include "signal.h"
-InterruptIn GPIO_int(GPIO_int_pin);
-JTAG *pJtag;
+// pointer to thread
+Thread *thread_ptr;
-void trigger() {
- for (int i = 0; i < 2; ++i) {
- sprintf(tx_line, "hex is: %08x\r\n", pJtag->readMemory(0x24000110 + i * 4));
- send_line();
- }
-}
+void init_hw(void);
+void req_intr_handler(void);
+void print_rambuffer(void const *args);
int main()
{
- float core_volt = 1;
-
- //wdt.kick(20.0);
- pc.printf("Begin FFT\r\n");
- power_down();
- power_up(core_volt); // Power Up Chip
- pc.printf("Powered up!\r\n");
-
- PORESETn = 0;
- CORERESETn = 0;
- wait_us(100);
- PORESETn = 1;
- CORERESETn = 1;
-
+ init_hw();
+
JTAG jtag;
- pJtag = &jtag;
// We check if JTAG works well by checking idcode returned by issuing a test instruction and read result idcode back.
int idcode = jtag.readID();
if(idcode != 0x4ba00477) {
- pc.printf("ERROR: IDCode %X\r\n", idcode);
- wait(2);
- power_down();
- return -1;
+ panic("ERROR: IDCode %X\r\n", idcode);
}
- pc.printf("IDCode %X\r\n", idcode);
+
+ // create working threads first
+ Thread core_handler(listen_req, (void *)(&jtag));
+ Thread debugThread(print_rambuffer, (void *)(&jtag));
+ thread_ptr = &core_handler;
+ // enable GPIO interrupt
+ enable_GPIO_intr(&req_intr_handler);
jtag.reset();
jtag.leaveState();
@@ -62,79 +46,71 @@
power_core(1);
set_pll_frequency (200, jtag);
- // attach new interrupt handler
- pc.attach(&Tx_interrupt, Serial::TxIrq);
- pc.attach(&Rx_interrupt, Serial::RxIrq);
// Begin to load program
- sprintf(tx_line, "Begining loading program.\r\n");
- send_line();
+ mbed_printf("Begining loading program.\r\n");
if (jtag.loadProgram()) {
- sprintf(tx_line, "Load Failed!\r\n");
- send_line();
+ mbed_printf("Load Failed!\r\n");
} else {
+ mbed_printf("Load Succeed!\r\n");
CORERESETn = 0;
- CORERESETn = 1;
- wait(0.2);
- jtag.reset();
- jtag.leaveState();
- jtag.PowerupDAP();
+ CORERESETn = 1;
+ char line[80];
- sprintf(tx_line, "JTAG initialization finished.\r\n");
- send_line();
- // Enable interrupt from GPIO. Each time when an GPIO interrupt happens, we read an unsigned int
- // from a certain address of cortex-m3 through JTAG-DP
- GPIO_int.rise(&trigger);
- GPIO_int.mode(PullDown);
while (1) {
- sprintf(tx_line, "Type 'quit' to quit. Press any key to continue.\r\n");
- send_line();
- read_line();
- if (strncmp(rx_line, "quit", 80) == 0)
+
+ mbed_printf("Type 'quit' to quit.\r\n");
+ mbed_scanf("%s", line);
+ if (strncmp(line, "quit", 80) == 0)
break;
+ else if (strncmp(line, "debug", 80) == 0)
+ debugThread.signal_set(SIG_DEBUG);
+
}
+
}
-
- sprintf(tx_line, "Powering Down\r\n");
- send_line();
+
+ core_handler.terminate();
+ thread_ptr = NULL;
+ jtag.reset();
+
+ mbed_printf("Powering Down\r\n");
power_down();
- sprintf(tx_line, "Done.\r\n");
- send_line();
+ mbed_printf("Done.\r\n");
while (1)
;
}
-void DDRO_Sensor(JTAG &jtag)
-{
- /**********************enable****************************************/
- jtag.writeMemory(ddro_syn_en, 0xffffffff);
- jtag.writeMemory(ddro_inv_en, 0xffffffff);
- /**********************set ref_clk and samp_clk**********************/
- jtag.writeMemory(ddro_ref_src, 0x00000002);
- /**********************write threshold*******************************/
- jtag.writeMemory(ddro_threshold, 100000);
- //jtag.writeMemory(0xe000e104, 0x000000ff); // enable interrupts
+void init_hw(void) {
+ float core_volt = 1;
+ power_down();
+ power_up(core_volt); // Power Up Chip
+ mbed_printf("Powered up!\r\n");
+
+ PORESETn = 0;
+ CORERESETn = 0;
+ wait_us(100);
+ PORESETn = 1;
+ CORERESETn = 1;
+}
- for (int ro_id=3;ro_id<=15;ro_id++) {
- pc.printf("RO %d\r\n ", ro_id-2);
- jtag.writeMemory(ddro_samp_src, ro_id);
- jtag.writeMemory(ddro_start, 0);
- int meas1 = jtag.readMemory(ddro_count);
- pc.printf("Counter starts at: %d ", meas1);
- jtag.writeMemory(ddro_start, 1);
- wait_us(50000);
- jtag.writeMemory(ddro_start, 0);
- meas1 = jtag.readMemory(ddro_count);
- pc.printf("ends at: %d\r\n", meas1);
-
- jtag.writeMemory(ddro_samp_src, ro_id);
- jtag.writeMemory(ddro_start, 0);
- meas1 = jtag.readMemory(ddro_count);
- pc.printf("Counter starts at: %d ", meas1);
- jtag.writeMemory(ddro_start, 1);
- wait_us(50000);
- jtag.writeMemory(ddro_start, 0);
- meas1 = jtag.readMemory(ddro_count);
- printf("ends at: %d\r\n", meas1);
+void req_intr_handler(void) {
+ if (thread_ptr)
+ thread_ptr->signal_set(SIG_COREREQ);
+ return;
+}
+
+void print_rambuffer(void const *args) {
+ static bool init = true;
+ JTAG *pJtag = (JTAG *)args;
+ while (1) {
+ Thread::signal_wait(SIG_DEBUG);
+ if (init) {
+ pJtag->reset();
+ pJtag->leaveState();
+ pJtag->PowerupDAP();
+ init = false;
+ }
+ debug_print(pJtag);
}
}
