1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

lint: reduce scope

Fix some lint warnings of kind
```
style (variableScope): The scope of the variable '…' can be reduced
```
This commit is contained in:
René Kijewski 2014-08-11 19:51:23 +02:00
parent 26d3a94dff
commit 0cc699c0ce
35 changed files with 174 additions and 231 deletions

View File

@ -685,19 +685,17 @@ unsigned char SMB380_getWakeUpPause(void)
void SMB380_setBandWidth(unsigned char bandWidth)
{
unsigned char utemp;
if ((bandWidth == SMB380_BAND_WIDTH_100HZ) |
(bandWidth == SMB380_BAND_WIDTH_1500HZ) |
(bandWidth == SMB380_BAND_WIDTH_190HZ) |
(bandWidth == SMB380_BAND_WIDTH_25HZ) |
(bandWidth == SMB380_BAND_WIDTH_375HZ) |
(bandWidth == SMB380_BAND_WIDTH_50HZ) |
(bandWidth == SMB380_BAND_WIDTH_750HZ)) {
if ((bandWidth == SMB380_BAND_WIDTH_100HZ) ||
(bandWidth == SMB380_BAND_WIDTH_1500HZ) ||
(bandWidth == SMB380_BAND_WIDTH_190HZ) ||
(bandWidth == SMB380_BAND_WIDTH_25HZ) ||
(bandWidth == SMB380_BAND_WIDTH_375HZ) ||
(bandWidth == SMB380_BAND_WIDTH_50HZ) ||
(bandWidth == SMB380_BAND_WIDTH_750HZ)) {
unsigned long cpsr = disableIRQ();
SMB380_Prepare();
SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER);
utemp = SMB380_ssp_read();
unsigned char utemp = SMB380_ssp_read();
utemp &= ~SMB380_CONTROL3_BANDWITH_MASK;
utemp |= (bandWidth & 0x7);
SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER);
@ -709,13 +707,11 @@ void SMB380_setBandWidth(unsigned char bandWidth)
void SMB380_setRange(unsigned char range)
{
unsigned char utemp = 0;
if (range != 0x3) {
unsigned long cpsr = disableIRQ();
SMB380_Prepare();
SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER);
utemp = (unsigned char)SMB380_ssp_read();
unsigned char utemp = (unsigned char)SMB380_ssp_read();
utemp &= ~SMB380_CONTROL3_RANGE_MASK;
utemp |= (range & 0x3) << 3;
SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER);
@ -857,16 +853,14 @@ void SMB380_Selftest_1(void)
void SMB380_ShowMemory(void)
{
uint16_t uReg = 0;
uint8_t bitMask[16];
printf("SMB380 Speicher\n\r");
unsigned long cpsr;
for (unsigned char regAd = 0x16; regAd > 0; regAd--) {
cpsr = disableIRQ();
unsigned long cpsr = disableIRQ();
SMB380_Prepare();
SMB380_ssp_write(regAd - 1, 0, SMB380_READ_REGISTER);
uReg = SMB380_ssp_read();
uint16_t uReg = SMB380_ssp_read();
SMB380_Unprepare();
restoreIRQ(cpsr);
printf("Register: = %X: 0x%X = ", regAd - 1, uReg);

View File

@ -239,7 +239,7 @@ void display_char(uint8_t segment, char chr, uint8_t mode)
{
/* Write to single 7-segment character */
if ((segment >= LCD_SEG_L1_3) && (segment <= LCD_SEG_L2_DP)) {
uint8_t bits, bits1; /* Bits to write */
uint8_t bits; /* Bits to write */
/* Get LCD memory address for segment from table */
uint8_t *lcdmem = (uint8_t *)segments_lcdmem[segment];
@ -264,7 +264,7 @@ void display_char(uint8_t segment, char chr, uint8_t mode)
/* When addressing LINE2 7-segment characters need to swap high- and low-nibble, */
/* because LCD COM/SEG assignment is mirrored against LINE1 */
if (segment >= LCD_SEG_L2_5) {
bits1 = ((bits << 4) & 0xF0) | ((bits >> 4) & 0x0F);
uint8_t bits1 = ((bits << 4) & 0xF0) | ((bits >> 4) & 0x0F);
bits = bits1;
/* When addressing LCD_SEG_L2_5, need to convert ASCII '1' and 'L' to 1 bit, */

View File

@ -176,7 +176,7 @@ void msp430_init_dco(void)
BCSCTL2 = SELM_2 + SELS; /* MCLK und SMCLK = XT2 (safe) */
#else
int delta = __msp430_cpu_speed >> 12;
unsigned int compare, oldcapture = 0;
unsigned int oldcapture = 0;
unsigned int i;
BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK
@ -199,6 +199,8 @@ void msp430_init_dco(void)
while (1) {
unsigned int compare;
while ((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured! */
CCTL2 &= ~CCIFG; /* Capture occured, clear flag */

View File

@ -434,7 +434,7 @@ void usage(void)
int print_and_prompt(struct ftdi_device_list *devlist)
{
int i, ret;
int i;
struct ftdi_context ftdic;
struct ftdi_device_list *curdev;
char manufacturer[128], description[128], serial[128];
@ -449,11 +449,12 @@ int print_and_prompt(struct ftdi_device_list *devlist)
for (curdev = devlist; curdev != NULL; i++) {
printf(" [%d] ", i);
if (0 > (ret = ftdi_usb_get_strings(&ftdic,
curdev->dev,
manufacturer, 128,
description, 128,
serial, 128))) {
int ret = ftdi_usb_get_strings(&ftdic,
curdev->dev,
manufacturer, 128,
description, 128,
serial, 128)
if (0 > ret) {
fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n",
ret, ftdi_get_error_string(&ftdic));
return EXIT_FAILURE;

View File

@ -53,7 +53,7 @@ void msp430_init_dco(void)
/* This code taken from the FU Berlin sources and reformatted. */
#define DELTA (F_CPU / (F_RC_OSCILLATOR / 8))
unsigned int compare, oldcapture = 0;
unsigned int oldcapture = 0;
unsigned int i;
/* 10100100 = XT2 is off, ACLK divided by 4, RSELx=4 */
@ -73,6 +73,8 @@ void msp430_init_dco(void)
TACTL = TASSEL1 + TACLR + MC1; /* SMCLK, continous mode */
while (1) {
unsigned int compare;
while ((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured!*/
CCTL2 &= ~CCIFG; /* Capture occured, clear flag */

View File

@ -127,7 +127,7 @@ void msp430_init_dco(void)
#ifdef CALIBRATE_MSP430_DCO
#define DELTA (F_CPU / (F_RC_OSCILLATOR / 8))
/* This code taken from the FU Berlin sources and reformatted. */
unsigned int compare, oldcapture = 0;
unsigned int oldcapture = 0;
unsigned int i;
/* 10100100 = XT2 is off, ACLK divided by 4, RSELx=4 */
@ -147,6 +147,8 @@ void msp430_init_dco(void)
TACTL = TASSEL1 + TACLR + MC1; /* SMCLK, continous mode */
while (1) {
unsigned int compare;
while ((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured!*/
CCTL2 &= ~CCIFG; /* Capture occured, clear flag */

View File

@ -34,11 +34,10 @@
uint8_t cc110x_strobe(uint8_t c)
{
uint8_t statusByte = 0;
uint16_t int_state, gdo_state;
/* Check for valid strobe command */
if ((c == 0xBD) || ((c > RF_SRES) && (c < RF_SNOP))) {
int_state = disableIRQ();
uint16_t int_state = disableIRQ();
/* Clear the Status read flag */
RF1AIFCTL1 &= ~(RFSTATIFG);
@ -49,7 +48,7 @@ uint8_t cc110x_strobe(uint8_t c)
/* Write the strobe instruction */
if ((c > RF_SRES) && (c < RF_SNOP)) {
gdo_state = cc110x_read_reg(IOCFG2); /* buffer IOCFG2 state */
uint16_t gdo_state = cc110x_read_reg(IOCFG2); /* buffer IOCFG2 state */
cc110x_write_reg(IOCFG2, 0x29); /* c-ready to GDO2 */
RF1AINSTRB = c;

View File

@ -60,11 +60,9 @@ void gpioint_init(void)
bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
{
int8_t base;
if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) {
/* set the callback function */
base = bitarithm_msb(bitmask);
int8_t base = bitarithm_msb(bitmask);
if (base >= 0) {
cb[port - PORTINT_MIN][base] = callback;

View File

@ -68,9 +68,6 @@ void cpu_clock_scale(uint32_t source, uint32_t target, uint32_t *prescale)
bool install_irq(int IntNumber, void (*HandlerAddr)(void), int Priority)
{
int *vect_addr;
int *vect_cntl;
VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */
if (IntNumber >= VIC_SIZE) {
@ -78,8 +75,8 @@ bool install_irq(int IntNumber, void (*HandlerAddr)(void), int Priority)
}
else {
/* find first un-assigned VIC address for the handler */
vect_addr = (int *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber * 4);
vect_cntl = (int *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber * 4);
int *vect_addr = (int *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber * 4);
int *vect_cntl = (int *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber * 4);
*vect_addr = (int)HandlerAddr; /* set interrupt vector */
*vect_cntl = Priority;
VICIntEnable = 1 << IntNumber; /* Enable Interrupt */

View File

@ -103,7 +103,7 @@ void Isr_GPDMA(void) __attribute__((interrupt("IRQ")));
void Isr_MCI(void)
{
unsigned long ms;
unsigned char n, xs;
unsigned char xs;
ms = MCI_STATUS & 0x073A; /* Clear MCI interrupt status */
MCI_CLEAR = ms;
@ -116,7 +116,7 @@ void Isr_MCI(void)
GPDMA_SOFT_BREQ = 0x10; /* Pop off remaining data in the MCIFIFO */
}
n = (XferWp + 1) % N_BUF; /* Next write buffer */
unsigned char n = (XferWp + 1) % N_BUF; /* Next write buffer */
XferWp = n;
if (n == XferRp) {
@ -124,7 +124,7 @@ void Isr_MCI(void)
}
}
else { /* In card write operation */
n = (XferRp + 1) % N_BUF; /* Next read buffer */
unsigned char n = (XferRp + 1) % N_BUF; /* Next read buffer */
XferRp = n;
if (n == XferWp) {
@ -700,8 +700,6 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
{
unsigned long resp;
unsigned int cmd;
unsigned char rp;
if (count < 1 || count > 127) {
return RES_PARERR; /* Check parameter */
@ -725,7 +723,7 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
if (send_cmd(cmd, sector, 1, &resp) /* Start to read */
&& !(resp & 0xC0580000)) {
rp = 0;
unsigned char rp = 0;
do {
while ((rp == XferWp) && !(XferStat & 0xC)) {
@ -879,7 +877,7 @@ DRESULT MCI_ioctl(
)
{
DRESULT res;
unsigned char b, *ptr = (unsigned char *)buff;
unsigned char *ptr = (unsigned char *)buff;
unsigned long resp[4], d, *dp, st, ed;
@ -903,7 +901,7 @@ DRESULT MCI_ioctl(
*(unsigned long *)buff = d << 10;
}
else { /* MMC or SDC CSD v1.0 */
b = (CardInfo[5] & 15) + ((CardInfo[10] & 128) >> 7) + ((CardInfo[9] & 3) << 1) + 2;
unsigned char b = (CardInfo[5] & 15) + ((CardInfo[10] & 128) >> 7) + ((CardInfo[9] & 3) << 1) + 2;
d = (CardInfo[8] >> 6) + ((unsigned short)CardInfo[7] << 2) + ((unsigned short)(CardInfo[6] & 3) << 10) + 1;
*(unsigned long *)buff = d << (b - 9);
}

View File

@ -179,10 +179,8 @@ void adc_flush(void)
*/
void adc_service(uint16_t *channels_read)
{
uint16_t tmp;
while (!ADC->FIFO_STATUSbits.EMPTY) {
tmp = ADC->FIFO_READ;
uint16_t tmp = ADC->FIFO_READ;
if ((tmp >> 12) < ADC_NUM_CHANS) {
channels_read[tmp >> 12] = tmp & 0x0fff;

View File

@ -937,14 +937,12 @@ uint16_t maca_get_pan(void)
#define MACA_ROM_END 0x0013ffff
#define MACA_ENTRY_EOF 0x00000e0f
uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) {
volatile uint32_t i;
if ( entries[0] <= MACA_ROM_END ) {
if ( entries[0] == 0 ) {
/* do delay */
printf ( "init_entry: delay 0x%08x\n", (unsigned int) entries[1] );
for ( i=0; i < entries[1]; i++ ) {
for ( volatile uint32_t i=0; i < entries[1]; i++ ) {
continue;
}

View File

@ -34,16 +34,14 @@ extern volatile uint16_t timer_round;
void timerA_init(void)
{
volatile unsigned int *ccr;
volatile unsigned int *ctl;
timer_round = 0; /* Set to round 0 */
TACTL = TASSEL_1 + TACLR; /* Clear the timer counter, set ACLK */
TACTL &= ~TAIFG; /* Clear the IFG */
TACTL |= TAIE; /* Enable TAIE (overflow IRQ) */
for (int i = 0; i < HWTIMER_MAXTIMERS; i++) {
ccr = &TACCR0 + (i);
ctl = &TACCTL0 + (i);
volatile unsigned int *ccr = &TACCR0 + (i);
volatile unsigned int *ctl = &TACCTL0 + (i);
*ccr = 0;
*ctl &= ~(CCIFG);
*ctl &= ~(CCIE);

View File

@ -170,13 +170,12 @@ static bool spi_receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t
/* Needed here for statistics */
extern cc1100_statistic_t cc1100_statistic;
uint8_t status[2];
uint8_t packetLength = 0;
/* Any bytes available in RX FIFO? */
if ((cc1100_spi_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) {
uint8_t status[2];
/* Read length byte (first byte in RX FIFO) */
packetLength = cc1100_spi_read_reg(CC1100_RXFIFO);
uint8_t packetLength = cc1100_spi_read_reg(CC1100_RXFIFO);
/* Read data from RX FIFO and store in rxBuffer */
if (packetLength <= length) {

View File

@ -632,10 +632,8 @@ static void *cc1100_event_handler_function(void *arg)
}
if (m.type == MSG_TIMER) {
uint8_t state;
if (radio_mode == CC1100_MODE_CONSTANT_RX) {
state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE;
uint8_t state = cc1100_spi_read_status(CC1100_MARCSTATE) & MARC_STATE;
if ((state < 13 || state > 15) && radio_state == RADIO_RX && !rflags.TX) {
cc1100_statistic.watch_dog_resets++;

View File

@ -130,12 +130,11 @@ static uint16_t lm75A_get_register_value(uint8_t i2c_interface,
uint8_t reg_addr,
uint8_t reg_size)
{
bool status = false;
uint8_t rx_buff[reg_size];
i2c_clear_buffer(rx_buff, sizeof(rx_buff));
if ((reg_size > 0) && (reg_size < 3)) {
status = i2c_read(i2c_interface, LM75A_ADDR, reg_addr, rx_buff, sizeof(rx_buff));
bool status = i2c_read(i2c_interface, LM75A_ADDR, reg_addr, rx_buff, sizeof(rx_buff));
if (!status) { //Slave is not ready
puts(
"[lm75a_tempSensorI2C/lm75A_getConfigReg]: Slave is not\

View File

@ -83,9 +83,6 @@ int32_t srf08_get_distances(uint32_t *range_array, uint8_t ranging_mode)
{
bool status = false;
uint8_t reg_size = 1;
uint8_t range_high_byte = 0;
uint8_t range_low_byte = 0;
uint32_t distance = 0;
uint8_t rx_buff[reg_size];
uint8_t tx_buff[reg_size];
uint8_t register_location;
@ -110,7 +107,7 @@ int32_t srf08_get_distances(uint32_t *range_array, uint8_t ranging_mode)
puts("Read the high echo byte from the i2c-interface is failed");
return -1;
}
range_high_byte = rx_buff[0];
uint8_t range_high_byte = rx_buff[0];
//read the low echo byte
status = i2c_read(SRF08_I2C_INTERFACE, SRF08_DEFAULT_ADDR,
register_location + 1, rx_buff, reg_size);
@ -118,12 +115,12 @@ int32_t srf08_get_distances(uint32_t *range_array, uint8_t ranging_mode)
puts("Read the low echo byte from the i2c-interface is failed");
return -1;
}
range_low_byte = rx_buff[0];
uint8_t range_low_byte = rx_buff[0];
if ((range_high_byte == 0) && (range_low_byte == 0)) {
break;
}
else {
distance = (range_high_byte << 8) | range_low_byte;
uint32_t distance = (range_high_byte << 8) | range_low_byte;
range_array[(register_location - 2) / 2] = distance;
echo_number++;
printf("distance = %4lu cm , echo%d\n",
@ -139,7 +136,6 @@ void srf08_start_ranging(uint8_t ranging_mode)
{
uint32_t range_array[SRF08_MAX_ECHO_NUMBER];
uint8_t i;
uint8_t echo_number;
puts("Ultrasonic SRF08 engine is started");
//wait due to calibration
@ -149,7 +145,7 @@ void srf08_start_ranging(uint8_t ranging_mode)
while (1) {
puts("--------------------------------------------");
echo_number = srf08_get_distances(range_array, ranging_mode);
uint8_t echo_number = srf08_get_distances(range_array, ranging_mode);
if (echo_number > 0) {
for (i = 0; i < echo_number; i++) {
printf("stored distance = %4lu cm , echo%d\n", range_array[i], i + 1);

View File

@ -42,6 +42,8 @@
#define RIOT_CCN_APPSERVER (1)
#define RIOT_CCN_TESTS (0)
static const char DEFAULT_INTEREST[] = "/ccnx/0.7.1/doc/technical/CanonicalOrder.txt";
char relay_stack[KERNEL_CONF_STACKSIZE_MAIN];
#if RIOT_CCN_APPSERVER
@ -58,7 +60,6 @@ unsigned char big_buf[3 * 1024];
char small_buf[PAYLOAD_SIZE];
#if RIOT_CCN_APPSERVER
static void riot_ccn_appserver(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
@ -79,13 +80,11 @@ static void riot_ccn_appserver(int argc, char **argv)
static void riot_ccn_express_interest(int argc, char **argv)
{
static const char *default_interest = "/ccnx/0.7.1/doc/technical/CanonicalOrder.txt";
if (argc < 2) {
strncpy(small_buf, default_interest, 100); // null terminated
strncpy(small_buf, DEFAULT_INTEREST, sizeof(small_buf));
}
else {
strncpy(small_buf, argv[1], 100);
strncpy(small_buf, argv[1], sizeof(small_buf));
}
DEBUG("in='%s'\n", small_buf);

View File

@ -53,8 +53,6 @@ void rpl_udp_init(int argc, char **argv)
return;
}
uint8_t state;
char command = argv[1][0];
if ((command == 'n') || (command == 'r')) {
printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);
@ -68,7 +66,7 @@ void rpl_udp_init(int argc, char **argv)
net_if_set_hardware_address(0, id);
DEBUGF("Initializing RPL for interface 0\n");
state = rpl_init(0);
uint8_t state = rpl_init(0);
if (state != SIXLOWERROR_SUCCESS) {
printf("Error initializing RPL\n");

View File

@ -75,22 +75,16 @@ void bloom_del(struct bloom_t *bloom)
void bloom_add(struct bloom_t *bloom, const uint8_t *buf, size_t len)
{
uint32_t hash;
size_t n;
for (n = 0; n < bloom->k; n++) {
hash = bloom->hash[n](buf, len);
for (size_t n = 0; n < bloom->k; n++) {
uint32_t hash = bloom->hash[n](buf, len);
SETBIT(bloom->a, (hash % bloom->m));
}
}
bool bloom_check(struct bloom_t *bloom, const uint8_t *buf, size_t len)
{
uint32_t hash;
size_t n;
for (n = 0; n < bloom->k; n++) {
hash = bloom->hash[n](buf, len);
for (size_t n = 0; n < bloom->k; n++) {
uint32_t hash = bloom->hash[n](buf, len);
if (!(GETBIT(bloom->a, (hash % bloom->m)))) {
return false;

View File

@ -23,7 +23,7 @@
void color_rgb2hsv(color_rgb_t *rgb, color_hsv_t *hsv)
{
float rd, gd, bd, delta, rc, gc, bc;
float rd, gd, bd, delta;
/* norm RGB colors to the range [0 - 1.0] */
rd = (float)rgb->r / 255.0f;
@ -52,6 +52,8 @@ void color_rgb2hsv(color_rgb_t *rgb, color_hsv_t *hsv)
/* compute hue */
hsv->h = 0.0f;
if (hsv->s != 0.0) {
float rc, gc, bc;
rc = (hsv->v - rd) / delta;
gc = (hsv->v - gd) / delta;
bc = (hsv->v - bd) / delta;
@ -81,47 +83,47 @@ void color_hsv2rgb(color_hsv_t *hsv, color_rgb_t *rgb)
rgb->r = (uint8_t)(hsv->v * 255.0f);
rgb->g = (uint8_t)(hsv->v * 255.0f);
rgb->b = (uint8_t)(hsv->v * 255.0f);
return;
}
else {
h = (hsv->h == 360.0f) ? 0.0 : hsv->h;
h /= 60.0f;
i = (int)h;
f = h - i;
aa = hsv->v * (1.0f - hsv->s);
bb = hsv->v * (1.0f - (hsv->s * f));
cc = hsv->v * (1.0f - (hsv->s * (1.0f - f)));
switch (i) {
case 0:
rgb->r = (uint8_t)(hsv->v * 255.0f);
rgb->g = (uint8_t)(cc * 255.0f);
rgb->b = (uint8_t)(aa * 255.0f);
break;
case 1:
rgb->r = (uint8_t)(bb * 255.0f);
rgb->g = (uint8_t)(hsv->v * 255.0f);
rgb->b = (uint8_t)(aa * 255.0f);
break;
case 2:
rgb->r = (uint8_t)(aa * 255.0f);
rgb->g = (uint8_t)(hsv->v * 255.0f);
rgb->b = (uint8_t)(cc * 255.0f);
break;
case 3:
rgb->r = (uint8_t)(aa * 255.0f);
rgb->g = (uint8_t)(bb * 255.0f);
rgb->b = (uint8_t)(hsv->v * 255.0f);
break;
case 4:
rgb->r = (uint8_t)(cc * 255.0f);
rgb->g = (uint8_t)(aa * 255.0f);
rgb->b = (uint8_t)(hsv->v * 255.0f);
break;
case 5:
rgb->r = (uint8_t)(hsv->v * 255.0f);
rgb->g = (uint8_t)(aa * 255.0f);
rgb->b = (uint8_t)(bb * 255.0f);
break;
}
h = (hsv->h == 360.0f) ? 0.0 : hsv->h;
h /= 60.0f;
i = (int)h;
f = h - i;
aa = hsv->v * (1.0f - hsv->s);
bb = hsv->v * (1.0f - (hsv->s * f));
cc = hsv->v * (1.0f - (hsv->s * (1.0f - f)));
switch (i) {
case 0:
rgb->r = (uint8_t)(hsv->v * 255.0f);
rgb->g = (uint8_t)(cc * 255.0f);
rgb->b = (uint8_t)(aa * 255.0f);
break;
case 1:
rgb->r = (uint8_t)(bb * 255.0f);
rgb->g = (uint8_t)(hsv->v * 255.0f);
rgb->b = (uint8_t)(aa * 255.0f);
break;
case 2:
rgb->r = (uint8_t)(aa * 255.0f);
rgb->g = (uint8_t)(hsv->v * 255.0f);
rgb->b = (uint8_t)(cc * 255.0f);
break;
case 3:
rgb->r = (uint8_t)(aa * 255.0f);
rgb->g = (uint8_t)(bb * 255.0f);
rgb->b = (uint8_t)(hsv->v * 255.0f);
break;
case 4:
rgb->r = (uint8_t)(cc * 255.0f);
rgb->g = (uint8_t)(aa * 255.0f);
rgb->b = (uint8_t)(hsv->v * 255.0f);
break;
case 5:
rgb->r = (uint8_t)(hsv->v * 255.0f);
rgb->g = (uint8_t)(aa * 255.0f);
rgb->b = (uint8_t)(bb * 255.0f);
break;
}
}

View File

@ -58,14 +58,12 @@ struct timeval *
ccnl_run_events(void)
{
static struct timeval now;
long usec;
ccnl_get_timeval(&now);
//DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec);
while (eventqueue) {
struct ccnl_timer_s *t = eventqueue;
usec = timevaldelta(&(t->timeout), &now);
long usec = timevaldelta(&(t->timeout), &now);
if (usec >= 0) {
//DEBUGMSG(1, "ccnl_run_events nothing to do: %ld:%ld\n", now.tv_sec, now.tv_usec);

View File

@ -652,12 +652,11 @@ void ccnl_face_CTS_done(void *ptr, int cnt, int len)
void ccnl_face_CTS(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f)
{
struct ccnl_buf_s *buf;
DEBUGMSG(99, "ccnl_face_CTS face=%p sched=%p\n", (void *) f,
(void *) f->sched);
if (!f->frag || f->frag->protocol == CCNL_FRAG_NONE) {
buf = ccnl_face_dequeue(ccnl, f);
struct ccnl_buf_s *buf = ccnl_face_dequeue(ccnl, f);
if (buf)
ccnl_interface_enqueue(ccnl_face_CTS_done, f, ccnl,

View File

@ -174,14 +174,12 @@ int unmkBinaryInt(unsigned char **data, int *datalen, unsigned int *result,
int mkInterest(char **namecomp, unsigned int *nonce, unsigned char *out)
{
int len = 0, k;
len = mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest
int len = mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest
len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name
while (*namecomp) {
len += mkHeader(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG); // comp
k = strlen(*namecomp);
int k = strlen(*namecomp);
len += mkHeader(out + len, k, CCN_TT_BLOB);
memcpy(out + len, *namecomp++, k);
len += k;
@ -205,14 +203,12 @@ int mkInterest(char **namecomp, unsigned int *nonce, unsigned char *out)
int
mkContent(char **namecomp, char *data, int datalen, unsigned char *out)
{
int len = 0, k;
len = mkHeader(out, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // content
len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name
int len = mkHeader(out, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // content
len += mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); // name
while (*namecomp) {
len += mkHeader(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG); // comp
k = strlen(*namecomp);
int k = strlen(*namecomp);
len += mkHeader(out + len, k, CCN_TT_BLOB);
memcpy(out + len, *namecomp++, k);
len += k;

View File

@ -87,6 +87,9 @@ static int inet_pton4(const char *src, unsigned char *dst)
return (1);
}
static const char XDIGITS_L[] = "0123456789abcdef";
static const char XDIGITS_U[] = "0123456789ABCDEF";
/* int
* inet_pton6(src, dst)
* convert presentation level address to network order binary form.
@ -102,10 +105,8 @@ static int inet_pton4(const char *src, unsigned char *dst)
*/
static int inet_pton6(const char *src, unsigned char *dst)
{
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok;
const char *curtok;
int ch, saw_xdigit;
unsigned int val;
@ -114,10 +115,11 @@ static int inet_pton6(const char *src, unsigned char *dst)
colonp = NULL;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*src == ':') {
if (*++src != ':') {
return (0);
}
}
curtok = src;
saw_xdigit = 0;
@ -125,9 +127,10 @@ static int inet_pton6(const char *src, unsigned char *dst)
while ((ch = *src++) != '\0') {
const char *pch;
const char *xdigits;
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) {
pch = strchr((xdigits = xdigits_u), ch);
if ((pch = strchr((xdigits = XDIGITS_L), ch)) == NULL) {
pch = strchr((xdigits = XDIGITS_U), ch);
}
if (pch != NULL) {

View File

@ -33,27 +33,21 @@ void printArrayRange(uint8_t *array, uint16_t len, char *str)
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)
{
int count;
uint16_t carry;
count = len >> 1;
int count = len >> 1;
if (count) {
if (count) {
carry = 0;
do {
uint16_t t = (*buf << 8) + *(buf + 1);
count--;
buf += 2;
sum += carry;
sum += t;
carry = (t > sum);
}
while (count);
uint16_t carry = 0;
do {
uint16_t t = (*buf << 8) + *(buf + 1);
count--;
buf += 2;
sum += carry;
}
sum += t;
carry = (t > sum);
} while (count);
sum += carry;
}
if (len & 1) {

View File

@ -77,7 +77,6 @@ kernel_pid_t border_get_serial_reader()
void serial_reader_f(void)
{
kernel_pid_t main_pid;
int bytes;
msg_t m;
border_packet_t *uart_buf;
@ -88,7 +87,7 @@ void serial_reader_f(void)
while (1) {
posix_open(uart0_handler_pid, 0);
bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE);
int bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE);
if (bytes < 0) {
switch (bytes) {
@ -171,11 +170,10 @@ int sixlowpan_lowpan_border_init(int if_id)
void border_process_lowpan(void)
{
msg_t m;
ipv6_hdr_t *ipv6_buf;
while (1) {
msg_receive(&m);
ipv6_buf = (ipv6_hdr_t *)m.content.ptr;
ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)m.content.ptr;
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) {
icmpv6_hdr_t *icmp_buf = (icmpv6_hdr_t *)(((uint8_t *)ipv6_buf) + IPV6_HDR_LEN);

View File

@ -131,11 +131,10 @@ void multiplex_send_addr_over_uart(ipv6_addr_t *addr)
int readpacket(uint8_t *packet_buf, size_t size)
{
uint8_t *line_buf_ptr = packet_buf;
uint8_t byte = END + 1;
uint8_t esc = 0;
while (1) {
byte = uart0_readc();
uint8_t byte = uart0_readc();
if (byte == END) {
break;

View File

@ -91,16 +91,13 @@ ipv6_addr_t flowcontrol_init(void)
static void sending_slot(void)
{
msg_t m;
uint8_t seq_num;
struct send_slot *slot;
border_packet_t *tmp;
while (1) {
msg_t m;
msg_receive(&m);
seq_num = *((uint8_t *)m.content.ptr);
slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]);
tmp = (border_packet_t *)slot->frame;
uint8_t seq_num = *((uint8_t *) m.content.ptr);
struct send_slot *slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]);
border_packet_t *tmp = (border_packet_t *)slot->frame;
if (seq_num == tmp->seq_num) {
writepacket(slot->frame, slot->frame_len);

View File

@ -319,18 +319,15 @@ uint8_t ipv6_get_addr_match(const ipv6_addr_t *src,
*/
static int is_our_address(ipv6_addr_t *addr)
{
ipv6_net_if_ext_t *net_if_ext;
ipv6_net_if_addr_t *myaddr;
uint8_t prefix, suffix;
int if_id = -1;
unsigned counter = 0;
DEBUGF("Is this my addres: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr));
while ((if_id = net_if_iter_interfaces(if_id)) >= 0) {
net_if_ext = ipv6_net_if_get_ext(if_id);
myaddr = NULL;
prefix = net_if_ext->prefix / 8;
suffix = IPV6_ADDR_LEN - prefix;
ipv6_net_if_ext_t *net_if_ext = ipv6_net_if_get_ext(if_id);
ipv6_net_if_addr_t *myaddr = NULL;
uint8_t prefix = net_if_ext->prefix / 8;
uint8_t suffix = IPV6_ADDR_LEN - prefix;
while ((myaddr = (ipv6_net_if_addr_t *)net_if_iter_addresses(if_id,
(net_if_addr_t **) &myaddr)) != NULL) {
@ -494,7 +491,6 @@ int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr,
ndp_addr_state_t state, uint32_t val_ltime,
uint32_t pref_ltime, uint8_t is_anycast)
{
ipv6_net_if_addr_t *addr_entry;
ipv6_net_if_hit_t hit;
if (ipv6_addr_is_unspecified(addr) == 128) {
@ -522,7 +518,7 @@ int ipv6_net_if_add_addr(int if_id, const ipv6_addr_t *addr,
ipv6_addr_t *addr_data = &ipv6_addr_buffer[ipv6_net_if_addr_buffer_count];
memcpy(addr_data, addr, sizeof(ipv6_addr_t));
addr_entry = &ipv6_net_if_addr_buffer[ipv6_net_if_addr_buffer_count];
ipv6_net_if_addr_t *addr_entry = &ipv6_net_if_addr_buffer[ipv6_net_if_addr_buffer_count];
addr_entry->addr_data = addr_data;
addr_entry->addr_len = 128;

View File

@ -24,12 +24,10 @@
static inline uint8_t sector_read(unsigned char *read_buf, unsigned long sector, unsigned long length, unsigned long offset)
{
unsigned long i;
if (MCI_read(read_buf, sector, 1) == RES_OK) {
printf("[disk] Read sector %lu (%lu):\n", sector, offset);
for (i = offset + 1; i <= offset + length; i++) {
for (unsigned long i = offset + 1; i <= offset + length; i++) {
printf(" %u", read_buf[i - 1]);
if (!(i % 16)) {
@ -88,11 +86,11 @@ void _get_sectorcount(int argc, char **argv)
void _read_sector(int argc, char **argv)
{
unsigned long sectornr, scount;
unsigned short ssize;
if (argc == 2) {
sectornr = atol(argv[1]);
unsigned long scount;
unsigned short ssize;
unsigned long sectornr = atol(argv[1]);
if ((MCI_ioctl(GET_SECTOR_COUNT, &scount) == RES_OK) && (MCI_ioctl(GET_SECTOR_SIZE, &ssize) == RES_OK)) {
unsigned char read_buf[ssize];

View File

@ -32,15 +32,15 @@ static void _gettime_handler(void)
static void _settime_handler(char **argv)
{
struct tm now;
short i1, i2, i3;
int res;
do {
res = sscanf(argv[1], "%hd-%hd-%hd", &i1, &i2, &i3);
short i1, i2, i3;
int res = sscanf(argv[1], "%hd-%hd-%hd", &i1, &i2, &i3);
if (res != 3) {
break;
}
struct tm now;
now.tm_year = i1 - 1900;
now.tm_mon = i2 - 1;
now.tm_mday = i3;

View File

@ -281,16 +281,14 @@ static void *run(void *arg)
{
(void) arg;
msg_t m;
transceiver_command_t *cmd;
msg_init_queue(msg_buffer, TRANSCEIVER_MSG_BUFFER_SIZE);
while (1) {
DEBUG("transceiver: Waiting for next message\n");
msg_t m;
msg_receive(&m);
/* only makes sense for messages for upper layers */
cmd = (transceiver_command_t *) m.content.ptr;
transceiver_command_t *cmd = (transceiver_command_t *) m.content.ptr;
DEBUG("transceiver: Transceiver: Message received, type: %02X\n", m.type);
switch (m.type) {

View File

@ -67,10 +67,8 @@ void rx(void *ptr, char data)
int tx(void *ptr)
{
char data;
if (tx_buf.avail > 0) {
data = ringbuffer_get_one(&tx_buf);
char data = ringbuffer_get_one(&tx_buf);
uart_write(DEV, data);
return 1;
}
@ -95,10 +93,6 @@ void *uart_thread(void *arg)
int main(void)
{
char buf[128];
int res;
msg_t msg;
main_pid = thread_getpid();
puts("\nTesting interrupt driven mode of UART driver\n");
@ -121,10 +115,12 @@ int main(void)
0, uart_thread, 0, "uart");
while (1) {
msg_t msg;
msg_receive(&msg);
printf("RECEIVED INPUT: ");
res = ringbuffer_get(&rx_buf, buf, rx_buf.avail);
char buf[128];
int res = ringbuffer_get(&rx_buf, buf, rx_buf.avail);
buf[res] = '\0';
printf("%s", buf);

View File

@ -508,20 +508,19 @@ static void test_map_invalid(void)
static void test_semantic_tagging(void)
{
char buffer[128];
{
const char *input = "1";
/* CBOR: byte string of length 1 marked with a tag to indicate it is a positive bignum */
/* byte 1: (major type 6, additional information */
/* byte 2: (major type 2, additional 1 for the length) */
/* byte 3: bytes representing the bignum */
unsigned char data[] = {0xc2, 0x41, 0x31};
TEST_ASSERT(cbor_write_tag(&stream, 2)); /* write byte 1 */
TEST_ASSERT(cbor_serialize_byte_string(&stream, input)); /* write byte 2 and 3 */
CBOR_CHECK_SERIALIZED(stream, data, sizeof(data));
TEST_ASSERT(cbor_at_tag(&stream, 0));
TEST_ASSERT(cbor_deserialize_byte_string(&stream, 1, buffer, sizeof(buffer)));
CBOR_CHECK_DESERIALIZED(input, buffer, EQUAL_STRING);
}
const char *input = "1";
/* CBOR: byte string of length 1 marked with a tag to indicate it is a positive bignum */
/* byte 1: (major type 6, additional information */
/* byte 2: (major type 2, additional 1 for the length) */
/* byte 3: bytes representing the bignum */
unsigned char data[] = {0xc2, 0x41, 0x31};
TEST_ASSERT(cbor_write_tag(&stream, 2)); /* write byte 1 */
TEST_ASSERT(cbor_serialize_byte_string(&stream, input)); /* write byte 2 and 3 */
CBOR_CHECK_SERIALIZED(stream, data, sizeof(data));
TEST_ASSERT(cbor_at_tag(&stream, 0));
TEST_ASSERT(cbor_deserialize_byte_string(&stream, 1, buffer, sizeof(buffer)));
CBOR_CHECK_DESERIALIZED(input, buffer, EQUAL_STRING);
}
#ifndef CBOR_NO_CTIME