mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
fixed a few unsigned->signed overflows
This commit is contained in:
parent
38be9bec88
commit
86386ae363
@ -1,8 +1,8 @@
|
||||
// Different utilities
|
||||
// General purpose function/macros
|
||||
|
||||
#ifndef __UTILS_H__
|
||||
#define __UTILS_H__
|
||||
|
||||
int utils_get_uart_key();
|
||||
#define ABSDIFF( x, y ) ( ( x ) >= ( y ) ? ( x ) - ( y ) : ( y ) - ( x ) )
|
||||
|
||||
#endif
|
||||
|
@ -16,8 +16,7 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define PABS( x ) ( ( x ) >= 0 ? ( x ) : -( x ) )
|
||||
#include "utils.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// std functions
|
||||
@ -287,7 +286,7 @@ static u32 platform_timer_set_clock( unsigned id, u32 clock )
|
||||
unsigned i, mini = 0;
|
||||
|
||||
for( i = 0; i < 5; i ++ )
|
||||
if( PABS( clock - BOARD_MCK / clkdivs[ i ] ) < PABS( clock - BOARD_MCK / clkdivs[ mini ] ) )
|
||||
if( ABSDIFF( clock, BOARD_MCK / clkdivs[ i ] ) < ABSDIFF( clock, BOARD_MCK / clkdivs[ mini ] ) )
|
||||
mini = i;
|
||||
TC_Configure( ( AT91S_TC* )timer_base[ id ], mini | AT91C_TC_WAVE );
|
||||
return BOARD_MCK / clkdivs[ mini ];
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "ssi.h"
|
||||
#include "timer.h"
|
||||
#include "pwm.h"
|
||||
#include "utils.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// std function
|
||||
@ -439,7 +440,6 @@ u32 platform_timer_get_diff_us( unsigned id, timer_data_type end, timer_data_typ
|
||||
// PWMs
|
||||
|
||||
#define PLATFORM_NUM_PWMS 6
|
||||
#define PABS( x ) ( ( x ) < 0 ? -( x ) : ( x ) )
|
||||
|
||||
// SYSCTL div data and actual div factors
|
||||
const static u32 pwm_div_ctl[] = { SYSCTL_PWMDIV_1, SYSCTL_PWMDIV_2, SYSCTL_PWMDIV_4, SYSCTL_PWMDIV_8, SYSCTL_PWMDIV_16, SYSCTL_PWMDIV_32, SYSCTL_PWMDIV_64 };
|
||||
@ -479,7 +479,7 @@ static u32 platform_pwm_set_clock( u32 clock )
|
||||
|
||||
sysclk = SysCtlClockGet();
|
||||
for( i = min_i = 0; i < sizeof( pwm_div_data ) / sizeof( u8 ); i ++ )
|
||||
if( PABS( clock - sysclk / pwm_div_data[ i ] ) < PABS( clock - sysclk / pwm_div_data[ min_i ] ) )
|
||||
if( ABSDIFF( clock, sysclk / pwm_div_data[ i ] ) < ABSDIFF( clock, sysclk / pwm_div_data[ min_i ] ) )
|
||||
min_i = i;
|
||||
SysCtlPWMClockSet( pwm_div_ctl[ min_i ] );
|
||||
return sysclk / pwm_div_data[ min_i ];
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "lpc288x.h"
|
||||
#include "target.h"
|
||||
#include "uart.h"
|
||||
#include "utils.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// std functions
|
||||
@ -189,7 +190,6 @@ static const vu_ptr tmr_value[] = { &T0VALUE, &T1VALUE };
|
||||
static const vu_ptr tmr_ctrl[] = { &T0CTRL, &T1CTRL };
|
||||
static const vu_ptr tmr_clr[] = { &T0CLR, &T1CLR };
|
||||
static const unsigned tmr_prescale[] = { 1, 16, 256, 1 };
|
||||
#define TABS( x ) ( ( x ) < 0 ? -( x ) : ( x ) )
|
||||
|
||||
// Helper: get timer clock
|
||||
static u32 platform_timer_get_clock( unsigned id )
|
||||
@ -203,7 +203,7 @@ static u32 platform_timer_set_clock( unsigned id, u32 clock )
|
||||
unsigned i, mini = 0;
|
||||
|
||||
for( i = 0; i < 3; i ++ )
|
||||
if( TABS( clock - MAIN_CLOCK / tmr_prescale[ i ] ) < TABS( clock - MAIN_CLOCK / tmr_prescale[ mini ] ) )
|
||||
if( ABSDIFF( clock, MAIN_CLOCK / tmr_prescale[ i ] ) < ABSDIFF( clock, MAIN_CLOCK / tmr_prescale[ mini ] ) )
|
||||
mini = i;
|
||||
*tmr_ctrl[ id ] = ( *tmr_ctrl[ id ] & ~0xB ) | ( mini << 2 );
|
||||
return MAIN_CLOCK / tmr_prescale[ mini ];
|
||||
|
@ -7,8 +7,7 @@
|
||||
#include <reent.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LABS( x ) ( ( x ) < 0 ? -( x ) : ( x ) )
|
||||
#include "utils.h"
|
||||
|
||||
// Structure with UART baud/parameters
|
||||
// Computed used Philip's "baud rate calculator" XLS file
|
||||
@ -68,7 +67,7 @@ u32 uart_init( u32 baud, int databits, int parity, int stopbits )
|
||||
|
||||
// Find correct baud
|
||||
for( i = minpos = 0; i < sizeof( uart_baudinfo ) / sizeof( UART_BAUDDATA ); i ++ )
|
||||
if( LABS( baud - uart_baudinfo[ i ].baud ) < LABS( baud - uart_baudinfo[ minpos ].baud ) )
|
||||
if( ABSDIFF( baud, uart_baudinfo[ i ].baud ) < ABSDIFF( baud, uart_baudinfo[ minpos ].baud ) )
|
||||
minpos = i;
|
||||
pdata = uart_baudinfo + minpos;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user