Skip to content

Commit 8d64ff6

Browse files
committed
change flag to bit and remove unused usbMsgFlags
1 parent 4e9a13c commit 8d64ff6

4 files changed

Lines changed: 14 additions & 17 deletions

File tree

ch55xduino/ch55x/cores/ch55xduino/HardwareSerial0.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern volatile __xdata uint8_t uart0_rx_buffer_head;
88
extern volatile __xdata uint8_t uart0_rx_buffer_tail;
99
extern volatile __xdata uint8_t uart0_tx_buffer_head;
1010
extern volatile __xdata uint8_t uart0_tx_buffer_tail;
11-
extern volatile __xdata uint8_t uart0_flags;
11+
extern volatile __bit uart0_flag_sending;
1212

1313
//extern wait functions
1414
void delayMicroseconds(uint16_t us);
@@ -49,8 +49,8 @@ void Serial0_begin(unsigned long baud){
4949

5050
uint8_t Serial0_write(uint8_t SendDat)
5151
{
52-
if ((uart0_tx_buffer_head == uart0_tx_buffer_tail) && ( (uart0_flags & UART0_FLG_SENDING)==0)){ //start to send
53-
uart0_flags |= UART0_FLG_SENDING;
52+
if ( (uart0_tx_buffer_head == uart0_tx_buffer_tail) && (uart0_flag_sending==0) ){ //start to send
53+
uart0_flag_sending = 1;
5454
SBUF = SendDat;
5555
return 1;
5656
}
@@ -71,7 +71,7 @@ uint8_t Serial0_write(uint8_t SendDat)
7171
}
7272

7373
void Serial0_flush(void){
74-
while( (uart0_flags & UART0_FLG_SENDING) );
74+
while( uart0_flag_sending );
7575
}
7676

7777
uint8_t Serial0_available(void){

ch55xduino/ch55x/cores/ch55xduino/HardwareSerial0ISR.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ volatile __xdata uint8_t uart0_rx_buffer_head=0;
66
volatile __xdata uint8_t uart0_rx_buffer_tail=0;
77
volatile __xdata uint8_t uart0_tx_buffer_head=0;
88
volatile __xdata uint8_t uart0_tx_buffer_tail=0;
9-
volatile __xdata uint8_t uart0_flags=0;
9+
volatile __bit uart0_flag_sending=0;
1010

1111
void uart0IntRxHandler(){
1212
uint8_t nextHead = (uart0_rx_buffer_head + 1) % SERIAL0_RX_BUFFER_SIZE;
@@ -18,10 +18,10 @@ void uart0IntRxHandler(){
1818
}
1919

2020
void uart0IntTxHandler(){
21-
if ((uart0_flags & UART0_FLG_SENDING)){
21+
if (uart0_flag_sending){
2222
if (uart0_tx_buffer_head == uart0_tx_buffer_tail){
2323
//do no more
24-
uart0_flags &= ~(UART0_FLG_SENDING);
24+
uart0_flag_sending &= 0;
2525
}else{
2626
SBUF=Transmit_Uart0_Buf[uart0_tx_buffer_tail];
2727
uart0_tx_buffer_tail = (uart0_tx_buffer_tail + 1) % SERIAL0_TX_BUFFER_SIZE;

ch55xduino/ch55x/cores/ch55xduino/USBCDC.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ __xdata uint8_t LineCoding[LINE_CODEING_SIZE]={0x00,0xe1,0x00,0x00,0x00,0x00,0x0
1414
volatile __xdata uint8_t USBByteCountEP2 = 0; //Bytes of received data on USB endpoint
1515
volatile __xdata uint8_t USBBufOutPointEP2 = 0; //Data pointer for fetching
1616

17-
volatile __xdata uint8_t UpPoint2_Busy = 0; //Flag of whether upload pointer is busy
17+
volatile __bit UpPoint2BusyFlag = 0; //Flag of whether upload pointer is busy
1818
volatile __xdata uint8_t controlLineState = 0;
1919

2020
__xdata uint8_t usbWritePointer = 0;
@@ -24,7 +24,7 @@ void delayMicroseconds(uint16_t us);
2424
void resetCDCParameters(){
2525

2626
USBByteCountEP2 = 0; //Bytes of received data on USB endpoint
27-
UpPoint2_Busy = 0;
27+
UpPoint2BusyFlag = 0;
2828
}
2929

3030
void setLineCodingHandler(){
@@ -71,10 +71,10 @@ bool USBSerial(){
7171

7272

7373
void USBSerial_flush(void){
74-
if (!UpPoint2_Busy && usbWritePointer>0){
74+
if (!UpPoint2BusyFlag && usbWritePointer>0){
7575
UEP2_T_LEN = usbWritePointer;
7676
UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK; //Respond ACK
77-
UpPoint2_Busy = 1;
77+
UpPoint2BusyFlag = 1;
7878
usbWritePointer = 0;
7979
}
8080
}
@@ -84,7 +84,7 @@ uint8_t USBSerial_write(char c){ //3 bytes generic pointer
8484
if (controlLineState > 0) {
8585
while (true){
8686
waitWriteCount = 0;
87-
while (UpPoint2_Busy){//wait for 250ms or give up, on my mac it takes about 256us
87+
while (UpPoint2BusyFlag){//wait for 250ms or give up, on my mac it takes about 256us
8888
waitWriteCount++;
8989
delayMicroseconds(5);
9090
if (waitWriteCount>=50000) return 0;
@@ -106,7 +106,7 @@ uint8_t USBSerial_print_n(uint8_t * __xdata buf, __xdata int len){ //3 bytes ge
106106
if (controlLineState > 0) {
107107
while (len>0){
108108
waitWriteCount = 0;
109-
while (UpPoint2_Busy){//wait for 250ms or give up, on my mac it takes about 256us
109+
while (UpPoint2BusyFlag){//wait for 250ms or give up, on my mac it takes about 256us
110110
waitWriteCount++;
111111
delayMicroseconds(5);
112112
if (waitWriteCount>=50000) return 0;
@@ -144,7 +144,7 @@ char USBSerial_read(){
144144
void USB_EP2_IN(){
145145
UEP2_T_LEN = 0; // No data to send anymore
146146
UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_NAK; //Respond NAK by default
147-
UpPoint2_Busy = 0; //Clear busy flag
147+
UpPoint2BusyFlag = 0; //Clear busy flag
148148
}
149149

150150
void USB_EP2_OUT(){

ch55xduino/ch55x/cores/ch55xduino/USBhandler.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ uint8_t SetupReq,UsbConfig;
2121

2222
__code uint8_t *pDescr;
2323

24-
volatile uint8_t usbMsgFlags=0; // uint8_t usbMsgFlags copied from VUSB
25-
2624
inline void NOP_Process(void) {}
2725

2826
void USB_EP0_SETUP(){
@@ -32,7 +30,6 @@ void USB_EP0_SETUP(){
3230
SetupLen = ((uint16_t)UsbSetupBuf->wLengthH<<8) | (UsbSetupBuf->wLengthL);
3331
len = 0; // Default is success and upload 0 length
3432
SetupReq = UsbSetupBuf->bRequest;
35-
usbMsgFlags = 0;
3633
if ( ( UsbSetupBuf->bRequestType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD )//Not standard request
3734
{
3835

0 commit comments

Comments
 (0)