📄 davincievm_msp430.c
字号:
/*
* Copyright 2005 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*
* Not for distribution.
*/
/*
* MSP430 implementation
*
*/
#include "davincievm_msp430.h"
#include "davincievm_gpio.h"
/* ------------------------------------------------------------------------ *
* *
* Command Format *
* *
* [ 0 ] - Length *
* [ 1 ] - Command Code *
* [ 2 ] - Data[0] *
* [ 3 ] - Data[1] *
* . *
* . *
* . *
* [ 31] - Data[29] *
* *
* ------------------------------------------------------------------------ */
static Uint8 cmd[32];
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_open( ) *
* *
* *
* ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_MSP430_open( )
{
/*
* Setup GPIO7 to receive MSP30 Interrupt
*/
DAVINCIEVM_GPIO_init( );
DAVINCIEVM_GPIO_setDirection( 7, GPIO_IN );
return 0;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_send( msg, len ) *
* Send Msg *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_send( Uint8* msg, Uint16 len )
{
Uint16 retcode;
/* Send Msg */
retcode = DAVINCIEVM_I2C_write( MSP430_I2CADDR, msg, len );
/* Wait 1 msec */
DAVINCIEVM_waitusec( 1000 );
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_recv( msg, len ) *
* Get Msg *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_recv( Uint8* msg, Uint16 len )
{
Uint16 retcode;
/* Recv Msg */
retcode = DAVINCIEVM_I2C_read( MSP430_I2CADDR, msg, len );
/* Wait 1 msec */
DAVINCIEVM_waitusec( 1000 );
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_recv_variable( msg, len ) *
* Get MSG with unknown size *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_recv_variable( Uint8* msg, Uint16* len )
{
Uint16 retcode;
/* Recv Msg */
retcode = DAVINCIEVM_I2C_read_variable( MSP430_I2CADDR, msg, 32 );
/* Msg length */
*len = msg[0];
/* Wait 1 msec */
DAVINCIEVM_waitusec( 1000 );
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_getIntrState( ) *
* Get MSP430 Interrupt value *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_getIntrState( )
{
return DAVINCIEVM_GPIO_getInput( 7 ); // Return GPIO7 value
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_setRtc( time ) *
* Set Realtime clock *
* *
* time <- RTC_Time structure used to describe time *
* > year (16-bit) *
* > month *
* > day *
* > hour *
* > minute *
* > second *
* *
* note: The year "2005" is value 0x2005. A number must be in the *
* hexadecimal form, but read as a decimal when "0x" is used. *
* The primary reasoning is for each digit to be stored as a *
* 4-bit value, and can be displayed on a LCD time display *
* without any further number processing. *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_setRtc( RTC_Time* time )
{
Uint16 retcode = 0;
/* Set time */
cmd[0] = 9;
cmd[1] = SET_RTC_PARAMS;
cmd[2] = time->year & 0xff;
cmd[3] = time->year >> 8;
cmd[4] = time->month;
cmd[5] = time->day;
cmd[6] = time->hour;
cmd[7] = time->minute;
cmd[8] = time->second;
retcode |= DAVINCIEVM_MSP430_send( cmd, 9 );
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_getRtc( time ) *
* Get Realtime Clock *
* *
* time <- RTC_Time structure used to describe time *
* > year (16-bit) *
* > month *
* > day *
* > hour *
* > minute *
* > second *
* *
* note: The year "2005" is value 0x2005. A number must be in the *
* hexadecimal form, but read as a decimal when "0x" is used. *
* The primary reasoning is for each digit to be stored as a *
* 4-bit value, and can be displayed on a LCD time display *
* without any further number processing. *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_getRtc( RTC_Time* time )
{
Uint16 retcode = 0;
cmd[0] = 2;
cmd[1] = GET_RTC_PARAMS;
retcode |= DAVINCIEVM_MSP430_send( cmd, 2 );
retcode |= DAVINCIEVM_MSP430_recv( cmd, 9 );
/* Get time */
time->year = cmd[2] | ( cmd[3] << 8 );
time->month = cmd[4];
time->day = cmd[5];
time->hour = cmd[6];
time->minute = cmd[7];
time->second = cmd[8];
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_getIrValue( ir_value ) *
* Get the current IR value *
* *
* ir_value <- 16-bit IR value - Each successful getIrValue call will *
* toggle bit 12 ( 0x0800 ). This is to distinguish *
* between 2 consecutive IR values with the same value. *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_getIrValue( Uint16* ir_value )
{
Uint16 retcode = 0;
cmd[0] = 2;
cmd[1] = GET_IR_VALUE;
retcode |= DAVINCIEVM_MSP430_send( cmd, 2 );
retcode |= DAVINCIEVM_MSP430_recv( cmd, 4 );
*ir_value = cmd[2] | ( cmd[3] << 8 ); // Get 16-bit IR data
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_getIrData( ir_data, len ) *
* Get the current IR list *
* *
* ir_data <- 16-bit IR list - Each list consecutive list entry will *
* toggle bit 12 ( 0x0800 ). *
* len <- Total number of list entries *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_getIrData( Uint16* ir_data, Uint8* len )
{
Uint16 retcode = 0;
Uint16 msglen;
Uint8 i;
cmd[0] = 2;
cmd[1] = GET_IR_DATA;
retcode |= DAVINCIEVM_MSP430_send( cmd, 2 );
retcode |= DAVINCIEVM_MSP430_recv_variable( cmd, &msglen );
*len = msglen / 2;
for ( i = 0 ; i < msglen * 2 ; i++ ) // Get 16-bit IR data
ir_data[i] = ( cmd[ 2 * i + 2 ] )
| ( cmd[ 2 * i + 3 ] << 8 );
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_getInput( port2, port3 ) *
* Get Inputs of all input pins *
* *
* port2 <- 8-bit value of pins 2.X *
* port3 <- 8-bit value of pins 3.X *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_getInput( Uint8* port2, Uint8* port3 )
{
Uint16 retcode = 0;
cmd[0] = 2;
cmd[1] = GET_INPUT_STATE;
retcode |= DAVINCIEVM_MSP430_send( cmd, 2 );
retcode |= DAVINCIEVM_MSP430_recv( cmd, 4 );
*port2 = cmd[2]; // Get Inputs
*port3 = cmd[3];
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_getEvent( event ) *
* Get the current event *
* *
* event <- status of the current event *
* 0x00 - no event *
* 0x01 - state change event *
* 0x02 - IR event *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_getEvent( Uint8* event )
{
Uint16 retcode = 0;
cmd[0] = 2;
cmd[1] = GET_EVENT;
retcode |= DAVINCIEVM_MSP430_send( cmd, 2 );
retcode |= DAVINCIEVM_MSP430_recv( cmd, 3 );
*event = cmd[2]; // Get Event data
return retcode;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_MSP430_setOutput( port2, port3 ) *
* Set Outputs of all output pins *
* *
* port2 <- 8-bit value of pins 2.X ( no effect ) *
* port3 <- 8-bit value of pins 3.X ( only bits 0 & 3 have effect ) *
* *
* ------------------------------------------------------------------------ */
Uint16 DAVINCIEVM_MSP430_setOutput( Uint8 port2, Uint8 port3 )
{
Uint16 retcode = 0;
cmd[0] = 4;
cmd[1] = SET_OUTPUT_STATE;
cmd[2] = port2; // Pins 2.x
cmd[3] = port3; // Pins 3.x
retcode |= DAVINCIEVM_MSP430_send( cmd, 4 ); // SET Outputs
return retcode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -