Ejemplo n.º 1
0
void embsys_7segments_write(char tens_value, char units_value)
{
	/*set tens digit, upper nibble*/
	_sr(TENS_DIGIT | (tens_value & 0x7F), EMBSYS_7SEGMENTS_ADDR);
	/*set unit digit, lower nibble*/
	_sr(UNITS_DIGIT | (units_value & 0x7F), EMBSYS_7SEGMENTS_ADDR);
}
Ejemplo n.º 2
0
myFlashRead(int sizeToRead,int currentStartAddress){
//	int currentStartAddress=0;
	unsigned int tmpComannd=CMD_READ|FLASH_CONTROL_CYCLE_GO | (sizeToRead-1)<<16|FLASH_CONTROL_INTERRUPT_ENABLE;
	_sr(currentStartAddress,FLASH_ADDRESS);
	_sr(tmpComannd,FLASH_CONTROL_REG);



}
Ejemplo n.º 3
0
/* initialize timer 0 */
void embsys_timer_init(unsigned int interval)
{
	timer_control t;
	t.data = 0;
	t.bits.interrupt_enable = 1;
	t.bits.interrupt_pending = 0;
	t.bits.watchdog = 0;

	_sr(0, TIMER0_COUNT);
	_sr(CYCLES_IN_MS * interval, TIMER0_LIMIT);
	_sr(t.data, TIMER0_CONTROL);
}
Ejemplo n.º 4
0
/*_Interrupt2 void */timer1ISR()
{
	/* acknowledge the interrupt - disable the interrupt flag*/
		unsigned control1val=_lr(CONTROL1_REG);
		_sr((control1val&(~INTEREUPT_ENABLE_FLAG)),CONTROL1_REG);
		/* reset the interrupt flag if _oneShot=1 */
		if(!my_isOneShot1){
			_sr((control1val|INTEREUPT_ENABLE_FLAG),CONTROL1_REG);
		}

		my_timer1_cb();
}
Ejemplo n.º 5
0
/**********************************************************************
 *
 * Function:    timer1_register
 *
 * Descriptor:  Set expiration interval from now in milliseconds
 *
 * Notes:
 *
 * Return:      OPERATION_SUCCESS:      Timer request done successfully.
 *              NULL_POINTER:           One of the arguments points to NULL.
 *
 ***********************************************************************/
result_t timer1_register(uint32_t interval, bool one_shot, void(*timer_cb)(void)){
	if(timer_cb==NULL) return NULL_POINTER;
	//	if(interval==0) return INVALID_ARGUMENTS;
	_sr(RESET_VALUE,CONTROL1_REG);
	my_timer1_cb=timer_cb;
	my_isOneShot1=one_shot;
	_sr(RESET_VALUE,COUNT1_REG);
	_sr(LIMIT_RESET_VALUE,LIMIT1_REG);
	_sr(CYCLES_PER_MILISECOND*interval,LIMIT1_REG);
	_sr(INTEREUPT_ENABLE_FLAG,CONTROL1_REG);
	return OPERATION_SUCCESS;
}
Ejemplo n.º 6
0
/* Delete a block of 4k at a given address */
void embsys_flash_delete(Address addr) 
{
	/* note non-reading operation for callback */
	isRead = 0;
	_sr(addr & 0xFFFFF000, FLASH_FADDR);
	run_spi(CMD_ERASE_BLOCK, 0);
}
Ejemplo n.º 7
0
/* Reads from a given address to a buffer */
void embsys_flash_continue_read() 
{
	if (bufferTotal <= 0)
		return;
	/* write flash address */
	_sr(address + bufferCurrent, FLASH_FADDR);
	/* calculate how much to read out of 64 bytes max */
	cur_count = _min(64, bufferTotal - bufferCurrent);
	/* start the SPI command */
	run_spi(CMD_READ, cur_count);
}
Ejemplo n.º 8
0
/* Copy a buffer to the flash */
void embsys_flash_continue_write() 
{
	if (bufferTotal <= 0) 
		return;
	/* write flash address */
	_sr(address + bufferCurrent, FLASH_FADDR);
	/* calculate current count out of 64 bytes max per write */
	cur_count = _min(64, bufferTotal - bufferCurrent);
	/* copy the bytes to the flash data registers */
	flash_transfer_data(STORE_DATA, cur_count, buffer + bufferCurrent);
	/* start the SPI command */
	run_spi(CMD_WRITE, cur_count);
}
Ejemplo n.º 9
0
void flash_transfer_data(unsigned char direction, int count, unsigned char* data) 
{
	unsigned int data_pos = 0, i;
	if (direction == STORE_DATA) 
	{	
		for(i = 0 , data_pos = 0 ; i < count ; i+=4 , ++data_pos)
			_sr((*(unsigned int*)(data+i)),FLASH_FDATA+data_pos);
	} 
	else /* LOAD_DATA */
	{
		unsigned int j, regData;
		unsigned char* pRegData = (unsigned char*)&regData;
		while(i < count)
		{
			regData = _lr(FLASH_FDATA + data_pos);
			for(j = 0; j < 4 && i < count; ++i, ++j)
				data[i] = pRegData[j];
			data_pos++;
		}
	}
}
Ejemplo n.º 10
0
/* Called upon interrupt, immediately after the end of each cycle */
_Interrupt1 void flash_isr()
{
	_sr(FLASH_SR_SPI_CYCLE_DONE, FLASH_SR);
	if(isRead == 1)
	{
		flash_transfer_data(LOAD_DATA, cur_count, buffer + bufferCurrent);	
		bufferCurrent += 64;
		if(bufferTotal - bufferCurrent > 0)
			embsys_flash_continue_read();
		else
		{
			(*pFlashReadCallback)(buffer, bufferTotal);
			(*pFlashCallback)();
		}
	}
	else
	{
		bufferCurrent += 64;
		if(bufferCurrent < bufferTotal)
			embsys_flash_continue_write();
		else
			(*pFlashCallback)();
	}
}
Ejemplo n.º 11
0
void Cpu_EnableDataCache (void)
{
    _sr(0xC2, AUX_DCACHE_CNT);              // Enable the data cache
    _sr(0x01, AUX_INVAL_CNT);               // Invalidate DataCache
}
Ejemplo n.º 12
0
void run_spi(int cmd, int count) {
	/* spi cycle go = 1, interrupt enable = 1, set command, set byte count */
	unsigned int cr = SPI_CYCLE_GO | INTERRUPT_ENABLE | (cmd << 8) | ((count -1) << 16);
	/* execute the cycle */
	_sr(cr, FLASH_CR);
}