spinnaker_tools (BMP)  latest
SpiNNaker BMP firmware
bmp.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //
3 // bmp.h Low-level hardware interface code for BMP LPC1768
4 //
5 // Copyright (C) The University of Manchester - 2012-2018
6 //
7 // Author Steve Temple, APT Group, School of Computer Science
8 // Email steven.temple@manchester.ac.uk
9 //
10 //------------------------------------------------------------------------------
11 
12 /*
13  * Copyright (c) 2012 The University of Manchester
14  *
15  * Licensed under the Apache License, Version 2.0 (the "License");
16  * you may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at
18  *
19  * https://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  */
27 
28 //
31 //
32 
33 #include <stdint.h>
34 #include <stdbool.h>
35 
36 #ifndef DOXYGEN
37 #define NORETURN __attribute__((noreturn))
38 #define SECTION(sec) __attribute__((section (sec)))
39 #define ALIAS(fun) __attribute__((weak, alias(#fun)))
40 #define ALIGNED(a) __attribute__ ((aligned(a)))
41 #endif
42 
43 //------------------------------------------------------------------------------
44 
46 #define BMP_VER_STR "2.1.2"
48 #define BMP_VER_NUM 0x020102
50 #define BMP_ID_STR "BC&MP/Spin5-BMP"
51 
52 //------------------------------------------------------------------------------
53 
54 #define CCLK 100000000
55 
57 #ifndef NULL
58 #define NULL 0
59 #endif
60 
61 //------------------------------------------------------------------------------
62 
65  LED_0 = (1 << 4),
66  LED_1 = (1 << 5),
67  LED_2 = (1 << 19),
68  LED_3 = (1 << 20),
69  LED_4 = (1 << 21),
70  LED_5 = (1 << 22),
71  LED_6 = (1 << 29),
72  LED_7 = (1 << 30),
73 };
74 
76 #define LED_MASK \
77  (LED_0 + LED_1 + LED_2 + LED_3 + LED_4 + LED_5 + LED_6 + LED_7)
78 
81  SF_NCS = (1 << 16),
82 
83  XFSEL_0 = (1 << 25),
84  XFSEL_1 = (1 << 26),
85  XFSEL_2 = (1 << 29),
86 };
87 
88 //------------------------------------------------------------------------------
89 
91 #define NUM_FPGAS 3
92 
95  FPGA_READ = 0,
96  FPGA_WRITE = 1
97 };
98 
99 //------------------------------------------------------------------------------
102 
105  CMD_VER = 0,
106  CMD_RUN = 1,
107  CMD_READ = 2,
108  CMD_WRITE = 3,
109  CMD_FILL = 5,
110 
113 
114  CMD_LED = 25,
115  CMD_IPTAG = 26,
116 
121 // CMD_XXX_52 = 52, //!< Unimplemented
122  CMD_BMP_SF = 53,
123  CMD_BMP_EE = 54,
124  CMD_RESET = 55,
125  CMD_XILINX = 56,
126  CMD_POWER = 57,
127 
128  CMD_BMP_I2C = 61,
129  CMD_BMP_PWM = 62,
130 // CMD_BMP_TEST = 63, //!< Test (unimplemented)
131 
132  CMD_TUBE = 64
133 };
134 
137  TYPE_BYTE = 0,
138  TYPE_HALF = 1,
139  TYPE_WORD = 2
140 };
141 
144  RC_OK = 0x80,
145  RC_LEN = 0x81,
146  RC_SUM = 0x82,
147  RC_CMD = 0x83,
148  RC_ARG = 0x84,
149  RC_PORT = 0x85,
150  RC_TIMEOUT = 0x86,
151  RC_ROUTE = 0x87,
152  RC_CPU = 0x88
153 };
154 
155 #define BOARD_MASK 31
156 
157 #define FLASH_BYTES 4096
158 #define FLASH_WORDS 1024
160 
163 
166  IPTAG_NEW = 0,
167  IPTAG_SET = 1,
168  IPTAG_GET = 2,
169  IPTAG_CLR = 3,
170  IPTAG_TTO = 4
171 };
172 
174 #define IPTAG_MAX 4
175 
178  IPTAG_VALID = 0x8000,
179  IPTAG_TRANS = 0x4000,
180  IPTAG_ARP = 0x2000
181 };
182 
183 #define TAG_NONE 255
184 #define TAG_HOST 0
185 
187 #define TAG_FIXED_SIZE 8 // At bottom of table
189 #define TAG_POOL_SIZE 8
191 #define FIRST_POOL_TAG TAG_FIXED_SIZE
193 #define LAST_POOL_TAG (TAG_FIXED_SIZE + TAG_POOL_SIZE - 1)
195 #define TAG_TABLE_SIZE (TAG_FIXED_SIZE + TAG_POOL_SIZE)
197 #define SDPF_REPLY 0x80
198 
200 typedef struct {
201  uint8_t ip[4];
202  uint8_t mac[6];
203  uint16_t port;
204  uint16_t timeout;
205  uint16_t flags;
206  uint32_t count;
207  uint32_t _PAD;
208 } iptag_t;
209 
211 //------------------------------------------------------------------------------
214 
216 #define PORT_SHIFT 5
218 #define PORT_MASK 7
220 #define BOARD_MASK 31
221 
223 #define PORT_ETH (7 << PORT_SHIFT) // Port 7
224 
226 #define SDP_BUF_SIZE 256
227 
228 // ------------------------------------------------------------------------
230 // ------------------------------------------------------------------------
235 
236 typedef struct sdp_msg { // SDP message (=292 bytes)
237  struct sdp_msg *next;
238  uint16_t length;
239  uint16_t checksum;
240 
241  // sdp_hdr_t
242 
243  uint8_t flags;
244  uint8_t tag;
245  uint8_t dest_port;
246  uint8_t srce_port;
247  uint16_t dest_addr;
248  uint16_t srce_addr;
249 
250  // cmd_hdr_t (optional)
251 
252  uint16_t cmd_rc;
253  uint16_t seq;
254  uint32_t arg1;
255  uint32_t arg2;
256  uint32_t arg3;
257 
258  // user data (optional)
259 
260  uint8_t data[SDP_BUF_SIZE];
261 
262  uint32_t _PAD; // Private padding
263 } sdp_msg_t;
264 
266 //------------------------------------------------------------------------------
267 
269 #define IO_STD ((char *) 0) // Stream numbers
271 #define IO_DBG ((char *) 1)
273 #define IO_LCD ((char *) 2)
275 #define IO_NULL ((char *) 3)
276 
281 #define LCD_POS(x, y) (0x80 + (y) * 64 + (x))
282 
283 //------------------------------------------------------------------------------
284 
285 #define FL_DIR_SIZE 16
286 
289  FL_BMP_IP = 1,
290  FL_SPIN_IP = 2,
291  FL_FPGA = 3,
292  FL_XREG = 4,
293 };
294 
296 typedef struct { // 128 bytes
297  uint8_t type;
298  uint8_t size;
299  uint16_t flags;
300  uint32_t time;
301  uint32_t crc;
302  uint32_t base;
303  uint32_t length;
304  uint32_t p0;
305  uint32_t p1;
306  uint32_t p2;
307  uint8_t data[96];
308 } fl_dir_t;
309 
311 typedef struct { // 256 bytes
312  uint8_t marker;
313  uint8_t sw_ver;
314  uint8_t hw_ver;
315  uint8_t frame_ID;
316 
317  uint32_t mod_date;
318  uint8_t gw_addr[4];
319  uint8_t flags;
320  uint8_t mask_bits;
321  uint8_t mac_byte;
322  uint8_t LCD_time;
323 
324  uint8_t __PAD1[16];
325 
326  int8_t warn_int[4];
327  int8_t shut_int[4];
328 
329  int8_t warn_ext[4];
330  int8_t shut_ext[4];
331 
332  uint8_t warn_fan[4];
333  uint8_t shut_fan[4];
334 
335  uint8_t warn_vlow[8];
336  uint8_t shut_vlow[8];
337 
338  uint8_t warn_vhigh[8];
339  uint8_t shut_vhigh[8];
340 
341  uint8_t __PAD2[164]; // 88
342  uint32_t CRC32;
343 } ee_data_t;
344 
346 typedef struct { // 48 bytes
347  uint16_t adc[8];
348  int16_t t_int[4];
349  int16_t t_ext[4];
350  uint16_t fan[4];
351  uint32_t warning;
352  uint32_t shutdown;
353 } board_stat_t;
354 
356 typedef struct { // 32 bytes
357  uint16_t flags;
358  uint8_t mac_addr[6];
359  uint8_t ip_addr[4];
360  uint8_t gw_addr[4];
361  uint8_t net_mask[4];
362  uint16_t udp_port;
363  uint16_t __PAD1;
364  uint32_t __PAD2;
365  uint32_t __PAD3;
366 } ip_data_t;
367 
368 //------------------------------------------------------------------------------
369 
372 
374 typedef void (*handler) (void);
376 typedef void (*proc4) (uint32_t, uint32_t, uint32_t, uint32_t);
378 typedef void (*main_proc) (void *, uint32_t, uint32_t, uint32_t);
379 
381 typedef struct {
382  uint32_t *stack_top; // 0
383  main_proc main;
384 
385  handler NMI; // 2
386  handler HardFault;
387  handler MemManage;
388  handler BusFault;
389  handler UsageFault;
390  handler Rsvd_7;
391  handler Rsvd_8;
392  handler Rsvd_9;
393  handler Rsvd_10;
394  handler SVC;
395  handler DebugMon;
396  handler Rsvd_13;
397  handler PendSV;
398  handler SysTickH;
399 
400  handler WDT; // 16
401  handler TIMER0;
402  handler TIMER1;
403  handler TIMER2;
404  handler TIMER3;
405  handler UART0;
406  handler UART1;
407  handler UART2;
408  handler UART3;
409  handler PWM1;
410  handler I2C0;
411  handler I2C1;
412  handler I2C2;
413  handler SPI;
414  handler SSP0;
415  handler SSP1;
416 
417  handler PLL0; // 32
418  handler RTC;
419  handler EINT0;
420  handler EINT1;
421  handler EINT2;
422  handler EINT3;
423  handler ADC;
424  handler BOD;
425  handler USB;
426  handler CAN;
427  handler DMA;
428  handler I2S;
429  handler ENET;
430  handler RIT;
431  handler MCPWM;
432  handler QEI;
433 
434  handler PLL1; // 48
435  handler USBActivity;
436  handler CANActivity;
437 
438  handler Rsvd_51; // 51
439  handler Rsvd_52;
440 
441  uint32_t build_date; // 53
442  uint32_t sw_ver;
443 
444  uint32_t RO_length; // 55
445  uint32_t RW_length;
446  uint32_t *RO_limit;
447  uint32_t *RW_base;
448  uint32_t *RW_limit;
449  uint32_t *ZI_base;
450  uint32_t *ZI_limit;
451  uint32_t *stack_base;
452  uint32_t *stack_limit; // 63
453 } cortex_vec_t;
454 
456 typedef struct {
457  uint32_t *stack_top;
460  proc4 Rsvd_3; // 3: reserved
461  proc4 Rsvd_4; // 4: reserved
462  uint32_t build_date;
463  uint32_t sw_ver;
464  uint32_t checksum;
465 } boot_vec_t;
466 
468 static boot_vec_t * const boot_vec = (boot_vec_t *) 0;
469 
470 extern cortex_vec_t *cortex_vec;
471 
473 //------------------------------------------------------------------------------
474 
479  PROC_LED = 2
480 };
481 
482 //------------------------------------------------------------------------------
483 
485 static fl_dir_t *const fl_dir = (fl_dir_t *) 0x1000;
487 static ip_data_t *const bmp_flash_ip = (ip_data_t *) 0x1020;
489 static ip_data_t *const spin_flash_ip = (ip_data_t *) 0x10a0;
490 
494 typedef void (*LPC_IAP) (uint32_t *cmd, uint32_t *res);
495 
498 static LPC_IAP const lpc_iap = (LPC_IAP) 0x1fff1ff1;
499 
502 
503 static uint32_t * const flash_buf = (uint32_t *) 0x10000000;
504 
506 #define UNI_VEC_SIZE 8
507 
520 static uint32_t * const uni_vec = (uint32_t *) 0x10001000;
521 
523 #define DBG_VEC_SIZE 16
524 
544 static uint32_t * const dbg_vec = (uint32_t *) 0x10001020;
545 
546 //------------------------------------------------------------------------------
549 
551 typedef void (*event_proc) (uint32_t, uint32_t);
552 
553 struct event_t;
554 typedef struct event_t event_t;
556 struct event_t {
558  uint32_t arg1;
559  uint32_t arg2;
560  uint32_t time;
561  uint32_t ID;
563 };
564 
565 void event_init (uint32_t priority);
566 event_t* event_new (event_proc proc, uint32_t a1, uint32_t a2);
567 
568 void event_set_byte (uint32_t addr, uint32_t data);
569 
570 void event_schedule (event_t *e, uint32_t t);
571 void event_cancel (event_t *e, uint32_t ID);
572 
573 void proc_queue_add (event_t *e);
574 void proc_queue_run (void);
575 
577 //------------------------------------------------------------------------------
578 #if 0 // DKF: Not used, not implemented
581 
582 void heap_init (char *base, char *top);
583 void *bmp_malloc (uint32_t size);
584 
586 #endif
587 //------------------------------------------------------------------------------
590 
591 void configure_i2c (void);
592 
593 uint32_t i2c_poll (LPC_I2C_TypeDef *restrict i2c, uint32_t ctrl);
594 
595 uint32_t i2c_receive (LPC_I2C_TypeDef *restrict i2c, uint32_t ctrl,
596  uint32_t addr, uint32_t length, void *buf);
597 
598 uint32_t i2c_send (LPC_I2C_TypeDef *restrict i2c, uint32_t ctrl,
599  uint32_t addr, uint32_t length, const void *buf);
600 
601 int16_t read_ts (LPC_I2C_TypeDef *restrict i2c, uint32_t addr);
602 
603 uint32_t read_ee (uint32_t addr, uint32_t count, void *buf);
604 
605 uint32_t write_ee (uint32_t addr, uint32_t count, const void *buf);
606 
607 void configure_lcd (void);
608 void lcd_ctrl (uint32_t c);
609 void lcd_putc (uint32_t c);
610 
612 //------------------------------------------------------------------------------
615 
616 void clock_div (uint32_t bit_pos, uint32_t value);
617 
618 void delay_us (uint32_t n);
619 void delay_ms (uint32_t n);
620 
621 void configure_hw (void);
622 void read_adc (void);
623 void read_temp (void);
624 void read_fans (void);
625 
626 void set_power (uint32_t state);
627 
628 void reset_spin (uint32_t code);
629 
630 void fpga_reset (uint32_t code);
631 uint32_t fpga_init (uint32_t mask);
632 
633 void refresh_wdt (void);
634 
635 void led_set (uint32_t leds);
636 
637 void ssp0_pins (uint32_t on);
638 
639 uint32_t cpu_int_off (void);
640 void cpu_int_restore (uint32_t cpsr);
641 
642 #if 0
643 void die(uint32_t code) NORETURN;
644 #endif
645 
647 //------------------------------------------------------------------------------
650 
651 uint32_t is_blank (const void *buf, uint32_t len);
652 uint32_t flash_sector (uint32_t addr);
653 uint32_t flash_write (uint32_t addr, uint32_t length, const uint32_t *buffer);
654 uint32_t flash_erase (uint32_t start, uint32_t end);
655 
657 //------------------------------------------------------------------------------
660 
661 void configure_clocks (void);
662 
664 //------------------------------------------------------------------------------
667 
668 void flash_buf_init (void);
669 
670 void proc_power (uint32_t arg1, uint32_t arg2);
671 void proc_reset (uint32_t arg1, uint32_t arg2);
672 void proc_led (uint32_t arg1, uint32_t arg2);
673 
674 uint32_t debug (sdp_msg_t *);
675 
677 //------------------------------------------------------------------------------
680 
681 void eth_receive (void);
682 void copy_ip_data (void);
683 void iptag_timer (void);
684 void copy_ip (const uint8_t *restrict f, uint8_t *restrict t);
685 void arp_lookup (iptag_t *iptag);
686 uint32_t iptag_new (void);
687 
688 //------------------------------------------------------------------------------
689 
690 void msg_init (void);
691 sdp_msg_t* msg_get (void);
692 uint32_t msg_queue_size (void);
693 uint32_t msg_queue_insert (sdp_msg_t *msg);
695 void route_msg (sdp_msg_t * msg);
696 
698 //------------------------------------------------------------------------------
701 
702 uint32_t eth_rx_rdy (void);
703 uint32_t eth_tx_rdy (void);
704 uint32_t eth_rx_size (void);
705 void eth_update_tx (void);
706 void eth_rx_discard (void);
707 void eth_copy_txbuf (uint32_t *buffer, uint32_t length);
708 void eth_copy_rxbuf (uint32_t *buffer, uint32_t length);
709 
710 void configure_eth (const uint8_t *mac_addr);
711 
713 //------------------------------------------------------------------------------
716 
717 void configure_can (uint32_t id);
718 uint32_t can_send_msg (uint32_t dest, sdp_msg_t *msg);
719 void can_timer (void);
720 void can_proc_cmd (uint32_t dest, uint32_t op, uint32_t arg1, uint32_t arg2);
721 
723 //------------------------------------------------------------------------------
726 
727 uint32_t crc32 (void *buf, uint32_t len, uint32_t crc);
728 uint32_t crc32_chk (void *buf, uint32_t len);
729 void crc32_buf (void *buf, uint32_t len);
730 
732 //------------------------------------------------------------------------------
735 
736 void io_printf (char *stream, char *f, ...);
737 
739 //------------------------------------------------------------------------------
742 
743 void configure_ssp (void);
744 
745 void ssp1_fast (void);
746 void ssp1_slow (void);
747 
748 void ssp0_read (uint32_t cmd, uint32_t addr, uint32_t len, uint8_t *buf);
749 void ssp0_write (uint32_t cmd, uint32_t addr, uint32_t len, const uint8_t *buf);
750 void ssp0_copy (uint32_t addr, uint32_t len);
751 
752 void ssp1_copy (uint32_t count, const uint8_t *buf);
753 
754 void sf_read (uint32_t addr, uint32_t len, uint8_t *buf);
755 void sf_write (uint32_t addr, uint32_t len, const uint8_t *buf);
756 uint32_t sf_crc32 (uint32_t addr, uint32_t len);
757 
758 void fpga_word (uint32_t addr, uint32_t fpga, uint32_t *buf, uint32_t dir);
759 
761 //------------------------------------------------------------------------------
762 
763 enum bmp_power_status_commands {
764  POWER_ON = 2,
765  POWER_OFF = 0,
766  POWER_SHUT = 1
767 };
768 
769 extern uint8_t can_ID;
770 extern uint8_t board_ID;
771 extern bool bp_ctrl;
772 extern bool fan_sense;
773 extern uint8_t power_state;
774 
775 extern ip_data_t spin_ip;
776 extern ip_data_t bmp_ip;
777 
780 #define CAN_SIZE 24
781 
782 extern uint8_t can_status[CAN_SIZE];
784 
785 extern ee_data_t ee_data;
786 
787 extern bool lcd_active;
788 
789 extern uint32_t boot_sec;
790 
791 extern uint32_t up_time;
792 
793 extern const uint8_t *can2board;
794 extern const uint8_t *board2can;
795 
796 extern bool data_ok;
797 
798 extern iptag_t tag_table[];
799 
800 extern const uint32_t hw_ver;
801 
802 //------------------------------------------------------------------------------
#define SDP_BUF_SIZE
Size of user data area of SDP message.
Definition: bmp.h:226
void proc_power(uint32_t arg1, uint32_t arg2)
Control power for this board; calls set_power() (and sf_scan() and reset_spin() if powering on)
Definition: bmp_cmd.c:444
uint16_t dest_addr
SDP destination address.
Definition: bmp.h:247
void ssp0_copy(uint32_t addr, uint32_t len)
Copy from Serial Flash on SSP0 to FPGA(s) on SSP1.
Definition: bmp_ssp.c:249
bmp_iptag_flags
Flags on IPTags.
Definition: bmp.h:177
@ IPTAG_ARP
Awaiting ARP resolution.
Definition: bmp.h:180
@ IPTAG_VALID
Entry is valid.
Definition: bmp.h:178
@ IPTAG_TRANS
Entry is transient.
Definition: bmp.h:179
bmp_proc_opcodes
Commands that can be invoked over CAN.
Definition: bmp.h:476
@ PROC_LED
proc_led()
Definition: bmp.h:479
@ PROC_POWER
proc_power()
Definition: bmp.h:478
@ PROC_RESET
proc_reset()
Definition: bmp.h:477
void sf_read(uint32_t addr, uint32_t len, uint8_t *buf)
Read from flash.
Definition: bmp_ssp.c:317
void eth_rx_discard(void)
Discard received packet, releasing buffer for reuse.
Definition: bmp_eth.c:108
void sf_write(uint32_t addr, uint32_t len, const uint8_t *buf)
Write to flash.
Definition: bmp_ssp.c:287
uint8_t tag
SDP IPtag.
Definition: bmp.h:244
uint32_t * stack_top
Stack top.
Definition: bmp.h:457
void(* event_proc)(uint32_t, uint32_t)
The type of an event handler.
Definition: bmp.h:551
uint32_t mod_date
4: Date written
Definition: bmp.h:317
void can_timer(void)
This is called every 10ms on all boards.
Definition: bmp_can.c:763
uint16_t udp_port
UDP port.
Definition: bmp.h:362
uint32_t crc32(void *buf, uint32_t len, uint32_t crc)
Compute CRC32 for a buffer of given length.
Definition: bmp_crc.c:88
uint32_t sf_crc32(uint32_t addr, uint32_t len)
Compute CRC of data on flash.
Definition: bmp_ssp.c:326
bool lcd_active
Whether the LCD is active; if not, nothing should be sent to the LCD.
Definition: bmp_i2c.c:49
void read_fans(void)
Count transitions on the fan sensor inputs.
Definition: bmp_hw.c:884
uint32_t arg3
Arg 3.
Definition: bmp.h:256
cortex_vec_t * cortex_vec
Cortex boot vector.
Definition: bmp_main.c:55
void read_adc(void)
Read voltage from an ADC (directly into board_stat_t::adc) and start the read of the next ADC.
Definition: bmp_hw.c:475
uint16_t port
UDP port of target.
Definition: bmp.h:203
uint32_t flash_write(uint32_t addr, uint32_t length, const uint32_t *buffer)
Write to flash from supplied buffer. Only writes one sector.
Definition: bmp_flash.c:114
uint32_t boot_sec
Boot block number.
Definition: bmp_main.c:54
uint16_t timeout
Timeout (in 10ms ticks)
Definition: bmp.h:204
uint32_t is_blank(const void *buf, uint32_t len)
Check if an area of memory is blank (filled with 0xFF)
Definition: bmp_flash.c:48
uint32_t i2c_poll(LPC_I2C_TypeDef *restrict i2c, uint32_t ctrl)
Poll an I2C port.
Definition: bmp_i2c.c:87
void(* handler)(void)
Type of an interrupt handler.
Definition: bmp.h:374
void configure_i2c(void)
Set up I2C0 and I2C2 - 25MHz PCLK.
Definition: bmp_i2c.c:59
iptag_t tag_table[]
The table of IPTags.
Definition: bmp_net.c:166
proc4 flash_copy
Flash copy.
Definition: bmp.h:459
void event_set_byte(uint32_t addr, uint32_t data)
Set a byte at an address.
Definition: bmp_event.c:54
void copy_ip_data(void)
Copy IP address data from Flash (bmp_flash_ip and spin_flash_ip)
Definition: bmp_net.c:879
uint32_t flash_sector(uint32_t addr)
Convert flash address to sector number (LPC17xx specific)
Definition: bmp_flash.c:67
uint8_t board_ID
Board ID (devived from can_ID)
Definition: bmp_hw.c:254
static ip_data_t *const bmp_flash_ip
Address in Flash of BMP IP address.
Definition: bmp.h:487
uint16_t checksum
checksum (if used)
Definition: bmp.h:239
void arp_lookup(iptag_t *iptag)
Request an ARP lookup.
Definition: bmp_net.c:812
static ip_data_t *const spin_flash_ip
Address in Flash of SpiNNaker base IP address.
Definition: bmp.h:489
sdp_msg_t * msg_queue_remove(void)
Get a message from the head of the message queue and remove it from the queue.
Definition: bmp_net.c:270
bmp_fl_dir_type
Values in fl_dir->type.
Definition: bmp.h:288
uint32_t fpga_init(uint32_t mask)
Initialise FPGAs.
Definition: bmp_hw.c:396
uint32_t build_date
Build date.
Definition: bmp.h:462
static uint32_t *const uni_vec
32 byte (8 word) uninitialised vector
Definition: bmp.h:520
void reset_spin(uint32_t code)
Resets SpiNNaker by raising/lowering POR and switching the Serial Flash multiplexer as needed when PO...
Definition: bmp_hw.c:824
void ssp0_pins(uint32_t on)
Set up GPIO pins that talk to Flash.
Definition: bmp_hw.c:684
uint32_t read_ee(uint32_t addr, uint32_t count, void *buf)
Read from EEPROM.
Definition: bmp_i2c.c:234
uint32_t CRC32
252: CRC
Definition: bmp.h:342
void iptag_timer(void)
IPTag timeout tick. Called from proc_100hz() every 10ms.
Definition: bmp_net.c:355
uint32_t i2c_receive(LPC_I2C_TypeDef *restrict i2c, uint32_t ctrl, uint32_t addr, uint32_t length, void *buf)
Receive a buffer over I2C.
Definition: bmp_i2c.c:164
uint32_t count
Count of messages sent via IPTag.
Definition: bmp.h:206
uint32_t arg1
First arg to proc.
Definition: bmp.h:558
uint8_t marker
0: == 0x96
Definition: bmp.h:312
ip_data_t bmp_ip
Our own IP address.
Definition: bmp_net.c:188
uint16_t length
length
Definition: bmp.h:238
void led_set(uint32_t leds)
Control the LEDs.
Definition: bmp_hw.c:350
uint32_t sw_ver
Software version.
Definition: bmp.h:463
#define CAN_SIZE
Number of boards that can be managed over the CAN bus.
Definition: bmp.h:780
void delay_ms(uint32_t n)
Delay using a busy loop.
Definition: bmp_hw.c:978
uint16_t flags
Miscellaneous flags.
Definition: bmp.h:357
void proc_queue_add(event_t *e)
Adds an event to a list of events which can (all) be executed at some later time.
Definition: bmp_event.c:83
bmp_led_code
Encoding of LED control bits.
Definition: bmp.h:64
@ LED_2
Red.
Definition: bmp.h:67
@ LED_1
Orange.
Definition: bmp.h:66
@ LED_3
Green.
Definition: bmp.h:68
@ LED_0
Green.
Definition: bmp.h:65
@ LED_5
Green.
Definition: bmp.h:70
@ LED_7
Red.
Definition: bmp.h:72
@ LED_4
Green.
Definition: bmp.h:69
@ LED_6
Green.
Definition: bmp.h:71
board_stat_t board_stat[CAN_SIZE]
Board status.
Definition: bmp_hw.c:248
bool data_ok
Data sector CRC OK.
Definition: bmp_main.c:53
bmp_gpio_bits
Miscellaneous GPIO bits.
Definition: bmp.h:80
@ XFSEL_2
Port 4.
Definition: bmp.h:85
@ XFSEL_1
Port 3.
Definition: bmp.h:84
@ XFSEL_0
Port 3.
Definition: bmp.h:83
event_t * next
Next in Q or NULL.
Definition: bmp.h:562
bmp_return_code
SDP return codes.
Definition: bmp.h:143
@ RC_CMD
Bad/invalid command.
Definition: bmp.h:147
@ RC_TIMEOUT
Timeout.
Definition: bmp.h:150
@ RC_ARG
Invalid arguments.
Definition: bmp.h:148
@ RC_ROUTE
No P2P route.
Definition: bmp.h:151
@ RC_SUM
Bad checksum.
Definition: bmp.h:146
@ RC_CPU
Bad CPU number.
Definition: bmp.h:152
@ RC_OK
Command completed OK.
Definition: bmp.h:144
@ RC_PORT
Bad port number.
Definition: bmp.h:149
@ RC_LEN
Bad packet length.
Definition: bmp.h:145
uint32_t can_send_msg(uint32_t dest, sdp_msg_t *msg)
Send an SDP message over the CAN.
Definition: bmp_can.c:370
uint8_t frame_ID
3: Frame Identifier
Definition: bmp.h:315
const uint8_t * can2board
Mapping from CAN ID to board number.
Definition: bmp_hw.c:266
void copy_ip(const uint8_t *restrict f, uint8_t *restrict t)
Copy IP address.
Definition: bmp_net.c:331
uint8_t flags
SDP flag byte.
Definition: bmp.h:243
uint8_t LCD_time
15: Time (secs) for initial display
Definition: bmp.h:322
void fpga_reset(uint32_t code)
Reset the FPGAs.
Definition: bmp_hw.c:378
void flash_buf_init(void)
Initialise flash_buf.
Definition: bmp_cmd.c:117
void cpu_int_restore(uint32_t cpsr)
Restore interrupts.
Definition: bmp_hw.c:288
uint32_t msg_queue_insert(sdp_msg_t *msg)
Insert a message in the message queue.
Definition: bmp_net.c:246
void configure_lcd(void)
Configure the LCD.
Definition: bmp_i2c.c:281
uint32_t checksum
Checksum.
Definition: bmp.h:464
void read_temp(void)
Read I2C temperature sensors and also compute the fan speed.
Definition: bmp_hw.c:910
void eth_copy_rxbuf(uint32_t *buffer, uint32_t length)
Copy received message into supplied buffer.
Definition: bmp_eth.c:137
uint8_t can_ID
CAN ID (from backplane)
Definition: bmp_hw.c:253
void crc32_buf(void *buf, uint32_t len)
Compute and insert CRC32 of a buffer where the CRC is placed in the last 4 bytes.
Definition: bmp_crc.c:119
uint8_t power_state
Power supply state.
Definition: bmp_hw.c:258
uint32_t debug(sdp_msg_t *)
SDP message dispatcher.
Definition: bmp_cmd.c:824
uint32_t msg_queue_size(void)
How big is the message queue?
Definition: bmp_net.c:284
uint32_t iptag_new(void)
Allocate a transient IPTag.
Definition: bmp_net.c:372
static LPC_IAP const lpc_iap
LPC17xx In Application Programming entry point.
Definition: bmp.h:498
void event_init(uint32_t priority)
Initialise the event processing system.
Definition: bmp_event.c:62
bmp_commands
Commands supported by the BMP.
Definition: bmp.h:104
@ CMD_FLASH_WRITE
Write Flash.
Definition: bmp.h:120
@ CMD_FLASH_ERASE
Erase Flash.
Definition: bmp.h:119
@ CMD_BMP_EE
Access EEPROM.
Definition: bmp.h:123
@ CMD_FPGA_READ
Read FPGA memory.
Definition: bmp.h:111
@ CMD_LED
Control LEDs.
Definition: bmp.h:114
@ CMD_READ
Read memory.
Definition: bmp.h:107
@ CMD_POWER
Control board power.
Definition: bmp.h:126
@ CMD_RUN
Run.
Definition: bmp.h:106
@ CMD_VER
Get BMP version.
Definition: bmp.h:105
@ CMD_XILINX
Access XILINX.
Definition: bmp.h:125
@ CMD_WRITE
Write memory.
Definition: bmp.h:108
@ CMD_FLASH_COPY
Copy Flash.
Definition: bmp.h:118
@ CMD_FPGA_WRITE
Write FPGA memory.
Definition: bmp.h:112
@ CMD_BMP_SF
Access Boot Flash.
Definition: bmp.h:122
@ CMD_BMP_INFO
Get BMP information.
Definition: bmp.h:117
@ CMD_BMP_PWM
Configure PWM.
Definition: bmp.h:129
@ CMD_FILL
Fill memory.
Definition: bmp.h:109
@ CMD_BMP_I2C
Access I2C bus.
Definition: bmp.h:128
@ CMD_IPTAG
Control IPTags.
Definition: bmp.h:115
@ CMD_RESET
Reset boards.
Definition: bmp.h:124
@ CMD_TUBE
tubotron: outbound message
Definition: bmp.h:132
uint32_t crc32_chk(void *buf, uint32_t len)
Compute the CRC of a buffer.
Definition: bmp_crc.c:103
uint32_t arg2
Second arg to proc.
Definition: bmp.h:559
uint8_t sw_ver
1: EE Data format version
Definition: bmp.h:313
int16_t read_ts(LPC_I2C_TypeDef *restrict i2c, uint32_t addr)
Read temperature sensor.
Definition: bmp_i2c.c:217
void msg_init(void)
Initialise the message queue.
Definition: bmp_net.c:195
uint32_t warning
Warning flags.
Definition: bmp.h:351
ee_data_t ee_data
Copy of EEPROM data.
Definition: bmp_hw.c:260
bmp_iptag_commands
Subcommands for manipulating IPTags.
Definition: bmp.h:165
@ IPTAG_TTO
Set IPTag timeout (common)
Definition: bmp.h:170
@ IPTAG_SET
Configure existing IPTag.
Definition: bmp.h:167
@ IPTAG_NEW
Allocate and configure IPTag.
Definition: bmp.h:166
@ IPTAG_GET
Read IPTag status.
Definition: bmp.h:168
@ IPTAG_CLR
Deallocate all IPTags.
Definition: bmp.h:169
bmp_fpga_command
Directions for fpga_word()
Definition: bmp.h:94
@ FPGA_READ
Read from FPGA.
Definition: bmp.h:95
@ FPGA_WRITE
Write to FPGA.
Definition: bmp.h:96
uint32_t eth_tx_rdy(void)
Is the ethernet hardware ready to transmit?
Definition: bmp_eth.c:90
void proc_reset(uint32_t arg1, uint32_t arg2)
Board reset handler; calls reset_spin()
Definition: bmp_cmd.c:401
void event_cancel(event_t *e, uint32_t ID)
Cancel an event that was previously scheduled.
Definition: bmp_event.c:195
uint8_t dest_port
SDP destination port/CPU.
Definition: bmp.h:245
void configure_ssp(void)
Configure SSP (serial flash, FPGAs)
Definition: bmp_ssp.c:371
const uint8_t * board2can
Mapping from board number to CAN ID.
Definition: bmp_hw.c:268
bmp_type_code
Data transfer unit.
Definition: bmp.h:136
@ TYPE_BYTE
Transfer by bytes.
Definition: bmp.h:137
@ TYPE_HALF
Transfer by half-words.
Definition: bmp.h:138
@ TYPE_WORD
Transfer by words.
Definition: bmp.h:139
uint32_t ID
Unique ID for active event (0 if inactive)
Definition: bmp.h:561
void ssp0_read(uint32_t cmd, uint32_t addr, uint32_t len, uint8_t *buf)
Read buffer from Serial Flash.
Definition: bmp_ssp.c:210
void eth_receive(void)
Receive a packet off the ethernet hardware.
Definition: bmp_net.c:636
static uint32_t *const flash_buf
4096 byte buffer used for writing to Flash and as a general purpose buffer
Definition: bmp.h:503
void lcd_putc(uint32_t c)
Write a character to the LCD. Buffers.
Definition: bmp_i2c.c:310
uint8_t hw_ver
2: Backplane HW version (0..7)
Definition: bmp.h:314
void proc_queue_run(void)
Execute a list of events (in the order in which they were added to the list).
Definition: bmp_event.c:102
void configure_hw(void)
Configure the BMP hardware.
Definition: bmp_hw.c:1188
void route_msg(sdp_msg_t *msg)
Route a message to its destination.
Definition: bmp_net.c:782
uint8_t mask_bits
13: IP mask bits (0..31)
Definition: bmp.h:320
void ssp1_slow(void)
Configure SSP1 to be slow.
Definition: bmp_ssp.c:349
void eth_copy_txbuf(uint32_t *buffer, uint32_t length)
Copy supplied buffer into transmit hardware.
Definition: bmp_eth.c:122
bool bp_ctrl
Backplane controller.
Definition: bmp_hw.c:255
uint32_t write_ee(uint32_t addr, uint32_t count, const void *buf)
Write to EEPROM.
Definition: bmp_i2c.c:252
uint32_t eth_rx_size(void)
Get size of received data.
Definition: bmp_eth.c:149
void ssp1_fast(void)
Configure SSP1 to be fast.
Definition: bmp_ssp.c:359
uint8_t flags
12: 8 flag bits
Definition: bmp.h:319
void refresh_wdt(void)
Refresh the watchdog timer so that the watchdog doesn't bark.
Definition: bmp_hw.c:508
bool fan_sense
Compute fan speed.
Definition: bmp_hw.c:256
uint8_t srce_port
SDP source port/CPU.
Definition: bmp.h:246
void event_schedule(event_t *e, uint32_t t)
Schedules an event to occur some time in the future.
Definition: bmp_event.c:279
void io_printf(char *stream, char *f,...)
Print to an output stream.
Definition: bmp_io.c:266
ip_data_t spin_ip
IP address of the board we manage.
Definition: bmp_net.c:186
void configure_clocks(void)
Configure the clocks.
Definition: bmp_clock.c:192
void configure_can(uint32_t id)
Initialises the CAN controller.
Definition: bmp_can.c:881
uint8_t can_status[CAN_SIZE]
Whether a particular board is talking to the CAN bus.
Definition: bmp_can.c:142
uint32_t cpu_int_off(void)
Disable interrupts.
Definition: bmp_hw.c:279
void ssp0_write(uint32_t cmd, uint32_t addr, uint32_t len, const uint8_t *buf)
Write buffer to Serial Flash.
Definition: bmp_ssp.c:167
void(* proc4)(uint32_t, uint32_t, uint32_t, uint32_t)
Type of a function that takes four arguments.
Definition: bmp.h:376
event_proc proc
Proc to be called or NULL.
Definition: bmp.h:557
static boot_vec_t *const boot_vec
Boot vector.
Definition: bmp.h:468
void(* LPC_IAP)(uint32_t *cmd, uint32_t *res)
LPC17xx In-Application Programming entry point.
Definition: bmp.h:494
uint32_t shutdown
Shutdown flags.
Definition: bmp.h:352
static fl_dir_t *const fl_dir
Address in Flash of Flash directory.
Definition: bmp.h:485
uint16_t flags
Flags (bmp_iptag_flags)
Definition: bmp.h:205
void configure_eth(const uint8_t *mac_addr)
Configure the ethernet hardware.
Definition: bmp_eth.c:197
uint32_t i2c_send(LPC_I2C_TypeDef *restrict i2c, uint32_t ctrl, uint32_t addr, uint32_t length, const void *buf)
Send a buffer over I2C.
Definition: bmp_i2c.c:114
void clock_div(uint32_t bit_pos, uint32_t value)
Configure clock division.
Definition: bmp_hw.c:300
uint32_t arg1
Arg 1.
Definition: bmp.h:254
void eth_update_tx(void)
Select the next transmission buffer.
Definition: bmp_eth.c:97
uint32_t eth_rx_rdy(void)
Is the ethernet hardware ready to receive?
Definition: bmp_eth.c:82
void proc_led(uint32_t arg1, uint32_t arg2)
Control the LEDs on this board; call led_set()
Definition: bmp_cmd.c:372
sdp_msg_t * msg_get(void)
"Allocate" a message from the free message pool
Definition: bmp_net.c:209
uint32_t arg2
Arg 2.
Definition: bmp.h:255
uint32_t time
Time (CPU ticks) until event due (0 if at head of Q)
Definition: bmp.h:560
struct sdp_msg * next
Next in free list.
Definition: bmp.h:237
uint16_t cmd_rc
Command/Return Code.
Definition: bmp.h:252
void fpga_word(uint32_t addr, uint32_t fpga, uint32_t *buf, uint32_t dir)
Read or write an FPGA.
Definition: bmp_ssp.c:77
void can_proc_cmd(uint32_t dest, uint32_t op, uint32_t arg1, uint32_t arg2)
Asks another BMP to run a proc from proc_list.
Definition: bmp_can.c:746
const uint32_t hw_ver
Hardware version.
Definition: bmp_hw.c:270
uint16_t seq
Sequence number.
Definition: bmp.h:253
event_t * event_new(event_proc proc, uint32_t a1, uint32_t a2)
Allocates a new event.
Definition: bmp_event.c:242
void set_power(uint32_t state)
Turn board off or on.
Definition: bmp_hw.c:316
void lcd_ctrl(uint32_t c)
Write a control byte to the LCD.
Definition: bmp_i2c.c:299
void ssp1_copy(uint32_t count, const uint8_t *buf)
Copy buffer to FPGAs.
Definition: bmp_ssp.c:58
uint32_t flash_erase(uint32_t start, uint32_t end)
Erase sectors given start and end (byte) addresses.
Definition: bmp_flash.c:83
void(* main_proc)(void *, uint32_t, uint32_t, uint32_t)
Type of a main entry point.
Definition: bmp.h:378
void delay_us(uint32_t n)
Delay using a busy loop.
Definition: bmp_hw.c:968
uint8_t mac_byte
14: Byte 1 of MAC address
Definition: bmp.h:321
handler boot_proc
Boot handler.
Definition: bmp.h:458
static uint32_t *const dbg_vec
64 byte (16 word) uninitialised fault debug vector
Definition: bmp.h:544
uint16_t srce_addr
SDP source address.
Definition: bmp.h:248
Board status.
Definition: bmp.h:346
Boot vector.
Definition: bmp.h:456
Cortex master vector.
Definition: bmp.h:381
Data read from EEPROM.
Definition: bmp.h:311
Record of how to handle an event.
Definition: bmp.h:556
Flash directory entry.
Definition: bmp.h:296
Information about an IP address.
Definition: bmp.h:356
IPTag entry (24 bytes)
Definition: bmp.h:200
SDP message type definition.
Definition: bmp.h:236
void die(uint32_t code)
Curl up and die (probably because of hardware failure or misconfiguration.
Definition: bmp_hw.c:946
static uint8_t fan
Current fan speed. 0 (off) .. 3 (high)
Definition: bmp_main.c:179