Skip to content

Commit

Permalink
Beta 1
Browse files Browse the repository at this point in the history
  • Loading branch information
redchenjs committed Mar 20, 2017
1 parent 7a26a96 commit 9f5e108
Show file tree
Hide file tree
Showing 18 changed files with 521 additions and 375 deletions.
50 changes: 26 additions & 24 deletions .cproject

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Debug/
Release/
.launches/
.settings/
.settings/
5 changes: 4 additions & 1 deletion inc/driver/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ enum direction {
};

extern unsigned char stepper_ready;
extern unsigned int stepper_location;

extern unsigned int stepper_location_now;
extern unsigned int stepper_location_set;

extern void stepper_update(void);
extern void stepper_init(void);
extern void stepper_step(unsigned int steps_to_move, unsigned char direction);

Expand Down
1 change: 1 addition & 0 deletions inc/user/motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ extern unsigned char motor_status_past;
extern void motor_init(void);
extern void motor_step(int num);
extern void motor_update(void);
extern void motor_set_position(unsigned int value);

#endif
13 changes: 13 additions & 0 deletions inc/user/status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* status.h
*
* Created on: 2017-3-19
* Author: redchenjs
*/

#ifndef STATUS_H_
#define STATUS_H_

extern void status_update(void);

#endif /* STATUS_H_ */
3 changes: 1 addition & 2 deletions inc/user/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ enum terminal_mode {
extern unsigned char mode_now;
extern unsigned char mode_past;

extern void terminal_value_to_string(unsigned int value, char *p_string);
extern char* terminal_sub_string(char* p_string, unsigned char position, unsigned char length);
extern void terminal_set_mode(unsigned int value);

extern void terminal_update(void);

Expand Down
2 changes: 1 addition & 1 deletion src/device/wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
void wdt_init(void)
{
WDTCTL = WDT_MDLY_8;
IE1 |= WDTIE;
IE1 |= WDTIE;
}
43 changes: 25 additions & 18 deletions src/driver/stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
#define stepper_port P2OUT

unsigned char stepper_ready = 0;
unsigned int stepper_location = 0;

static unsigned int location_set = 0;
unsigned int stepper_location_now = 0;
unsigned int stepper_location_set = 0;

const static unsigned char stepper_mask[4] = {0x03, 0x06, 0x0c, 0x09};

void stepper_update(void)
{
stepper_ready = 0;

TA0CTL |= MC_1;
}

void stepper_step(unsigned int steps_to_move, unsigned char direction)
{
const static unsigned int min_of_steps = 0;
const static unsigned int max_of_steps = 6400;
const static unsigned int max_of_steps = 2000;

if (direction == FORWARD) {
if (steps_to_move + location_set > max_of_steps) {
location_set = max_of_steps;
if (steps_to_move + stepper_location_set > max_of_steps) {
stepper_location_set = max_of_steps;
}
else {
location_set += steps_to_move;
stepper_location_set += steps_to_move;
}
}
else {
if (steps_to_move > location_set) {
location_set = min_of_steps;
if (steps_to_move > stepper_location_set) {
stepper_location_set = min_of_steps;
}
else {
location_set -= steps_to_move;
stepper_location_set -= steps_to_move;
}
}

Expand All @@ -42,27 +49,27 @@ void stepper_init(void)
P2DIR = 0x0f;
P2OUT = 0x00;

TA0CCR0 = 5000;
TA0CCTL0 = CCIE;
TA0CTL = TASSEL_2 + ID_3 + MC_0 + TACLR;
TA0CCR0 = 4000;
TA0CCTL0 |= CCIE;
TA0CTL |= TASSEL_2 + ID_3 + MC_0 + TACLR;

stepper_ready = 1;
}

inline void stepper_timer_isr_handle(void)
{
if (stepper_location != location_set) {
if (stepper_location < location_set) {
stepper_location++;
if (stepper_location_now != stepper_location_set) {
if (stepper_location_now < stepper_location_set) {
stepper_location_now++;
}
else {
stepper_location--;
stepper_location_now--;
}
stepper_port = stepper_mask[stepper_location & 0x03];
stepper_port = stepper_mask[stepper_location_now & 0x03];
}
else {
TA0CTL |= MC_0;
stepper_port = 0x0f;
stepper_port = 0x00;
stepper_ready = 1;
}
}
31 changes: 11 additions & 20 deletions src/interface/uart_usci_a0.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
static unsigned char *uart_tx_buff = 0;
static unsigned char uart_rx_buff[SIZE] = {0};

static unsigned char uart_rx_read_index = 0;
static unsigned char uart_rx_write_index = 0;

static unsigned char uart_tx_num = 0;
static unsigned char uart_rx_num = 0;

Expand All @@ -31,15 +28,15 @@ void uart_init(void)
UCA0CTL1 |= UCSWRST;

UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 140;
UCA0BR0 = 139;
UCA0BR1 = 0;
UCA0MCTL = UCBRS2 + UCBRS0;
UCA0MCTL = UCBRS0;

UCA0CTL1 &=~UCSWRST;

UC0IFG &=~(UCA0RXIFG + UCA0TXIFG);

UC0IE |= UCA0RXIE;
UC0IE |= UCA0RXIE;
}

unsigned char uart_transmit_frame(unsigned char *p_buff, unsigned char num)
Expand All @@ -58,17 +55,15 @@ unsigned char uart_transmit_frame(unsigned char *p_buff, unsigned char num)

unsigned char uart_receive_frame(unsigned char *p_buff, unsigned char num)
{
unsigned char i, cnt=0;
unsigned char cnt=0;
if (num == 0 || uart_rx_num == 0) return 0;
p_buff += uart_rx_num;
__disable_interrupt();
for (i = uart_rx_num; i>0 && num>0; i--, num--) {
if (uart_rx_read_index == SIZE) {
uart_rx_read_index = 0;
}
*p_buff++ = uart_rx_buff[uart_rx_read_index++];
uart_rx_num--;
do {
*--p_buff = uart_rx_buff[--uart_rx_num];
cnt++;
}
}while (uart_rx_num > 0);
uart_rx_num = 0;
__enable_interrupt();
return cnt;
}
Expand All @@ -88,12 +83,8 @@ inline void uart_tx_isr_handle(void)

inline void uart_rx_isr_handle(void)
{
if (uart_rx_write_index == SIZE) {
uart_rx_write_index = 0;
}
if (uart_rx_num == SIZE) {
uart_rx_num = 0;
uart_rx_num = SIZE-1;
}
uart_rx_buff[uart_rx_write_index++] = UCA0RXBUF;
uart_rx_num++;
uart_rx_buff[uart_rx_num++] = UCA0RXBUF;
}
Loading

0 comments on commit 9f5e108

Please sign in to comment.