spinnaker_tools (BMP) latest
SpiNNaker BMP firmware
Loading...
Searching...
No Matches
Macros | Functions | Variables
bmp_hw.c File Reference

Low-level hardware interface code for BMP LPC1768. More...

#include <string.h>
#include "lpc17xx.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_clkpwr.h"
#include "bmp.h"

Macros

#define ADC_PCLK   25000000
 25 MHz
 
#define ADC_CLK   13000000
 13 MHz
 
#define ADC_PDN   (1 << 21)
 
#define ADC_VALID   0xde
 Channels 0, 5 not used on Spin5.
 
#define SYSRAM_IP_DATA   0xf5007fe0
 System RAM IP address data.
 
Port 3
#define P3_EN   (XFSEL_0 + XFSEL_1)
 
#define P3_INIT   (XFSEL_0 + XFSEL_1)
 
Port 4
#define P4_EN   (XFSEL_2)
 
#define P4_INIT   (XFSEL_2)
 

Functions

uint32_t cpu_int_off (void)
 Disable interrupts.
 
void cpu_int_restore (uint32_t cpsr)
 Restore interrupts.
 
void clock_div (uint32_t bit_pos, uint32_t value)
 Configure clock division.
 
void set_power (uint32_t state)
 Turn board off or on.
 
void led_set (uint32_t leds)
 Control the LEDs.
 
void fpga_reset (uint32_t code)
 Reset the FPGAs.
 
uint32_t fpga_init (uint32_t mask)
 Initialise FPGAs.
 
static void configure_adc (void)
 Configure analog-to-digital converters for voltage monitoring.
 
void read_adc (void)
 Read voltage from an ADC (directly into board_stat_t::adc) and start the read of the next ADC.
 
static void configure_wdt (uint32_t period)
 Configure the watchdog timer.
 
void refresh_wdt (void)
 Refresh the watchdog timer so that the watchdog doesn't bark.
 
static void process_reset (void)
 Reset critical vectors and timers.
 
void configure_pwm (uint32_t period, uint32_t width)
 Configure pulse-width modulation hardware.
 
static void timer_init (LPC_TIM_TypeDef *timer, uint32_t channel, uint32_t value)
 Configure a timer.
 
static void configure_timers (void)
 Configure periodic timers.
 
static void set_pin_mf (uint32_t port, uint32_t pin, uint32_t mode, uint32_t function)
 Set pin mode and function.
 
static void set_pin_od (uint32_t port, uint32_t pin, uint32_t mode)
 Set pin operation: open-drain or normal.
 
static void config_pin (uint32_t port, uint32_t pin, uint32_t func)
 Set pin function.
 
void ssp0_pins (uint32_t on)
 Set up GPIO pins that talk to Flash.
 
static uint32_t configure_pins (void)
 Configure pins for talking to external peripherals.
 
void reset_spin (uint32_t code)
 Resets SpiNNaker by raising/lowering POR and switching the Serial Flash multiplexer as needed when POR falls.
 
static void configure_mcpwm (void)
 Set up a 300kHz 120 degree duty-cycle waveform on three outputs MC0B0, MC0B1, MC0B2 (NB outputs not enabled on Spin4)
 
void read_fans (void)
 Count transitions on the fan sensor inputs.
 
void read_temp (void)
 Read I2C temperature sensors and also compute the fan speed.
 
void die (uint32_t code)
 Curl up and die (probably because of hardware failure or misconfiguration.
 
void delay_us (uint32_t n)
 Delay using a busy loop.
 
void delay_ms (uint32_t n)
 Delay using a busy loop.
 
static void configure_spin (void)
 
void proc_setup (uint32_t d1, uint32_t d2)
 Set up networking. Handles remote request across CAN from BMP master.
 
void configure_hw (void)
 Configure the BMP hardware.
 

Variables

board_stat_t board_stat [CAN_SIZE]
 Board status.
 
static uint32_t adc_chan
 Current ADC channel (see read_adc())
 
uint8_t can_ID
 CAN ID (from backplane)
 
uint8_t board_ID
 Board ID (devived from can_ID)
 
bool bp_ctrl
 Backplane controller.
 
bool fan_sense
 Compute fan speed.
 
uint8_t power_state
 Power supply state.
 
ee_data_t ee_data
 Copy of EEPROM data.
 
uint32_t config1
 Argument d1 to pass to proc_setup()
 
uint32_t config2
 Argument d2 to pass to proc_setup()
 
const uint8_t * can2board
 Mapping from CAN ID to board number.
 
const uint8_t * board2can
 Mapping from board number to CAN ID.
 
const uint32_t hw_ver = 5
 Hardware version.
 
static const uint32_t led_bit []
 Mapping from LED index to GPIO pin flags.
 
static uint32_t fan_last [4]
 Last fan state.
 
static uint16_t fan_count [4]
 Fan rotation counter.
 
static const uint8_t can2board_0 []
 Default mapping from CAN ID to board number, for can2board.
 
static const uint8_t board2can_0 []
 Default mapping from board number to CAN ID, for board2can.
 
static const uint8_t null_map []
 Null mapping, used when not in a frame. One-to-one.
 
static const ee_data_t ee_default
 Default "EEPROM" data, when EEPROM fails.
 

Port 0

#define P0_EN   (SF_NCS + IO_EN1 + LED_MASK)
 
#define P0_INIT   (SF_NCS + IO_EN1 + LED_0)
 
enum  gpio_bits_port_0 { FAN_ED2 = (1 << 6) , IO_EN1 = (1 << 23) , I2C_SDA = (1 << 27) , I2C_SCL = (1 << 28) }
 

Port 1

#define P1_EN    (EN_V12 + EN_V18 + EN_VFPGA + XPROGB_0 + XPROGB_1 + XPROGB_2 + XIL_RST)
 
#define P1_INIT   (EN_V12 + EN_V18 + XPROGB_0 + XPROGB_1 + XPROGB_2)
 
enum  gpio_bits_port_1 {
  XIL_RST = (1 << 14) , EN_V12 = (1 << 18) , EN_V18 = (1 << 19) , EN_VFPGA = (1 << 20) ,
  XPROGB_0 = (1 << 21) , XPROGB_1 = (1 << 23) , XPROGB_2 = (1 << 24) , XDONE = (1 << 31)
}
 

Port 2

#define XINIT_B   (XINITB_0 + XINITB_1 + XINITB_2)
 
#define P2_EN    (BOOT_1 + POR + RST + IO_EN2 + IO_6 + IO_7 + IO_8 + IO_9)
 
#define P2_INIT   (IO_6 + IO_EN2)
 BootROM + serial + POST.
 
enum  gpio_bits_port_2 {
  BOOT_1 = (1 << 0) , IO_6 = (1 << 1) , IO_7 = (1 << 2) , IO_8 = (1 << 3) ,
  IO_9 = (1 << 4) , FAN_PWM = (1 << 5) , POR = (1 << 6) , RST = (1 << 7) ,
  FAN_ED0 = (1 << 8) , FAN_ED1 = (1 << 9) , IO_EN2 = (1 << 10) , XINITB_0 = (1 << 11) ,
  XINITB_1 = (1 << 12) , XINITB_2 = (1 << 13)
}
 

Detailed Description

Low-level hardware interface code for BMP LPC1768.

Author
Steve Temple, APT Group, School of Computer Science

Enumeration Type Documentation

◆ gpio_bits_port_0

Enumerator
I2C_SDA 

I2C data.

I2C_SCL 

I2C clock.

◆ gpio_bits_port_1

Enumerator
XIL_RST 

FPGA reset.

EN_VFPGA 

Enable FPGA.

◆ gpio_bits_port_2

Enumerator
BOOT_1 

GPIO[1].

IO_6 

GPIO[6].

IO_7 

GPIO[7].

FAN_PWM 

Fan pulse width modulation.

POR 

Power on reset.

RST 

Reset.

Function Documentation

◆ cpu_int_off()

uint32_t cpu_int_off ( void  )

Disable interrupts.

Returns
old CPSR state

◆ cpu_int_restore()

void cpu_int_restore ( uint32_t  cpsr)

Restore interrupts.

Parameters
[in]cpsrold CPSR state to restore

◆ clock_div()

void clock_div ( uint32_t  bit_pos,
uint32_t  value 
)

Configure clock division.

Parameters
bit_posthe bit position to configure
valuethe value of that bit

◆ set_power()

void set_power ( uint32_t  state)

Turn board off or on.

Parameters
[in]stateState to go into.

◆ led_set()

void led_set ( uint32_t  leds)

Control the LEDs.

Parameters
[in]ledsEncoded packed LED control word. Two bits per LED: 0 = ignore, 1 = toggle, 2 = turn off, 3 = turn on.

◆ fpga_reset()

void fpga_reset ( uint32_t  code)

Reset the FPGAs.

Parameters
[in]codeHow to do the reset. 0 = clear reset line, 1 = set reset line, 2 = cycle reset line

◆ fpga_init()

uint32_t fpga_init ( uint32_t  mask)

Initialise FPGAs.

Parameters
[in]maskWhich FPGAs to initialise
Returns
True if initalisation succeeded

◆ read_adc()

void read_adc ( void  )

Read voltage from an ADC (directly into board_stat_t::adc) and start the read of the next ADC.

This is called approx every 80ms from proc_100hz().

◆ configure_wdt()

static void configure_wdt ( uint32_t  period)
static

Configure the watchdog timer.

Parameters
[in]periodTimer period

◆ configure_pwm()

void configure_pwm ( uint32_t  period,
uint32_t  width 
)

Configure pulse-width modulation hardware.

Parameters
[in]periodOverall period
[in]widthPulse width. No longer than than period.

◆ timer_init()

static void timer_init ( LPC_TIM_TypeDef *  timer,
uint32_t  channel,
uint32_t  value 
)
static

Configure a timer.

Parameters
[in]timerThe timer to configure
[in]channelThe channel to put a timer on
[in]valueTimer match value

◆ set_pin_mf()

static void set_pin_mf ( uint32_t  port,
uint32_t  pin,
uint32_t  mode,
uint32_t  function 
)
static

Set pin mode and function.

Parameters
[in]portPort index
[in]pinPin number
[in]modeMode
[in]functionFunction

◆ set_pin_od()

static void set_pin_od ( uint32_t  port,
uint32_t  pin,
uint32_t  mode 
)
static

Set pin operation: open-drain or normal.

Parameters
[in]portPort index
[in]pinPin number
[in]modeMode

◆ config_pin()

static void config_pin ( uint32_t  port,
uint32_t  pin,
uint32_t  func 
)
static

Set pin function.

Parameters
[in]portPort index
[in]pinPin number
[in]funcFunction

◆ ssp0_pins()

void ssp0_pins ( uint32_t  on)

Set up GPIO pins that talk to Flash.

Parameters
[in]onTrue to enable

◆ configure_pins()

static uint32_t configure_pins ( void  )
static

Configure pins for talking to external peripherals.

GPIO, CAN, Serial Flash, LED, I2C, Ethernet, FPGA

Returns
our CAN ID

◆ reset_spin()

void reset_spin ( uint32_t  code)

Resets SpiNNaker by raising/lowering POR and switching the Serial Flash multiplexer as needed when POR falls.

Parameters
[in]codeHow to do the reset

code = 0 - lower POR (reset off) code = 1 - raise POR (reset on) code = 2 - pulse POR

If Bit 2 of code is set then the FPGAs are also reset

The Serial Flash is dual ported on Spin5 and the SpiNNaker root chip reads its IP address from it just after it is reset. The read takes about 12ms for the 'standard' IP address block of 32 bytes. If the Serial Flash is set up to contain more code, the delay of 20ms will need to be increased.

◆ read_fans()

void read_fans ( void  )

Count transitions on the fan sensor inputs.

This routine is called once per millisec and it's assumed that the fan speed is low enough for there to be no more than one transition per ms.

◆ read_temp()

void read_temp ( void  )

Read I2C temperature sensors and also compute the fan speed.

This routine is called once per second.

◆ die()

void die ( uint32_t  code)

Curl up and die (probably because of hardware failure or misconfiguration.

The top LED is turned on (Red on Spin5) and the code is put on the next 4 LEDs (Green on Spin5). The bottom 3 LEDs are turned off.

Parameters
[in]codeFailure code to indicate in LEDs

◆ delay_us()

void delay_us ( uint32_t  n)

Delay using a busy loop.

Parameters
[in]nHow many μs to delay for

◆ delay_ms()

void delay_ms ( uint32_t  n)

Delay using a busy loop.

Parameters
[in]nHow many milliseconds to delay for

◆ configure_spin()

static void configure_spin ( void  )
static

Copy the SpiNNaker IP address from buffer in memory (spin_ip) to the bottom of the serial Flash. The 32 bytes of data is padded with the necessary control codes to allow SpiNNaker to load the address block. The first 44 bytes of the serial Flash are used for this. The data is only updated if it is different from the buffer.

Word 12 is used to hold a count of the number of times the update has occurred. If more load blocks are needed this word can form the single entry in a dummy load block.

◆ proc_setup()

void proc_setup ( uint32_t  d1,
uint32_t  d2 
)

Set up networking. Handles remote request across CAN from BMP master.

Parameters
[in]d1Combined hardware version, count of zero IP netmask bits, and frame ID
[in]d2IP gateway address. (Local addresses derive from this, frame ID and board ID.)

Variable Documentation

◆ led_bit

const uint32_t led_bit[]
static
Initial value:
= {
}
@ 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

Mapping from LED index to GPIO pin flags.

◆ can2board_0

const uint8_t can2board_0[]
static
Initial value:
= {
0, 1, 2, 3, 4, 5, 0, 0,
6, 7, 8, 9, 10, 11, 0, 0,
12, 13, 14, 15, 16, 17, 0, 0,
18, 19, 20, 21, 22, 23, 0, 0
}

Default mapping from CAN ID to board number, for can2board.

◆ board2can_0

const uint8_t board2can_0[]
static
Initial value:
= {
0, 1, 2, 3, 4, 5,
8, 9, 10, 11, 12, 13,
16, 17, 18, 19, 20, 21,
24, 25, 26, 27, 28, 29
}

Default mapping from board number to CAN ID, for board2can.

◆ null_map

const uint8_t null_map[]
static
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31
}

Null mapping, used when not in a frame. One-to-one.

◆ ee_default

const ee_data_t ee_default
static
Initial value:
= {
0x96,
0,
0,
240,
0,
{192, 168, 240, 254},
0,
16,
0,
5,
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{65, 65, 0, 0},
{80, 80, 0, 0},
{50, 50, 0, 0},
{65, 65, 0, 0},
{50, 50, 50, 0},
{0, 0, 0, 0},
{114, 114, 114, 114, 166, 184, 203, 184},
{102, 102, 102, 102, 147, 164, 0, 0},
{140, 140, 140, 140, 203, 225, 248, 225},
{152, 152, 152, 152, 221, 246, 0, 0}
}

Default "EEPROM" data, when EEPROM fails.