fixes and updates after the mbed unit tests have been carried out.

pull/159/head
tkuyucu 2014-01-08 11:14:19 +01:00
parent eb5fd7d6e0
commit 694f9c726c
22 changed files with 282 additions and 236 deletions

View File

@ -100,8 +100,8 @@ NRF_POWER_RAMON_RAMxON_ONMODE_Msk EQU 0xF ; All RAM blocks on in onmod
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT EnableSoftDevice
IMPORT SystemInit
IMPORT EnableSoftDevice
IMPORT __main
LDR R0, =NRF_POWER_RAMON_ADDRESS
LDR R2, [R0]

View File

@ -37,11 +37,11 @@ static bool is_disabled_in_debug_needed(void);
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
#endif
static void softdevice_assertion_handler(uint32_t pc, uint16_t line_num, const uint8_t * file_name)
{
//static void softdevice_assertion_handler(uint32_t pc, uint16_t line_num, const uint8_t * file_name)
//{
// UNUSED_PARAMETER(pc);
// assert_nrf_callback(line_num, file_name);
}
//}
void SystemCoreClockUpdate(void)
@ -72,11 +72,21 @@ void SystemInit(void)
{
NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
}
// Start 16 MHz crystal oscillator.
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
// Wait for the external oscillator to start up.
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
{
// Do nothing.
}
}
void EnableSoftDevice(void)
{
sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, softdevice_assertion_handler);
// sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, softdevice_assertion_handler);
}
static bool is_manual_peripheral_setup_needed(void)

View File

@ -22,6 +22,10 @@
extern "C" {
#endif
#define STDIO_UART_TX TX_PIN_NUMBER
#define STDIO_UART_RX RX_PIN_NUMBER
#define STDIO_UART UART_0
typedef enum {
UART_0 = (int)NRF_UART0_BASE
} UARTName;
@ -33,10 +37,6 @@ typedef enum {
SPIS = (int)NRF_SPIS1_BASE
} SPIName;
#define STDIO_UART_TX TX_PIN_NUMBER
#define STDIO_UART_RX RX_PIN_NUMBER
#define STDIO_UART UART_0
typedef enum {
PWM_1 = 0,
PWM_2
@ -50,13 +50,7 @@ typedef enum {
typedef enum {
ADC0_0 = (int)NRF_ADC_BASE
} ADCName;
/*
typedef enum {
DAC_0 = 0
} DACName;
*/
#ifdef __cplusplus
}
#endif

View File

@ -63,6 +63,42 @@ typedef enum {
p30=30,
// p31=31,
P0_0 = p0,
P0_1 = p1,
P0_2 = p2,
P0_3 = p3,
P0_4 = p4,
P0_5 = p5,
P0_6 = p6,
P0_7 = p7,
P1_0 = p8,
P1_1 = p9,
P1_2 = p10,
P1_3 = p11,
P1_4 = p12,
P1_5 = p13,
P1_6 = p14,
P1_7 = p15,
P2_0 = p16,
P2_1 = p17,
P2_2 = p18,
P2_3 = p19,
P2_4 = p20,
P2_5 = p21,
P2_6 = p22,
P2_7 = p23,
P3_0 = p24,
P3_1 = p25,
P3_2 = p26,
P3_3 = p27,
P3_4 = p28,
P3_5 = p29,
P3_6 = p30,
//P3_7 = p31,
LED_START = p18,
LED_STOP = p19,
LED1 = LED_START,
@ -82,20 +118,20 @@ typedef enum {
USBTX = TX_PIN_NUMBER,
USBRX = RX_PIN_NUMBER,
SPI_PSELSCK0 = p25,
SPI_PSELMOSI0 = p20,
SPI_PSELMISO0 = p22,
SPI_PSELSS0 = p24,
SPI_PSELSCK0 = p25,
SPI_PSELMOSI1 = p12,
SPI_PSELMISO1 = p13,
SPI_PSELSS1 = p14,
SPI_PSELSCK1 = p15,
SPI_PSELSCK1 = p29,
SPI_PSELMOSI1 = p21,
SPI_PSELMISO1 = p23,
SPI_PSELSS1 = p28,
SPIS_PSELMISO = p12,
SPIS_PSELSS = p13,
SPIS_PSELMOSI = p14,
SPIS_PSELMOSI = p12,
SPIS_PSELMISO = p13,
SPIS_PSELSS = p14,
SPIS_PSELSCK = p15,
// Not connected

View File

@ -22,9 +22,7 @@
#define ADC_10BIT_RANGE 0x3FF
static inline int div_round_up(int x, int y) {
return (x + (y - 1)) / y;
}
#define ADC_RANGE ADC_10BIT_RANGE
static const PinMap PinMap_ADC[] = {
// {p26, ADC0_0, 1},
@ -38,15 +36,14 @@ static const PinMap PinMap_ADC[] = {
{NC , NC , 0}
};
#define ADC_RANGE ADC_10BIT_RANGE
void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (NRF_ADC_Type *) ((ADCName)pinmap_peripheral(pin, PinMap_ADC));
obj->adc = (ADCName)((NRF_ADC_Type *)pinmap_peripheral(pin, PinMap_ADC));
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
}
int analogInputPin=0;
PinMap *map = PinMap_ADC;
const PinMap *map = PinMap_ADC;
while (map->pin != NC) {
if (map->pin == pin){
analogInputPin = map->function;
@ -63,7 +60,6 @@ void analogin_init(analogin_t *obj, PinName pin) {
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
}
uint16_t analogin_read_u16(analogin_t *obj) {
NRF_ADC->TASKS_START = 1;
while (((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) >> ADC_BUSY_BUSY_Pos) == ADC_BUSY_BUSY_Busy)

View File

@ -51,8 +51,6 @@
#define DEVICE_STDIO_MESSAGES 0
//#define DEVICE_ERROR_RED 0
#include "objects.h"
#endif

View File

@ -25,15 +25,13 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
if(pin == NC) return;
obj->pin = pin;
obj->mask = (1<<pin);//gpio_set(pin);
obj->mask = (1<<pin);
unsigned int port = (unsigned int)pin/8;//(unsigned int)pin >> PORT_SHIFT;
// FGPIO_Type *reg = (FGPIO_Type *)(FPTA_BASE + port * 0x40);
obj->reg_set = &NRF_GPIO->OUTSET;// &reg->PSOR;
obj->reg_clr = &NRF_GPIO->OUTCLR;//&reg->PCOR;
obj->reg_in = &NRF_GPIO->IN;//&reg->PDIR;
obj->reg_dir = &NRF_GPIO->DIR;//&reg->PDDR;
unsigned int port = (unsigned int)pin/8;
obj->reg_set = &NRF_GPIO->OUTSET;
obj->reg_clr = &NRF_GPIO->OUTCLR;
obj->reg_in = &NRF_GPIO->IN;
obj->reg_dir = &NRF_GPIO->DIR;
gpio_dir(obj, direction);
switch (direction) {
@ -63,15 +61,4 @@ void gpio_dir(gpio_t *obj, PinDirection direction) {
break;
}
}
/*
void gpio_write(gpio_t *obj, int value) {
if (value)
*obj->reg_set = obj->mask;
else
*obj->reg_clr = obj->mask;
}
int gpio_read(gpio_t *obj) {
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}*/

View File

@ -27,48 +27,34 @@ static uint32_t portRISE= 0;
static uint32_t portFALL= 0;
static gpio_irq_handler irq_handler;
volatile uint32_t oldPortValue;
static int test=0;
void GPIOTE_IRQHandler(void)
{
volatile uint32_t newVal = NRF_GPIO->IN;
if ((NRF_GPIOTE->EVENTS_PORT != 0) && ((NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_PORT_Msk) != 0)){
//NRF_GPIOTE->INTENSET &= ~(GPIOTE_INTENSET_PORT_Enabled<<GPIOTE_INTENSET_PORT_Pos);
volatile uint32_t newVal = NRF_GPIO->IN;
if ((NRF_GPIOTE->EVENTS_PORT != 0) && ((NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_PORT_Msk) != 0)){
NRF_GPIOTE->EVENTS_PORT = 0;
for(uint8_t i=0;i<31;i++)
{
if(channel_ids[i]>0){
if((portRISE>>i)&1){
if(((newVal>>i)&1) && ((oldPortValue>>i)&1)==0 ){//
if(channel_enabled[i]){
irq_handler(channel_ids[i], IRQ_RISE);
}
NRF_GPIO->PIN_CNF[i] &= ~(GPIO_PIN_CNF_SENSE_Msk);
NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos) ;
}
else if(((newVal>>i)&1)==0 && ((NRF_GPIO->PIN_CNF[i] >>GPIO_PIN_CNF_SENSE_Pos)&GPIO_PIN_CNF_SENSE_Low) == GPIO_PIN_CNF_SENSE_Low){
NRF_GPIO->PIN_CNF[i] &= ~(GPIO_PIN_CNF_SENSE_Msk);
NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;
}
}
else if((portFALL>>i)&1){
if(((oldPortValue>>i)&1) && ((newVal>>i)&1)==0 ){
if(channel_enabled[i]){
if(channel_ids[i]>0){
if(channel_enabled[i]){
if(((newVal>>i)&1) && ((NRF_GPIO->PIN_CNF[i] >>GPIO_PIN_CNF_SENSE_Pos)&GPIO_PIN_CNF_SENSE_Low) != GPIO_PIN_CNF_SENSE_Low && (portRISE>>i)&1){
irq_handler(channel_ids[i], IRQ_RISE);
}
else if( ((newVal>>i)&1)==0&& ((NRF_GPIO->PIN_CNF[i] >>GPIO_PIN_CNF_SENSE_Pos)&GPIO_PIN_CNF_SENSE_Low) == GPIO_PIN_CNF_SENSE_Low && (portFALL>>i)&1){
irq_handler(channel_ids[i], IRQ_FALL);
}
NRF_GPIO->PIN_CNF[i] &= ~(GPIO_PIN_CNF_SENSE_Msk);
NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;
}
else if(((newVal>>i)&1) && ((NRF_GPIO->PIN_CNF[i] >>GPIO_PIN_CNF_SENSE_Pos)&GPIO_PIN_CNF_SENSE_Low) != GPIO_PIN_CNF_SENSE_Low){
NRF_GPIO->PIN_CNF[i] &= ~(GPIO_PIN_CNF_SENSE_Msk);
}
}
if(NRF_GPIO->PIN_CNF[i] &GPIO_PIN_CNF_SENSE_Msk)
{
NRF_GPIO->PIN_CNF[i] &= ~(GPIO_PIN_CNF_SENSE_Msk);
if(newVal>>i &1){
NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos) ;
}
else{
NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;
}
}
}
}
oldPortValue = newVal;
//NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Enabled<<GPIOTE_INTENSET_PORT_Pos;
}
}
}
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
@ -77,14 +63,12 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
obj->ch = pin;
oldPortValue = NRF_GPIO->IN;
//NVIC_DisableIRQ(GPIOTE_IRQn);
NRF_GPIOTE->EVENTS_PORT = 0;
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set<<GPIOTE_INTENSET_PORT_Pos;
NVIC_EnableIRQ(GPIOTE_IRQn);
NRF_GPIOTE->EVENTS_PORT = 0;
channel_ids[pin]=id;
channel_enabled[pin]=1;
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set<<GPIOTE_INTENSET_PORT_Pos;
NVIC_EnableIRQ(GPIOTE_IRQn);
return 0;
}
void gpio_irq_free(gpio_irq_t *obj) {
@ -92,21 +76,35 @@ void gpio_irq_free(gpio_irq_t *obj) {
}
void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
portRISE &=~(1<<obj->ch);
portFALL &=~(1<<obj->ch);
NRF_GPIO->PIN_CNF[obj->ch] &= ~(GPIO_PIN_CNF_SENSE_Msk);
if(enable){
if(event == IRQ_RISE){
portRISE |=(1<<obj->ch);
NRF_GPIO->PIN_CNF[obj->ch] &= ~(GPIO_PIN_CNF_SENSE_Msk);// | GPIO_PIN_CNF_PULL_Msk);
NRF_GPIO->PIN_CNF[obj->ch] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;//| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
}
else if(event == IRQ_FALL){
portFALL |=(1<<obj->ch);
NRF_GPIO->PIN_CNF[obj->ch] &= ~(GPIO_PIN_CNF_SENSE_Msk );//| GPIO_PIN_CNF_PULL_Msk);
NRF_GPIO->PIN_CNF[obj->ch] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);// | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
}
}
else{
if(event == IRQ_RISE){
portRISE &=~(1<<obj->ch);
}
}
oldPortValue = NRF_GPIO->IN;
else if(event == IRQ_FALL){
portFALL &=~(1<<obj->ch);
}
}
if( (portRISE>>obj->ch) || (portFALL>>obj->ch) )
{
if((NRF_GPIO->IN>>obj->ch)&1)
{
NRF_GPIO->PIN_CNF[obj->ch] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);// | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
}
else{
NRF_GPIO->PIN_CNF[obj->ch] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;//| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
}
}
}
void gpio_irq_enable(gpio_irq_t *obj) {

View File

@ -19,16 +19,18 @@
#include "error.h"
/*
static const PinMap PinMap_I2C_SDA[] = {
{p9, I2C_0, 1},
{p22, I2C_0, 1},
{p13, I2C_1, 2},
{NC , NC , 0}
};
static const PinMap PinMap_I2C_SCL[] = {
{p8, I2C_0, 1},
{p20, I2C_0, 1},
{p15, I2C_1, 2},
{NC , NC, 0}
};*/
};
uint8_t I2C_USED[] = {0,0};
uint8_t addrSet=0;
void i2c_interface_enable(i2c_t *obj)
@ -57,9 +59,11 @@ void twi_master_init(i2c_t *obj, PinName sda, PinName scl, int frequency) {
}
void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
// determine the SPI to use
// I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
// I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
if(I2C_USED[0]){
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
I2CName i2c = (I2CName)pinmap_merge(i2c_sda,i2c_scl);
obj->i2c = (NRF_TWI_Type *)i2c;
/*if(I2C_USED[0]){
if(I2C_USED[1]){
error("All TWI peripherals in use.");
}
@ -68,7 +72,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
else{
obj->i2c = (NRF_TWI_Type *)I2C_0;
}
}*/
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
@ -185,20 +189,6 @@ int checkError(i2c_t *obj)
return 0;
}
// The I2C does a read or a write as a whole operation
// There are two types of error conditions it can encounter
// 1) it can not obtain the bus
// 2) it gets error responses at part of the transmission
//
// We tackle them as follows:
// 1) we retry until we get the bus. we could have a "timeout" if we can not get it
// which basically turns it in to a 2)
// 2) on error, we use the standard error mechanisms to report/debug
//
// Therefore an I2C transaction should always complete. If it doesn't it is usually
// because something is setup wrong (e.g. wiring), and we don't need to programatically
// check for that
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
int status,count;
obj->i2c->ADDRESS = (address>>1);
@ -217,11 +207,6 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
}
}
/*status = i2c_do_read(obj,&data[length-2], 1);
if (status) {
i2c_reset(obj);
return length - 2;
}*/
// read in last byte
status = i2c_do_read(obj,&data[length-1], 1);
if (status) {

View File

@ -25,12 +25,6 @@ void pin_mode(PinName pin, PinMode mode) {
uint32_t pin_number = (uint32_t)pin;
NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_PULL_Msk;
NRF_GPIO->PIN_CNF[pin_number] |= (mode<<GPIO_PIN_CNF_PULL_Pos);
}
/*
NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (mode << GPIO_PIN_CNF_PULL_Pos)
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);*/
}

View File

@ -28,14 +28,6 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
obj->reg_out = &NRF_GPIO->OUT;
obj->reg_in = &NRF_GPIO->IN;
obj->reg_cnf = NRF_GPIO->PIN_CNF;
uint32_t i;
// The function is set per pin: reuse gpio logic
/* for (i=0; i<32; i++) {
if (obj->mask & (1<<i)) {
gpio_set(port_pin(obj->port, i));
}
}*/
port_dir(obj, dir);
}

View File

@ -57,12 +57,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
//pin configurations --
//outputs
//nrf_gpio_cfg_output(TX_PIN_NUMBER);
NRF_GPIO->DIR |= (1<<tx);//TX_PIN_NUMBER);
NRF_GPIO->DIR |= (1<<RTS_PIN_NUMBER);
//nrf_gpio_cfg_output(RTS_PIN_NUMBER);
//nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);
NRF_GPIO->DIR &= ~(1<<rx);//RX_PIN_NUMBER);
NRF_GPIO->DIR &= ~(1<<CTS_PIN_NUMBER);
@ -71,12 +68,6 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
//inputs
obj->uart->PSELCTS = CTS_PIN_NUMBER;
obj->uart->PSELRXD = rx;//RX_PIN_NUMBER;
// LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
//disconnect USBTX/RX mapping mux, for case when switching ports
//pin_function(USBTX, 0);
//pin_function(USBRX, 0);
// set default baud rate and format
@ -87,9 +78,6 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
obj->uart->TASKS_STARTTX = 1;
obj->uart->TASKS_STARTRX = 1;
obj->uart->EVENTS_RXDRDY =0;
// pinout the chosen uart
// pinmap_pinout(tx, PinMap_UART_TX);
// pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
@ -144,8 +132,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
obj->uart->CONFIG = (UART_CONFIG_PARITY_Included<<UART_CONFIG_PARITY_Pos);
return;
}
//enable HW flow control
obj->uart->CONFIG |= (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
//no Flow Control
}
//******************************************************************************
@ -164,7 +151,7 @@ static inline void uart_irq(uint32_t iir, uint32_t index) {
irq_handler(serial_irq_ids[index], irq_type);
}
void uart0_irq()
void UART0_IRQHandler()
{
uint32_t irtype =0;
if(NRF_UART0->EVENTS_TXDRDY)
@ -188,32 +175,22 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
}
if (enable) {
switch (irq) {
case RxIrq:// obj->uart->INTEN |= (UART_INTENSET_RXDRDY_Msk);
obj->uart->INTENSET |= (UART_INTENSET_RXDRDY_Msk);
break;
case TxIrq: //obj->uart->INTEN |= (UART_INTENSET_TXDRDY_Msk);
obj->uart->INTENSET |= (UART_INTENSET_TXDRDY_Msk);
break;
}
// NVIC_SetVector(irq_n, vector);
NVIC_EnableIRQ(irq_n);
} else { // disable
int all_disabled = 0;
switch (irq) {
case RxIrq: //obj->uart->INTEN &= ~(UART_INTENSET_RXDRDY_Msk);
obj->uart->INTENSET &= ~(UART_INTENSET_RXDRDY_Msk);
case RxIrq: obj->uart->INTENSET |= (UART_INTENSET_RXDRDY_Msk);break;
case TxIrq: obj->uart->INTENSET |= (UART_INTENSET_TXDRDY_Msk);break;
}
NVIC_EnableIRQ(irq_n);
}
else { // disable
int all_disabled = 0;
switch (irq) {
case RxIrq: obj->uart->INTENSET &= ~(UART_INTENSET_RXDRDY_Msk);
all_disabled = (obj->uart->INTENSET& (UART_INTENSET_TXDRDY_Msk))==0;
break;
case TxIrq://obj->uart->INTEN &= ~(UART_INTENSET_TXDRDY_Msk);
obj->uart->INTENSET &= ~(UART_INTENSET_TXDRDY_Msk);
case TxIrq: obj->uart->INTENSET &= ~(UART_INTENSET_TXDRDY_Msk);
all_disabled = (obj->uart->INTENSET& (UART_INTENSET_RXDRDY_Msk))==0;
break;
}
if (all_disabled)
NVIC_DisableIRQ(irq_n);
}
@ -224,16 +201,14 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
//******************************************************************************
int serial_getc(serial_t *obj) {
while (!serial_readable(obj));
obj->uart->EVENTS_RXDRDY = 0;
return (uint8_t)obj->uart->RXD;
}
void serial_putc(serial_t *obj, int c) {
obj->uart->TXD = (uint8_t)c;
while (!serial_writable(obj));
obj->uart->EVENTS_TXDRDY =0;
while (!serial_writable(obj));
obj->uart->EVENTS_TXDRDY =0;
}
int serial_readable(serial_t *obj) {
@ -244,18 +219,11 @@ int serial_writable(serial_t *obj) {
return (obj->uart->EVENTS_TXDRDY ==1);
}
void serial_clear(serial_t *obj) {
}
void serial_pinout_tx(PinName tx) {
// pinmap_pinout(tx, PinMap_UART_TX);
//obj->uart->PSELTXD = (1<<tx));//TX_PIN_NUMBER);
}
void serial_break_set(serial_t *obj) {
// obj->uart->LCR |= (1 << 6);
obj->uart->TASKS_SUSPEND = 1;
}
void serial_break_clear(serial_t *obj) {
// obj->uart->LCR &= ~(1 << 6);
}
obj->uart->TASKS_STARTTX = 1;
obj->uart->TASKS_STARTRX = 1;
}

View File

@ -0,0 +1,38 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "sleep_api.h"
#include "cmsis.h"
#include "mbed_interface.h"
void sleep(void) {
// ensure debug is disconnected if semihost is enabled....
// mbed_interface_disconnect();
NRF_POWER->TASKS_LOWPWR=1;
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
// wait for interrupt
__WFI();
}
void deepsleep(void) {
// PCON[PD] set to deepsleep
// sleep();
NRF_POWER->TASKS_LOWPWR=1;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();
}

View File

@ -23,7 +23,7 @@
int us_ticker_inited = 0;
volatile uint16_t overflow=0; //overflow value that forms the upper 16 bits of the counter
volatile uint32_t overflowShifted=0; //reduces number of times the overflow is shifted
volatile uint16_t timeStamp=0;
void TIMER1_IRQHandler(void)
{
if ((US_TICKER_TIMER->EVENTS_COMPARE[1] != 0) &&
@ -31,14 +31,26 @@ void TIMER1_IRQHandler(void)
{
US_TICKER_TIMER->EVENTS_COMPARE[1] = 0;
overflow++;
overflowShifted = ((uint32_t)overflow<<16);
US_TICKER_TIMER->CC[1] =0;//US_TICKER_TIMER->CC[1]+ 1;
US_TICKER_TIMER->CC[1] =0xFFFF;
if(timeStamp>0)
{
timeStamp--;
if(timeStamp==0)
{
us_ticker_clear_interrupt();
us_ticker_disable_interrupt();
us_ticker_irq_handler();
return;
}
}
}
if ((US_TICKER_TIMER->EVENTS_COMPARE[0] != 0) &&
((US_TICKER_TIMER->INTENSET & TIMER_INTENSET_COMPARE0_Msk) != 0))
{
us_ticker_irq_handler();
{
us_ticker_clear_interrupt();
us_ticker_disable_interrupt();
if(timeStamp==0)
us_ticker_irq_handler();
}
}
@ -59,7 +71,8 @@ void us_ticker_init(void)
US_TICKER_TIMER->PRESCALER = 4;
US_TICKER_TIMER->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
US_TICKER_TIMER->CC[1] = 0;
US_TICKER_TIMER->TASKS_CLEAR =1;
US_TICKER_TIMER->CC[1] = 0xFFFF;
US_TICKER_TIMER->INTENSET = TIMER_INTENSET_COMPARE1_Set << TIMER_INTENSET_COMPARE1_Pos;
NVIC_EnableIRQ(US_TICKER_TIMER_IRQn);
@ -73,16 +86,13 @@ uint32_t us_ticker_read()
{
us_ticker_init();
}
uint32_t bufferedOverFlow = overflowShifted;
US_TICKER_TIMER->TASKS_CAPTURE[2] = 1;
__NOP(); //essential to register the capture
if(overflowShifted!=bufferedOverFlow){
bufferedOverFlow = overflowShifted;
uint16_t bufferedOverFlow = overflow;
US_TICKER_TIMER->TASKS_CAPTURE[2] = 1;
if(overflow!=bufferedOverFlow){
bufferedOverFlow = overflow;
US_TICKER_TIMER->TASKS_CAPTURE[2] = 1;
}
return (bufferedOverFlow | US_TICKER_TIMER->CC[2]);
return (((uint32_t)bufferedOverFlow<<16) | US_TICKER_TIMER->CC[2]);
}
void us_ticker_set_interrupt(unsigned int timestamp)
@ -90,11 +100,18 @@ void us_ticker_set_interrupt(unsigned int timestamp)
if (!us_ticker_inited)
{
us_ticker_init();
}
US_TICKER_TIMER->INTENSET |= TIMER_INTENSET_COMPARE0_Set << TIMER_INTENSET_COMPARE0_Pos;
US_TICKER_TIMER->TASKS_CAPTURE[0] = 1;
US_TICKER_TIMER->CC[0] += timestamp;// * 16;
}
US_TICKER_TIMER->TASKS_CAPTURE[0] = 1;
uint16_t tsUpper16 = (uint16_t)((timestamp-us_ticker_read())>>16);
if(tsUpper16>0){
if(timeStamp ==0 || timeStamp> tsUpper16){
timeStamp = tsUpper16;
}
}
else{
US_TICKER_TIMER->INTENSET |= TIMER_INTENSET_COMPARE0_Set << TIMER_INTENSET_COMPARE0_Pos;
US_TICKER_TIMER->CC[0] += timestamp-us_ticker_read();
}
}
void us_ticker_disable_interrupt(void)

View File

@ -1,5 +1,4 @@
#include "test_env.h"
int main() {
notify_completion(true);
}

View File

@ -6,6 +6,8 @@
#if defined(TARGET_KL25Z)
I2C i2c(PTE0, PTE1);
#elif defined(TARGET_nRF51822)
I2C i2c(p22,p20);
#else
I2C i2c(p28, p27);
#endif

View File

@ -48,14 +48,13 @@ void flipper() {
int main() {
out = 0; myled = 0;
//Test falling edges first
in.rise(NULL);
in.fall(in_handler);
flipper();
if(checks != 5) {
printf("falling edges test failed\n");
printf("falling edges test failed: %d\n",checks);
notify_completion(false);
}
@ -65,7 +64,7 @@ int main() {
flipper();
if (checks != 10) {
printf("raising edges test failed\n");
printf("raising edges test failed: %d\n",checks);
notify_completion(false);
}

View File

@ -44,34 +44,44 @@
#define P2_1 (1 << 5) // PTC5
#define P2_2 (1 << 6) // PTC6
#define PORT_2 PortC
#elif defined(TARGET_nRF51822)
#define P1_1 (1 << 4) // p4
#define P1_2 (1 << 5) // p5
#define PORT_1 Port0
#define P2_1 (1 << 0) // p24
#define P2_2 (1 << 1) // p25
#define PORT_2 Port3
#endif
#define MASK_1 (P1_1 | P1_2)
#define MASK_2 (P2_1 | P2_2)
PortInOut p1(PORT_1, MASK_1);
PortInOut p2(PORT_2, MASK_2);
PortInOut port1(PORT_1, MASK_1);
PortInOut port2(PORT_2, MASK_2);
int main() {
bool check = true;
p1.output();
p2.input();
port1.output();
port2.input();
p1 = MASK_1; wait(0.1);
if (p2 != MASK_2) check = false;
port1 = MASK_1; wait(0.1);
if (port2 != MASK_2) check = false;
p1 = 0; wait(0.1);
if (p2 != 0) check = false;
port1 = 0; wait(0.1);
if (port2 != 0) check = false;
p1.input();
p2.output();
port1.input();
port2.output();
p2 = MASK_2; wait(0.1);
if (p1 != MASK_1) check = false;
port2 = MASK_2; wait(0.1);
if (port1 != MASK_1) check = false;
p2 = 0; wait(0.1);
if (p1 != 0) check = false;
port2 = 0; wait(0.1);
if (port1 != 0) check = false;
notify_completion(check);
}

View File

@ -44,6 +44,15 @@
#define P2_1 (1 << 5) // PTC5
#define P2_2 (1 << 6) // PTC6
#define PORT_2 PortC
#elif defined(TARGET_nRF51822)
#define P1_1 (1 << 4) // p4
#define P1_2 (1 << 5) // p5
#define PORT_1 Port0
#define P2_1 (1 << 0) // p24
#define P2_2 (1 << 1) // p25
#define PORT_2 Port3
#endif
#define MASK_1 (P1_1 | P1_2)

View File

@ -16,7 +16,7 @@ CT32B0/MR2 p10 (P1_26)
int main() {
#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088)
PwmOut pwm_p25(p25);
PwmOut pwm_p25(p25);
PwmOut pwm_p26(p26);
pwm_p25.write(0.75);
@ -48,6 +48,15 @@ int main() {
pwm_d2.period_ms(10);
pwm_d2.write(0.75);
printf("%.2f\n", pwm_d2.read());
#elif defined(TARGET_nRF51822)
PwmOut pwm_p24(p24);
PwmOut pwm_p25(p25);
pwm_p24.write(0.75);
pwm_p25.write(0.50);
printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read());
printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
#endif
notify_completion(true);

View File

@ -20,6 +20,7 @@ TEST BUILD & RUN
"""
import sys
from os.path import join, abspath, dirname
from subprocess import call
from shutil import copy
from time import sleep
@ -74,7 +75,8 @@ if __name__ == '__main__':
default=None, help="The mbed serial port")
parser.add_option("-b", "--baud", type="int", dest="baud",
default=None, help="The mbed serial baud rate")
parser.add_option("--nrfjprog",dest="nrfjprog",default=None,help="Program nRF Chip via J-Link")
# Ideally, all the tests with a single "main" thread can be run with, or
# without the rtos
parser.add_option("--rtos", action="store_true", dest="rtos",
@ -164,7 +166,10 @@ if __name__ == '__main__':
if options.disk:
# Simple copy to the mbed disk
copy(bin, options.disk)
if options.nrfjprog:
#Convert bin to Hex and Program nrf chip via jlink
call(["c:\\msdos\\msdos.exe","c:\\BIN2HEX.EXE",bin])
call(["nrfjprog","-e","--program",bin.replace(".bin",".hex"),"--verify","-p"])
if options.serial:
# Import pyserial: https://pypi.python.org/pypi/pyserial
from serial import Serial

View File

@ -253,7 +253,7 @@ TESTS = [
"source_dir": join(TEST_DIR, "mbed", "sleep"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"duration": 30,
"mcu": ["LPC1768", "LPC11U24", "LPC4088"]
"mcu": ["LPC1768", "LPC11U24", "LPC4088","nRF51822"]
},
{
"id": "MBED_5", "description": "PWM",