Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into develop
  • Loading branch information
changtengfei committed Feb 26, 2016
2 parents 33d6593 + 6768d2b commit f179a2d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 105 deletions.
83 changes: 31 additions & 52 deletions bsp/boards/iot-lab_A8-M3/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "stdint.h"
#include "string.h"
#include "uart.h"
#include "leds.h"

#include "rcc.h"
#include "nvic.h"
Expand All @@ -22,35 +21,27 @@
typedef struct {
uart_tx_cbt txCb;
uart_rx_cbt rxCb;
uint8_t startOrend;
uint8_t flagByte;
} uart_vars_t;

volatile uart_vars_t uart_vars;
uart_vars_t uart_vars;

//=========================== prototypes ======================================

//=========================== public ==========================================

void uart_init()
{
// reset local variables
memset(&uart_vars,0,sizeof(uart_vars_t));

//when this value is 0, we are send the first data
uart_vars.startOrend = 0;
//flag byte for start byte and end byte
uart_vars.flagByte = 0x7E;
void uart_init() {

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
// reset local variables
memset(&uart_vars,0,sizeof(uart_vars_t));

/* enable GPIO and USART clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/* Configure USART Tx as alternate function push-pull */
/* Configure USART TX pin as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
Expand All @@ -69,73 +60,61 @@ void uart_init()
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE); // enable USART1
// make sure no interrupts fire as we enable the UART
uart_clearTxInterrupts();
uart_clearRxInterrupts();

// enable USART1
USART_Cmd(USART1, ENABLE);

// enable NVIC uart
NVIC_uart();
}

void uart_setCallbacks(uart_tx_cbt txCb, uart_rx_cbt rxCb)
{
void uart_setCallbacks(uart_tx_cbt txCb, uart_rx_cbt rxCb) {
uart_vars.txCb = txCb;
uart_vars.rxCb = rxCb;

//enable nvic uart.
NVIC_uart();
}

void uart_enableInterrupts()
{
void uart_enableInterrupts() {
USART_ITConfig(USART1, USART_IT_TC, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}

void uart_disableInterrupts()
{
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
void uart_disableInterrupts() {
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
}

void uart_clearRxInterrupts()
{
void uart_clearRxInterrupts() {
USART_ClearFlag(USART1, USART_FLAG_RXNE);
}

void uart_clearTxInterrupts()
{
USART_ClearFlag(USART1, USART_FLAG_TXE);
void uart_clearTxInterrupts() {
USART_ClearFlag(USART1, USART_FLAG_TC);
}

void uart_writeByte(uint8_t byteToWrite)
{
void uart_writeByte(uint8_t byteToWrite) {
USART_SendData(USART1, byteToWrite);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

//start or end byte?
if(byteToWrite == uart_vars.flagByte) {
uart_vars.startOrend = (uart_vars.startOrend == 0)?1:0;
//start byte
if(uart_vars.startOrend == 1) {
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
} else {
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
}
}

uint8_t uart_readByte()
{
uint8_t uart_readByte() {
uint16_t temp;

temp = USART_ReceiveData(USART1);
return (uint8_t)temp;
}

//=========================== interrupt handlers ==============================

kick_scheduler_t uart_tx_isr()
{
kick_scheduler_t uart_tx_isr() {
uart_clearTxInterrupts();
uart_vars.txCb();
return DO_NOT_KICK_SCHEDULER;
}

kick_scheduler_t uart_rx_isr()
{
kick_scheduler_t uart_rx_isr() {
uart_clearRxInterrupts();
uart_vars.rxCb();
return DO_NOT_KICK_SCHEDULER;
}
Expand Down
2 changes: 1 addition & 1 deletion bsp/boards/iot-lab_M3/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void uart_init() {
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_BaudRate = 500000;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
Expand Down
6 changes: 6 additions & 0 deletions openstack/03b-IPv6/icmpv6rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ void icmpv6rpl_receive(OpenQueueEntry_t* msg) {
// update neighbor table
neighbors_indicateRxDIO(msg);

memcpy(
&(icmpv6rpl_vars.dio),
(icmpv6rpl_dio_ht*)(msg->payload),
sizeof(icmpv6rpl_dio_ht)
);

// write DODAGID in DIO and DAO
icmpv6rpl_writeDODAGid(&(((icmpv6rpl_dio_ht*)(msg->payload))->DODAGID[0]));

Expand Down
91 changes: 39 additions & 52 deletions projects/common/01bsp_radio_rx/01bsp_radio_rx.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import struct
import socket
Expand All @@ -17,71 +20,55 @@
banner = '\n'.join(banner)
print banner

DEFAULT_IOTLAB = True
DEFAULT_MOTENAME = 'wsn430-35'
DEFAULT_SERIALPORT = 'COM10'

#============================ configuration ===================================

iotlab = None
motename = None
serialport = None

# iotlab

t = raw_input('running IoT-lAB? (Y|N): '.format(DEFAULT_IOTLAB))
if not t.strip():
iotlab = DEFAULT_IOTLAB
elif t.strip() in ['1','yes','y','Y']:
iotlab = True
else:
iotlab = False

# motename

if iotlab:
t = raw_input('motename? (e.g. {0}): '.format(DEFAULT_MOTENAME))
if not t.strip():
motename = DEFAULT_MOTENAME
else:
motename = t.strip()

# serialport

if not iotlab:
t = raw_input('name of serial port (e.g. {0}): '.format(DEFAULT_SERIALPORT))
if not t.strip():
serialport = DEFAULT_SERIALPORT
else:
serialport = t.strip()

#============================ connect =========================================

if iotlab:
assert motename
def mote_connect(motename=None , serialport= None, baudrate='115200'):
try:
mote = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mote.connect((motename,20000))
if (motename):
mote = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mote.connect((motename,20000))
else:
mote = serial.Serial(serialport, baudrate)
return mote
except Exception as err:
print 'could not connect to {0}, reason: {1}'.format(motename,err)
print "{0}".format(err)
raw_input('Press Enter to close.')
sys.exit(1)


#============================ configuration and connection ===================================

iotlab_serialport = False
motename = 'wsn430-35'
serialport = 'COM10'
mote = None

t = raw_input('Are you running on IoT-LAB nodes ? (Y|N): ')
if (not t.strip() or t.strip() in ['1','yes','y','Y']):
t = raw_input('Enter mote name ? (e.g. {0}): '.format(motename))
if t.strip():
motename = t.strip()
archi = motename.split('-')
assert len(archi) == 2
assert archi[0] in ['wsn430', 'a8', 'm3']
if (archi[0] != 'a8'):
iotlab_serialport = True
mote = mote_connect(motename=motename)
else:
mote = mote_connect(serialport='/dev/ttyA8_M3', baudrate='500000')

else:
assert serialport
try:
mote = serial.Serial(serialport,115200)
except Exception as err:
print 'could not open {0}, reason: {1}'.format(serialport,err)
raw_input('Press Enter to close.')
sys.exit(1)
t = raw_input('Enter serial port name (e.g. {0}): '.format(serialport))
if t.strip():
serialport = t.strip()
mote = mote_connect(serialport=serialport)

#============================ read ============================================

rawFrame = []

while True:

if iotlab:
if iotlab_serialport:
bytes = mote.recv(1024)
rawFrame += [ord(b) for b in bytes]
else:
Expand Down

0 comments on commit f179a2d

Please sign in to comment.